Commit | Line | Data |
---|---|---|
f5314dd5 DM |
1 | // sparc.cc -- sparc target support for gold. |
2 | ||
8c2bf391 | 3 | // Copyright 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. |
f5314dd5 DM |
4 | // Written by David S. Miller <davem@davemloft.net>. |
5 | ||
6 | // This file is part of gold. | |
7 | ||
8 | // This program is free software; you can redistribute it and/or modify | |
9 | // it under the terms of the GNU General Public License as published by | |
10 | // the Free Software Foundation; either version 3 of the License, or | |
11 | // (at your option) any later version. | |
12 | ||
13 | // This program is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | ||
18 | // You should have received a copy of the GNU General Public License | |
19 | // along with this program; if not, write to the Free Software | |
20 | // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
21 | // MA 02110-1301, USA. | |
22 | ||
23 | #include "gold.h" | |
24 | ||
25 | #include <cstdlib> | |
26 | #include <cstdio> | |
27 | #include <cstring> | |
28 | ||
29 | #include "elfcpp.h" | |
30 | #include "parameters.h" | |
31 | #include "reloc.h" | |
32 | #include "sparc.h" | |
33 | #include "object.h" | |
34 | #include "symtab.h" | |
35 | #include "layout.h" | |
36 | #include "output.h" | |
12c0daef | 37 | #include "copy-relocs.h" |
f5314dd5 DM |
38 | #include "target.h" |
39 | #include "target-reloc.h" | |
40 | #include "target-select.h" | |
41 | #include "tls.h" | |
42 | #include "errors.h" | |
f345227a | 43 | #include "gc.h" |
f5314dd5 DM |
44 | |
45 | namespace | |
46 | { | |
47 | ||
48 | using namespace gold; | |
49 | ||
50 | template<int size, bool big_endian> | |
51 | class Output_data_plt_sparc; | |
52 | ||
53 | template<int size, bool big_endian> | |
54 | class Target_sparc : public Sized_target<size, big_endian> | |
55 | { | |
56 | public: | |
57 | typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian> Reloc_section; | |
58 | ||
59 | Target_sparc() | |
60 | : Sized_target<size, big_endian>(&sparc_info), | |
8c2bf391 | 61 | got_(NULL), plt_(NULL), rela_dyn_(NULL), rela_ifunc_(NULL), |
12c0daef | 62 | copy_relocs_(elfcpp::R_SPARC_COPY), dynbss_(NULL), |
a4d85145 DM |
63 | got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL), |
64 | elf_machine_(sparc_info.machine_code), elf_flags_(0), | |
65 | elf_flags_set_(false) | |
f5314dd5 DM |
66 | { |
67 | } | |
68 | ||
6d03d481 ST |
69 | // Process the relocations to determine unreferenced sections for |
70 | // garbage collection. | |
71 | void | |
ad0f2072 | 72 | gc_process_relocs(Symbol_table* symtab, |
6d03d481 | 73 | Layout* layout, |
6fa2a40b | 74 | Sized_relobj_file<size, big_endian>* object, |
6d03d481 ST |
75 | unsigned int data_shndx, |
76 | unsigned int sh_type, | |
77 | const unsigned char* prelocs, | |
78 | size_t reloc_count, | |
79 | Output_section* output_section, | |
80 | bool needs_special_offset_handling, | |
81 | size_t local_symbol_count, | |
82 | const unsigned char* plocal_symbols); | |
83 | ||
f5314dd5 DM |
84 | // Scan the relocations to look for symbol adjustments. |
85 | void | |
ad0f2072 | 86 | scan_relocs(Symbol_table* symtab, |
f5314dd5 | 87 | Layout* layout, |
6fa2a40b | 88 | Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
89 | unsigned int data_shndx, |
90 | unsigned int sh_type, | |
91 | const unsigned char* prelocs, | |
92 | size_t reloc_count, | |
93 | Output_section* output_section, | |
94 | bool needs_special_offset_handling, | |
95 | size_t local_symbol_count, | |
96 | const unsigned char* plocal_symbols); | |
97 | // Finalize the sections. | |
98 | void | |
f59f41f3 | 99 | do_finalize_sections(Layout*, const Input_objects*, Symbol_table*); |
f5314dd5 DM |
100 | |
101 | // Return the value to use for a dynamic which requires special | |
102 | // treatment. | |
103 | uint64_t | |
104 | do_dynsym_value(const Symbol*) const; | |
105 | ||
106 | // Relocate a section. | |
107 | void | |
108 | relocate_section(const Relocate_info<size, big_endian>*, | |
109 | unsigned int sh_type, | |
110 | const unsigned char* prelocs, | |
111 | size_t reloc_count, | |
112 | Output_section* output_section, | |
113 | bool needs_special_offset_handling, | |
114 | unsigned char* view, | |
115 | typename elfcpp::Elf_types<size>::Elf_Addr view_address, | |
364c7fa5 ILT |
116 | section_size_type view_size, |
117 | const Reloc_symbol_changes*); | |
f5314dd5 DM |
118 | |
119 | // Scan the relocs during a relocatable link. | |
120 | void | |
ad0f2072 | 121 | scan_relocatable_relocs(Symbol_table* symtab, |
f5314dd5 | 122 | Layout* layout, |
6fa2a40b | 123 | Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
124 | unsigned int data_shndx, |
125 | unsigned int sh_type, | |
126 | const unsigned char* prelocs, | |
127 | size_t reloc_count, | |
128 | Output_section* output_section, | |
129 | bool needs_special_offset_handling, | |
130 | size_t local_symbol_count, | |
131 | const unsigned char* plocal_symbols, | |
132 | Relocatable_relocs*); | |
133 | ||
134 | // Relocate a section during a relocatable link. | |
135 | void | |
136 | relocate_for_relocatable(const Relocate_info<size, big_endian>*, | |
137 | unsigned int sh_type, | |
138 | const unsigned char* prelocs, | |
139 | size_t reloc_count, | |
140 | Output_section* output_section, | |
141 | off_t offset_in_output_section, | |
142 | const Relocatable_relocs*, | |
143 | unsigned char* view, | |
144 | typename elfcpp::Elf_types<size>::Elf_Addr view_address, | |
145 | section_size_type view_size, | |
146 | unsigned char* reloc_view, | |
147 | section_size_type reloc_view_size); | |
148 | // Return whether SYM is defined by the ABI. | |
149 | bool | |
9c2d0ef9 | 150 | do_is_defined_by_abi(const Symbol* sym) const |
f5314dd5 DM |
151 | { |
152 | // XXX Really need to support this better... | |
153 | if (sym->type() == elfcpp::STT_SPARC_REGISTER) | |
154 | return 1; | |
155 | ||
156 | return strcmp(sym->name(), "___tls_get_addr") == 0; | |
157 | } | |
158 | ||
8c2bf391 DM |
159 | // Return the PLT address to use for a global symbol. |
160 | uint64_t | |
161 | do_plt_address_for_global(const Symbol* gsym) const | |
162 | { return this->plt_section()->address_for_global(gsym); } | |
163 | ||
164 | uint64_t | |
165 | do_plt_address_for_local(const Relobj* relobj, unsigned int symndx) const | |
166 | { return this->plt_section()->address_for_local(relobj, symndx); } | |
167 | ||
9efe6174 ILT |
168 | // Return whether there is a GOT section. |
169 | bool | |
170 | has_got_section() const | |
171 | { return this->got_ != NULL; } | |
172 | ||
f5314dd5 DM |
173 | // Return the size of the GOT section. |
174 | section_size_type | |
0e70b911 | 175 | got_size() const |
f5314dd5 DM |
176 | { |
177 | gold_assert(this->got_ != NULL); | |
178 | return this->got_->data_size(); | |
179 | } | |
180 | ||
0e70b911 CC |
181 | // Return the number of entries in the GOT. |
182 | unsigned int | |
183 | got_entry_count() const | |
184 | { | |
185 | if (this->got_ == NULL) | |
186 | return 0; | |
187 | return this->got_size() / (size / 8); | |
188 | } | |
189 | ||
2a1079e8 DM |
190 | // Return the address of the GOT. |
191 | uint64_t | |
192 | got_address() const | |
193 | { | |
194 | if (this->got_ == NULL) | |
195 | return 0; | |
196 | return this->got_->address(); | |
197 | } | |
198 | ||
0e70b911 CC |
199 | // Return the number of entries in the PLT. |
200 | unsigned int | |
201 | plt_entry_count() const; | |
202 | ||
203 | // Return the offset of the first non-reserved PLT entry. | |
204 | unsigned int | |
205 | first_plt_entry_offset() const; | |
206 | ||
207 | // Return the size of each PLT entry. | |
208 | unsigned int | |
209 | plt_entry_size() const; | |
210 | ||
a4d85145 DM |
211 | protected: |
212 | // Make an ELF object. | |
213 | Object* | |
214 | do_make_elf_object(const std::string&, Input_file*, off_t, | |
215 | const elfcpp::Ehdr<size, big_endian>& ehdr); | |
216 | ||
217 | void | |
218 | do_adjust_elf_header(unsigned char* view, int len) const; | |
219 | ||
f5314dd5 DM |
220 | private: |
221 | ||
222 | // The class which scans relocations. | |
32b769e1 | 223 | class Scan |
f5314dd5 | 224 | { |
32b769e1 DM |
225 | public: |
226 | Scan() | |
227 | : issued_non_pic_error_(false) | |
228 | { } | |
229 | ||
95a2c8d6 RS |
230 | static inline int |
231 | get_reference_flags(unsigned int r_type); | |
232 | ||
f5314dd5 | 233 | inline void |
ad0f2072 | 234 | local(Symbol_table* symtab, Layout* layout, Target_sparc* target, |
6fa2a40b | 235 | Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
236 | unsigned int data_shndx, |
237 | Output_section* output_section, | |
238 | const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type, | |
239 | const elfcpp::Sym<size, big_endian>& lsym); | |
240 | ||
241 | inline void | |
ad0f2072 | 242 | global(Symbol_table* symtab, Layout* layout, Target_sparc* target, |
6fa2a40b | 243 | Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
244 | unsigned int data_shndx, |
245 | Output_section* output_section, | |
246 | const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type, | |
247 | Symbol* gsym); | |
248 | ||
21bb3914 ST |
249 | inline bool |
250 | local_reloc_may_be_function_pointer(Symbol_table* , Layout* , | |
251 | Target_sparc* , | |
6fa2a40b | 252 | Sized_relobj_file<size, big_endian>* , |
21bb3914 ST |
253 | unsigned int , |
254 | Output_section* , | |
255 | const elfcpp::Rela<size, big_endian>& , | |
256 | unsigned int , | |
257 | const elfcpp::Sym<size, big_endian>&) | |
258 | { return false; } | |
259 | ||
260 | inline bool | |
261 | global_reloc_may_be_function_pointer(Symbol_table* , Layout* , | |
262 | Target_sparc* , | |
6fa2a40b | 263 | Sized_relobj_file<size, big_endian>* , |
21bb3914 ST |
264 | unsigned int , |
265 | Output_section* , | |
266 | const elfcpp::Rela<size, | |
267 | big_endian>& , | |
268 | unsigned int , Symbol*) | |
269 | { return false; } | |
270 | ||
271 | ||
32b769e1 | 272 | private: |
f5314dd5 | 273 | static void |
6fa2a40b | 274 | unsupported_reloc_local(Sized_relobj_file<size, big_endian>*, |
f5314dd5 DM |
275 | unsigned int r_type); |
276 | ||
277 | static void | |
6fa2a40b | 278 | unsupported_reloc_global(Sized_relobj_file<size, big_endian>*, |
f5314dd5 DM |
279 | unsigned int r_type, Symbol*); |
280 | ||
281 | static void | |
282 | generate_tls_call(Symbol_table* symtab, Layout* layout, | |
283 | Target_sparc* target); | |
32b769e1 DM |
284 | |
285 | void | |
286 | check_non_pic(Relobj*, unsigned int r_type); | |
287 | ||
8c2bf391 DM |
288 | bool |
289 | reloc_needs_plt_for_ifunc(Sized_relobj_file<size, big_endian>*, | |
290 | unsigned int r_type); | |
291 | ||
32b769e1 DM |
292 | // Whether we have issued an error about a non-PIC compilation. |
293 | bool issued_non_pic_error_; | |
f5314dd5 DM |
294 | }; |
295 | ||
296 | // The class which implements relocation. | |
297 | class Relocate | |
298 | { | |
299 | public: | |
300 | Relocate() | |
abd242a9 | 301 | : ignore_gd_add_(false), reloc_adjust_addr_(NULL) |
f5314dd5 DM |
302 | { } |
303 | ||
304 | ~Relocate() | |
305 | { | |
306 | if (this->ignore_gd_add_) | |
307 | { | |
308 | // FIXME: This needs to specify the location somehow. | |
309 | gold_error(_("missing expected TLS relocation")); | |
310 | } | |
311 | } | |
312 | ||
313 | // Do a relocation. Return false if the caller should not issue | |
314 | // any warnings about this relocation. | |
315 | inline bool | |
316 | relocate(const Relocate_info<size, big_endian>*, Target_sparc*, | |
031cdbed ILT |
317 | Output_section*, size_t relnum, |
318 | const elfcpp::Rela<size, big_endian>&, | |
f5314dd5 DM |
319 | unsigned int r_type, const Sized_symbol<size>*, |
320 | const Symbol_value<size>*, | |
321 | unsigned char*, | |
322 | typename elfcpp::Elf_types<size>::Elf_Addr, | |
323 | section_size_type); | |
324 | ||
325 | private: | |
326 | // Do a TLS relocation. | |
327 | inline void | |
328 | relocate_tls(const Relocate_info<size, big_endian>*, Target_sparc* target, | |
329 | size_t relnum, const elfcpp::Rela<size, big_endian>&, | |
330 | unsigned int r_type, const Sized_symbol<size>*, | |
331 | const Symbol_value<size>*, | |
332 | unsigned char*, | |
333 | typename elfcpp::Elf_types<size>::Elf_Addr, | |
334 | section_size_type); | |
335 | ||
a5a5f7a3 DM |
336 | inline void |
337 | relax_call(Target_sparc<size, big_endian>* target, | |
338 | unsigned char* view, | |
339 | const elfcpp::Rela<size, big_endian>& rela, | |
340 | section_size_type view_size); | |
341 | ||
f5314dd5 DM |
342 | // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD |
343 | bool ignore_gd_add_; | |
abd242a9 DM |
344 | |
345 | // If we hit a reloc at this view address, adjust it back by 4 bytes. | |
346 | unsigned char *reloc_adjust_addr_; | |
f5314dd5 DM |
347 | }; |
348 | ||
349 | // A class which returns the size required for a relocation type, | |
350 | // used while scanning relocs during a relocatable link. | |
351 | class Relocatable_size_for_reloc | |
352 | { | |
353 | public: | |
354 | unsigned int | |
355 | get_size_for_reloc(unsigned int, Relobj*); | |
356 | }; | |
357 | ||
358 | // Get the GOT section, creating it if necessary. | |
359 | Output_data_got<size, big_endian>* | |
360 | got_section(Symbol_table*, Layout*); | |
361 | ||
8c2bf391 DM |
362 | // Create the PLT section. |
363 | void | |
364 | make_plt_section(Symbol_table* symtab, Layout* layout); | |
365 | ||
f5314dd5 DM |
366 | // Create a PLT entry for a global symbol. |
367 | void | |
368 | make_plt_entry(Symbol_table*, Layout*, Symbol*); | |
369 | ||
8c2bf391 DM |
370 | // Create a PLT entry for a local STT_GNU_IFUNC symbol. |
371 | void | |
372 | make_local_ifunc_plt_entry(Symbol_table*, Layout*, | |
373 | Sized_relobj_file<size, big_endian>* relobj, | |
374 | unsigned int local_sym_index); | |
375 | ||
f5314dd5 DM |
376 | // Create a GOT entry for the TLS module index. |
377 | unsigned int | |
378 | got_mod_index_entry(Symbol_table* symtab, Layout* layout, | |
6fa2a40b | 379 | Sized_relobj_file<size, big_endian>* object); |
f5314dd5 DM |
380 | |
381 | // Return the gsym for "__tls_get_addr". Cache if not already | |
382 | // cached. | |
383 | Symbol* | |
384 | tls_get_addr_sym(Symbol_table* symtab) | |
385 | { | |
386 | if (!this->tls_get_addr_sym_) | |
387 | this->tls_get_addr_sym_ = symtab->lookup("__tls_get_addr", NULL); | |
388 | gold_assert(this->tls_get_addr_sym_); | |
389 | return this->tls_get_addr_sym_; | |
390 | } | |
391 | ||
392 | // Get the PLT section. | |
8c2bf391 | 393 | Output_data_plt_sparc<size, big_endian>* |
f5314dd5 DM |
394 | plt_section() const |
395 | { | |
396 | gold_assert(this->plt_ != NULL); | |
397 | return this->plt_; | |
398 | } | |
399 | ||
400 | // Get the dynamic reloc section, creating it if necessary. | |
401 | Reloc_section* | |
402 | rela_dyn_section(Layout*); | |
403 | ||
8c2bf391 DM |
404 | // Get the section to use for IFUNC relocations. |
405 | Reloc_section* | |
406 | rela_ifunc_section(Layout*); | |
407 | ||
f5314dd5 DM |
408 | // Copy a relocation against a global symbol. |
409 | void | |
ef9beddf | 410 | copy_reloc(Symbol_table* symtab, Layout* layout, |
6fa2a40b | 411 | Sized_relobj_file<size, big_endian>* object, |
12c0daef ILT |
412 | unsigned int shndx, Output_section* output_section, |
413 | Symbol* sym, const elfcpp::Rela<size, big_endian>& reloc) | |
414 | { | |
415 | this->copy_relocs_.copy_reloc(symtab, layout, | |
416 | symtab->get_sized_symbol<size>(sym), | |
417 | object, shndx, output_section, | |
418 | reloc, this->rela_dyn_section(layout)); | |
419 | } | |
f5314dd5 DM |
420 | |
421 | // Information about this specific target which we pass to the | |
422 | // general Target structure. | |
423 | static Target::Target_info sparc_info; | |
424 | ||
425 | // The types of GOT entries needed for this platform. | |
0e70b911 CC |
426 | // These values are exposed to the ABI in an incremental link. |
427 | // Do not renumber existing values without changing the version | |
428 | // number of the .gnu_incremental_inputs section. | |
f5314dd5 DM |
429 | enum Got_type |
430 | { | |
431 | GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol | |
432 | GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset | |
433 | GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair | |
434 | }; | |
435 | ||
436 | // The GOT section. | |
437 | Output_data_got<size, big_endian>* got_; | |
438 | // The PLT section. | |
439 | Output_data_plt_sparc<size, big_endian>* plt_; | |
440 | // The dynamic reloc section. | |
441 | Reloc_section* rela_dyn_; | |
8c2bf391 DM |
442 | // The section to use for IFUNC relocs. |
443 | Reloc_section* rela_ifunc_; | |
f5314dd5 | 444 | // Relocs saved to avoid a COPY reloc. |
12c0daef | 445 | Copy_relocs<elfcpp::SHT_RELA, size, big_endian> copy_relocs_; |
f5314dd5 DM |
446 | // Space for variables copied with a COPY reloc. |
447 | Output_data_space* dynbss_; | |
448 | // Offset of the GOT entry for the TLS module index; | |
449 | unsigned int got_mod_index_offset_; | |
450 | // Cached pointer to __tls_get_addr symbol | |
451 | Symbol* tls_get_addr_sym_; | |
a4d85145 DM |
452 | // Accumulated elf machine type |
453 | elfcpp::Elf_Half elf_machine_; | |
454 | // Accumulated elf header flags | |
455 | elfcpp::Elf_Word elf_flags_; | |
456 | // Whether elf_flags_ has been set for the first time yet | |
457 | bool elf_flags_set_; | |
f5314dd5 DM |
458 | }; |
459 | ||
460 | template<> | |
461 | Target::Target_info Target_sparc<32, true>::sparc_info = | |
462 | { | |
463 | 32, // size | |
464 | true, // is_big_endian | |
465 | elfcpp::EM_SPARC, // machine_code | |
466 | false, // has_make_symbol | |
467 | false, // has_resolve | |
468 | false, // has_code_fill | |
469 | true, // is_default_stack_executable | |
b3ce541e | 470 | false, // can_icf_inline_merge_sections |
f5314dd5 DM |
471 | '\0', // wrap_char |
472 | "/usr/lib/ld.so.1", // dynamic_linker | |
473 | 0x00010000, // default_text_segment_address | |
474 | 64 * 1024, // abi_pagesize (overridable by -z max-page-size) | |
8a5e3e08 ILT |
475 | 8 * 1024, // common_pagesize (overridable by -z common-page-size) |
476 | elfcpp::SHN_UNDEF, // small_common_shndx | |
477 | elfcpp::SHN_UNDEF, // large_common_shndx | |
478 | 0, // small_common_section_flags | |
05a352e6 DK |
479 | 0, // large_common_section_flags |
480 | NULL, // attributes_section | |
481 | NULL // attributes_vendor | |
f5314dd5 DM |
482 | }; |
483 | ||
484 | template<> | |
485 | Target::Target_info Target_sparc<64, true>::sparc_info = | |
486 | { | |
487 | 64, // size | |
488 | true, // is_big_endian | |
489 | elfcpp::EM_SPARCV9, // machine_code | |
490 | false, // has_make_symbol | |
491 | false, // has_resolve | |
492 | false, // has_code_fill | |
493 | true, // is_default_stack_executable | |
b3ce541e | 494 | false, // can_icf_inline_merge_sections |
f5314dd5 DM |
495 | '\0', // wrap_char |
496 | "/usr/lib/sparcv9/ld.so.1", // dynamic_linker | |
497 | 0x100000, // default_text_segment_address | |
498 | 64 * 1024, // abi_pagesize (overridable by -z max-page-size) | |
8a5e3e08 ILT |
499 | 8 * 1024, // common_pagesize (overridable by -z common-page-size) |
500 | elfcpp::SHN_UNDEF, // small_common_shndx | |
501 | elfcpp::SHN_UNDEF, // large_common_shndx | |
502 | 0, // small_common_section_flags | |
05a352e6 DK |
503 | 0, // large_common_section_flags |
504 | NULL, // attributes_section | |
505 | NULL // attributes_vendor | |
f5314dd5 DM |
506 | }; |
507 | ||
508 | // We have to take care here, even when operating in little-endian | |
509 | // mode, sparc instructions are still big endian. | |
510 | template<int size, bool big_endian> | |
511 | class Sparc_relocate_functions | |
512 | { | |
513 | private: | |
514 | // Do a simple relocation with the addend in the relocation. | |
515 | template<int valsize> | |
516 | static inline void | |
517 | rela(unsigned char* view, | |
518 | unsigned int right_shift, | |
519 | typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask, | |
2ea97941 | 520 | typename elfcpp::Swap<size, big_endian>::Valtype value, |
f5314dd5 DM |
521 | typename elfcpp::Swap<size, big_endian>::Valtype addend) |
522 | { | |
523 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; | |
524 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
525 | Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv); | |
2ea97941 | 526 | Valtype reloc = ((value + addend) >> right_shift); |
f5314dd5 DM |
527 | |
528 | val &= ~dst_mask; | |
529 | reloc &= dst_mask; | |
530 | ||
531 | elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc); | |
532 | } | |
533 | ||
534 | // Do a simple relocation using a symbol value with the addend in | |
535 | // the relocation. | |
536 | template<int valsize> | |
537 | static inline void | |
538 | rela(unsigned char* view, | |
539 | unsigned int right_shift, | |
540 | typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask, | |
6fa2a40b | 541 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
542 | const Symbol_value<size>* psymval, |
543 | typename elfcpp::Swap<valsize, big_endian>::Valtype addend) | |
544 | { | |
545 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; | |
546 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
547 | Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv); | |
548 | Valtype reloc = (psymval->value(object, addend) >> right_shift); | |
549 | ||
550 | val &= ~dst_mask; | |
551 | reloc &= dst_mask; | |
552 | ||
553 | elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc); | |
554 | } | |
555 | ||
556 | // Do a simple relocation using a symbol value with the addend in | |
557 | // the relocation, unaligned. | |
558 | template<int valsize> | |
559 | static inline void | |
560 | rela_ua(unsigned char* view, | |
561 | unsigned int right_shift, elfcpp::Elf_Xword dst_mask, | |
6fa2a40b | 562 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
563 | const Symbol_value<size>* psymval, |
564 | typename elfcpp::Swap<size, big_endian>::Valtype addend) | |
565 | { | |
566 | typedef typename elfcpp::Swap_unaligned<valsize, | |
567 | big_endian>::Valtype Valtype; | |
568 | unsigned char* wv = view; | |
569 | Valtype val = elfcpp::Swap_unaligned<valsize, big_endian>::readval(wv); | |
570 | Valtype reloc = (psymval->value(object, addend) >> right_shift); | |
571 | ||
572 | val &= ~dst_mask; | |
573 | reloc &= dst_mask; | |
574 | ||
575 | elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, val | reloc); | |
576 | } | |
577 | ||
578 | // Do a simple PC relative relocation with a Symbol_value with the | |
579 | // addend in the relocation. | |
580 | template<int valsize> | |
581 | static inline void | |
582 | pcrela(unsigned char* view, | |
583 | unsigned int right_shift, | |
584 | typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask, | |
6fa2a40b | 585 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
586 | const Symbol_value<size>* psymval, |
587 | typename elfcpp::Swap<size, big_endian>::Valtype addend, | |
588 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
589 | { | |
590 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; | |
591 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
592 | Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv); | |
593 | Valtype reloc = ((psymval->value(object, addend) - address) | |
594 | >> right_shift); | |
595 | ||
596 | val &= ~dst_mask; | |
597 | reloc &= dst_mask; | |
598 | ||
599 | elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc); | |
600 | } | |
601 | ||
602 | template<int valsize> | |
603 | static inline void | |
604 | pcrela_unaligned(unsigned char* view, | |
6fa2a40b | 605 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
606 | const Symbol_value<size>* psymval, |
607 | typename elfcpp::Swap<size, big_endian>::Valtype addend, | |
608 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
609 | { | |
610 | typedef typename elfcpp::Swap_unaligned<valsize, | |
611 | big_endian>::Valtype Valtype; | |
612 | unsigned char* wv = view; | |
613 | Valtype reloc = (psymval->value(object, addend) - address); | |
614 | ||
615 | elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, reloc); | |
616 | } | |
617 | ||
618 | typedef Sparc_relocate_functions<size, big_endian> This; | |
619 | typedef Sparc_relocate_functions<size, true> This_insn; | |
620 | ||
621 | public: | |
622 | // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2 | |
623 | static inline void | |
624 | wdisp30(unsigned char* view, | |
6fa2a40b | 625 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
626 | const Symbol_value<size>* psymval, |
627 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
628 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
629 | { | |
630 | This_insn::template pcrela<32>(view, 2, 0x3fffffff, object, | |
631 | psymval, addend, address); | |
632 | } | |
633 | ||
634 | // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2 | |
635 | static inline void | |
636 | wdisp22(unsigned char* view, | |
6fa2a40b | 637 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
638 | const Symbol_value<size>* psymval, |
639 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
640 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
641 | { | |
642 | This_insn::template pcrela<32>(view, 2, 0x003fffff, object, | |
643 | psymval, addend, address); | |
644 | } | |
645 | ||
646 | // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2 | |
647 | static inline void | |
648 | wdisp19(unsigned char* view, | |
6fa2a40b | 649 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
650 | const Symbol_value<size>* psymval, |
651 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
652 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
653 | { | |
654 | This_insn::template pcrela<32>(view, 2, 0x0007ffff, object, | |
655 | psymval, addend, address); | |
656 | } | |
657 | ||
658 | // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2 | |
659 | static inline void | |
660 | wdisp16(unsigned char* view, | |
6fa2a40b | 661 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
662 | const Symbol_value<size>* psymval, |
663 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
664 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
665 | { | |
666 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
667 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
668 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
669 | Valtype reloc = ((psymval->value(object, addend) - address) | |
670 | >> 2); | |
671 | ||
672 | // The relocation value is split between the low 14 bits, | |
673 | // and bits 20-21. | |
674 | val &= ~((0x3 << 20) | 0x3fff); | |
675 | reloc = (((reloc & 0xc000) << (20 - 14)) | |
676 | | (reloc & 0x3ffff)); | |
677 | ||
678 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
679 | } | |
680 | ||
2615994e DM |
681 | // R_SPARC_WDISP10: (Symbol + Addend - Address) >> 2 |
682 | static inline void | |
683 | wdisp10(unsigned char* view, | |
684 | const Sized_relobj_file<size, big_endian>* object, | |
685 | const Symbol_value<size>* psymval, | |
686 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
687 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
688 | { | |
689 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
690 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
691 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
692 | Valtype reloc = ((psymval->value(object, addend) - address) | |
693 | >> 2); | |
694 | ||
695 | // The relocation value is split between the low bits 5-12, | |
696 | // and high bits 19-20. | |
697 | val &= ~((0x3 << 19) | (0xff << 5)); | |
698 | reloc = (((reloc & 0x300) << (19 - 8)) | |
699 | | ((reloc & 0xff) << (5 - 0))); | |
700 | ||
701 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
702 | } | |
703 | ||
f5314dd5 DM |
704 | // R_SPARC_PC22: (Symbol + Addend - Address) >> 10 |
705 | static inline void | |
706 | pc22(unsigned char* view, | |
6fa2a40b | 707 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
708 | const Symbol_value<size>* psymval, |
709 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
710 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
711 | { | |
712 | This_insn::template pcrela<32>(view, 10, 0x003fffff, object, | |
713 | psymval, addend, address); | |
714 | } | |
715 | ||
716 | // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff | |
717 | static inline void | |
718 | pc10(unsigned char* view, | |
6fa2a40b | 719 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
720 | const Symbol_value<size>* psymval, |
721 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
722 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
723 | { | |
724 | This_insn::template pcrela<32>(view, 0, 0x000003ff, object, | |
725 | psymval, addend, address); | |
726 | } | |
727 | ||
728 | // R_SPARC_HI22: (Symbol + Addend) >> 10 | |
729 | static inline void | |
730 | hi22(unsigned char* view, | |
2ea97941 | 731 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
f5314dd5 DM |
732 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
733 | { | |
2ea97941 | 734 | This_insn::template rela<32>(view, 10, 0x003fffff, value, addend); |
f5314dd5 DM |
735 | } |
736 | ||
737 | // R_SPARC_HI22: (Symbol + Addend) >> 10 | |
738 | static inline void | |
739 | hi22(unsigned char* view, | |
6fa2a40b | 740 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
741 | const Symbol_value<size>* psymval, |
742 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
743 | { | |
744 | This_insn::template rela<32>(view, 10, 0x003fffff, object, psymval, addend); | |
745 | } | |
746 | ||
747 | // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10 | |
748 | static inline void | |
749 | pcplt22(unsigned char* view, | |
6fa2a40b | 750 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
751 | const Symbol_value<size>* psymval, |
752 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
753 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
754 | { | |
755 | This_insn::template pcrela<32>(view, 10, 0x003fffff, object, | |
756 | psymval, addend, address); | |
757 | } | |
758 | ||
759 | // R_SPARC_LO10: (Symbol + Addend) & 0x3ff | |
760 | static inline void | |
761 | lo10(unsigned char* view, | |
2ea97941 | 762 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
f5314dd5 DM |
763 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
764 | { | |
2ea97941 | 765 | This_insn::template rela<32>(view, 0, 0x000003ff, value, addend); |
f5314dd5 DM |
766 | } |
767 | ||
768 | // R_SPARC_LO10: (Symbol + Addend) & 0x3ff | |
769 | static inline void | |
770 | lo10(unsigned char* view, | |
6fa2a40b | 771 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
772 | const Symbol_value<size>* psymval, |
773 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
774 | { | |
775 | This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend); | |
776 | } | |
777 | ||
778 | // R_SPARC_LO10: (Symbol + Addend) & 0x3ff | |
779 | static inline void | |
780 | lo10(unsigned char* view, | |
6fa2a40b | 781 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
782 | const Symbol_value<size>* psymval, |
783 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
784 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
785 | { | |
786 | This_insn::template pcrela<32>(view, 0, 0x000003ff, object, | |
787 | psymval, addend, address); | |
788 | } | |
789 | ||
790 | // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2 | |
791 | static inline void | |
792 | olo10(unsigned char* view, | |
6fa2a40b | 793 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
794 | const Symbol_value<size>* psymval, |
795 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
796 | typename elfcpp::Elf_types<size>::Elf_Addr addend2) | |
797 | { | |
798 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
799 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
800 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
801 | Valtype reloc = psymval->value(object, addend); | |
802 | ||
803 | val &= ~0x1fff; | |
804 | reloc &= 0x3ff; | |
805 | reloc += addend2; | |
806 | reloc &= 0x1fff; | |
807 | ||
808 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
809 | } | |
810 | ||
811 | // R_SPARC_22: (Symbol + Addend) | |
812 | static inline void | |
813 | rela32_22(unsigned char* view, | |
6fa2a40b | 814 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
815 | const Symbol_value<size>* psymval, |
816 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
817 | { | |
818 | This_insn::template rela<32>(view, 0, 0x003fffff, object, psymval, addend); | |
819 | } | |
820 | ||
821 | // R_SPARC_13: (Symbol + Addend) | |
822 | static inline void | |
823 | rela32_13(unsigned char* view, | |
2ea97941 | 824 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
f5314dd5 DM |
825 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
826 | { | |
2ea97941 | 827 | This_insn::template rela<32>(view, 0, 0x00001fff, value, addend); |
f5314dd5 DM |
828 | } |
829 | ||
830 | // R_SPARC_13: (Symbol + Addend) | |
831 | static inline void | |
832 | rela32_13(unsigned char* view, | |
6fa2a40b | 833 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
834 | const Symbol_value<size>* psymval, |
835 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
836 | { | |
837 | This_insn::template rela<32>(view, 0, 0x00001fff, object, psymval, addend); | |
838 | } | |
839 | ||
840 | // R_SPARC_UA16: (Symbol + Addend) | |
841 | static inline void | |
842 | ua16(unsigned char* view, | |
6fa2a40b | 843 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
844 | const Symbol_value<size>* psymval, |
845 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
846 | { | |
847 | This::template rela_ua<16>(view, 0, 0xffff, object, psymval, addend); | |
848 | } | |
849 | ||
850 | // R_SPARC_UA32: (Symbol + Addend) | |
851 | static inline void | |
852 | ua32(unsigned char* view, | |
6fa2a40b | 853 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
854 | const Symbol_value<size>* psymval, |
855 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
856 | { | |
857 | This::template rela_ua<32>(view, 0, 0xffffffff, object, psymval, addend); | |
858 | } | |
859 | ||
860 | // R_SPARC_UA64: (Symbol + Addend) | |
861 | static inline void | |
862 | ua64(unsigned char* view, | |
6fa2a40b | 863 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
864 | const Symbol_value<size>* psymval, |
865 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
866 | { | |
867 | This::template rela_ua<64>(view, 0, ~(elfcpp::Elf_Xword) 0, | |
868 | object, psymval, addend); | |
869 | } | |
870 | ||
871 | // R_SPARC_DISP8: (Symbol + Addend - Address) | |
872 | static inline void | |
873 | disp8(unsigned char* view, | |
6fa2a40b | 874 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
875 | const Symbol_value<size>* psymval, |
876 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
877 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
878 | { | |
879 | This::template pcrela_unaligned<8>(view, object, psymval, | |
880 | addend, address); | |
881 | } | |
882 | ||
883 | // R_SPARC_DISP16: (Symbol + Addend - Address) | |
884 | static inline void | |
885 | disp16(unsigned char* view, | |
6fa2a40b | 886 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
887 | const Symbol_value<size>* psymval, |
888 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
889 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
890 | { | |
891 | This::template pcrela_unaligned<16>(view, object, psymval, | |
892 | addend, address); | |
893 | } | |
894 | ||
895 | // R_SPARC_DISP32: (Symbol + Addend - Address) | |
896 | static inline void | |
897 | disp32(unsigned char* view, | |
6fa2a40b | 898 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
899 | const Symbol_value<size>* psymval, |
900 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
901 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
902 | { | |
903 | This::template pcrela_unaligned<32>(view, object, psymval, | |
904 | addend, address); | |
905 | } | |
906 | ||
907 | // R_SPARC_DISP64: (Symbol + Addend - Address) | |
908 | static inline void | |
909 | disp64(unsigned char* view, | |
6fa2a40b | 910 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
911 | const Symbol_value<size>* psymval, |
912 | elfcpp::Elf_Xword addend, | |
913 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
914 | { | |
915 | This::template pcrela_unaligned<64>(view, object, psymval, | |
916 | addend, address); | |
917 | } | |
918 | ||
2615994e DM |
919 | // R_SPARC_H34: (Symbol + Addend) >> 12 |
920 | static inline void | |
921 | h34(unsigned char* view, | |
922 | const Sized_relobj_file<size, big_endian>* object, | |
923 | const Symbol_value<size>* psymval, | |
924 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
925 | { | |
926 | This_insn::template rela<32>(view, 12, 0x003fffff, object, psymval, addend); | |
927 | } | |
928 | ||
f5314dd5 DM |
929 | // R_SPARC_H44: (Symbol + Addend) >> 22 |
930 | static inline void | |
931 | h44(unsigned char* view, | |
6fa2a40b | 932 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
933 | const Symbol_value<size>* psymval, |
934 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
935 | { | |
936 | This_insn::template rela<32>(view, 22, 0x003fffff, object, psymval, addend); | |
937 | } | |
938 | ||
939 | // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff | |
940 | static inline void | |
941 | m44(unsigned char* view, | |
6fa2a40b | 942 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
943 | const Symbol_value<size>* psymval, |
944 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
945 | { | |
946 | This_insn::template rela<32>(view, 12, 0x000003ff, object, psymval, addend); | |
947 | } | |
948 | ||
949 | // R_SPARC_L44: (Symbol + Addend) & 0xfff | |
950 | static inline void | |
951 | l44(unsigned char* view, | |
6fa2a40b | 952 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
953 | const Symbol_value<size>* psymval, |
954 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
955 | { | |
956 | This_insn::template rela<32>(view, 0, 0x00000fff, object, psymval, addend); | |
957 | } | |
958 | ||
959 | // R_SPARC_HH22: (Symbol + Addend) >> 42 | |
960 | static inline void | |
961 | hh22(unsigned char* view, | |
6fa2a40b | 962 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
963 | const Symbol_value<size>* psymval, |
964 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
965 | { | |
966 | This_insn::template rela<32>(view, 42, 0x003fffff, object, psymval, addend); | |
967 | } | |
968 | ||
969 | // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42 | |
970 | static inline void | |
971 | pc_hh22(unsigned char* view, | |
6fa2a40b | 972 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
973 | const Symbol_value<size>* psymval, |
974 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
975 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
976 | { | |
977 | This_insn::template pcrela<32>(view, 42, 0x003fffff, object, | |
978 | psymval, addend, address); | |
979 | } | |
980 | ||
981 | // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff | |
982 | static inline void | |
983 | hm10(unsigned char* view, | |
6fa2a40b | 984 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
985 | const Symbol_value<size>* psymval, |
986 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
987 | { | |
988 | This_insn::template rela<32>(view, 32, 0x000003ff, object, psymval, addend); | |
989 | } | |
990 | ||
991 | // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff | |
992 | static inline void | |
993 | pc_hm10(unsigned char* view, | |
6fa2a40b | 994 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
995 | const Symbol_value<size>* psymval, |
996 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
997 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
998 | { | |
999 | This_insn::template pcrela<32>(view, 32, 0x000003ff, object, | |
1000 | psymval, addend, address); | |
1001 | } | |
1002 | ||
1003 | // R_SPARC_11: (Symbol + Addend) | |
1004 | static inline void | |
1005 | rela32_11(unsigned char* view, | |
6fa2a40b | 1006 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
1007 | const Symbol_value<size>* psymval, |
1008 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
1009 | { | |
1010 | This_insn::template rela<32>(view, 0, 0x000007ff, object, psymval, addend); | |
1011 | } | |
1012 | ||
1013 | // R_SPARC_10: (Symbol + Addend) | |
1014 | static inline void | |
1015 | rela32_10(unsigned char* view, | |
6fa2a40b | 1016 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
1017 | const Symbol_value<size>* psymval, |
1018 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
1019 | { | |
1020 | This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend); | |
1021 | } | |
1022 | ||
1023 | // R_SPARC_7: (Symbol + Addend) | |
1024 | static inline void | |
1025 | rela32_7(unsigned char* view, | |
6fa2a40b | 1026 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
1027 | const Symbol_value<size>* psymval, |
1028 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
1029 | { | |
1030 | This_insn::template rela<32>(view, 0, 0x0000007f, object, psymval, addend); | |
1031 | } | |
1032 | ||
1033 | // R_SPARC_6: (Symbol + Addend) | |
1034 | static inline void | |
1035 | rela32_6(unsigned char* view, | |
6fa2a40b | 1036 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
1037 | const Symbol_value<size>* psymval, |
1038 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
1039 | { | |
1040 | This_insn::template rela<32>(view, 0, 0x0000003f, object, psymval, addend); | |
1041 | } | |
1042 | ||
1043 | // R_SPARC_5: (Symbol + Addend) | |
1044 | static inline void | |
1045 | rela32_5(unsigned char* view, | |
6fa2a40b | 1046 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
1047 | const Symbol_value<size>* psymval, |
1048 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
1049 | { | |
1050 | This_insn::template rela<32>(view, 0, 0x0000001f, object, psymval, addend); | |
1051 | } | |
1052 | ||
1053 | // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10 | |
1054 | static inline void | |
1055 | ldo_hix22(unsigned char* view, | |
2ea97941 | 1056 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
f5314dd5 DM |
1057 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
1058 | { | |
2ea97941 | 1059 | This_insn::hi22(view, value, addend); |
f5314dd5 DM |
1060 | } |
1061 | ||
1062 | // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff | |
1063 | static inline void | |
1064 | ldo_lox10(unsigned char* view, | |
2ea97941 | 1065 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
f5314dd5 DM |
1066 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
1067 | { | |
1068 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
1069 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
1070 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
2ea97941 | 1071 | Valtype reloc = (value + addend); |
f5314dd5 DM |
1072 | |
1073 | val &= ~0x1fff; | |
1074 | reloc &= 0x3ff; | |
1075 | ||
1076 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
1077 | } | |
1078 | ||
1079 | // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10 | |
1080 | static inline void | |
1081 | hix22(unsigned char* view, | |
2ea97941 | 1082 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
f5314dd5 DM |
1083 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
1084 | { | |
1085 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
1086 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
1087 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
2ea97941 | 1088 | Valtype reloc = (value + addend); |
f5314dd5 DM |
1089 | |
1090 | val &= ~0x3fffff; | |
1091 | ||
1092 | reloc ^= ~(Valtype)0; | |
1093 | reloc >>= 10; | |
1094 | ||
1095 | reloc &= 0x3fffff; | |
1096 | ||
1097 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
1098 | } | |
1099 | ||
2a1079e8 DM |
1100 | // R_SPARC_GOTDATA_OP_HIX22: @gdopoff(Symbol + Addend) >> 10 |
1101 | static inline void | |
1102 | gdop_hix22(unsigned char* view, | |
1103 | typename elfcpp::Elf_types<size>::Elf_Addr value, | |
1104 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
1105 | { | |
1106 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
1107 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
1108 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
1109 | int32_t reloc = static_cast<int32_t>(value + addend); | |
1110 | ||
1111 | val &= ~0x3fffff; | |
1112 | ||
1113 | if (reloc < 0) | |
1114 | reloc ^= ~static_cast<int32_t>(0); | |
1115 | reloc >>= 10; | |
1116 | ||
1117 | reloc &= 0x3fffff; | |
1118 | ||
1119 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
1120 | } | |
1121 | ||
f5314dd5 DM |
1122 | // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10 |
1123 | static inline void | |
1124 | hix22(unsigned char* view, | |
6fa2a40b | 1125 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
1126 | const Symbol_value<size>* psymval, |
1127 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
1128 | { | |
1129 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
1130 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
1131 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
1132 | Valtype reloc = psymval->value(object, addend); | |
1133 | ||
1134 | val &= ~0x3fffff; | |
1135 | ||
1136 | reloc ^= ~(Valtype)0; | |
1137 | reloc >>= 10; | |
1138 | ||
1139 | reloc &= 0x3fffff; | |
1140 | ||
1141 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
1142 | } | |
1143 | ||
1144 | ||
1145 | // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00 | |
1146 | static inline void | |
1147 | lox10(unsigned char* view, | |
2ea97941 | 1148 | typename elfcpp::Elf_types<size>::Elf_Addr value, |
f5314dd5 DM |
1149 | typename elfcpp::Elf_types<size>::Elf_Addr addend) |
1150 | { | |
1151 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
1152 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
1153 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
2ea97941 | 1154 | Valtype reloc = (value + addend); |
f5314dd5 DM |
1155 | |
1156 | val &= ~0x1fff; | |
1157 | reloc &= 0x3ff; | |
1158 | reloc |= 0x1c00; | |
1159 | ||
1160 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
1161 | } | |
1162 | ||
2a1079e8 DM |
1163 | // R_SPARC_GOTDATA_OP_LOX10: (@gdopoff(Symbol + Addend) & 0x3ff) | 0x1c00 |
1164 | static inline void | |
1165 | gdop_lox10(unsigned char* view, | |
1166 | typename elfcpp::Elf_types<size>::Elf_Addr value, | |
1167 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
1168 | { | |
1169 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
1170 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
1171 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
1172 | int32_t reloc = static_cast<int32_t>(value + addend); | |
1173 | ||
1174 | if (reloc < 0) | |
1175 | reloc = (reloc & 0x3ff) | 0x1c00; | |
1176 | else | |
1177 | reloc = (reloc & 0x3ff); | |
1178 | ||
1179 | val &= ~0x1fff; | |
1180 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
1181 | } | |
1182 | ||
f5314dd5 DM |
1183 | // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00 |
1184 | static inline void | |
1185 | lox10(unsigned char* view, | |
6fa2a40b | 1186 | const Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
1187 | const Symbol_value<size>* psymval, |
1188 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
1189 | { | |
1190 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
1191 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
1192 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
1193 | Valtype reloc = psymval->value(object, addend); | |
1194 | ||
1195 | val &= ~0x1fff; | |
1196 | reloc &= 0x3ff; | |
1197 | reloc |= 0x1c00; | |
1198 | ||
1199 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
1200 | } | |
1201 | }; | |
1202 | ||
1203 | // Get the GOT section, creating it if necessary. | |
1204 | ||
1205 | template<int size, bool big_endian> | |
1206 | Output_data_got<size, big_endian>* | |
1207 | Target_sparc<size, big_endian>::got_section(Symbol_table* symtab, | |
1208 | Layout* layout) | |
1209 | { | |
1210 | if (this->got_ == NULL) | |
1211 | { | |
1212 | gold_assert(symtab != NULL && layout != NULL); | |
1213 | ||
1214 | this->got_ = new Output_data_got<size, big_endian>(); | |
1215 | ||
82742395 ILT |
1216 | layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS, |
1217 | (elfcpp::SHF_ALLOC | |
1218 | | elfcpp::SHF_WRITE), | |
22f0da72 | 1219 | this->got_, ORDER_RELRO, true); |
f5314dd5 DM |
1220 | |
1221 | // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section. | |
1222 | symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL, | |
99fff23b | 1223 | Symbol_table::PREDEFINED, |
f5314dd5 DM |
1224 | this->got_, |
1225 | 0, 0, elfcpp::STT_OBJECT, | |
1226 | elfcpp::STB_LOCAL, | |
1227 | elfcpp::STV_HIDDEN, 0, | |
1228 | false, false); | |
1229 | } | |
1230 | ||
1231 | return this->got_; | |
1232 | } | |
1233 | ||
1234 | // Get the dynamic reloc section, creating it if necessary. | |
1235 | ||
1236 | template<int size, bool big_endian> | |
1237 | typename Target_sparc<size, big_endian>::Reloc_section* | |
1238 | Target_sparc<size, big_endian>::rela_dyn_section(Layout* layout) | |
1239 | { | |
1240 | if (this->rela_dyn_ == NULL) | |
1241 | { | |
1242 | gold_assert(layout != NULL); | |
d98bc257 | 1243 | this->rela_dyn_ = new Reloc_section(parameters->options().combreloc()); |
f5314dd5 | 1244 | layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA, |
22f0da72 ILT |
1245 | elfcpp::SHF_ALLOC, this->rela_dyn_, |
1246 | ORDER_DYNAMIC_RELOCS, false); | |
f5314dd5 DM |
1247 | } |
1248 | return this->rela_dyn_; | |
1249 | } | |
1250 | ||
8c2bf391 DM |
1251 | // Get the section to use for IFUNC relocs, creating it if |
1252 | // necessary. These go in .rela.dyn, but only after all other dynamic | |
1253 | // relocations. They need to follow the other dynamic relocations so | |
1254 | // that they can refer to global variables initialized by those | |
1255 | // relocs. | |
1256 | ||
1257 | template<int size, bool big_endian> | |
1258 | typename Target_sparc<size, big_endian>::Reloc_section* | |
1259 | Target_sparc<size, big_endian>::rela_ifunc_section(Layout* layout) | |
1260 | { | |
1261 | if (this->rela_ifunc_ == NULL) | |
1262 | { | |
1263 | // Make sure we have already created the dynamic reloc section. | |
1264 | this->rela_dyn_section(layout); | |
1265 | this->rela_ifunc_ = new Reloc_section(false); | |
1266 | layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA, | |
1267 | elfcpp::SHF_ALLOC, this->rela_ifunc_, | |
1268 | ORDER_DYNAMIC_RELOCS, false); | |
1269 | gold_assert(this->rela_dyn_->output_section() | |
1270 | == this->rela_ifunc_->output_section()); | |
1271 | } | |
1272 | return this->rela_ifunc_; | |
1273 | } | |
1274 | ||
f5314dd5 DM |
1275 | // A class to handle the PLT data. |
1276 | ||
1277 | template<int size, bool big_endian> | |
1278 | class Output_data_plt_sparc : public Output_section_data | |
1279 | { | |
1280 | public: | |
1281 | typedef Output_data_reloc<elfcpp::SHT_RELA, true, | |
1282 | size, big_endian> Reloc_section; | |
1283 | ||
1284 | Output_data_plt_sparc(Layout*); | |
1285 | ||
1286 | // Add an entry to the PLT. | |
8c2bf391 DM |
1287 | void add_entry(Symbol_table* symtab, Layout* layout, Symbol* gsym); |
1288 | ||
1289 | // Add an entry to the PLT for a local STT_GNU_IFUNC symbol. | |
1290 | unsigned int | |
1291 | add_local_ifunc_entry(Symbol_table*, Layout*, | |
1292 | Sized_relobj_file<size, big_endian>* relobj, | |
1293 | unsigned int local_sym_index); | |
f5314dd5 DM |
1294 | |
1295 | // Return the .rela.plt section data. | |
1296 | const Reloc_section* rel_plt() const | |
1297 | { | |
1298 | return this->rel_; | |
1299 | } | |
1300 | ||
8c2bf391 DM |
1301 | // Return where the IFUNC relocations should go. |
1302 | Reloc_section* | |
1303 | rela_ifunc(Symbol_table*, Layout*); | |
1304 | ||
1305 | void | |
1306 | emit_pending_ifunc_relocs(); | |
1307 | ||
1308 | // Return whether we created a section for IFUNC relocations. | |
1309 | bool | |
1310 | has_ifunc_section() const | |
1311 | { return this->ifunc_rel_ != NULL; } | |
1312 | ||
0e70b911 CC |
1313 | // Return the number of PLT entries. |
1314 | unsigned int | |
1315 | entry_count() const | |
8c2bf391 | 1316 | { return this->count_ + this->ifunc_count_; } |
0e70b911 CC |
1317 | |
1318 | // Return the offset of the first non-reserved PLT entry. | |
1319 | static unsigned int | |
1320 | first_plt_entry_offset() | |
1321 | { return 4 * base_plt_entry_size; } | |
1322 | ||
1323 | // Return the size of a PLT entry. | |
1324 | static unsigned int | |
1325 | get_plt_entry_size() | |
1326 | { return base_plt_entry_size; } | |
1327 | ||
8c2bf391 DM |
1328 | // Return the PLT address to use for a global symbol. |
1329 | uint64_t | |
1330 | address_for_global(const Symbol*); | |
1331 | ||
1332 | // Return the PLT address to use for a local symbol. | |
1333 | uint64_t | |
1334 | address_for_local(const Relobj*, unsigned int symndx); | |
1335 | ||
f5314dd5 DM |
1336 | protected: |
1337 | void do_adjust_output_section(Output_section* os); | |
1338 | ||
7d9e3d98 ILT |
1339 | // Write to a map file. |
1340 | void | |
1341 | do_print_to_mapfile(Mapfile* mapfile) const | |
1342 | { mapfile->print_output_data(this, _("** PLT")); } | |
1343 | ||
f5314dd5 DM |
1344 | private: |
1345 | // The size of an entry in the PLT. | |
1346 | static const int base_plt_entry_size = (size == 32 ? 12 : 32); | |
1347 | ||
1348 | static const unsigned int plt_entries_per_block = 160; | |
1349 | static const unsigned int plt_insn_chunk_size = 24; | |
1350 | static const unsigned int plt_pointer_chunk_size = 8; | |
1351 | static const unsigned int plt_block_size = | |
1352 | (plt_entries_per_block | |
1353 | * (plt_insn_chunk_size + plt_pointer_chunk_size)); | |
1354 | ||
8c2bf391 DM |
1355 | section_offset_type |
1356 | plt_index_to_offset(unsigned int index) | |
f5314dd5 | 1357 | { |
8c2bf391 | 1358 | section_offset_type offset; |
f5314dd5 | 1359 | |
8c2bf391 DM |
1360 | if (size == 32 || index < 32768) |
1361 | offset = index * base_plt_entry_size; | |
f5314dd5 DM |
1362 | else |
1363 | { | |
8c2bf391 | 1364 | unsigned int ext_index = index - 32768; |
f5314dd5 | 1365 | |
8c2bf391 DM |
1366 | offset = (32768 * base_plt_entry_size) |
1367 | + ((ext_index / plt_entries_per_block) | |
1368 | * plt_block_size) | |
1369 | + ((ext_index % plt_entries_per_block) | |
1370 | * plt_insn_chunk_size); | |
f5314dd5 | 1371 | } |
8c2bf391 DM |
1372 | return offset; |
1373 | } | |
1374 | ||
1375 | // Set the final size. | |
1376 | void | |
1377 | set_final_data_size() | |
1378 | { | |
1379 | unsigned int full_count = this->entry_count() + 4; | |
1380 | unsigned int extra = (size == 32 ? 4 : 0); | |
1381 | section_offset_type sz = plt_index_to_offset(full_count) + extra; | |
1382 | ||
1383 | return this->set_data_size(sz); | |
f5314dd5 DM |
1384 | } |
1385 | ||
1386 | // Write out the PLT data. | |
1387 | void | |
1388 | do_write(Output_file*); | |
1389 | ||
8c2bf391 DM |
1390 | struct Global_ifunc |
1391 | { | |
1392 | Reloc_section* rel; | |
1393 | Symbol* gsym; | |
1394 | unsigned int plt_index; | |
1395 | }; | |
1396 | ||
1397 | struct Local_ifunc | |
1398 | { | |
1399 | Reloc_section* rel; | |
1400 | Sized_relobj_file<size, big_endian>* object; | |
1401 | unsigned int local_sym_index; | |
1402 | unsigned int plt_index; | |
1403 | }; | |
1404 | ||
f5314dd5 DM |
1405 | // The reloc section. |
1406 | Reloc_section* rel_; | |
8c2bf391 DM |
1407 | // The IFUNC relocations, if necessary. These must follow the |
1408 | // regular relocations. | |
1409 | Reloc_section* ifunc_rel_; | |
f5314dd5 DM |
1410 | // The number of PLT entries. |
1411 | unsigned int count_; | |
8c2bf391 DM |
1412 | // The number of PLT entries for IFUNC symbols. |
1413 | unsigned int ifunc_count_; | |
1414 | // Global STT_GNU_IFUNC symbols. | |
1415 | std::vector<Global_ifunc> global_ifuncs_; | |
1416 | // Local STT_GNU_IFUNC symbols. | |
1417 | std::vector<Local_ifunc> local_ifuncs_; | |
f5314dd5 DM |
1418 | }; |
1419 | ||
4f2a9edd ILT |
1420 | // Define the constants as required by C++ standard. |
1421 | ||
1422 | template<int size, bool big_endian> | |
1423 | const int Output_data_plt_sparc<size, big_endian>::base_plt_entry_size; | |
1424 | ||
1425 | template<int size, bool big_endian> | |
1426 | const unsigned int | |
1427 | Output_data_plt_sparc<size, big_endian>::plt_entries_per_block; | |
1428 | ||
1429 | template<int size, bool big_endian> | |
1430 | const unsigned int Output_data_plt_sparc<size, big_endian>::plt_insn_chunk_size; | |
1431 | ||
1432 | template<int size, bool big_endian> | |
1433 | const unsigned int | |
1434 | Output_data_plt_sparc<size, big_endian>::plt_pointer_chunk_size; | |
1435 | ||
1436 | template<int size, bool big_endian> | |
1437 | const unsigned int Output_data_plt_sparc<size, big_endian>::plt_block_size; | |
1438 | ||
f5314dd5 DM |
1439 | // Create the PLT section. The ordinary .got section is an argument, |
1440 | // since we need to refer to the start. | |
1441 | ||
1442 | template<int size, bool big_endian> | |
1443 | Output_data_plt_sparc<size, big_endian>::Output_data_plt_sparc(Layout* layout) | |
8c2bf391 DM |
1444 | : Output_section_data(size == 32 ? 4 : 8), ifunc_rel_(NULL), |
1445 | count_(0), ifunc_count_(0), global_ifuncs_(), local_ifuncs_() | |
f5314dd5 | 1446 | { |
d98bc257 | 1447 | this->rel_ = new Reloc_section(false); |
f5314dd5 | 1448 | layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA, |
22f0da72 ILT |
1449 | elfcpp::SHF_ALLOC, this->rel_, |
1450 | ORDER_DYNAMIC_PLT_RELOCS, false); | |
f5314dd5 DM |
1451 | } |
1452 | ||
1453 | template<int size, bool big_endian> | |
1454 | void | |
1455 | Output_data_plt_sparc<size, big_endian>::do_adjust_output_section(Output_section* os) | |
1456 | { | |
1457 | os->set_entsize(0); | |
1458 | } | |
1459 | ||
1460 | // Add an entry to the PLT. | |
1461 | ||
1462 | template<int size, bool big_endian> | |
1463 | void | |
8c2bf391 DM |
1464 | Output_data_plt_sparc<size, big_endian>::add_entry(Symbol_table* symtab, |
1465 | Layout* layout, | |
1466 | Symbol* gsym) | |
f5314dd5 DM |
1467 | { |
1468 | gold_assert(!gsym->has_plt_offset()); | |
1469 | ||
f5314dd5 | 1470 | section_offset_type plt_offset; |
8c2bf391 | 1471 | unsigned int index; |
f5314dd5 | 1472 | |
8c2bf391 DM |
1473 | if (gsym->type() == elfcpp::STT_GNU_IFUNC |
1474 | && gsym->can_use_relative_reloc(false)) | |
1475 | { | |
1476 | index = this->ifunc_count_; | |
1477 | plt_offset = plt_index_to_offset(index); | |
1478 | gsym->set_plt_offset(plt_offset); | |
1479 | ++this->ifunc_count_; | |
1480 | Reloc_section* rel = this->rela_ifunc(symtab, layout); | |
1481 | ||
1482 | struct Global_ifunc gi; | |
1483 | gi.rel = rel; | |
1484 | gi.gsym = gsym; | |
1485 | gi.plt_index = index; | |
1486 | this->global_ifuncs_.push_back(gi); | |
1487 | } | |
f5314dd5 DM |
1488 | else |
1489 | { | |
8c2bf391 DM |
1490 | plt_offset = plt_index_to_offset(this->count_ + 4); |
1491 | gsym->set_plt_offset(plt_offset); | |
1492 | ++this->count_; | |
1493 | gsym->set_needs_dynsym_entry(); | |
1494 | this->rel_->add_global(gsym, elfcpp::R_SPARC_JMP_SLOT, this, | |
1495 | plt_offset, 0); | |
1496 | } | |
f5314dd5 | 1497 | |
8c2bf391 DM |
1498 | // Note that we don't need to save the symbol. The contents of the |
1499 | // PLT are independent of which symbols are used. The symbols only | |
1500 | // appear in the relocations. | |
1501 | } | |
1502 | ||
1503 | template<int size, bool big_endian> | |
1504 | unsigned int | |
1505 | Output_data_plt_sparc<size, big_endian>::add_local_ifunc_entry( | |
1506 | Symbol_table* symtab, | |
1507 | Layout* layout, | |
1508 | Sized_relobj_file<size, big_endian>* relobj, | |
1509 | unsigned int local_sym_index) | |
1510 | { | |
1511 | unsigned int index = this->ifunc_count_; | |
1512 | section_offset_type plt_offset; | |
1513 | ||
1514 | plt_offset = plt_index_to_offset(index); | |
1515 | ++this->ifunc_count_; | |
1516 | ||
1517 | Reloc_section* rel = this->rela_ifunc(symtab, layout); | |
1518 | ||
1519 | struct Local_ifunc li; | |
1520 | li.rel = rel; | |
1521 | li.object = relobj; | |
1522 | li.local_sym_index = local_sym_index; | |
1523 | li.plt_index = index; | |
1524 | this->local_ifuncs_.push_back(li); | |
1525 | ||
1526 | return plt_offset; | |
1527 | } | |
1528 | ||
1529 | // Emit any pending IFUNC plt relocations. | |
1530 | ||
1531 | template<int size, bool big_endian> | |
1532 | void | |
1533 | Output_data_plt_sparc<size, big_endian>::emit_pending_ifunc_relocs() | |
1534 | { | |
1535 | // Emit any pending IFUNC relocs. | |
1536 | for (typename std::vector<Global_ifunc>::const_iterator p = | |
1537 | this->global_ifuncs_.begin(); | |
1538 | p != this->global_ifuncs_.end(); | |
1539 | ++p) | |
1540 | { | |
1541 | section_offset_type plt_offset; | |
1542 | unsigned int index; | |
1543 | ||
1544 | index = this->count_ + p->plt_index + 4; | |
1545 | plt_offset = this->plt_index_to_offset(index); | |
1546 | p->rel->add_symbolless_global_addend(p->gsym, elfcpp::R_SPARC_JMP_IREL, | |
1547 | this, plt_offset, 0); | |
1548 | } | |
1549 | ||
1550 | for (typename std::vector<Local_ifunc>::const_iterator p = | |
1551 | this->local_ifuncs_.begin(); | |
1552 | p != this->local_ifuncs_.end(); | |
1553 | ++p) | |
1554 | { | |
1555 | section_offset_type plt_offset; | |
1556 | unsigned int index; | |
1557 | ||
1558 | index = this->count_ + p->plt_index + 4; | |
1559 | plt_offset = this->plt_index_to_offset(index); | |
1560 | p->rel->add_symbolless_local_addend(p->object, p->local_sym_index, | |
1561 | elfcpp::R_SPARC_JMP_IREL, | |
1562 | this, plt_offset, 0); | |
f5314dd5 | 1563 | } |
8c2bf391 | 1564 | } |
f5314dd5 | 1565 | |
8c2bf391 DM |
1566 | // Return where the IFUNC relocations should go in the PLT. These |
1567 | // follow the non-IFUNC relocations. | |
f5314dd5 | 1568 | |
8c2bf391 DM |
1569 | template<int size, bool big_endian> |
1570 | typename Output_data_plt_sparc<size, big_endian>::Reloc_section* | |
1571 | Output_data_plt_sparc<size, big_endian>::rela_ifunc( | |
1572 | Symbol_table* symtab, | |
1573 | Layout* layout) | |
1574 | { | |
1575 | if (this->ifunc_rel_ == NULL) | |
1576 | { | |
1577 | this->ifunc_rel_ = new Reloc_section(false); | |
1578 | layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA, | |
1579 | elfcpp::SHF_ALLOC, this->ifunc_rel_, | |
1580 | ORDER_DYNAMIC_PLT_RELOCS, false); | |
1581 | gold_assert(this->ifunc_rel_->output_section() | |
1582 | == this->rel_->output_section()); | |
1583 | ||
1584 | if (parameters->doing_static_link()) | |
1585 | { | |
1586 | // A statically linked executable will only have a .rel.plt | |
1587 | // section to hold R_SPARC_IRELATIVE and R_SPARC_JMP_IREL | |
1588 | // relocs for STT_GNU_IFUNC symbols. The library will use | |
1589 | // these symbols to locate the IRELATIVE and JMP_IREL relocs | |
1590 | // at program startup time. | |
1591 | symtab->define_in_output_data("__rela_iplt_start", NULL, | |
1592 | Symbol_table::PREDEFINED, | |
1593 | this->ifunc_rel_, 0, 0, | |
1594 | elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL, | |
1595 | elfcpp::STV_HIDDEN, 0, false, true); | |
1596 | symtab->define_in_output_data("__rela_iplt_end", NULL, | |
1597 | Symbol_table::PREDEFINED, | |
1598 | this->ifunc_rel_, 0, 0, | |
1599 | elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL, | |
1600 | elfcpp::STV_HIDDEN, 0, true, true); | |
1601 | } | |
1602 | } | |
1603 | return this->ifunc_rel_; | |
1604 | } | |
f5314dd5 | 1605 | |
8c2bf391 | 1606 | // Return the PLT address to use for a global symbol. |
f5314dd5 | 1607 | |
8c2bf391 DM |
1608 | template<int size, bool big_endian> |
1609 | uint64_t | |
1610 | Output_data_plt_sparc<size, big_endian>::address_for_global(const Symbol* gsym) | |
1611 | { | |
1612 | uint64_t offset = 0; | |
1613 | if (gsym->type() == elfcpp::STT_GNU_IFUNC | |
1614 | && gsym->can_use_relative_reloc(false)) | |
1615 | offset = plt_index_to_offset(this->count_ + 4); | |
1616 | return this->address() + offset; | |
1617 | } | |
1618 | ||
1619 | // Return the PLT address to use for a local symbol. These are always | |
1620 | // IRELATIVE relocs. | |
1621 | ||
1622 | template<int size, bool big_endian> | |
1623 | uint64_t | |
1624 | Output_data_plt_sparc<size, big_endian>::address_for_local( | |
1625 | const Relobj*, | |
1626 | unsigned int) | |
1627 | { | |
1628 | return this->address() + plt_index_to_offset(this->count_ + 4); | |
f5314dd5 DM |
1629 | } |
1630 | ||
1631 | static const unsigned int sparc_nop = 0x01000000; | |
1632 | static const unsigned int sparc_sethi_g1 = 0x03000000; | |
1633 | static const unsigned int sparc_branch_always = 0x30800000; | |
1634 | static const unsigned int sparc_branch_always_pt = 0x30680000; | |
1635 | static const unsigned int sparc_mov = 0x80100000; | |
1636 | static const unsigned int sparc_mov_g0_o0 = 0x90100000; | |
1637 | static const unsigned int sparc_mov_o7_g5 = 0x8a10000f; | |
1638 | static const unsigned int sparc_call_plus_8 = 0x40000002; | |
1639 | static const unsigned int sparc_ldx_o7_imm_g1 = 0xc25be000; | |
1640 | static const unsigned int sparc_jmpl_o7_g1_g1 = 0x83c3c001; | |
1641 | static const unsigned int sparc_mov_g5_o7 = 0x9e100005; | |
1642 | ||
1643 | // Write out the PLT. | |
1644 | ||
1645 | template<int size, bool big_endian> | |
1646 | void | |
1647 | Output_data_plt_sparc<size, big_endian>::do_write(Output_file* of) | |
1648 | { | |
2ea97941 | 1649 | const off_t offset = this->offset(); |
f5314dd5 DM |
1650 | const section_size_type oview_size = |
1651 | convert_to_section_size_type(this->data_size()); | |
2ea97941 | 1652 | unsigned char* const oview = of->get_output_view(offset, oview_size); |
f5314dd5 DM |
1653 | unsigned char* pov = oview; |
1654 | ||
1655 | memset(pov, 0, base_plt_entry_size * 4); | |
8c2bf391 | 1656 | pov += this->first_plt_entry_offset(); |
f5314dd5 DM |
1657 | |
1658 | unsigned int plt_offset = base_plt_entry_size * 4; | |
8c2bf391 | 1659 | const unsigned int count = this->entry_count(); |
f5314dd5 DM |
1660 | |
1661 | if (size == 64) | |
1662 | { | |
1663 | unsigned int limit; | |
1664 | ||
1665 | limit = (count > 32768 ? 32768 : count); | |
1666 | ||
1667 | for (unsigned int i = 0; i < limit; ++i) | |
1668 | { | |
1669 | elfcpp::Swap<32, true>::writeval(pov + 0x00, | |
1670 | sparc_sethi_g1 + plt_offset); | |
1671 | elfcpp::Swap<32, true>::writeval(pov + 0x04, | |
1672 | sparc_branch_always_pt + | |
1673 | (((base_plt_entry_size - | |
1674 | (plt_offset + 4)) >> 2) & | |
1675 | 0x7ffff)); | |
1676 | elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop); | |
1677 | elfcpp::Swap<32, true>::writeval(pov + 0x0c, sparc_nop); | |
1678 | elfcpp::Swap<32, true>::writeval(pov + 0x10, sparc_nop); | |
1679 | elfcpp::Swap<32, true>::writeval(pov + 0x14, sparc_nop); | |
1680 | elfcpp::Swap<32, true>::writeval(pov + 0x18, sparc_nop); | |
1681 | elfcpp::Swap<32, true>::writeval(pov + 0x1c, sparc_nop); | |
1682 | ||
1683 | pov += base_plt_entry_size; | |
1684 | plt_offset += base_plt_entry_size; | |
1685 | } | |
1686 | ||
1687 | if (count > 32768) | |
1688 | { | |
1689 | unsigned int ext_cnt = count - 32768; | |
1690 | unsigned int blks = ext_cnt / plt_entries_per_block; | |
1691 | ||
1692 | for (unsigned int i = 0; i < blks; ++i) | |
1693 | { | |
1694 | unsigned int data_off = (plt_entries_per_block | |
1695 | * plt_insn_chunk_size) - 4; | |
1696 | ||
1697 | for (unsigned int j = 0; j < plt_entries_per_block; ++j) | |
1698 | { | |
1699 | elfcpp::Swap<32, true>::writeval(pov + 0x00, | |
1700 | sparc_mov_o7_g5); | |
1701 | elfcpp::Swap<32, true>::writeval(pov + 0x04, | |
1702 | sparc_call_plus_8); | |
1703 | elfcpp::Swap<32, true>::writeval(pov + 0x08, | |
1704 | sparc_nop); | |
1705 | elfcpp::Swap<32, true>::writeval(pov + 0x0c, | |
1706 | sparc_ldx_o7_imm_g1 + | |
1707 | (data_off & 0x1fff)); | |
1708 | elfcpp::Swap<32, true>::writeval(pov + 0x10, | |
1709 | sparc_jmpl_o7_g1_g1); | |
1710 | elfcpp::Swap<32, true>::writeval(pov + 0x14, | |
1711 | sparc_mov_g5_o7); | |
1712 | ||
1713 | elfcpp::Swap<64, big_endian>::writeval( | |
1714 | pov + 0x4 + data_off, | |
1715 | (elfcpp::Elf_Xword) (oview - (pov + 0x04))); | |
1716 | ||
1717 | pov += plt_insn_chunk_size; | |
1718 | data_off -= 16; | |
1719 | } | |
1720 | } | |
1721 | ||
1722 | unsigned int sub_blk_cnt = ext_cnt % plt_entries_per_block; | |
1723 | for (unsigned int i = 0; i < sub_blk_cnt; ++i) | |
1724 | { | |
1725 | unsigned int data_off = (sub_blk_cnt | |
1726 | * plt_insn_chunk_size) - 4; | |
1727 | ||
1728 | for (unsigned int j = 0; j < plt_entries_per_block; ++j) | |
1729 | { | |
1730 | elfcpp::Swap<32, true>::writeval(pov + 0x00, | |
1731 | sparc_mov_o7_g5); | |
1732 | elfcpp::Swap<32, true>::writeval(pov + 0x04, | |
1733 | sparc_call_plus_8); | |
1734 | elfcpp::Swap<32, true>::writeval(pov + 0x08, | |
1735 | sparc_nop); | |
1736 | elfcpp::Swap<32, true>::writeval(pov + 0x0c, | |
1737 | sparc_ldx_o7_imm_g1 + | |
1738 | (data_off & 0x1fff)); | |
1739 | elfcpp::Swap<32, true>::writeval(pov + 0x10, | |
1740 | sparc_jmpl_o7_g1_g1); | |
1741 | elfcpp::Swap<32, true>::writeval(pov + 0x14, | |
1742 | sparc_mov_g5_o7); | |
1743 | ||
1744 | elfcpp::Swap<64, big_endian>::writeval( | |
1745 | pov + 0x4 + data_off, | |
1746 | (elfcpp::Elf_Xword) (oview - (pov + 0x04))); | |
1747 | ||
1748 | pov += plt_insn_chunk_size; | |
1749 | data_off -= 16; | |
1750 | } | |
1751 | } | |
1752 | } | |
1753 | } | |
1754 | else | |
1755 | { | |
1756 | for (unsigned int i = 0; i < count; ++i) | |
1757 | { | |
1758 | elfcpp::Swap<32, true>::writeval(pov + 0x00, | |
1759 | sparc_sethi_g1 + plt_offset); | |
1760 | elfcpp::Swap<32, true>::writeval(pov + 0x04, | |
1761 | sparc_branch_always + | |
1762 | (((- (plt_offset + 4)) >> 2) & | |
1763 | 0x003fffff)); | |
1764 | elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop); | |
1765 | ||
1766 | pov += base_plt_entry_size; | |
1767 | plt_offset += base_plt_entry_size; | |
1768 | } | |
1769 | ||
1770 | elfcpp::Swap<32, true>::writeval(pov, sparc_nop); | |
1771 | pov += 4; | |
1772 | } | |
1773 | ||
1774 | gold_assert(static_cast<section_size_type>(pov - oview) == oview_size); | |
1775 | ||
2ea97941 | 1776 | of->write_output_view(offset, oview_size, oview); |
f5314dd5 DM |
1777 | } |
1778 | ||
8c2bf391 DM |
1779 | // Create the PLT section. |
1780 | ||
1781 | template<int size, bool big_endian> | |
1782 | void | |
1783 | Target_sparc<size, big_endian>::make_plt_section(Symbol_table* symtab, | |
1784 | Layout* layout) | |
1785 | { | |
1786 | // Create the GOT sections first. | |
1787 | this->got_section(symtab, layout); | |
1788 | ||
1789 | // Ensure that .rela.dyn always appears before .rela.plt This is | |
1790 | // necessary due to how, on Sparc and some other targets, .rela.dyn | |
1791 | // needs to include .rela.plt in it's range. | |
1792 | this->rela_dyn_section(layout); | |
1793 | ||
1794 | this->plt_ = new Output_data_plt_sparc<size, big_endian>(layout); | |
1795 | layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS, | |
1796 | (elfcpp::SHF_ALLOC | |
1797 | | elfcpp::SHF_EXECINSTR | |
1798 | | elfcpp::SHF_WRITE), | |
1799 | this->plt_, ORDER_NON_RELRO_FIRST, false); | |
1800 | ||
1801 | // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section. | |
1802 | symtab->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL, | |
1803 | Symbol_table::PREDEFINED, | |
1804 | this->plt_, | |
1805 | 0, 0, elfcpp::STT_OBJECT, | |
1806 | elfcpp::STB_LOCAL, | |
1807 | elfcpp::STV_HIDDEN, 0, | |
1808 | false, false); | |
1809 | } | |
1810 | ||
f5314dd5 DM |
1811 | // Create a PLT entry for a global symbol. |
1812 | ||
1813 | template<int size, bool big_endian> | |
1814 | void | |
1815 | Target_sparc<size, big_endian>::make_plt_entry(Symbol_table* symtab, | |
1816 | Layout* layout, | |
1817 | Symbol* gsym) | |
1818 | { | |
1819 | if (gsym->has_plt_offset()) | |
1820 | return; | |
1821 | ||
1822 | if (this->plt_ == NULL) | |
8c2bf391 | 1823 | this->make_plt_section(symtab, layout); |
f5314dd5 | 1824 | |
8c2bf391 DM |
1825 | this->plt_->add_entry(symtab, layout, gsym); |
1826 | } | |
f5314dd5 | 1827 | |
8c2bf391 | 1828 | // Make a PLT entry for a local STT_GNU_IFUNC symbol. |
f5314dd5 | 1829 | |
8c2bf391 DM |
1830 | template<int size, bool big_endian> |
1831 | void | |
1832 | Target_sparc<size, big_endian>::make_local_ifunc_plt_entry( | |
1833 | Symbol_table* symtab, | |
1834 | Layout* layout, | |
1835 | Sized_relobj_file<size, big_endian>* relobj, | |
1836 | unsigned int local_sym_index) | |
1837 | { | |
1838 | if (relobj->local_has_plt_offset(local_sym_index)) | |
1839 | return; | |
1840 | if (this->plt_ == NULL) | |
1841 | this->make_plt_section(symtab, layout); | |
1842 | unsigned int plt_offset = this->plt_->add_local_ifunc_entry(symtab, layout, | |
1843 | relobj, | |
1844 | local_sym_index); | |
1845 | relobj->set_local_plt_offset(local_sym_index, plt_offset); | |
f5314dd5 DM |
1846 | } |
1847 | ||
0e70b911 CC |
1848 | // Return the number of entries in the PLT. |
1849 | ||
1850 | template<int size, bool big_endian> | |
1851 | unsigned int | |
1852 | Target_sparc<size, big_endian>::plt_entry_count() const | |
1853 | { | |
1854 | if (this->plt_ == NULL) | |
1855 | return 0; | |
1856 | return this->plt_->entry_count(); | |
1857 | } | |
1858 | ||
1859 | // Return the offset of the first non-reserved PLT entry. | |
1860 | ||
1861 | template<int size, bool big_endian> | |
1862 | unsigned int | |
1863 | Target_sparc<size, big_endian>::first_plt_entry_offset() const | |
1864 | { | |
1865 | return Output_data_plt_sparc<size, big_endian>::first_plt_entry_offset(); | |
1866 | } | |
1867 | ||
1868 | // Return the size of each PLT entry. | |
1869 | ||
1870 | template<int size, bool big_endian> | |
1871 | unsigned int | |
1872 | Target_sparc<size, big_endian>::plt_entry_size() const | |
1873 | { | |
1874 | return Output_data_plt_sparc<size, big_endian>::get_plt_entry_size(); | |
1875 | } | |
1876 | ||
f5314dd5 DM |
1877 | // Create a GOT entry for the TLS module index. |
1878 | ||
1879 | template<int size, bool big_endian> | |
1880 | unsigned int | |
6fa2a40b CC |
1881 | Target_sparc<size, big_endian>::got_mod_index_entry( |
1882 | Symbol_table* symtab, | |
1883 | Layout* layout, | |
1884 | Sized_relobj_file<size, big_endian>* object) | |
f5314dd5 DM |
1885 | { |
1886 | if (this->got_mod_index_offset_ == -1U) | |
1887 | { | |
1888 | gold_assert(symtab != NULL && layout != NULL && object != NULL); | |
1889 | Reloc_section* rela_dyn = this->rela_dyn_section(layout); | |
1890 | Output_data_got<size, big_endian>* got; | |
1891 | unsigned int got_offset; | |
1892 | ||
1893 | got = this->got_section(symtab, layout); | |
1894 | got_offset = got->add_constant(0); | |
1895 | rela_dyn->add_local(object, 0, | |
1896 | (size == 64 ? | |
1897 | elfcpp::R_SPARC_TLS_DTPMOD64 : | |
1898 | elfcpp::R_SPARC_TLS_DTPMOD32), got, | |
1899 | got_offset, 0); | |
1900 | got->add_constant(0); | |
1901 | this->got_mod_index_offset_ = got_offset; | |
1902 | } | |
1903 | return this->got_mod_index_offset_; | |
1904 | } | |
1905 | ||
f5314dd5 DM |
1906 | // Optimize the TLS relocation type based on what we know about the |
1907 | // symbol. IS_FINAL is true if the final address of this symbol is | |
1908 | // known at link time. | |
1909 | ||
1910 | static tls::Tls_optimization | |
1911 | optimize_tls_reloc(bool is_final, int r_type) | |
1912 | { | |
1913 | // If we are generating a shared library, then we can't do anything | |
1914 | // in the linker. | |
1915 | if (parameters->options().shared()) | |
1916 | return tls::TLSOPT_NONE; | |
1917 | ||
1918 | switch (r_type) | |
1919 | { | |
1920 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic | |
1921 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
1922 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
1923 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
1924 | // These are General-Dynamic which permits fully general TLS | |
1925 | // access. Since we know that we are generating an executable, | |
1926 | // we can convert this to Initial-Exec. If we also know that | |
1927 | // this is a local symbol, we can further switch to Local-Exec. | |
1928 | if (is_final) | |
1929 | return tls::TLSOPT_TO_LE; | |
1930 | return tls::TLSOPT_TO_IE; | |
1931 | ||
1932 | case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic | |
1933 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
1934 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
1935 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
1936 | // This is Local-Dynamic, which refers to a local symbol in the | |
1937 | // dynamic TLS block. Since we know that we generating an | |
1938 | // executable, we can switch to Local-Exec. | |
1939 | return tls::TLSOPT_TO_LE; | |
1940 | ||
1941 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic | |
1942 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
1943 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
1944 | // Another type of Local-Dynamic relocation. | |
1945 | return tls::TLSOPT_TO_LE; | |
1946 | ||
1947 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec | |
1948 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
1949 | case elfcpp::R_SPARC_TLS_IE_LD: | |
1950 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
9efe6174 | 1951 | case elfcpp::R_SPARC_TLS_IE_ADD: |
f5314dd5 DM |
1952 | // These are Initial-Exec relocs which get the thread offset |
1953 | // from the GOT. If we know that we are linking against the | |
1954 | // local symbol, we can switch to Local-Exec, which links the | |
1955 | // thread offset into the instruction. | |
1956 | if (is_final) | |
1957 | return tls::TLSOPT_TO_LE; | |
1958 | return tls::TLSOPT_NONE; | |
1959 | ||
1960 | case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec | |
1961 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
1962 | // When we already have Local-Exec, there is nothing further we | |
1963 | // can do. | |
1964 | return tls::TLSOPT_NONE; | |
1965 | ||
1966 | default: | |
1967 | gold_unreachable(); | |
1968 | } | |
1969 | } | |
1970 | ||
95a2c8d6 RS |
1971 | // Get the Reference_flags for a particular relocation. |
1972 | ||
1973 | template<int size, bool big_endian> | |
1974 | int | |
1975 | Target_sparc<size, big_endian>::Scan::get_reference_flags(unsigned int r_type) | |
1976 | { | |
1977 | r_type &= 0xff; | |
1978 | switch (r_type) | |
1979 | { | |
1980 | case elfcpp::R_SPARC_NONE: | |
1981 | case elfcpp::R_SPARC_REGISTER: | |
1982 | case elfcpp::R_SPARC_GNU_VTINHERIT: | |
1983 | case elfcpp::R_SPARC_GNU_VTENTRY: | |
1984 | // No symbol reference. | |
1985 | return 0; | |
1986 | ||
1987 | case elfcpp::R_SPARC_UA64: | |
1988 | case elfcpp::R_SPARC_64: | |
1989 | case elfcpp::R_SPARC_HIX22: | |
1990 | case elfcpp::R_SPARC_LOX10: | |
2615994e | 1991 | case elfcpp::R_SPARC_H34: |
95a2c8d6 RS |
1992 | case elfcpp::R_SPARC_H44: |
1993 | case elfcpp::R_SPARC_M44: | |
1994 | case elfcpp::R_SPARC_L44: | |
1995 | case elfcpp::R_SPARC_HH22: | |
1996 | case elfcpp::R_SPARC_HM10: | |
1997 | case elfcpp::R_SPARC_LM22: | |
1998 | case elfcpp::R_SPARC_HI22: | |
1999 | case elfcpp::R_SPARC_LO10: | |
2000 | case elfcpp::R_SPARC_OLO10: | |
2001 | case elfcpp::R_SPARC_UA32: | |
2002 | case elfcpp::R_SPARC_32: | |
2003 | case elfcpp::R_SPARC_UA16: | |
2004 | case elfcpp::R_SPARC_16: | |
2005 | case elfcpp::R_SPARC_11: | |
2006 | case elfcpp::R_SPARC_10: | |
2007 | case elfcpp::R_SPARC_8: | |
2008 | case elfcpp::R_SPARC_7: | |
2009 | case elfcpp::R_SPARC_6: | |
2010 | case elfcpp::R_SPARC_5: | |
2011 | return Symbol::ABSOLUTE_REF; | |
2012 | ||
2013 | case elfcpp::R_SPARC_DISP8: | |
2014 | case elfcpp::R_SPARC_DISP16: | |
2015 | case elfcpp::R_SPARC_DISP32: | |
2016 | case elfcpp::R_SPARC_DISP64: | |
2017 | case elfcpp::R_SPARC_PC_HH22: | |
2018 | case elfcpp::R_SPARC_PC_HM10: | |
2019 | case elfcpp::R_SPARC_PC_LM22: | |
2020 | case elfcpp::R_SPARC_PC10: | |
2021 | case elfcpp::R_SPARC_PC22: | |
2022 | case elfcpp::R_SPARC_WDISP30: | |
2023 | case elfcpp::R_SPARC_WDISP22: | |
2024 | case elfcpp::R_SPARC_WDISP19: | |
2025 | case elfcpp::R_SPARC_WDISP16: | |
2615994e | 2026 | case elfcpp::R_SPARC_WDISP10: |
95a2c8d6 RS |
2027 | return Symbol::RELATIVE_REF; |
2028 | ||
2029 | case elfcpp::R_SPARC_PLT64: | |
2030 | case elfcpp::R_SPARC_PLT32: | |
2031 | case elfcpp::R_SPARC_HIPLT22: | |
2032 | case elfcpp::R_SPARC_LOPLT10: | |
2033 | case elfcpp::R_SPARC_PCPLT10: | |
2034 | return Symbol::FUNCTION_CALL | Symbol::ABSOLUTE_REF; | |
2035 | ||
2036 | case elfcpp::R_SPARC_PCPLT32: | |
2037 | case elfcpp::R_SPARC_PCPLT22: | |
2038 | case elfcpp::R_SPARC_WPLT30: | |
2039 | return Symbol::FUNCTION_CALL | Symbol::RELATIVE_REF; | |
2040 | ||
2041 | case elfcpp::R_SPARC_GOTDATA_OP: | |
2042 | case elfcpp::R_SPARC_GOTDATA_OP_HIX22: | |
2043 | case elfcpp::R_SPARC_GOTDATA_OP_LOX10: | |
2044 | case elfcpp::R_SPARC_GOT10: | |
2045 | case elfcpp::R_SPARC_GOT13: | |
2046 | case elfcpp::R_SPARC_GOT22: | |
2047 | // Absolute in GOT. | |
2048 | return Symbol::ABSOLUTE_REF; | |
2049 | ||
2050 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic | |
2051 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
2052 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
2053 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
2054 | case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic | |
2055 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
2056 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
2057 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
2058 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic | |
2059 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
2060 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
2061 | case elfcpp::R_SPARC_TLS_LE_HIX22: | |
2062 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
2063 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec | |
2064 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
2065 | case elfcpp::R_SPARC_TLS_IE_LD: | |
2066 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
2067 | case elfcpp::R_SPARC_TLS_IE_ADD: | |
2068 | return Symbol::TLS_REF; | |
2069 | ||
2070 | case elfcpp::R_SPARC_COPY: | |
2071 | case elfcpp::R_SPARC_GLOB_DAT: | |
2072 | case elfcpp::R_SPARC_JMP_SLOT: | |
8c2bf391 | 2073 | case elfcpp::R_SPARC_JMP_IREL: |
95a2c8d6 | 2074 | case elfcpp::R_SPARC_RELATIVE: |
8c2bf391 | 2075 | case elfcpp::R_SPARC_IRELATIVE: |
95a2c8d6 RS |
2076 | case elfcpp::R_SPARC_TLS_DTPMOD64: |
2077 | case elfcpp::R_SPARC_TLS_DTPMOD32: | |
2078 | case elfcpp::R_SPARC_TLS_DTPOFF64: | |
2079 | case elfcpp::R_SPARC_TLS_DTPOFF32: | |
2080 | case elfcpp::R_SPARC_TLS_TPOFF64: | |
2081 | case elfcpp::R_SPARC_TLS_TPOFF32: | |
2082 | default: | |
2083 | // Not expected. We will give an error later. | |
2084 | return 0; | |
2085 | } | |
2086 | } | |
2087 | ||
f5314dd5 DM |
2088 | // Generate a PLT entry slot for a call to __tls_get_addr |
2089 | template<int size, bool big_endian> | |
2090 | void | |
2091 | Target_sparc<size, big_endian>::Scan::generate_tls_call(Symbol_table* symtab, | |
2092 | Layout* layout, | |
2093 | Target_sparc<size, big_endian>* target) | |
2094 | { | |
2095 | Symbol* gsym = target->tls_get_addr_sym(symtab); | |
2096 | ||
2097 | target->make_plt_entry(symtab, layout, gsym); | |
2098 | } | |
2099 | ||
2100 | // Report an unsupported relocation against a local symbol. | |
2101 | ||
2102 | template<int size, bool big_endian> | |
2103 | void | |
2104 | Target_sparc<size, big_endian>::Scan::unsupported_reloc_local( | |
6fa2a40b | 2105 | Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
2106 | unsigned int r_type) |
2107 | { | |
2108 | gold_error(_("%s: unsupported reloc %u against local symbol"), | |
2109 | object->name().c_str(), r_type); | |
2110 | } | |
2111 | ||
32b769e1 DM |
2112 | // We are about to emit a dynamic relocation of type R_TYPE. If the |
2113 | // dynamic linker does not support it, issue an error. | |
2114 | ||
2115 | template<int size, bool big_endian> | |
2116 | void | |
2117 | Target_sparc<size, big_endian>::Scan::check_non_pic(Relobj* object, unsigned int r_type) | |
2118 | { | |
2119 | gold_assert(r_type != elfcpp::R_SPARC_NONE); | |
2120 | ||
2121 | if (size == 64) | |
2122 | { | |
2123 | switch (r_type) | |
2124 | { | |
2125 | // These are the relocation types supported by glibc for sparc 64-bit. | |
2126 | case elfcpp::R_SPARC_RELATIVE: | |
8c2bf391 | 2127 | case elfcpp::R_SPARC_IRELATIVE: |
32b769e1 DM |
2128 | case elfcpp::R_SPARC_COPY: |
2129 | case elfcpp::R_SPARC_64: | |
2130 | case elfcpp::R_SPARC_GLOB_DAT: | |
2131 | case elfcpp::R_SPARC_JMP_SLOT: | |
8c2bf391 | 2132 | case elfcpp::R_SPARC_JMP_IREL: |
32b769e1 DM |
2133 | case elfcpp::R_SPARC_TLS_DTPMOD64: |
2134 | case elfcpp::R_SPARC_TLS_DTPOFF64: | |
2135 | case elfcpp::R_SPARC_TLS_TPOFF64: | |
2136 | case elfcpp::R_SPARC_TLS_LE_HIX22: | |
2137 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
2138 | case elfcpp::R_SPARC_8: | |
2139 | case elfcpp::R_SPARC_16: | |
2140 | case elfcpp::R_SPARC_DISP8: | |
2141 | case elfcpp::R_SPARC_DISP16: | |
2142 | case elfcpp::R_SPARC_DISP32: | |
2143 | case elfcpp::R_SPARC_WDISP30: | |
2144 | case elfcpp::R_SPARC_LO10: | |
2145 | case elfcpp::R_SPARC_HI22: | |
2146 | case elfcpp::R_SPARC_OLO10: | |
2615994e | 2147 | case elfcpp::R_SPARC_H34: |
32b769e1 DM |
2148 | case elfcpp::R_SPARC_H44: |
2149 | case elfcpp::R_SPARC_M44: | |
2150 | case elfcpp::R_SPARC_L44: | |
2151 | case elfcpp::R_SPARC_HH22: | |
2152 | case elfcpp::R_SPARC_HM10: | |
2153 | case elfcpp::R_SPARC_LM22: | |
2154 | case elfcpp::R_SPARC_UA16: | |
2155 | case elfcpp::R_SPARC_UA32: | |
2156 | case elfcpp::R_SPARC_UA64: | |
2157 | return; | |
2158 | ||
2159 | default: | |
2160 | break; | |
2161 | } | |
2162 | } | |
2163 | else | |
2164 | { | |
2165 | switch (r_type) | |
2166 | { | |
2167 | // These are the relocation types supported by glibc for sparc 32-bit. | |
2168 | case elfcpp::R_SPARC_RELATIVE: | |
8c2bf391 | 2169 | case elfcpp::R_SPARC_IRELATIVE: |
32b769e1 DM |
2170 | case elfcpp::R_SPARC_COPY: |
2171 | case elfcpp::R_SPARC_GLOB_DAT: | |
2172 | case elfcpp::R_SPARC_32: | |
2173 | case elfcpp::R_SPARC_JMP_SLOT: | |
8c2bf391 | 2174 | case elfcpp::R_SPARC_JMP_IREL: |
32b769e1 DM |
2175 | case elfcpp::R_SPARC_TLS_DTPMOD32: |
2176 | case elfcpp::R_SPARC_TLS_DTPOFF32: | |
2177 | case elfcpp::R_SPARC_TLS_TPOFF32: | |
2178 | case elfcpp::R_SPARC_TLS_LE_HIX22: | |
2179 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
2180 | case elfcpp::R_SPARC_8: | |
2181 | case elfcpp::R_SPARC_16: | |
2182 | case elfcpp::R_SPARC_DISP8: | |
2183 | case elfcpp::R_SPARC_DISP16: | |
2184 | case elfcpp::R_SPARC_DISP32: | |
2185 | case elfcpp::R_SPARC_LO10: | |
2186 | case elfcpp::R_SPARC_WDISP30: | |
2187 | case elfcpp::R_SPARC_HI22: | |
2188 | case elfcpp::R_SPARC_UA16: | |
2189 | case elfcpp::R_SPARC_UA32: | |
2190 | return; | |
2191 | ||
2192 | default: | |
2193 | break; | |
2194 | } | |
2195 | } | |
2196 | ||
2197 | // This prevents us from issuing more than one error per reloc | |
2198 | // section. But we can still wind up issuing more than one | |
2199 | // error per object file. | |
2200 | if (this->issued_non_pic_error_) | |
2201 | return; | |
33aea2fd | 2202 | gold_assert(parameters->options().output_is_position_independent()); |
32b769e1 DM |
2203 | object->error(_("requires unsupported dynamic reloc; " |
2204 | "recompile with -fPIC")); | |
2205 | this->issued_non_pic_error_ = true; | |
2206 | return; | |
2207 | } | |
2208 | ||
8c2bf391 DM |
2209 | // Return whether we need to make a PLT entry for a relocation of the |
2210 | // given type against a STT_GNU_IFUNC symbol. | |
2211 | ||
2212 | template<int size, bool big_endian> | |
2213 | bool | |
2214 | Target_sparc<size, big_endian>::Scan::reloc_needs_plt_for_ifunc( | |
2215 | Sized_relobj_file<size, big_endian>* object, | |
2216 | unsigned int r_type) | |
2217 | { | |
2218 | int flags = Scan::get_reference_flags(r_type); | |
2219 | if (flags & Symbol::TLS_REF) | |
2220 | gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"), | |
2221 | object->name().c_str(), r_type); | |
2222 | return flags != 0; | |
2223 | } | |
2224 | ||
f5314dd5 DM |
2225 | // Scan a relocation for a local symbol. |
2226 | ||
2227 | template<int size, bool big_endian> | |
2228 | inline void | |
2229 | Target_sparc<size, big_endian>::Scan::local( | |
f5314dd5 DM |
2230 | Symbol_table* symtab, |
2231 | Layout* layout, | |
2232 | Target_sparc<size, big_endian>* target, | |
6fa2a40b | 2233 | Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
2234 | unsigned int data_shndx, |
2235 | Output_section* output_section, | |
2236 | const elfcpp::Rela<size, big_endian>& reloc, | |
2237 | unsigned int r_type, | |
2238 | const elfcpp::Sym<size, big_endian>& lsym) | |
2239 | { | |
8c2bf391 | 2240 | bool is_ifunc = lsym.get_st_type() == elfcpp::STT_GNU_IFUNC; |
f5314dd5 | 2241 | unsigned int orig_r_type = r_type; |
f5314dd5 | 2242 | r_type &= 0xff; |
8c2bf391 DM |
2243 | |
2244 | if (is_ifunc | |
2245 | && this->reloc_needs_plt_for_ifunc(object, r_type)) | |
2246 | { | |
2247 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); | |
2248 | target->make_local_ifunc_plt_entry(symtab, layout, object, r_sym); | |
2249 | } | |
2250 | ||
f5314dd5 DM |
2251 | switch (r_type) |
2252 | { | |
2253 | case elfcpp::R_SPARC_NONE: | |
2254 | case elfcpp::R_SPARC_REGISTER: | |
2255 | case elfcpp::R_SPARC_GNU_VTINHERIT: | |
2256 | case elfcpp::R_SPARC_GNU_VTENTRY: | |
2257 | break; | |
2258 | ||
2259 | case elfcpp::R_SPARC_64: | |
2260 | case elfcpp::R_SPARC_32: | |
2261 | // If building a shared library (or a position-independent | |
2262 | // executable), we need to create a dynamic relocation for | |
2263 | // this location. The relocation applied at link time will | |
2264 | // apply the link-time value, so we flag the location with | |
2265 | // an R_SPARC_RELATIVE relocation so the dynamic loader can | |
2266 | // relocate it easily. | |
2267 | if (parameters->options().output_is_position_independent()) | |
2268 | { | |
2269 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
2270 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); | |
2271 | rela_dyn->add_local_relative(object, r_sym, elfcpp::R_SPARC_RELATIVE, | |
2272 | output_section, data_shndx, | |
2273 | reloc.get_r_offset(), | |
8c2bf391 | 2274 | reloc.get_r_addend(), is_ifunc); |
f5314dd5 DM |
2275 | } |
2276 | break; | |
2277 | ||
2278 | case elfcpp::R_SPARC_HIX22: | |
2279 | case elfcpp::R_SPARC_LOX10: | |
2615994e | 2280 | case elfcpp::R_SPARC_H34: |
f5314dd5 DM |
2281 | case elfcpp::R_SPARC_H44: |
2282 | case elfcpp::R_SPARC_M44: | |
2283 | case elfcpp::R_SPARC_L44: | |
2284 | case elfcpp::R_SPARC_HH22: | |
2285 | case elfcpp::R_SPARC_HM10: | |
2286 | case elfcpp::R_SPARC_LM22: | |
2287 | case elfcpp::R_SPARC_UA64: | |
2288 | case elfcpp::R_SPARC_UA32: | |
2289 | case elfcpp::R_SPARC_UA16: | |
2290 | case elfcpp::R_SPARC_HI22: | |
2291 | case elfcpp::R_SPARC_LO10: | |
2292 | case elfcpp::R_SPARC_OLO10: | |
2293 | case elfcpp::R_SPARC_16: | |
2294 | case elfcpp::R_SPARC_11: | |
2295 | case elfcpp::R_SPARC_10: | |
2296 | case elfcpp::R_SPARC_8: | |
2297 | case elfcpp::R_SPARC_7: | |
2298 | case elfcpp::R_SPARC_6: | |
2299 | case elfcpp::R_SPARC_5: | |
2300 | // If building a shared library (or a position-independent | |
2301 | // executable), we need to create a dynamic relocation for | |
2302 | // this location. | |
2303 | if (parameters->options().output_is_position_independent()) | |
2304 | { | |
2305 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
684b268a | 2306 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); |
32b769e1 DM |
2307 | |
2308 | check_non_pic(object, r_type); | |
f5314dd5 DM |
2309 | if (lsym.get_st_type() != elfcpp::STT_SECTION) |
2310 | { | |
f5314dd5 DM |
2311 | rela_dyn->add_local(object, r_sym, orig_r_type, output_section, |
2312 | data_shndx, reloc.get_r_offset(), | |
2313 | reloc.get_r_addend()); | |
2314 | } | |
2315 | else | |
2316 | { | |
f5314dd5 | 2317 | gold_assert(lsym.get_st_value() == 0); |
0da6fa6c DM |
2318 | rela_dyn->add_symbolless_local_addend(object, r_sym, orig_r_type, |
2319 | output_section, data_shndx, | |
2320 | reloc.get_r_offset(), | |
2321 | reloc.get_r_addend()); | |
f5314dd5 DM |
2322 | } |
2323 | } | |
2324 | break; | |
2325 | ||
2326 | case elfcpp::R_SPARC_WDISP30: | |
8861f32b | 2327 | case elfcpp::R_SPARC_WPLT30: |
f5314dd5 DM |
2328 | case elfcpp::R_SPARC_WDISP22: |
2329 | case elfcpp::R_SPARC_WDISP19: | |
2330 | case elfcpp::R_SPARC_WDISP16: | |
2615994e | 2331 | case elfcpp::R_SPARC_WDISP10: |
f5314dd5 DM |
2332 | case elfcpp::R_SPARC_DISP8: |
2333 | case elfcpp::R_SPARC_DISP16: | |
2334 | case elfcpp::R_SPARC_DISP32: | |
2335 | case elfcpp::R_SPARC_DISP64: | |
2336 | case elfcpp::R_SPARC_PC10: | |
2337 | case elfcpp::R_SPARC_PC22: | |
2338 | break; | |
2339 | ||
024c4466 DM |
2340 | case elfcpp::R_SPARC_GOTDATA_OP: |
2341 | case elfcpp::R_SPARC_GOTDATA_OP_HIX22: | |
2342 | case elfcpp::R_SPARC_GOTDATA_OP_LOX10: | |
2a1079e8 DM |
2343 | // We will optimize this into a GOT relative relocation |
2344 | // and code transform the GOT load into an addition. | |
2345 | break; | |
2346 | ||
f5314dd5 DM |
2347 | case elfcpp::R_SPARC_GOT10: |
2348 | case elfcpp::R_SPARC_GOT13: | |
2349 | case elfcpp::R_SPARC_GOT22: | |
2350 | { | |
2351 | // The symbol requires a GOT entry. | |
2352 | Output_data_got<size, big_endian>* got; | |
2353 | unsigned int r_sym; | |
2354 | ||
2355 | got = target->got_section(symtab, layout); | |
2356 | r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); | |
2357 | ||
2358 | // If we are generating a shared object, we need to add a | |
2359 | // dynamic relocation for this symbol's GOT entry. | |
2360 | if (parameters->options().output_is_position_independent()) | |
2361 | { | |
2362 | if (!object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD)) | |
2363 | { | |
2364 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
8c2bf391 | 2365 | unsigned int off = got->add_constant(0); |
f5314dd5 DM |
2366 | object->set_local_got_offset(r_sym, GOT_TYPE_STANDARD, off); |
2367 | rela_dyn->add_local_relative(object, r_sym, | |
2368 | elfcpp::R_SPARC_RELATIVE, | |
8c2bf391 | 2369 | got, off, 0, is_ifunc); |
f5314dd5 DM |
2370 | } |
2371 | } | |
2372 | else | |
2373 | got->add_local(object, r_sym, GOT_TYPE_STANDARD); | |
2374 | } | |
2375 | break; | |
2376 | ||
2377 | // These are initial TLS relocs, which are expected when | |
2378 | // linking. | |
2379 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic | |
2380 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
2381 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
2382 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
2383 | case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic | |
2384 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
2385 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
2386 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
2387 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic | |
2388 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
2389 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
2390 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec | |
2391 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
2392 | case elfcpp::R_SPARC_TLS_IE_LD: | |
2393 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
9efe6174 | 2394 | case elfcpp::R_SPARC_TLS_IE_ADD: |
f5314dd5 DM |
2395 | case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec |
2396 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
2397 | { | |
2398 | bool output_is_shared = parameters->options().shared(); | |
2399 | const tls::Tls_optimization optimized_type | |
2400 | = optimize_tls_reloc(!output_is_shared, r_type); | |
2401 | switch (r_type) | |
2402 | { | |
2403 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic | |
2404 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
2405 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
2406 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
2407 | if (optimized_type == tls::TLSOPT_NONE) | |
2408 | { | |
2409 | // Create a pair of GOT entries for the module index and | |
2410 | // dtv-relative offset. | |
2411 | Output_data_got<size, big_endian>* got | |
2412 | = target->got_section(symtab, layout); | |
2413 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); | |
d491d34e ILT |
2414 | unsigned int shndx = lsym.get_st_shndx(); |
2415 | bool is_ordinary; | |
2416 | shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary); | |
2417 | if (!is_ordinary) | |
2418 | object->error(_("local symbol %u has bad shndx %u"), | |
2419 | r_sym, shndx); | |
2420 | else | |
83896202 ILT |
2421 | got->add_local_pair_with_rel(object, r_sym, |
2422 | lsym.get_st_shndx(), | |
2423 | GOT_TYPE_TLS_PAIR, | |
2424 | target->rela_dyn_section(layout), | |
2425 | (size == 64 | |
2426 | ? elfcpp::R_SPARC_TLS_DTPMOD64 | |
2427 | : elfcpp::R_SPARC_TLS_DTPMOD32), | |
2428 | 0); | |
f5314dd5 DM |
2429 | if (r_type == elfcpp::R_SPARC_TLS_GD_CALL) |
2430 | generate_tls_call(symtab, layout, target); | |
2431 | } | |
2432 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
2433 | unsupported_reloc_local(object, r_type); | |
2434 | break; | |
2435 | ||
2436 | case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic | |
2437 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
2438 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
2439 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
2440 | if (optimized_type == tls::TLSOPT_NONE) | |
2441 | { | |
2442 | // Create a GOT entry for the module index. | |
2443 | target->got_mod_index_entry(symtab, layout, object); | |
2444 | ||
2445 | if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL) | |
2446 | generate_tls_call(symtab, layout, target); | |
2447 | } | |
2448 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
2449 | unsupported_reloc_local(object, r_type); | |
2450 | break; | |
2451 | ||
2452 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic | |
2453 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
2454 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
2455 | break; | |
2456 | ||
2457 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec | |
2458 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
2459 | case elfcpp::R_SPARC_TLS_IE_LD: | |
2460 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
9efe6174 | 2461 | case elfcpp::R_SPARC_TLS_IE_ADD: |
f5314dd5 DM |
2462 | layout->set_has_static_tls(); |
2463 | if (optimized_type == tls::TLSOPT_NONE) | |
2464 | { | |
2465 | // Create a GOT entry for the tp-relative offset. | |
2466 | Output_data_got<size, big_endian>* got | |
2467 | = target->got_section(symtab, layout); | |
2468 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); | |
2469 | ||
2470 | if (!object->local_has_got_offset(r_sym, GOT_TYPE_TLS_OFFSET)) | |
2471 | { | |
2472 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
0da6fa6c DM |
2473 | unsigned int off = got->add_constant(0); |
2474 | ||
2475 | object->set_local_got_offset(r_sym, GOT_TYPE_TLS_OFFSET, off); | |
684b268a | 2476 | |
0da6fa6c DM |
2477 | rela_dyn->add_symbolless_local_addend(object, r_sym, |
2478 | (size == 64 ? | |
2479 | elfcpp::R_SPARC_TLS_TPOFF64 : | |
2480 | elfcpp::R_SPARC_TLS_TPOFF32), | |
2481 | got, off, 0); | |
f5314dd5 DM |
2482 | } |
2483 | } | |
2484 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
2485 | unsupported_reloc_local(object, r_type); | |
2486 | break; | |
2487 | ||
2488 | case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec | |
2489 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
2490 | layout->set_has_static_tls(); | |
2491 | if (output_is_shared) | |
2492 | { | |
2493 | // We need to create a dynamic relocation. | |
2494 | gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION); | |
2495 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); | |
2496 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
0da6fa6c DM |
2497 | rela_dyn->add_symbolless_local_addend(object, r_sym, r_type, |
2498 | output_section, data_shndx, | |
2499 | reloc.get_r_offset(), 0); | |
f5314dd5 DM |
2500 | } |
2501 | break; | |
2502 | } | |
2503 | } | |
2504 | break; | |
2505 | ||
2506 | // These are relocations which should only be seen by the | |
2507 | // dynamic linker, and should never be seen here. | |
2508 | case elfcpp::R_SPARC_COPY: | |
2509 | case elfcpp::R_SPARC_GLOB_DAT: | |
2510 | case elfcpp::R_SPARC_JMP_SLOT: | |
8c2bf391 | 2511 | case elfcpp::R_SPARC_JMP_IREL: |
f5314dd5 | 2512 | case elfcpp::R_SPARC_RELATIVE: |
8c2bf391 | 2513 | case elfcpp::R_SPARC_IRELATIVE: |
f5314dd5 DM |
2514 | case elfcpp::R_SPARC_TLS_DTPMOD64: |
2515 | case elfcpp::R_SPARC_TLS_DTPMOD32: | |
2516 | case elfcpp::R_SPARC_TLS_DTPOFF64: | |
2517 | case elfcpp::R_SPARC_TLS_DTPOFF32: | |
2518 | case elfcpp::R_SPARC_TLS_TPOFF64: | |
2519 | case elfcpp::R_SPARC_TLS_TPOFF32: | |
2520 | gold_error(_("%s: unexpected reloc %u in object file"), | |
2521 | object->name().c_str(), r_type); | |
2522 | break; | |
2523 | ||
2524 | default: | |
2525 | unsupported_reloc_local(object, r_type); | |
2526 | break; | |
2527 | } | |
2528 | } | |
2529 | ||
2530 | // Report an unsupported relocation against a global symbol. | |
2531 | ||
2532 | template<int size, bool big_endian> | |
2533 | void | |
2534 | Target_sparc<size, big_endian>::Scan::unsupported_reloc_global( | |
6fa2a40b | 2535 | Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
2536 | unsigned int r_type, |
2537 | Symbol* gsym) | |
2538 | { | |
2539 | gold_error(_("%s: unsupported reloc %u against global symbol %s"), | |
2540 | object->name().c_str(), r_type, gsym->demangled_name().c_str()); | |
2541 | } | |
2542 | ||
2543 | // Scan a relocation for a global symbol. | |
2544 | ||
2545 | template<int size, bool big_endian> | |
2546 | inline void | |
2547 | Target_sparc<size, big_endian>::Scan::global( | |
f5314dd5 DM |
2548 | Symbol_table* symtab, |
2549 | Layout* layout, | |
2550 | Target_sparc<size, big_endian>* target, | |
6fa2a40b | 2551 | Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
2552 | unsigned int data_shndx, |
2553 | Output_section* output_section, | |
2554 | const elfcpp::Rela<size, big_endian>& reloc, | |
2555 | unsigned int r_type, | |
2556 | Symbol* gsym) | |
2557 | { | |
2558 | unsigned int orig_r_type = r_type; | |
8c2bf391 | 2559 | bool is_ifunc = gsym->type() == elfcpp::STT_GNU_IFUNC; |
f5314dd5 | 2560 | |
9efe6174 ILT |
2561 | // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got |
2562 | // section. We check here to avoid creating a dynamic reloc against | |
2563 | // _GLOBAL_OFFSET_TABLE_. | |
2564 | if (!target->has_got_section() | |
2565 | && strcmp(gsym->name(), "_GLOBAL_OFFSET_TABLE_") == 0) | |
2566 | target->got_section(symtab, layout); | |
2567 | ||
f5314dd5 | 2568 | r_type &= 0xff; |
8c2bf391 DM |
2569 | |
2570 | // A STT_GNU_IFUNC symbol may require a PLT entry. | |
2571 | if (is_ifunc | |
2572 | && this->reloc_needs_plt_for_ifunc(object, r_type)) | |
2573 | target->make_plt_entry(symtab, layout, gsym); | |
2574 | ||
f5314dd5 DM |
2575 | switch (r_type) |
2576 | { | |
2577 | case elfcpp::R_SPARC_NONE: | |
2578 | case elfcpp::R_SPARC_REGISTER: | |
2579 | case elfcpp::R_SPARC_GNU_VTINHERIT: | |
2580 | case elfcpp::R_SPARC_GNU_VTENTRY: | |
2581 | break; | |
2582 | ||
2583 | case elfcpp::R_SPARC_PLT64: | |
2584 | case elfcpp::R_SPARC_PLT32: | |
2585 | case elfcpp::R_SPARC_HIPLT22: | |
2586 | case elfcpp::R_SPARC_LOPLT10: | |
2587 | case elfcpp::R_SPARC_PCPLT32: | |
2588 | case elfcpp::R_SPARC_PCPLT22: | |
2589 | case elfcpp::R_SPARC_PCPLT10: | |
2590 | case elfcpp::R_SPARC_WPLT30: | |
2591 | // If the symbol is fully resolved, this is just a PC32 reloc. | |
2592 | // Otherwise we need a PLT entry. | |
2593 | if (gsym->final_value_is_known()) | |
2594 | break; | |
2595 | // If building a shared library, we can also skip the PLT entry | |
2596 | // if the symbol is defined in the output file and is protected | |
2597 | // or hidden. | |
2598 | if (gsym->is_defined() | |
2599 | && !gsym->is_from_dynobj() | |
2600 | && !gsym->is_preemptible()) | |
2601 | break; | |
2602 | target->make_plt_entry(symtab, layout, gsym); | |
2603 | break; | |
2604 | ||
2605 | case elfcpp::R_SPARC_DISP8: | |
2606 | case elfcpp::R_SPARC_DISP16: | |
2607 | case elfcpp::R_SPARC_DISP32: | |
2608 | case elfcpp::R_SPARC_DISP64: | |
2609 | case elfcpp::R_SPARC_PC_HH22: | |
2610 | case elfcpp::R_SPARC_PC_HM10: | |
2611 | case elfcpp::R_SPARC_PC_LM22: | |
2612 | case elfcpp::R_SPARC_PC10: | |
2613 | case elfcpp::R_SPARC_PC22: | |
2614 | case elfcpp::R_SPARC_WDISP30: | |
2615 | case elfcpp::R_SPARC_WDISP22: | |
2616 | case elfcpp::R_SPARC_WDISP19: | |
2617 | case elfcpp::R_SPARC_WDISP16: | |
2615994e | 2618 | case elfcpp::R_SPARC_WDISP10: |
f5314dd5 DM |
2619 | { |
2620 | if (gsym->needs_plt_entry()) | |
2621 | target->make_plt_entry(symtab, layout, gsym); | |
2622 | // Make a dynamic relocation if necessary. | |
95a2c8d6 | 2623 | if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type))) |
f5314dd5 | 2624 | { |
966d4097 | 2625 | if (gsym->may_need_copy_reloc()) |
f5314dd5 | 2626 | { |
12c0daef | 2627 | target->copy_reloc(symtab, layout, object, |
f5314dd5 DM |
2628 | data_shndx, output_section, gsym, |
2629 | reloc); | |
2630 | } | |
2631 | else | |
2632 | { | |
2633 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
32b769e1 | 2634 | check_non_pic(object, r_type); |
f5314dd5 DM |
2635 | rela_dyn->add_global(gsym, orig_r_type, output_section, object, |
2636 | data_shndx, reloc.get_r_offset(), | |
2637 | reloc.get_r_addend()); | |
2638 | } | |
2639 | } | |
2640 | } | |
2641 | break; | |
2642 | ||
2643 | case elfcpp::R_SPARC_UA64: | |
2644 | case elfcpp::R_SPARC_64: | |
2645 | case elfcpp::R_SPARC_HIX22: | |
2646 | case elfcpp::R_SPARC_LOX10: | |
2615994e | 2647 | case elfcpp::R_SPARC_H34: |
f5314dd5 DM |
2648 | case elfcpp::R_SPARC_H44: |
2649 | case elfcpp::R_SPARC_M44: | |
2650 | case elfcpp::R_SPARC_L44: | |
2651 | case elfcpp::R_SPARC_HH22: | |
2652 | case elfcpp::R_SPARC_HM10: | |
2653 | case elfcpp::R_SPARC_LM22: | |
2654 | case elfcpp::R_SPARC_HI22: | |
2655 | case elfcpp::R_SPARC_LO10: | |
2656 | case elfcpp::R_SPARC_OLO10: | |
2657 | case elfcpp::R_SPARC_UA32: | |
2658 | case elfcpp::R_SPARC_32: | |
2659 | case elfcpp::R_SPARC_UA16: | |
2660 | case elfcpp::R_SPARC_16: | |
2661 | case elfcpp::R_SPARC_11: | |
2662 | case elfcpp::R_SPARC_10: | |
2663 | case elfcpp::R_SPARC_8: | |
2664 | case elfcpp::R_SPARC_7: | |
2665 | case elfcpp::R_SPARC_6: | |
2666 | case elfcpp::R_SPARC_5: | |
2667 | { | |
2668 | // Make a PLT entry if necessary. | |
2669 | if (gsym->needs_plt_entry()) | |
2670 | { | |
2671 | target->make_plt_entry(symtab, layout, gsym); | |
2672 | // Since this is not a PC-relative relocation, we may be | |
2673 | // taking the address of a function. In that case we need to | |
2674 | // set the entry in the dynamic symbol table to the address of | |
2675 | // the PLT entry. | |
2676 | if (gsym->is_from_dynobj() && !parameters->options().shared()) | |
2677 | gsym->set_needs_dynsym_value(); | |
2678 | } | |
2679 | // Make a dynamic relocation if necessary. | |
95a2c8d6 | 2680 | if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type))) |
f5314dd5 | 2681 | { |
0da6fa6c DM |
2682 | unsigned int r_off = reloc.get_r_offset(); |
2683 | ||
2684 | // The assembler can sometimes emit unaligned relocations | |
2685 | // for dwarf2 cfi directives. | |
2686 | switch (r_type) | |
2687 | { | |
2688 | case elfcpp::R_SPARC_16: | |
2689 | if (r_off & 0x1) | |
2690 | orig_r_type = r_type = elfcpp::R_SPARC_UA16; | |
2691 | break; | |
2692 | case elfcpp::R_SPARC_32: | |
2693 | if (r_off & 0x3) | |
2694 | orig_r_type = r_type = elfcpp::R_SPARC_UA32; | |
2695 | break; | |
2696 | case elfcpp::R_SPARC_64: | |
2697 | if (r_off & 0x7) | |
2698 | orig_r_type = r_type = elfcpp::R_SPARC_UA64; | |
2699 | break; | |
2700 | case elfcpp::R_SPARC_UA16: | |
2701 | if (!(r_off & 0x1)) | |
2702 | orig_r_type = r_type = elfcpp::R_SPARC_16; | |
2703 | break; | |
2704 | case elfcpp::R_SPARC_UA32: | |
2705 | if (!(r_off & 0x3)) | |
2706 | orig_r_type = r_type = elfcpp::R_SPARC_32; | |
2707 | break; | |
2708 | case elfcpp::R_SPARC_UA64: | |
2709 | if (!(r_off & 0x7)) | |
2710 | orig_r_type = r_type = elfcpp::R_SPARC_64; | |
2711 | break; | |
2712 | } | |
2713 | ||
966d4097 | 2714 | if (gsym->may_need_copy_reloc()) |
f5314dd5 | 2715 | { |
12c0daef | 2716 | target->copy_reloc(symtab, layout, object, |
f5314dd5 DM |
2717 | data_shndx, output_section, gsym, reloc); |
2718 | } | |
8c2bf391 DM |
2719 | else if (((size == 64 && r_type == elfcpp::R_SPARC_64) |
2720 | || (size == 32 && r_type == elfcpp::R_SPARC_32)) | |
2721 | && gsym->type() == elfcpp::STT_GNU_IFUNC | |
2722 | && gsym->can_use_relative_reloc(false) | |
2723 | && !gsym->is_from_dynobj() | |
2724 | && !gsym->is_undefined() | |
2725 | && !gsym->is_preemptible()) | |
2726 | { | |
2727 | // Use an IRELATIVE reloc for a locally defined | |
2728 | // STT_GNU_IFUNC symbol. This makes a function | |
2729 | // address in a PIE executable match the address in a | |
2730 | // shared library that it links against. | |
2731 | Reloc_section* rela_dyn = | |
2732 | target->rela_ifunc_section(layout); | |
2733 | unsigned int r_type = elfcpp::R_SPARC_IRELATIVE; | |
2734 | rela_dyn->add_symbolless_global_addend(gsym, r_type, | |
2735 | output_section, object, | |
2736 | data_shndx, | |
2737 | reloc.get_r_offset(), | |
2738 | reloc.get_r_addend()); | |
2739 | } | |
f5314dd5 DM |
2740 | else if ((r_type == elfcpp::R_SPARC_32 |
2741 | || r_type == elfcpp::R_SPARC_64) | |
2742 | && gsym->can_use_relative_reloc(false)) | |
2743 | { | |
2744 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
2745 | rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE, | |
2746 | output_section, object, | |
2747 | data_shndx, reloc.get_r_offset(), | |
8c2bf391 | 2748 | reloc.get_r_addend(), is_ifunc); |
f5314dd5 DM |
2749 | } |
2750 | else | |
2751 | { | |
2752 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
2753 | ||
32b769e1 | 2754 | check_non_pic(object, r_type); |
0da6fa6c DM |
2755 | if (gsym->is_from_dynobj() |
2756 | || gsym->is_undefined() | |
2757 | || gsym->is_preemptible()) | |
2758 | rela_dyn->add_global(gsym, orig_r_type, output_section, | |
2759 | object, data_shndx, | |
2760 | reloc.get_r_offset(), | |
2761 | reloc.get_r_addend()); | |
2762 | else | |
2763 | rela_dyn->add_symbolless_global_addend(gsym, orig_r_type, | |
2764 | output_section, | |
2765 | object, data_shndx, | |
2766 | reloc.get_r_offset(), | |
2767 | reloc.get_r_addend()); | |
f5314dd5 DM |
2768 | } |
2769 | } | |
2770 | } | |
2771 | break; | |
2772 | ||
024c4466 DM |
2773 | case elfcpp::R_SPARC_GOTDATA_OP: |
2774 | case elfcpp::R_SPARC_GOTDATA_OP_HIX22: | |
2775 | case elfcpp::R_SPARC_GOTDATA_OP_LOX10: | |
2a1079e8 DM |
2776 | if (gsym->is_defined() |
2777 | && !gsym->is_from_dynobj() | |
2778 | && !gsym->is_preemptible() | |
2779 | && !is_ifunc) | |
2780 | { | |
2781 | // We will optimize this into a GOT relative relocation | |
2782 | // and code transform the GOT load into an addition. | |
2783 | break; | |
2784 | } | |
f5314dd5 DM |
2785 | case elfcpp::R_SPARC_GOT10: |
2786 | case elfcpp::R_SPARC_GOT13: | |
2787 | case elfcpp::R_SPARC_GOT22: | |
2788 | { | |
2789 | // The symbol requires a GOT entry. | |
2790 | Output_data_got<size, big_endian>* got; | |
2791 | ||
2792 | got = target->got_section(symtab, layout); | |
2793 | if (gsym->final_value_is_known()) | |
8c2bf391 DM |
2794 | { |
2795 | // For a STT_GNU_IFUNC symbol we want the PLT address. | |
2796 | if (gsym->type() == elfcpp::STT_GNU_IFUNC) | |
2797 | got->add_global_plt(gsym, GOT_TYPE_STANDARD); | |
2798 | else | |
2799 | got->add_global(gsym, GOT_TYPE_STANDARD); | |
2800 | } | |
f5314dd5 DM |
2801 | else |
2802 | { | |
2803 | // If this symbol is not fully resolved, we need to add a | |
8c2bf391 DM |
2804 | // GOT entry with a dynamic relocation. |
2805 | bool is_ifunc = gsym->type() == elfcpp::STT_GNU_IFUNC; | |
2806 | ||
2807 | // Use a GLOB_DAT rather than a RELATIVE reloc if: | |
2808 | // | |
2809 | // 1) The symbol may be defined in some other module. | |
2810 | // | |
2811 | // 2) We are building a shared library and this is a | |
2812 | // protected symbol; using GLOB_DAT means that the dynamic | |
2813 | // linker can use the address of the PLT in the main | |
2814 | // executable when appropriate so that function address | |
2815 | // comparisons work. | |
2816 | // | |
2817 | // 3) This is a STT_GNU_IFUNC symbol in position dependent | |
2818 | // code, again so that function address comparisons work. | |
f5314dd5 DM |
2819 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); |
2820 | if (gsym->is_from_dynobj() | |
2821 | || gsym->is_undefined() | |
8c2bf391 DM |
2822 | || gsym->is_preemptible() |
2823 | || (gsym->visibility() == elfcpp::STV_PROTECTED | |
2824 | && parameters->options().shared()) | |
2825 | || (gsym->type() == elfcpp::STT_GNU_IFUNC | |
2826 | && parameters->options().output_is_position_independent() | |
2827 | && !gsym->is_forced_local())) | |
2828 | { | |
2829 | unsigned int r_type = elfcpp::R_SPARC_GLOB_DAT; | |
2830 | ||
2831 | // If this symbol is forced local, this relocation will | |
2832 | // not work properly. That's because ld.so on sparc | |
2833 | // (and 32-bit powerpc) expects st_value in the r_addend | |
2834 | // of relocations for STB_LOCAL symbols. Curiously the | |
2835 | // BFD linker does not promote global hidden symbols to be | |
2836 | // STB_LOCAL in the dynamic symbol table like Gold does. | |
2837 | gold_assert(!gsym->is_forced_local()); | |
2838 | got->add_global_with_rel(gsym, GOT_TYPE_STANDARD, rela_dyn, | |
2839 | r_type); | |
2840 | } | |
f5314dd5 DM |
2841 | else if (!gsym->has_got_offset(GOT_TYPE_STANDARD)) |
2842 | { | |
2843 | unsigned int off = got->add_constant(0); | |
2844 | ||
2845 | gsym->set_got_offset(GOT_TYPE_STANDARD, off); | |
8c2bf391 DM |
2846 | if (is_ifunc) |
2847 | { | |
2848 | // Tell the dynamic linker to use the PLT address | |
2849 | // when resolving relocations. | |
2850 | if (gsym->is_from_dynobj() | |
2851 | && !parameters->options().shared()) | |
2852 | gsym->set_needs_dynsym_value(); | |
2853 | } | |
f5314dd5 | 2854 | rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE, |
8c2bf391 | 2855 | got, off, 0, is_ifunc); |
f5314dd5 DM |
2856 | } |
2857 | } | |
2858 | } | |
2859 | break; | |
2860 | ||
2861 | // These are initial tls relocs, which are expected when | |
2862 | // linking. | |
2863 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic | |
2864 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
2865 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
2866 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
2867 | case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic | |
2868 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
2869 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
2870 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
2871 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic | |
2872 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
2873 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
2874 | case elfcpp::R_SPARC_TLS_LE_HIX22: | |
2875 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
2876 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec | |
2877 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
2878 | case elfcpp::R_SPARC_TLS_IE_LD: | |
2879 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
9efe6174 | 2880 | case elfcpp::R_SPARC_TLS_IE_ADD: |
f5314dd5 DM |
2881 | { |
2882 | const bool is_final = gsym->final_value_is_known(); | |
2883 | const tls::Tls_optimization optimized_type | |
2884 | = optimize_tls_reloc(is_final, r_type); | |
2885 | switch (r_type) | |
2886 | { | |
2887 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic | |
2888 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
2889 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
2890 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
2891 | if (optimized_type == tls::TLSOPT_NONE) | |
2892 | { | |
2893 | // Create a pair of GOT entries for the module index and | |
2894 | // dtv-relative offset. | |
2895 | Output_data_got<size, big_endian>* got | |
2896 | = target->got_section(symtab, layout); | |
83896202 ILT |
2897 | got->add_global_pair_with_rel(gsym, GOT_TYPE_TLS_PAIR, |
2898 | target->rela_dyn_section(layout), | |
2899 | (size == 64 | |
2900 | ? elfcpp::R_SPARC_TLS_DTPMOD64 | |
2901 | : elfcpp::R_SPARC_TLS_DTPMOD32), | |
2902 | (size == 64 | |
2903 | ? elfcpp::R_SPARC_TLS_DTPOFF64 | |
2904 | : elfcpp::R_SPARC_TLS_DTPOFF32)); | |
f5314dd5 DM |
2905 | |
2906 | // Emit R_SPARC_WPLT30 against "__tls_get_addr" | |
2907 | if (r_type == elfcpp::R_SPARC_TLS_GD_CALL) | |
2908 | generate_tls_call(symtab, layout, target); | |
2909 | } | |
2910 | else if (optimized_type == tls::TLSOPT_TO_IE) | |
2911 | { | |
2912 | // Create a GOT entry for the tp-relative offset. | |
2913 | Output_data_got<size, big_endian>* got | |
2914 | = target->got_section(symtab, layout); | |
83896202 ILT |
2915 | got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET, |
2916 | target->rela_dyn_section(layout), | |
2917 | (size == 64 ? | |
2918 | elfcpp::R_SPARC_TLS_TPOFF64 : | |
2919 | elfcpp::R_SPARC_TLS_TPOFF32)); | |
f5314dd5 DM |
2920 | } |
2921 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
2922 | unsupported_reloc_global(object, r_type, gsym); | |
2923 | break; | |
2924 | ||
2925 | case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic | |
2926 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
2927 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
2928 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
2929 | if (optimized_type == tls::TLSOPT_NONE) | |
2930 | { | |
2931 | // Create a GOT entry for the module index. | |
2932 | target->got_mod_index_entry(symtab, layout, object); | |
2933 | ||
2934 | if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL) | |
2935 | generate_tls_call(symtab, layout, target); | |
2936 | } | |
2937 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
2938 | unsupported_reloc_global(object, r_type, gsym); | |
2939 | break; | |
2940 | ||
2941 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic | |
2942 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
2943 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
2944 | break; | |
2945 | ||
2946 | case elfcpp::R_SPARC_TLS_LE_HIX22: | |
2947 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
2948 | layout->set_has_static_tls(); | |
2949 | if (parameters->options().shared()) | |
2950 | { | |
2951 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
0da6fa6c DM |
2952 | rela_dyn->add_symbolless_global_addend(gsym, orig_r_type, |
2953 | output_section, object, | |
2954 | data_shndx, reloc.get_r_offset(), | |
2955 | 0); | |
f5314dd5 DM |
2956 | } |
2957 | break; | |
2958 | ||
2959 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec | |
2960 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
2961 | case elfcpp::R_SPARC_TLS_IE_LD: | |
2962 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
9efe6174 | 2963 | case elfcpp::R_SPARC_TLS_IE_ADD: |
f5314dd5 DM |
2964 | layout->set_has_static_tls(); |
2965 | if (optimized_type == tls::TLSOPT_NONE) | |
2966 | { | |
2967 | // Create a GOT entry for the tp-relative offset. | |
2968 | Output_data_got<size, big_endian>* got | |
2969 | = target->got_section(symtab, layout); | |
83896202 ILT |
2970 | got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET, |
2971 | target->rela_dyn_section(layout), | |
2972 | (size == 64 | |
2973 | ? elfcpp::R_SPARC_TLS_TPOFF64 | |
2974 | : elfcpp::R_SPARC_TLS_TPOFF32)); | |
f5314dd5 DM |
2975 | } |
2976 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
2977 | unsupported_reloc_global(object, r_type, gsym); | |
2978 | break; | |
2979 | } | |
2980 | } | |
2981 | break; | |
2982 | ||
2983 | // These are relocations which should only be seen by the | |
2984 | // dynamic linker, and should never be seen here. | |
2985 | case elfcpp::R_SPARC_COPY: | |
2986 | case elfcpp::R_SPARC_GLOB_DAT: | |
2987 | case elfcpp::R_SPARC_JMP_SLOT: | |
8c2bf391 | 2988 | case elfcpp::R_SPARC_JMP_IREL: |
f5314dd5 | 2989 | case elfcpp::R_SPARC_RELATIVE: |
8c2bf391 | 2990 | case elfcpp::R_SPARC_IRELATIVE: |
f5314dd5 DM |
2991 | case elfcpp::R_SPARC_TLS_DTPMOD64: |
2992 | case elfcpp::R_SPARC_TLS_DTPMOD32: | |
2993 | case elfcpp::R_SPARC_TLS_DTPOFF64: | |
2994 | case elfcpp::R_SPARC_TLS_DTPOFF32: | |
2995 | case elfcpp::R_SPARC_TLS_TPOFF64: | |
2996 | case elfcpp::R_SPARC_TLS_TPOFF32: | |
2997 | gold_error(_("%s: unexpected reloc %u in object file"), | |
2998 | object->name().c_str(), r_type); | |
2999 | break; | |
3000 | ||
3001 | default: | |
3002 | unsupported_reloc_global(object, r_type, gsym); | |
3003 | break; | |
3004 | } | |
3005 | } | |
3006 | ||
6d03d481 ST |
3007 | // Process relocations for gc. |
3008 | ||
3009 | template<int size, bool big_endian> | |
3010 | void | |
3011 | Target_sparc<size, big_endian>::gc_process_relocs( | |
6d03d481 ST |
3012 | Symbol_table* symtab, |
3013 | Layout* layout, | |
6fa2a40b | 3014 | Sized_relobj_file<size, big_endian>* object, |
6d03d481 ST |
3015 | unsigned int data_shndx, |
3016 | unsigned int, | |
3017 | const unsigned char* prelocs, | |
3018 | size_t reloc_count, | |
3019 | Output_section* output_section, | |
3020 | bool needs_special_offset_handling, | |
3021 | size_t local_symbol_count, | |
3022 | const unsigned char* plocal_symbols) | |
3023 | { | |
3024 | typedef Target_sparc<size, big_endian> Sparc; | |
2ea97941 | 3025 | typedef typename Target_sparc<size, big_endian>::Scan Scan; |
6d03d481 | 3026 | |
41cbeecc | 3027 | gold::gc_process_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan, |
3ff2ccb0 | 3028 | typename Target_sparc::Relocatable_size_for_reloc>( |
6d03d481 ST |
3029 | symtab, |
3030 | layout, | |
3031 | this, | |
3032 | object, | |
3033 | data_shndx, | |
3034 | prelocs, | |
3035 | reloc_count, | |
3036 | output_section, | |
3037 | needs_special_offset_handling, | |
3038 | local_symbol_count, | |
3039 | plocal_symbols); | |
3040 | } | |
3041 | ||
f5314dd5 DM |
3042 | // Scan relocations for a section. |
3043 | ||
3044 | template<int size, bool big_endian> | |
3045 | void | |
3046 | Target_sparc<size, big_endian>::scan_relocs( | |
f5314dd5 DM |
3047 | Symbol_table* symtab, |
3048 | Layout* layout, | |
6fa2a40b | 3049 | Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
3050 | unsigned int data_shndx, |
3051 | unsigned int sh_type, | |
3052 | const unsigned char* prelocs, | |
3053 | size_t reloc_count, | |
3054 | Output_section* output_section, | |
3055 | bool needs_special_offset_handling, | |
3056 | size_t local_symbol_count, | |
3057 | const unsigned char* plocal_symbols) | |
3058 | { | |
3059 | typedef Target_sparc<size, big_endian> Sparc; | |
2ea97941 | 3060 | typedef typename Target_sparc<size, big_endian>::Scan Scan; |
f5314dd5 DM |
3061 | |
3062 | if (sh_type == elfcpp::SHT_REL) | |
3063 | { | |
3064 | gold_error(_("%s: unsupported REL reloc section"), | |
3065 | object->name().c_str()); | |
3066 | return; | |
3067 | } | |
3068 | ||
2ea97941 | 3069 | gold::scan_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan>( |
f5314dd5 DM |
3070 | symtab, |
3071 | layout, | |
3072 | this, | |
3073 | object, | |
3074 | data_shndx, | |
3075 | prelocs, | |
3076 | reloc_count, | |
3077 | output_section, | |
3078 | needs_special_offset_handling, | |
3079 | local_symbol_count, | |
3080 | plocal_symbols); | |
3081 | } | |
3082 | ||
3083 | // Finalize the sections. | |
3084 | ||
3085 | template<int size, bool big_endian> | |
3086 | void | |
d5b40221 DK |
3087 | Target_sparc<size, big_endian>::do_finalize_sections( |
3088 | Layout* layout, | |
f59f41f3 | 3089 | const Input_objects*, |
8c2bf391 | 3090 | Symbol_table* symtab) |
f5314dd5 | 3091 | { |
8c2bf391 DM |
3092 | if (this->plt_) |
3093 | this->plt_->emit_pending_ifunc_relocs(); | |
3094 | ||
f5314dd5 | 3095 | // Fill in some more dynamic tags. |
ea715a34 ILT |
3096 | const Reloc_section* rel_plt = (this->plt_ == NULL |
3097 | ? NULL | |
3098 | : this->plt_->rel_plt()); | |
3099 | layout->add_target_dynamic_tags(false, this->plt_, rel_plt, | |
612a8d3d | 3100 | this->rela_dyn_, true, true); |
f5314dd5 DM |
3101 | |
3102 | // Emit any relocs we saved in an attempt to avoid generating COPY | |
3103 | // relocs. | |
12c0daef ILT |
3104 | if (this->copy_relocs_.any_saved_relocs()) |
3105 | this->copy_relocs_.emit(this->rela_dyn_section(layout)); | |
8c2bf391 DM |
3106 | |
3107 | if (parameters->doing_static_link() | |
3108 | && (this->plt_ == NULL || !this->plt_->has_ifunc_section())) | |
3109 | { | |
3110 | // If linking statically, make sure that the __rela_iplt symbols | |
3111 | // were defined if necessary, even if we didn't create a PLT. | |
3112 | static const Define_symbol_in_segment syms[] = | |
3113 | { | |
3114 | { | |
3115 | "__rela_iplt_start", // name | |
3116 | elfcpp::PT_LOAD, // segment_type | |
3117 | elfcpp::PF_W, // segment_flags_set | |
3118 | elfcpp::PF(0), // segment_flags_clear | |
3119 | 0, // value | |
3120 | 0, // size | |
3121 | elfcpp::STT_NOTYPE, // type | |
3122 | elfcpp::STB_GLOBAL, // binding | |
3123 | elfcpp::STV_HIDDEN, // visibility | |
3124 | 0, // nonvis | |
3125 | Symbol::SEGMENT_START, // offset_from_base | |
3126 | true // only_if_ref | |
3127 | }, | |
3128 | { | |
3129 | "__rela_iplt_end", // name | |
3130 | elfcpp::PT_LOAD, // segment_type | |
3131 | elfcpp::PF_W, // segment_flags_set | |
3132 | elfcpp::PF(0), // segment_flags_clear | |
3133 | 0, // value | |
3134 | 0, // size | |
3135 | elfcpp::STT_NOTYPE, // type | |
3136 | elfcpp::STB_GLOBAL, // binding | |
3137 | elfcpp::STV_HIDDEN, // visibility | |
3138 | 0, // nonvis | |
3139 | Symbol::SEGMENT_START, // offset_from_base | |
3140 | true // only_if_ref | |
3141 | } | |
3142 | }; | |
3143 | ||
3144 | symtab->define_symbols(layout, 2, syms, | |
3145 | layout->script_options()->saw_sections_clause()); | |
3146 | } | |
f5314dd5 DM |
3147 | } |
3148 | ||
3149 | // Perform a relocation. | |
3150 | ||
3151 | template<int size, bool big_endian> | |
3152 | inline bool | |
3153 | Target_sparc<size, big_endian>::Relocate::relocate( | |
3154 | const Relocate_info<size, big_endian>* relinfo, | |
3155 | Target_sparc* target, | |
031cdbed | 3156 | Output_section*, |
f5314dd5 DM |
3157 | size_t relnum, |
3158 | const elfcpp::Rela<size, big_endian>& rela, | |
3159 | unsigned int r_type, | |
3160 | const Sized_symbol<size>* gsym, | |
3161 | const Symbol_value<size>* psymval, | |
3162 | unsigned char* view, | |
3163 | typename elfcpp::Elf_types<size>::Elf_Addr address, | |
3164 | section_size_type view_size) | |
3165 | { | |
2a1079e8 | 3166 | bool orig_is_ifunc = psymval->is_ifunc_symbol(); |
f5314dd5 DM |
3167 | r_type &= 0xff; |
3168 | ||
3169 | if (this->ignore_gd_add_) | |
3170 | { | |
3171 | if (r_type != elfcpp::R_SPARC_TLS_GD_ADD) | |
3172 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), | |
3173 | _("missing expected TLS relocation")); | |
3174 | else | |
3175 | { | |
3176 | this->ignore_gd_add_ = false; | |
3177 | return false; | |
3178 | } | |
3179 | } | |
abd242a9 DM |
3180 | if (this->reloc_adjust_addr_ == view) |
3181 | view -= 4; | |
f5314dd5 DM |
3182 | |
3183 | typedef Sparc_relocate_functions<size, big_endian> Reloc; | |
8c2bf391 | 3184 | const Sized_relobj_file<size, big_endian>* object = relinfo->object; |
f5314dd5 DM |
3185 | |
3186 | // Pick the value to use for symbols defined in shared objects. | |
3187 | Symbol_value<size> symval; | |
3188 | if (gsym != NULL | |
95a2c8d6 | 3189 | && gsym->use_plt_offset(Scan::get_reference_flags(r_type))) |
f5314dd5 | 3190 | { |
2ea97941 | 3191 | elfcpp::Elf_Xword value; |
f5314dd5 | 3192 | |
8c2bf391 | 3193 | value = target->plt_address_for_global(gsym) + gsym->plt_offset(); |
f5314dd5 | 3194 | |
2ea97941 | 3195 | symval.set_output_value(value); |
f5314dd5 DM |
3196 | |
3197 | psymval = &symval; | |
3198 | } | |
2a1079e8 | 3199 | else if (gsym == NULL && orig_is_ifunc) |
8c2bf391 DM |
3200 | { |
3201 | unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info()); | |
3202 | if (object->local_has_plt_offset(r_sym)) | |
3203 | { | |
3204 | symval.set_output_value(target->plt_address_for_local(object, r_sym) | |
3205 | + object->local_plt_offset(r_sym)); | |
3206 | psymval = &symval; | |
3207 | } | |
3208 | } | |
f5314dd5 | 3209 | |
f5314dd5 DM |
3210 | const elfcpp::Elf_Xword addend = rela.get_r_addend(); |
3211 | ||
3212 | // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT | |
3213 | // pointer points to the beginning, not the end, of the table. | |
3214 | // So we just use the plain offset. | |
f5314dd5 | 3215 | unsigned int got_offset = 0; |
2a1079e8 | 3216 | bool gdop_valid = false; |
f5314dd5 DM |
3217 | switch (r_type) |
3218 | { | |
024c4466 DM |
3219 | case elfcpp::R_SPARC_GOTDATA_OP: |
3220 | case elfcpp::R_SPARC_GOTDATA_OP_HIX22: | |
3221 | case elfcpp::R_SPARC_GOTDATA_OP_LOX10: | |
2a1079e8 DM |
3222 | // If this is local, we did not create a GOT entry because we |
3223 | // intend to transform this into a GOT relative relocation. | |
3224 | if (gsym == NULL | |
3225 | || (gsym->is_defined() | |
3226 | && !gsym->is_from_dynobj() | |
3227 | && !gsym->is_preemptible() | |
3228 | && !orig_is_ifunc)) | |
3229 | { | |
3230 | got_offset = psymval->value(object, 0) - target->got_address(); | |
3231 | gdop_valid = true; | |
3232 | break; | |
3233 | } | |
f5314dd5 DM |
3234 | case elfcpp::R_SPARC_GOT10: |
3235 | case elfcpp::R_SPARC_GOT13: | |
3236 | case elfcpp::R_SPARC_GOT22: | |
3237 | if (gsym != NULL) | |
3238 | { | |
3239 | gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD)); | |
3240 | got_offset = gsym->got_offset(GOT_TYPE_STANDARD); | |
3241 | } | |
3242 | else | |
3243 | { | |
3244 | unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info()); | |
3245 | gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD)); | |
3246 | got_offset = object->local_got_offset(r_sym, GOT_TYPE_STANDARD); | |
3247 | } | |
f5314dd5 DM |
3248 | break; |
3249 | ||
3250 | default: | |
3251 | break; | |
3252 | } | |
3253 | ||
3254 | switch (r_type) | |
3255 | { | |
3256 | case elfcpp::R_SPARC_NONE: | |
3257 | case elfcpp::R_SPARC_REGISTER: | |
3258 | case elfcpp::R_SPARC_GNU_VTINHERIT: | |
3259 | case elfcpp::R_SPARC_GNU_VTENTRY: | |
3260 | break; | |
3261 | ||
3262 | case elfcpp::R_SPARC_8: | |
3263 | Relocate_functions<size, big_endian>::rela8(view, object, | |
3264 | psymval, addend); | |
3265 | break; | |
3266 | ||
3267 | case elfcpp::R_SPARC_16: | |
705b5121 DM |
3268 | if (rela.get_r_offset() & 0x1) |
3269 | { | |
3270 | // The assembler can sometimes emit unaligned relocations | |
3271 | // for dwarf2 cfi directives. | |
3272 | Reloc::ua16(view, object, psymval, addend); | |
3273 | } | |
3274 | else | |
3275 | Relocate_functions<size, big_endian>::rela16(view, object, | |
3276 | psymval, addend); | |
f5314dd5 DM |
3277 | break; |
3278 | ||
3279 | case elfcpp::R_SPARC_32: | |
3280 | if (!parameters->options().output_is_position_independent()) | |
705b5121 DM |
3281 | { |
3282 | if (rela.get_r_offset() & 0x3) | |
3283 | { | |
3284 | // The assembler can sometimes emit unaligned relocations | |
3285 | // for dwarf2 cfi directives. | |
3286 | Reloc::ua32(view, object, psymval, addend); | |
3287 | } | |
3288 | else | |
3289 | Relocate_functions<size, big_endian>::rela32(view, object, | |
3290 | psymval, addend); | |
3291 | } | |
f5314dd5 DM |
3292 | break; |
3293 | ||
3294 | case elfcpp::R_SPARC_DISP8: | |
3295 | Reloc::disp8(view, object, psymval, addend, address); | |
3296 | break; | |
3297 | ||
3298 | case elfcpp::R_SPARC_DISP16: | |
3299 | Reloc::disp16(view, object, psymval, addend, address); | |
3300 | break; | |
3301 | ||
3302 | case elfcpp::R_SPARC_DISP32: | |
3303 | Reloc::disp32(view, object, psymval, addend, address); | |
3304 | break; | |
3305 | ||
3306 | case elfcpp::R_SPARC_DISP64: | |
3307 | Reloc::disp64(view, object, psymval, addend, address); | |
3308 | break; | |
3309 | ||
3310 | case elfcpp::R_SPARC_WDISP30: | |
3311 | case elfcpp::R_SPARC_WPLT30: | |
3312 | Reloc::wdisp30(view, object, psymval, addend, address); | |
a5a5f7a3 DM |
3313 | if (target->may_relax()) |
3314 | relax_call(target, view, rela, view_size); | |
f5314dd5 DM |
3315 | break; |
3316 | ||
3317 | case elfcpp::R_SPARC_WDISP22: | |
3318 | Reloc::wdisp22(view, object, psymval, addend, address); | |
3319 | break; | |
3320 | ||
3321 | case elfcpp::R_SPARC_WDISP19: | |
3322 | Reloc::wdisp19(view, object, psymval, addend, address); | |
3323 | break; | |
3324 | ||
3325 | case elfcpp::R_SPARC_WDISP16: | |
3326 | Reloc::wdisp16(view, object, psymval, addend, address); | |
3327 | break; | |
3328 | ||
2615994e DM |
3329 | case elfcpp::R_SPARC_WDISP10: |
3330 | Reloc::wdisp10(view, object, psymval, addend, address); | |
3331 | break; | |
3332 | ||
f5314dd5 DM |
3333 | case elfcpp::R_SPARC_HI22: |
3334 | Reloc::hi22(view, object, psymval, addend); | |
3335 | break; | |
3336 | ||
3337 | case elfcpp::R_SPARC_22: | |
3338 | Reloc::rela32_22(view, object, psymval, addend); | |
3339 | break; | |
3340 | ||
3341 | case elfcpp::R_SPARC_13: | |
3342 | Reloc::rela32_13(view, object, psymval, addend); | |
3343 | break; | |
3344 | ||
3345 | case elfcpp::R_SPARC_LO10: | |
3346 | Reloc::lo10(view, object, psymval, addend); | |
3347 | break; | |
3348 | ||
3349 | case elfcpp::R_SPARC_GOT10: | |
3350 | Reloc::lo10(view, got_offset, addend); | |
3351 | break; | |
3352 | ||
024c4466 | 3353 | case elfcpp::R_SPARC_GOTDATA_OP: |
2a1079e8 DM |
3354 | if (gdop_valid) |
3355 | { | |
3356 | typedef typename elfcpp::Swap<32, true>::Valtype Insntype; | |
3357 | Insntype* wv = reinterpret_cast<Insntype*>(view); | |
3358 | Insntype val; | |
3359 | ||
3360 | // {ld,ldx} [%rs1 + %rs2], %rd --> add %rs1, %rs2, %rd | |
3361 | val = elfcpp::Swap<32, true>::readval(wv); | |
3362 | val = 0x80000000 | (val & 0x3e07c01f); | |
3363 | elfcpp::Swap<32, true>::writeval(wv, val); | |
3364 | } | |
024c4466 DM |
3365 | break; |
3366 | ||
3367 | case elfcpp::R_SPARC_GOTDATA_OP_LOX10: | |
2a1079e8 DM |
3368 | if (gdop_valid) |
3369 | { | |
3370 | Reloc::gdop_lox10(view, got_offset, addend); | |
3371 | break; | |
3372 | } | |
3373 | /* Fall through. */ | |
f5314dd5 DM |
3374 | case elfcpp::R_SPARC_GOT13: |
3375 | Reloc::rela32_13(view, got_offset, addend); | |
3376 | break; | |
3377 | ||
024c4466 | 3378 | case elfcpp::R_SPARC_GOTDATA_OP_HIX22: |
2a1079e8 DM |
3379 | if (gdop_valid) |
3380 | { | |
3381 | Reloc::gdop_hix22(view, got_offset, addend); | |
3382 | break; | |
3383 | } | |
3384 | /* Fall through. */ | |
f5314dd5 DM |
3385 | case elfcpp::R_SPARC_GOT22: |
3386 | Reloc::hi22(view, got_offset, addend); | |
3387 | break; | |
3388 | ||
3389 | case elfcpp::R_SPARC_PC10: | |
3390 | Reloc::pc10(view, object, psymval, addend, address); | |
3391 | break; | |
3392 | ||
3393 | case elfcpp::R_SPARC_PC22: | |
3394 | Reloc::pc22(view, object, psymval, addend, address); | |
3395 | break; | |
3396 | ||
3397 | case elfcpp::R_SPARC_TLS_DTPOFF32: | |
3398 | case elfcpp::R_SPARC_UA32: | |
3399 | Reloc::ua32(view, object, psymval, addend); | |
3400 | break; | |
3401 | ||
3402 | case elfcpp::R_SPARC_PLT64: | |
3403 | Relocate_functions<size, big_endian>::rela64(view, object, | |
3404 | psymval, addend); | |
3405 | break; | |
3406 | ||
3407 | case elfcpp::R_SPARC_PLT32: | |
3408 | Relocate_functions<size, big_endian>::rela32(view, object, | |
3409 | psymval, addend); | |
3410 | break; | |
3411 | ||
3412 | case elfcpp::R_SPARC_HIPLT22: | |
3413 | Reloc::hi22(view, object, psymval, addend); | |
3414 | break; | |
3415 | ||
3416 | case elfcpp::R_SPARC_LOPLT10: | |
3417 | Reloc::lo10(view, object, psymval, addend); | |
3418 | break; | |
3419 | ||
3420 | case elfcpp::R_SPARC_PCPLT32: | |
3421 | Reloc::disp32(view, object, psymval, addend, address); | |
3422 | break; | |
3423 | ||
3424 | case elfcpp::R_SPARC_PCPLT22: | |
3425 | Reloc::pcplt22(view, object, psymval, addend, address); | |
3426 | break; | |
3427 | ||
3428 | case elfcpp::R_SPARC_PCPLT10: | |
3429 | Reloc::lo10(view, object, psymval, addend, address); | |
3430 | break; | |
3431 | ||
3432 | case elfcpp::R_SPARC_64: | |
3433 | if (!parameters->options().output_is_position_independent()) | |
705b5121 DM |
3434 | { |
3435 | if (rela.get_r_offset() & 0x7) | |
3436 | { | |
3437 | // The assembler can sometimes emit unaligned relocations | |
3438 | // for dwarf2 cfi directives. | |
3439 | Reloc::ua64(view, object, psymval, addend); | |
3440 | } | |
3441 | else | |
3442 | Relocate_functions<size, big_endian>::rela64(view, object, | |
3443 | psymval, addend); | |
3444 | } | |
f5314dd5 DM |
3445 | break; |
3446 | ||
3447 | case elfcpp::R_SPARC_OLO10: | |
3448 | { | |
3449 | unsigned int addend2 = rela.get_r_info() & 0xffffffff; | |
3450 | addend2 = ((addend2 >> 8) ^ 0x800000) - 0x800000; | |
3451 | Reloc::olo10(view, object, psymval, addend, addend2); | |
3452 | } | |
3453 | break; | |
3454 | ||
3455 | case elfcpp::R_SPARC_HH22: | |
3456 | Reloc::hh22(view, object, psymval, addend); | |
3457 | break; | |
3458 | ||
3459 | case elfcpp::R_SPARC_PC_HH22: | |
3460 | Reloc::pc_hh22(view, object, psymval, addend, address); | |
3461 | break; | |
3462 | ||
3463 | case elfcpp::R_SPARC_HM10: | |
3464 | Reloc::hm10(view, object, psymval, addend); | |
3465 | break; | |
3466 | ||
3467 | case elfcpp::R_SPARC_PC_HM10: | |
3468 | Reloc::pc_hm10(view, object, psymval, addend, address); | |
3469 | break; | |
3470 | ||
3471 | case elfcpp::R_SPARC_LM22: | |
3472 | Reloc::hi22(view, object, psymval, addend); | |
3473 | break; | |
3474 | ||
3475 | case elfcpp::R_SPARC_PC_LM22: | |
3476 | Reloc::pcplt22(view, object, psymval, addend, address); | |
3477 | break; | |
3478 | ||
3479 | case elfcpp::R_SPARC_11: | |
3480 | Reloc::rela32_11(view, object, psymval, addend); | |
3481 | break; | |
3482 | ||
3483 | case elfcpp::R_SPARC_10: | |
3484 | Reloc::rela32_10(view, object, psymval, addend); | |
3485 | break; | |
3486 | ||
3487 | case elfcpp::R_SPARC_7: | |
3488 | Reloc::rela32_7(view, object, psymval, addend); | |
3489 | break; | |
3490 | ||
3491 | case elfcpp::R_SPARC_6: | |
3492 | Reloc::rela32_6(view, object, psymval, addend); | |
3493 | break; | |
3494 | ||
3495 | case elfcpp::R_SPARC_5: | |
3496 | Reloc::rela32_5(view, object, psymval, addend); | |
3497 | break; | |
3498 | ||
3499 | case elfcpp::R_SPARC_HIX22: | |
3500 | Reloc::hix22(view, object, psymval, addend); | |
3501 | break; | |
3502 | ||
3503 | case elfcpp::R_SPARC_LOX10: | |
3504 | Reloc::lox10(view, object, psymval, addend); | |
3505 | break; | |
3506 | ||
2615994e DM |
3507 | case elfcpp::R_SPARC_H34: |
3508 | Reloc::h34(view, object, psymval, addend); | |
3509 | break; | |
3510 | ||
f5314dd5 DM |
3511 | case elfcpp::R_SPARC_H44: |
3512 | Reloc::h44(view, object, psymval, addend); | |
3513 | break; | |
3514 | ||
3515 | case elfcpp::R_SPARC_M44: | |
3516 | Reloc::m44(view, object, psymval, addend); | |
3517 | break; | |
3518 | ||
3519 | case elfcpp::R_SPARC_L44: | |
3520 | Reloc::l44(view, object, psymval, addend); | |
3521 | break; | |
3522 | ||
3523 | case elfcpp::R_SPARC_TLS_DTPOFF64: | |
3524 | case elfcpp::R_SPARC_UA64: | |
3525 | Reloc::ua64(view, object, psymval, addend); | |
3526 | break; | |
3527 | ||
3528 | case elfcpp::R_SPARC_UA16: | |
3529 | Reloc::ua16(view, object, psymval, addend); | |
3530 | break; | |
3531 | ||
3532 | case elfcpp::R_SPARC_TLS_GD_HI22: | |
3533 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
3534 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
3535 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
3536 | case elfcpp::R_SPARC_TLS_LDM_HI22: | |
3537 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
3538 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
3539 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
3540 | case elfcpp::R_SPARC_TLS_LDO_HIX22: | |
3541 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
3542 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
3543 | case elfcpp::R_SPARC_TLS_IE_HI22: | |
3544 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
3545 | case elfcpp::R_SPARC_TLS_IE_LD: | |
3546 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
9efe6174 | 3547 | case elfcpp::R_SPARC_TLS_IE_ADD: |
f5314dd5 DM |
3548 | case elfcpp::R_SPARC_TLS_LE_HIX22: |
3549 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
3550 | this->relocate_tls(relinfo, target, relnum, rela, | |
3551 | r_type, gsym, psymval, view, | |
3552 | address, view_size); | |
3553 | break; | |
3554 | ||
3555 | case elfcpp::R_SPARC_COPY: | |
3556 | case elfcpp::R_SPARC_GLOB_DAT: | |
3557 | case elfcpp::R_SPARC_JMP_SLOT: | |
8c2bf391 | 3558 | case elfcpp::R_SPARC_JMP_IREL: |
f5314dd5 | 3559 | case elfcpp::R_SPARC_RELATIVE: |
8c2bf391 | 3560 | case elfcpp::R_SPARC_IRELATIVE: |
f5314dd5 DM |
3561 | // These are outstanding tls relocs, which are unexpected when |
3562 | // linking. | |
3563 | case elfcpp::R_SPARC_TLS_DTPMOD64: | |
3564 | case elfcpp::R_SPARC_TLS_DTPMOD32: | |
3565 | case elfcpp::R_SPARC_TLS_TPOFF64: | |
3566 | case elfcpp::R_SPARC_TLS_TPOFF32: | |
3567 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), | |
3568 | _("unexpected reloc %u in object file"), | |
3569 | r_type); | |
3570 | break; | |
3571 | ||
3572 | default: | |
3573 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), | |
3574 | _("unsupported reloc %u"), | |
3575 | r_type); | |
3576 | break; | |
3577 | } | |
3578 | ||
3579 | return true; | |
3580 | } | |
3581 | ||
3582 | // Perform a TLS relocation. | |
3583 | ||
3584 | template<int size, bool big_endian> | |
3585 | inline void | |
3586 | Target_sparc<size, big_endian>::Relocate::relocate_tls( | |
3587 | const Relocate_info<size, big_endian>* relinfo, | |
3588 | Target_sparc<size, big_endian>* target, | |
3589 | size_t relnum, | |
3590 | const elfcpp::Rela<size, big_endian>& rela, | |
3591 | unsigned int r_type, | |
3592 | const Sized_symbol<size>* gsym, | |
3593 | const Symbol_value<size>* psymval, | |
3594 | unsigned char* view, | |
3595 | typename elfcpp::Elf_types<size>::Elf_Addr address, | |
3596 | section_size_type) | |
3597 | { | |
3598 | Output_segment* tls_segment = relinfo->layout->tls_segment(); | |
3599 | typedef Sparc_relocate_functions<size, big_endian> Reloc; | |
6fa2a40b | 3600 | const Sized_relobj_file<size, big_endian>* object = relinfo->object; |
f5314dd5 DM |
3601 | typedef typename elfcpp::Swap<32, true>::Valtype Insntype; |
3602 | ||
3603 | const elfcpp::Elf_Xword addend = rela.get_r_addend(); | |
2ea97941 | 3604 | typename elfcpp::Elf_types<size>::Elf_Addr value = psymval->value(object, 0); |
f5314dd5 DM |
3605 | |
3606 | const bool is_final = | |
3607 | (gsym == NULL | |
3608 | ? !parameters->options().output_is_position_independent() | |
3609 | : gsym->final_value_is_known()); | |
3610 | const tls::Tls_optimization optimized_type | |
3611 | = optimize_tls_reloc(is_final, r_type); | |
3612 | ||
3613 | switch (r_type) | |
3614 | { | |
3615 | case elfcpp::R_SPARC_TLS_GD_HI22: | |
3616 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
3617 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
3618 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
3619 | if (optimized_type == tls::TLSOPT_TO_LE) | |
3620 | { | |
3621 | Insntype* wv = reinterpret_cast<Insntype*>(view); | |
3622 | Insntype val; | |
3623 | ||
2ea97941 | 3624 | value -= tls_segment->memsz(); |
f5314dd5 DM |
3625 | |
3626 | switch (r_type) | |
3627 | { | |
3628 | case elfcpp::R_SPARC_TLS_GD_HI22: | |
3629 | // TLS_GD_HI22 --> TLS_LE_HIX22 | |
2ea97941 | 3630 | Reloc::hix22(view, value, addend); |
f5314dd5 DM |
3631 | break; |
3632 | ||
3633 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
3634 | // TLS_GD_LO10 --> TLS_LE_LOX10 | |
2ea97941 | 3635 | Reloc::lox10(view, value, addend); |
f5314dd5 DM |
3636 | break; |
3637 | ||
3638 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
3639 | // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3 | |
3640 | val = elfcpp::Swap<32, true>::readval(wv); | |
3641 | val = (val & ~0x7c000) | 0x1c000; | |
3642 | elfcpp::Swap<32, true>::writeval(wv, val); | |
3643 | break; | |
3644 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
3645 | // call __tls_get_addr --> nop | |
3646 | elfcpp::Swap<32, true>::writeval(wv, sparc_nop); | |
3647 | break; | |
3648 | } | |
3649 | break; | |
3650 | } | |
3651 | else | |
3652 | { | |
3653 | unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE | |
3654 | ? GOT_TYPE_TLS_OFFSET | |
3655 | : GOT_TYPE_TLS_PAIR); | |
3656 | if (gsym != NULL) | |
3657 | { | |
3658 | gold_assert(gsym->has_got_offset(got_type)); | |
2ea97941 | 3659 | value = gsym->got_offset(got_type); |
f5314dd5 DM |
3660 | } |
3661 | else | |
3662 | { | |
3663 | unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info()); | |
3664 | gold_assert(object->local_has_got_offset(r_sym, got_type)); | |
2ea97941 | 3665 | value = object->local_got_offset(r_sym, got_type); |
f5314dd5 DM |
3666 | } |
3667 | if (optimized_type == tls::TLSOPT_TO_IE) | |
3668 | { | |
3669 | Insntype* wv = reinterpret_cast<Insntype*>(view); | |
3670 | Insntype val; | |
3671 | ||
3672 | switch (r_type) | |
3673 | { | |
3674 | case elfcpp::R_SPARC_TLS_GD_HI22: | |
3675 | // TLS_GD_HI22 --> TLS_IE_HI22 | |
2ea97941 | 3676 | Reloc::hi22(view, value, addend); |
f5314dd5 DM |
3677 | break; |
3678 | ||
3679 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
3680 | // TLS_GD_LO10 --> TLS_IE_LO10 | |
2ea97941 | 3681 | Reloc::lo10(view, value, addend); |
f5314dd5 DM |
3682 | break; |
3683 | ||
3684 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
3685 | // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3 | |
3686 | val = elfcpp::Swap<32, true>::readval(wv); | |
3687 | ||
3688 | if (size == 64) | |
3689 | val |= 0xc0580000; | |
3690 | else | |
3691 | val |= 0xc0000000; | |
3692 | ||
3693 | elfcpp::Swap<32, true>::writeval(wv, val); | |
3694 | break; | |
3695 | ||
3696 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
3697 | // The compiler can put the TLS_GD_ADD instruction | |
3698 | // into the delay slot of the call. If so, we need | |
3699 | // to transpose the two instructions so that the | |
9b547ce6 | 3700 | // new sequence works properly. |
f5314dd5 DM |
3701 | // |
3702 | // The test we use is if the instruction in the | |
3703 | // delay slot is an add with destination register | |
3704 | // equal to %o0 | |
3705 | val = elfcpp::Swap<32, true>::readval(wv + 1); | |
3706 | if ((val & 0x81f80000) == 0x80000000 | |
3707 | && ((val >> 25) & 0x1f) == 0x8) | |
3708 | { | |
3709 | if (size == 64) | |
3710 | val |= 0xc0580000; | |
3711 | else | |
3712 | val |= 0xc0000000; | |
3713 | ||
3714 | elfcpp::Swap<32, true>::writeval(wv, val); | |
3715 | ||
3716 | wv += 1; | |
3717 | this->ignore_gd_add_ = true; | |
3718 | } | |
abd242a9 DM |
3719 | else |
3720 | { | |
3721 | // Even if the delay slot isn't the TLS_GD_ADD | |
3722 | // instruction, we still have to handle the case | |
3723 | // where it sets up %o0 in some other way. | |
3724 | elfcpp::Swap<32, true>::writeval(wv, val); | |
3725 | wv += 1; | |
3726 | this->reloc_adjust_addr_ = view + 4; | |
3727 | } | |
f5314dd5 DM |
3728 | // call __tls_get_addr --> add %g7, %o0, %o0 |
3729 | elfcpp::Swap<32, true>::writeval(wv, 0x9001c008); | |
3730 | break; | |
3731 | } | |
3732 | break; | |
3733 | } | |
3734 | else if (optimized_type == tls::TLSOPT_NONE) | |
3735 | { | |
3736 | switch (r_type) | |
3737 | { | |
3738 | case elfcpp::R_SPARC_TLS_GD_HI22: | |
2ea97941 | 3739 | Reloc::hi22(view, value, addend); |
f5314dd5 DM |
3740 | break; |
3741 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
2ea97941 | 3742 | Reloc::lo10(view, value, addend); |
f5314dd5 DM |
3743 | break; |
3744 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
3745 | break; | |
3746 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
3747 | { | |
3748 | Symbol_value<size> symval; | |
2ea97941 | 3749 | elfcpp::Elf_Xword value; |
f5314dd5 DM |
3750 | Symbol* tsym; |
3751 | ||
3752 | tsym = target->tls_get_addr_sym_; | |
3753 | gold_assert(tsym); | |
2ea97941 ILT |
3754 | value = (target->plt_section()->address() + |
3755 | tsym->plt_offset()); | |
3756 | symval.set_output_value(value); | |
f5314dd5 DM |
3757 | Reloc::wdisp30(view, object, &symval, addend, address); |
3758 | } | |
3759 | break; | |
3760 | } | |
3761 | break; | |
3762 | } | |
3763 | } | |
3764 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), | |
3765 | _("unsupported reloc %u"), | |
3766 | r_type); | |
3767 | break; | |
3768 | ||
3769 | case elfcpp::R_SPARC_TLS_LDM_HI22: | |
3770 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
3771 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
3772 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
3773 | if (optimized_type == tls::TLSOPT_TO_LE) | |
3774 | { | |
3775 | Insntype* wv = reinterpret_cast<Insntype*>(view); | |
3776 | ||
3777 | switch (r_type) | |
3778 | { | |
3779 | case elfcpp::R_SPARC_TLS_LDM_HI22: | |
3780 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
3781 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
3782 | elfcpp::Swap<32, true>::writeval(wv, sparc_nop); | |
3783 | break; | |
3784 | ||
3785 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
3786 | elfcpp::Swap<32, true>::writeval(wv, sparc_mov_g0_o0); | |
3787 | break; | |
3788 | } | |
3789 | break; | |
3790 | } | |
3791 | else if (optimized_type == tls::TLSOPT_NONE) | |
3792 | { | |
3793 | // Relocate the field with the offset of the GOT entry for | |
3794 | // the module index. | |
3795 | unsigned int got_offset; | |
3796 | ||
3797 | got_offset = target->got_mod_index_entry(NULL, NULL, NULL); | |
3798 | switch (r_type) | |
3799 | { | |
3800 | case elfcpp::R_SPARC_TLS_LDM_HI22: | |
3801 | Reloc::hi22(view, got_offset, addend); | |
3802 | break; | |
3803 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
3804 | Reloc::lo10(view, got_offset, addend); | |
3805 | break; | |
3806 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
3807 | break; | |
3808 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
3809 | { | |
3810 | Symbol_value<size> symval; | |
2ea97941 | 3811 | elfcpp::Elf_Xword value; |
f5314dd5 DM |
3812 | Symbol* tsym; |
3813 | ||
3814 | tsym = target->tls_get_addr_sym_; | |
3815 | gold_assert(tsym); | |
2ea97941 ILT |
3816 | value = (target->plt_section()->address() + |
3817 | tsym->plt_offset()); | |
3818 | symval.set_output_value(value); | |
f5314dd5 DM |
3819 | Reloc::wdisp30(view, object, &symval, addend, address); |
3820 | } | |
3821 | break; | |
3822 | } | |
3823 | break; | |
3824 | } | |
3825 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), | |
3826 | _("unsupported reloc %u"), | |
3827 | r_type); | |
3828 | break; | |
3829 | ||
3830 | // These relocs can appear in debugging sections, in which case | |
3831 | // we won't see the TLS_LDM relocs. The local_dynamic_type | |
3832 | // field tells us this. | |
3833 | case elfcpp::R_SPARC_TLS_LDO_HIX22: | |
3834 | if (optimized_type == tls::TLSOPT_TO_LE) | |
3835 | { | |
2ea97941 ILT |
3836 | value -= tls_segment->memsz(); |
3837 | Reloc::hix22(view, value, addend); | |
f5314dd5 DM |
3838 | } |
3839 | else | |
2ea97941 | 3840 | Reloc::ldo_hix22(view, value, addend); |
f5314dd5 DM |
3841 | break; |
3842 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
3843 | if (optimized_type == tls::TLSOPT_TO_LE) | |
3844 | { | |
2ea97941 ILT |
3845 | value -= tls_segment->memsz(); |
3846 | Reloc::lox10(view, value, addend); | |
f5314dd5 DM |
3847 | } |
3848 | else | |
2ea97941 | 3849 | Reloc::ldo_lox10(view, value, addend); |
f5314dd5 DM |
3850 | break; |
3851 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
3852 | if (optimized_type == tls::TLSOPT_TO_LE) | |
3853 | { | |
3854 | Insntype* wv = reinterpret_cast<Insntype*>(view); | |
3855 | Insntype val; | |
3856 | ||
3857 | // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3 | |
3858 | val = elfcpp::Swap<32, true>::readval(wv); | |
3859 | val = (val & ~0x7c000) | 0x1c000; | |
3860 | elfcpp::Swap<32, true>::writeval(wv, val); | |
3861 | } | |
3862 | break; | |
3863 | ||
3864 | // When optimizing IE --> LE, the only relocation that is handled | |
3865 | // differently is R_SPARC_TLS_IE_LD, it is rewritten from | |
3866 | // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is | |
3867 | // rs2 and rd are the same. | |
3868 | case elfcpp::R_SPARC_TLS_IE_LD: | |
3869 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
3870 | if (optimized_type == tls::TLSOPT_TO_LE) | |
3871 | { | |
3872 | Insntype* wv = reinterpret_cast<Insntype*>(view); | |
3873 | Insntype val = elfcpp::Swap<32, true>::readval(wv); | |
3874 | Insntype rs2 = val & 0x1f; | |
3875 | Insntype rd = (val >> 25) & 0x1f; | |
3876 | ||
3877 | if (rs2 == rd) | |
3878 | val = sparc_nop; | |
3879 | else | |
3880 | val = sparc_mov | (val & 0x3e00001f); | |
3881 | ||
3882 | elfcpp::Swap<32, true>::writeval(wv, val); | |
3883 | } | |
3884 | break; | |
3885 | ||
3886 | case elfcpp::R_SPARC_TLS_IE_HI22: | |
3887 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
3888 | if (optimized_type == tls::TLSOPT_TO_LE) | |
3889 | { | |
2ea97941 | 3890 | value -= tls_segment->memsz(); |
f5314dd5 DM |
3891 | switch (r_type) |
3892 | { | |
3893 | case elfcpp::R_SPARC_TLS_IE_HI22: | |
3894 | // IE_HI22 --> LE_HIX22 | |
2ea97941 | 3895 | Reloc::hix22(view, value, addend); |
f5314dd5 DM |
3896 | break; |
3897 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
3898 | // IE_LO10 --> LE_LOX10 | |
2ea97941 | 3899 | Reloc::lox10(view, value, addend); |
f5314dd5 DM |
3900 | break; |
3901 | } | |
3902 | break; | |
3903 | } | |
3904 | else if (optimized_type == tls::TLSOPT_NONE) | |
3905 | { | |
3906 | // Relocate the field with the offset of the GOT entry for | |
3907 | // the tp-relative offset of the symbol. | |
3908 | if (gsym != NULL) | |
3909 | { | |
3910 | gold_assert(gsym->has_got_offset(GOT_TYPE_TLS_OFFSET)); | |
2ea97941 | 3911 | value = gsym->got_offset(GOT_TYPE_TLS_OFFSET); |
f5314dd5 DM |
3912 | } |
3913 | else | |
3914 | { | |
3915 | unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info()); | |
3916 | gold_assert(object->local_has_got_offset(r_sym, | |
3917 | GOT_TYPE_TLS_OFFSET)); | |
2ea97941 ILT |
3918 | value = object->local_got_offset(r_sym, |
3919 | GOT_TYPE_TLS_OFFSET); | |
f5314dd5 DM |
3920 | } |
3921 | switch (r_type) | |
3922 | { | |
3923 | case elfcpp::R_SPARC_TLS_IE_HI22: | |
2ea97941 | 3924 | Reloc::hi22(view, value, addend); |
f5314dd5 DM |
3925 | break; |
3926 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
2ea97941 | 3927 | Reloc::lo10(view, value, addend); |
f5314dd5 DM |
3928 | break; |
3929 | } | |
3930 | break; | |
3931 | } | |
3932 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), | |
3933 | _("unsupported reloc %u"), | |
3934 | r_type); | |
3935 | break; | |
3936 | ||
9efe6174 ILT |
3937 | case elfcpp::R_SPARC_TLS_IE_ADD: |
3938 | // This seems to be mainly so that we can find the addition | |
3939 | // instruction if there is one. There doesn't seem to be any | |
3940 | // actual relocation to apply. | |
3941 | break; | |
3942 | ||
f5314dd5 DM |
3943 | case elfcpp::R_SPARC_TLS_LE_HIX22: |
3944 | // If we're creating a shared library, a dynamic relocation will | |
3945 | // have been created for this location, so do not apply it now. | |
3946 | if (!parameters->options().shared()) | |
3947 | { | |
2ea97941 ILT |
3948 | value -= tls_segment->memsz(); |
3949 | Reloc::hix22(view, value, addend); | |
f5314dd5 DM |
3950 | } |
3951 | break; | |
3952 | ||
3953 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
3954 | // If we're creating a shared library, a dynamic relocation will | |
3955 | // have been created for this location, so do not apply it now. | |
3956 | if (!parameters->options().shared()) | |
3957 | { | |
2ea97941 ILT |
3958 | value -= tls_segment->memsz(); |
3959 | Reloc::lox10(view, value, addend); | |
f5314dd5 DM |
3960 | } |
3961 | break; | |
3962 | } | |
3963 | } | |
3964 | ||
a5a5f7a3 DM |
3965 | // Relax a call instruction. |
3966 | ||
3967 | template<int size, bool big_endian> | |
3968 | inline void | |
3969 | Target_sparc<size, big_endian>::Relocate::relax_call( | |
3970 | Target_sparc<size, big_endian>* target, | |
3971 | unsigned char* view, | |
3972 | const elfcpp::Rela<size, big_endian>& rela, | |
3973 | section_size_type view_size) | |
3974 | { | |
3975 | typedef typename elfcpp::Swap<32, true>::Valtype Insntype; | |
3976 | Insntype *wv = reinterpret_cast<Insntype*>(view); | |
3977 | Insntype call_insn, delay_insn, set_insn; | |
3978 | uint32_t op3, reg, off; | |
3979 | ||
3980 | // This code tries to relax call instructions that meet | |
3981 | // certain criteria. | |
3982 | // | |
3983 | // The first criteria is that the call must be such that the return | |
3984 | // address which the call writes into %o7 is unused. Two sequences | |
3985 | // meet this criteria, and are used to implement tail calls. | |
3986 | // | |
3987 | // Leaf function tail call: | |
3988 | // | |
3989 | // or %o7, %g0, %ANY_REG | |
3990 | // call FUNC | |
3991 | // or %ANY_REG, %g0, %o7 | |
3992 | // | |
3993 | // Non-leaf function tail call: | |
3994 | // | |
3995 | // call FUNC | |
3996 | // restore | |
3997 | // | |
3998 | // The second criteria is that the call destination is close. If | |
3999 | // the displacement can fit in a signed 22-bit immediate field of a | |
4000 | // pre-V9 branch, we can do it. If we are generating a 64-bit | |
4001 | // object or a 32-bit object with ELF machine type EF_SPARC32PLUS, | |
4002 | // and the displacement fits in a signed 19-bit immediate field, | |
4003 | // then we can use a V9 branch. | |
4004 | ||
4005 | // Make sure the delay instruction can be safely accessed. | |
4006 | if (rela.get_r_offset() + 8 > view_size) | |
4007 | return; | |
4008 | ||
4009 | call_insn = elfcpp::Swap<32, true>::readval(wv); | |
4010 | delay_insn = elfcpp::Swap<32, true>::readval(wv + 1); | |
4011 | ||
4012 | // Make sure it is really a call instruction. | |
4013 | if (((call_insn >> 30) & 0x3) != 1) | |
4014 | return; | |
4015 | ||
4016 | if (((delay_insn >> 30) & 0x3) != 2) | |
4017 | return; | |
4018 | ||
4019 | // Accept only a restore or an integer arithmetic operation whose | |
4020 | // sole side effect is to write the %o7 register (and perhaps set | |
4021 | // the condition codes, which are considered clobbered across | |
4022 | // function calls). | |
4023 | // | |
4024 | // For example, we don't want to match a tagged addition or | |
4025 | // subtraction. We also don't want to match something like a | |
4026 | // divide. | |
4027 | // | |
4028 | // Specifically we accept add{,cc}, and{,cc}, or{,cc}, | |
4029 | // xor{,cc}, sub{,cc}, andn{,cc}, orn{,cc}, and xnor{,cc}. | |
4030 | ||
4031 | op3 = (delay_insn >> 19) & 0x3f; | |
4032 | reg = (delay_insn >> 25) & 0x1f; | |
4033 | if (op3 != 0x3d | |
4034 | && ((op3 & 0x28) != 0 || reg != 15)) | |
4035 | return; | |
4036 | ||
4037 | // For non-restore instructions, make sure %o7 isn't | |
4038 | // an input. | |
4039 | if (op3 != 0x3d) | |
4040 | { | |
4041 | // First check RS1 | |
4042 | reg = (delay_insn >> 14) & 0x15; | |
4043 | if (reg == 15) | |
4044 | return; | |
4045 | ||
4046 | // And if non-immediate, check RS2 | |
4047 | if (((delay_insn >> 13) & 1) == 0) | |
4048 | { | |
4049 | reg = (delay_insn & 0x1f); | |
4050 | if (reg == 15) | |
4051 | return; | |
4052 | } | |
4053 | } | |
4054 | ||
4055 | // Now check the branch distance. We are called after the | |
4056 | // call has been relocated, so we just have to peek at the | |
4057 | // offset contained in the instruction. | |
4058 | off = call_insn & 0x3fffffff; | |
4059 | if ((off & 0x3fe00000) != 0 | |
4060 | && (off & 0x3fe00000) != 0x3fe00000) | |
4061 | return; | |
4062 | ||
4063 | if ((size == 64 || target->elf_machine_ == elfcpp::EM_SPARC32PLUS) | |
4064 | && ((off & 0x3c0000) == 0 | |
4065 | || (off & 0x3c0000) == 0x3c0000)) | |
4066 | { | |
4067 | // ba,pt %xcc, FUNC | |
4068 | call_insn = 0x10680000 | (off & 0x07ffff); | |
4069 | } | |
4070 | else | |
4071 | { | |
4072 | // ba FUNC | |
4073 | call_insn = 0x10800000 | (off & 0x3fffff); | |
4074 | } | |
4075 | elfcpp::Swap<32, true>::writeval(wv, call_insn); | |
4076 | ||
4077 | // See if we can NOP out the delay slot instruction. We peek | |
4078 | // at the instruction before the call to make sure we're dealing | |
4079 | // with exactly the: | |
4080 | // | |
4081 | // or %o7, %g0, %ANY_REG | |
4082 | // call | |
4083 | // or %ANY_REG, %g0, %o7 | |
4084 | // | |
4085 | // case. Otherwise this might be a tricky piece of hand written | |
4086 | // assembler calculating %o7 in some non-trivial way, and therefore | |
4087 | // we can't be sure that NOP'ing out the delay slot is safe. | |
4088 | if (op3 == 0x02 | |
4089 | && rela.get_r_offset() >= 4) | |
4090 | { | |
4091 | if ((delay_insn & ~(0x1f << 14)) != 0x9e100000) | |
4092 | return; | |
4093 | ||
4094 | set_insn = elfcpp::Swap<32, true>::readval(wv - 1); | |
4095 | if ((set_insn & ~(0x1f << 25)) != 0x8013c000) | |
4096 | return; | |
4097 | ||
4098 | reg = (set_insn >> 25) & 0x1f; | |
4099 | if (reg == 0 || reg == 15) | |
4100 | return; | |
4101 | if (reg != ((delay_insn >> 14) & 0x1f)) | |
4102 | return; | |
4103 | ||
4104 | // All tests pass, nop it out. | |
4105 | elfcpp::Swap<32, true>::writeval(wv + 1, sparc_nop); | |
4106 | } | |
4107 | } | |
4108 | ||
f5314dd5 DM |
4109 | // Relocate section data. |
4110 | ||
4111 | template<int size, bool big_endian> | |
4112 | void | |
4113 | Target_sparc<size, big_endian>::relocate_section( | |
4114 | const Relocate_info<size, big_endian>* relinfo, | |
4115 | unsigned int sh_type, | |
4116 | const unsigned char* prelocs, | |
4117 | size_t reloc_count, | |
4118 | Output_section* output_section, | |
4119 | bool needs_special_offset_handling, | |
4120 | unsigned char* view, | |
4121 | typename elfcpp::Elf_types<size>::Elf_Addr address, | |
364c7fa5 ILT |
4122 | section_size_type view_size, |
4123 | const Reloc_symbol_changes* reloc_symbol_changes) | |
f5314dd5 DM |
4124 | { |
4125 | typedef Target_sparc<size, big_endian> Sparc; | |
4126 | typedef typename Target_sparc<size, big_endian>::Relocate Sparc_relocate; | |
4127 | ||
4128 | gold_assert(sh_type == elfcpp::SHT_RELA); | |
4129 | ||
4130 | gold::relocate_section<size, big_endian, Sparc, elfcpp::SHT_RELA, | |
4131 | Sparc_relocate>( | |
4132 | relinfo, | |
4133 | this, | |
4134 | prelocs, | |
4135 | reloc_count, | |
4136 | output_section, | |
4137 | needs_special_offset_handling, | |
4138 | view, | |
4139 | address, | |
364c7fa5 ILT |
4140 | view_size, |
4141 | reloc_symbol_changes); | |
f5314dd5 DM |
4142 | } |
4143 | ||
4144 | // Return the size of a relocation while scanning during a relocatable | |
4145 | // link. | |
4146 | ||
4147 | template<int size, bool big_endian> | |
4148 | unsigned int | |
4149 | Target_sparc<size, big_endian>::Relocatable_size_for_reloc::get_size_for_reloc( | |
4150 | unsigned int, | |
4151 | Relobj*) | |
4152 | { | |
4153 | // We are always SHT_RELA, so we should never get here. | |
4154 | gold_unreachable(); | |
4155 | return 0; | |
4156 | } | |
4157 | ||
4158 | // Scan the relocs during a relocatable link. | |
4159 | ||
4160 | template<int size, bool big_endian> | |
4161 | void | |
4162 | Target_sparc<size, big_endian>::scan_relocatable_relocs( | |
f5314dd5 DM |
4163 | Symbol_table* symtab, |
4164 | Layout* layout, | |
6fa2a40b | 4165 | Sized_relobj_file<size, big_endian>* object, |
f5314dd5 DM |
4166 | unsigned int data_shndx, |
4167 | unsigned int sh_type, | |
4168 | const unsigned char* prelocs, | |
4169 | size_t reloc_count, | |
4170 | Output_section* output_section, | |
4171 | bool needs_special_offset_handling, | |
4172 | size_t local_symbol_count, | |
4173 | const unsigned char* plocal_symbols, | |
4174 | Relocatable_relocs* rr) | |
4175 | { | |
4176 | gold_assert(sh_type == elfcpp::SHT_RELA); | |
4177 | ||
4178 | typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA, | |
4179 | Relocatable_size_for_reloc> Scan_relocatable_relocs; | |
4180 | ||
4181 | gold::scan_relocatable_relocs<size, big_endian, elfcpp::SHT_RELA, | |
4182 | Scan_relocatable_relocs>( | |
f5314dd5 DM |
4183 | symtab, |
4184 | layout, | |
4185 | object, | |
4186 | data_shndx, | |
4187 | prelocs, | |
4188 | reloc_count, | |
4189 | output_section, | |
4190 | needs_special_offset_handling, | |
4191 | local_symbol_count, | |
4192 | plocal_symbols, | |
4193 | rr); | |
4194 | } | |
4195 | ||
4196 | // Relocate a section during a relocatable link. | |
4197 | ||
4198 | template<int size, bool big_endian> | |
4199 | void | |
4200 | Target_sparc<size, big_endian>::relocate_for_relocatable( | |
4201 | const Relocate_info<size, big_endian>* relinfo, | |
4202 | unsigned int sh_type, | |
4203 | const unsigned char* prelocs, | |
4204 | size_t reloc_count, | |
4205 | Output_section* output_section, | |
4206 | off_t offset_in_output_section, | |
4207 | const Relocatable_relocs* rr, | |
4208 | unsigned char* view, | |
4209 | typename elfcpp::Elf_types<size>::Elf_Addr view_address, | |
4210 | section_size_type view_size, | |
4211 | unsigned char* reloc_view, | |
4212 | section_size_type reloc_view_size) | |
4213 | { | |
4214 | gold_assert(sh_type == elfcpp::SHT_RELA); | |
4215 | ||
4216 | gold::relocate_for_relocatable<size, big_endian, elfcpp::SHT_RELA>( | |
4217 | relinfo, | |
4218 | prelocs, | |
4219 | reloc_count, | |
4220 | output_section, | |
4221 | offset_in_output_section, | |
4222 | rr, | |
4223 | view, | |
4224 | view_address, | |
4225 | view_size, | |
4226 | reloc_view, | |
4227 | reloc_view_size); | |
4228 | } | |
4229 | ||
4230 | // Return the value to use for a dynamic which requires special | |
4231 | // treatment. This is how we support equality comparisons of function | |
4232 | // pointers across shared library boundaries, as described in the | |
4233 | // processor specific ABI supplement. | |
4234 | ||
4235 | template<int size, bool big_endian> | |
4236 | uint64_t | |
4237 | Target_sparc<size, big_endian>::do_dynsym_value(const Symbol* gsym) const | |
4238 | { | |
4239 | gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset()); | |
4240 | return this->plt_section()->address() + gsym->plt_offset(); | |
4241 | } | |
4242 | ||
a4d85145 DM |
4243 | // do_make_elf_object to override the same function in the base class. |
4244 | // We need to use a target-specific sub-class of | |
4245 | // Sized_relobj_file<size, big_endian> to process SPARC specific bits | |
4246 | // of the ELF headers. Hence we need to have our own ELF object creation. | |
4247 | ||
4248 | template<int size, bool big_endian> | |
4249 | Object* | |
4250 | Target_sparc<size, big_endian>::do_make_elf_object( | |
4251 | const std::string& name, | |
4252 | Input_file* input_file, | |
4253 | off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr) | |
4254 | { | |
4255 | elfcpp::Elf_Half machine = ehdr.get_e_machine(); | |
4256 | elfcpp::Elf_Word flags = ehdr.get_e_flags(); | |
4257 | elfcpp::Elf_Word omm, mm; | |
4258 | ||
4259 | switch (machine) | |
4260 | { | |
4261 | case elfcpp::EM_SPARC32PLUS: | |
4262 | this->elf_machine_ = elfcpp::EM_SPARC32PLUS; | |
4263 | break; | |
4264 | ||
4265 | case elfcpp::EM_SPARC: | |
4266 | case elfcpp::EM_SPARCV9: | |
4267 | break; | |
4268 | ||
4269 | default: | |
4270 | break; | |
4271 | } | |
4272 | ||
4273 | if (!this->elf_flags_set_) | |
4274 | { | |
4275 | this->elf_flags_ = flags; | |
4276 | this->elf_flags_set_ = true; | |
4277 | } | |
4278 | else | |
4279 | { | |
4280 | // Accumulate cpu feature bits. | |
4281 | this->elf_flags_ |= (flags & (elfcpp::EF_SPARC_32PLUS | |
4282 | | elfcpp::EF_SPARC_SUN_US1 | |
4283 | | elfcpp::EF_SPARC_HAL_R1 | |
4284 | | elfcpp::EF_SPARC_SUN_US3)); | |
4285 | ||
4286 | // Bump the memory model setting to the most restrictive | |
4287 | // one we encounter. | |
4288 | omm = (this->elf_flags_ & elfcpp::EF_SPARCV9_MM); | |
4289 | mm = (flags & elfcpp::EF_SPARCV9_MM); | |
4290 | if (omm != mm) | |
4291 | { | |
4292 | if (mm == elfcpp::EF_SPARCV9_TSO) | |
4293 | { | |
4294 | this->elf_flags_ &= ~elfcpp::EF_SPARCV9_MM; | |
4295 | this->elf_flags_ |= elfcpp::EF_SPARCV9_TSO; | |
4296 | } | |
4297 | else if (mm == elfcpp::EF_SPARCV9_PSO | |
4298 | && omm == elfcpp::EF_SPARCV9_RMO) | |
4299 | { | |
4300 | this->elf_flags_ &= ~elfcpp::EF_SPARCV9_MM; | |
4301 | this->elf_flags_ |= elfcpp::EF_SPARCV9_PSO; | |
4302 | } | |
4303 | } | |
4304 | } | |
4305 | ||
4306 | // Validate that the little-endian flag matches how we've | |
4307 | // been instantiated. | |
4308 | if (!(flags & elfcpp::EF_SPARC_LEDATA) != big_endian) | |
4309 | { | |
4310 | if (big_endian) | |
4311 | gold_error(_("%s: little endian elf flag set on BE object"), | |
4312 | name.c_str()); | |
4313 | else | |
4314 | gold_error(_("%s: little endian elf flag clear on LE object"), | |
4315 | name.c_str()); | |
4316 | } | |
4317 | ||
4318 | return Target::do_make_elf_object(name, input_file, offset, ehdr); | |
4319 | } | |
4320 | ||
4321 | // Adjust ELF file header. | |
4322 | ||
4323 | template<int size, bool big_endian> | |
4324 | void | |
4325 | Target_sparc<size, big_endian>::do_adjust_elf_header( | |
4326 | unsigned char* view, | |
4327 | int len) const | |
4328 | { | |
4329 | elfcpp::Ehdr_write<size, big_endian> oehdr(view); | |
4330 | ||
4331 | oehdr.put_e_machine(this->elf_machine_); | |
4332 | oehdr.put_e_flags(this->elf_flags_); | |
4333 | ||
4334 | Sized_target<size, big_endian>::do_adjust_elf_header(view, len); | |
4335 | } | |
4336 | ||
f5314dd5 DM |
4337 | // The selector for sparc object files. |
4338 | ||
4339 | template<int size, bool big_endian> | |
4340 | class Target_selector_sparc : public Target_selector | |
4341 | { | |
4342 | public: | |
4343 | Target_selector_sparc() | |
4344 | : Target_selector(elfcpp::EM_NONE, size, big_endian, | |
03ef7571 ILT |
4345 | (size == 64 ? "elf64-sparc" : "elf32-sparc"), |
4346 | (size == 64 ? "elf64_sparc" : "elf32_sparc")) | |
f5314dd5 DM |
4347 | { } |
4348 | ||
2ea97941 | 4349 | Target* do_recognize(int machine, int, int) |
f5314dd5 DM |
4350 | { |
4351 | switch (size) | |
4352 | { | |
4353 | case 64: | |
2ea97941 | 4354 | if (machine != elfcpp::EM_SPARCV9) |
f5314dd5 DM |
4355 | return NULL; |
4356 | break; | |
4357 | ||
4358 | case 32: | |
2ea97941 ILT |
4359 | if (machine != elfcpp::EM_SPARC |
4360 | && machine != elfcpp::EM_SPARC32PLUS) | |
f5314dd5 DM |
4361 | return NULL; |
4362 | break; | |
4363 | ||
4364 | default: | |
4365 | return NULL; | |
4366 | } | |
4367 | ||
7f055c20 | 4368 | return this->instantiate_target(); |
f5314dd5 DM |
4369 | } |
4370 | ||
4371 | Target* do_instantiate_target() | |
7f055c20 | 4372 | { return new Target_sparc<size, big_endian>(); } |
f5314dd5 DM |
4373 | }; |
4374 | ||
4375 | Target_selector_sparc<32, true> target_selector_sparc32; | |
4376 | Target_selector_sparc<64, true> target_selector_sparc64; | |
4377 | ||
4378 | } // End anonymous namespace. |