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