Commit | Line | Data |
---|---|---|
f5314dd5 DM |
1 | // sparc.cc -- sparc target support for gold. |
2 | ||
3 | // Copyright 2008 Free Software Foundation, Inc. | |
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" | |
43 | ||
44 | namespace | |
45 | { | |
46 | ||
47 | using namespace gold; | |
48 | ||
49 | template<int size, bool big_endian> | |
50 | class Output_data_plt_sparc; | |
51 | ||
52 | template<int size, bool big_endian> | |
53 | class Target_sparc : public Sized_target<size, big_endian> | |
54 | { | |
55 | public: | |
56 | typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian> Reloc_section; | |
57 | ||
58 | Target_sparc() | |
59 | : Sized_target<size, big_endian>(&sparc_info), | |
60 | got_(NULL), plt_(NULL), rela_dyn_(NULL), | |
12c0daef ILT |
61 | copy_relocs_(elfcpp::R_SPARC_COPY), dynbss_(NULL), |
62 | got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL) | |
f5314dd5 DM |
63 | { |
64 | } | |
65 | ||
66 | // Scan the relocations to look for symbol adjustments. | |
67 | void | |
68 | scan_relocs(const General_options& options, | |
69 | Symbol_table* symtab, | |
70 | Layout* layout, | |
71 | Sized_relobj<size, big_endian>* object, | |
72 | unsigned int data_shndx, | |
73 | unsigned int sh_type, | |
74 | const unsigned char* prelocs, | |
75 | size_t reloc_count, | |
76 | Output_section* output_section, | |
77 | bool needs_special_offset_handling, | |
78 | size_t local_symbol_count, | |
79 | const unsigned char* plocal_symbols); | |
80 | // Finalize the sections. | |
81 | void | |
82 | do_finalize_sections(Layout*); | |
83 | ||
84 | // Return the value to use for a dynamic which requires special | |
85 | // treatment. | |
86 | uint64_t | |
87 | do_dynsym_value(const Symbol*) const; | |
88 | ||
89 | // Relocate a section. | |
90 | void | |
91 | relocate_section(const Relocate_info<size, big_endian>*, | |
92 | unsigned int sh_type, | |
93 | const unsigned char* prelocs, | |
94 | size_t reloc_count, | |
95 | Output_section* output_section, | |
96 | bool needs_special_offset_handling, | |
97 | unsigned char* view, | |
98 | typename elfcpp::Elf_types<size>::Elf_Addr view_address, | |
99 | section_size_type view_size); | |
100 | ||
101 | // Scan the relocs during a relocatable link. | |
102 | void | |
103 | scan_relocatable_relocs(const General_options& options, | |
104 | Symbol_table* symtab, | |
105 | Layout* layout, | |
106 | Sized_relobj<size, big_endian>* object, | |
107 | unsigned int data_shndx, | |
108 | unsigned int sh_type, | |
109 | const unsigned char* prelocs, | |
110 | size_t reloc_count, | |
111 | Output_section* output_section, | |
112 | bool needs_special_offset_handling, | |
113 | size_t local_symbol_count, | |
114 | const unsigned char* plocal_symbols, | |
115 | Relocatable_relocs*); | |
116 | ||
117 | // Relocate a section during a relocatable link. | |
118 | void | |
119 | relocate_for_relocatable(const Relocate_info<size, big_endian>*, | |
120 | unsigned int sh_type, | |
121 | const unsigned char* prelocs, | |
122 | size_t reloc_count, | |
123 | Output_section* output_section, | |
124 | off_t offset_in_output_section, | |
125 | const Relocatable_relocs*, | |
126 | unsigned char* view, | |
127 | typename elfcpp::Elf_types<size>::Elf_Addr view_address, | |
128 | section_size_type view_size, | |
129 | unsigned char* reloc_view, | |
130 | section_size_type reloc_view_size); | |
131 | // Return whether SYM is defined by the ABI. | |
132 | bool | |
133 | do_is_defined_by_abi(Symbol* sym) const | |
134 | { | |
135 | // XXX Really need to support this better... | |
136 | if (sym->type() == elfcpp::STT_SPARC_REGISTER) | |
137 | return 1; | |
138 | ||
139 | return strcmp(sym->name(), "___tls_get_addr") == 0; | |
140 | } | |
141 | ||
142 | // Return the size of the GOT section. | |
143 | section_size_type | |
144 | got_size() | |
145 | { | |
146 | gold_assert(this->got_ != NULL); | |
147 | return this->got_->data_size(); | |
148 | } | |
149 | ||
150 | private: | |
151 | ||
152 | // The class which scans relocations. | |
32b769e1 | 153 | class Scan |
f5314dd5 | 154 | { |
32b769e1 DM |
155 | public: |
156 | Scan() | |
157 | : issued_non_pic_error_(false) | |
158 | { } | |
159 | ||
f5314dd5 DM |
160 | inline void |
161 | local(const General_options& options, Symbol_table* symtab, | |
162 | Layout* layout, Target_sparc* target, | |
163 | Sized_relobj<size, big_endian>* object, | |
164 | unsigned int data_shndx, | |
165 | Output_section* output_section, | |
166 | const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type, | |
167 | const elfcpp::Sym<size, big_endian>& lsym); | |
168 | ||
169 | inline void | |
170 | global(const General_options& options, Symbol_table* symtab, | |
171 | Layout* layout, Target_sparc* target, | |
172 | Sized_relobj<size, big_endian>* object, | |
173 | unsigned int data_shndx, | |
174 | Output_section* output_section, | |
175 | const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type, | |
176 | Symbol* gsym); | |
177 | ||
32b769e1 | 178 | private: |
f5314dd5 DM |
179 | static void |
180 | unsupported_reloc_local(Sized_relobj<size, big_endian>*, | |
181 | unsigned int r_type); | |
182 | ||
183 | static void | |
184 | unsupported_reloc_global(Sized_relobj<size, big_endian>*, | |
185 | unsigned int r_type, Symbol*); | |
186 | ||
187 | static void | |
188 | generate_tls_call(Symbol_table* symtab, Layout* layout, | |
189 | Target_sparc* target); | |
32b769e1 DM |
190 | |
191 | void | |
192 | check_non_pic(Relobj*, unsigned int r_type); | |
193 | ||
194 | // Whether we have issued an error about a non-PIC compilation. | |
195 | bool issued_non_pic_error_; | |
f5314dd5 DM |
196 | }; |
197 | ||
198 | // The class which implements relocation. | |
199 | class Relocate | |
200 | { | |
201 | public: | |
202 | Relocate() | |
203 | : ignore_gd_add_(false) | |
204 | { } | |
205 | ||
206 | ~Relocate() | |
207 | { | |
208 | if (this->ignore_gd_add_) | |
209 | { | |
210 | // FIXME: This needs to specify the location somehow. | |
211 | gold_error(_("missing expected TLS relocation")); | |
212 | } | |
213 | } | |
214 | ||
215 | // Do a relocation. Return false if the caller should not issue | |
216 | // any warnings about this relocation. | |
217 | inline bool | |
218 | relocate(const Relocate_info<size, big_endian>*, Target_sparc*, | |
219 | size_t relnum, const elfcpp::Rela<size, big_endian>&, | |
220 | unsigned int r_type, const Sized_symbol<size>*, | |
221 | const Symbol_value<size>*, | |
222 | unsigned char*, | |
223 | typename elfcpp::Elf_types<size>::Elf_Addr, | |
224 | section_size_type); | |
225 | ||
226 | private: | |
227 | // Do a TLS relocation. | |
228 | inline void | |
229 | relocate_tls(const Relocate_info<size, big_endian>*, Target_sparc* target, | |
230 | size_t relnum, const elfcpp::Rela<size, big_endian>&, | |
231 | unsigned int r_type, const Sized_symbol<size>*, | |
232 | const Symbol_value<size>*, | |
233 | unsigned char*, | |
234 | typename elfcpp::Elf_types<size>::Elf_Addr, | |
235 | section_size_type); | |
236 | ||
237 | // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD | |
238 | bool ignore_gd_add_; | |
239 | }; | |
240 | ||
241 | // A class which returns the size required for a relocation type, | |
242 | // used while scanning relocs during a relocatable link. | |
243 | class Relocatable_size_for_reloc | |
244 | { | |
245 | public: | |
246 | unsigned int | |
247 | get_size_for_reloc(unsigned int, Relobj*); | |
248 | }; | |
249 | ||
250 | // Get the GOT section, creating it if necessary. | |
251 | Output_data_got<size, big_endian>* | |
252 | got_section(Symbol_table*, Layout*); | |
253 | ||
254 | // Create a PLT entry for a global symbol. | |
255 | void | |
256 | make_plt_entry(Symbol_table*, Layout*, Symbol*); | |
257 | ||
258 | // Create a GOT entry for the TLS module index. | |
259 | unsigned int | |
260 | got_mod_index_entry(Symbol_table* symtab, Layout* layout, | |
261 | Sized_relobj<size, big_endian>* object); | |
262 | ||
263 | // Return the gsym for "__tls_get_addr". Cache if not already | |
264 | // cached. | |
265 | Symbol* | |
266 | tls_get_addr_sym(Symbol_table* symtab) | |
267 | { | |
268 | if (!this->tls_get_addr_sym_) | |
269 | this->tls_get_addr_sym_ = symtab->lookup("__tls_get_addr", NULL); | |
270 | gold_assert(this->tls_get_addr_sym_); | |
271 | return this->tls_get_addr_sym_; | |
272 | } | |
273 | ||
274 | // Get the PLT section. | |
275 | const Output_data_plt_sparc<size, big_endian>* | |
276 | plt_section() const | |
277 | { | |
278 | gold_assert(this->plt_ != NULL); | |
279 | return this->plt_; | |
280 | } | |
281 | ||
282 | // Get the dynamic reloc section, creating it if necessary. | |
283 | Reloc_section* | |
284 | rela_dyn_section(Layout*); | |
285 | ||
286 | // Return true if the symbol may need a COPY relocation. | |
287 | // References from an executable object to non-function symbols | |
288 | // defined in a dynamic object may need a COPY relocation. | |
289 | bool | |
290 | may_need_copy_reloc(Symbol* gsym) | |
291 | { | |
292 | return (!parameters->options().shared() | |
293 | && gsym->is_from_dynobj() | |
294 | && gsym->type() != elfcpp::STT_FUNC); | |
295 | } | |
296 | ||
297 | // Copy a relocation against a global symbol. | |
298 | void | |
12c0daef ILT |
299 | copy_reloc(Symbol_table* symtab, Layout* layout, Relobj* object, |
300 | unsigned int shndx, Output_section* output_section, | |
301 | Symbol* sym, const elfcpp::Rela<size, big_endian>& reloc) | |
302 | { | |
303 | this->copy_relocs_.copy_reloc(symtab, layout, | |
304 | symtab->get_sized_symbol<size>(sym), | |
305 | object, shndx, output_section, | |
306 | reloc, this->rela_dyn_section(layout)); | |
307 | } | |
f5314dd5 DM |
308 | |
309 | // Information about this specific target which we pass to the | |
310 | // general Target structure. | |
311 | static Target::Target_info sparc_info; | |
312 | ||
313 | // The types of GOT entries needed for this platform. | |
314 | enum Got_type | |
315 | { | |
316 | GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol | |
317 | GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset | |
318 | GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair | |
319 | }; | |
320 | ||
321 | // The GOT section. | |
322 | Output_data_got<size, big_endian>* got_; | |
323 | // The PLT section. | |
324 | Output_data_plt_sparc<size, big_endian>* plt_; | |
325 | // The dynamic reloc section. | |
326 | Reloc_section* rela_dyn_; | |
327 | // Relocs saved to avoid a COPY reloc. | |
12c0daef | 328 | Copy_relocs<elfcpp::SHT_RELA, size, big_endian> copy_relocs_; |
f5314dd5 DM |
329 | // Space for variables copied with a COPY reloc. |
330 | Output_data_space* dynbss_; | |
331 | // Offset of the GOT entry for the TLS module index; | |
332 | unsigned int got_mod_index_offset_; | |
333 | // Cached pointer to __tls_get_addr symbol | |
334 | Symbol* tls_get_addr_sym_; | |
335 | }; | |
336 | ||
337 | template<> | |
338 | Target::Target_info Target_sparc<32, true>::sparc_info = | |
339 | { | |
340 | 32, // size | |
341 | true, // is_big_endian | |
342 | elfcpp::EM_SPARC, // machine_code | |
343 | false, // has_make_symbol | |
344 | false, // has_resolve | |
345 | false, // has_code_fill | |
346 | true, // is_default_stack_executable | |
347 | '\0', // wrap_char | |
348 | "/usr/lib/ld.so.1", // dynamic_linker | |
349 | 0x00010000, // default_text_segment_address | |
350 | 64 * 1024, // abi_pagesize (overridable by -z max-page-size) | |
351 | 8 * 1024 // common_pagesize (overridable by -z common-page-size) | |
352 | }; | |
353 | ||
354 | template<> | |
355 | Target::Target_info Target_sparc<64, true>::sparc_info = | |
356 | { | |
357 | 64, // size | |
358 | true, // is_big_endian | |
359 | elfcpp::EM_SPARCV9, // machine_code | |
360 | false, // has_make_symbol | |
361 | false, // has_resolve | |
362 | false, // has_code_fill | |
363 | true, // is_default_stack_executable | |
364 | '\0', // wrap_char | |
365 | "/usr/lib/sparcv9/ld.so.1", // dynamic_linker | |
366 | 0x100000, // default_text_segment_address | |
367 | 64 * 1024, // abi_pagesize (overridable by -z max-page-size) | |
368 | 8 * 1024 // common_pagesize (overridable by -z common-page-size) | |
369 | }; | |
370 | ||
371 | // We have to take care here, even when operating in little-endian | |
372 | // mode, sparc instructions are still big endian. | |
373 | template<int size, bool big_endian> | |
374 | class Sparc_relocate_functions | |
375 | { | |
376 | private: | |
377 | // Do a simple relocation with the addend in the relocation. | |
378 | template<int valsize> | |
379 | static inline void | |
380 | rela(unsigned char* view, | |
381 | unsigned int right_shift, | |
382 | typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask, | |
383 | typename elfcpp::Swap<size, big_endian>::Valtype value, | |
384 | typename elfcpp::Swap<size, big_endian>::Valtype addend) | |
385 | { | |
386 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; | |
387 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
388 | Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv); | |
389 | Valtype reloc = ((value + addend) >> right_shift); | |
390 | ||
391 | val &= ~dst_mask; | |
392 | reloc &= dst_mask; | |
393 | ||
394 | elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc); | |
395 | } | |
396 | ||
397 | // Do a simple relocation using a symbol value with the addend in | |
398 | // the relocation. | |
399 | template<int valsize> | |
400 | static inline void | |
401 | rela(unsigned char* view, | |
402 | unsigned int right_shift, | |
403 | typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask, | |
404 | const Sized_relobj<size, big_endian>* object, | |
405 | const Symbol_value<size>* psymval, | |
406 | typename elfcpp::Swap<valsize, big_endian>::Valtype addend) | |
407 | { | |
408 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; | |
409 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
410 | Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv); | |
411 | Valtype reloc = (psymval->value(object, addend) >> right_shift); | |
412 | ||
413 | val &= ~dst_mask; | |
414 | reloc &= dst_mask; | |
415 | ||
416 | elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc); | |
417 | } | |
418 | ||
419 | // Do a simple relocation using a symbol value with the addend in | |
420 | // the relocation, unaligned. | |
421 | template<int valsize> | |
422 | static inline void | |
423 | rela_ua(unsigned char* view, | |
424 | unsigned int right_shift, elfcpp::Elf_Xword dst_mask, | |
425 | const Sized_relobj<size, big_endian>* object, | |
426 | const Symbol_value<size>* psymval, | |
427 | typename elfcpp::Swap<size, big_endian>::Valtype addend) | |
428 | { | |
429 | typedef typename elfcpp::Swap_unaligned<valsize, | |
430 | big_endian>::Valtype Valtype; | |
431 | unsigned char* wv = view; | |
432 | Valtype val = elfcpp::Swap_unaligned<valsize, big_endian>::readval(wv); | |
433 | Valtype reloc = (psymval->value(object, addend) >> right_shift); | |
434 | ||
435 | val &= ~dst_mask; | |
436 | reloc &= dst_mask; | |
437 | ||
438 | elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, val | reloc); | |
439 | } | |
440 | ||
441 | // Do a simple PC relative relocation with a Symbol_value with the | |
442 | // addend in the relocation. | |
443 | template<int valsize> | |
444 | static inline void | |
445 | pcrela(unsigned char* view, | |
446 | unsigned int right_shift, | |
447 | typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask, | |
448 | const Sized_relobj<size, big_endian>* object, | |
449 | const Symbol_value<size>* psymval, | |
450 | typename elfcpp::Swap<size, big_endian>::Valtype addend, | |
451 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
452 | { | |
453 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; | |
454 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
455 | Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv); | |
456 | Valtype reloc = ((psymval->value(object, addend) - address) | |
457 | >> right_shift); | |
458 | ||
459 | val &= ~dst_mask; | |
460 | reloc &= dst_mask; | |
461 | ||
462 | elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc); | |
463 | } | |
464 | ||
465 | template<int valsize> | |
466 | static inline void | |
467 | pcrela_unaligned(unsigned char* view, | |
468 | const Sized_relobj<size, big_endian>* object, | |
469 | const Symbol_value<size>* psymval, | |
470 | typename elfcpp::Swap<size, big_endian>::Valtype addend, | |
471 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
472 | { | |
473 | typedef typename elfcpp::Swap_unaligned<valsize, | |
474 | big_endian>::Valtype Valtype; | |
475 | unsigned char* wv = view; | |
476 | Valtype reloc = (psymval->value(object, addend) - address); | |
477 | ||
478 | elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, reloc); | |
479 | } | |
480 | ||
481 | typedef Sparc_relocate_functions<size, big_endian> This; | |
482 | typedef Sparc_relocate_functions<size, true> This_insn; | |
483 | ||
484 | public: | |
485 | // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2 | |
486 | static inline void | |
487 | wdisp30(unsigned char* view, | |
488 | const Sized_relobj<size, big_endian>* object, | |
489 | const Symbol_value<size>* psymval, | |
490 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
491 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
492 | { | |
493 | This_insn::template pcrela<32>(view, 2, 0x3fffffff, object, | |
494 | psymval, addend, address); | |
495 | } | |
496 | ||
497 | // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2 | |
498 | static inline void | |
499 | wdisp22(unsigned char* view, | |
500 | const Sized_relobj<size, big_endian>* object, | |
501 | const Symbol_value<size>* psymval, | |
502 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
503 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
504 | { | |
505 | This_insn::template pcrela<32>(view, 2, 0x003fffff, object, | |
506 | psymval, addend, address); | |
507 | } | |
508 | ||
509 | // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2 | |
510 | static inline void | |
511 | wdisp19(unsigned char* view, | |
512 | const Sized_relobj<size, big_endian>* object, | |
513 | const Symbol_value<size>* psymval, | |
514 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
515 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
516 | { | |
517 | This_insn::template pcrela<32>(view, 2, 0x0007ffff, object, | |
518 | psymval, addend, address); | |
519 | } | |
520 | ||
521 | // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2 | |
522 | static inline void | |
523 | wdisp16(unsigned char* view, | |
524 | const Sized_relobj<size, big_endian>* object, | |
525 | const Symbol_value<size>* psymval, | |
526 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
527 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
528 | { | |
529 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
530 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
531 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
532 | Valtype reloc = ((psymval->value(object, addend) - address) | |
533 | >> 2); | |
534 | ||
535 | // The relocation value is split between the low 14 bits, | |
536 | // and bits 20-21. | |
537 | val &= ~((0x3 << 20) | 0x3fff); | |
538 | reloc = (((reloc & 0xc000) << (20 - 14)) | |
539 | | (reloc & 0x3ffff)); | |
540 | ||
541 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
542 | } | |
543 | ||
544 | // R_SPARC_PC22: (Symbol + Addend - Address) >> 10 | |
545 | static inline void | |
546 | pc22(unsigned char* view, | |
547 | const Sized_relobj<size, big_endian>* object, | |
548 | const Symbol_value<size>* psymval, | |
549 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
550 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
551 | { | |
552 | This_insn::template pcrela<32>(view, 10, 0x003fffff, object, | |
553 | psymval, addend, address); | |
554 | } | |
555 | ||
556 | // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff | |
557 | static inline void | |
558 | pc10(unsigned char* view, | |
559 | const Sized_relobj<size, big_endian>* object, | |
560 | const Symbol_value<size>* psymval, | |
561 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
562 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
563 | { | |
564 | This_insn::template pcrela<32>(view, 0, 0x000003ff, object, | |
565 | psymval, addend, address); | |
566 | } | |
567 | ||
568 | // R_SPARC_HI22: (Symbol + Addend) >> 10 | |
569 | static inline void | |
570 | hi22(unsigned char* view, | |
571 | typename elfcpp::Elf_types<size>::Elf_Addr value, | |
572 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
573 | { | |
574 | This_insn::template rela<32>(view, 10, 0x003fffff, value, addend); | |
575 | } | |
576 | ||
577 | // R_SPARC_HI22: (Symbol + Addend) >> 10 | |
578 | static inline void | |
579 | hi22(unsigned char* view, | |
580 | const Sized_relobj<size, big_endian>* object, | |
581 | const Symbol_value<size>* psymval, | |
582 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
583 | { | |
584 | This_insn::template rela<32>(view, 10, 0x003fffff, object, psymval, addend); | |
585 | } | |
586 | ||
587 | // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10 | |
588 | static inline void | |
589 | pcplt22(unsigned char* view, | |
590 | const Sized_relobj<size, big_endian>* object, | |
591 | const Symbol_value<size>* psymval, | |
592 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
593 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
594 | { | |
595 | This_insn::template pcrela<32>(view, 10, 0x003fffff, object, | |
596 | psymval, addend, address); | |
597 | } | |
598 | ||
599 | // R_SPARC_LO10: (Symbol + Addend) & 0x3ff | |
600 | static inline void | |
601 | lo10(unsigned char* view, | |
602 | typename elfcpp::Elf_types<size>::Elf_Addr value, | |
603 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
604 | { | |
605 | This_insn::template rela<32>(view, 0, 0x000003ff, value, addend); | |
606 | } | |
607 | ||
608 | // R_SPARC_LO10: (Symbol + Addend) & 0x3ff | |
609 | static inline void | |
610 | lo10(unsigned char* view, | |
611 | const Sized_relobj<size, big_endian>* object, | |
612 | const Symbol_value<size>* psymval, | |
613 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
614 | { | |
615 | This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend); | |
616 | } | |
617 | ||
618 | // R_SPARC_LO10: (Symbol + Addend) & 0x3ff | |
619 | static inline void | |
620 | lo10(unsigned char* view, | |
621 | const Sized_relobj<size, big_endian>* object, | |
622 | const Symbol_value<size>* psymval, | |
623 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
624 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
625 | { | |
626 | This_insn::template pcrela<32>(view, 0, 0x000003ff, object, | |
627 | psymval, addend, address); | |
628 | } | |
629 | ||
630 | // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2 | |
631 | static inline void | |
632 | olo10(unsigned char* view, | |
633 | const Sized_relobj<size, big_endian>* object, | |
634 | const Symbol_value<size>* psymval, | |
635 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
636 | typename elfcpp::Elf_types<size>::Elf_Addr addend2) | |
637 | { | |
638 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
639 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
640 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
641 | Valtype reloc = psymval->value(object, addend); | |
642 | ||
643 | val &= ~0x1fff; | |
644 | reloc &= 0x3ff; | |
645 | reloc += addend2; | |
646 | reloc &= 0x1fff; | |
647 | ||
648 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
649 | } | |
650 | ||
651 | // R_SPARC_22: (Symbol + Addend) | |
652 | static inline void | |
653 | rela32_22(unsigned char* view, | |
654 | const Sized_relobj<size, big_endian>* object, | |
655 | const Symbol_value<size>* psymval, | |
656 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
657 | { | |
658 | This_insn::template rela<32>(view, 0, 0x003fffff, object, psymval, addend); | |
659 | } | |
660 | ||
661 | // R_SPARC_13: (Symbol + Addend) | |
662 | static inline void | |
663 | rela32_13(unsigned char* view, | |
664 | typename elfcpp::Elf_types<size>::Elf_Addr value, | |
665 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
666 | { | |
667 | This_insn::template rela<32>(view, 0, 0x00001fff, value, addend); | |
668 | } | |
669 | ||
670 | // R_SPARC_13: (Symbol + Addend) | |
671 | static inline void | |
672 | rela32_13(unsigned char* view, | |
673 | const Sized_relobj<size, big_endian>* object, | |
674 | const Symbol_value<size>* psymval, | |
675 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
676 | { | |
677 | This_insn::template rela<32>(view, 0, 0x00001fff, object, psymval, addend); | |
678 | } | |
679 | ||
680 | // R_SPARC_UA16: (Symbol + Addend) | |
681 | static inline void | |
682 | ua16(unsigned char* view, | |
683 | const Sized_relobj<size, big_endian>* object, | |
684 | const Symbol_value<size>* psymval, | |
685 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
686 | { | |
687 | This::template rela_ua<16>(view, 0, 0xffff, object, psymval, addend); | |
688 | } | |
689 | ||
690 | // R_SPARC_UA32: (Symbol + Addend) | |
691 | static inline void | |
692 | ua32(unsigned char* view, | |
693 | const Sized_relobj<size, big_endian>* object, | |
694 | const Symbol_value<size>* psymval, | |
695 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
696 | { | |
697 | This::template rela_ua<32>(view, 0, 0xffffffff, object, psymval, addend); | |
698 | } | |
699 | ||
700 | // R_SPARC_UA64: (Symbol + Addend) | |
701 | static inline void | |
702 | ua64(unsigned char* view, | |
703 | const Sized_relobj<size, big_endian>* object, | |
704 | const Symbol_value<size>* psymval, | |
705 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
706 | { | |
707 | This::template rela_ua<64>(view, 0, ~(elfcpp::Elf_Xword) 0, | |
708 | object, psymval, addend); | |
709 | } | |
710 | ||
711 | // R_SPARC_DISP8: (Symbol + Addend - Address) | |
712 | static inline void | |
713 | disp8(unsigned char* view, | |
714 | const Sized_relobj<size, big_endian>* object, | |
715 | const Symbol_value<size>* psymval, | |
716 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
717 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
718 | { | |
719 | This::template pcrela_unaligned<8>(view, object, psymval, | |
720 | addend, address); | |
721 | } | |
722 | ||
723 | // R_SPARC_DISP16: (Symbol + Addend - Address) | |
724 | static inline void | |
725 | disp16(unsigned char* view, | |
726 | const Sized_relobj<size, big_endian>* object, | |
727 | const Symbol_value<size>* psymval, | |
728 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
729 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
730 | { | |
731 | This::template pcrela_unaligned<16>(view, object, psymval, | |
732 | addend, address); | |
733 | } | |
734 | ||
735 | // R_SPARC_DISP32: (Symbol + Addend - Address) | |
736 | static inline void | |
737 | disp32(unsigned char* view, | |
738 | const Sized_relobj<size, big_endian>* object, | |
739 | const Symbol_value<size>* psymval, | |
740 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
741 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
742 | { | |
743 | This::template pcrela_unaligned<32>(view, object, psymval, | |
744 | addend, address); | |
745 | } | |
746 | ||
747 | // R_SPARC_DISP64: (Symbol + Addend - Address) | |
748 | static inline void | |
749 | disp64(unsigned char* view, | |
750 | const Sized_relobj<size, big_endian>* object, | |
751 | const Symbol_value<size>* psymval, | |
752 | elfcpp::Elf_Xword addend, | |
753 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
754 | { | |
755 | This::template pcrela_unaligned<64>(view, object, psymval, | |
756 | addend, address); | |
757 | } | |
758 | ||
759 | // R_SPARC_H44: (Symbol + Addend) >> 22 | |
760 | static inline void | |
761 | h44(unsigned char* view, | |
762 | const Sized_relobj<size, big_endian>* object, | |
763 | const Symbol_value<size>* psymval, | |
764 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
765 | { | |
766 | This_insn::template rela<32>(view, 22, 0x003fffff, object, psymval, addend); | |
767 | } | |
768 | ||
769 | // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff | |
770 | static inline void | |
771 | m44(unsigned char* view, | |
772 | const Sized_relobj<size, big_endian>* object, | |
773 | const Symbol_value<size>* psymval, | |
774 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
775 | { | |
776 | This_insn::template rela<32>(view, 12, 0x000003ff, object, psymval, addend); | |
777 | } | |
778 | ||
779 | // R_SPARC_L44: (Symbol + Addend) & 0xfff | |
780 | static inline void | |
781 | l44(unsigned char* view, | |
782 | const Sized_relobj<size, big_endian>* object, | |
783 | const Symbol_value<size>* psymval, | |
784 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
785 | { | |
786 | This_insn::template rela<32>(view, 0, 0x00000fff, object, psymval, addend); | |
787 | } | |
788 | ||
789 | // R_SPARC_HH22: (Symbol + Addend) >> 42 | |
790 | static inline void | |
791 | hh22(unsigned char* view, | |
792 | const Sized_relobj<size, big_endian>* object, | |
793 | const Symbol_value<size>* psymval, | |
794 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
795 | { | |
796 | This_insn::template rela<32>(view, 42, 0x003fffff, object, psymval, addend); | |
797 | } | |
798 | ||
799 | // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42 | |
800 | static inline void | |
801 | pc_hh22(unsigned char* view, | |
802 | const Sized_relobj<size, big_endian>* object, | |
803 | const Symbol_value<size>* psymval, | |
804 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
805 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
806 | { | |
807 | This_insn::template pcrela<32>(view, 42, 0x003fffff, object, | |
808 | psymval, addend, address); | |
809 | } | |
810 | ||
811 | // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff | |
812 | static inline void | |
813 | hm10(unsigned char* view, | |
814 | const Sized_relobj<size, big_endian>* object, | |
815 | const Symbol_value<size>* psymval, | |
816 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
817 | { | |
818 | This_insn::template rela<32>(view, 32, 0x000003ff, object, psymval, addend); | |
819 | } | |
820 | ||
821 | // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff | |
822 | static inline void | |
823 | pc_hm10(unsigned char* view, | |
824 | const Sized_relobj<size, big_endian>* object, | |
825 | const Symbol_value<size>* psymval, | |
826 | typename elfcpp::Elf_types<size>::Elf_Addr addend, | |
827 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
828 | { | |
829 | This_insn::template pcrela<32>(view, 32, 0x000003ff, object, | |
830 | psymval, addend, address); | |
831 | } | |
832 | ||
833 | // R_SPARC_11: (Symbol + Addend) | |
834 | static inline void | |
835 | rela32_11(unsigned char* view, | |
836 | const Sized_relobj<size, big_endian>* object, | |
837 | const Symbol_value<size>* psymval, | |
838 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
839 | { | |
840 | This_insn::template rela<32>(view, 0, 0x000007ff, object, psymval, addend); | |
841 | } | |
842 | ||
843 | // R_SPARC_10: (Symbol + Addend) | |
844 | static inline void | |
845 | rela32_10(unsigned char* view, | |
846 | const Sized_relobj<size, big_endian>* object, | |
847 | const Symbol_value<size>* psymval, | |
848 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
849 | { | |
850 | This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend); | |
851 | } | |
852 | ||
853 | // R_SPARC_7: (Symbol + Addend) | |
854 | static inline void | |
855 | rela32_7(unsigned char* view, | |
856 | const Sized_relobj<size, big_endian>* object, | |
857 | const Symbol_value<size>* psymval, | |
858 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
859 | { | |
860 | This_insn::template rela<32>(view, 0, 0x0000007f, object, psymval, addend); | |
861 | } | |
862 | ||
863 | // R_SPARC_6: (Symbol + Addend) | |
864 | static inline void | |
865 | rela32_6(unsigned char* view, | |
866 | const Sized_relobj<size, big_endian>* object, | |
867 | const Symbol_value<size>* psymval, | |
868 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
869 | { | |
870 | This_insn::template rela<32>(view, 0, 0x0000003f, object, psymval, addend); | |
871 | } | |
872 | ||
873 | // R_SPARC_5: (Symbol + Addend) | |
874 | static inline void | |
875 | rela32_5(unsigned char* view, | |
876 | const Sized_relobj<size, big_endian>* object, | |
877 | const Symbol_value<size>* psymval, | |
878 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
879 | { | |
880 | This_insn::template rela<32>(view, 0, 0x0000001f, object, psymval, addend); | |
881 | } | |
882 | ||
883 | // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10 | |
884 | static inline void | |
885 | ldo_hix22(unsigned char* view, | |
886 | typename elfcpp::Elf_types<size>::Elf_Addr value, | |
887 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
888 | { | |
889 | This_insn::hi22(view, value, addend); | |
890 | } | |
891 | ||
892 | // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff | |
893 | static inline void | |
894 | ldo_lox10(unsigned char* view, | |
895 | typename elfcpp::Elf_types<size>::Elf_Addr value, | |
896 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
897 | { | |
898 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
899 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
900 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
901 | Valtype reloc = (value + addend); | |
902 | ||
903 | val &= ~0x1fff; | |
904 | reloc &= 0x3ff; | |
905 | ||
906 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
907 | } | |
908 | ||
909 | // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10 | |
910 | static inline void | |
911 | hix22(unsigned char* view, | |
912 | typename elfcpp::Elf_types<size>::Elf_Addr value, | |
913 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
914 | { | |
915 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
916 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
917 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
918 | Valtype reloc = (value + addend); | |
919 | ||
920 | val &= ~0x3fffff; | |
921 | ||
922 | reloc ^= ~(Valtype)0; | |
923 | reloc >>= 10; | |
924 | ||
925 | reloc &= 0x3fffff; | |
926 | ||
927 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
928 | } | |
929 | ||
930 | // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10 | |
931 | static inline void | |
932 | hix22(unsigned char* view, | |
933 | const Sized_relobj<size, big_endian>* object, | |
934 | const Symbol_value<size>* psymval, | |
935 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
936 | { | |
937 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
938 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
939 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
940 | Valtype reloc = psymval->value(object, addend); | |
941 | ||
942 | val &= ~0x3fffff; | |
943 | ||
944 | reloc ^= ~(Valtype)0; | |
945 | reloc >>= 10; | |
946 | ||
947 | reloc &= 0x3fffff; | |
948 | ||
949 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
950 | } | |
951 | ||
952 | ||
953 | // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00 | |
954 | static inline void | |
955 | lox10(unsigned char* view, | |
956 | typename elfcpp::Elf_types<size>::Elf_Addr value, | |
957 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
958 | { | |
959 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
960 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
961 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
962 | Valtype reloc = (value + addend); | |
963 | ||
964 | val &= ~0x1fff; | |
965 | reloc &= 0x3ff; | |
966 | reloc |= 0x1c00; | |
967 | ||
968 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
969 | } | |
970 | ||
971 | // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00 | |
972 | static inline void | |
973 | lox10(unsigned char* view, | |
974 | const Sized_relobj<size, big_endian>* object, | |
975 | const Symbol_value<size>* psymval, | |
976 | typename elfcpp::Elf_types<size>::Elf_Addr addend) | |
977 | { | |
978 | typedef typename elfcpp::Swap<32, true>::Valtype Valtype; | |
979 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
980 | Valtype val = elfcpp::Swap<32, true>::readval(wv); | |
981 | Valtype reloc = psymval->value(object, addend); | |
982 | ||
983 | val &= ~0x1fff; | |
984 | reloc &= 0x3ff; | |
985 | reloc |= 0x1c00; | |
986 | ||
987 | elfcpp::Swap<32, true>::writeval(wv, val | reloc); | |
988 | } | |
989 | }; | |
990 | ||
991 | // Get the GOT section, creating it if necessary. | |
992 | ||
993 | template<int size, bool big_endian> | |
994 | Output_data_got<size, big_endian>* | |
995 | Target_sparc<size, big_endian>::got_section(Symbol_table* symtab, | |
996 | Layout* layout) | |
997 | { | |
998 | if (this->got_ == NULL) | |
999 | { | |
1000 | gold_assert(symtab != NULL && layout != NULL); | |
1001 | ||
1002 | this->got_ = new Output_data_got<size, big_endian>(); | |
1003 | ||
9f1d377b ILT |
1004 | Output_section* os; |
1005 | os = layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS, | |
1006 | (elfcpp::SHF_ALLOC | |
1007 | | elfcpp::SHF_WRITE), | |
1008 | this->got_); | |
1009 | os->set_is_relro(); | |
f5314dd5 DM |
1010 | |
1011 | // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section. | |
1012 | symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL, | |
1013 | this->got_, | |
1014 | 0, 0, elfcpp::STT_OBJECT, | |
1015 | elfcpp::STB_LOCAL, | |
1016 | elfcpp::STV_HIDDEN, 0, | |
1017 | false, false); | |
1018 | } | |
1019 | ||
1020 | return this->got_; | |
1021 | } | |
1022 | ||
1023 | // Get the dynamic reloc section, creating it if necessary. | |
1024 | ||
1025 | template<int size, bool big_endian> | |
1026 | typename Target_sparc<size, big_endian>::Reloc_section* | |
1027 | Target_sparc<size, big_endian>::rela_dyn_section(Layout* layout) | |
1028 | { | |
1029 | if (this->rela_dyn_ == NULL) | |
1030 | { | |
1031 | gold_assert(layout != NULL); | |
d98bc257 | 1032 | this->rela_dyn_ = new Reloc_section(parameters->options().combreloc()); |
f5314dd5 DM |
1033 | layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA, |
1034 | elfcpp::SHF_ALLOC, this->rela_dyn_); | |
1035 | } | |
1036 | return this->rela_dyn_; | |
1037 | } | |
1038 | ||
1039 | // A class to handle the PLT data. | |
1040 | ||
1041 | template<int size, bool big_endian> | |
1042 | class Output_data_plt_sparc : public Output_section_data | |
1043 | { | |
1044 | public: | |
1045 | typedef Output_data_reloc<elfcpp::SHT_RELA, true, | |
1046 | size, big_endian> Reloc_section; | |
1047 | ||
1048 | Output_data_plt_sparc(Layout*); | |
1049 | ||
1050 | // Add an entry to the PLT. | |
1051 | void add_entry(Symbol* gsym); | |
1052 | ||
1053 | // Return the .rela.plt section data. | |
1054 | const Reloc_section* rel_plt() const | |
1055 | { | |
1056 | return this->rel_; | |
1057 | } | |
1058 | ||
1059 | protected: | |
1060 | void do_adjust_output_section(Output_section* os); | |
1061 | ||
7d9e3d98 ILT |
1062 | // Write to a map file. |
1063 | void | |
1064 | do_print_to_mapfile(Mapfile* mapfile) const | |
1065 | { mapfile->print_output_data(this, _("** PLT")); } | |
1066 | ||
f5314dd5 DM |
1067 | private: |
1068 | // The size of an entry in the PLT. | |
1069 | static const int base_plt_entry_size = (size == 32 ? 12 : 32); | |
1070 | ||
1071 | static const unsigned int plt_entries_per_block = 160; | |
1072 | static const unsigned int plt_insn_chunk_size = 24; | |
1073 | static const unsigned int plt_pointer_chunk_size = 8; | |
1074 | static const unsigned int plt_block_size = | |
1075 | (plt_entries_per_block | |
1076 | * (plt_insn_chunk_size + plt_pointer_chunk_size)); | |
1077 | ||
1078 | // Set the final size. | |
1079 | void | |
1080 | set_final_data_size() | |
1081 | { | |
1082 | unsigned int full_count = this->count_ + 4; | |
1083 | unsigned int extra = (size == 32 ? 4 : 0); | |
1084 | ||
1085 | if (size == 32 || full_count < 32768) | |
1086 | this->set_data_size((full_count * base_plt_entry_size) + extra); | |
1087 | else | |
1088 | { | |
1089 | unsigned int ext_cnt = full_count - 32768; | |
1090 | ||
1091 | this->set_data_size((32768 * base_plt_entry_size) | |
1092 | + (ext_cnt | |
1093 | * (plt_insn_chunk_size | |
1094 | + plt_pointer_chunk_size))); | |
1095 | } | |
1096 | } | |
1097 | ||
1098 | // Write out the PLT data. | |
1099 | void | |
1100 | do_write(Output_file*); | |
1101 | ||
1102 | // The reloc section. | |
1103 | Reloc_section* rel_; | |
1104 | // The number of PLT entries. | |
1105 | unsigned int count_; | |
1106 | }; | |
1107 | ||
4f2a9edd ILT |
1108 | // Define the constants as required by C++ standard. |
1109 | ||
1110 | template<int size, bool big_endian> | |
1111 | const int Output_data_plt_sparc<size, big_endian>::base_plt_entry_size; | |
1112 | ||
1113 | template<int size, bool big_endian> | |
1114 | const unsigned int | |
1115 | Output_data_plt_sparc<size, big_endian>::plt_entries_per_block; | |
1116 | ||
1117 | template<int size, bool big_endian> | |
1118 | const unsigned int Output_data_plt_sparc<size, big_endian>::plt_insn_chunk_size; | |
1119 | ||
1120 | template<int size, bool big_endian> | |
1121 | const unsigned int | |
1122 | Output_data_plt_sparc<size, big_endian>::plt_pointer_chunk_size; | |
1123 | ||
1124 | template<int size, bool big_endian> | |
1125 | const unsigned int Output_data_plt_sparc<size, big_endian>::plt_block_size; | |
1126 | ||
f5314dd5 DM |
1127 | // Create the PLT section. The ordinary .got section is an argument, |
1128 | // since we need to refer to the start. | |
1129 | ||
1130 | template<int size, bool big_endian> | |
1131 | Output_data_plt_sparc<size, big_endian>::Output_data_plt_sparc(Layout* layout) | |
1132 | : Output_section_data(size == 32 ? 4 : 8), count_(0) | |
1133 | { | |
d98bc257 | 1134 | this->rel_ = new Reloc_section(false); |
f5314dd5 DM |
1135 | layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA, |
1136 | elfcpp::SHF_ALLOC, this->rel_); | |
1137 | } | |
1138 | ||
1139 | template<int size, bool big_endian> | |
1140 | void | |
1141 | Output_data_plt_sparc<size, big_endian>::do_adjust_output_section(Output_section* os) | |
1142 | { | |
1143 | os->set_entsize(0); | |
1144 | } | |
1145 | ||
1146 | // Add an entry to the PLT. | |
1147 | ||
1148 | template<int size, bool big_endian> | |
1149 | void | |
1150 | Output_data_plt_sparc<size, big_endian>::add_entry(Symbol* gsym) | |
1151 | { | |
1152 | gold_assert(!gsym->has_plt_offset()); | |
1153 | ||
1154 | unsigned int index = this->count_ + 4; | |
1155 | section_offset_type plt_offset; | |
1156 | ||
1157 | if (size == 32 || index < 32768) | |
1158 | plt_offset = index * base_plt_entry_size; | |
1159 | else | |
1160 | { | |
1161 | unsigned int ext_index = index - 32768; | |
1162 | ||
1163 | plt_offset = (32768 * base_plt_entry_size) | |
1164 | + ((ext_index / plt_entries_per_block) | |
1165 | * plt_block_size) | |
1166 | + ((ext_index % plt_entries_per_block) | |
1167 | * plt_insn_chunk_size); | |
1168 | } | |
1169 | ||
1170 | gsym->set_plt_offset(plt_offset); | |
1171 | ||
1172 | ++this->count_; | |
1173 | ||
1174 | // Every PLT entry needs a reloc. | |
1175 | gsym->set_needs_dynsym_entry(); | |
1176 | this->rel_->add_global(gsym, elfcpp::R_SPARC_JMP_SLOT, this, | |
1177 | plt_offset, 0); | |
1178 | ||
1179 | // Note that we don't need to save the symbol. The contents of the | |
1180 | // PLT are independent of which symbols are used. The symbols only | |
1181 | // appear in the relocations. | |
1182 | } | |
1183 | ||
1184 | static const unsigned int sparc_nop = 0x01000000; | |
1185 | static const unsigned int sparc_sethi_g1 = 0x03000000; | |
1186 | static const unsigned int sparc_branch_always = 0x30800000; | |
1187 | static const unsigned int sparc_branch_always_pt = 0x30680000; | |
1188 | static const unsigned int sparc_mov = 0x80100000; | |
1189 | static const unsigned int sparc_mov_g0_o0 = 0x90100000; | |
1190 | static const unsigned int sparc_mov_o7_g5 = 0x8a10000f; | |
1191 | static const unsigned int sparc_call_plus_8 = 0x40000002; | |
1192 | static const unsigned int sparc_ldx_o7_imm_g1 = 0xc25be000; | |
1193 | static const unsigned int sparc_jmpl_o7_g1_g1 = 0x83c3c001; | |
1194 | static const unsigned int sparc_mov_g5_o7 = 0x9e100005; | |
1195 | ||
1196 | // Write out the PLT. | |
1197 | ||
1198 | template<int size, bool big_endian> | |
1199 | void | |
1200 | Output_data_plt_sparc<size, big_endian>::do_write(Output_file* of) | |
1201 | { | |
1202 | const off_t offset = this->offset(); | |
1203 | const section_size_type oview_size = | |
1204 | convert_to_section_size_type(this->data_size()); | |
1205 | unsigned char* const oview = of->get_output_view(offset, oview_size); | |
1206 | unsigned char* pov = oview; | |
1207 | ||
1208 | memset(pov, 0, base_plt_entry_size * 4); | |
1209 | pov += base_plt_entry_size * 4; | |
1210 | ||
1211 | unsigned int plt_offset = base_plt_entry_size * 4; | |
1212 | const unsigned int count = this->count_; | |
1213 | ||
1214 | if (size == 64) | |
1215 | { | |
1216 | unsigned int limit; | |
1217 | ||
1218 | limit = (count > 32768 ? 32768 : count); | |
1219 | ||
1220 | for (unsigned int i = 0; i < limit; ++i) | |
1221 | { | |
1222 | elfcpp::Swap<32, true>::writeval(pov + 0x00, | |
1223 | sparc_sethi_g1 + plt_offset); | |
1224 | elfcpp::Swap<32, true>::writeval(pov + 0x04, | |
1225 | sparc_branch_always_pt + | |
1226 | (((base_plt_entry_size - | |
1227 | (plt_offset + 4)) >> 2) & | |
1228 | 0x7ffff)); | |
1229 | elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop); | |
1230 | elfcpp::Swap<32, true>::writeval(pov + 0x0c, sparc_nop); | |
1231 | elfcpp::Swap<32, true>::writeval(pov + 0x10, sparc_nop); | |
1232 | elfcpp::Swap<32, true>::writeval(pov + 0x14, sparc_nop); | |
1233 | elfcpp::Swap<32, true>::writeval(pov + 0x18, sparc_nop); | |
1234 | elfcpp::Swap<32, true>::writeval(pov + 0x1c, sparc_nop); | |
1235 | ||
1236 | pov += base_plt_entry_size; | |
1237 | plt_offset += base_plt_entry_size; | |
1238 | } | |
1239 | ||
1240 | if (count > 32768) | |
1241 | { | |
1242 | unsigned int ext_cnt = count - 32768; | |
1243 | unsigned int blks = ext_cnt / plt_entries_per_block; | |
1244 | ||
1245 | for (unsigned int i = 0; i < blks; ++i) | |
1246 | { | |
1247 | unsigned int data_off = (plt_entries_per_block | |
1248 | * plt_insn_chunk_size) - 4; | |
1249 | ||
1250 | for (unsigned int j = 0; j < plt_entries_per_block; ++j) | |
1251 | { | |
1252 | elfcpp::Swap<32, true>::writeval(pov + 0x00, | |
1253 | sparc_mov_o7_g5); | |
1254 | elfcpp::Swap<32, true>::writeval(pov + 0x04, | |
1255 | sparc_call_plus_8); | |
1256 | elfcpp::Swap<32, true>::writeval(pov + 0x08, | |
1257 | sparc_nop); | |
1258 | elfcpp::Swap<32, true>::writeval(pov + 0x0c, | |
1259 | sparc_ldx_o7_imm_g1 + | |
1260 | (data_off & 0x1fff)); | |
1261 | elfcpp::Swap<32, true>::writeval(pov + 0x10, | |
1262 | sparc_jmpl_o7_g1_g1); | |
1263 | elfcpp::Swap<32, true>::writeval(pov + 0x14, | |
1264 | sparc_mov_g5_o7); | |
1265 | ||
1266 | elfcpp::Swap<64, big_endian>::writeval( | |
1267 | pov + 0x4 + data_off, | |
1268 | (elfcpp::Elf_Xword) (oview - (pov + 0x04))); | |
1269 | ||
1270 | pov += plt_insn_chunk_size; | |
1271 | data_off -= 16; | |
1272 | } | |
1273 | } | |
1274 | ||
1275 | unsigned int sub_blk_cnt = ext_cnt % plt_entries_per_block; | |
1276 | for (unsigned int i = 0; i < sub_blk_cnt; ++i) | |
1277 | { | |
1278 | unsigned int data_off = (sub_blk_cnt | |
1279 | * plt_insn_chunk_size) - 4; | |
1280 | ||
1281 | for (unsigned int j = 0; j < plt_entries_per_block; ++j) | |
1282 | { | |
1283 | elfcpp::Swap<32, true>::writeval(pov + 0x00, | |
1284 | sparc_mov_o7_g5); | |
1285 | elfcpp::Swap<32, true>::writeval(pov + 0x04, | |
1286 | sparc_call_plus_8); | |
1287 | elfcpp::Swap<32, true>::writeval(pov + 0x08, | |
1288 | sparc_nop); | |
1289 | elfcpp::Swap<32, true>::writeval(pov + 0x0c, | |
1290 | sparc_ldx_o7_imm_g1 + | |
1291 | (data_off & 0x1fff)); | |
1292 | elfcpp::Swap<32, true>::writeval(pov + 0x10, | |
1293 | sparc_jmpl_o7_g1_g1); | |
1294 | elfcpp::Swap<32, true>::writeval(pov + 0x14, | |
1295 | sparc_mov_g5_o7); | |
1296 | ||
1297 | elfcpp::Swap<64, big_endian>::writeval( | |
1298 | pov + 0x4 + data_off, | |
1299 | (elfcpp::Elf_Xword) (oview - (pov + 0x04))); | |
1300 | ||
1301 | pov += plt_insn_chunk_size; | |
1302 | data_off -= 16; | |
1303 | } | |
1304 | } | |
1305 | } | |
1306 | } | |
1307 | else | |
1308 | { | |
1309 | for (unsigned int i = 0; i < count; ++i) | |
1310 | { | |
1311 | elfcpp::Swap<32, true>::writeval(pov + 0x00, | |
1312 | sparc_sethi_g1 + plt_offset); | |
1313 | elfcpp::Swap<32, true>::writeval(pov + 0x04, | |
1314 | sparc_branch_always + | |
1315 | (((- (plt_offset + 4)) >> 2) & | |
1316 | 0x003fffff)); | |
1317 | elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop); | |
1318 | ||
1319 | pov += base_plt_entry_size; | |
1320 | plt_offset += base_plt_entry_size; | |
1321 | } | |
1322 | ||
1323 | elfcpp::Swap<32, true>::writeval(pov, sparc_nop); | |
1324 | pov += 4; | |
1325 | } | |
1326 | ||
1327 | gold_assert(static_cast<section_size_type>(pov - oview) == oview_size); | |
1328 | ||
1329 | of->write_output_view(offset, oview_size, oview); | |
1330 | } | |
1331 | ||
1332 | // Create a PLT entry for a global symbol. | |
1333 | ||
1334 | template<int size, bool big_endian> | |
1335 | void | |
1336 | Target_sparc<size, big_endian>::make_plt_entry(Symbol_table* symtab, | |
1337 | Layout* layout, | |
1338 | Symbol* gsym) | |
1339 | { | |
1340 | if (gsym->has_plt_offset()) | |
1341 | return; | |
1342 | ||
1343 | if (this->plt_ == NULL) | |
1344 | { | |
1345 | // Create the GOT sections first. | |
1346 | this->got_section(symtab, layout); | |
1347 | ||
1348 | this->plt_ = new Output_data_plt_sparc<size, big_endian>(layout); | |
1349 | layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS, | |
1350 | (elfcpp::SHF_ALLOC | |
1351 | | elfcpp::SHF_EXECINSTR | |
1352 | | elfcpp::SHF_WRITE), | |
1353 | this->plt_); | |
1354 | ||
1355 | // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section. | |
1356 | symtab->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL, | |
1357 | this->plt_, | |
1358 | 0, 0, elfcpp::STT_OBJECT, | |
1359 | elfcpp::STB_LOCAL, | |
1360 | elfcpp::STV_HIDDEN, 0, | |
1361 | false, false); | |
1362 | } | |
1363 | ||
1364 | this->plt_->add_entry(gsym); | |
1365 | } | |
1366 | ||
1367 | // Create a GOT entry for the TLS module index. | |
1368 | ||
1369 | template<int size, bool big_endian> | |
1370 | unsigned int | |
1371 | Target_sparc<size, big_endian>::got_mod_index_entry(Symbol_table* symtab, | |
1372 | Layout* layout, | |
1373 | Sized_relobj<size, big_endian>* object) | |
1374 | { | |
1375 | if (this->got_mod_index_offset_ == -1U) | |
1376 | { | |
1377 | gold_assert(symtab != NULL && layout != NULL && object != NULL); | |
1378 | Reloc_section* rela_dyn = this->rela_dyn_section(layout); | |
1379 | Output_data_got<size, big_endian>* got; | |
1380 | unsigned int got_offset; | |
1381 | ||
1382 | got = this->got_section(symtab, layout); | |
1383 | got_offset = got->add_constant(0); | |
1384 | rela_dyn->add_local(object, 0, | |
1385 | (size == 64 ? | |
1386 | elfcpp::R_SPARC_TLS_DTPMOD64 : | |
1387 | elfcpp::R_SPARC_TLS_DTPMOD32), got, | |
1388 | got_offset, 0); | |
1389 | got->add_constant(0); | |
1390 | this->got_mod_index_offset_ = got_offset; | |
1391 | } | |
1392 | return this->got_mod_index_offset_; | |
1393 | } | |
1394 | ||
f5314dd5 DM |
1395 | // Optimize the TLS relocation type based on what we know about the |
1396 | // symbol. IS_FINAL is true if the final address of this symbol is | |
1397 | // known at link time. | |
1398 | ||
1399 | static tls::Tls_optimization | |
1400 | optimize_tls_reloc(bool is_final, int r_type) | |
1401 | { | |
1402 | // If we are generating a shared library, then we can't do anything | |
1403 | // in the linker. | |
1404 | if (parameters->options().shared()) | |
1405 | return tls::TLSOPT_NONE; | |
1406 | ||
1407 | switch (r_type) | |
1408 | { | |
1409 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic | |
1410 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
1411 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
1412 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
1413 | // These are General-Dynamic which permits fully general TLS | |
1414 | // access. Since we know that we are generating an executable, | |
1415 | // we can convert this to Initial-Exec. If we also know that | |
1416 | // this is a local symbol, we can further switch to Local-Exec. | |
1417 | if (is_final) | |
1418 | return tls::TLSOPT_TO_LE; | |
1419 | return tls::TLSOPT_TO_IE; | |
1420 | ||
1421 | case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic | |
1422 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
1423 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
1424 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
1425 | // This is Local-Dynamic, which refers to a local symbol in the | |
1426 | // dynamic TLS block. Since we know that we generating an | |
1427 | // executable, we can switch to Local-Exec. | |
1428 | return tls::TLSOPT_TO_LE; | |
1429 | ||
1430 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic | |
1431 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
1432 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
1433 | // Another type of Local-Dynamic relocation. | |
1434 | return tls::TLSOPT_TO_LE; | |
1435 | ||
1436 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec | |
1437 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
1438 | case elfcpp::R_SPARC_TLS_IE_LD: | |
1439 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
1440 | // These are Initial-Exec relocs which get the thread offset | |
1441 | // from the GOT. If we know that we are linking against the | |
1442 | // local symbol, we can switch to Local-Exec, which links the | |
1443 | // thread offset into the instruction. | |
1444 | if (is_final) | |
1445 | return tls::TLSOPT_TO_LE; | |
1446 | return tls::TLSOPT_NONE; | |
1447 | ||
1448 | case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec | |
1449 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
1450 | // When we already have Local-Exec, there is nothing further we | |
1451 | // can do. | |
1452 | return tls::TLSOPT_NONE; | |
1453 | ||
1454 | default: | |
1455 | gold_unreachable(); | |
1456 | } | |
1457 | } | |
1458 | ||
1459 | // Generate a PLT entry slot for a call to __tls_get_addr | |
1460 | template<int size, bool big_endian> | |
1461 | void | |
1462 | Target_sparc<size, big_endian>::Scan::generate_tls_call(Symbol_table* symtab, | |
1463 | Layout* layout, | |
1464 | Target_sparc<size, big_endian>* target) | |
1465 | { | |
1466 | Symbol* gsym = target->tls_get_addr_sym(symtab); | |
1467 | ||
1468 | target->make_plt_entry(symtab, layout, gsym); | |
1469 | } | |
1470 | ||
1471 | // Report an unsupported relocation against a local symbol. | |
1472 | ||
1473 | template<int size, bool big_endian> | |
1474 | void | |
1475 | Target_sparc<size, big_endian>::Scan::unsupported_reloc_local( | |
1476 | Sized_relobj<size, big_endian>* object, | |
1477 | unsigned int r_type) | |
1478 | { | |
1479 | gold_error(_("%s: unsupported reloc %u against local symbol"), | |
1480 | object->name().c_str(), r_type); | |
1481 | } | |
1482 | ||
32b769e1 DM |
1483 | // We are about to emit a dynamic relocation of type R_TYPE. If the |
1484 | // dynamic linker does not support it, issue an error. | |
1485 | ||
1486 | template<int size, bool big_endian> | |
1487 | void | |
1488 | Target_sparc<size, big_endian>::Scan::check_non_pic(Relobj* object, unsigned int r_type) | |
1489 | { | |
1490 | gold_assert(r_type != elfcpp::R_SPARC_NONE); | |
1491 | ||
1492 | if (size == 64) | |
1493 | { | |
1494 | switch (r_type) | |
1495 | { | |
1496 | // These are the relocation types supported by glibc for sparc 64-bit. | |
1497 | case elfcpp::R_SPARC_RELATIVE: | |
1498 | case elfcpp::R_SPARC_COPY: | |
1499 | case elfcpp::R_SPARC_64: | |
1500 | case elfcpp::R_SPARC_GLOB_DAT: | |
1501 | case elfcpp::R_SPARC_JMP_SLOT: | |
1502 | case elfcpp::R_SPARC_TLS_DTPMOD64: | |
1503 | case elfcpp::R_SPARC_TLS_DTPOFF64: | |
1504 | case elfcpp::R_SPARC_TLS_TPOFF64: | |
1505 | case elfcpp::R_SPARC_TLS_LE_HIX22: | |
1506 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
1507 | case elfcpp::R_SPARC_8: | |
1508 | case elfcpp::R_SPARC_16: | |
1509 | case elfcpp::R_SPARC_DISP8: | |
1510 | case elfcpp::R_SPARC_DISP16: | |
1511 | case elfcpp::R_SPARC_DISP32: | |
1512 | case elfcpp::R_SPARC_WDISP30: | |
1513 | case elfcpp::R_SPARC_LO10: | |
1514 | case elfcpp::R_SPARC_HI22: | |
1515 | case elfcpp::R_SPARC_OLO10: | |
1516 | case elfcpp::R_SPARC_H44: | |
1517 | case elfcpp::R_SPARC_M44: | |
1518 | case elfcpp::R_SPARC_L44: | |
1519 | case elfcpp::R_SPARC_HH22: | |
1520 | case elfcpp::R_SPARC_HM10: | |
1521 | case elfcpp::R_SPARC_LM22: | |
1522 | case elfcpp::R_SPARC_UA16: | |
1523 | case elfcpp::R_SPARC_UA32: | |
1524 | case elfcpp::R_SPARC_UA64: | |
1525 | return; | |
1526 | ||
1527 | default: | |
1528 | break; | |
1529 | } | |
1530 | } | |
1531 | else | |
1532 | { | |
1533 | switch (r_type) | |
1534 | { | |
1535 | // These are the relocation types supported by glibc for sparc 32-bit. | |
1536 | case elfcpp::R_SPARC_RELATIVE: | |
1537 | case elfcpp::R_SPARC_COPY: | |
1538 | case elfcpp::R_SPARC_GLOB_DAT: | |
1539 | case elfcpp::R_SPARC_32: | |
1540 | case elfcpp::R_SPARC_JMP_SLOT: | |
1541 | case elfcpp::R_SPARC_TLS_DTPMOD32: | |
1542 | case elfcpp::R_SPARC_TLS_DTPOFF32: | |
1543 | case elfcpp::R_SPARC_TLS_TPOFF32: | |
1544 | case elfcpp::R_SPARC_TLS_LE_HIX22: | |
1545 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
1546 | case elfcpp::R_SPARC_8: | |
1547 | case elfcpp::R_SPARC_16: | |
1548 | case elfcpp::R_SPARC_DISP8: | |
1549 | case elfcpp::R_SPARC_DISP16: | |
1550 | case elfcpp::R_SPARC_DISP32: | |
1551 | case elfcpp::R_SPARC_LO10: | |
1552 | case elfcpp::R_SPARC_WDISP30: | |
1553 | case elfcpp::R_SPARC_HI22: | |
1554 | case elfcpp::R_SPARC_UA16: | |
1555 | case elfcpp::R_SPARC_UA32: | |
1556 | return; | |
1557 | ||
1558 | default: | |
1559 | break; | |
1560 | } | |
1561 | } | |
1562 | ||
1563 | // This prevents us from issuing more than one error per reloc | |
1564 | // section. But we can still wind up issuing more than one | |
1565 | // error per object file. | |
1566 | if (this->issued_non_pic_error_) | |
1567 | return; | |
1568 | object->error(_("requires unsupported dynamic reloc; " | |
1569 | "recompile with -fPIC")); | |
1570 | this->issued_non_pic_error_ = true; | |
1571 | return; | |
1572 | } | |
1573 | ||
f5314dd5 DM |
1574 | // Scan a relocation for a local symbol. |
1575 | ||
1576 | template<int size, bool big_endian> | |
1577 | inline void | |
1578 | Target_sparc<size, big_endian>::Scan::local( | |
1579 | const General_options&, | |
1580 | Symbol_table* symtab, | |
1581 | Layout* layout, | |
1582 | Target_sparc<size, big_endian>* target, | |
1583 | Sized_relobj<size, big_endian>* object, | |
1584 | unsigned int data_shndx, | |
1585 | Output_section* output_section, | |
1586 | const elfcpp::Rela<size, big_endian>& reloc, | |
1587 | unsigned int r_type, | |
1588 | const elfcpp::Sym<size, big_endian>& lsym) | |
1589 | { | |
1590 | unsigned int orig_r_type = r_type; | |
1591 | ||
1592 | r_type &= 0xff; | |
1593 | switch (r_type) | |
1594 | { | |
1595 | case elfcpp::R_SPARC_NONE: | |
1596 | case elfcpp::R_SPARC_REGISTER: | |
1597 | case elfcpp::R_SPARC_GNU_VTINHERIT: | |
1598 | case elfcpp::R_SPARC_GNU_VTENTRY: | |
1599 | break; | |
1600 | ||
1601 | case elfcpp::R_SPARC_64: | |
1602 | case elfcpp::R_SPARC_32: | |
1603 | // If building a shared library (or a position-independent | |
1604 | // executable), we need to create a dynamic relocation for | |
1605 | // this location. The relocation applied at link time will | |
1606 | // apply the link-time value, so we flag the location with | |
1607 | // an R_SPARC_RELATIVE relocation so the dynamic loader can | |
1608 | // relocate it easily. | |
1609 | if (parameters->options().output_is_position_independent()) | |
1610 | { | |
1611 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
1612 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); | |
1613 | rela_dyn->add_local_relative(object, r_sym, elfcpp::R_SPARC_RELATIVE, | |
1614 | output_section, data_shndx, | |
1615 | reloc.get_r_offset(), | |
1616 | reloc.get_r_addend()); | |
1617 | } | |
1618 | break; | |
1619 | ||
1620 | case elfcpp::R_SPARC_HIX22: | |
1621 | case elfcpp::R_SPARC_LOX10: | |
1622 | case elfcpp::R_SPARC_H44: | |
1623 | case elfcpp::R_SPARC_M44: | |
1624 | case elfcpp::R_SPARC_L44: | |
1625 | case elfcpp::R_SPARC_HH22: | |
1626 | case elfcpp::R_SPARC_HM10: | |
1627 | case elfcpp::R_SPARC_LM22: | |
1628 | case elfcpp::R_SPARC_UA64: | |
1629 | case elfcpp::R_SPARC_UA32: | |
1630 | case elfcpp::R_SPARC_UA16: | |
1631 | case elfcpp::R_SPARC_HI22: | |
1632 | case elfcpp::R_SPARC_LO10: | |
1633 | case elfcpp::R_SPARC_OLO10: | |
1634 | case elfcpp::R_SPARC_16: | |
1635 | case elfcpp::R_SPARC_11: | |
1636 | case elfcpp::R_SPARC_10: | |
1637 | case elfcpp::R_SPARC_8: | |
1638 | case elfcpp::R_SPARC_7: | |
1639 | case elfcpp::R_SPARC_6: | |
1640 | case elfcpp::R_SPARC_5: | |
1641 | // If building a shared library (or a position-independent | |
1642 | // executable), we need to create a dynamic relocation for | |
1643 | // this location. | |
1644 | if (parameters->options().output_is_position_independent()) | |
1645 | { | |
1646 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
32b769e1 DM |
1647 | |
1648 | check_non_pic(object, r_type); | |
f5314dd5 DM |
1649 | if (lsym.get_st_type() != elfcpp::STT_SECTION) |
1650 | { | |
1651 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); | |
1652 | rela_dyn->add_local(object, r_sym, orig_r_type, output_section, | |
1653 | data_shndx, reloc.get_r_offset(), | |
1654 | reloc.get_r_addend()); | |
1655 | } | |
1656 | else | |
1657 | { | |
1658 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); | |
1659 | gold_assert(lsym.get_st_value() == 0); | |
1660 | rela_dyn->add_local_relative(object, r_sym, orig_r_type, | |
1661 | output_section, data_shndx, | |
1662 | reloc.get_r_offset(), | |
1663 | reloc.get_r_addend()); | |
1664 | } | |
1665 | } | |
1666 | break; | |
1667 | ||
1668 | case elfcpp::R_SPARC_WDISP30: | |
1669 | case elfcpp::R_SPARC_WDISP22: | |
1670 | case elfcpp::R_SPARC_WDISP19: | |
1671 | case elfcpp::R_SPARC_WDISP16: | |
1672 | case elfcpp::R_SPARC_DISP8: | |
1673 | case elfcpp::R_SPARC_DISP16: | |
1674 | case elfcpp::R_SPARC_DISP32: | |
1675 | case elfcpp::R_SPARC_DISP64: | |
1676 | case elfcpp::R_SPARC_PC10: | |
1677 | case elfcpp::R_SPARC_PC22: | |
1678 | break; | |
1679 | ||
1680 | case elfcpp::R_SPARC_GOT10: | |
1681 | case elfcpp::R_SPARC_GOT13: | |
1682 | case elfcpp::R_SPARC_GOT22: | |
1683 | { | |
1684 | // The symbol requires a GOT entry. | |
1685 | Output_data_got<size, big_endian>* got; | |
1686 | unsigned int r_sym; | |
1687 | ||
1688 | got = target->got_section(symtab, layout); | |
1689 | r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); | |
1690 | ||
1691 | // If we are generating a shared object, we need to add a | |
1692 | // dynamic relocation for this symbol's GOT entry. | |
1693 | if (parameters->options().output_is_position_independent()) | |
1694 | { | |
1695 | if (!object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD)) | |
1696 | { | |
1697 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
1698 | unsigned int off; | |
1699 | ||
1700 | off = got->add_constant(0); | |
1701 | object->set_local_got_offset(r_sym, GOT_TYPE_STANDARD, off); | |
1702 | rela_dyn->add_local_relative(object, r_sym, | |
1703 | elfcpp::R_SPARC_RELATIVE, | |
1704 | got, off, 0); | |
1705 | } | |
1706 | } | |
1707 | else | |
1708 | got->add_local(object, r_sym, GOT_TYPE_STANDARD); | |
1709 | } | |
1710 | break; | |
1711 | ||
1712 | // These are initial TLS relocs, which are expected when | |
1713 | // linking. | |
1714 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic | |
1715 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
1716 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
1717 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
1718 | case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic | |
1719 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
1720 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
1721 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
1722 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic | |
1723 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
1724 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
1725 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec | |
1726 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
1727 | case elfcpp::R_SPARC_TLS_IE_LD: | |
1728 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
1729 | case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec | |
1730 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
1731 | { | |
1732 | bool output_is_shared = parameters->options().shared(); | |
1733 | const tls::Tls_optimization optimized_type | |
1734 | = optimize_tls_reloc(!output_is_shared, r_type); | |
1735 | switch (r_type) | |
1736 | { | |
1737 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic | |
1738 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
1739 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
1740 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
1741 | if (optimized_type == tls::TLSOPT_NONE) | |
1742 | { | |
1743 | // Create a pair of GOT entries for the module index and | |
1744 | // dtv-relative offset. | |
1745 | Output_data_got<size, big_endian>* got | |
1746 | = target->got_section(symtab, layout); | |
1747 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); | |
d491d34e ILT |
1748 | unsigned int shndx = lsym.get_st_shndx(); |
1749 | bool is_ordinary; | |
1750 | shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary); | |
1751 | if (!is_ordinary) | |
1752 | object->error(_("local symbol %u has bad shndx %u"), | |
1753 | r_sym, shndx); | |
1754 | else | |
1755 | got->add_local_pair_with_rela(object, r_sym, | |
1756 | lsym.get_st_shndx(), | |
1757 | GOT_TYPE_TLS_PAIR, | |
1758 | target->rela_dyn_section(layout), | |
1759 | (size == 64 | |
1760 | ? elfcpp::R_SPARC_TLS_DTPMOD64 | |
1761 | : elfcpp::R_SPARC_TLS_DTPMOD32), | |
1762 | 0); | |
f5314dd5 DM |
1763 | if (r_type == elfcpp::R_SPARC_TLS_GD_CALL) |
1764 | generate_tls_call(symtab, layout, target); | |
1765 | } | |
1766 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
1767 | unsupported_reloc_local(object, r_type); | |
1768 | break; | |
1769 | ||
1770 | case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic | |
1771 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
1772 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
1773 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
1774 | if (optimized_type == tls::TLSOPT_NONE) | |
1775 | { | |
1776 | // Create a GOT entry for the module index. | |
1777 | target->got_mod_index_entry(symtab, layout, object); | |
1778 | ||
1779 | if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL) | |
1780 | generate_tls_call(symtab, layout, target); | |
1781 | } | |
1782 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
1783 | unsupported_reloc_local(object, r_type); | |
1784 | break; | |
1785 | ||
1786 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic | |
1787 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
1788 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
1789 | break; | |
1790 | ||
1791 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec | |
1792 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
1793 | case elfcpp::R_SPARC_TLS_IE_LD: | |
1794 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
1795 | layout->set_has_static_tls(); | |
1796 | if (optimized_type == tls::TLSOPT_NONE) | |
1797 | { | |
1798 | // Create a GOT entry for the tp-relative offset. | |
1799 | Output_data_got<size, big_endian>* got | |
1800 | = target->got_section(symtab, layout); | |
1801 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); | |
1802 | ||
1803 | if (!object->local_has_got_offset(r_sym, GOT_TYPE_TLS_OFFSET)) | |
1804 | { | |
1805 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
1806 | unsigned int off = got->add_constant(0); | |
1807 | ||
1808 | object->set_local_got_offset(r_sym, GOT_TYPE_TLS_OFFSET, | |
1809 | off); | |
1810 | rela_dyn->add_local_relative(object, r_sym, | |
1811 | (size == 64 ? | |
1812 | elfcpp::R_SPARC_TLS_TPOFF64 : | |
1813 | elfcpp::R_SPARC_TLS_TPOFF32), | |
1814 | got, off, 0); | |
1815 | } | |
1816 | } | |
1817 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
1818 | unsupported_reloc_local(object, r_type); | |
1819 | break; | |
1820 | ||
1821 | case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec | |
1822 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
1823 | layout->set_has_static_tls(); | |
1824 | if (output_is_shared) | |
1825 | { | |
1826 | // We need to create a dynamic relocation. | |
1827 | gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION); | |
1828 | unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info()); | |
1829 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
1830 | rela_dyn->add_local_relative(object, r_sym, r_type, | |
1831 | output_section, data_shndx, | |
1832 | reloc.get_r_offset(), 0); | |
1833 | } | |
1834 | break; | |
1835 | } | |
1836 | } | |
1837 | break; | |
1838 | ||
1839 | // These are relocations which should only be seen by the | |
1840 | // dynamic linker, and should never be seen here. | |
1841 | case elfcpp::R_SPARC_COPY: | |
1842 | case elfcpp::R_SPARC_GLOB_DAT: | |
1843 | case elfcpp::R_SPARC_JMP_SLOT: | |
1844 | case elfcpp::R_SPARC_RELATIVE: | |
1845 | case elfcpp::R_SPARC_TLS_DTPMOD64: | |
1846 | case elfcpp::R_SPARC_TLS_DTPMOD32: | |
1847 | case elfcpp::R_SPARC_TLS_DTPOFF64: | |
1848 | case elfcpp::R_SPARC_TLS_DTPOFF32: | |
1849 | case elfcpp::R_SPARC_TLS_TPOFF64: | |
1850 | case elfcpp::R_SPARC_TLS_TPOFF32: | |
1851 | gold_error(_("%s: unexpected reloc %u in object file"), | |
1852 | object->name().c_str(), r_type); | |
1853 | break; | |
1854 | ||
1855 | default: | |
1856 | unsupported_reloc_local(object, r_type); | |
1857 | break; | |
1858 | } | |
1859 | } | |
1860 | ||
1861 | // Report an unsupported relocation against a global symbol. | |
1862 | ||
1863 | template<int size, bool big_endian> | |
1864 | void | |
1865 | Target_sparc<size, big_endian>::Scan::unsupported_reloc_global( | |
1866 | Sized_relobj<size, big_endian>* object, | |
1867 | unsigned int r_type, | |
1868 | Symbol* gsym) | |
1869 | { | |
1870 | gold_error(_("%s: unsupported reloc %u against global symbol %s"), | |
1871 | object->name().c_str(), r_type, gsym->demangled_name().c_str()); | |
1872 | } | |
1873 | ||
1874 | // Scan a relocation for a global symbol. | |
1875 | ||
1876 | template<int size, bool big_endian> | |
1877 | inline void | |
1878 | Target_sparc<size, big_endian>::Scan::global( | |
12c0daef | 1879 | const General_options&, |
f5314dd5 DM |
1880 | Symbol_table* symtab, |
1881 | Layout* layout, | |
1882 | Target_sparc<size, big_endian>* target, | |
1883 | Sized_relobj<size, big_endian>* object, | |
1884 | unsigned int data_shndx, | |
1885 | Output_section* output_section, | |
1886 | const elfcpp::Rela<size, big_endian>& reloc, | |
1887 | unsigned int r_type, | |
1888 | Symbol* gsym) | |
1889 | { | |
1890 | unsigned int orig_r_type = r_type; | |
1891 | ||
1892 | r_type &= 0xff; | |
1893 | switch (r_type) | |
1894 | { | |
1895 | case elfcpp::R_SPARC_NONE: | |
1896 | case elfcpp::R_SPARC_REGISTER: | |
1897 | case elfcpp::R_SPARC_GNU_VTINHERIT: | |
1898 | case elfcpp::R_SPARC_GNU_VTENTRY: | |
1899 | break; | |
1900 | ||
1901 | case elfcpp::R_SPARC_PLT64: | |
1902 | case elfcpp::R_SPARC_PLT32: | |
1903 | case elfcpp::R_SPARC_HIPLT22: | |
1904 | case elfcpp::R_SPARC_LOPLT10: | |
1905 | case elfcpp::R_SPARC_PCPLT32: | |
1906 | case elfcpp::R_SPARC_PCPLT22: | |
1907 | case elfcpp::R_SPARC_PCPLT10: | |
1908 | case elfcpp::R_SPARC_WPLT30: | |
1909 | // If the symbol is fully resolved, this is just a PC32 reloc. | |
1910 | // Otherwise we need a PLT entry. | |
1911 | if (gsym->final_value_is_known()) | |
1912 | break; | |
1913 | // If building a shared library, we can also skip the PLT entry | |
1914 | // if the symbol is defined in the output file and is protected | |
1915 | // or hidden. | |
1916 | if (gsym->is_defined() | |
1917 | && !gsym->is_from_dynobj() | |
1918 | && !gsym->is_preemptible()) | |
1919 | break; | |
1920 | target->make_plt_entry(symtab, layout, gsym); | |
1921 | break; | |
1922 | ||
1923 | case elfcpp::R_SPARC_DISP8: | |
1924 | case elfcpp::R_SPARC_DISP16: | |
1925 | case elfcpp::R_SPARC_DISP32: | |
1926 | case elfcpp::R_SPARC_DISP64: | |
1927 | case elfcpp::R_SPARC_PC_HH22: | |
1928 | case elfcpp::R_SPARC_PC_HM10: | |
1929 | case elfcpp::R_SPARC_PC_LM22: | |
1930 | case elfcpp::R_SPARC_PC10: | |
1931 | case elfcpp::R_SPARC_PC22: | |
1932 | case elfcpp::R_SPARC_WDISP30: | |
1933 | case elfcpp::R_SPARC_WDISP22: | |
1934 | case elfcpp::R_SPARC_WDISP19: | |
1935 | case elfcpp::R_SPARC_WDISP16: | |
1936 | { | |
1937 | if (gsym->needs_plt_entry()) | |
1938 | target->make_plt_entry(symtab, layout, gsym); | |
1939 | // Make a dynamic relocation if necessary. | |
1940 | int flags = Symbol::NON_PIC_REF; | |
1941 | if (gsym->type() == elfcpp::STT_FUNC) | |
1942 | flags |= Symbol::FUNCTION_CALL; | |
1943 | if (gsym->needs_dynamic_reloc(flags)) | |
1944 | { | |
1945 | if (target->may_need_copy_reloc(gsym)) | |
1946 | { | |
12c0daef | 1947 | target->copy_reloc(symtab, layout, object, |
f5314dd5 DM |
1948 | data_shndx, output_section, gsym, |
1949 | reloc); | |
1950 | } | |
1951 | else | |
1952 | { | |
1953 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
32b769e1 | 1954 | check_non_pic(object, r_type); |
f5314dd5 DM |
1955 | rela_dyn->add_global(gsym, orig_r_type, output_section, object, |
1956 | data_shndx, reloc.get_r_offset(), | |
1957 | reloc.get_r_addend()); | |
1958 | } | |
1959 | } | |
1960 | } | |
1961 | break; | |
1962 | ||
1963 | case elfcpp::R_SPARC_UA64: | |
1964 | case elfcpp::R_SPARC_64: | |
1965 | case elfcpp::R_SPARC_HIX22: | |
1966 | case elfcpp::R_SPARC_LOX10: | |
1967 | case elfcpp::R_SPARC_H44: | |
1968 | case elfcpp::R_SPARC_M44: | |
1969 | case elfcpp::R_SPARC_L44: | |
1970 | case elfcpp::R_SPARC_HH22: | |
1971 | case elfcpp::R_SPARC_HM10: | |
1972 | case elfcpp::R_SPARC_LM22: | |
1973 | case elfcpp::R_SPARC_HI22: | |
1974 | case elfcpp::R_SPARC_LO10: | |
1975 | case elfcpp::R_SPARC_OLO10: | |
1976 | case elfcpp::R_SPARC_UA32: | |
1977 | case elfcpp::R_SPARC_32: | |
1978 | case elfcpp::R_SPARC_UA16: | |
1979 | case elfcpp::R_SPARC_16: | |
1980 | case elfcpp::R_SPARC_11: | |
1981 | case elfcpp::R_SPARC_10: | |
1982 | case elfcpp::R_SPARC_8: | |
1983 | case elfcpp::R_SPARC_7: | |
1984 | case elfcpp::R_SPARC_6: | |
1985 | case elfcpp::R_SPARC_5: | |
1986 | { | |
1987 | // Make a PLT entry if necessary. | |
1988 | if (gsym->needs_plt_entry()) | |
1989 | { | |
1990 | target->make_plt_entry(symtab, layout, gsym); | |
1991 | // Since this is not a PC-relative relocation, we may be | |
1992 | // taking the address of a function. In that case we need to | |
1993 | // set the entry in the dynamic symbol table to the address of | |
1994 | // the PLT entry. | |
1995 | if (gsym->is_from_dynobj() && !parameters->options().shared()) | |
1996 | gsym->set_needs_dynsym_value(); | |
1997 | } | |
1998 | // Make a dynamic relocation if necessary. | |
1999 | if (gsym->needs_dynamic_reloc(Symbol::ABSOLUTE_REF)) | |
2000 | { | |
2001 | if (target->may_need_copy_reloc(gsym)) | |
2002 | { | |
12c0daef | 2003 | target->copy_reloc(symtab, layout, object, |
f5314dd5 DM |
2004 | data_shndx, output_section, gsym, reloc); |
2005 | } | |
2006 | else if ((r_type == elfcpp::R_SPARC_32 | |
2007 | || r_type == elfcpp::R_SPARC_64) | |
2008 | && gsym->can_use_relative_reloc(false)) | |
2009 | { | |
2010 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
2011 | rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE, | |
2012 | output_section, object, | |
2013 | data_shndx, reloc.get_r_offset(), | |
2014 | reloc.get_r_addend()); | |
2015 | } | |
2016 | else | |
2017 | { | |
2018 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
2019 | ||
32b769e1 | 2020 | check_non_pic(object, r_type); |
f5314dd5 DM |
2021 | if (gsym->is_from_dynobj() |
2022 | || gsym->is_undefined() | |
2023 | || gsym->is_preemptible()) | |
2024 | rela_dyn->add_global(gsym, orig_r_type, output_section, | |
2025 | object, data_shndx, | |
2026 | reloc.get_r_offset(), | |
2027 | reloc.get_r_addend()); | |
2028 | else | |
2029 | rela_dyn->add_global_relative(gsym, orig_r_type, | |
2030 | output_section, object, | |
2031 | data_shndx, | |
2032 | reloc.get_r_offset(), | |
2033 | reloc.get_r_addend()); | |
2034 | } | |
2035 | } | |
2036 | } | |
2037 | break; | |
2038 | ||
2039 | case elfcpp::R_SPARC_GOT10: | |
2040 | case elfcpp::R_SPARC_GOT13: | |
2041 | case elfcpp::R_SPARC_GOT22: | |
2042 | { | |
2043 | // The symbol requires a GOT entry. | |
2044 | Output_data_got<size, big_endian>* got; | |
2045 | ||
2046 | got = target->got_section(symtab, layout); | |
2047 | if (gsym->final_value_is_known()) | |
2048 | got->add_global(gsym, GOT_TYPE_STANDARD); | |
2049 | else | |
2050 | { | |
2051 | // If this symbol is not fully resolved, we need to add a | |
2052 | // dynamic relocation for it. | |
2053 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
2054 | if (gsym->is_from_dynobj() | |
2055 | || gsym->is_undefined() | |
2056 | || gsym->is_preemptible()) | |
2057 | got->add_global_with_rela(gsym, GOT_TYPE_STANDARD, rela_dyn, | |
2058 | elfcpp::R_SPARC_GLOB_DAT); | |
2059 | else if (!gsym->has_got_offset(GOT_TYPE_STANDARD)) | |
2060 | { | |
2061 | unsigned int off = got->add_constant(0); | |
2062 | ||
2063 | gsym->set_got_offset(GOT_TYPE_STANDARD, off); | |
2064 | rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE, | |
2065 | got, off, 0); | |
2066 | } | |
2067 | } | |
2068 | } | |
2069 | break; | |
2070 | ||
2071 | // These are initial tls relocs, which are expected when | |
2072 | // linking. | |
2073 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic | |
2074 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
2075 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
2076 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
2077 | case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic | |
2078 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
2079 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
2080 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
2081 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic | |
2082 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
2083 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
2084 | case elfcpp::R_SPARC_TLS_LE_HIX22: | |
2085 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
2086 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec | |
2087 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
2088 | case elfcpp::R_SPARC_TLS_IE_LD: | |
2089 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
2090 | { | |
2091 | const bool is_final = gsym->final_value_is_known(); | |
2092 | const tls::Tls_optimization optimized_type | |
2093 | = optimize_tls_reloc(is_final, r_type); | |
2094 | switch (r_type) | |
2095 | { | |
2096 | case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic | |
2097 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
2098 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
2099 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
2100 | if (optimized_type == tls::TLSOPT_NONE) | |
2101 | { | |
2102 | // Create a pair of GOT entries for the module index and | |
2103 | // dtv-relative offset. | |
2104 | Output_data_got<size, big_endian>* got | |
2105 | = target->got_section(symtab, layout); | |
2106 | got->add_global_pair_with_rela(gsym, GOT_TYPE_TLS_PAIR, | |
2107 | target->rela_dyn_section(layout), | |
2108 | (size == 64 ? | |
2109 | elfcpp::R_SPARC_TLS_DTPMOD64 : | |
2110 | elfcpp::R_SPARC_TLS_DTPMOD32), | |
2111 | (size == 64 ? | |
2112 | elfcpp::R_SPARC_TLS_DTPOFF64 : | |
2113 | elfcpp::R_SPARC_TLS_DTPOFF32)); | |
2114 | ||
2115 | // Emit R_SPARC_WPLT30 against "__tls_get_addr" | |
2116 | if (r_type == elfcpp::R_SPARC_TLS_GD_CALL) | |
2117 | generate_tls_call(symtab, layout, target); | |
2118 | } | |
2119 | else if (optimized_type == tls::TLSOPT_TO_IE) | |
2120 | { | |
2121 | // Create a GOT entry for the tp-relative offset. | |
2122 | Output_data_got<size, big_endian>* got | |
2123 | = target->got_section(symtab, layout); | |
2124 | got->add_global_with_rela(gsym, GOT_TYPE_TLS_OFFSET, | |
2125 | target->rela_dyn_section(layout), | |
2126 | (size == 64 ? | |
2127 | elfcpp::R_SPARC_TLS_TPOFF64 : | |
2128 | elfcpp::R_SPARC_TLS_TPOFF32)); | |
2129 | } | |
2130 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
2131 | unsupported_reloc_global(object, r_type, gsym); | |
2132 | break; | |
2133 | ||
2134 | case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic | |
2135 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
2136 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
2137 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
2138 | if (optimized_type == tls::TLSOPT_NONE) | |
2139 | { | |
2140 | // Create a GOT entry for the module index. | |
2141 | target->got_mod_index_entry(symtab, layout, object); | |
2142 | ||
2143 | if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL) | |
2144 | generate_tls_call(symtab, layout, target); | |
2145 | } | |
2146 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
2147 | unsupported_reloc_global(object, r_type, gsym); | |
2148 | break; | |
2149 | ||
2150 | case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic | |
2151 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
2152 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
2153 | break; | |
2154 | ||
2155 | case elfcpp::R_SPARC_TLS_LE_HIX22: | |
2156 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
2157 | layout->set_has_static_tls(); | |
2158 | if (parameters->options().shared()) | |
2159 | { | |
2160 | Reloc_section* rela_dyn = target->rela_dyn_section(layout); | |
2161 | rela_dyn->add_global_relative(gsym, orig_r_type, | |
2162 | output_section, object, | |
2163 | data_shndx, reloc.get_r_offset(), | |
2164 | 0); | |
2165 | } | |
2166 | break; | |
2167 | ||
2168 | case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec | |
2169 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
2170 | case elfcpp::R_SPARC_TLS_IE_LD: | |
2171 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
2172 | layout->set_has_static_tls(); | |
2173 | if (optimized_type == tls::TLSOPT_NONE) | |
2174 | { | |
2175 | // Create a GOT entry for the tp-relative offset. | |
2176 | Output_data_got<size, big_endian>* got | |
2177 | = target->got_section(symtab, layout); | |
2178 | got->add_global_with_rela(gsym, GOT_TYPE_TLS_OFFSET, | |
2179 | target->rela_dyn_section(layout), | |
2180 | (size == 64 ? | |
2181 | elfcpp::R_SPARC_TLS_TPOFF64 : | |
2182 | elfcpp::R_SPARC_TLS_TPOFF32)); | |
2183 | } | |
2184 | else if (optimized_type != tls::TLSOPT_TO_LE) | |
2185 | unsupported_reloc_global(object, r_type, gsym); | |
2186 | break; | |
2187 | } | |
2188 | } | |
2189 | break; | |
2190 | ||
2191 | // These are relocations which should only be seen by the | |
2192 | // dynamic linker, and should never be seen here. | |
2193 | case elfcpp::R_SPARC_COPY: | |
2194 | case elfcpp::R_SPARC_GLOB_DAT: | |
2195 | case elfcpp::R_SPARC_JMP_SLOT: | |
2196 | case elfcpp::R_SPARC_RELATIVE: | |
2197 | case elfcpp::R_SPARC_TLS_DTPMOD64: | |
2198 | case elfcpp::R_SPARC_TLS_DTPMOD32: | |
2199 | case elfcpp::R_SPARC_TLS_DTPOFF64: | |
2200 | case elfcpp::R_SPARC_TLS_DTPOFF32: | |
2201 | case elfcpp::R_SPARC_TLS_TPOFF64: | |
2202 | case elfcpp::R_SPARC_TLS_TPOFF32: | |
2203 | gold_error(_("%s: unexpected reloc %u in object file"), | |
2204 | object->name().c_str(), r_type); | |
2205 | break; | |
2206 | ||
2207 | default: | |
2208 | unsupported_reloc_global(object, r_type, gsym); | |
2209 | break; | |
2210 | } | |
2211 | } | |
2212 | ||
2213 | // Scan relocations for a section. | |
2214 | ||
2215 | template<int size, bool big_endian> | |
2216 | void | |
2217 | Target_sparc<size, big_endian>::scan_relocs( | |
2218 | const General_options& options, | |
2219 | Symbol_table* symtab, | |
2220 | Layout* layout, | |
2221 | Sized_relobj<size, big_endian>* object, | |
2222 | unsigned int data_shndx, | |
2223 | unsigned int sh_type, | |
2224 | const unsigned char* prelocs, | |
2225 | size_t reloc_count, | |
2226 | Output_section* output_section, | |
2227 | bool needs_special_offset_handling, | |
2228 | size_t local_symbol_count, | |
2229 | const unsigned char* plocal_symbols) | |
2230 | { | |
2231 | typedef Target_sparc<size, big_endian> Sparc; | |
2232 | typedef typename Target_sparc<size, big_endian>::Scan Scan; | |
2233 | ||
2234 | if (sh_type == elfcpp::SHT_REL) | |
2235 | { | |
2236 | gold_error(_("%s: unsupported REL reloc section"), | |
2237 | object->name().c_str()); | |
2238 | return; | |
2239 | } | |
2240 | ||
2241 | gold::scan_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan>( | |
2242 | options, | |
2243 | symtab, | |
2244 | layout, | |
2245 | this, | |
2246 | object, | |
2247 | data_shndx, | |
2248 | prelocs, | |
2249 | reloc_count, | |
2250 | output_section, | |
2251 | needs_special_offset_handling, | |
2252 | local_symbol_count, | |
2253 | plocal_symbols); | |
2254 | } | |
2255 | ||
2256 | // Finalize the sections. | |
2257 | ||
2258 | template<int size, bool big_endian> | |
2259 | void | |
2260 | Target_sparc<size, big_endian>::do_finalize_sections(Layout* layout) | |
2261 | { | |
2262 | // Fill in some more dynamic tags. | |
2263 | Output_data_dynamic* const odyn = layout->dynamic_data(); | |
2264 | if (odyn != NULL) | |
2265 | { | |
2266 | if (this->plt_ != NULL) | |
2267 | { | |
2268 | const Output_data* od = this->plt_->rel_plt(); | |
2269 | odyn->add_section_size(elfcpp::DT_PLTRELSZ, od); | |
2270 | odyn->add_section_address(elfcpp::DT_JMPREL, od); | |
2271 | odyn->add_constant(elfcpp::DT_PLTREL, elfcpp::DT_RELA); | |
2272 | ||
2273 | odyn->add_section_address(elfcpp::DT_PLTGOT, this->plt_); | |
2274 | } | |
2275 | ||
2276 | if (this->rela_dyn_ != NULL) | |
2277 | { | |
2278 | const Output_data* od = this->rela_dyn_; | |
2279 | odyn->add_section_address(elfcpp::DT_RELA, od); | |
2280 | odyn->add_section_size(elfcpp::DT_RELASZ, od); | |
2281 | odyn->add_constant(elfcpp::DT_RELAENT, | |
2282 | elfcpp::Elf_sizes<size>::rela_size); | |
2283 | } | |
2284 | ||
2285 | if (!parameters->options().shared()) | |
2286 | { | |
2287 | // The value of the DT_DEBUG tag is filled in by the dynamic | |
2288 | // linker at run time, and used by the debugger. | |
2289 | odyn->add_constant(elfcpp::DT_DEBUG, 0); | |
2290 | } | |
2291 | } | |
2292 | ||
2293 | // Emit any relocs we saved in an attempt to avoid generating COPY | |
2294 | // relocs. | |
12c0daef ILT |
2295 | if (this->copy_relocs_.any_saved_relocs()) |
2296 | this->copy_relocs_.emit(this->rela_dyn_section(layout)); | |
f5314dd5 DM |
2297 | } |
2298 | ||
2299 | // Perform a relocation. | |
2300 | ||
2301 | template<int size, bool big_endian> | |
2302 | inline bool | |
2303 | Target_sparc<size, big_endian>::Relocate::relocate( | |
2304 | const Relocate_info<size, big_endian>* relinfo, | |
2305 | Target_sparc* target, | |
2306 | size_t relnum, | |
2307 | const elfcpp::Rela<size, big_endian>& rela, | |
2308 | unsigned int r_type, | |
2309 | const Sized_symbol<size>* gsym, | |
2310 | const Symbol_value<size>* psymval, | |
2311 | unsigned char* view, | |
2312 | typename elfcpp::Elf_types<size>::Elf_Addr address, | |
2313 | section_size_type view_size) | |
2314 | { | |
2315 | r_type &= 0xff; | |
2316 | ||
2317 | if (this->ignore_gd_add_) | |
2318 | { | |
2319 | if (r_type != elfcpp::R_SPARC_TLS_GD_ADD) | |
2320 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), | |
2321 | _("missing expected TLS relocation")); | |
2322 | else | |
2323 | { | |
2324 | this->ignore_gd_add_ = false; | |
2325 | return false; | |
2326 | } | |
2327 | } | |
2328 | ||
2329 | typedef Sparc_relocate_functions<size, big_endian> Reloc; | |
2330 | ||
2331 | // Pick the value to use for symbols defined in shared objects. | |
2332 | Symbol_value<size> symval; | |
2333 | if (gsym != NULL | |
2334 | && (gsym->is_from_dynobj() | |
2335 | || (parameters->options().shared() | |
2336 | && (gsym->is_undefined() || gsym->is_preemptible()))) | |
2337 | && gsym->has_plt_offset()) | |
2338 | { | |
2339 | elfcpp::Elf_Xword value; | |
2340 | ||
2341 | value = target->plt_section()->address() + gsym->plt_offset(); | |
2342 | ||
2343 | symval.set_output_value(value); | |
2344 | ||
2345 | psymval = &symval; | |
2346 | } | |
2347 | ||
2348 | const Sized_relobj<size, big_endian>* object = relinfo->object; | |
2349 | const elfcpp::Elf_Xword addend = rela.get_r_addend(); | |
2350 | ||
2351 | // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT | |
2352 | // pointer points to the beginning, not the end, of the table. | |
2353 | // So we just use the plain offset. | |
2354 | bool have_got_offset = false; | |
2355 | unsigned int got_offset = 0; | |
2356 | switch (r_type) | |
2357 | { | |
2358 | case elfcpp::R_SPARC_GOT10: | |
2359 | case elfcpp::R_SPARC_GOT13: | |
2360 | case elfcpp::R_SPARC_GOT22: | |
2361 | if (gsym != NULL) | |
2362 | { | |
2363 | gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD)); | |
2364 | got_offset = gsym->got_offset(GOT_TYPE_STANDARD); | |
2365 | } | |
2366 | else | |
2367 | { | |
2368 | unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info()); | |
2369 | gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD)); | |
2370 | got_offset = object->local_got_offset(r_sym, GOT_TYPE_STANDARD); | |
2371 | } | |
2372 | have_got_offset = true; | |
2373 | break; | |
2374 | ||
2375 | default: | |
2376 | break; | |
2377 | } | |
2378 | ||
2379 | switch (r_type) | |
2380 | { | |
2381 | case elfcpp::R_SPARC_NONE: | |
2382 | case elfcpp::R_SPARC_REGISTER: | |
2383 | case elfcpp::R_SPARC_GNU_VTINHERIT: | |
2384 | case elfcpp::R_SPARC_GNU_VTENTRY: | |
2385 | break; | |
2386 | ||
2387 | case elfcpp::R_SPARC_8: | |
2388 | Relocate_functions<size, big_endian>::rela8(view, object, | |
2389 | psymval, addend); | |
2390 | break; | |
2391 | ||
2392 | case elfcpp::R_SPARC_16: | |
2393 | Relocate_functions<size, big_endian>::rela16(view, object, | |
2394 | psymval, addend); | |
2395 | break; | |
2396 | ||
2397 | case elfcpp::R_SPARC_32: | |
2398 | if (!parameters->options().output_is_position_independent()) | |
2399 | Relocate_functions<size, big_endian>::rela32(view, object, | |
2400 | psymval, addend); | |
2401 | break; | |
2402 | ||
2403 | case elfcpp::R_SPARC_DISP8: | |
2404 | Reloc::disp8(view, object, psymval, addend, address); | |
2405 | break; | |
2406 | ||
2407 | case elfcpp::R_SPARC_DISP16: | |
2408 | Reloc::disp16(view, object, psymval, addend, address); | |
2409 | break; | |
2410 | ||
2411 | case elfcpp::R_SPARC_DISP32: | |
2412 | Reloc::disp32(view, object, psymval, addend, address); | |
2413 | break; | |
2414 | ||
2415 | case elfcpp::R_SPARC_DISP64: | |
2416 | Reloc::disp64(view, object, psymval, addend, address); | |
2417 | break; | |
2418 | ||
2419 | case elfcpp::R_SPARC_WDISP30: | |
2420 | case elfcpp::R_SPARC_WPLT30: | |
2421 | Reloc::wdisp30(view, object, psymval, addend, address); | |
2422 | break; | |
2423 | ||
2424 | case elfcpp::R_SPARC_WDISP22: | |
2425 | Reloc::wdisp22(view, object, psymval, addend, address); | |
2426 | break; | |
2427 | ||
2428 | case elfcpp::R_SPARC_WDISP19: | |
2429 | Reloc::wdisp19(view, object, psymval, addend, address); | |
2430 | break; | |
2431 | ||
2432 | case elfcpp::R_SPARC_WDISP16: | |
2433 | Reloc::wdisp16(view, object, psymval, addend, address); | |
2434 | break; | |
2435 | ||
2436 | case elfcpp::R_SPARC_HI22: | |
2437 | Reloc::hi22(view, object, psymval, addend); | |
2438 | break; | |
2439 | ||
2440 | case elfcpp::R_SPARC_22: | |
2441 | Reloc::rela32_22(view, object, psymval, addend); | |
2442 | break; | |
2443 | ||
2444 | case elfcpp::R_SPARC_13: | |
2445 | Reloc::rela32_13(view, object, psymval, addend); | |
2446 | break; | |
2447 | ||
2448 | case elfcpp::R_SPARC_LO10: | |
2449 | Reloc::lo10(view, object, psymval, addend); | |
2450 | break; | |
2451 | ||
2452 | case elfcpp::R_SPARC_GOT10: | |
2453 | Reloc::lo10(view, got_offset, addend); | |
2454 | break; | |
2455 | ||
2456 | case elfcpp::R_SPARC_GOT13: | |
2457 | Reloc::rela32_13(view, got_offset, addend); | |
2458 | break; | |
2459 | ||
2460 | case elfcpp::R_SPARC_GOT22: | |
2461 | Reloc::hi22(view, got_offset, addend); | |
2462 | break; | |
2463 | ||
2464 | case elfcpp::R_SPARC_PC10: | |
2465 | Reloc::pc10(view, object, psymval, addend, address); | |
2466 | break; | |
2467 | ||
2468 | case elfcpp::R_SPARC_PC22: | |
2469 | Reloc::pc22(view, object, psymval, addend, address); | |
2470 | break; | |
2471 | ||
2472 | case elfcpp::R_SPARC_TLS_DTPOFF32: | |
2473 | case elfcpp::R_SPARC_UA32: | |
2474 | Reloc::ua32(view, object, psymval, addend); | |
2475 | break; | |
2476 | ||
2477 | case elfcpp::R_SPARC_PLT64: | |
2478 | Relocate_functions<size, big_endian>::rela64(view, object, | |
2479 | psymval, addend); | |
2480 | break; | |
2481 | ||
2482 | case elfcpp::R_SPARC_PLT32: | |
2483 | Relocate_functions<size, big_endian>::rela32(view, object, | |
2484 | psymval, addend); | |
2485 | break; | |
2486 | ||
2487 | case elfcpp::R_SPARC_HIPLT22: | |
2488 | Reloc::hi22(view, object, psymval, addend); | |
2489 | break; | |
2490 | ||
2491 | case elfcpp::R_SPARC_LOPLT10: | |
2492 | Reloc::lo10(view, object, psymval, addend); | |
2493 | break; | |
2494 | ||
2495 | case elfcpp::R_SPARC_PCPLT32: | |
2496 | Reloc::disp32(view, object, psymval, addend, address); | |
2497 | break; | |
2498 | ||
2499 | case elfcpp::R_SPARC_PCPLT22: | |
2500 | Reloc::pcplt22(view, object, psymval, addend, address); | |
2501 | break; | |
2502 | ||
2503 | case elfcpp::R_SPARC_PCPLT10: | |
2504 | Reloc::lo10(view, object, psymval, addend, address); | |
2505 | break; | |
2506 | ||
2507 | case elfcpp::R_SPARC_64: | |
2508 | if (!parameters->options().output_is_position_independent()) | |
2509 | Relocate_functions<size, big_endian>::rela64(view, object, | |
2510 | psymval, addend); | |
2511 | break; | |
2512 | ||
2513 | case elfcpp::R_SPARC_OLO10: | |
2514 | { | |
2515 | unsigned int addend2 = rela.get_r_info() & 0xffffffff; | |
2516 | addend2 = ((addend2 >> 8) ^ 0x800000) - 0x800000; | |
2517 | Reloc::olo10(view, object, psymval, addend, addend2); | |
2518 | } | |
2519 | break; | |
2520 | ||
2521 | case elfcpp::R_SPARC_HH22: | |
2522 | Reloc::hh22(view, object, psymval, addend); | |
2523 | break; | |
2524 | ||
2525 | case elfcpp::R_SPARC_PC_HH22: | |
2526 | Reloc::pc_hh22(view, object, psymval, addend, address); | |
2527 | break; | |
2528 | ||
2529 | case elfcpp::R_SPARC_HM10: | |
2530 | Reloc::hm10(view, object, psymval, addend); | |
2531 | break; | |
2532 | ||
2533 | case elfcpp::R_SPARC_PC_HM10: | |
2534 | Reloc::pc_hm10(view, object, psymval, addend, address); | |
2535 | break; | |
2536 | ||
2537 | case elfcpp::R_SPARC_LM22: | |
2538 | Reloc::hi22(view, object, psymval, addend); | |
2539 | break; | |
2540 | ||
2541 | case elfcpp::R_SPARC_PC_LM22: | |
2542 | Reloc::pcplt22(view, object, psymval, addend, address); | |
2543 | break; | |
2544 | ||
2545 | case elfcpp::R_SPARC_11: | |
2546 | Reloc::rela32_11(view, object, psymval, addend); | |
2547 | break; | |
2548 | ||
2549 | case elfcpp::R_SPARC_10: | |
2550 | Reloc::rela32_10(view, object, psymval, addend); | |
2551 | break; | |
2552 | ||
2553 | case elfcpp::R_SPARC_7: | |
2554 | Reloc::rela32_7(view, object, psymval, addend); | |
2555 | break; | |
2556 | ||
2557 | case elfcpp::R_SPARC_6: | |
2558 | Reloc::rela32_6(view, object, psymval, addend); | |
2559 | break; | |
2560 | ||
2561 | case elfcpp::R_SPARC_5: | |
2562 | Reloc::rela32_5(view, object, psymval, addend); | |
2563 | break; | |
2564 | ||
2565 | case elfcpp::R_SPARC_HIX22: | |
2566 | Reloc::hix22(view, object, psymval, addend); | |
2567 | break; | |
2568 | ||
2569 | case elfcpp::R_SPARC_LOX10: | |
2570 | Reloc::lox10(view, object, psymval, addend); | |
2571 | break; | |
2572 | ||
2573 | case elfcpp::R_SPARC_H44: | |
2574 | Reloc::h44(view, object, psymval, addend); | |
2575 | break; | |
2576 | ||
2577 | case elfcpp::R_SPARC_M44: | |
2578 | Reloc::m44(view, object, psymval, addend); | |
2579 | break; | |
2580 | ||
2581 | case elfcpp::R_SPARC_L44: | |
2582 | Reloc::l44(view, object, psymval, addend); | |
2583 | break; | |
2584 | ||
2585 | case elfcpp::R_SPARC_TLS_DTPOFF64: | |
2586 | case elfcpp::R_SPARC_UA64: | |
2587 | Reloc::ua64(view, object, psymval, addend); | |
2588 | break; | |
2589 | ||
2590 | case elfcpp::R_SPARC_UA16: | |
2591 | Reloc::ua16(view, object, psymval, addend); | |
2592 | break; | |
2593 | ||
2594 | case elfcpp::R_SPARC_TLS_GD_HI22: | |
2595 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
2596 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
2597 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
2598 | case elfcpp::R_SPARC_TLS_LDM_HI22: | |
2599 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
2600 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
2601 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
2602 | case elfcpp::R_SPARC_TLS_LDO_HIX22: | |
2603 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
2604 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
2605 | case elfcpp::R_SPARC_TLS_IE_HI22: | |
2606 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
2607 | case elfcpp::R_SPARC_TLS_IE_LD: | |
2608 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
2609 | case elfcpp::R_SPARC_TLS_LE_HIX22: | |
2610 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
2611 | this->relocate_tls(relinfo, target, relnum, rela, | |
2612 | r_type, gsym, psymval, view, | |
2613 | address, view_size); | |
2614 | break; | |
2615 | ||
2616 | case elfcpp::R_SPARC_COPY: | |
2617 | case elfcpp::R_SPARC_GLOB_DAT: | |
2618 | case elfcpp::R_SPARC_JMP_SLOT: | |
2619 | case elfcpp::R_SPARC_RELATIVE: | |
2620 | // These are outstanding tls relocs, which are unexpected when | |
2621 | // linking. | |
2622 | case elfcpp::R_SPARC_TLS_DTPMOD64: | |
2623 | case elfcpp::R_SPARC_TLS_DTPMOD32: | |
2624 | case elfcpp::R_SPARC_TLS_TPOFF64: | |
2625 | case elfcpp::R_SPARC_TLS_TPOFF32: | |
2626 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), | |
2627 | _("unexpected reloc %u in object file"), | |
2628 | r_type); | |
2629 | break; | |
2630 | ||
2631 | default: | |
2632 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), | |
2633 | _("unsupported reloc %u"), | |
2634 | r_type); | |
2635 | break; | |
2636 | } | |
2637 | ||
2638 | return true; | |
2639 | } | |
2640 | ||
2641 | // Perform a TLS relocation. | |
2642 | ||
2643 | template<int size, bool big_endian> | |
2644 | inline void | |
2645 | Target_sparc<size, big_endian>::Relocate::relocate_tls( | |
2646 | const Relocate_info<size, big_endian>* relinfo, | |
2647 | Target_sparc<size, big_endian>* target, | |
2648 | size_t relnum, | |
2649 | const elfcpp::Rela<size, big_endian>& rela, | |
2650 | unsigned int r_type, | |
2651 | const Sized_symbol<size>* gsym, | |
2652 | const Symbol_value<size>* psymval, | |
2653 | unsigned char* view, | |
2654 | typename elfcpp::Elf_types<size>::Elf_Addr address, | |
2655 | section_size_type) | |
2656 | { | |
2657 | Output_segment* tls_segment = relinfo->layout->tls_segment(); | |
2658 | typedef Sparc_relocate_functions<size, big_endian> Reloc; | |
2659 | const Sized_relobj<size, big_endian>* object = relinfo->object; | |
2660 | typedef typename elfcpp::Swap<32, true>::Valtype Insntype; | |
2661 | ||
2662 | const elfcpp::Elf_Xword addend = rela.get_r_addend(); | |
2663 | typename elfcpp::Elf_types<size>::Elf_Addr value = psymval->value(object, 0); | |
2664 | ||
2665 | const bool is_final = | |
2666 | (gsym == NULL | |
2667 | ? !parameters->options().output_is_position_independent() | |
2668 | : gsym->final_value_is_known()); | |
2669 | const tls::Tls_optimization optimized_type | |
2670 | = optimize_tls_reloc(is_final, r_type); | |
2671 | ||
2672 | switch (r_type) | |
2673 | { | |
2674 | case elfcpp::R_SPARC_TLS_GD_HI22: | |
2675 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
2676 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
2677 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
2678 | if (optimized_type == tls::TLSOPT_TO_LE) | |
2679 | { | |
2680 | Insntype* wv = reinterpret_cast<Insntype*>(view); | |
2681 | Insntype val; | |
2682 | ||
2683 | value -= tls_segment->memsz(); | |
2684 | ||
2685 | switch (r_type) | |
2686 | { | |
2687 | case elfcpp::R_SPARC_TLS_GD_HI22: | |
2688 | // TLS_GD_HI22 --> TLS_LE_HIX22 | |
2689 | Reloc::hix22(view, value, addend); | |
2690 | break; | |
2691 | ||
2692 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
2693 | // TLS_GD_LO10 --> TLS_LE_LOX10 | |
2694 | Reloc::lox10(view, value, addend); | |
2695 | break; | |
2696 | ||
2697 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
2698 | // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3 | |
2699 | val = elfcpp::Swap<32, true>::readval(wv); | |
2700 | val = (val & ~0x7c000) | 0x1c000; | |
2701 | elfcpp::Swap<32, true>::writeval(wv, val); | |
2702 | break; | |
2703 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
2704 | // call __tls_get_addr --> nop | |
2705 | elfcpp::Swap<32, true>::writeval(wv, sparc_nop); | |
2706 | break; | |
2707 | } | |
2708 | break; | |
2709 | } | |
2710 | else | |
2711 | { | |
2712 | unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE | |
2713 | ? GOT_TYPE_TLS_OFFSET | |
2714 | : GOT_TYPE_TLS_PAIR); | |
2715 | if (gsym != NULL) | |
2716 | { | |
2717 | gold_assert(gsym->has_got_offset(got_type)); | |
2718 | value = gsym->got_offset(got_type); | |
2719 | } | |
2720 | else | |
2721 | { | |
2722 | unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info()); | |
2723 | gold_assert(object->local_has_got_offset(r_sym, got_type)); | |
2724 | value = object->local_got_offset(r_sym, got_type); | |
2725 | } | |
2726 | if (optimized_type == tls::TLSOPT_TO_IE) | |
2727 | { | |
2728 | Insntype* wv = reinterpret_cast<Insntype*>(view); | |
2729 | Insntype val; | |
2730 | ||
2731 | switch (r_type) | |
2732 | { | |
2733 | case elfcpp::R_SPARC_TLS_GD_HI22: | |
2734 | // TLS_GD_HI22 --> TLS_IE_HI22 | |
2735 | Reloc::hi22(view, value, addend); | |
2736 | break; | |
2737 | ||
2738 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
2739 | // TLS_GD_LO10 --> TLS_IE_LO10 | |
2740 | Reloc::lo10(view, value, addend); | |
2741 | break; | |
2742 | ||
2743 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
2744 | // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3 | |
2745 | val = elfcpp::Swap<32, true>::readval(wv); | |
2746 | ||
2747 | if (size == 64) | |
2748 | val |= 0xc0580000; | |
2749 | else | |
2750 | val |= 0xc0000000; | |
2751 | ||
2752 | elfcpp::Swap<32, true>::writeval(wv, val); | |
2753 | break; | |
2754 | ||
2755 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
2756 | // The compiler can put the TLS_GD_ADD instruction | |
2757 | // into the delay slot of the call. If so, we need | |
2758 | // to transpose the two instructions so that the | |
2759 | // the new sequence works properly. | |
2760 | // | |
2761 | // The test we use is if the instruction in the | |
2762 | // delay slot is an add with destination register | |
2763 | // equal to %o0 | |
2764 | val = elfcpp::Swap<32, true>::readval(wv + 1); | |
2765 | if ((val & 0x81f80000) == 0x80000000 | |
2766 | && ((val >> 25) & 0x1f) == 0x8) | |
2767 | { | |
2768 | if (size == 64) | |
2769 | val |= 0xc0580000; | |
2770 | else | |
2771 | val |= 0xc0000000; | |
2772 | ||
2773 | elfcpp::Swap<32, true>::writeval(wv, val); | |
2774 | ||
2775 | wv += 1; | |
2776 | this->ignore_gd_add_ = true; | |
2777 | } | |
2778 | ||
2779 | // call __tls_get_addr --> add %g7, %o0, %o0 | |
2780 | elfcpp::Swap<32, true>::writeval(wv, 0x9001c008); | |
2781 | break; | |
2782 | } | |
2783 | break; | |
2784 | } | |
2785 | else if (optimized_type == tls::TLSOPT_NONE) | |
2786 | { | |
2787 | switch (r_type) | |
2788 | { | |
2789 | case elfcpp::R_SPARC_TLS_GD_HI22: | |
2790 | Reloc::hi22(view, value, addend); | |
2791 | break; | |
2792 | case elfcpp::R_SPARC_TLS_GD_LO10: | |
2793 | Reloc::lo10(view, value, addend); | |
2794 | break; | |
2795 | case elfcpp::R_SPARC_TLS_GD_ADD: | |
2796 | break; | |
2797 | case elfcpp::R_SPARC_TLS_GD_CALL: | |
2798 | { | |
2799 | Symbol_value<size> symval; | |
2800 | elfcpp::Elf_Xword value; | |
2801 | Symbol* tsym; | |
2802 | ||
2803 | tsym = target->tls_get_addr_sym_; | |
2804 | gold_assert(tsym); | |
2805 | value = (target->plt_section()->address() + | |
2806 | tsym->plt_offset()); | |
2807 | symval.set_output_value(value); | |
2808 | Reloc::wdisp30(view, object, &symval, addend, address); | |
2809 | } | |
2810 | break; | |
2811 | } | |
2812 | break; | |
2813 | } | |
2814 | } | |
2815 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), | |
2816 | _("unsupported reloc %u"), | |
2817 | r_type); | |
2818 | break; | |
2819 | ||
2820 | case elfcpp::R_SPARC_TLS_LDM_HI22: | |
2821 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
2822 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
2823 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
2824 | if (optimized_type == tls::TLSOPT_TO_LE) | |
2825 | { | |
2826 | Insntype* wv = reinterpret_cast<Insntype*>(view); | |
2827 | ||
2828 | switch (r_type) | |
2829 | { | |
2830 | case elfcpp::R_SPARC_TLS_LDM_HI22: | |
2831 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
2832 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
2833 | elfcpp::Swap<32, true>::writeval(wv, sparc_nop); | |
2834 | break; | |
2835 | ||
2836 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
2837 | elfcpp::Swap<32, true>::writeval(wv, sparc_mov_g0_o0); | |
2838 | break; | |
2839 | } | |
2840 | break; | |
2841 | } | |
2842 | else if (optimized_type == tls::TLSOPT_NONE) | |
2843 | { | |
2844 | // Relocate the field with the offset of the GOT entry for | |
2845 | // the module index. | |
2846 | unsigned int got_offset; | |
2847 | ||
2848 | got_offset = target->got_mod_index_entry(NULL, NULL, NULL); | |
2849 | switch (r_type) | |
2850 | { | |
2851 | case elfcpp::R_SPARC_TLS_LDM_HI22: | |
2852 | Reloc::hi22(view, got_offset, addend); | |
2853 | break; | |
2854 | case elfcpp::R_SPARC_TLS_LDM_LO10: | |
2855 | Reloc::lo10(view, got_offset, addend); | |
2856 | break; | |
2857 | case elfcpp::R_SPARC_TLS_LDM_ADD: | |
2858 | break; | |
2859 | case elfcpp::R_SPARC_TLS_LDM_CALL: | |
2860 | { | |
2861 | Symbol_value<size> symval; | |
2862 | elfcpp::Elf_Xword value; | |
2863 | Symbol* tsym; | |
2864 | ||
2865 | tsym = target->tls_get_addr_sym_; | |
2866 | gold_assert(tsym); | |
2867 | value = (target->plt_section()->address() + | |
2868 | tsym->plt_offset()); | |
2869 | symval.set_output_value(value); | |
2870 | Reloc::wdisp30(view, object, &symval, addend, address); | |
2871 | } | |
2872 | break; | |
2873 | } | |
2874 | break; | |
2875 | } | |
2876 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), | |
2877 | _("unsupported reloc %u"), | |
2878 | r_type); | |
2879 | break; | |
2880 | ||
2881 | // These relocs can appear in debugging sections, in which case | |
2882 | // we won't see the TLS_LDM relocs. The local_dynamic_type | |
2883 | // field tells us this. | |
2884 | case elfcpp::R_SPARC_TLS_LDO_HIX22: | |
2885 | if (optimized_type == tls::TLSOPT_TO_LE) | |
2886 | { | |
2887 | value -= tls_segment->memsz(); | |
2888 | Reloc::hix22(view, value, addend); | |
2889 | } | |
2890 | else | |
2891 | Reloc::ldo_hix22(view, value, addend); | |
2892 | break; | |
2893 | case elfcpp::R_SPARC_TLS_LDO_LOX10: | |
2894 | if (optimized_type == tls::TLSOPT_TO_LE) | |
2895 | { | |
2896 | value -= tls_segment->memsz(); | |
2897 | Reloc::lox10(view, value, addend); | |
2898 | } | |
2899 | else | |
2900 | Reloc::ldo_lox10(view, value, addend); | |
2901 | break; | |
2902 | case elfcpp::R_SPARC_TLS_LDO_ADD: | |
2903 | if (optimized_type == tls::TLSOPT_TO_LE) | |
2904 | { | |
2905 | Insntype* wv = reinterpret_cast<Insntype*>(view); | |
2906 | Insntype val; | |
2907 | ||
2908 | // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3 | |
2909 | val = elfcpp::Swap<32, true>::readval(wv); | |
2910 | val = (val & ~0x7c000) | 0x1c000; | |
2911 | elfcpp::Swap<32, true>::writeval(wv, val); | |
2912 | } | |
2913 | break; | |
2914 | ||
2915 | // When optimizing IE --> LE, the only relocation that is handled | |
2916 | // differently is R_SPARC_TLS_IE_LD, it is rewritten from | |
2917 | // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is | |
2918 | // rs2 and rd are the same. | |
2919 | case elfcpp::R_SPARC_TLS_IE_LD: | |
2920 | case elfcpp::R_SPARC_TLS_IE_LDX: | |
2921 | if (optimized_type == tls::TLSOPT_TO_LE) | |
2922 | { | |
2923 | Insntype* wv = reinterpret_cast<Insntype*>(view); | |
2924 | Insntype val = elfcpp::Swap<32, true>::readval(wv); | |
2925 | Insntype rs2 = val & 0x1f; | |
2926 | Insntype rd = (val >> 25) & 0x1f; | |
2927 | ||
2928 | if (rs2 == rd) | |
2929 | val = sparc_nop; | |
2930 | else | |
2931 | val = sparc_mov | (val & 0x3e00001f); | |
2932 | ||
2933 | elfcpp::Swap<32, true>::writeval(wv, val); | |
2934 | } | |
2935 | break; | |
2936 | ||
2937 | case elfcpp::R_SPARC_TLS_IE_HI22: | |
2938 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
2939 | if (optimized_type == tls::TLSOPT_TO_LE) | |
2940 | { | |
2941 | value -= tls_segment->memsz(); | |
2942 | switch (r_type) | |
2943 | { | |
2944 | case elfcpp::R_SPARC_TLS_IE_HI22: | |
2945 | // IE_HI22 --> LE_HIX22 | |
2946 | Reloc::hix22(view, value, addend); | |
2947 | break; | |
2948 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
2949 | // IE_LO10 --> LE_LOX10 | |
2950 | Reloc::lox10(view, value, addend); | |
2951 | break; | |
2952 | } | |
2953 | break; | |
2954 | } | |
2955 | else if (optimized_type == tls::TLSOPT_NONE) | |
2956 | { | |
2957 | // Relocate the field with the offset of the GOT entry for | |
2958 | // the tp-relative offset of the symbol. | |
2959 | if (gsym != NULL) | |
2960 | { | |
2961 | gold_assert(gsym->has_got_offset(GOT_TYPE_TLS_OFFSET)); | |
2962 | value = gsym->got_offset(GOT_TYPE_TLS_OFFSET); | |
2963 | } | |
2964 | else | |
2965 | { | |
2966 | unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info()); | |
2967 | gold_assert(object->local_has_got_offset(r_sym, | |
2968 | GOT_TYPE_TLS_OFFSET)); | |
2969 | value = object->local_got_offset(r_sym, | |
2970 | GOT_TYPE_TLS_OFFSET); | |
2971 | } | |
2972 | switch (r_type) | |
2973 | { | |
2974 | case elfcpp::R_SPARC_TLS_IE_HI22: | |
2975 | Reloc::hi22(view, value, addend); | |
2976 | break; | |
2977 | case elfcpp::R_SPARC_TLS_IE_LO10: | |
2978 | Reloc::lo10(view, value, addend); | |
2979 | break; | |
2980 | } | |
2981 | break; | |
2982 | } | |
2983 | gold_error_at_location(relinfo, relnum, rela.get_r_offset(), | |
2984 | _("unsupported reloc %u"), | |
2985 | r_type); | |
2986 | break; | |
2987 | ||
2988 | case elfcpp::R_SPARC_TLS_LE_HIX22: | |
2989 | // If we're creating a shared library, a dynamic relocation will | |
2990 | // have been created for this location, so do not apply it now. | |
2991 | if (!parameters->options().shared()) | |
2992 | { | |
2993 | value -= tls_segment->memsz(); | |
2994 | Reloc::hix22(view, value, addend); | |
2995 | } | |
2996 | break; | |
2997 | ||
2998 | case elfcpp::R_SPARC_TLS_LE_LOX10: | |
2999 | // If we're creating a shared library, a dynamic relocation will | |
3000 | // have been created for this location, so do not apply it now. | |
3001 | if (!parameters->options().shared()) | |
3002 | { | |
3003 | value -= tls_segment->memsz(); | |
3004 | Reloc::lox10(view, value, addend); | |
3005 | } | |
3006 | break; | |
3007 | } | |
3008 | } | |
3009 | ||
3010 | // Relocate section data. | |
3011 | ||
3012 | template<int size, bool big_endian> | |
3013 | void | |
3014 | Target_sparc<size, big_endian>::relocate_section( | |
3015 | const Relocate_info<size, big_endian>* relinfo, | |
3016 | unsigned int sh_type, | |
3017 | const unsigned char* prelocs, | |
3018 | size_t reloc_count, | |
3019 | Output_section* output_section, | |
3020 | bool needs_special_offset_handling, | |
3021 | unsigned char* view, | |
3022 | typename elfcpp::Elf_types<size>::Elf_Addr address, | |
3023 | section_size_type view_size) | |
3024 | { | |
3025 | typedef Target_sparc<size, big_endian> Sparc; | |
3026 | typedef typename Target_sparc<size, big_endian>::Relocate Sparc_relocate; | |
3027 | ||
3028 | gold_assert(sh_type == elfcpp::SHT_RELA); | |
3029 | ||
3030 | gold::relocate_section<size, big_endian, Sparc, elfcpp::SHT_RELA, | |
3031 | Sparc_relocate>( | |
3032 | relinfo, | |
3033 | this, | |
3034 | prelocs, | |
3035 | reloc_count, | |
3036 | output_section, | |
3037 | needs_special_offset_handling, | |
3038 | view, | |
3039 | address, | |
3040 | view_size); | |
3041 | } | |
3042 | ||
3043 | // Return the size of a relocation while scanning during a relocatable | |
3044 | // link. | |
3045 | ||
3046 | template<int size, bool big_endian> | |
3047 | unsigned int | |
3048 | Target_sparc<size, big_endian>::Relocatable_size_for_reloc::get_size_for_reloc( | |
3049 | unsigned int, | |
3050 | Relobj*) | |
3051 | { | |
3052 | // We are always SHT_RELA, so we should never get here. | |
3053 | gold_unreachable(); | |
3054 | return 0; | |
3055 | } | |
3056 | ||
3057 | // Scan the relocs during a relocatable link. | |
3058 | ||
3059 | template<int size, bool big_endian> | |
3060 | void | |
3061 | Target_sparc<size, big_endian>::scan_relocatable_relocs( | |
3062 | const General_options& options, | |
3063 | Symbol_table* symtab, | |
3064 | Layout* layout, | |
3065 | Sized_relobj<size, big_endian>* object, | |
3066 | unsigned int data_shndx, | |
3067 | unsigned int sh_type, | |
3068 | const unsigned char* prelocs, | |
3069 | size_t reloc_count, | |
3070 | Output_section* output_section, | |
3071 | bool needs_special_offset_handling, | |
3072 | size_t local_symbol_count, | |
3073 | const unsigned char* plocal_symbols, | |
3074 | Relocatable_relocs* rr) | |
3075 | { | |
3076 | gold_assert(sh_type == elfcpp::SHT_RELA); | |
3077 | ||
3078 | typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA, | |
3079 | Relocatable_size_for_reloc> Scan_relocatable_relocs; | |
3080 | ||
3081 | gold::scan_relocatable_relocs<size, big_endian, elfcpp::SHT_RELA, | |
3082 | Scan_relocatable_relocs>( | |
3083 | options, | |
3084 | symtab, | |
3085 | layout, | |
3086 | object, | |
3087 | data_shndx, | |
3088 | prelocs, | |
3089 | reloc_count, | |
3090 | output_section, | |
3091 | needs_special_offset_handling, | |
3092 | local_symbol_count, | |
3093 | plocal_symbols, | |
3094 | rr); | |
3095 | } | |
3096 | ||
3097 | // Relocate a section during a relocatable link. | |
3098 | ||
3099 | template<int size, bool big_endian> | |
3100 | void | |
3101 | Target_sparc<size, big_endian>::relocate_for_relocatable( | |
3102 | const Relocate_info<size, big_endian>* relinfo, | |
3103 | unsigned int sh_type, | |
3104 | const unsigned char* prelocs, | |
3105 | size_t reloc_count, | |
3106 | Output_section* output_section, | |
3107 | off_t offset_in_output_section, | |
3108 | const Relocatable_relocs* rr, | |
3109 | unsigned char* view, | |
3110 | typename elfcpp::Elf_types<size>::Elf_Addr view_address, | |
3111 | section_size_type view_size, | |
3112 | unsigned char* reloc_view, | |
3113 | section_size_type reloc_view_size) | |
3114 | { | |
3115 | gold_assert(sh_type == elfcpp::SHT_RELA); | |
3116 | ||
3117 | gold::relocate_for_relocatable<size, big_endian, elfcpp::SHT_RELA>( | |
3118 | relinfo, | |
3119 | prelocs, | |
3120 | reloc_count, | |
3121 | output_section, | |
3122 | offset_in_output_section, | |
3123 | rr, | |
3124 | view, | |
3125 | view_address, | |
3126 | view_size, | |
3127 | reloc_view, | |
3128 | reloc_view_size); | |
3129 | } | |
3130 | ||
3131 | // Return the value to use for a dynamic which requires special | |
3132 | // treatment. This is how we support equality comparisons of function | |
3133 | // pointers across shared library boundaries, as described in the | |
3134 | // processor specific ABI supplement. | |
3135 | ||
3136 | template<int size, bool big_endian> | |
3137 | uint64_t | |
3138 | Target_sparc<size, big_endian>::do_dynsym_value(const Symbol* gsym) const | |
3139 | { | |
3140 | gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset()); | |
3141 | return this->plt_section()->address() + gsym->plt_offset(); | |
3142 | } | |
3143 | ||
3144 | // The selector for sparc object files. | |
3145 | ||
3146 | template<int size, bool big_endian> | |
3147 | class Target_selector_sparc : public Target_selector | |
3148 | { | |
3149 | public: | |
3150 | Target_selector_sparc() | |
3151 | : Target_selector(elfcpp::EM_NONE, size, big_endian, | |
3152 | (size == 64 ? "elf64-sparc" : "elf32-sparc")) | |
3153 | { } | |
3154 | ||
3155 | Target* instantiated_target_; | |
3156 | ||
3157 | Target* do_recognize(int machine, int, int) | |
3158 | { | |
3159 | switch (size) | |
3160 | { | |
3161 | case 64: | |
3162 | if (machine != elfcpp::EM_SPARCV9) | |
3163 | return NULL; | |
3164 | break; | |
3165 | ||
3166 | case 32: | |
3167 | if (machine != elfcpp::EM_SPARC | |
3168 | && machine != elfcpp::EM_SPARC32PLUS) | |
3169 | return NULL; | |
3170 | break; | |
3171 | ||
3172 | default: | |
3173 | return NULL; | |
3174 | } | |
3175 | ||
3176 | return do_instantiate_target(); | |
3177 | } | |
3178 | ||
3179 | Target* do_instantiate_target() | |
3180 | { | |
3181 | if (this->instantiated_target_ == NULL) | |
3182 | this->instantiated_target_ = new Target_sparc<size, big_endian>(); | |
3183 | return this->instantiated_target_; | |
3184 | } | |
3185 | }; | |
3186 | ||
3187 | Target_selector_sparc<32, true> target_selector_sparc32; | |
3188 | Target_selector_sparc<64, true> target_selector_sparc64; | |
3189 | ||
3190 | } // End anonymous namespace. |