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