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