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