* arm.cc (Target_arm::gc_process_relocs): Use typename.
[deliverable/binutils-gdb.git] / gold / powerpc.cc
1 // powerpc.cc -- powerpc target support for gold.
2
3 // Copyright 2008, 2009 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>
5 // and David Edelsohn <edelsohn@gnu.org>
6
7 // This file is part of gold.
8
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
13
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 // MA 02110-1301, USA.
23
24 #include "gold.h"
25
26 #include "elfcpp.h"
27 #include "parameters.h"
28 #include "reloc.h"
29 #include "powerpc.h"
30 #include "object.h"
31 #include "symtab.h"
32 #include "layout.h"
33 #include "output.h"
34 #include "copy-relocs.h"
35 #include "target.h"
36 #include "target-reloc.h"
37 #include "target-select.h"
38 #include "tls.h"
39 #include "errors.h"
40 #include "gc.h"
41
42 namespace
43 {
44
45 using namespace gold;
46
47 template<int size, bool big_endian>
48 class Output_data_plt_powerpc;
49
50 template<int size, bool big_endian>
51 class Target_powerpc : public Sized_target<size, big_endian>
52 {
53 public:
54 typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian> Reloc_section;
55
56 Target_powerpc()
57 : Sized_target<size, big_endian>(&powerpc_info),
58 got_(NULL), got2_(NULL), toc_(NULL),
59 plt_(NULL), rela_dyn_(NULL),
60 copy_relocs_(elfcpp::R_POWERPC_COPY),
61 dynbss_(NULL), got_mod_index_offset_(-1U)
62 {
63 }
64
65 // Process the relocations to determine unreferenced sections for
66 // garbage collection.
67 void
68 gc_process_relocs(Symbol_table* symtab,
69 Layout* layout,
70 Sized_relobj<size, big_endian>* object,
71 unsigned int data_shndx,
72 unsigned int sh_type,
73 const unsigned char* prelocs,
74 size_t reloc_count,
75 Output_section* output_section,
76 bool needs_special_offset_handling,
77 size_t local_symbol_count,
78 const unsigned char* plocal_symbols);
79
80 // Scan the relocations to look for symbol adjustments.
81 void
82 scan_relocs(Symbol_table* symtab,
83 Layout* layout,
84 Sized_relobj<size, big_endian>* object,
85 unsigned int data_shndx,
86 unsigned int sh_type,
87 const unsigned char* prelocs,
88 size_t reloc_count,
89 Output_section* output_section,
90 bool needs_special_offset_handling,
91 size_t local_symbol_count,
92 const unsigned char* plocal_symbols);
93 // Finalize the sections.
94 void
95 do_finalize_sections(Layout*, const Input_objects*, Symbol_table*);
96
97 // Return the value to use for a dynamic which requires special
98 // treatment.
99 uint64_t
100 do_dynsym_value(const Symbol*) const;
101
102 // Relocate a section.
103 void
104 relocate_section(const Relocate_info<size, big_endian>*,
105 unsigned int sh_type,
106 const unsigned char* prelocs,
107 size_t reloc_count,
108 Output_section* output_section,
109 bool needs_special_offset_handling,
110 unsigned char* view,
111 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
112 section_size_type view_size,
113 const Reloc_symbol_changes*);
114
115 // Scan the relocs during a relocatable link.
116 void
117 scan_relocatable_relocs(Symbol_table* symtab,
118 Layout* layout,
119 Sized_relobj<size, big_endian>* object,
120 unsigned int data_shndx,
121 unsigned int sh_type,
122 const unsigned char* prelocs,
123 size_t reloc_count,
124 Output_section* output_section,
125 bool needs_special_offset_handling,
126 size_t local_symbol_count,
127 const unsigned char* plocal_symbols,
128 Relocatable_relocs*);
129
130 // Relocate a section during a relocatable link.
131 void
132 relocate_for_relocatable(const Relocate_info<size, big_endian>*,
133 unsigned int sh_type,
134 const unsigned char* prelocs,
135 size_t reloc_count,
136 Output_section* output_section,
137 off_t offset_in_output_section,
138 const Relocatable_relocs*,
139 unsigned char* view,
140 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
141 section_size_type view_size,
142 unsigned char* reloc_view,
143 section_size_type reloc_view_size);
144
145 // Return whether SYM is defined by the ABI.
146 bool
147 do_is_defined_by_abi(const Symbol* sym) const
148 {
149 return strcmp(sym->name(), "___tls_get_addr") == 0;
150 }
151
152 // Return the size of the GOT section.
153 section_size_type
154 got_size()
155 {
156 gold_assert(this->got_ != NULL);
157 return this->got_->data_size();
158 }
159
160 private:
161
162 // The class which scans relocations.
163 class Scan
164 {
165 public:
166 Scan()
167 : issued_non_pic_error_(false)
168 { }
169
170 inline void
171 local(Symbol_table* symtab, Layout* layout, Target_powerpc* 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 const elfcpp::Sym<size, big_endian>& lsym);
177
178 inline void
179 global(Symbol_table* symtab, Layout* layout, Target_powerpc* target,
180 Sized_relobj<size, big_endian>* object,
181 unsigned int data_shndx,
182 Output_section* output_section,
183 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
184 Symbol* gsym);
185
186 inline bool
187 local_reloc_may_be_function_pointer(Symbol_table* , Layout* ,
188 Target_powerpc* ,
189 Sized_relobj<size, big_endian>* ,
190 unsigned int ,
191 Output_section* ,
192 const elfcpp::Rela<size, big_endian>& ,
193 unsigned int ,
194 const elfcpp::Sym<size, big_endian>&)
195 { return false; }
196
197 inline bool
198 global_reloc_may_be_function_pointer(Symbol_table* , Layout* ,
199 Target_powerpc* ,
200 Sized_relobj<size, big_endian>* ,
201 unsigned int ,
202 Output_section* ,
203 const elfcpp::Rela<size,
204 big_endian>& ,
205 unsigned int , Symbol*)
206 { return false; }
207
208 private:
209 static void
210 unsupported_reloc_local(Sized_relobj<size, big_endian>*,
211 unsigned int r_type);
212
213 static void
214 unsupported_reloc_global(Sized_relobj<size, big_endian>*,
215 unsigned int r_type, Symbol*);
216
217 static void
218 generate_tls_call(Symbol_table* symtab, Layout* layout,
219 Target_powerpc* target);
220
221 void
222 check_non_pic(Relobj*, unsigned int r_type);
223
224 // Whether we have issued an error about a non-PIC compilation.
225 bool issued_non_pic_error_;
226 };
227
228 // The class which implements relocation.
229 class Relocate
230 {
231 public:
232 // Do a relocation. Return false if the caller should not issue
233 // any warnings about this relocation.
234 inline bool
235 relocate(const Relocate_info<size, big_endian>*, Target_powerpc*,
236 Output_section*, size_t relnum,
237 const elfcpp::Rela<size, big_endian>&,
238 unsigned int r_type, const Sized_symbol<size>*,
239 const Symbol_value<size>*,
240 unsigned char*,
241 typename elfcpp::Elf_types<size>::Elf_Addr,
242 section_size_type);
243
244 private:
245 // Do a TLS relocation.
246 inline void
247 relocate_tls(const Relocate_info<size, big_endian>*,
248 Target_powerpc* target,
249 size_t relnum, const elfcpp::Rela<size, big_endian>&,
250 unsigned int r_type, const Sized_symbol<size>*,
251 const Symbol_value<size>*,
252 unsigned char*,
253 typename elfcpp::Elf_types<size>::Elf_Addr,
254 section_size_type);
255 };
256
257 // A class which returns the size required for a relocation type,
258 // used while scanning relocs during a relocatable link.
259 class Relocatable_size_for_reloc
260 {
261 public:
262 unsigned int
263 get_size_for_reloc(unsigned int, Relobj*);
264 };
265
266 // Get the GOT section, creating it if necessary.
267 Output_data_got<size, big_endian>*
268 got_section(Symbol_table*, Layout*);
269
270 Output_data_space*
271 got2_section() const
272 {
273 gold_assert (this->got2_ != NULL);
274 return this->got2_;
275 }
276
277 // Get the TOC section.
278 Output_data_space*
279 toc_section() const
280 {
281 gold_assert (this->toc_ != NULL);
282 return this->toc_;
283 }
284
285 // Create a PLT entry for a global symbol.
286 void
287 make_plt_entry(Symbol_table*, Layout*, Symbol*);
288
289 // Create a GOT entry for the TLS module index.
290 unsigned int
291 got_mod_index_entry(Symbol_table* symtab, Layout* layout,
292 Sized_relobj<size, big_endian>* object);
293
294 // Get the PLT section.
295 const Output_data_plt_powerpc<size, big_endian>*
296 plt_section() const
297 {
298 gold_assert(this->plt_ != NULL);
299 return this->plt_;
300 }
301
302 // Get the dynamic reloc section, creating it if necessary.
303 Reloc_section*
304 rela_dyn_section(Layout*);
305
306 // Copy a relocation against a global symbol.
307 void
308 copy_reloc(Symbol_table* symtab, Layout* layout,
309 Sized_relobj<size, big_endian>* object,
310 unsigned int shndx, Output_section* output_section,
311 Symbol* sym, const elfcpp::Rela<size, big_endian>& reloc)
312 {
313 this->copy_relocs_.copy_reloc(symtab, layout,
314 symtab->get_sized_symbol<size>(sym),
315 object, shndx, output_section,
316 reloc, this->rela_dyn_section(layout));
317 }
318
319 // Information about this specific target which we pass to the
320 // general Target structure.
321 static Target::Target_info powerpc_info;
322
323 // The types of GOT entries needed for this platform.
324 enum Got_type
325 {
326 GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol
327 GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset
328 GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair
329 };
330
331 // The GOT section.
332 Output_data_got<size, big_endian>* got_;
333 // The GOT2 section.
334 Output_data_space* got2_;
335 // The TOC section.
336 Output_data_space* toc_;
337 // The PLT section.
338 Output_data_plt_powerpc<size, big_endian>* plt_;
339 // The dynamic reloc section.
340 Reloc_section* rela_dyn_;
341 // Relocs saved to avoid a COPY reloc.
342 Copy_relocs<elfcpp::SHT_RELA, size, big_endian> copy_relocs_;
343 // Space for variables copied with a COPY reloc.
344 Output_data_space* dynbss_;
345 // Offset of the GOT entry for the TLS module index;
346 unsigned int got_mod_index_offset_;
347 };
348
349 template<>
350 Target::Target_info Target_powerpc<32, true>::powerpc_info =
351 {
352 32, // size
353 true, // is_big_endian
354 elfcpp::EM_PPC, // machine_code
355 false, // has_make_symbol
356 false, // has_resolve
357 false, // has_code_fill
358 true, // is_default_stack_executable
359 '\0', // wrap_char
360 "/usr/lib/ld.so.1", // dynamic_linker
361 0x10000000, // default_text_segment_address
362 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
363 4 * 1024, // common_pagesize (overridable by -z common-page-size)
364 elfcpp::SHN_UNDEF, // small_common_shndx
365 elfcpp::SHN_UNDEF, // large_common_shndx
366 0, // small_common_section_flags
367 0, // large_common_section_flags
368 NULL, // attributes_section
369 NULL // attributes_vendor
370 };
371
372 template<>
373 Target::Target_info Target_powerpc<32, false>::powerpc_info =
374 {
375 32, // size
376 false, // is_big_endian
377 elfcpp::EM_PPC, // machine_code
378 false, // has_make_symbol
379 false, // has_resolve
380 false, // has_code_fill
381 true, // is_default_stack_executable
382 '\0', // wrap_char
383 "/usr/lib/ld.so.1", // dynamic_linker
384 0x10000000, // default_text_segment_address
385 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
386 4 * 1024, // common_pagesize (overridable by -z common-page-size)
387 elfcpp::SHN_UNDEF, // small_common_shndx
388 elfcpp::SHN_UNDEF, // large_common_shndx
389 0, // small_common_section_flags
390 0, // large_common_section_flags
391 NULL, // attributes_section
392 NULL // attributes_vendor
393 };
394
395 template<>
396 Target::Target_info Target_powerpc<64, true>::powerpc_info =
397 {
398 64, // size
399 true, // is_big_endian
400 elfcpp::EM_PPC64, // machine_code
401 false, // has_make_symbol
402 false, // has_resolve
403 false, // has_code_fill
404 true, // is_default_stack_executable
405 '\0', // wrap_char
406 "/usr/lib/ld.so.1", // dynamic_linker
407 0x10000000, // default_text_segment_address
408 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
409 8 * 1024, // common_pagesize (overridable by -z common-page-size)
410 elfcpp::SHN_UNDEF, // small_common_shndx
411 elfcpp::SHN_UNDEF, // large_common_shndx
412 0, // small_common_section_flags
413 0, // large_common_section_flags
414 NULL, // attributes_section
415 NULL // attributes_vendor
416 };
417
418 template<>
419 Target::Target_info Target_powerpc<64, false>::powerpc_info =
420 {
421 64, // size
422 false, // is_big_endian
423 elfcpp::EM_PPC64, // machine_code
424 false, // has_make_symbol
425 false, // has_resolve
426 false, // has_code_fill
427 true, // is_default_stack_executable
428 '\0', // wrap_char
429 "/usr/lib/ld.so.1", // dynamic_linker
430 0x10000000, // default_text_segment_address
431 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
432 8 * 1024, // common_pagesize (overridable by -z common-page-size)
433 elfcpp::SHN_UNDEF, // small_common_shndx
434 elfcpp::SHN_UNDEF, // large_common_shndx
435 0, // small_common_section_flags
436 0, // large_common_section_flags
437 NULL, // attributes_section
438 NULL // attributes_vendor
439 };
440
441 template<int size, bool big_endian>
442 class Powerpc_relocate_functions
443 {
444 private:
445 // Do a simple relocation with the addend in the relocation.
446 template<int valsize>
447 static inline void
448 rela(unsigned char* view,
449 unsigned int right_shift,
450 elfcpp::Elf_Xword dst_mask,
451 typename elfcpp::Swap<size, big_endian>::Valtype value,
452 typename elfcpp::Swap<size, big_endian>::Valtype addend)
453 {
454 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
455 Valtype* wv = reinterpret_cast<Valtype*>(view);
456 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
457 Valtype reloc = ((value + addend) >> 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 // Do a simple relocation using a symbol value with the addend in
466 // the relocation.
467 template<int valsize>
468 static inline void
469 rela(unsigned char* view,
470 unsigned int right_shift,
471 elfcpp::Elf_Xword dst_mask,
472 const Sized_relobj<size, big_endian>* object,
473 const Symbol_value<size>* psymval,
474 typename elfcpp::Swap<valsize, big_endian>::Valtype addend)
475 {
476 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
477 Valtype* wv = reinterpret_cast<Valtype*>(view);
478 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
479 Valtype reloc = (psymval->value(object, addend) >> right_shift);
480
481 val &= ~dst_mask;
482 reloc &= dst_mask;
483
484 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
485 }
486
487 // Do a simple relocation using a symbol value with the addend in
488 // the relocation, unaligned.
489 template<int valsize>
490 static inline void
491 rela_ua(unsigned char* view, unsigned int right_shift,
492 elfcpp::Elf_Xword dst_mask,
493 const Sized_relobj<size, big_endian>* object,
494 const Symbol_value<size>* psymval,
495 typename elfcpp::Swap<size, big_endian>::Valtype addend)
496 {
497 typedef typename elfcpp::Swap_unaligned<valsize,
498 big_endian>::Valtype Valtype;
499 unsigned char* wv = view;
500 Valtype val = elfcpp::Swap_unaligned<valsize, big_endian>::readval(wv);
501 Valtype reloc = (psymval->value(object, addend) >> right_shift);
502
503 val &= ~dst_mask;
504 reloc &= dst_mask;
505
506 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, val | reloc);
507 }
508
509 // Do a simple PC relative relocation with a Symbol_value with the
510 // addend in the relocation.
511 template<int valsize>
512 static inline void
513 pcrela(unsigned char* view, unsigned int right_shift,
514 elfcpp::Elf_Xword dst_mask,
515 const Sized_relobj<size, big_endian>* object,
516 const Symbol_value<size>* psymval,
517 typename elfcpp::Swap<size, big_endian>::Valtype addend,
518 typename elfcpp::Elf_types<size>::Elf_Addr address)
519 {
520 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
521 Valtype* wv = reinterpret_cast<Valtype*>(view);
522 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
523 Valtype reloc = ((psymval->value(object, addend) - address)
524 >> right_shift);
525
526 val &= ~dst_mask;
527 reloc &= dst_mask;
528
529 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
530 }
531
532 template<int valsize>
533 static inline void
534 pcrela_unaligned(unsigned char* view,
535 const Sized_relobj<size, big_endian>* object,
536 const Symbol_value<size>* psymval,
537 typename elfcpp::Swap<size, big_endian>::Valtype addend,
538 typename elfcpp::Elf_types<size>::Elf_Addr address)
539 {
540 typedef typename elfcpp::Swap_unaligned<valsize,
541 big_endian>::Valtype Valtype;
542 unsigned char* wv = view;
543 Valtype reloc = (psymval->value(object, addend) - address);
544
545 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, reloc);
546 }
547
548 typedef Powerpc_relocate_functions<size, big_endian> This;
549 typedef Relocate_functions<size, big_endian> This_reloc;
550 public:
551 // R_POWERPC_REL32: (Symbol + Addend - Address)
552 static inline void
553 rel32(unsigned char* view,
554 const Sized_relobj<size, big_endian>* object,
555 const Symbol_value<size>* psymval,
556 typename elfcpp::Elf_types<size>::Elf_Addr addend,
557 typename elfcpp::Elf_types<size>::Elf_Addr address)
558 { This_reloc::pcrela32(view, object, psymval, addend, address); }
559
560 // R_POWERPC_REL24: (Symbol + Addend - Address) & 0x3fffffc
561 static inline void
562 rel24(unsigned char* view,
563 const Sized_relobj<size, big_endian>* object,
564 const Symbol_value<size>* psymval,
565 typename elfcpp::Elf_types<size>::Elf_Addr addend,
566 typename elfcpp::Elf_types<size>::Elf_Addr address)
567 {
568 This::template pcrela<32>(view, 0, 0x03fffffc, object,
569 psymval, addend, address);
570 }
571
572 // R_POWERPC_REL14: (Symbol + Addend - Address) & 0xfffc
573 static inline void
574 rel14(unsigned char* view,
575 const Sized_relobj<size, big_endian>* object,
576 const Symbol_value<size>* psymval,
577 typename elfcpp::Elf_types<size>::Elf_Addr addend,
578 typename elfcpp::Elf_types<size>::Elf_Addr address)
579 {
580 This::template pcrela<32>(view, 0, 0x0000fffc, object,
581 psymval, addend, address);
582 }
583
584 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
585 static inline void
586 addr16(unsigned char* view,
587 typename elfcpp::Elf_types<size>::Elf_Addr value,
588 typename elfcpp::Elf_types<size>::Elf_Addr addend)
589 { This_reloc::rela16(view, value, addend); }
590
591 static inline void
592 addr16(unsigned char* view,
593 const Sized_relobj<size, big_endian>* object,
594 const Symbol_value<size>* psymval,
595 typename elfcpp::Elf_types<size>::Elf_Addr addend)
596 { This_reloc::rela16(view, object, psymval, addend); }
597
598 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
599 static inline void
600 addr16_ds(unsigned char* view,
601 typename elfcpp::Elf_types<size>::Elf_Addr value,
602 typename elfcpp::Elf_types<size>::Elf_Addr addend)
603 {
604 This::template rela<16>(view, 0, 0xfffc, value, addend);
605 }
606
607 // R_POWERPC_ADDR16_LO: (Symbol + Addend) & 0xffff
608 static inline void
609 addr16_lo(unsigned char* view,
610 typename elfcpp::Elf_types<size>::Elf_Addr value,
611 typename elfcpp::Elf_types<size>::Elf_Addr addend)
612 { This_reloc::rela16(view, value, addend); }
613
614 static inline void
615 addr16_lo(unsigned char* view,
616 const Sized_relobj<size, big_endian>* object,
617 const Symbol_value<size>* psymval,
618 typename elfcpp::Elf_types<size>::Elf_Addr addend)
619 { This_reloc::rela16(view, object, psymval, addend); }
620
621 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
622 static inline void
623 addr16_hi(unsigned char* view,
624 typename elfcpp::Elf_types<size>::Elf_Addr value,
625 typename elfcpp::Elf_types<size>::Elf_Addr addend)
626 {
627 This::template rela<16>(view, 16, 0xffff, value, addend);
628 }
629
630 static inline void
631 addr16_hi(unsigned char* view,
632 const Sized_relobj<size, big_endian>* object,
633 const Symbol_value<size>* psymval,
634 typename elfcpp::Elf_types<size>::Elf_Addr addend)
635 {
636 This::template rela<16>(view, 16, 0xffff, object, psymval, addend);
637 }
638
639 // R_POWERPC_ADDR16_HA: Same as R_POWERPC_ADDR16_HI except that if the
640 // final value of the low 16 bits of the
641 // relocation is negative, add one.
642 static inline void
643 addr16_ha(unsigned char* view,
644 typename elfcpp::Elf_types<size>::Elf_Addr value,
645 typename elfcpp::Elf_types<size>::Elf_Addr addend)
646 {
647 typename elfcpp::Elf_types<size>::Elf_Addr reloc;
648
649 reloc = value + addend;
650
651 if (reloc & 0x8000)
652 reloc += 0x10000;
653 reloc >>= 16;
654
655 elfcpp::Swap<16, big_endian>::writeval(view, reloc);
656 }
657
658 static inline void
659 addr16_ha(unsigned char* view,
660 const Sized_relobj<size, big_endian>* object,
661 const Symbol_value<size>* psymval,
662 typename elfcpp::Elf_types<size>::Elf_Addr addend)
663 {
664 typename elfcpp::Elf_types<size>::Elf_Addr reloc;
665
666 reloc = psymval->value(object, addend);
667
668 if (reloc & 0x8000)
669 reloc += 0x10000;
670 reloc >>= 16;
671
672 elfcpp::Swap<16, big_endian>::writeval(view, reloc);
673 }
674
675 // R_PPC_REL16: (Symbol + Addend - Address) & 0xffff
676 static inline void
677 rel16(unsigned char* view,
678 const Sized_relobj<size, big_endian>* object,
679 const Symbol_value<size>* psymval,
680 typename elfcpp::Elf_types<size>::Elf_Addr addend,
681 typename elfcpp::Elf_types<size>::Elf_Addr address)
682 { This_reloc::pcrela16(view, object, psymval, addend, address); }
683
684 // R_PPC_REL16_LO: (Symbol + Addend - Address) & 0xffff
685 static inline void
686 rel16_lo(unsigned char* view,
687 const Sized_relobj<size, big_endian>* object,
688 const Symbol_value<size>* psymval,
689 typename elfcpp::Elf_types<size>::Elf_Addr addend,
690 typename elfcpp::Elf_types<size>::Elf_Addr address)
691 { This_reloc::pcrela16(view, object, psymval, addend, address); }
692
693 // R_PPC_REL16_HI: ((Symbol + Addend - Address) >> 16) & 0xffff
694 static inline void
695 rel16_hi(unsigned char* view,
696 const Sized_relobj<size, big_endian>* object,
697 const Symbol_value<size>* psymval,
698 typename elfcpp::Elf_types<size>::Elf_Addr addend,
699 typename elfcpp::Elf_types<size>::Elf_Addr address)
700 {
701 This::template pcrela<16>(view, 16, 0xffff, object,
702 psymval, addend, address);
703 }
704
705 // R_PPC_REL16_HA: Same as R_PPC_REL16_HI except that if the
706 // final value of the low 16 bits of the
707 // relocation is negative, add one.
708 static inline void
709 rel16_ha(unsigned char* view,
710 const Sized_relobj<size, big_endian>* object,
711 const Symbol_value<size>* psymval,
712 typename elfcpp::Elf_types<size>::Elf_Addr addend,
713 typename elfcpp::Elf_types<size>::Elf_Addr address)
714 {
715 typename elfcpp::Elf_types<size>::Elf_Addr reloc;
716
717 reloc = (psymval->value(object, addend) - address);
718 if (reloc & 0x8000)
719 reloc += 0x10000;
720 reloc >>= 16;
721
722 elfcpp::Swap<16, big_endian>::writeval(view, reloc);
723 }
724 };
725
726 // Get the GOT section, creating it if necessary.
727
728 template<int size, bool big_endian>
729 Output_data_got<size, big_endian>*
730 Target_powerpc<size, big_endian>::got_section(Symbol_table* symtab,
731 Layout* layout)
732 {
733 if (this->got_ == NULL)
734 {
735 gold_assert(symtab != NULL && layout != NULL);
736
737 this->got_ = new Output_data_got<size, big_endian>();
738
739 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
740 elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE,
741 this->got_, false, false, false, false);
742
743 // Create the GOT2 or TOC in the .got section.
744 if (size == 32)
745 {
746 this->got2_ = new Output_data_space(4, "** GOT2");
747 layout->add_output_section_data(".got2", elfcpp::SHT_PROGBITS,
748 elfcpp::SHF_ALLOC
749 | elfcpp::SHF_WRITE,
750 this->got2_, false, false, false,
751 false);
752 }
753 else
754 {
755 this->toc_ = new Output_data_space(8, "** TOC");
756 layout->add_output_section_data(".toc", elfcpp::SHT_PROGBITS,
757 elfcpp::SHF_ALLOC
758 | elfcpp::SHF_WRITE,
759 this->toc_, false, false, false,
760 false);
761 }
762
763 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
764 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
765 Symbol_table::PREDEFINED,
766 this->got_,
767 0, 0, elfcpp::STT_OBJECT,
768 elfcpp::STB_LOCAL,
769 elfcpp::STV_HIDDEN, 0,
770 false, false);
771 }
772
773 return this->got_;
774 }
775
776 // Get the dynamic reloc section, creating it if necessary.
777
778 template<int size, bool big_endian>
779 typename Target_powerpc<size, big_endian>::Reloc_section*
780 Target_powerpc<size, big_endian>::rela_dyn_section(Layout* layout)
781 {
782 if (this->rela_dyn_ == NULL)
783 {
784 gold_assert(layout != NULL);
785 this->rela_dyn_ = new Reloc_section(parameters->options().combreloc());
786 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
787 elfcpp::SHF_ALLOC, this->rela_dyn_, true,
788 false, false, false);
789 }
790 return this->rela_dyn_;
791 }
792
793 // A class to handle the PLT data.
794
795 template<int size, bool big_endian>
796 class Output_data_plt_powerpc : public Output_section_data
797 {
798 public:
799 typedef Output_data_reloc<elfcpp::SHT_RELA, true,
800 size, big_endian> Reloc_section;
801
802 Output_data_plt_powerpc(Layout*);
803
804 // Add an entry to the PLT.
805 void add_entry(Symbol* gsym);
806
807 // Return the .rela.plt section data.
808 const Reloc_section* rel_plt() const
809 {
810 return this->rel_;
811 }
812
813 protected:
814 void do_adjust_output_section(Output_section* os);
815
816 private:
817 // The size of an entry in the PLT.
818 static const int base_plt_entry_size = (size == 32 ? 16 : 24);
819
820 // Set the final size.
821 void
822 set_final_data_size()
823 {
824 unsigned int full_count = this->count_ + 4;
825
826 this->set_data_size(full_count * base_plt_entry_size);
827 }
828
829 // Write out the PLT data.
830 void
831 do_write(Output_file*);
832
833 // The reloc section.
834 Reloc_section* rel_;
835 // The number of PLT entries.
836 unsigned int count_;
837 };
838
839 // Create the PLT section. The ordinary .got section is an argument,
840 // since we need to refer to the start.
841
842 template<int size, bool big_endian>
843 Output_data_plt_powerpc<size, big_endian>::Output_data_plt_powerpc(Layout* layout)
844 : Output_section_data(size == 32 ? 4 : 8), count_(0)
845 {
846 this->rel_ = new Reloc_section(false);
847 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
848 elfcpp::SHF_ALLOC, this->rel_, true, false,
849 false, false);
850 }
851
852 template<int size, bool big_endian>
853 void
854 Output_data_plt_powerpc<size, big_endian>::do_adjust_output_section(Output_section* os)
855 {
856 os->set_entsize(0);
857 }
858
859 // Add an entry to the PLT.
860
861 template<int size, bool big_endian>
862 void
863 Output_data_plt_powerpc<size, big_endian>::add_entry(Symbol* gsym)
864 {
865 gold_assert(!gsym->has_plt_offset());
866 unsigned int index = this->count_+ + 4;
867 section_offset_type plt_offset;
868
869 if (index < 8192)
870 plt_offset = index * base_plt_entry_size;
871 else
872 gold_unreachable();
873
874 gsym->set_plt_offset(plt_offset);
875
876 ++this->count_;
877
878 gsym->set_needs_dynsym_entry();
879 this->rel_->add_global(gsym, elfcpp::R_POWERPC_JMP_SLOT, this,
880 plt_offset, 0);
881 }
882
883 static const unsigned int addis_11_11 = 0x3d6b0000;
884 static const unsigned int addis_11_30 = 0x3d7e0000;
885 static const unsigned int addis_12_12 = 0x3d8c0000;
886 static const unsigned int addi_11_11 = 0x396b0000;
887 static const unsigned int add_0_11_11 = 0x7c0b5a14;
888 static const unsigned int add_11_0_11 = 0x7d605a14;
889 static const unsigned int b = 0x48000000;
890 static const unsigned int bcl_20_31 = 0x429f0005;
891 static const unsigned int bctr = 0x4e800420;
892 static const unsigned int lis_11 = 0x3d600000;
893 static const unsigned int lis_12 = 0x3d800000;
894 static const unsigned int lwzu_0_12 = 0x840c0000;
895 static const unsigned int lwz_0_12 = 0x800c0000;
896 static const unsigned int lwz_11_11 = 0x816b0000;
897 static const unsigned int lwz_11_30 = 0x817e0000;
898 static const unsigned int lwz_12_12 = 0x818c0000;
899 static const unsigned int mflr_0 = 0x7c0802a6;
900 static const unsigned int mflr_12 = 0x7d8802a6;
901 static const unsigned int mtctr_0 = 0x7c0903a6;
902 static const unsigned int mtctr_11 = 0x7d6903a6;
903 static const unsigned int mtlr_0 = 0x7c0803a6;
904 static const unsigned int nop = 0x60000000;
905 static const unsigned int sub_11_11_12 = 0x7d6c5850;
906
907 static const unsigned int addis_r12_r2 = 0x3d820000; /* addis %r12,%r2,xxx@ha */
908 static const unsigned int std_r2_40r1 = 0xf8410028; /* std %r2,40(%r1) */
909 static const unsigned int ld_r11_0r12 = 0xe96c0000; /* ld %r11,xxx+0@l(%r12) */
910 static const unsigned int ld_r2_0r12 = 0xe84c0000; /* ld %r2,xxx+8@l(%r12) */
911 /* ld %r11,xxx+16@l(%r12) */
912
913
914 // Write out the PLT.
915
916 template<int size, bool big_endian>
917 void
918 Output_data_plt_powerpc<size, big_endian>::do_write(Output_file* of)
919 {
920 const off_t offset = this->offset();
921 const section_size_type oview_size =
922 convert_to_section_size_type(this->data_size());
923 unsigned char* const oview = of->get_output_view(offset, oview_size);
924 unsigned char* pov = oview;
925
926 memset(pov, 0, base_plt_entry_size * 4);
927 pov += base_plt_entry_size * 4;
928
929 unsigned int plt_offset = base_plt_entry_size * 4;
930 const unsigned int count = this->count_;
931
932 if (size == 64)
933 {
934 for (unsigned int i = 0; i < count; i++)
935 {
936 }
937 }
938 else
939 {
940 for (unsigned int i = 0; i < count; i++)
941 {
942 elfcpp::Swap<32, true>::writeval(pov + 0x00,
943 lwz_11_30 + plt_offset);
944 elfcpp::Swap<32, true>::writeval(pov + 0x04, mtctr_11);
945 elfcpp::Swap<32, true>::writeval(pov + 0x08, bctr);
946 elfcpp::Swap<32, true>::writeval(pov + 0x0c, nop);
947 pov += base_plt_entry_size;
948 plt_offset += base_plt_entry_size;
949 }
950 }
951
952 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
953
954 of->write_output_view(offset, oview_size, oview);
955 }
956
957 // Create a PLT entry for a global symbol.
958
959 template<int size, bool big_endian>
960 void
961 Target_powerpc<size, big_endian>::make_plt_entry(Symbol_table* symtab,
962 Layout* layout,
963 Symbol* gsym)
964 {
965 if (gsym->has_plt_offset())
966 return;
967
968 if (this->plt_ == NULL)
969 {
970 // Create the GOT section first.
971 this->got_section(symtab, layout);
972
973 // Ensure that .rela.dyn always appears before .rela.plt This is
974 // necessary due to how, on PowerPC and some other targets, .rela.dyn
975 // needs to include .rela.plt in it's range.
976 this->rela_dyn_section(layout);
977
978 this->plt_ = new Output_data_plt_powerpc<size, big_endian>(layout);
979 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
980 (elfcpp::SHF_ALLOC
981 | elfcpp::SHF_EXECINSTR
982 | elfcpp::SHF_WRITE),
983 this->plt_, false, false, false, false);
984
985 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
986 symtab->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL,
987 Symbol_table::PREDEFINED,
988 this->plt_,
989 0, 0, elfcpp::STT_OBJECT,
990 elfcpp::STB_LOCAL,
991 elfcpp::STV_HIDDEN, 0,
992 false, false);
993 }
994
995 this->plt_->add_entry(gsym);
996 }
997
998 // Create a GOT entry for the TLS module index.
999
1000 template<int size, bool big_endian>
1001 unsigned int
1002 Target_powerpc<size, big_endian>::got_mod_index_entry(Symbol_table* symtab,
1003 Layout* layout,
1004 Sized_relobj<size, big_endian>* object)
1005 {
1006 if (this->got_mod_index_offset_ == -1U)
1007 {
1008 gold_assert(symtab != NULL && layout != NULL && object != NULL);
1009 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
1010 Output_data_got<size, big_endian>* got;
1011 unsigned int got_offset;
1012
1013 got = this->got_section(symtab, layout);
1014 got_offset = got->add_constant(0);
1015 rela_dyn->add_local(object, 0, elfcpp::R_POWERPC_DTPMOD, got,
1016 got_offset, 0);
1017 got->add_constant(0);
1018 this->got_mod_index_offset_ = got_offset;
1019 }
1020 return this->got_mod_index_offset_;
1021 }
1022
1023 // Optimize the TLS relocation type based on what we know about the
1024 // symbol. IS_FINAL is true if the final address of this symbol is
1025 // known at link time.
1026
1027 static tls::Tls_optimization
1028 optimize_tls_reloc(bool /* is_final */, int r_type)
1029 {
1030 // If we are generating a shared library, then we can't do anything
1031 // in the linker.
1032 if (parameters->options().shared())
1033 return tls::TLSOPT_NONE;
1034 switch (r_type)
1035 {
1036 // XXX
1037 default:
1038 gold_unreachable();
1039 }
1040 }
1041
1042 // Report an unsupported relocation against a local symbol.
1043
1044 template<int size, bool big_endian>
1045 void
1046 Target_powerpc<size, big_endian>::Scan::unsupported_reloc_local(
1047 Sized_relobj<size, big_endian>* object,
1048 unsigned int r_type)
1049 {
1050 gold_error(_("%s: unsupported reloc %u against local symbol"),
1051 object->name().c_str(), r_type);
1052 }
1053
1054 // We are about to emit a dynamic relocation of type R_TYPE. If the
1055 // dynamic linker does not support it, issue an error.
1056
1057 template<int size, bool big_endian>
1058 void
1059 Target_powerpc<size, big_endian>::Scan::check_non_pic(Relobj* object,
1060 unsigned int r_type)
1061 {
1062 gold_assert(r_type != elfcpp::R_POWERPC_NONE);
1063
1064 // These are the relocation types supported by glibc for both 32-bit
1065 // and 64-bit powerpc.
1066 switch (r_type)
1067 {
1068 case elfcpp::R_POWERPC_RELATIVE:
1069 case elfcpp::R_POWERPC_GLOB_DAT:
1070 case elfcpp::R_POWERPC_DTPMOD:
1071 case elfcpp::R_POWERPC_DTPREL:
1072 case elfcpp::R_POWERPC_TPREL:
1073 case elfcpp::R_POWERPC_JMP_SLOT:
1074 case elfcpp::R_POWERPC_COPY:
1075 case elfcpp::R_POWERPC_ADDR32:
1076 case elfcpp::R_POWERPC_ADDR24:
1077 case elfcpp::R_POWERPC_REL24:
1078 return;
1079
1080 default:
1081 break;
1082 }
1083
1084 if (size == 64)
1085 {
1086 switch (r_type)
1087 {
1088 // These are the relocation types supported only on 64-bit.
1089 case elfcpp::R_PPC64_ADDR64:
1090 case elfcpp::R_PPC64_TPREL16_LO_DS:
1091 case elfcpp::R_PPC64_TPREL16_DS:
1092 case elfcpp::R_POWERPC_TPREL16:
1093 case elfcpp::R_POWERPC_TPREL16_LO:
1094 case elfcpp::R_POWERPC_TPREL16_HI:
1095 case elfcpp::R_POWERPC_TPREL16_HA:
1096 case elfcpp::R_PPC64_TPREL16_HIGHER:
1097 case elfcpp::R_PPC64_TPREL16_HIGHEST:
1098 case elfcpp::R_PPC64_TPREL16_HIGHERA:
1099 case elfcpp::R_PPC64_TPREL16_HIGHESTA:
1100 case elfcpp::R_PPC64_ADDR16_LO_DS:
1101 case elfcpp::R_POWERPC_ADDR16_LO:
1102 case elfcpp::R_POWERPC_ADDR16_HI:
1103 case elfcpp::R_POWERPC_ADDR16_HA:
1104 case elfcpp::R_POWERPC_ADDR30:
1105 case elfcpp::R_PPC64_UADDR64:
1106 case elfcpp::R_POWERPC_UADDR32:
1107 case elfcpp::R_POWERPC_ADDR16:
1108 case elfcpp::R_POWERPC_UADDR16:
1109 case elfcpp::R_PPC64_ADDR16_DS:
1110 case elfcpp::R_PPC64_ADDR16_HIGHER:
1111 case elfcpp::R_PPC64_ADDR16_HIGHEST:
1112 case elfcpp::R_PPC64_ADDR16_HIGHERA:
1113 case elfcpp::R_PPC64_ADDR16_HIGHESTA:
1114 case elfcpp::R_POWERPC_ADDR14_BRTAKEN:
1115 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN:
1116 case elfcpp::R_POWERPC_REL32:
1117 case elfcpp::R_PPC64_REL64:
1118 return;
1119
1120 default:
1121 break;
1122 }
1123 }
1124 else
1125 {
1126 switch (r_type)
1127 {
1128 // These are the relocation types supported only on 32-bit.
1129
1130 default:
1131 break;
1132 }
1133 }
1134
1135 // This prevents us from issuing more than one error per reloc
1136 // section. But we can still wind up issuing more than one
1137 // error per object file.
1138 if (this->issued_non_pic_error_)
1139 return;
1140 gold_assert(parameters->options().output_is_position_independent());
1141 object->error(_("requires unsupported dynamic reloc; "
1142 "recompile with -fPIC"));
1143 this->issued_non_pic_error_ = true;
1144 return;
1145 }
1146
1147 // Scan a relocation for a local symbol.
1148
1149 template<int size, bool big_endian>
1150 inline void
1151 Target_powerpc<size, big_endian>::Scan::local(
1152 Symbol_table* symtab,
1153 Layout* layout,
1154 Target_powerpc<size, big_endian>* target,
1155 Sized_relobj<size, big_endian>* object,
1156 unsigned int data_shndx,
1157 Output_section* output_section,
1158 const elfcpp::Rela<size, big_endian>& reloc,
1159 unsigned int r_type,
1160 const elfcpp::Sym<size, big_endian>& lsym)
1161 {
1162 switch (r_type)
1163 {
1164 case elfcpp::R_POWERPC_NONE:
1165 case elfcpp::R_POWERPC_GNU_VTINHERIT:
1166 case elfcpp::R_POWERPC_GNU_VTENTRY:
1167 break;
1168
1169 case elfcpp::R_PPC64_ADDR64:
1170 case elfcpp::R_POWERPC_ADDR32:
1171 case elfcpp::R_POWERPC_ADDR16_HA:
1172 case elfcpp::R_POWERPC_ADDR16_LO:
1173 // If building a shared library (or a position-independent
1174 // executable), we need to create a dynamic relocation for
1175 // this location.
1176 if (parameters->options().output_is_position_independent())
1177 {
1178 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1179
1180 check_non_pic(object, r_type);
1181 if (lsym.get_st_type() != elfcpp::STT_SECTION)
1182 {
1183 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1184 rela_dyn->add_local(object, r_sym, r_type, output_section,
1185 data_shndx, reloc.get_r_offset(),
1186 reloc.get_r_addend());
1187 }
1188 else
1189 {
1190 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1191 gold_assert(lsym.get_st_value() == 0);
1192 rela_dyn->add_local_relative(object, r_sym, r_type,
1193 output_section, data_shndx,
1194 reloc.get_r_offset(),
1195 reloc.get_r_addend());
1196 }
1197 }
1198 break;
1199
1200 case elfcpp::R_POWERPC_REL24:
1201 case elfcpp::R_PPC_LOCAL24PC:
1202 case elfcpp::R_POWERPC_REL32:
1203 case elfcpp::R_PPC_REL16_LO:
1204 case elfcpp::R_PPC_REL16_HA:
1205 break;
1206
1207 case elfcpp::R_POWERPC_GOT16:
1208 case elfcpp::R_POWERPC_GOT16_LO:
1209 case elfcpp::R_POWERPC_GOT16_HI:
1210 case elfcpp::R_POWERPC_GOT16_HA:
1211 case elfcpp::R_PPC64_TOC16:
1212 case elfcpp::R_PPC64_TOC16_LO:
1213 case elfcpp::R_PPC64_TOC16_HI:
1214 case elfcpp::R_PPC64_TOC16_HA:
1215 case elfcpp::R_PPC64_TOC16_DS:
1216 case elfcpp::R_PPC64_TOC16_LO_DS:
1217 {
1218 // The symbol requires a GOT entry.
1219 Output_data_got<size, big_endian>* got;
1220 unsigned int r_sym;
1221
1222 got = target->got_section(symtab, layout);
1223 r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1224
1225 // If we are generating a shared object, we need to add a
1226 // dynamic relocation for this symbol's GOT entry.
1227 if (parameters->options().output_is_position_independent())
1228 {
1229 if (!object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD))
1230 {
1231 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1232 unsigned int off;
1233
1234 off = got->add_constant(0);
1235 object->set_local_got_offset(r_sym, GOT_TYPE_STANDARD, off);
1236 rela_dyn->add_local_relative(object, r_sym,
1237 elfcpp::R_POWERPC_RELATIVE,
1238 got, off, 0);
1239 }
1240 }
1241 else
1242 got->add_local(object, r_sym, GOT_TYPE_STANDARD);
1243 }
1244 break;
1245
1246 case elfcpp::R_PPC64_TOC:
1247 // We need a GOT section.
1248 target->got_section(symtab, layout);
1249 break;
1250
1251 // These are relocations which should only be seen by the
1252 // dynamic linker, and should never be seen here.
1253 case elfcpp::R_POWERPC_COPY:
1254 case elfcpp::R_POWERPC_GLOB_DAT:
1255 case elfcpp::R_POWERPC_JMP_SLOT:
1256 case elfcpp::R_POWERPC_RELATIVE:
1257 case elfcpp::R_POWERPC_DTPMOD:
1258 gold_error(_("%s: unexpected reloc %u in object file"),
1259 object->name().c_str(), r_type);
1260 break;
1261
1262 default:
1263 unsupported_reloc_local(object, r_type);
1264 break;
1265 }
1266 }
1267
1268 // Report an unsupported relocation against a global symbol.
1269
1270 template<int size, bool big_endian>
1271 void
1272 Target_powerpc<size, big_endian>::Scan::unsupported_reloc_global(
1273 Sized_relobj<size, big_endian>* object,
1274 unsigned int r_type,
1275 Symbol* gsym)
1276 {
1277 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1278 object->name().c_str(), r_type, gsym->demangled_name().c_str());
1279 }
1280
1281 // Scan a relocation for a global symbol.
1282
1283 template<int size, bool big_endian>
1284 inline void
1285 Target_powerpc<size, big_endian>::Scan::global(
1286 Symbol_table* symtab,
1287 Layout* layout,
1288 Target_powerpc<size, big_endian>* target,
1289 Sized_relobj<size, big_endian>* object,
1290 unsigned int data_shndx,
1291 Output_section* output_section,
1292 const elfcpp::Rela<size, big_endian>& reloc,
1293 unsigned int r_type,
1294 Symbol* gsym)
1295 {
1296 switch (r_type)
1297 {
1298 case elfcpp::R_POWERPC_NONE:
1299 case elfcpp::R_POWERPC_GNU_VTINHERIT:
1300 case elfcpp::R_POWERPC_GNU_VTENTRY:
1301 break;
1302
1303 case elfcpp::R_PPC_PLTREL24:
1304 // If the symbol is fully resolved, this is just a PC32 reloc.
1305 // Otherwise we need a PLT entry.
1306 if (gsym->final_value_is_known())
1307 break;
1308 // If building a shared library, we can also skip the PLT entry
1309 // if the symbol is defined in the output file and is protected
1310 // or hidden.
1311 if (gsym->is_defined()
1312 && !gsym->is_from_dynobj()
1313 && !gsym->is_preemptible())
1314 break;
1315 target->make_plt_entry(symtab, layout, gsym);
1316 break;
1317
1318 case elfcpp::R_POWERPC_ADDR16:
1319 case elfcpp::R_POWERPC_ADDR16_LO:
1320 case elfcpp::R_POWERPC_ADDR16_HI:
1321 case elfcpp::R_POWERPC_ADDR16_HA:
1322 case elfcpp::R_POWERPC_ADDR32:
1323 case elfcpp::R_PPC64_ADDR64:
1324 {
1325 // Make a PLT entry if necessary.
1326 if (gsym->needs_plt_entry())
1327 {
1328 target->make_plt_entry(symtab, layout, gsym);
1329 // Since this is not a PC-relative relocation, we may be
1330 // taking the address of a function. In that case we need to
1331 // set the entry in the dynamic symbol table to the address of
1332 // the PLT entry.
1333 if (gsym->is_from_dynobj() && !parameters->options().shared())
1334 gsym->set_needs_dynsym_value();
1335 }
1336 // Make a dynamic relocation if necessary.
1337 if (gsym->needs_dynamic_reloc(Symbol::ABSOLUTE_REF))
1338 {
1339 if (gsym->may_need_copy_reloc())
1340 {
1341 target->copy_reloc(symtab, layout, object,
1342 data_shndx, output_section, gsym, reloc);
1343 }
1344 else if ((r_type == elfcpp::R_POWERPC_ADDR32
1345 || r_type == elfcpp::R_PPC64_ADDR64)
1346 && gsym->can_use_relative_reloc(false))
1347 {
1348 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1349 rela_dyn->add_global_relative(gsym, elfcpp::R_POWERPC_RELATIVE,
1350 output_section, object,
1351 data_shndx, reloc.get_r_offset(),
1352 reloc.get_r_addend());
1353 }
1354 else
1355 {
1356 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1357
1358 check_non_pic(object, r_type);
1359 if (gsym->is_from_dynobj()
1360 || gsym->is_undefined()
1361 || gsym->is_preemptible())
1362 rela_dyn->add_global(gsym, r_type, output_section,
1363 object, data_shndx,
1364 reloc.get_r_offset(),
1365 reloc.get_r_addend());
1366 else
1367 rela_dyn->add_global_relative(gsym, r_type,
1368 output_section, object,
1369 data_shndx,
1370 reloc.get_r_offset(),
1371 reloc.get_r_addend());
1372 }
1373 }
1374 }
1375 break;
1376
1377 case elfcpp::R_POWERPC_REL24:
1378 case elfcpp::R_PPC_LOCAL24PC:
1379 case elfcpp::R_PPC_REL16:
1380 case elfcpp::R_PPC_REL16_LO:
1381 case elfcpp::R_PPC_REL16_HI:
1382 case elfcpp::R_PPC_REL16_HA:
1383 {
1384 if (gsym->needs_plt_entry())
1385 target->make_plt_entry(symtab, layout, gsym);
1386 // Make a dynamic relocation if necessary.
1387 int flags = Symbol::NON_PIC_REF;
1388 if (gsym->type() == elfcpp::STT_FUNC)
1389 flags |= Symbol::FUNCTION_CALL;
1390 if (gsym->needs_dynamic_reloc(flags))
1391 {
1392 if (gsym->may_need_copy_reloc())
1393 {
1394 target->copy_reloc(symtab, layout, object,
1395 data_shndx, output_section, gsym,
1396 reloc);
1397 }
1398 else
1399 {
1400 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1401 check_non_pic(object, r_type);
1402 rela_dyn->add_global(gsym, r_type, output_section, object,
1403 data_shndx, reloc.get_r_offset(),
1404 reloc.get_r_addend());
1405 }
1406 }
1407 }
1408 break;
1409
1410 case elfcpp::R_POWERPC_GOT16:
1411 case elfcpp::R_POWERPC_GOT16_LO:
1412 case elfcpp::R_POWERPC_GOT16_HI:
1413 case elfcpp::R_POWERPC_GOT16_HA:
1414 case elfcpp::R_PPC64_TOC16:
1415 case elfcpp::R_PPC64_TOC16_LO:
1416 case elfcpp::R_PPC64_TOC16_HI:
1417 case elfcpp::R_PPC64_TOC16_HA:
1418 case elfcpp::R_PPC64_TOC16_DS:
1419 case elfcpp::R_PPC64_TOC16_LO_DS:
1420 {
1421 // The symbol requires a GOT entry.
1422 Output_data_got<size, big_endian>* got;
1423
1424 got = target->got_section(symtab, layout);
1425 if (gsym->final_value_is_known())
1426 got->add_global(gsym, GOT_TYPE_STANDARD);
1427 else
1428 {
1429 // If this symbol is not fully resolved, we need to add a
1430 // dynamic relocation for it.
1431 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1432 if (gsym->is_from_dynobj()
1433 || gsym->is_undefined()
1434 || gsym->is_preemptible())
1435 got->add_global_with_rela(gsym, GOT_TYPE_STANDARD, rela_dyn,
1436 elfcpp::R_POWERPC_GLOB_DAT);
1437 else if (!gsym->has_got_offset(GOT_TYPE_STANDARD))
1438 {
1439 unsigned int off = got->add_constant(0);
1440
1441 gsym->set_got_offset(GOT_TYPE_STANDARD, off);
1442 rela_dyn->add_global_relative(gsym, elfcpp::R_POWERPC_RELATIVE,
1443 got, off, 0);
1444 }
1445 }
1446 }
1447 break;
1448
1449 case elfcpp::R_PPC64_TOC:
1450 // We need a GOT section.
1451 target->got_section(symtab, layout);
1452 break;
1453
1454 case elfcpp::R_POWERPC_GOT_TPREL16:
1455 case elfcpp::R_POWERPC_TLS:
1456 // XXX TLS
1457 break;
1458
1459 // These are relocations which should only be seen by the
1460 // dynamic linker, and should never be seen here.
1461 case elfcpp::R_POWERPC_COPY:
1462 case elfcpp::R_POWERPC_GLOB_DAT:
1463 case elfcpp::R_POWERPC_JMP_SLOT:
1464 case elfcpp::R_POWERPC_RELATIVE:
1465 case elfcpp::R_POWERPC_DTPMOD:
1466 gold_error(_("%s: unexpected reloc %u in object file"),
1467 object->name().c_str(), r_type);
1468 break;
1469
1470 default:
1471 unsupported_reloc_global(object, r_type, gsym);
1472 break;
1473 }
1474 }
1475
1476 // Process relocations for gc.
1477
1478 template<int size, bool big_endian>
1479 void
1480 Target_powerpc<size, big_endian>::gc_process_relocs(
1481 Symbol_table* symtab,
1482 Layout* layout,
1483 Sized_relobj<size, big_endian>* object,
1484 unsigned int data_shndx,
1485 unsigned int,
1486 const unsigned char* prelocs,
1487 size_t reloc_count,
1488 Output_section* output_section,
1489 bool needs_special_offset_handling,
1490 size_t local_symbol_count,
1491 const unsigned char* plocal_symbols)
1492 {
1493 typedef Target_powerpc<size, big_endian> Powerpc;
1494 typedef typename Target_powerpc<size, big_endian>::Scan Scan;
1495
1496 gold::gc_process_relocs<size, big_endian, Powerpc, elfcpp::SHT_RELA, Scan,
1497 typename Target_powerpc::Relocatable_size_for_reloc>(
1498 symtab,
1499 layout,
1500 this,
1501 object,
1502 data_shndx,
1503 prelocs,
1504 reloc_count,
1505 output_section,
1506 needs_special_offset_handling,
1507 local_symbol_count,
1508 plocal_symbols);
1509 }
1510
1511 // Scan relocations for a section.
1512
1513 template<int size, bool big_endian>
1514 void
1515 Target_powerpc<size, big_endian>::scan_relocs(
1516 Symbol_table* symtab,
1517 Layout* layout,
1518 Sized_relobj<size, big_endian>* object,
1519 unsigned int data_shndx,
1520 unsigned int sh_type,
1521 const unsigned char* prelocs,
1522 size_t reloc_count,
1523 Output_section* output_section,
1524 bool needs_special_offset_handling,
1525 size_t local_symbol_count,
1526 const unsigned char* plocal_symbols)
1527 {
1528 typedef Target_powerpc<size, big_endian> Powerpc;
1529 typedef typename Target_powerpc<size, big_endian>::Scan Scan;
1530 static Output_data_space* sdata;
1531
1532 if (sh_type == elfcpp::SHT_REL)
1533 {
1534 gold_error(_("%s: unsupported REL reloc section"),
1535 object->name().c_str());
1536 return;
1537 }
1538
1539 // Define _SDA_BASE_ at the start of the .sdata section.
1540 if (sdata == NULL)
1541 {
1542 // layout->find_output_section(".sdata") == NULL
1543 sdata = new Output_data_space(4, "** sdata");
1544 Output_section* os = layout->add_output_section_data(".sdata", 0,
1545 elfcpp::SHF_ALLOC
1546 | elfcpp::SHF_WRITE,
1547 sdata, false,
1548 false, false, false);
1549 symtab->define_in_output_data("_SDA_BASE_", NULL,
1550 Symbol_table::PREDEFINED,
1551 os,
1552 32768, 0,
1553 elfcpp::STT_OBJECT,
1554 elfcpp::STB_LOCAL,
1555 elfcpp::STV_HIDDEN, 0,
1556 false, false);
1557 }
1558
1559 gold::scan_relocs<size, big_endian, Powerpc, elfcpp::SHT_RELA, Scan>(
1560 symtab,
1561 layout,
1562 this,
1563 object,
1564 data_shndx,
1565 prelocs,
1566 reloc_count,
1567 output_section,
1568 needs_special_offset_handling,
1569 local_symbol_count,
1570 plocal_symbols);
1571 }
1572
1573 // Finalize the sections.
1574
1575 template<int size, bool big_endian>
1576 void
1577 Target_powerpc<size, big_endian>::do_finalize_sections(
1578 Layout* layout,
1579 const Input_objects*,
1580 Symbol_table*)
1581 {
1582 // Fill in some more dynamic tags.
1583 const Reloc_section* rel_plt = (this->plt_ == NULL
1584 ? NULL
1585 : this->plt_->rel_plt());
1586 layout->add_target_dynamic_tags(false, this->plt_, rel_plt,
1587 this->rela_dyn_, true, size == 32);
1588
1589 // Emit any relocs we saved in an attempt to avoid generating COPY
1590 // relocs.
1591 if (this->copy_relocs_.any_saved_relocs())
1592 this->copy_relocs_.emit(this->rela_dyn_section(layout));
1593 }
1594
1595 // Perform a relocation.
1596
1597 template<int size, bool big_endian>
1598 inline bool
1599 Target_powerpc<size, big_endian>::Relocate::relocate(
1600 const Relocate_info<size, big_endian>* relinfo,
1601 Target_powerpc* target,
1602 Output_section*,
1603 size_t relnum,
1604 const elfcpp::Rela<size, big_endian>& rela,
1605 unsigned int r_type,
1606 const Sized_symbol<size>* gsym,
1607 const Symbol_value<size>* psymval,
1608 unsigned char* view,
1609 typename elfcpp::Elf_types<size>::Elf_Addr address,
1610 section_size_type /* view_size */)
1611 {
1612 const unsigned int toc_base_offset = 0x8000;
1613 typedef Powerpc_relocate_functions<size, big_endian> Reloc;
1614
1615 // Pick the value to use for symbols defined in shared objects.
1616 Symbol_value<size> symval;
1617 if (gsym != NULL
1618 && gsym->use_plt_offset(r_type == elfcpp::R_POWERPC_REL24
1619 || r_type == elfcpp::R_PPC_LOCAL24PC
1620 || r_type == elfcpp::R_PPC_REL16
1621 || r_type == elfcpp::R_PPC_REL16_LO
1622 || r_type == elfcpp::R_PPC_REL16_HI
1623 || r_type == elfcpp::R_PPC_REL16_HA))
1624 {
1625 elfcpp::Elf_Xword value;
1626
1627 value = target->plt_section()->address() + gsym->plt_offset();
1628
1629 symval.set_output_value(value);
1630
1631 psymval = &symval;
1632 }
1633
1634 const Sized_relobj<size, big_endian>* object = relinfo->object;
1635 elfcpp::Elf_Xword addend = rela.get_r_addend();
1636
1637 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
1638 // pointer points to the beginning, not the end, of the table.
1639 // So we just use the plain offset.
1640 unsigned int got_offset = 0;
1641 unsigned int got2_offset = 0;
1642 switch (r_type)
1643 {
1644 case elfcpp::R_PPC64_TOC16:
1645 case elfcpp::R_PPC64_TOC16_LO:
1646 case elfcpp::R_PPC64_TOC16_HI:
1647 case elfcpp::R_PPC64_TOC16_HA:
1648 case elfcpp::R_PPC64_TOC16_DS:
1649 case elfcpp::R_PPC64_TOC16_LO_DS:
1650 // Subtract the TOC base address.
1651 addend -= target->toc_section()->address() + toc_base_offset;
1652 /* FALLTHRU */
1653
1654 case elfcpp::R_POWERPC_GOT16:
1655 case elfcpp::R_POWERPC_GOT16_LO:
1656 case elfcpp::R_POWERPC_GOT16_HI:
1657 case elfcpp::R_POWERPC_GOT16_HA:
1658 case elfcpp::R_PPC64_GOT16_DS:
1659 case elfcpp::R_PPC64_GOT16_LO_DS:
1660 if (gsym != NULL)
1661 {
1662 gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
1663 got_offset = gsym->got_offset(GOT_TYPE_STANDARD);
1664 }
1665 else
1666 {
1667 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
1668 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
1669 got_offset = object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
1670 }
1671 break;
1672
1673 // R_PPC_PLTREL24 is rather special. If non-zero,
1674 // the addend specifies the GOT pointer offset within .got2.
1675 case elfcpp::R_PPC_PLTREL24:
1676 if (addend >= 32768)
1677 {
1678 Output_data_space* got2;
1679 got2 = target->got2_section();
1680 got2_offset = got2->offset();
1681 addend += got2_offset;
1682 }
1683 break;
1684
1685 default:
1686 break;
1687 }
1688
1689 switch (r_type)
1690 {
1691 case elfcpp::R_POWERPC_NONE:
1692 case elfcpp::R_POWERPC_GNU_VTINHERIT:
1693 case elfcpp::R_POWERPC_GNU_VTENTRY:
1694 break;
1695
1696 case elfcpp::R_POWERPC_REL32:
1697 Reloc::rel32(view, object, psymval, addend, address);
1698 break;
1699
1700 case elfcpp::R_POWERPC_REL24:
1701 Reloc::rel24(view, object, psymval, addend, address);
1702 break;
1703
1704 case elfcpp::R_POWERPC_REL14:
1705 Reloc::rel14(view, object, psymval, addend, address);
1706 break;
1707
1708 case elfcpp::R_PPC_PLTREL24:
1709 Reloc::rel24(view, object, psymval, addend, address);
1710 break;
1711
1712 case elfcpp::R_PPC_LOCAL24PC:
1713 Reloc::rel24(view, object, psymval, addend, address);
1714 break;
1715
1716 case elfcpp::R_PPC64_ADDR64:
1717 if (!parameters->options().output_is_position_independent())
1718 Relocate_functions<size, big_endian>::rela64(view, object,
1719 psymval, addend);
1720 break;
1721
1722 case elfcpp::R_POWERPC_ADDR32:
1723 if (!parameters->options().output_is_position_independent())
1724 Relocate_functions<size, big_endian>::rela32(view, object,
1725 psymval, addend);
1726 break;
1727
1728 case elfcpp::R_POWERPC_ADDR16_LO:
1729 Reloc::addr16_lo(view, object, psymval, addend);
1730 break;
1731
1732 case elfcpp::R_POWERPC_ADDR16_HI:
1733 Reloc::addr16_hi(view, object, psymval, addend);
1734 break;
1735
1736 case elfcpp::R_POWERPC_ADDR16_HA:
1737 Reloc::addr16_ha(view, object, psymval, addend);
1738 break;
1739
1740 case elfcpp::R_PPC_REL16_LO:
1741 Reloc::rel16_lo(view, object, psymval, addend, address);
1742 break;
1743
1744 case elfcpp::R_PPC_REL16_HI:
1745 Reloc::rel16_lo(view, object, psymval, addend, address);
1746 break;
1747
1748 case elfcpp::R_PPC_REL16_HA:
1749 Reloc::rel16_ha(view, object, psymval, addend, address);
1750 break;
1751
1752 case elfcpp::R_POWERPC_GOT16:
1753 Reloc::addr16(view, got_offset, addend);
1754 break;
1755
1756 case elfcpp::R_POWERPC_GOT16_LO:
1757 Reloc::addr16_lo(view, got_offset, addend);
1758 break;
1759
1760 case elfcpp::R_POWERPC_GOT16_HI:
1761 Reloc::addr16_hi(view, got_offset, addend);
1762 break;
1763
1764 case elfcpp::R_POWERPC_GOT16_HA:
1765 Reloc::addr16_ha(view, got_offset, addend);
1766 break;
1767
1768 case elfcpp::R_PPC64_TOC16:
1769 Reloc::addr16(view, got_offset, addend);
1770 break;
1771
1772 case elfcpp::R_PPC64_TOC16_LO:
1773 Reloc::addr16_lo(view, got_offset, addend);
1774 break;
1775
1776 case elfcpp::R_PPC64_TOC16_HI:
1777 Reloc::addr16_hi(view, got_offset, addend);
1778 break;
1779
1780 case elfcpp::R_PPC64_TOC16_HA:
1781 Reloc::addr16_ha(view, got_offset, addend);
1782 break;
1783
1784 case elfcpp::R_PPC64_TOC16_DS:
1785 case elfcpp::R_PPC64_TOC16_LO_DS:
1786 Reloc::addr16_ds(view, got_offset, addend);
1787 break;
1788
1789 case elfcpp::R_PPC64_TOC:
1790 {
1791 elfcpp::Elf_types<64>::Elf_Addr value;
1792 value = target->toc_section()->address() + toc_base_offset;
1793 Relocate_functions<64, false>::rela64(view, value, addend);
1794 }
1795 break;
1796
1797 case elfcpp::R_POWERPC_COPY:
1798 case elfcpp::R_POWERPC_GLOB_DAT:
1799 case elfcpp::R_POWERPC_JMP_SLOT:
1800 case elfcpp::R_POWERPC_RELATIVE:
1801 // This is an outstanding tls reloc, which is unexpected when
1802 // linking.
1803 case elfcpp::R_POWERPC_DTPMOD:
1804 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
1805 _("unexpected reloc %u in object file"),
1806 r_type);
1807 break;
1808
1809 default:
1810 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
1811 _("unsupported reloc %u"),
1812 r_type);
1813 break;
1814 }
1815
1816 return true;
1817 }
1818
1819 // Perform a TLS relocation.
1820
1821 template<int size, bool big_endian>
1822 inline void
1823 Target_powerpc<size, big_endian>::Relocate::relocate_tls(
1824 const Relocate_info<size, big_endian>* relinfo,
1825 Target_powerpc<size, big_endian>* target,
1826 size_t relnum,
1827 const elfcpp::Rela<size, big_endian>& rela,
1828 unsigned int r_type,
1829 const Sized_symbol<size>* gsym,
1830 const Symbol_value<size>* psymval,
1831 unsigned char* view,
1832 typename elfcpp::Elf_types<size>::Elf_Addr address,
1833 section_size_type)
1834 {
1835 Output_segment* tls_segment = relinfo->layout->tls_segment();
1836 typedef Powerpc_relocate_functions<size, big_endian> Reloc;
1837 const Sized_relobj<size, big_endian>* object = relinfo->object;
1838
1839 const elfcpp::Elf_Xword addend = rela.get_r_addend();
1840 typename elfcpp::Elf_types<size>::Elf_Addr value = psymval->value(object, 0);
1841
1842 const bool is_final =
1843 (gsym == NULL
1844 ? !parameters->options().output_is_position_independent()
1845 : gsym->final_value_is_known());
1846 const tls::Tls_optimization optimized_type
1847 = optimize_tls_reloc(is_final, r_type);
1848
1849 switch (r_type)
1850 {
1851 // XXX
1852 }
1853 }
1854
1855 // Relocate section data.
1856
1857 template<int size, bool big_endian>
1858 void
1859 Target_powerpc<size, big_endian>::relocate_section(
1860 const Relocate_info<size, big_endian>* relinfo,
1861 unsigned int sh_type,
1862 const unsigned char* prelocs,
1863 size_t reloc_count,
1864 Output_section* output_section,
1865 bool needs_special_offset_handling,
1866 unsigned char* view,
1867 typename elfcpp::Elf_types<size>::Elf_Addr address,
1868 section_size_type view_size,
1869 const Reloc_symbol_changes* reloc_symbol_changes)
1870 {
1871 typedef Target_powerpc<size, big_endian> Powerpc;
1872 typedef typename Target_powerpc<size, big_endian>::Relocate Powerpc_relocate;
1873
1874 gold_assert(sh_type == elfcpp::SHT_RELA);
1875
1876 gold::relocate_section<size, big_endian, Powerpc, elfcpp::SHT_RELA,
1877 Powerpc_relocate>(
1878 relinfo,
1879 this,
1880 prelocs,
1881 reloc_count,
1882 output_section,
1883 needs_special_offset_handling,
1884 view,
1885 address,
1886 view_size,
1887 reloc_symbol_changes);
1888 }
1889
1890 // Return the size of a relocation while scanning during a relocatable
1891 // link.
1892
1893 template<int size, bool big_endian>
1894 unsigned int
1895 Target_powerpc<size, big_endian>::Relocatable_size_for_reloc::get_size_for_reloc(
1896 unsigned int,
1897 Relobj*)
1898 {
1899 // We are always SHT_RELA, so we should never get here.
1900 gold_unreachable();
1901 return 0;
1902 }
1903
1904 // Scan the relocs during a relocatable link.
1905
1906 template<int size, bool big_endian>
1907 void
1908 Target_powerpc<size, big_endian>::scan_relocatable_relocs(
1909 Symbol_table* symtab,
1910 Layout* layout,
1911 Sized_relobj<size, big_endian>* object,
1912 unsigned int data_shndx,
1913 unsigned int sh_type,
1914 const unsigned char* prelocs,
1915 size_t reloc_count,
1916 Output_section* output_section,
1917 bool needs_special_offset_handling,
1918 size_t local_symbol_count,
1919 const unsigned char* plocal_symbols,
1920 Relocatable_relocs* rr)
1921 {
1922 gold_assert(sh_type == elfcpp::SHT_RELA);
1923
1924 typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA,
1925 Relocatable_size_for_reloc> Scan_relocatable_relocs;
1926
1927 gold::scan_relocatable_relocs<size, big_endian, elfcpp::SHT_RELA,
1928 Scan_relocatable_relocs>(
1929 symtab,
1930 layout,
1931 object,
1932 data_shndx,
1933 prelocs,
1934 reloc_count,
1935 output_section,
1936 needs_special_offset_handling,
1937 local_symbol_count,
1938 plocal_symbols,
1939 rr);
1940 }
1941
1942 // Relocate a section during a relocatable link.
1943
1944 template<int size, bool big_endian>
1945 void
1946 Target_powerpc<size, big_endian>::relocate_for_relocatable(
1947 const Relocate_info<size, big_endian>* relinfo,
1948 unsigned int sh_type,
1949 const unsigned char* prelocs,
1950 size_t reloc_count,
1951 Output_section* output_section,
1952 off_t offset_in_output_section,
1953 const Relocatable_relocs* rr,
1954 unsigned char* view,
1955 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
1956 section_size_type view_size,
1957 unsigned char* reloc_view,
1958 section_size_type reloc_view_size)
1959 {
1960 gold_assert(sh_type == elfcpp::SHT_RELA);
1961
1962 gold::relocate_for_relocatable<size, big_endian, elfcpp::SHT_RELA>(
1963 relinfo,
1964 prelocs,
1965 reloc_count,
1966 output_section,
1967 offset_in_output_section,
1968 rr,
1969 view,
1970 view_address,
1971 view_size,
1972 reloc_view,
1973 reloc_view_size);
1974 }
1975
1976 // Return the value to use for a dynamic which requires special
1977 // treatment. This is how we support equality comparisons of function
1978 // pointers across shared library boundaries, as described in the
1979 // processor specific ABI supplement.
1980
1981 template<int size, bool big_endian>
1982 uint64_t
1983 Target_powerpc<size, big_endian>::do_dynsym_value(const Symbol* gsym) const
1984 {
1985 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
1986 return this->plt_section()->address() + gsym->plt_offset();
1987 }
1988
1989 // The selector for powerpc object files.
1990
1991 template<int size, bool big_endian>
1992 class Target_selector_powerpc : public Target_selector
1993 {
1994 public:
1995 Target_selector_powerpc()
1996 : Target_selector(elfcpp::EM_NONE, size, big_endian,
1997 (size == 64 ?
1998 (big_endian ? "elf64-powerpc" : "elf64-powerpcle") :
1999 (big_endian ? "elf32-powerpc" : "elf32-powerpcle")))
2000 { }
2001
2002 Target* do_recognize(int machine, int, int)
2003 {
2004 switch (size)
2005 {
2006 case 64:
2007 if (machine != elfcpp::EM_PPC64)
2008 return NULL;
2009 break;
2010
2011 case 32:
2012 if (machine != elfcpp::EM_PPC)
2013 return NULL;
2014 break;
2015
2016 default:
2017 return NULL;
2018 }
2019
2020 return this->instantiate_target();
2021 }
2022
2023 Target* do_instantiate_target()
2024 { return new Target_powerpc<size, big_endian>(); }
2025 };
2026
2027 Target_selector_powerpc<32, true> target_selector_ppc32;
2028 Target_selector_powerpc<32, false> target_selector_ppc32le;
2029 Target_selector_powerpc<64, true> target_selector_ppc64;
2030 Target_selector_powerpc<64, false> target_selector_ppc64le;
2031
2032 } // End anonymous namespace.
This page took 0.073348 seconds and 5 git commands to generate.