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