1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>
5 // and David Edelsohn <edelsohn@gnu.org>
7 // This file is part of gold.
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.
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.
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.
27 #include "parameters.h"
34 #include "copy-relocs.h"
36 #include "target-reloc.h"
37 #include "target-select.h"
47 template<int size
, bool big_endian
>
48 class Output_data_plt_powerpc
;
50 template<int size
, bool big_endian
>
51 class Output_data_got_powerpc
;
53 template<int size
, bool big_endian
>
54 class Output_data_glink
;
56 template<int size
, bool big_endian
>
57 class Powerpc_relobj
: public Sized_relobj_file
<size
, big_endian
>
60 typedef typename
elfcpp::Elf_types
<size
>::Elf_Off Offset
;
62 Powerpc_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
63 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
64 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
65 special_(0), opd_ent_shndx_(), opd_ent_off_()
71 // The .got2 section shndx.
76 return this->special_
;
81 // The .opd section shndx.
88 return this->special_
;
91 // Init OPD entry arrays.
93 init_opd(size_t opd_size
)
95 size_t count
= this->opd_ent_ndx(opd_size
);
96 this->opd_ent_shndx_
.resize(count
);
97 this->opd_ent_off_
.reserve(count
);
100 // Return section and offset of function entry for .opd + R_OFF.
102 get_opd_ent(typename
elfcpp::Elf_types
<size
>::Elf_Addr r_off
,
104 typename
elfcpp::Elf_types
<size
>::Elf_Addr
* value
)
106 size_t ndx
= this->opd_ent_ndx(r_off
);
107 gold_assert(ndx
< this->opd_ent_shndx_
.size());
108 gold_assert(this->opd_ent_shndx_
[ndx
] != 0);
109 *shndx
= this->opd_ent_shndx_
[ndx
];
110 *value
= this->opd_ent_off_
[ndx
];
113 // Set section and offset of function entry for .opd + R_OFF.
115 set_opd_ent(typename
elfcpp::Elf_types
<size
>::Elf_Addr r_off
,
117 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
)
119 size_t ndx
= this->opd_ent_ndx(r_off
);
120 gold_assert(ndx
< this->opd_ent_shndx_
.size());
121 this->opd_ent_shndx_
[ndx
] = shndx
;
122 this->opd_ent_off_
[ndx
] = value
;
125 // Examine .rela.opd to build info about function entry points.
127 scan_opd_relocs(size_t reloc_count
,
128 const unsigned char* prelocs
,
129 const unsigned char* plocal_syms
);
132 do_read_relocs(Read_relocs_data
*);
135 do_find_special_sections(Read_symbols_data
* sd
);
138 // Return index into opd_ent_shndx or opd_ent_off array for .opd entry
139 // at OFF. .opd entries are 24 bytes long, but they can be spaced
140 // 16 bytes apart when the language doesn't use the last 8-byte
141 // word, the environment pointer. Thus dividing the entry section
142 // offset by 16 will give an index into opd_ent_shndx_ and
143 // opd_ent_off_ that works for either layout of .opd. (It leaves
144 // some elements of the vectors unused when .opd entries are spaced
145 // 24 bytes apart, but we don't know the spacing until relocations
146 // are processed, and in any case it is possible for an object to
147 // have some entries spaced 16 bytes apart and others 24 bytes apart.)
149 opd_ent_ndx(size_t off
) const
152 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
153 unsigned int special_
;
154 // The first 8-byte word of an OPD entry gives the address of the
155 // entry point of the function. Relocatable object files have a
156 // relocation on this word. The following two vectors record the
157 // section and offset specified by these relocations.
158 std::vector
<unsigned int> opd_ent_shndx_
;
159 std::vector
<Offset
> opd_ent_off_
;
162 template<int size
, bool big_endian
>
163 class Target_powerpc
: public Sized_target
<size
, big_endian
>
167 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
168 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
169 static const Address invalid_address
= static_cast<Address
>(0) - 1;
172 : Sized_target
<size
, big_endian
>(&powerpc_info
),
173 got_(NULL
), plt_(NULL
), glink_(NULL
), rela_dyn_(NULL
),
174 copy_relocs_(elfcpp::R_POWERPC_COPY
),
175 dynbss_(NULL
), got_mod_index_offset_(-1U)
179 // Process the relocations to determine unreferenced sections for
180 // garbage collection.
182 gc_process_relocs(Symbol_table
* symtab
,
184 Sized_relobj_file
<size
, big_endian
>* object
,
185 unsigned int data_shndx
,
186 unsigned int sh_type
,
187 const unsigned char* prelocs
,
189 Output_section
* output_section
,
190 bool needs_special_offset_handling
,
191 size_t local_symbol_count
,
192 const unsigned char* plocal_symbols
);
194 // Scan the relocations to look for symbol adjustments.
196 scan_relocs(Symbol_table
* symtab
,
198 Sized_relobj_file
<size
, big_endian
>* object
,
199 unsigned int data_shndx
,
200 unsigned int sh_type
,
201 const unsigned char* prelocs
,
203 Output_section
* output_section
,
204 bool needs_special_offset_handling
,
205 size_t local_symbol_count
,
206 const unsigned char* plocal_symbols
);
208 // Map input .toc section to output .got section.
210 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
212 if (size
== 64 && strcmp(name
, ".toc") == 0)
220 // Finalize the sections.
222 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
224 // Return the value to use for a dynamic which requires special
227 do_dynsym_value(const Symbol
*) const;
229 // Relocate a section.
231 relocate_section(const Relocate_info
<size
, big_endian
>*,
232 unsigned int sh_type
,
233 const unsigned char* prelocs
,
235 Output_section
* output_section
,
236 bool needs_special_offset_handling
,
238 Address view_address
,
239 section_size_type view_size
,
240 const Reloc_symbol_changes
*);
242 // Scan the relocs during a relocatable link.
244 scan_relocatable_relocs(Symbol_table
* symtab
,
246 Sized_relobj_file
<size
, big_endian
>* object
,
247 unsigned int data_shndx
,
248 unsigned int sh_type
,
249 const unsigned char* prelocs
,
251 Output_section
* output_section
,
252 bool needs_special_offset_handling
,
253 size_t local_symbol_count
,
254 const unsigned char* plocal_symbols
,
255 Relocatable_relocs
*);
257 // Relocate a section during a relocatable link.
259 relocate_for_relocatable(const Relocate_info
<size
, big_endian
>*,
260 unsigned int sh_type
,
261 const unsigned char* prelocs
,
263 Output_section
* output_section
,
264 off_t offset_in_output_section
,
265 const Relocatable_relocs
*,
269 unsigned char* reloc_view
,
270 section_size_type reloc_view_size
);
272 // Return whether SYM is defined by the ABI.
274 do_is_defined_by_abi(const Symbol
* sym
) const
276 return strcmp(sym
->name(), "__tls_get_addr") == 0;
279 // Return the size of the GOT section.
283 gold_assert(this->got_
!= NULL
);
284 return this->got_
->data_size();
287 // Get the PLT section.
288 const Output_data_plt_powerpc
<size
, big_endian
>*
291 gold_assert(this->plt_
!= NULL
);
295 // Get the .glink section.
296 const Output_data_glink
<size
, big_endian
>*
297 glink_section() const
299 gold_assert(this->glink_
!= NULL
);
303 // Get the GOT section.
304 const Output_data_got_powerpc
<size
, big_endian
>*
307 gold_assert(this->got_
!= NULL
);
313 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
314 const elfcpp::Ehdr
<size
, big_endian
>&);
316 // Return the number of entries in the GOT.
318 got_entry_count() const
320 if (this->got_
== NULL
)
322 return this->got_size() / (size
/ 8);
325 // Return the number of entries in the PLT.
327 plt_entry_count() const;
329 // Return the offset of the first non-reserved PLT entry.
331 first_plt_entry_offset() const;
333 // Return the size of each PLT entry.
335 plt_entry_size() const;
339 // The class which scans relocations.
344 : issued_non_pic_error_(false)
348 get_reference_flags(unsigned int r_type
);
351 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
352 Sized_relobj_file
<size
, big_endian
>* object
,
353 unsigned int data_shndx
,
354 Output_section
* output_section
,
355 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
356 const elfcpp::Sym
<size
, big_endian
>& lsym
);
359 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
360 Sized_relobj_file
<size
, big_endian
>* object
,
361 unsigned int data_shndx
,
362 Output_section
* output_section
,
363 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
367 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
369 Sized_relobj_file
<size
, big_endian
>* ,
372 const elfcpp::Rela
<size
, big_endian
>& ,
374 const elfcpp::Sym
<size
, big_endian
>&)
378 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
380 Sized_relobj_file
<size
, big_endian
>* ,
383 const elfcpp::Rela
<size
,
385 unsigned int , Symbol
*)
390 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
391 unsigned int r_type
);
394 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
395 unsigned int r_type
, Symbol
*);
398 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
399 Target_powerpc
* target
);
402 check_non_pic(Relobj
*, unsigned int r_type
);
404 // Whether we have issued an error about a non-PIC compilation.
405 bool issued_non_pic_error_
;
408 // The class which implements relocation.
412 // Do a relocation. Return false if the caller should not issue
413 // any warnings about this relocation.
415 relocate(const Relocate_info
<size
, big_endian
>*, Target_powerpc
*,
416 Output_section
*, size_t relnum
,
417 const elfcpp::Rela
<size
, big_endian
>&,
418 unsigned int r_type
, const Sized_symbol
<size
>*,
419 const Symbol_value
<size
>*,
421 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
425 is_branch_reloc(unsigned int r_type
) const
427 return (r_type
== elfcpp::R_POWERPC_REL24
428 || r_type
== elfcpp::R_POWERPC_REL14
429 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
430 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
431 || r_type
== elfcpp::R_POWERPC_ADDR24
432 || r_type
== elfcpp::R_POWERPC_ADDR14
433 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
434 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
438 // Do a TLS relocation.
440 relocate_tls(const Relocate_info
<size
, big_endian
>*,
441 Target_powerpc
* target
,
442 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
443 unsigned int r_type
, const Sized_symbol
<size
>*,
444 const Symbol_value
<size
>*,
446 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
450 // A class which returns the size required for a relocation type,
451 // used while scanning relocs during a relocatable link.
452 class Relocatable_size_for_reloc
456 get_size_for_reloc(unsigned int, Relobj
*)
463 // Adjust TLS relocation type based on the options and whether this
464 // is a local symbol.
465 static tls::Tls_optimization
466 optimize_tls_reloc(bool is_final
, int r_type
);
468 // Get the GOT section, creating it if necessary.
469 Output_data_got_powerpc
<size
, big_endian
>*
470 got_section(Symbol_table
*, Layout
*);
474 make_glink_section(Layout
*);
476 // Create the PLT section.
478 make_plt_section(Layout
*);
480 // Create a PLT entry for a global symbol.
482 make_plt_entry(Layout
*, Symbol
*,
483 const elfcpp::Rela
<size
, big_endian
>&,
484 const Sized_relobj
<size
, big_endian
>* object
);
486 // Create a GOT entry for the TLS module index.
488 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
489 Sized_relobj_file
<size
, big_endian
>* object
);
491 // Get the dynamic reloc section, creating it if necessary.
493 rela_dyn_section(Layout
*);
495 // Copy a relocation against a global symbol.
497 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
498 Sized_relobj_file
<size
, big_endian
>* object
,
499 unsigned int shndx
, Output_section
* output_section
,
500 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
502 this->copy_relocs_
.copy_reloc(symtab
, layout
,
503 symtab
->get_sized_symbol
<size
>(sym
),
504 object
, shndx
, output_section
,
505 reloc
, this->rela_dyn_section(layout
));
508 // Information about this specific target which we pass to the
509 // general Target structure.
510 static Target::Target_info powerpc_info
;
512 // The types of GOT entries needed for this platform.
513 // These values are exposed to the ABI in an incremental link.
514 // Do not renumber existing values without changing the version
515 // number of the .gnu_incremental_inputs section.
518 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
519 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
520 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
523 // The GOT output section.
524 Output_data_got_powerpc
<size
, big_endian
>* got_
;
525 // The PLT output section.
526 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
527 // The .glink output section.
528 Output_data_glink
<size
, big_endian
>* glink_
;
529 // The dynamic reloc output section.
530 Reloc_section
* rela_dyn_
;
531 // Relocs saved to avoid a COPY reloc.
532 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
533 // Space for variables copied with a COPY reloc.
534 Output_data_space
* dynbss_
;
535 // Offset of the GOT entry for the TLS module index;
536 unsigned int got_mod_index_offset_
;
540 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
543 true, // is_big_endian
544 elfcpp::EM_PPC
, // machine_code
545 false, // has_make_symbol
546 false, // has_resolve
547 false, // has_code_fill
548 true, // is_default_stack_executable
549 false, // can_icf_inline_merge_sections
551 "/usr/lib/ld.so.1", // dynamic_linker
552 0x10000000, // default_text_segment_address
553 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
554 4 * 1024, // common_pagesize (overridable by -z common-page-size)
555 false, // isolate_execinstr
557 elfcpp::SHN_UNDEF
, // small_common_shndx
558 elfcpp::SHN_UNDEF
, // large_common_shndx
559 0, // small_common_section_flags
560 0, // large_common_section_flags
561 NULL
, // attributes_section
562 NULL
// attributes_vendor
566 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
569 false, // is_big_endian
570 elfcpp::EM_PPC
, // machine_code
571 false, // has_make_symbol
572 false, // has_resolve
573 false, // has_code_fill
574 true, // is_default_stack_executable
575 false, // can_icf_inline_merge_sections
577 "/usr/lib/ld.so.1", // dynamic_linker
578 0x10000000, // default_text_segment_address
579 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
580 4 * 1024, // common_pagesize (overridable by -z common-page-size)
581 false, // isolate_execinstr
583 elfcpp::SHN_UNDEF
, // small_common_shndx
584 elfcpp::SHN_UNDEF
, // large_common_shndx
585 0, // small_common_section_flags
586 0, // large_common_section_flags
587 NULL
, // attributes_section
588 NULL
// attributes_vendor
592 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
595 true, // is_big_endian
596 elfcpp::EM_PPC64
, // machine_code
597 false, // has_make_symbol
598 false, // has_resolve
599 false, // has_code_fill
600 true, // is_default_stack_executable
601 false, // can_icf_inline_merge_sections
603 "/usr/lib/ld.so.1", // dynamic_linker
604 0x10000000, // default_text_segment_address
605 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
606 8 * 1024, // common_pagesize (overridable by -z common-page-size)
607 false, // isolate_execinstr
609 elfcpp::SHN_UNDEF
, // small_common_shndx
610 elfcpp::SHN_UNDEF
, // large_common_shndx
611 0, // small_common_section_flags
612 0, // large_common_section_flags
613 NULL
, // attributes_section
614 NULL
// attributes_vendor
618 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
621 false, // is_big_endian
622 elfcpp::EM_PPC64
, // machine_code
623 false, // has_make_symbol
624 false, // has_resolve
625 false, // has_code_fill
626 true, // is_default_stack_executable
627 false, // can_icf_inline_merge_sections
629 "/usr/lib/ld.so.1", // dynamic_linker
630 0x10000000, // default_text_segment_address
631 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
632 8 * 1024, // common_pagesize (overridable by -z common-page-size)
633 false, // isolate_execinstr
635 elfcpp::SHN_UNDEF
, // small_common_shndx
636 elfcpp::SHN_UNDEF
, // large_common_shndx
637 0, // small_common_section_flags
638 0, // large_common_section_flags
639 NULL
, // attributes_section
640 NULL
// attributes_vendor
643 template<int size
, bool big_endian
>
644 class Powerpc_relocate_functions
647 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
648 typedef Relocate_functions
<size
, big_endian
> This_reloc
;
649 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
651 // Do a simple RELA relocation
652 template<int valsize
>
654 rela(unsigned char* view
,
655 unsigned int right_shift
,
656 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
660 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
661 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
662 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
663 Valtype reloc
= (value
+ addend
) >> right_shift
;
666 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
669 // Do a simple RELA relocation, unaligned.
670 template<int valsize
>
672 rela_ua(unsigned char* view
,
673 unsigned int right_shift
,
674 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
678 typedef typename
elfcpp::Swap_unaligned
<valsize
, big_endian
>::Valtype
680 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
681 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
682 Valtype reloc
= (value
+ addend
) >> right_shift
;
685 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
689 // R_POWERPC_REL32: (Symbol + Addend - Address)
691 rel32(unsigned char* view
, Address value
, Address addend
, Address address
)
692 { This_reloc::pcrela32(view
, value
, addend
, address
); }
694 // R_POWERPC_REL24: (Symbol + Addend - Address) & 0x3fffffc
696 rel24(unsigned char* view
, Address value
, Address addend
, Address address
)
697 { This::template rela
<32>(view
, 0, 0x03fffffc, value
- address
, addend
); }
699 // R_POWERPC_REL14: (Symbol + Addend - Address) & 0xfffc
701 rel14(unsigned char* view
, Address value
, Address addend
, Address address
)
702 { This::template rela
<32>(view
, 0, 0xfffc, value
- address
, addend
); }
704 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
706 addr16(unsigned char* view
, Address value
, Address addend
)
707 { This_reloc::rela16(view
, value
, addend
); }
709 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
711 addr16_ds(unsigned char* view
, Address value
, Address addend
)
712 { This::template rela
<16>(view
, 0, 0xfffc, value
, addend
); }
714 // R_POWERPC_ADDR16_LO: (Symbol + Addend) & 0xffff
716 addr16_lo(unsigned char* view
, Address value
, Address addend
)
717 { This_reloc::rela16(view
, value
, addend
); }
719 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
721 addr16_hi(unsigned char* view
, Address value
, Address addend
)
722 { This::template rela
<16>(view
, 16, 0xffff, value
, addend
); }
724 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
726 addr16_ha(unsigned char* view
, Address value
, Address addend
)
727 { This::addr16_hi(view
, value
+ 0x8000, addend
); }
729 // R_POWERPC_REL16: (Symbol + Addend - Address) & 0xffff
731 rel16(unsigned char* view
, Address value
, Address addend
, Address address
)
732 { This_reloc::pcrela16(view
, value
, addend
, address
); }
734 // R_POWERPC_REL16_LO: (Symbol + Addend - Address) & 0xffff
736 rel16_lo(unsigned char* view
, Address value
, Address addend
, Address address
)
737 { This_reloc::pcrela16(view
, value
, addend
, address
); }
739 // R_POWERPC_REL16_HI: ((Symbol + Addend - Address) >> 16) & 0xffff
741 rel16_hi(unsigned char* view
, Address value
, Address addend
, Address address
)
742 { This::template rela
<16>(view
, 16, 0xffff, value
- address
, addend
); }
744 // R_POWERPC_REL16_HA: ((Symbol + Addend + 0x8000 - Address) >> 16) & 0xffff
746 rel16_ha(unsigned char* view
, Address value
, Address addend
, Address address
)
747 { This::rel16_hi(view
, value
+ 0x8000, addend
, address
); }
750 // Stash away the index of .got2 or .opd in a relocatable object, if
751 // such a section exists.
753 template<int size
, bool big_endian
>
755 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
756 Read_symbols_data
* sd
)
758 const unsigned char* const pshdrs
= sd
->section_headers
->data();
759 const unsigned char* namesu
= sd
->section_names
->data();
760 const char* names
= reinterpret_cast<const char*>(namesu
);
761 section_size_type names_size
= sd
->section_names_size
;
762 const unsigned char* s
;
764 s
= this->find_shdr(pshdrs
, size
== 32 ? ".got2" : ".opd",
765 names
, names_size
, NULL
);
768 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
769 this->special_
= ndx
;
771 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
774 // Examine .rela.opd to build info about function entry points.
776 template<int size
, bool big_endian
>
778 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
780 const unsigned char* prelocs
,
781 const unsigned char* plocal_syms
)
785 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
788 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
789 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
791 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
793 Reltype
reloc(prelocs
);
794 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
795 = reloc
.get_r_info();
796 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
797 if (r_type
== elfcpp::R_PPC64_ADDR64
)
799 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
800 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
803 if (r_sym
< this->local_symbol_count())
805 typename
elfcpp::Sym
<size
, big_endian
>
806 lsym(plocal_syms
+ r_sym
* sym_size
);
807 shndx
= lsym
.get_st_shndx();
808 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
809 value
= lsym
.get_st_value();
812 shndx
= this->symbol_section_and_value(r_sym
, &value
,
814 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
815 value
+ reloc
.get_r_addend());
821 template<int size
, bool big_endian
>
823 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
825 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
828 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
829 p
!= rd
->relocs
.end();
832 if (p
->data_shndx
== this->opd_shndx())
834 this->init_opd(this->section_size(this->opd_shndx()));
835 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
836 rd
->local_symbols
->data());
843 // Set up PowerPC target specific relobj.
845 template<int size
, bool big_endian
>
847 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
848 const std::string
& name
,
849 Input_file
* input_file
,
850 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
852 int et
= ehdr
.get_e_type();
853 if (et
== elfcpp::ET_REL
)
855 Powerpc_relobj
<size
, big_endian
>* obj
=
856 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
860 else if (et
== elfcpp::ET_DYN
)
862 Sized_dynobj
<size
, big_endian
>* obj
=
863 new Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
869 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
874 template<int size
, bool big_endian
>
875 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
878 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
879 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
881 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
882 : Output_data_got
<size
, big_endian
>(),
883 symtab_(symtab
), layout_(layout
),
884 header_ent_cnt_(size
== 32 ? 3 : 1),
885 header_index_(size
== 32 ? 0x2000 : 0)
890 // Create a new GOT entry and return its offset.
892 add_got_entry(Got_entry got_entry
)
895 return Output_data_got
<size
, big_endian
>::add_got_entry(got_entry
);
898 // Create a pair of new GOT entries and return the offset of the first.
900 add_got_entry_pair(Got_entry got_entry_1
, Got_entry got_entry_2
)
902 this->reserve_ent(2);
903 return Output_data_got
<size
, big_endian
>::add_got_entry_pair(got_entry_1
,
907 // Value of _GLOBAL_OFFSET_TABLE_
911 return this->got_offset(this->header_index_
);
914 // Ensure our GOT has a header.
916 set_final_data_size()
918 if (this->header_ent_cnt_
!= 0)
920 Output_data_got
<size
, big_endian
>::set_final_data_size();
923 // First word of GOT header needs some values that are not
924 // handled by Output_data_got so poke them in here.
925 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
927 do_write(Output_file
* of
)
929 this->replace_constant(this->header_index_
,
931 ? this->layout_
->dynamic_section()->address()
932 : this->address() + 0x8000));
934 Output_data_got
<size
, big_endian
>::do_write(of
);
939 reserve_ent(unsigned int cnt
= 1)
941 if (this->header_ent_cnt_
== 0)
943 if (this->num_entries() + cnt
> this->header_index_
)
950 this->header_ent_cnt_
= 0;
951 this->header_index_
= this->num_entries();
954 Output_data_got
<size
, big_endian
>::add_constant(0);
955 Output_data_got
<size
, big_endian
>::add_constant(0);
956 Output_data_got
<size
, big_endian
>::add_constant(0);
958 // Define _GLOBAL_OFFSET_TABLE_ at the header
959 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
960 Symbol_table::PREDEFINED
,
961 this, this->g_o_t(), 0,
968 Output_data_got
<size
, big_endian
>::add_constant(0);
972 Symbol_table
* symtab_
;
976 unsigned int header_ent_cnt_
;
978 unsigned int header_index_
;
981 // Get the GOT section, creating it if necessary.
983 template<int size
, bool big_endian
>
984 Output_data_got_powerpc
<size
, big_endian
>*
985 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
988 if (this->got_
== NULL
)
990 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
993 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
995 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
996 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
997 this->got_
, ORDER_DATA
, false);
1003 // Get the dynamic reloc section, creating it if necessary.
1005 template<int size
, bool big_endian
>
1006 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
1007 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1009 if (this->rela_dyn_
== NULL
)
1011 gold_assert(layout
!= NULL
);
1012 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1013 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1014 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1015 ORDER_DYNAMIC_RELOCS
, false);
1017 return this->rela_dyn_
;
1020 // A class to handle the PLT data.
1022 template<int size
, bool big_endian
>
1023 class Output_data_plt_powerpc
: public Output_section_data_build
1026 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1027 size
, big_endian
> Reloc_section
;
1029 Output_data_plt_powerpc(Layout
*, Target_powerpc
<size
, big_endian
>*);
1031 // Add an entry to the PLT.
1035 // Return the .rela.plt section data.
1036 const Reloc_section
*
1042 // Return the number of PLT entries.
1046 return ((this->current_data_size() - initial_plt_entry_size
)
1050 // Return the offset of the first non-reserved PLT entry.
1052 first_plt_entry_offset()
1053 { return initial_plt_entry_size
; }
1055 // Return the size of a PLT entry.
1057 get_plt_entry_size()
1058 { return plt_entry_size
; }
1062 do_adjust_output_section(Output_section
* os
)
1067 // Write to a map file.
1069 do_print_to_mapfile(Mapfile
* mapfile
) const
1070 { mapfile
->print_output_data(this, _("** PLT")); }
1073 // The size of an entry in the PLT.
1074 static const int plt_entry_size
= size
== 32 ? 4 : 24;
1075 // The size of the first reserved entry.
1076 static const int initial_plt_entry_size
= size
== 32 ? 0 : 24;
1078 // Write out the PLT data.
1080 do_write(Output_file
*);
1082 // The reloc section.
1083 Reloc_section
* rel_
;
1084 // Allows access to .glink for do_write.
1085 Target_powerpc
<size
, big_endian
>* targ_
;
1088 // Create the PLT section.
1090 template<int size
, bool big_endian
>
1091 Output_data_plt_powerpc
<size
, big_endian
>::Output_data_plt_powerpc(
1093 Target_powerpc
<size
, big_endian
>* targ
)
1094 : Output_section_data_build(size
== 32 ? 4 : 8),
1097 this->rel_
= new Reloc_section(false);
1098 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1099 elfcpp::SHF_ALLOC
, this->rel_
,
1100 ORDER_DYNAMIC_PLT_RELOCS
, false);
1103 // Add an entry to the PLT.
1105 template<int size
, bool big_endian
>
1107 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1109 if (!gsym
->has_plt_offset())
1111 off_t off
= this->current_data_size();
1114 off
+= initial_plt_entry_size
;
1115 gsym
->set_plt_offset(off
);
1116 gsym
->set_needs_dynsym_entry();
1117 this->rel_
->add_global(gsym
, elfcpp::R_POWERPC_JMP_SLOT
, this, off
, 0);
1118 off
+= plt_entry_size
;
1119 this->set_current_data_size(off
);
1123 static const uint32_t addis_11_11
= 0x3d6b0000;
1124 static const uint32_t addis_11_30
= 0x3d7e0000;
1125 static const uint32_t addis_12_12
= 0x3d8c0000;
1126 static const uint32_t addi_11_11
= 0x396b0000;
1127 static const uint32_t add_0_11_11
= 0x7c0b5a14;
1128 static const uint32_t add_11_0_11
= 0x7d605a14;
1129 static const uint32_t b
= 0x48000000;
1130 static const uint32_t bcl_20_31
= 0x429f0005;
1131 static const uint32_t bctr
= 0x4e800420;
1132 static const uint32_t blrl
= 0x4e800021;
1133 static const uint32_t lis_11
= 0x3d600000;
1134 static const uint32_t lis_12
= 0x3d800000;
1135 static const uint32_t lwzu_0_12
= 0x840c0000;
1136 static const uint32_t lwz_0_12
= 0x800c0000;
1137 static const uint32_t lwz_11_11
= 0x816b0000;
1138 static const uint32_t lwz_11_30
= 0x817e0000;
1139 static const uint32_t lwz_12_12
= 0x818c0000;
1140 static const uint32_t mflr_0
= 0x7c0802a6;
1141 static const uint32_t mflr_12
= 0x7d8802a6;
1142 static const uint32_t mtctr_0
= 0x7c0903a6;
1143 static const uint32_t mtctr_11
= 0x7d6903a6;
1144 static const uint32_t mtlr_0
= 0x7c0803a6;
1145 static const uint32_t nop
= 0x60000000;
1146 static const uint32_t sub_11_11_12
= 0x7d6c5850;
1147 static const uint32_t addis_12_2
= 0x3d820000;
1148 static const uint32_t std_2_1
= 0xf8410000;
1149 static const uint32_t ld_2_1
= 0xe8410000;
1150 static const uint32_t ld_11_12
= 0xe96c0000;
1151 static const uint32_t ld_2_12
= 0xe84c0000;
1152 static const uint32_t addi_12_12
= 0x398c0000;
1153 static const uint32_t ld_11_2
= 0xe9620000;
1154 static const uint32_t addi_2_2
= 0x38420000;
1155 static const uint32_t ld_2_2
= 0xe8420000;
1156 static const uint32_t mflr_11
= 0x7d6802a6;
1157 static const uint32_t ld_2_11
= 0xe84b0000;
1158 static const uint32_t mtlr_12
= 0x7d8803a6;
1159 static const uint32_t add_12_2_11
= 0x7d825a14;
1160 static const uint32_t li_0_0
= 0x38000000;
1161 static const uint32_t lis_0_0
= 0x3c000000;
1162 static const uint32_t ori_0_0_0
= 0x60000000;
1163 static const uint32_t cror_15_15_15
= 0x4def7b82;
1164 static const uint32_t cror_31_31_31
= 0x4ffffb82;
1166 // Write out the PLT.
1168 template<int size
, bool big_endian
>
1170 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
1174 const off_t offset
= this->offset();
1175 const section_size_type oview_size
1176 = convert_to_section_size_type(this->data_size());
1177 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1178 unsigned char* pov
= oview
;
1179 unsigned char* endpov
= oview
+ oview_size
;
1181 // The address the .glink branch table
1182 const Output_data_glink
<size
, big_endian
>* glink
1183 = this->targ_
->glink_section();
1184 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
1185 = glink
->address() + glink
->pltresolve();
1187 while (pov
< endpov
)
1189 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
1194 of
->write_output_view(offset
, oview_size
, oview
);
1198 // Create the PLT section.
1200 template<int size
, bool big_endian
>
1202 Target_powerpc
<size
, big_endian
>::make_plt_section(Layout
* layout
)
1204 if (this->plt_
== NULL
)
1206 if (this->glink_
== NULL
)
1207 make_glink_section(layout
);
1209 // Ensure that .rela.dyn always appears before .rela.plt This is
1210 // necessary due to how, on PowerPC and some other targets, .rela.dyn
1211 // needs to include .rela.plt in it's range.
1212 this->rela_dyn_section(layout
);
1214 this->plt_
= new Output_data_plt_powerpc
<size
, big_endian
>(layout
, this);
1215 layout
->add_output_section_data(".plt",
1217 ? elfcpp::SHT_PROGBITS
1218 : elfcpp::SHT_NOBITS
),
1219 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1228 // A class to handle .glink.
1230 template<int size
, bool big_endian
>
1231 class Output_data_glink
: public Output_section_data
1234 static const int pltresolve_size
= 16*4;
1236 Output_data_glink(Target_powerpc
<size
, big_endian
>*);
1240 add_entry(const Symbol
*, const elfcpp::Rela
<size
, big_endian
>&,
1241 const Sized_relobj
<size
, big_endian
>*);
1244 find_entry(const Symbol
*, const elfcpp::Rela
<size
, big_endian
>&,
1245 const Sized_relobj
<size
, big_endian
>*) const;
1248 glink_entry_size() const
1253 // FIXME: We should be using multiple glink sections for
1254 // stubs to support > 33M applications.
1261 return this->pltresolve_
;
1265 // Write to a map file.
1267 do_print_to_mapfile(Mapfile
* mapfile
) const
1268 { mapfile
->print_output_data(this, _("** glink")); }
1272 set_final_data_size();
1276 do_write(Output_file
*);
1281 Glink_sym_ent(const Symbol
* sym
,
1282 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1283 const Sized_relobj
<size
, big_endian
>* object
)
1284 : sym_(sym
), addend_(0), object_(0)
1287 this->addend_
= reloc
.get_r_addend();
1288 else if (parameters
->options().output_is_position_independent()
1289 && (elfcpp::elf_r_type
<size
>(reloc
.get_r_info())
1290 == elfcpp::R_PPC_PLTREL24
))
1292 this->addend_
= reloc
.get_r_addend();
1293 if (this->addend_
!= 0)
1294 this->object_
= object
;
1298 bool operator==(const Glink_sym_ent
& that
) const
1300 return (this->sym_
== that
.sym_
1301 && this->object_
== that
.object_
1302 && this->addend_
== that
.addend_
);
1306 unsigned int addend_
;
1307 const Sized_relobj
<size
, big_endian
>* object_
;
1310 class Glink_sym_ent_hash
1313 size_t operator()(const Glink_sym_ent
& ent
) const
1315 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
1316 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
1321 // Map sym/object/addend to index.
1322 typedef Unordered_map
<Glink_sym_ent
, unsigned int,
1323 Glink_sym_ent_hash
> Glink_entries
;
1324 Glink_entries glink_entries_
;
1326 // Offset of pltresolve stub (actually, branch table for 32-bit)
1329 // Allows access to .got and .plt for do_write.
1330 Target_powerpc
<size
, big_endian
>* targ_
;
1333 // Create the glink section.
1335 template<int size
, bool big_endian
>
1336 Output_data_glink
<size
, big_endian
>::Output_data_glink(
1337 Target_powerpc
<size
, big_endian
>* targ
)
1338 : Output_section_data(16),
1339 pltresolve_(0), targ_(targ
)
1343 // Add an entry to glink, if we do not already have one for this
1344 // sym/object/addend combo.
1346 template<int size
, bool big_endian
>
1348 Output_data_glink
<size
, big_endian
>::add_entry(
1350 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1351 const Sized_relobj
<size
, big_endian
>* object
)
1353 Glink_sym_ent
ent(gsym
, reloc
, object
);
1354 unsigned int indx
= this->glink_entries_
.size();
1355 this->glink_entries_
.insert(std::make_pair(ent
, indx
));
1358 template<int size
, bool big_endian
>
1360 Output_data_glink
<size
, big_endian
>::find_entry(
1362 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1363 const Sized_relobj
<size
, big_endian
>* object
) const
1365 Glink_sym_ent
ent(gsym
, reloc
, object
);
1366 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
1367 gold_assert(p
!= this->glink_entries_
.end());
1371 template<int size
, bool big_endian
>
1373 Output_data_glink
<size
, big_endian
>::set_final_data_size()
1375 unsigned int count
= this->glink_entries_
.size();
1376 off_t total
= count
;
1383 this->pltresolve_
= total
;
1385 // space for branch table
1386 total
+= 4 * (count
- 1);
1388 total
+= -total
& 15;
1389 total
+= this->pltresolve_size
;
1394 this->pltresolve_
= total
;
1395 total
+= this->pltresolve_size
;
1397 // space for branch table
1400 total
+= 4 * (count
- 0x8000);
1404 this->set_data_size(total
);
1407 static inline uint32_t
1413 static inline uint32_t
1419 static inline uint32_t
1422 return hi(a
+ 0x8000);
1425 template<bool big_endian
>
1427 write_insn(unsigned char* p
, uint32_t v
)
1429 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
1432 // Write out .glink.
1434 template<int size
, bool big_endian
>
1436 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
1438 const off_t off
= this->offset();
1439 const section_size_type oview_size
=
1440 convert_to_section_size_type(this->data_size());
1441 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
1444 // The base address of the .plt section.
1445 uint32_t plt_base
= this->targ_
->plt_section()->address();
1447 // The address of _GLOBAL_OFFSET_TABLE_.
1448 const Output_data_got_powerpc
<size
, big_endian
>* got
;
1449 typename
elfcpp::Elf_types
<size
>::Elf_Addr g_o_t
;
1450 got
= this->targ_
->got_section();
1454 const unsigned int toc_base_offset
= 0x8000;
1455 g_o_t
= got
->output_section()->address() + toc_base_offset
;
1457 // Write out call stubs.
1458 typename
Glink_entries::const_iterator g
;
1459 for (g
= this->glink_entries_
.begin();
1460 g
!= this->glink_entries_
.end();
1463 uint64_t plt_addr
= plt_base
+ g
->first
.sym_
->plt_offset();
1464 uint64_t got_addr
= g_o_t
;
1465 uint64_t pltoff
= plt_addr
- got_addr
;
1467 if (pltoff
+ 0x80008000 > 0xffffffff || (pltoff
& 7) != 0)
1468 gold_error(_("%s: linkage table error against `%s'"),
1469 g
->first
.object_
->name().c_str(),
1470 g
->first
.sym_
->demangled_name().c_str());
1472 p
= oview
+ g
->second
* this->glink_entry_size();
1473 if (ha(pltoff
) != 0)
1475 write_insn
<big_endian
>(p
, addis_12_2
+ ha(pltoff
)), p
+= 4;
1476 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
1477 write_insn
<big_endian
>(p
, ld_11_12
+ l(pltoff
)), p
+= 4;
1478 if (ha(pltoff
+ 16) != ha(pltoff
))
1480 write_insn
<big_endian
>(p
, addi_12_12
+ l(pltoff
)), p
+= 4;
1483 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
1484 write_insn
<big_endian
>(p
, ld_2_12
+ l(pltoff
+ 8)), p
+= 4;
1485 write_insn
<big_endian
>(p
, ld_11_12
+ l(pltoff
+ 16)), p
+= 4;
1486 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
1490 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
1491 write_insn
<big_endian
>(p
, ld_11_2
+ l(pltoff
)), p
+= 4;
1492 if (ha(pltoff
+ 16) != ha(pltoff
))
1494 write_insn
<big_endian
>(p
, addi_2_2
+ l(pltoff
)), p
+= 4;
1497 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
1498 write_insn
<big_endian
>(p
, ld_11_2
+ l(pltoff
+ 16)), p
+= 4;
1499 write_insn
<big_endian
>(p
, ld_2_2
+ l(pltoff
+ 8)), p
+= 4;
1500 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
1504 // Write pltresolve stub.
1505 p
= oview
+ this->pltresolve_
;
1506 uint64_t after_bcl
= this->address() + this->pltresolve_
+ 16;
1507 uint64_t pltoff
= plt_base
- after_bcl
;
1509 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
1511 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
1512 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
1513 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
1514 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
1515 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
1516 write_insn
<big_endian
>(p
, add_12_2_11
), p
+= 4;
1517 write_insn
<big_endian
>(p
, ld_11_12
+ 0), p
+= 4;
1518 write_insn
<big_endian
>(p
, ld_2_12
+ 8), p
+= 4;
1519 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
1520 write_insn
<big_endian
>(p
, ld_11_12
+ 16), p
+= 4;
1521 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
1522 while (p
< oview
+ this->pltresolve_
+ this->pltresolve_size
)
1523 write_insn
<big_endian
>(p
, nop
), p
+= 4;
1525 // Write lazy link call stubs.
1527 while (p
< oview
+ oview_size
)
1531 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
1535 write_insn
<big_endian
>(p
, lis_0_0
+ hi(indx
)), p
+= 4;
1536 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
1538 uint32_t branch_off
= this->pltresolve_
+ 8 - (p
- oview
);
1539 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
1545 g_o_t
= got
->address() + got
->g_o_t();
1547 // Write out call stubs.
1548 typename
Glink_entries::const_iterator g
;
1549 for (g
= this->glink_entries_
.begin();
1550 g
!= this->glink_entries_
.end();
1553 uint32_t plt_addr
= plt_base
+ g
->first
.sym_
->plt_offset();
1555 const uint32_t invalid_address
= static_cast<uint32_t>(-1);
1557 p
= oview
+ g
->second
* this->glink_entry_size();
1558 if (parameters
->options().output_is_position_independent())
1560 const Powerpc_relobj
<size
, big_endian
>* object
= static_cast
1561 <const Powerpc_relobj
<size
, big_endian
>*>(g
->first
.object_
);
1564 unsigned int got2
= object
->got2_shndx();
1565 got_addr
= g
->first
.object_
->get_output_section_offset(got2
);
1566 gold_assert(got_addr
!= invalid_address
);
1567 got_addr
+= (g
->first
.object_
->output_section(got2
)->address()
1568 + g
->first
.addend_
);
1573 uint32_t pltoff
= plt_addr
- got_addr
;
1574 if (ha(pltoff
) == 0)
1576 write_insn
<big_endian
>(p
+ 0, lwz_11_30
+ l(pltoff
));
1577 write_insn
<big_endian
>(p
+ 4, mtctr_11
);
1578 write_insn
<big_endian
>(p
+ 8, bctr
);
1582 write_insn
<big_endian
>(p
+ 0, addis_11_30
+ ha(pltoff
));
1583 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(pltoff
));
1584 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
1585 write_insn
<big_endian
>(p
+ 12, bctr
);
1590 write_insn
<big_endian
>(p
+ 0, lis_11
+ ha(plt_addr
));
1591 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(plt_addr
));
1592 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
1593 write_insn
<big_endian
>(p
+ 12, bctr
);
1597 // Write out pltresolve branch table.
1598 p
= oview
+ this->pltresolve_
;
1599 unsigned int the_end
= oview_size
- this->pltresolve_size
;
1600 unsigned char* end_p
= oview
+ the_end
;
1601 while (p
< end_p
- 8 * 4)
1602 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
1604 write_insn
<big_endian
>(p
, nop
), p
+= 4;
1606 // Write out pltresolve call stub.
1607 if (parameters
->options().output_is_position_independent())
1609 uint32_t res0_off
= this->pltresolve_
;
1610 uint32_t after_bcl_off
= the_end
+ 12;
1611 uint32_t bcl_res0
= after_bcl_off
- res0_off
;
1613 write_insn
<big_endian
>(p
+ 0, addis_11_11
+ ha(bcl_res0
));
1614 write_insn
<big_endian
>(p
+ 4, mflr_0
);
1615 write_insn
<big_endian
>(p
+ 8, bcl_20_31
);
1616 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(bcl_res0
));
1617 write_insn
<big_endian
>(p
+ 16, mflr_12
);
1618 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
1619 write_insn
<big_endian
>(p
+ 24, sub_11_11_12
);
1621 uint32_t got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
1623 write_insn
<big_endian
>(p
+ 28, addis_12_12
+ ha(got_bcl
));
1624 if (ha(got_bcl
) == ha(got_bcl
+ 4))
1626 write_insn
<big_endian
>(p
+ 32, lwz_0_12
+ l(got_bcl
));
1627 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ l(got_bcl
+ 4));
1631 write_insn
<big_endian
>(p
+ 32, lwzu_0_12
+ l(got_bcl
));
1632 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ 4);
1634 write_insn
<big_endian
>(p
+ 40, mtctr_0
);
1635 write_insn
<big_endian
>(p
+ 44, add_0_11_11
);
1636 write_insn
<big_endian
>(p
+ 48, add_11_0_11
);
1637 write_insn
<big_endian
>(p
+ 52, bctr
);
1638 write_insn
<big_endian
>(p
+ 56, nop
);
1639 write_insn
<big_endian
>(p
+ 60, nop
);
1643 uint32_t res0
= this->pltresolve_
+ this->address();
1645 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(g_o_t
+ 4));
1646 write_insn
<big_endian
>(p
+ 4, addis_11_11
+ ha(-res0
));
1647 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
1648 write_insn
<big_endian
>(p
+ 8, lwz_0_12
+ l(g_o_t
+ 4));
1650 write_insn
<big_endian
>(p
+ 8, lwzu_0_12
+ l(g_o_t
+ 4));
1651 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(-res0
));
1652 write_insn
<big_endian
>(p
+ 16, mtctr_0
);
1653 write_insn
<big_endian
>(p
+ 20, add_0_11_11
);
1654 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
1655 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ l(g_o_t
+ 8));
1657 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ 4);
1658 write_insn
<big_endian
>(p
+ 28, add_11_0_11
);
1659 write_insn
<big_endian
>(p
+ 32, bctr
);
1660 write_insn
<big_endian
>(p
+ 36, nop
);
1661 write_insn
<big_endian
>(p
+ 40, nop
);
1662 write_insn
<big_endian
>(p
+ 44, nop
);
1663 write_insn
<big_endian
>(p
+ 48, nop
);
1664 write_insn
<big_endian
>(p
+ 52, nop
);
1665 write_insn
<big_endian
>(p
+ 56, nop
);
1666 write_insn
<big_endian
>(p
+ 60, nop
);
1671 of
->write_output_view(off
, oview_size
, oview
);
1674 // Create the glink section.
1676 template<int size
, bool big_endian
>
1678 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
1680 if (this->glink_
== NULL
)
1682 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
1683 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
1684 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
1685 this->glink_
, ORDER_TEXT
, false);
1689 // Create a PLT entry for a global symbol.
1691 template<int size
, bool big_endian
>
1693 Target_powerpc
<size
, big_endian
>::make_plt_entry(
1696 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1697 const Sized_relobj
<size
, big_endian
>* object
)
1699 if (this->plt_
== NULL
)
1700 this->make_plt_section(layout
);
1702 this->plt_
->add_entry(gsym
);
1704 this->glink_
->add_entry(gsym
, reloc
, object
);
1707 // Return the number of entries in the PLT.
1709 template<int size
, bool big_endian
>
1711 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
1713 if (this->plt_
== NULL
)
1715 return this->plt_
->entry_count();
1718 // Return the offset of the first non-reserved PLT entry.
1720 template<int size
, bool big_endian
>
1722 Target_powerpc
<size
, big_endian
>::first_plt_entry_offset() const
1724 return Output_data_plt_powerpc
<size
, big_endian
>::first_plt_entry_offset();
1727 // Return the size of each PLT entry.
1729 template<int size
, bool big_endian
>
1731 Target_powerpc
<size
, big_endian
>::plt_entry_size() const
1733 return Output_data_plt_powerpc
<size
, big_endian
>::get_plt_entry_size();
1736 // Create a GOT entry for the TLS module index.
1738 template<int size
, bool big_endian
>
1740 Target_powerpc
<size
, big_endian
>::got_mod_index_entry(
1741 Symbol_table
* symtab
,
1743 Sized_relobj_file
<size
, big_endian
>* object
)
1745 if (this->got_mod_index_offset_
== -1U)
1747 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1748 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1749 Output_data_got_powerpc
<size
, big_endian
>* got
;
1750 unsigned int got_offset
;
1752 got
= this->got_section(symtab
, layout
);
1753 got
->reserve_ent(2);
1754 got_offset
= got
->add_constant(0);
1755 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
1757 got
->add_constant(0);
1758 this->got_mod_index_offset_
= got_offset
;
1760 return this->got_mod_index_offset_
;
1763 // Optimize the TLS relocation type based on what we know about the
1764 // symbol. IS_FINAL is true if the final address of this symbol is
1765 // known at link time.
1767 template<int size
, bool big_endian
>
1768 tls::Tls_optimization
1769 Target_powerpc
<size
, big_endian
>::optimize_tls_reloc(bool, int)
1771 // If we are generating a shared library, then we can't do anything
1773 if (parameters
->options().shared())
1774 return tls::TLSOPT_NONE
;
1776 return tls::TLSOPT_NONE
;
1779 // Get the Reference_flags for a particular relocation.
1781 template<int size
, bool big_endian
>
1783 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
1787 case elfcpp::R_POWERPC_NONE
:
1788 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
1789 case elfcpp::R_POWERPC_GNU_VTENTRY
:
1790 case elfcpp::R_PPC64_TOC
:
1791 // No symbol reference.
1794 case elfcpp::R_POWERPC_ADDR16
:
1795 case elfcpp::R_POWERPC_ADDR16_LO
:
1796 case elfcpp::R_POWERPC_ADDR16_HI
:
1797 case elfcpp::R_POWERPC_ADDR16_HA
:
1798 case elfcpp::R_POWERPC_ADDR32
:
1799 case elfcpp::R_PPC64_ADDR64
:
1800 return Symbol::ABSOLUTE_REF
;
1802 case elfcpp::R_POWERPC_REL24
:
1803 case elfcpp::R_PPC_LOCAL24PC
:
1804 case elfcpp::R_POWERPC_REL16
:
1805 case elfcpp::R_POWERPC_REL16_LO
:
1806 case elfcpp::R_POWERPC_REL16_HI
:
1807 case elfcpp::R_POWERPC_REL16_HA
:
1808 return Symbol::RELATIVE_REF
;
1810 case elfcpp::R_PPC_PLTREL24
:
1811 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
1813 case elfcpp::R_POWERPC_GOT16
:
1814 case elfcpp::R_POWERPC_GOT16_LO
:
1815 case elfcpp::R_POWERPC_GOT16_HI
:
1816 case elfcpp::R_POWERPC_GOT16_HA
:
1817 case elfcpp::R_PPC64_TOC16
:
1818 case elfcpp::R_PPC64_TOC16_LO
:
1819 case elfcpp::R_PPC64_TOC16_HI
:
1820 case elfcpp::R_PPC64_TOC16_HA
:
1821 case elfcpp::R_PPC64_TOC16_DS
:
1822 case elfcpp::R_PPC64_TOC16_LO_DS
:
1824 return Symbol::ABSOLUTE_REF
;
1826 case elfcpp::R_POWERPC_GOT_TPREL16
:
1827 case elfcpp::R_POWERPC_TLS
:
1828 return Symbol::TLS_REF
;
1830 case elfcpp::R_POWERPC_COPY
:
1831 case elfcpp::R_POWERPC_GLOB_DAT
:
1832 case elfcpp::R_POWERPC_JMP_SLOT
:
1833 case elfcpp::R_POWERPC_RELATIVE
:
1834 case elfcpp::R_POWERPC_DTPMOD
:
1836 // Not expected. We will give an error later.
1841 // Report an unsupported relocation against a local symbol.
1843 template<int size
, bool big_endian
>
1845 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
1846 Sized_relobj_file
<size
, big_endian
>* object
,
1847 unsigned int r_type
)
1849 gold_error(_("%s: unsupported reloc %u against local symbol"),
1850 object
->name().c_str(), r_type
);
1853 // We are about to emit a dynamic relocation of type R_TYPE. If the
1854 // dynamic linker does not support it, issue an error.
1856 template<int size
, bool big_endian
>
1858 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
1859 unsigned int r_type
)
1861 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
1863 // These are the relocation types supported by glibc for both 32-bit
1864 // and 64-bit powerpc.
1867 case elfcpp::R_POWERPC_RELATIVE
:
1868 case elfcpp::R_POWERPC_GLOB_DAT
:
1869 case elfcpp::R_POWERPC_DTPMOD
:
1870 case elfcpp::R_POWERPC_DTPREL
:
1871 case elfcpp::R_POWERPC_TPREL
:
1872 case elfcpp::R_POWERPC_JMP_SLOT
:
1873 case elfcpp::R_POWERPC_COPY
:
1874 case elfcpp::R_POWERPC_ADDR32
:
1875 case elfcpp::R_POWERPC_ADDR24
:
1876 case elfcpp::R_POWERPC_REL24
:
1887 // These are the relocation types supported only on 64-bit.
1888 case elfcpp::R_PPC64_ADDR64
:
1889 case elfcpp::R_PPC64_TPREL16_LO_DS
:
1890 case elfcpp::R_PPC64_TPREL16_DS
:
1891 case elfcpp::R_POWERPC_TPREL16
:
1892 case elfcpp::R_POWERPC_TPREL16_LO
:
1893 case elfcpp::R_POWERPC_TPREL16_HI
:
1894 case elfcpp::R_POWERPC_TPREL16_HA
:
1895 case elfcpp::R_PPC64_TPREL16_HIGHER
:
1896 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
1897 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
1898 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
1899 case elfcpp::R_PPC64_ADDR16_LO_DS
:
1900 case elfcpp::R_POWERPC_ADDR16_LO
:
1901 case elfcpp::R_POWERPC_ADDR16_HI
:
1902 case elfcpp::R_POWERPC_ADDR16_HA
:
1903 case elfcpp::R_POWERPC_ADDR30
:
1904 case elfcpp::R_PPC64_UADDR64
:
1905 case elfcpp::R_POWERPC_UADDR32
:
1906 case elfcpp::R_POWERPC_ADDR16
:
1907 case elfcpp::R_POWERPC_UADDR16
:
1908 case elfcpp::R_PPC64_ADDR16_DS
:
1909 case elfcpp::R_PPC64_ADDR16_HIGHER
:
1910 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
1911 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
1912 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
1913 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
1914 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
1915 case elfcpp::R_POWERPC_REL32
:
1916 case elfcpp::R_PPC64_REL64
:
1927 // These are the relocation types supported only on 32-bit.
1934 // This prevents us from issuing more than one error per reloc
1935 // section. But we can still wind up issuing more than one
1936 // error per object file.
1937 if (this->issued_non_pic_error_
)
1939 gold_assert(parameters
->options().output_is_position_independent());
1940 object
->error(_("requires unsupported dynamic reloc; "
1941 "recompile with -fPIC"));
1942 this->issued_non_pic_error_
= true;
1946 // Scan a relocation for a local symbol.
1948 template<int size
, bool big_endian
>
1950 Target_powerpc
<size
, big_endian
>::Scan::local(
1951 Symbol_table
* symtab
,
1953 Target_powerpc
<size
, big_endian
>* target
,
1954 Sized_relobj_file
<size
, big_endian
>* object
,
1955 unsigned int data_shndx
,
1956 Output_section
* output_section
,
1957 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1958 unsigned int r_type
,
1959 const elfcpp::Sym
<size
, big_endian
>& lsym
)
1963 case elfcpp::R_POWERPC_NONE
:
1964 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
1965 case elfcpp::R_POWERPC_GNU_VTENTRY
:
1966 case elfcpp::R_PPC64_TOCSAVE
:
1969 case elfcpp::R_PPC64_ADDR64
:
1970 case elfcpp::R_POWERPC_ADDR32
:
1971 case elfcpp::R_POWERPC_ADDR16
:
1972 case elfcpp::R_POWERPC_ADDR16_LO
:
1973 case elfcpp::R_POWERPC_ADDR16_HI
:
1974 case elfcpp::R_POWERPC_ADDR16_HA
:
1975 // If building a shared library (or a position-independent
1976 // executable), we need to create a dynamic relocation for
1978 if (parameters
->options().output_is_position_independent())
1980 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1982 check_non_pic(object
, r_type
);
1983 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
1985 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1986 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
1987 data_shndx
, reloc
.get_r_offset(),
1988 reloc
.get_r_addend());
1992 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1993 gold_assert(lsym
.get_st_value() == 0);
1994 rela_dyn
->add_local_relative(object
, r_sym
, r_type
,
1995 output_section
, data_shndx
,
1996 reloc
.get_r_offset(),
1997 reloc
.get_r_addend(), false);
2002 case elfcpp::R_POWERPC_REL24
:
2003 case elfcpp::R_PPC_LOCAL24PC
:
2004 case elfcpp::R_POWERPC_REL32
:
2005 case elfcpp::R_POWERPC_REL16_LO
:
2006 case elfcpp::R_POWERPC_REL16_HA
:
2009 case elfcpp::R_POWERPC_GOT16
:
2010 case elfcpp::R_POWERPC_GOT16_LO
:
2011 case elfcpp::R_POWERPC_GOT16_HI
:
2012 case elfcpp::R_POWERPC_GOT16_HA
:
2014 // The symbol requires a GOT entry.
2015 Output_data_got_powerpc
<size
, big_endian
>* got
;
2018 got
= target
->got_section(symtab
, layout
);
2019 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2021 // If we are generating a shared object, we need to add a
2022 // dynamic relocation for this symbol's GOT entry.
2023 if (parameters
->options().output_is_position_independent())
2025 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
2027 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2030 off
= got
->add_constant(0);
2031 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
2032 rela_dyn
->add_local_relative(object
, r_sym
,
2033 elfcpp::R_POWERPC_RELATIVE
,
2034 got
, off
, 0, false);
2038 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
2042 case elfcpp::R_PPC64_TOC16
:
2043 case elfcpp::R_PPC64_TOC16_LO
:
2044 case elfcpp::R_PPC64_TOC16_HI
:
2045 case elfcpp::R_PPC64_TOC16_HA
:
2046 case elfcpp::R_PPC64_TOC16_DS
:
2047 case elfcpp::R_PPC64_TOC16_LO_DS
:
2048 case elfcpp::R_PPC64_TOC
:
2049 // We need a GOT section.
2050 target
->got_section(symtab
, layout
);
2053 // These are relocations which should only be seen by the
2054 // dynamic linker, and should never be seen here.
2055 case elfcpp::R_POWERPC_COPY
:
2056 case elfcpp::R_POWERPC_GLOB_DAT
:
2057 case elfcpp::R_POWERPC_JMP_SLOT
:
2058 case elfcpp::R_POWERPC_RELATIVE
:
2059 case elfcpp::R_POWERPC_DTPMOD
:
2060 gold_error(_("%s: unexpected reloc %u in object file"),
2061 object
->name().c_str(), r_type
);
2065 unsupported_reloc_local(object
, r_type
);
2070 // Report an unsupported relocation against a global symbol.
2072 template<int size
, bool big_endian
>
2074 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
2075 Sized_relobj_file
<size
, big_endian
>* object
,
2076 unsigned int r_type
,
2079 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2080 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2083 // Scan a relocation for a global symbol.
2085 template<int size
, bool big_endian
>
2087 Target_powerpc
<size
, big_endian
>::Scan::global(
2088 Symbol_table
* symtab
,
2090 Target_powerpc
<size
, big_endian
>* target
,
2091 Sized_relobj_file
<size
, big_endian
>* object
,
2092 unsigned int data_shndx
,
2093 Output_section
* output_section
,
2094 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2095 unsigned int r_type
,
2100 case elfcpp::R_POWERPC_NONE
:
2101 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2102 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2103 case elfcpp::R_PPC_LOCAL24PC
:
2106 case elfcpp::R_PPC64_ADDR64
:
2107 case elfcpp::R_POWERPC_ADDR32
:
2108 case elfcpp::R_POWERPC_ADDR16
:
2109 case elfcpp::R_POWERPC_ADDR16_LO
:
2110 case elfcpp::R_POWERPC_ADDR16_HI
:
2111 case elfcpp::R_POWERPC_ADDR16_HA
:
2113 // Make a PLT entry if necessary.
2114 if (gsym
->needs_plt_entry())
2116 target
->make_plt_entry(layout
, gsym
, reloc
, 0);
2117 // Since this is not a PC-relative relocation, we may be
2118 // taking the address of a function. In that case we need to
2119 // set the entry in the dynamic symbol table to the address of
2122 && gsym
->is_from_dynobj() && !parameters
->options().shared())
2123 gsym
->set_needs_dynsym_value();
2125 // Make a dynamic relocation if necessary.
2126 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2128 if (gsym
->may_need_copy_reloc())
2130 target
->copy_reloc(symtab
, layout
, object
,
2131 data_shndx
, output_section
, gsym
, reloc
);
2133 else if ((r_type
== elfcpp::R_POWERPC_ADDR32
2134 || r_type
== elfcpp::R_PPC64_ADDR64
)
2135 && gsym
->can_use_relative_reloc(false))
2137 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2138 rela_dyn
->add_global_relative(gsym
, elfcpp::R_POWERPC_RELATIVE
,
2139 output_section
, object
,
2140 data_shndx
, reloc
.get_r_offset(),
2141 reloc
.get_r_addend(), false);
2145 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2147 check_non_pic(object
, r_type
);
2148 if (gsym
->is_from_dynobj()
2149 || gsym
->is_undefined()
2150 || gsym
->is_preemptible())
2151 rela_dyn
->add_global(gsym
, r_type
, output_section
,
2153 reloc
.get_r_offset(),
2154 reloc
.get_r_addend());
2156 rela_dyn
->add_global_relative(gsym
, r_type
,
2157 output_section
, object
,
2159 reloc
.get_r_offset(),
2160 reloc
.get_r_addend(), false);
2166 case elfcpp::R_PPC_PLTREL24
:
2167 case elfcpp::R_POWERPC_REL24
:
2169 if (gsym
->needs_plt_entry()
2170 || (!gsym
->final_value_is_known()
2171 && !(gsym
->is_defined()
2172 && !gsym
->is_from_dynobj()
2173 && !gsym
->is_preemptible())))
2174 target
->make_plt_entry(layout
, gsym
, reloc
, object
);
2175 // Make a dynamic relocation if necessary.
2176 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2178 if (gsym
->may_need_copy_reloc())
2180 target
->copy_reloc(symtab
, layout
, object
,
2181 data_shndx
, output_section
, gsym
,
2186 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2187 check_non_pic(object
, r_type
);
2188 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
2189 data_shndx
, reloc
.get_r_offset(),
2190 reloc
.get_r_addend());
2196 case elfcpp::R_POWERPC_REL16
:
2197 case elfcpp::R_POWERPC_REL16_LO
:
2198 case elfcpp::R_POWERPC_REL16_HI
:
2199 case elfcpp::R_POWERPC_REL16_HA
:
2202 case elfcpp::R_POWERPC_GOT16
:
2203 case elfcpp::R_POWERPC_GOT16_LO
:
2204 case elfcpp::R_POWERPC_GOT16_HI
:
2205 case elfcpp::R_POWERPC_GOT16_HA
:
2207 // The symbol requires a GOT entry.
2208 Output_data_got_powerpc
<size
, big_endian
>* got
;
2210 got
= target
->got_section(symtab
, layout
);
2211 if (gsym
->final_value_is_known())
2212 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2215 // If this symbol is not fully resolved, we need to add a
2216 // dynamic relocation for it.
2217 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2218 if (gsym
->is_from_dynobj()
2219 || gsym
->is_undefined()
2220 || gsym
->is_preemptible())
2221 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2222 elfcpp::R_POWERPC_GLOB_DAT
);
2223 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2225 unsigned int off
= got
->add_constant(0);
2227 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2228 rela_dyn
->add_global_relative(gsym
, elfcpp::R_POWERPC_RELATIVE
,
2229 got
, off
, 0, false);
2235 case elfcpp::R_PPC64_TOC
:
2236 case elfcpp::R_PPC64_TOC16
:
2237 case elfcpp::R_PPC64_TOC16_LO
:
2238 case elfcpp::R_PPC64_TOC16_HI
:
2239 case elfcpp::R_PPC64_TOC16_HA
:
2240 case elfcpp::R_PPC64_TOC16_DS
:
2241 case elfcpp::R_PPC64_TOC16_LO_DS
:
2242 // We need a GOT section.
2243 target
->got_section(symtab
, layout
);
2246 case elfcpp::R_POWERPC_GOT_TPREL16
:
2247 case elfcpp::R_POWERPC_TLS
:
2251 // These are relocations which should only be seen by the
2252 // dynamic linker, and should never be seen here.
2253 case elfcpp::R_POWERPC_COPY
:
2254 case elfcpp::R_POWERPC_GLOB_DAT
:
2255 case elfcpp::R_POWERPC_JMP_SLOT
:
2256 case elfcpp::R_POWERPC_RELATIVE
:
2257 case elfcpp::R_POWERPC_DTPMOD
:
2258 gold_error(_("%s: unexpected reloc %u in object file"),
2259 object
->name().c_str(), r_type
);
2263 unsupported_reloc_global(object
, r_type
, gsym
);
2268 // Process relocations for gc.
2270 template<int size
, bool big_endian
>
2272 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
2273 Symbol_table
* symtab
,
2275 Sized_relobj_file
<size
, big_endian
>* object
,
2276 unsigned int data_shndx
,
2278 const unsigned char* prelocs
,
2280 Output_section
* output_section
,
2281 bool needs_special_offset_handling
,
2282 size_t local_symbol_count
,
2283 const unsigned char* plocal_symbols
)
2285 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
2286 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
2288 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
,
2289 typename
Target_powerpc::Relocatable_size_for_reloc
>(
2298 needs_special_offset_handling
,
2303 // Scan relocations for a section.
2305 template<int size
, bool big_endian
>
2307 Target_powerpc
<size
, big_endian
>::scan_relocs(
2308 Symbol_table
* symtab
,
2310 Sized_relobj_file
<size
, big_endian
>* object
,
2311 unsigned int data_shndx
,
2312 unsigned int sh_type
,
2313 const unsigned char* prelocs
,
2315 Output_section
* output_section
,
2316 bool needs_special_offset_handling
,
2317 size_t local_symbol_count
,
2318 const unsigned char* plocal_symbols
)
2320 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
2321 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
2323 if (sh_type
== elfcpp::SHT_REL
)
2325 gold_error(_("%s: unsupported REL reloc section"),
2326 object
->name().c_str());
2332 static Output_data_space
* sdata
;
2334 // Define _SDA_BASE_ at the start of the .sdata section.
2337 // layout->find_output_section(".sdata") == NULL
2338 sdata
= new Output_data_space(4, "** sdata");
2340 = layout
->add_output_section_data(".sdata", 0,
2342 | elfcpp::SHF_WRITE
,
2343 sdata
, ORDER_SMALL_DATA
, false);
2344 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2345 Symbol_table::PREDEFINED
,
2346 os
, 32768, 0, elfcpp::STT_OBJECT
,
2347 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2352 gold::scan_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
>(
2361 needs_special_offset_handling
,
2366 // Finalize the sections.
2368 template<int size
, bool big_endian
>
2370 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
2372 const Input_objects
*,
2375 // Fill in some more dynamic tags.
2376 const Reloc_section
* rel_plt
= (this->plt_
== NULL
2378 : this->plt_
->rel_plt());
2379 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
2380 this->rela_dyn_
, true, size
== 32);
2382 Output_data_dynamic
* odyn
= layout
->dynamic_data();
2385 this->got_
->finalize_data_size();
2386 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
2387 this->got_
, this->got_
->g_o_t());
2391 this->glink_
->finalize_data_size();
2392 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
2394 (this->glink_
->pltresolve()
2395 + this->glink_
->pltresolve_size
- 32));
2398 // Emit any relocs we saved in an attempt to avoid generating COPY
2400 if (this->copy_relocs_
.any_saved_relocs())
2401 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
2404 // Perform a relocation.
2406 template<int size
, bool big_endian
>
2408 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
2409 const Relocate_info
<size
, big_endian
>* relinfo
,
2410 Target_powerpc
* target
,
2413 const elfcpp::Rela
<size
, big_endian
>& rela
,
2414 unsigned int r_type
,
2415 const Sized_symbol
<size
>* gsym
,
2416 const Symbol_value
<size
>* psymval
,
2417 unsigned char* view
,
2419 section_size_type view_size
)
2421 const unsigned int toc_base_offset
= 0x8000;
2422 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
2423 const Powerpc_relobj
<size
, big_endian
>* const object
2424 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
2427 if (r_type
== elfcpp::R_POWERPC_GOT16
2428 || r_type
== elfcpp::R_POWERPC_GOT16_LO
2429 || r_type
== elfcpp::R_POWERPC_GOT16_HI
2430 || r_type
== elfcpp::R_POWERPC_GOT16_HA
2431 || r_type
== elfcpp::R_PPC64_GOT16_DS
2432 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
2436 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
2437 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
2441 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2442 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
2443 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
2445 value
-= target
->got_section()->g_o_t();
2447 else if (r_type
== elfcpp::R_PPC64_TOC
)
2449 value
= (target
->got_section()->output_section()->address()
2452 else if (gsym
!= NULL
2453 && (r_type
== elfcpp::R_POWERPC_REL24
2454 || r_type
== elfcpp::R_PPC_PLTREL24
)
2455 && gsym
->use_plt_offset(Scan::get_reference_flags(r_type
)))
2457 const Output_data_glink
<size
, big_endian
>* glink
;
2459 glink
= target
->glink_section();
2460 unsigned int glink_index
= glink
->find_entry(gsym
, rela
, object
);
2461 value
= glink
->address() + glink_index
* glink
->glink_entry_size();
2464 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2465 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2466 bool can_plt_call
= false;
2467 if (rela
.get_r_offset() + 8 <= view_size
)
2469 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
2471 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
)
2473 elfcpp::Swap
<32, big_endian
>::writeval(wv
+ 1, ld_2_1
+ 40);
2474 can_plt_call
= true;
2478 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2479 _("call lacks nop, can't restore toc"));
2484 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
= 0;
2485 if (r_type
!= elfcpp::R_PPC_PLTREL24
)
2486 addend
= rela
.get_r_addend();
2487 value
= psymval
->value(object
, addend
);
2488 if (size
== 64 && this->is_branch_reloc(r_type
))
2490 Powerpc_relobj
<size
, big_endian
>* symobj
= const_cast
2491 <Powerpc_relobj
<size
, big_endian
>*>(object
);
2493 symobj
= static_cast
2494 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
2495 unsigned int shndx
= symobj
->opd_shndx();
2496 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
2497 gold_assert(opd_addr
!= invalid_address
);
2498 opd_addr
+= symobj
->output_section(shndx
)->address();
2499 if (value
>= opd_addr
2500 && value
< opd_addr
+ symobj
->section_size(shndx
))
2503 symobj
->get_opd_ent(value
- opd_addr
, &shndx
, &sec_off
);
2504 Address sec_addr
= symobj
->get_output_section_offset(shndx
);
2505 gold_assert(sec_addr
!= invalid_address
);
2506 sec_addr
+= symobj
->output_section(shndx
)->address();
2507 value
= sec_addr
+ sec_off
;
2514 case elfcpp::R_PPC64_TOC16
:
2515 case elfcpp::R_PPC64_TOC16_LO
:
2516 case elfcpp::R_PPC64_TOC16_HI
:
2517 case elfcpp::R_PPC64_TOC16_HA
:
2518 case elfcpp::R_PPC64_TOC16_DS
:
2519 case elfcpp::R_PPC64_TOC16_LO_DS
:
2520 // Subtract the TOC base address.
2521 value
-= (target
->got_section()->output_section()->address()
2525 case elfcpp::R_POWERPC_SECTOFF
:
2526 case elfcpp::R_POWERPC_SECTOFF_LO
:
2527 case elfcpp::R_POWERPC_SECTOFF_HI
:
2528 case elfcpp::R_POWERPC_SECTOFF_HA
:
2529 case elfcpp::R_PPC64_SECTOFF_DS
:
2530 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
2532 value
-= os
->address();
2541 case elfcpp::R_POWERPC_NONE
:
2542 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2543 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2546 case elfcpp::R_POWERPC_REL32
:
2547 Reloc::rel32(view
, value
, 0, address
);
2550 case elfcpp::R_POWERPC_REL24
:
2551 case elfcpp::R_PPC_PLTREL24
:
2552 case elfcpp::R_PPC_LOCAL24PC
:
2553 Reloc::rel24(view
, value
, 0, address
);
2556 case elfcpp::R_POWERPC_REL14
:
2557 Reloc::rel14(view
, value
, 0, address
);
2560 case elfcpp::R_PPC64_ADDR64
:
2561 case elfcpp::R_PPC64_TOC
:
2562 Relocate_functions
<size
, big_endian
>::rela64(view
, value
, 0);
2565 case elfcpp::R_POWERPC_ADDR32
:
2566 Relocate_functions
<size
, big_endian
>::rela32(view
, value
, 0);
2569 case elfcpp::R_POWERPC_ADDR16
:
2570 case elfcpp::R_PPC64_TOC16
:
2571 case elfcpp::R_POWERPC_GOT16
:
2572 case elfcpp::R_POWERPC_SECTOFF
:
2573 Reloc::addr16(view
, value
, 0);
2576 case elfcpp::R_POWERPC_ADDR16_LO
:
2577 case elfcpp::R_PPC64_TOC16_LO
:
2578 case elfcpp::R_POWERPC_GOT16_LO
:
2579 case elfcpp::R_POWERPC_SECTOFF_LO
:
2580 Reloc::addr16_lo(view
, value
, 0);
2583 case elfcpp::R_POWERPC_ADDR16_HI
:
2584 case elfcpp::R_PPC64_TOC16_HI
:
2585 case elfcpp::R_POWERPC_GOT16_HI
:
2586 case elfcpp::R_POWERPC_SECTOFF_HI
:
2587 Reloc::addr16_hi(view
, value
, 0);
2590 case elfcpp::R_POWERPC_ADDR16_HA
:
2591 case elfcpp::R_PPC64_TOC16_HA
:
2592 case elfcpp::R_POWERPC_GOT16_HA
:
2593 case elfcpp::R_POWERPC_SECTOFF_HA
:
2594 Reloc::addr16_ha(view
, value
, 0);
2597 case elfcpp::R_POWERPC_REL16_LO
:
2598 Reloc::rel16_lo(view
, value
, 0, address
);
2601 case elfcpp::R_POWERPC_REL16_HI
:
2602 Reloc::rel16_hi(view
, value
, 0, address
);
2605 case elfcpp::R_POWERPC_REL16_HA
:
2606 Reloc::rel16_ha(view
, value
, 0, address
);
2609 case elfcpp::R_PPC64_ADDR16_DS
:
2610 case elfcpp::R_PPC64_ADDR16_LO_DS
:
2611 case elfcpp::R_PPC64_TOC16_DS
:
2612 case elfcpp::R_PPC64_TOC16_LO_DS
:
2613 case elfcpp::R_PPC64_GOT16_DS
:
2614 case elfcpp::R_PPC64_GOT16_LO_DS
:
2615 case elfcpp::R_PPC64_SECTOFF_DS
:
2616 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
2617 Reloc::addr16_ds(view
, value
, 0);
2620 case elfcpp::R_POWERPC_COPY
:
2621 case elfcpp::R_POWERPC_GLOB_DAT
:
2622 case elfcpp::R_POWERPC_JMP_SLOT
:
2623 case elfcpp::R_POWERPC_RELATIVE
:
2624 // This is an outstanding tls reloc, which is unexpected when
2626 case elfcpp::R_POWERPC_DTPMOD
:
2627 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2628 _("unexpected reloc %u in object file"),
2632 case elfcpp::R_PPC64_TOCSAVE
:
2633 // For the time being this can be ignored.
2637 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2638 _("unsupported reloc %u"),
2646 // Perform a TLS relocation.
2648 template<int size
, bool big_endian
>
2650 Target_powerpc
<size
, big_endian
>::Relocate::relocate_tls(
2651 const Relocate_info
<size
, big_endian
>* relinfo
,
2652 Target_powerpc
<size
, big_endian
>* target
,
2654 const elfcpp::Rela
<size
, big_endian
>& rela
,
2655 unsigned int r_type
,
2656 const Sized_symbol
<size
>* gsym
,
2657 const Symbol_value
<size
>* psymval
,
2658 unsigned char* view
,
2662 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
2663 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
2665 const Address addend
= rela
.get_r_addend();
2666 Address value
= psymval
->value(object
, 0);
2668 const bool is_final
=
2670 ? !parameters
->options().output_is_position_independent()
2671 : gsym
->final_value_is_known());
2679 // Relocate section data.
2681 template<int size
, bool big_endian
>
2683 Target_powerpc
<size
, big_endian
>::relocate_section(
2684 const Relocate_info
<size
, big_endian
>* relinfo
,
2685 unsigned int sh_type
,
2686 const unsigned char* prelocs
,
2688 Output_section
* output_section
,
2689 bool needs_special_offset_handling
,
2690 unsigned char* view
,
2692 section_size_type view_size
,
2693 const Reloc_symbol_changes
* reloc_symbol_changes
)
2695 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
2696 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
2698 gold_assert(sh_type
== elfcpp::SHT_RELA
);
2700 gold::relocate_section
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
,
2707 needs_special_offset_handling
,
2711 reloc_symbol_changes
);
2714 class Powerpc_scan_relocatable_reloc
2717 // Return the strategy to use for a local symbol which is not a
2718 // section symbol, given the relocation type.
2719 inline Relocatable_relocs::Reloc_strategy
2720 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
2722 if (r_type
== 0 && r_sym
== 0)
2723 return Relocatable_relocs::RELOC_DISCARD
;
2724 return Relocatable_relocs::RELOC_COPY
;
2727 // Return the strategy to use for a local symbol which is a section
2728 // symbol, given the relocation type.
2729 inline Relocatable_relocs::Reloc_strategy
2730 local_section_strategy(unsigned int, Relobj
*)
2732 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
2735 // Return the strategy to use for a global symbol, given the
2736 // relocation type, the object, and the symbol index.
2737 inline Relocatable_relocs::Reloc_strategy
2738 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
2740 if (r_type
== elfcpp::R_PPC_PLTREL24
)
2741 return Relocatable_relocs::RELOC_SPECIAL
;
2742 return Relocatable_relocs::RELOC_COPY
;
2746 // Scan the relocs during a relocatable link.
2748 template<int size
, bool big_endian
>
2750 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
2751 Symbol_table
* symtab
,
2753 Sized_relobj_file
<size
, big_endian
>* object
,
2754 unsigned int data_shndx
,
2755 unsigned int sh_type
,
2756 const unsigned char* prelocs
,
2758 Output_section
* output_section
,
2759 bool needs_special_offset_handling
,
2760 size_t local_symbol_count
,
2761 const unsigned char* plocal_symbols
,
2762 Relocatable_relocs
* rr
)
2764 gold_assert(sh_type
== elfcpp::SHT_RELA
);
2766 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
2767 Powerpc_scan_relocatable_reloc
>(
2775 needs_special_offset_handling
,
2781 // Relocate a section during a relocatable link.
2783 template<int size
, bool big_endian
>
2785 Target_powerpc
<size
, big_endian
>::relocate_for_relocatable(
2786 const Relocate_info
<size
, big_endian
>* relinfo
,
2787 unsigned int sh_type
,
2788 const unsigned char* prelocs
,
2790 Output_section
* output_section
,
2791 off_t offset_in_output_section
,
2792 const Relocatable_relocs
* rr
,
2796 unsigned char* reloc_view
,
2797 section_size_type reloc_view_size
)
2799 gold_assert(sh_type
== elfcpp::SHT_RELA
);
2801 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
2803 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc_write
2805 const int reloc_size
2806 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
2808 Powerpc_relobj
<size
, big_endian
>* const object
2809 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
2810 const unsigned int local_count
= object
->local_symbol_count();
2811 unsigned int got2_shndx
= object
->got2_shndx();
2812 Address got2_addend
= 0;
2813 if (got2_shndx
!= 0)
2815 got2_addend
= object
->get_output_section_offset(got2_shndx
);
2816 gold_assert(got2_addend
!= invalid_address
);
2819 unsigned char* pwrite
= reloc_view
;
2821 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
2823 Relocatable_relocs::Reloc_strategy strategy
= rr
->strategy(i
);
2824 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
2827 Reltype
reloc(prelocs
);
2828 Reltype_write
reloc_write(pwrite
);
2830 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
2831 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
2832 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
2834 // Get the new symbol index.
2836 unsigned int new_symndx
;
2837 if (r_sym
< local_count
)
2841 case Relocatable_relocs::RELOC_COPY
:
2842 case Relocatable_relocs::RELOC_SPECIAL
:
2843 new_symndx
= object
->symtab_index(r_sym
);
2844 gold_assert(new_symndx
!= -1U);
2847 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
2849 // We are adjusting a section symbol. We need to find
2850 // the symbol table index of the section symbol for
2851 // the output section corresponding to input section
2852 // in which this symbol is defined.
2853 gold_assert(r_sym
< local_count
);
2855 unsigned int shndx
=
2856 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
2857 gold_assert(is_ordinary
);
2858 Output_section
* os
= object
->output_section(shndx
);
2859 gold_assert(os
!= NULL
);
2860 gold_assert(os
->needs_symtab_index());
2861 new_symndx
= os
->symtab_index();
2871 const Symbol
* gsym
= object
->global_symbol(r_sym
);
2872 gold_assert(gsym
!= NULL
);
2873 if (gsym
->is_forwarder())
2874 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
2876 gold_assert(gsym
->has_symtab_index());
2877 new_symndx
= gsym
->symtab_index();
2880 // Get the new offset--the location in the output section where
2881 // this relocation should be applied.
2883 Address offset
= reloc
.get_r_offset();
2885 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
2886 new_offset
= offset
+ offset_in_output_section
;
2889 section_offset_type sot_offset
=
2890 convert_types
<section_offset_type
, Address
>(offset
);
2891 section_offset_type new_sot_offset
=
2892 output_section
->output_offset(object
, relinfo
->data_shndx
,
2894 gold_assert(new_sot_offset
!= -1);
2895 new_offset
= new_sot_offset
;
2898 reloc_write
.put_r_offset(new_offset
);
2899 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(new_symndx
, r_type
));
2901 // Handle the reloc addend based on the strategy.
2902 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
;
2903 addend
= Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::
2904 get_reloc_addend(&reloc
);
2906 if (strategy
== Relocatable_relocs::RELOC_COPY
)
2908 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
2910 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
2912 addend
= psymval
->value(object
, addend
);
2914 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
2916 if (addend
>= 32768)
2917 addend
+= got2_addend
;
2922 Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::
2923 set_reloc_addend(&reloc_write
, addend
);
2925 pwrite
+= reloc_size
;
2928 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
2929 == reloc_view_size
);
2932 // Return the value to use for a dynamic which requires special
2933 // treatment. This is how we support equality comparisons of function
2934 // pointers across shared library boundaries, as described in the
2935 // processor specific ABI supplement.
2937 template<int size
, bool big_endian
>
2939 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
2943 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
2944 return this->plt_section()->address() + gsym
->plt_offset();
2950 // The selector for powerpc object files.
2952 template<int size
, bool big_endian
>
2953 class Target_selector_powerpc
: public Target_selector
2956 Target_selector_powerpc()
2957 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
2959 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
2960 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
2962 ? (big_endian
? "elf64ppc" : "elf64lppc")
2963 : (big_endian
? "elf32ppc" : "elf32lppc")))
2967 do_recognize(Input_file
*, off_t
, int machine
, int, int)
2972 if (machine
!= elfcpp::EM_PPC64
)
2977 if (machine
!= elfcpp::EM_PPC
)
2985 return this->instantiate_target();
2989 do_instantiate_target()
2990 { return new Target_powerpc
<size
, big_endian
>(); }
2993 Target_selector_powerpc
<32, true> target_selector_ppc32
;
2994 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
2995 Target_selector_powerpc
<64, true> target_selector_ppc64
;
2996 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
2998 } // End anonymous namespace.