1 // arm.cc -- arm target support for gold.
3 // Copyright 2009 Free Software Foundation, Inc.
4 // Written by Doug Kwan <dougkwan@google.com> based on the i386 code
5 // by Ian Lance Taylor <iant@google.com>.
6 // This file also contains borrowed and adapted code from
9 // This file is part of gold.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 3 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
24 // MA 02110-1301, USA.
35 #include "parameters.h"
42 #include "copy-relocs.h"
44 #include "target-reloc.h"
45 #include "target-select.h"
55 template<bool big_endian
>
56 class Output_data_plt_arm
;
58 template<bool big_endian
>
61 template<bool big_endian
>
62 class Arm_input_section
;
64 template<bool big_endian
>
65 class Arm_output_section
;
67 template<bool big_endian
>
70 template<bool big_endian
>
74 typedef elfcpp::Elf_types
<32>::Elf_Addr Arm_address
;
76 // Maximum branch offsets for ARM, THUMB and THUMB2.
77 const int32_t ARM_MAX_FWD_BRANCH_OFFSET
= ((((1 << 23) - 1) << 2) + 8);
78 const int32_t ARM_MAX_BWD_BRANCH_OFFSET
= ((-((1 << 23) << 2)) + 8);
79 const int32_t THM_MAX_FWD_BRANCH_OFFSET
= ((1 << 22) -2 + 4);
80 const int32_t THM_MAX_BWD_BRANCH_OFFSET
= (-(1 << 22) + 4);
81 const int32_t THM2_MAX_FWD_BRANCH_OFFSET
= (((1 << 24) - 2) + 4);
82 const int32_t THM2_MAX_BWD_BRANCH_OFFSET
= (-(1 << 24) + 4);
84 // The arm target class.
86 // This is a very simple port of gold for ARM-EABI. It is intended for
87 // supporting Android only for the time being. Only these relocation types
116 // R_ARM_THM_MOVW_ABS_NC
117 // R_ARM_THM_MOVT_ABS
118 // R_ARM_MOVW_PREL_NC
120 // R_ARM_THM_MOVW_PREL_NC
121 // R_ARM_THM_MOVT_PREL
124 // - Generate various branch stubs.
125 // - Support interworking.
126 // - Define section symbols __exidx_start and __exidx_stop.
127 // - Support more relocation types as needed.
128 // - Make PLTs more flexible for different architecture features like
130 // There are probably a lot more.
132 // Instruction template class. This class is similar to the insn_sequence
133 // struct in bfd/elf32-arm.c.
138 // Types of instruction templates.
147 // Factory methods to create instrunction templates in different formats.
149 static const Insn_template
150 thumb16_insn(uint32_t data
)
151 { return Insn_template(data
, THUMB16_TYPE
, elfcpp::R_ARM_NONE
, 0); }
153 // A bit of a hack. A Thumb conditional branch, in which the proper
154 // condition is inserted when we build the stub.
155 static const Insn_template
156 thumb16_bcond_insn(uint32_t data
)
157 { return Insn_template(data
, THUMB16_TYPE
, elfcpp::R_ARM_NONE
, 1); }
159 static const Insn_template
160 thumb32_insn(uint32_t data
)
161 { return Insn_template(data
, THUMB32_TYPE
, elfcpp::R_ARM_NONE
, 0); }
163 static const Insn_template
164 thumb32_b_insn(uint32_t data
, int reloc_addend
)
166 return Insn_template(data
, THUMB32_TYPE
, elfcpp::R_ARM_THM_JUMP24
,
170 static const Insn_template
171 arm_insn(uint32_t data
)
172 { return Insn_template(data
, ARM_TYPE
, elfcpp::R_ARM_NONE
, 0); }
174 static const Insn_template
175 arm_rel_insn(unsigned data
, int reloc_addend
)
176 { return Insn_template(data
, ARM_TYPE
, elfcpp::R_ARM_JUMP24
, reloc_addend
); }
178 static const Insn_template
179 data_word(unsigned data
, unsigned int r_type
, int reloc_addend
)
180 { return Insn_template(data
, DATA_TYPE
, r_type
, reloc_addend
); }
182 // Accessors. This class is used for read-only objects so no modifiers
187 { return this->data_
; }
189 // Return the instruction sequence type of this.
192 { return this->type_
; }
194 // Return the ARM relocation type of this.
197 { return this->r_type_
; }
201 { return this->reloc_addend_
; }
203 // Return size of instrunction template in bytes.
207 // Return byte-alignment of instrunction template.
212 // We make the constructor private to ensure that only the factory
215 Insn_template(unsigned data
, Type type
, unsigned int r_type
, int reloc_addend
)
216 : data_(data
), type_(type
), r_type_(r_type
), reloc_addend_(reloc_addend
)
219 // Instruction specific data. This is used to store information like
220 // some of the instruction bits.
222 // Instruction template type.
224 // Relocation type if there is a relocation or R_ARM_NONE otherwise.
225 unsigned int r_type_
;
226 // Relocation addend.
227 int32_t reloc_addend_
;
230 // Macro for generating code to stub types. One entry per long/short
234 DEF_STUB(long_branch_any_any) \
235 DEF_STUB(long_branch_v4t_arm_thumb) \
236 DEF_STUB(long_branch_thumb_only) \
237 DEF_STUB(long_branch_v4t_thumb_thumb) \
238 DEF_STUB(long_branch_v4t_thumb_arm) \
239 DEF_STUB(short_branch_v4t_thumb_arm) \
240 DEF_STUB(long_branch_any_arm_pic) \
241 DEF_STUB(long_branch_any_thumb_pic) \
242 DEF_STUB(long_branch_v4t_thumb_thumb_pic) \
243 DEF_STUB(long_branch_v4t_arm_thumb_pic) \
244 DEF_STUB(long_branch_v4t_thumb_arm_pic) \
245 DEF_STUB(long_branch_thumb_only_pic) \
246 DEF_STUB(a8_veneer_b_cond) \
247 DEF_STUB(a8_veneer_b) \
248 DEF_STUB(a8_veneer_bl) \
249 DEF_STUB(a8_veneer_blx)
253 #define DEF_STUB(x) arm_stub_##x,
259 // First reloc stub type.
260 arm_stub_reloc_first
= arm_stub_long_branch_any_any
,
261 // Last reloc stub type.
262 arm_stub_reloc_last
= arm_stub_long_branch_thumb_only_pic
,
264 // First Cortex-A8 stub type.
265 arm_stub_cortex_a8_first
= arm_stub_a8_veneer_b_cond
,
266 // Last Cortex-A8 stub type.
267 arm_stub_cortex_a8_last
= arm_stub_a8_veneer_blx
,
270 arm_stub_type_last
= arm_stub_a8_veneer_blx
274 // Stub template class. Templates are meant to be read-only objects.
275 // A stub template for a stub type contains all read-only attributes
276 // common to all stubs of the same type.
281 Stub_template(Stub_type
, const Insn_template
*, size_t);
289 { return this->type_
; }
291 // Return an array of instruction templates.
294 { return this->insns_
; }
296 // Return size of template in number of instructions.
299 { return this->insn_count_
; }
301 // Return size of template in bytes.
304 { return this->size_
; }
306 // Return alignment of the stub template.
309 { return this->alignment_
; }
311 // Return whether entry point is in thumb mode.
313 entry_in_thumb_mode() const
314 { return this->entry_in_thumb_mode_
; }
316 // Return number of relocations in this template.
319 { return this->relocs_
.size(); }
321 // Return index of the I-th instruction with relocation.
323 reloc_insn_index(size_t i
) const
325 gold_assert(i
< this->relocs_
.size());
326 return this->relocs_
[i
].first
;
329 // Return the offset of the I-th instruction with relocation from the
330 // beginning of the stub.
332 reloc_offset(size_t i
) const
334 gold_assert(i
< this->relocs_
.size());
335 return this->relocs_
[i
].second
;
339 // This contains information about an instruction template with a relocation
340 // and its offset from start of stub.
341 typedef std::pair
<size_t, section_size_type
> Reloc
;
343 // A Stub_template may not be copied. We want to share templates as much
345 Stub_template(const Stub_template
&);
346 Stub_template
& operator=(const Stub_template
&);
350 // Points to an array of Insn_templates.
351 const Insn_template
* insns_
;
352 // Number of Insn_templates in insns_[].
354 // Size of templated instructions in bytes.
356 // Alignment of templated instructions.
358 // Flag to indicate if entry is in thumb mode.
359 bool entry_in_thumb_mode_
;
360 // A table of reloc instruction indices and offsets. We can find these by
361 // looking at the instruction templates but we pre-compute and then stash
362 // them here for speed.
363 std::vector
<Reloc
> relocs_
;
367 // A class for code stubs. This is a base class for different type of
368 // stubs used in the ARM target.
374 static const section_offset_type invalid_offset
=
375 static_cast<section_offset_type
>(-1);
378 Stub(const Stub_template
* stub_template
)
379 : stub_template_(stub_template
), offset_(invalid_offset
)
386 // Return the stub template.
388 stub_template() const
389 { return this->stub_template_
; }
391 // Return offset of code stub from beginning of its containing stub table.
395 gold_assert(this->offset_
!= invalid_offset
);
396 return this->offset_
;
399 // Set offset of code stub from beginning of its containing stub table.
401 set_offset(section_offset_type offset
)
402 { this->offset_
= offset
; }
404 // Return the relocation target address of the i-th relocation in the
405 // stub. This must be defined in a child class.
407 reloc_target(size_t i
)
408 { return this->do_reloc_target(i
); }
410 // Write a stub at output VIEW. BIG_ENDIAN select how a stub is written.
412 write(unsigned char* view
, section_size_type view_size
, bool big_endian
)
413 { this->do_write(view
, view_size
, big_endian
); }
416 // This must be defined in the child class.
418 do_reloc_target(size_t) = 0;
420 // This must be defined in the child class.
422 do_write(unsigned char*, section_size_type
, bool) = 0;
426 const Stub_template
* stub_template_
;
427 // Offset within the section of containing this stub.
428 section_offset_type offset_
;
431 // Reloc stub class. These are stubs we use to fix up relocation because
432 // of limited branch ranges.
434 class Reloc_stub
: public Stub
437 static const unsigned int invalid_index
= static_cast<unsigned int>(-1);
438 // We assume we never jump to this address.
439 static const Arm_address invalid_address
= static_cast<Arm_address
>(-1);
441 // Return destination address.
443 destination_address() const
445 gold_assert(this->destination_address_
!= this->invalid_address
);
446 return this->destination_address_
;
449 // Set destination address.
451 set_destination_address(Arm_address address
)
453 gold_assert(address
!= this->invalid_address
);
454 this->destination_address_
= address
;
457 // Reset destination address.
459 reset_destination_address()
460 { this->destination_address_
= this->invalid_address
; }
462 // Determine stub type for a branch of a relocation of R_TYPE going
463 // from BRANCH_ADDRESS to BRANCH_TARGET. If TARGET_IS_THUMB is set,
464 // the branch target is a thumb instruction. TARGET is used for look
465 // up ARM-specific linker settings.
467 stub_type_for_reloc(unsigned int r_type
, Arm_address branch_address
,
468 Arm_address branch_target
, bool target_is_thumb
);
470 // Reloc_stub key. A key is logically a triplet of a stub type, a symbol
471 // and an addend. Since we treat global and local symbol differently, we
472 // use a Symbol object for a global symbol and a object-index pair for
477 // If SYMBOL is not null, this is a global symbol, we ignore RELOBJ and
478 // R_SYM. Otherwise, this is a local symbol and RELOBJ must non-NULL
479 // and R_SYM must not be invalid_index.
480 Key(Stub_type stub_type
, const Symbol
* symbol
, const Relobj
* relobj
,
481 unsigned int r_sym
, int32_t addend
)
482 : stub_type_(stub_type
), addend_(addend
)
486 this->r_sym_
= Reloc_stub::invalid_index
;
487 this->u_
.symbol
= symbol
;
491 gold_assert(relobj
!= NULL
&& r_sym
!= invalid_index
);
492 this->r_sym_
= r_sym
;
493 this->u_
.relobj
= relobj
;
500 // Accessors: Keys are meant to be read-only object so no modifiers are
506 { return this->stub_type_
; }
508 // Return the local symbol index or invalid_index.
511 { return this->r_sym_
; }
513 // Return the symbol if there is one.
516 { return this->r_sym_
== invalid_index
? this->u_
.symbol
: NULL
; }
518 // Return the relobj if there is one.
521 { return this->r_sym_
!= invalid_index
? this->u_
.relobj
: NULL
; }
523 // Whether this equals to another key k.
525 eq(const Key
& k
) const
527 return ((this->stub_type_
== k
.stub_type_
)
528 && (this->r_sym_
== k
.r_sym_
)
529 && ((this->r_sym_
!= Reloc_stub::invalid_index
)
530 ? (this->u_
.relobj
== k
.u_
.relobj
)
531 : (this->u_
.symbol
== k
.u_
.symbol
))
532 && (this->addend_
== k
.addend_
));
535 // Return a hash value.
539 return (this->stub_type_
541 ^ gold::string_hash
<char>(
542 (this->r_sym_
!= Reloc_stub::invalid_index
)
543 ? this->u_
.relobj
->name().c_str()
544 : this->u_
.symbol
->name())
548 // Functors for STL associative containers.
552 operator()(const Key
& k
) const
553 { return k
.hash_value(); }
559 operator()(const Key
& k1
, const Key
& k2
) const
560 { return k1
.eq(k2
); }
563 // Name of key. This is mainly for debugging.
569 Stub_type stub_type_
;
570 // If this is a local symbol, this is the index in the defining object.
571 // Otherwise, it is invalid_index for a global symbol.
573 // If r_sym_ is invalid index. This points to a global symbol.
574 // Otherwise, this points a relobj. We used the unsized and target
575 // independent Symbol and Relobj classes instead of Sized_symbol<32> and
576 // Arm_relobj. This is done to avoid making the stub class a template
577 // as most of the stub machinery is endianity-neutral. However, it
578 // may require a bit of casting done by users of this class.
581 const Symbol
* symbol
;
582 const Relobj
* relobj
;
584 // Addend associated with a reloc.
589 // Reloc_stubs are created via a stub factory. So these are protected.
590 Reloc_stub(const Stub_template
* stub_template
)
591 : Stub(stub_template
), destination_address_(invalid_address
)
597 friend class Stub_factory
;
600 // Return the relocation target address of the i-th relocation in the
603 do_reloc_target(size_t i
)
605 // All reloc stub have only one relocation.
607 return this->destination_address_
;
610 // A template to implement do_write below.
611 template<bool big_endian
>
613 do_fixed_endian_write(unsigned char*, section_size_type
);
617 do_write(unsigned char* view
, section_size_type view_size
, bool big_endian
);
619 // Address of destination.
620 Arm_address destination_address_
;
623 // Stub factory class.
628 // Return the unique instance of this class.
629 static const Stub_factory
&
632 static Stub_factory singleton
;
636 // Make a relocation stub.
638 make_reloc_stub(Stub_type stub_type
) const
640 gold_assert(stub_type
>= arm_stub_reloc_first
641 && stub_type
<= arm_stub_reloc_last
);
642 return new Reloc_stub(this->stub_templates_
[stub_type
]);
646 // Constructor and destructor are protected since we only return a single
647 // instance created in Stub_factory::get_instance().
651 // A Stub_factory may not be copied since it is a singleton.
652 Stub_factory(const Stub_factory
&);
653 Stub_factory
& operator=(Stub_factory
&);
655 // Stub templates. These are initialized in the constructor.
656 const Stub_template
* stub_templates_
[arm_stub_type_last
+1];
659 // A class to hold stubs for the ARM target.
661 template<bool big_endian
>
662 class Stub_table
: public Output_data
665 Stub_table(Arm_input_section
<big_endian
>* owner
)
666 : Output_data(), addralign_(1), owner_(owner
), has_been_changed_(false),
673 // Owner of this stub table.
674 Arm_input_section
<big_endian
>*
676 { return this->owner_
; }
678 // Whether this stub table is empty.
681 { return this->reloc_stubs_
.empty(); }
683 // Whether this has been changed.
685 has_been_changed() const
686 { return this->has_been_changed_
; }
688 // Set the has-been-changed flag.
690 set_has_been_changed(bool value
)
691 { this->has_been_changed_
= value
; }
693 // Return the current data size.
695 current_data_size() const
696 { return this->current_data_size_for_child(); }
698 // Add a STUB with using KEY. Caller is reponsible for avoid adding
699 // if already a STUB with the same key has been added.
701 add_reloc_stub(Reloc_stub
* stub
, const Reloc_stub::Key
& key
);
703 // Look up a relocation stub using KEY. Return NULL if there is none.
705 find_reloc_stub(const Reloc_stub::Key
& key
) const
707 typename
Reloc_stub_map::const_iterator p
= this->reloc_stubs_
.find(key
);
708 return (p
!= this->reloc_stubs_
.end()) ? p
->second
: NULL
;
711 // Relocate stubs in this stub table.
713 relocate_stubs(const Relocate_info
<32, big_endian
>*,
714 Target_arm
<big_endian
>*, Output_section
*,
715 unsigned char*, Arm_address
, section_size_type
);
718 // Write out section contents.
720 do_write(Output_file
*);
722 // Return the required alignment.
725 { return this->addralign_
; }
727 // Finalize data size.
729 set_final_data_size()
730 { this->set_data_size(this->current_data_size_for_child()); }
732 // Reset address and file offset.
734 do_reset_address_and_file_offset();
737 // Unordered map of stubs.
739 Unordered_map
<Reloc_stub::Key
, Reloc_stub
*, Reloc_stub::Key::hash
,
740 Reloc_stub::Key::equal_to
>
745 // Owner of this stub table.
746 Arm_input_section
<big_endian
>* owner_
;
747 // This is set to true during relaxiong if the size of the stub table
749 bool has_been_changed_
;
750 // The relocation stubs.
751 Reloc_stub_map reloc_stubs_
;
754 // A class to wrap an ordinary input section containing executable code.
756 template<bool big_endian
>
757 class Arm_input_section
: public Output_relaxed_input_section
760 Arm_input_section(Relobj
* relobj
, unsigned int shndx
)
761 : Output_relaxed_input_section(relobj
, shndx
, 1),
762 original_addralign_(1), original_size_(0), stub_table_(NULL
)
772 // Whether this is a stub table owner.
774 is_stub_table_owner() const
775 { return this->stub_table_
!= NULL
&& this->stub_table_
->owner() == this; }
777 // Return the stub table.
778 Stub_table
<big_endian
>*
780 { return this->stub_table_
; }
782 // Set the stub_table.
784 set_stub_table(Stub_table
<big_endian
>* stub_table
)
785 { this->stub_table_
= stub_table
; }
787 // Downcast a base pointer to an Arm_input_section pointer. This is
788 // not type-safe but we only use Arm_input_section not the base class.
789 static Arm_input_section
<big_endian
>*
790 as_arm_input_section(Output_relaxed_input_section
* poris
)
791 { return static_cast<Arm_input_section
<big_endian
>*>(poris
); }
794 // Write data to output file.
796 do_write(Output_file
*);
798 // Return required alignment of this.
802 if (this->is_stub_table_owner())
803 return std::max(this->stub_table_
->addralign(),
804 this->original_addralign_
);
806 return this->original_addralign_
;
809 // Finalize data size.
811 set_final_data_size();
813 // Reset address and file offset.
815 do_reset_address_and_file_offset();
819 do_output_offset(const Relobj
* object
, unsigned int shndx
,
820 section_offset_type offset
,
821 section_offset_type
* poutput
) const
823 if ((object
== this->relobj())
824 && (shndx
== this->shndx())
826 && (convert_types
<uint64_t, section_offset_type
>(offset
)
827 <= this->original_size_
))
837 // Copying is not allowed.
838 Arm_input_section(const Arm_input_section
&);
839 Arm_input_section
& operator=(const Arm_input_section
&);
841 // Address alignment of the original input section.
842 uint64_t original_addralign_
;
843 // Section size of the original input section.
844 uint64_t original_size_
;
846 Stub_table
<big_endian
>* stub_table_
;
849 // Arm output section class. This is defined mainly to add a number of
850 // stub generation methods.
852 template<bool big_endian
>
853 class Arm_output_section
: public Output_section
856 Arm_output_section(const char* name
, elfcpp::Elf_Word type
,
857 elfcpp::Elf_Xword flags
)
858 : Output_section(name
, type
, flags
)
861 ~Arm_output_section()
864 // Group input sections for stub generation.
866 group_sections(section_size_type
, bool, Target_arm
<big_endian
>*);
868 // Downcast a base pointer to an Arm_output_section pointer. This is
869 // not type-safe but we only use Arm_output_section not the base class.
870 static Arm_output_section
<big_endian
>*
871 as_arm_output_section(Output_section
* os
)
872 { return static_cast<Arm_output_section
<big_endian
>*>(os
); }
876 typedef Output_section::Input_section Input_section
;
877 typedef Output_section::Input_section_list Input_section_list
;
879 // Create a stub group.
880 void create_stub_group(Input_section_list::const_iterator
,
881 Input_section_list::const_iterator
,
882 Input_section_list::const_iterator
,
883 Target_arm
<big_endian
>*,
884 std::vector
<Output_relaxed_input_section
*>*);
889 template<bool big_endian
>
890 class Arm_relobj
: public Sized_relobj
<32, big_endian
>
893 static const Arm_address invalid_address
= static_cast<Arm_address
>(-1);
895 Arm_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
896 const typename
elfcpp::Ehdr
<32, big_endian
>& ehdr
)
897 : Sized_relobj
<32, big_endian
>(name
, input_file
, offset
, ehdr
),
898 stub_tables_(), local_symbol_is_thumb_function_()
904 // Return the stub table of the SHNDX-th section if there is one.
905 Stub_table
<big_endian
>*
906 stub_table(unsigned int shndx
) const
908 gold_assert(shndx
< this->stub_tables_
.size());
909 return this->stub_tables_
[shndx
];
912 // Set STUB_TABLE to be the stub_table of the SHNDX-th section.
914 set_stub_table(unsigned int shndx
, Stub_table
<big_endian
>* stub_table
)
916 gold_assert(shndx
< this->stub_tables_
.size());
917 this->stub_tables_
[shndx
] = stub_table
;
920 // Whether a local symbol is a THUMB function. R_SYM is the symbol table
921 // index. This is only valid after do_count_local_symbol is called.
923 local_symbol_is_thumb_function(unsigned int r_sym
) const
925 gold_assert(r_sym
< this->local_symbol_is_thumb_function_
.size());
926 return this->local_symbol_is_thumb_function_
[r_sym
];
929 // Scan all relocation sections for stub generation.
931 scan_sections_for_stubs(Target_arm
<big_endian
>*, const Symbol_table
*,
934 // Convert regular input section with index SHNDX to a relaxed section.
936 convert_input_section_to_relaxed_section(unsigned shndx
)
938 // The stubs have relocations and we need to process them after writing
939 // out the stubs. So relocation now must follow section write.
940 this->invalidate_section_offset(shndx
);
941 this->set_relocs_must_follow_section_writes();
944 // Downcast a base pointer to an Arm_relobj pointer. This is
945 // not type-safe but we only use Arm_relobj not the base class.
946 static Arm_relobj
<big_endian
>*
947 as_arm_relobj(Relobj
* relobj
)
948 { return static_cast<Arm_relobj
<big_endian
>*>(relobj
); }
950 // Processor-specific flags in ELF file header. This is valid only after
953 processor_specific_flags() const
954 { return this->processor_specific_flags_
; }
957 // Post constructor setup.
961 // Call parent's setup method.
962 Sized_relobj
<32, big_endian
>::do_setup();
964 // Initialize look-up tables.
965 Stub_table_list
empty_stub_table_list(this->shnum(), NULL
);
966 this->stub_tables_
.swap(empty_stub_table_list
);
969 // Count the local symbols.
971 do_count_local_symbols(Stringpool_template
<char>*,
972 Stringpool_template
<char>*);
975 do_relocate_sections(const Symbol_table
* symtab
, const Layout
* layout
,
976 const unsigned char* pshdrs
,
977 typename Sized_relobj
<32, big_endian
>::Views
* pivews
);
979 // Read the symbol information.
981 do_read_symbols(Read_symbols_data
* sd
);
984 // List of stub tables.
985 typedef std::vector
<Stub_table
<big_endian
>*> Stub_table_list
;
986 Stub_table_list stub_tables_
;
987 // Bit vector to tell if a local symbol is a thumb function or not.
988 // This is only valid after do_count_local_symbol is called.
989 std::vector
<bool> local_symbol_is_thumb_function_
;
990 // processor-specific flags in ELF file header.
991 elfcpp::Elf_Word processor_specific_flags_
;
996 template<bool big_endian
>
997 class Arm_dynobj
: public Sized_dynobj
<32, big_endian
>
1000 Arm_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
1001 const elfcpp::Ehdr
<32, big_endian
>& ehdr
)
1002 : Sized_dynobj
<32, big_endian
>(name
, input_file
, offset
, ehdr
),
1003 processor_specific_flags_(0)
1009 // Downcast a base pointer to an Arm_relobj pointer. This is
1010 // not type-safe but we only use Arm_relobj not the base class.
1011 static Arm_dynobj
<big_endian
>*
1012 as_arm_dynobj(Dynobj
* dynobj
)
1013 { return static_cast<Arm_dynobj
<big_endian
>*>(dynobj
); }
1015 // Processor-specific flags in ELF file header. This is valid only after
1018 processor_specific_flags() const
1019 { return this->processor_specific_flags_
; }
1022 // Read the symbol information.
1024 do_read_symbols(Read_symbols_data
* sd
);
1027 // processor-specific flags in ELF file header.
1028 elfcpp::Elf_Word processor_specific_flags_
;
1031 // Functor to read reloc addends during stub generation.
1033 template<int sh_type
, bool big_endian
>
1034 struct Stub_addend_reader
1036 // Return the addend for a relocation of a particular type. Depending
1037 // on whether this is a REL or RELA relocation, read the addend from a
1038 // view or from a Reloc object.
1039 elfcpp::Elf_types
<32>::Elf_Swxword
1041 unsigned int /* r_type */,
1042 const unsigned char* /* view */,
1043 const typename Reloc_types
<sh_type
,
1044 32, big_endian
>::Reloc
& /* reloc */) const;
1047 // Specialized Stub_addend_reader for SHT_REL type relocation sections.
1049 template<bool big_endian
>
1050 struct Stub_addend_reader
<elfcpp::SHT_REL
, big_endian
>
1052 elfcpp::Elf_types
<32>::Elf_Swxword
1055 const unsigned char*,
1056 const typename Reloc_types
<elfcpp::SHT_REL
, 32, big_endian
>::Reloc
&) const;
1059 // Specialized Stub_addend_reader for RELA type relocation sections.
1060 // We currently do not handle RELA type relocation sections but it is trivial
1061 // to implement the addend reader. This is provided for completeness and to
1062 // make it easier to add support for RELA relocation sections in the future.
1064 template<bool big_endian
>
1065 struct Stub_addend_reader
<elfcpp::SHT_RELA
, big_endian
>
1067 elfcpp::Elf_types
<32>::Elf_Swxword
1070 const unsigned char*,
1071 const typename Reloc_types
<elfcpp::SHT_RELA
, 32,
1072 big_endian
>::Reloc
& reloc
) const
1073 { return reloc
.get_r_addend(); }
1076 // Utilities for manipulating integers of up to 32-bits
1080 // Sign extend an n-bit unsigned integer stored in an uint32_t into
1081 // an int32_t. NO_BITS must be between 1 to 32.
1082 template<int no_bits
>
1083 static inline int32_t
1084 sign_extend(uint32_t bits
)
1086 gold_assert(no_bits
>= 0 && no_bits
<= 32);
1088 return static_cast<int32_t>(bits
);
1089 uint32_t mask
= (~((uint32_t) 0)) >> (32 - no_bits
);
1091 uint32_t top_bit
= 1U << (no_bits
- 1);
1092 int32_t as_signed
= static_cast<int32_t>(bits
);
1093 return (bits
& top_bit
) ? as_signed
+ (-top_bit
* 2) : as_signed
;
1096 // Detects overflow of an NO_BITS integer stored in a uint32_t.
1097 template<int no_bits
>
1099 has_overflow(uint32_t bits
)
1101 gold_assert(no_bits
>= 0 && no_bits
<= 32);
1104 int32_t max
= (1 << (no_bits
- 1)) - 1;
1105 int32_t min
= -(1 << (no_bits
- 1));
1106 int32_t as_signed
= static_cast<int32_t>(bits
);
1107 return as_signed
> max
|| as_signed
< min
;
1110 // Detects overflow of an NO_BITS integer stored in a uint32_t when it
1111 // fits in the given number of bits as either a signed or unsigned value.
1112 // For example, has_signed_unsigned_overflow<8> would check
1113 // -128 <= bits <= 255
1114 template<int no_bits
>
1116 has_signed_unsigned_overflow(uint32_t bits
)
1118 gold_assert(no_bits
>= 2 && no_bits
<= 32);
1121 int32_t max
= static_cast<int32_t>((1U << no_bits
) - 1);
1122 int32_t min
= -(1 << (no_bits
- 1));
1123 int32_t as_signed
= static_cast<int32_t>(bits
);
1124 return as_signed
> max
|| as_signed
< min
;
1127 // Select bits from A and B using bits in MASK. For each n in [0..31],
1128 // the n-th bit in the result is chosen from the n-th bits of A and B.
1129 // A zero selects A and a one selects B.
1130 static inline uint32_t
1131 bit_select(uint32_t a
, uint32_t b
, uint32_t mask
)
1132 { return (a
& ~mask
) | (b
& mask
); }
1135 template<bool big_endian
>
1136 class Target_arm
: public Sized_target
<32, big_endian
>
1139 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, big_endian
>
1142 // When were are relocating a stub, we pass this as the relocation number.
1143 static const size_t fake_relnum_for_stubs
= static_cast<size_t>(-1);
1146 : Sized_target
<32, big_endian
>(&arm_info
),
1147 got_(NULL
), plt_(NULL
), got_plt_(NULL
), rel_dyn_(NULL
),
1148 copy_relocs_(elfcpp::R_ARM_COPY
), dynbss_(NULL
), stub_tables_(),
1149 stub_factory_(Stub_factory::get_instance()),
1150 may_use_blx_(true), should_force_pic_veneer_(false),
1151 arm_input_section_map_()
1154 // Whether we can use BLX.
1157 { return this->may_use_blx_
; }
1159 // Set use-BLX flag.
1161 set_may_use_blx(bool value
)
1162 { this->may_use_blx_
= value
; }
1164 // Whether we force PCI branch veneers.
1166 should_force_pic_veneer() const
1167 { return this->should_force_pic_veneer_
; }
1169 // Set PIC veneer flag.
1171 set_should_force_pic_veneer(bool value
)
1172 { this->should_force_pic_veneer_
= value
; }
1174 // Whether we use THUMB-2 instructions.
1176 using_thumb2() const
1178 // FIXME: This should not hard-coded.
1182 // Whether we use THUMB/THUMB-2 instructions only.
1184 using_thumb_only() const
1186 // FIXME: This should not hard-coded.
1190 // Process the relocations to determine unreferenced sections for
1191 // garbage collection.
1193 gc_process_relocs(Symbol_table
* symtab
,
1195 Sized_relobj
<32, big_endian
>* object
,
1196 unsigned int data_shndx
,
1197 unsigned int sh_type
,
1198 const unsigned char* prelocs
,
1200 Output_section
* output_section
,
1201 bool needs_special_offset_handling
,
1202 size_t local_symbol_count
,
1203 const unsigned char* plocal_symbols
);
1205 // Scan the relocations to look for symbol adjustments.
1207 scan_relocs(Symbol_table
* symtab
,
1209 Sized_relobj
<32, big_endian
>* object
,
1210 unsigned int data_shndx
,
1211 unsigned int sh_type
,
1212 const unsigned char* prelocs
,
1214 Output_section
* output_section
,
1215 bool needs_special_offset_handling
,
1216 size_t local_symbol_count
,
1217 const unsigned char* plocal_symbols
);
1219 // Finalize the sections.
1221 do_finalize_sections(Layout
*, const Input_objects
*);
1223 // Return the value to use for a dynamic symbol which requires special
1226 do_dynsym_value(const Symbol
*) const;
1228 // Relocate a section.
1230 relocate_section(const Relocate_info
<32, big_endian
>*,
1231 unsigned int sh_type
,
1232 const unsigned char* prelocs
,
1234 Output_section
* output_section
,
1235 bool needs_special_offset_handling
,
1236 unsigned char* view
,
1237 Arm_address view_address
,
1238 section_size_type view_size
,
1239 const Reloc_symbol_changes
*);
1241 // Scan the relocs during a relocatable link.
1243 scan_relocatable_relocs(Symbol_table
* symtab
,
1245 Sized_relobj
<32, big_endian
>* object
,
1246 unsigned int data_shndx
,
1247 unsigned int sh_type
,
1248 const unsigned char* prelocs
,
1250 Output_section
* output_section
,
1251 bool needs_special_offset_handling
,
1252 size_t local_symbol_count
,
1253 const unsigned char* plocal_symbols
,
1254 Relocatable_relocs
*);
1256 // Relocate a section during a relocatable link.
1258 relocate_for_relocatable(const Relocate_info
<32, big_endian
>*,
1259 unsigned int sh_type
,
1260 const unsigned char* prelocs
,
1262 Output_section
* output_section
,
1263 off_t offset_in_output_section
,
1264 const Relocatable_relocs
*,
1265 unsigned char* view
,
1266 Arm_address view_address
,
1267 section_size_type view_size
,
1268 unsigned char* reloc_view
,
1269 section_size_type reloc_view_size
);
1271 // Return whether SYM is defined by the ABI.
1273 do_is_defined_by_abi(Symbol
* sym
) const
1274 { return strcmp(sym
->name(), "__tls_get_addr") == 0; }
1276 // Return the size of the GOT section.
1280 gold_assert(this->got_
!= NULL
);
1281 return this->got_
->data_size();
1284 // Map platform-specific reloc types
1286 get_real_reloc_type (unsigned int r_type
);
1289 // Methods to support stub-generations.
1292 // Return the stub factory
1294 stub_factory() const
1295 { return this->stub_factory_
; }
1297 // Make a new Arm_input_section object.
1298 Arm_input_section
<big_endian
>*
1299 new_arm_input_section(Relobj
*, unsigned int);
1301 // Find the Arm_input_section object corresponding to the SHNDX-th input
1302 // section of RELOBJ.
1303 Arm_input_section
<big_endian
>*
1304 find_arm_input_section(Relobj
* relobj
, unsigned int shndx
) const;
1306 // Make a new Stub_table
1307 Stub_table
<big_endian
>*
1308 new_stub_table(Arm_input_section
<big_endian
>*);
1310 // Scan a section for stub generation.
1312 scan_section_for_stubs(const Relocate_info
<32, big_endian
>*, unsigned int,
1313 const unsigned char*, size_t, Output_section
*,
1314 bool, const unsigned char*, Arm_address
,
1319 relocate_stub(Reloc_stub
*, const Relocate_info
<32, big_endian
>*,
1320 Output_section
*, unsigned char*, Arm_address
,
1323 // Get the default ARM target.
1324 static Target_arm
<big_endian
>*
1327 gold_assert(parameters
->target().machine_code() == elfcpp::EM_ARM
1328 && parameters
->target().is_big_endian() == big_endian
);
1329 return static_cast<Target_arm
<big_endian
>*>(
1330 parameters
->sized_target
<32, big_endian
>());
1333 // Whether relocation type uses LSB to distinguish THUMB addresses.
1335 reloc_uses_thumb_bit(unsigned int r_type
);
1338 // Make an ELF object.
1340 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
1341 const elfcpp::Ehdr
<32, big_endian
>& ehdr
);
1344 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
1345 const elfcpp::Ehdr
<32, !big_endian
>&)
1346 { gold_unreachable(); }
1349 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
1350 const elfcpp::Ehdr
<64, false>&)
1351 { gold_unreachable(); }
1354 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
1355 const elfcpp::Ehdr
<64, true>&)
1356 { gold_unreachable(); }
1358 // Make an output section.
1360 do_make_output_section(const char* name
, elfcpp::Elf_Word type
,
1361 elfcpp::Elf_Xword flags
)
1362 { return new Arm_output_section
<big_endian
>(name
, type
, flags
); }
1365 do_adjust_elf_header(unsigned char* view
, int len
) const;
1367 // We only need to generate stubs, and hence perform relaxation if we are
1368 // not doing relocatable linking.
1370 do_may_relax() const
1371 { return !parameters
->options().relocatable(); }
1374 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*);
1377 // The class which scans relocations.
1382 : issued_non_pic_error_(false)
1386 local(Symbol_table
* symtab
, Layout
* layout
, Target_arm
* target
,
1387 Sized_relobj
<32, big_endian
>* object
,
1388 unsigned int data_shndx
,
1389 Output_section
* output_section
,
1390 const elfcpp::Rel
<32, big_endian
>& reloc
, unsigned int r_type
,
1391 const elfcpp::Sym
<32, big_endian
>& lsym
);
1394 global(Symbol_table
* symtab
, Layout
* layout
, Target_arm
* target
,
1395 Sized_relobj
<32, big_endian
>* object
,
1396 unsigned int data_shndx
,
1397 Output_section
* output_section
,
1398 const elfcpp::Rel
<32, big_endian
>& reloc
, unsigned int r_type
,
1403 unsupported_reloc_local(Sized_relobj
<32, big_endian
>*,
1404 unsigned int r_type
);
1407 unsupported_reloc_global(Sized_relobj
<32, big_endian
>*,
1408 unsigned int r_type
, Symbol
*);
1411 check_non_pic(Relobj
*, unsigned int r_type
);
1413 // Almost identical to Symbol::needs_plt_entry except that it also
1414 // handles STT_ARM_TFUNC.
1416 symbol_needs_plt_entry(const Symbol
* sym
)
1418 // An undefined symbol from an executable does not need a PLT entry.
1419 if (sym
->is_undefined() && !parameters
->options().shared())
1422 return (!parameters
->doing_static_link()
1423 && (sym
->type() == elfcpp::STT_FUNC
1424 || sym
->type() == elfcpp::STT_ARM_TFUNC
)
1425 && (sym
->is_from_dynobj()
1426 || sym
->is_undefined()
1427 || sym
->is_preemptible()));
1430 // Whether we have issued an error about a non-PIC compilation.
1431 bool issued_non_pic_error_
;
1434 // The class which implements relocation.
1444 // Return whether the static relocation needs to be applied.
1446 should_apply_static_reloc(const Sized_symbol
<32>* gsym
,
1449 Output_section
* output_section
);
1451 // Do a relocation. Return false if the caller should not issue
1452 // any warnings about this relocation.
1454 relocate(const Relocate_info
<32, big_endian
>*, Target_arm
*,
1455 Output_section
*, size_t relnum
,
1456 const elfcpp::Rel
<32, big_endian
>&,
1457 unsigned int r_type
, const Sized_symbol
<32>*,
1458 const Symbol_value
<32>*,
1459 unsigned char*, Arm_address
,
1462 // Return whether we want to pass flag NON_PIC_REF for this
1465 reloc_is_non_pic (unsigned int r_type
)
1469 case elfcpp::R_ARM_REL32
:
1470 case elfcpp::R_ARM_THM_CALL
:
1471 case elfcpp::R_ARM_CALL
:
1472 case elfcpp::R_ARM_JUMP24
:
1473 case elfcpp::R_ARM_PREL31
:
1474 case elfcpp::R_ARM_THM_ABS5
:
1475 case elfcpp::R_ARM_ABS8
:
1476 case elfcpp::R_ARM_ABS12
:
1477 case elfcpp::R_ARM_ABS16
:
1478 case elfcpp::R_ARM_BASE_ABS
:
1486 // A class which returns the size required for a relocation type,
1487 // used while scanning relocs during a relocatable link.
1488 class Relocatable_size_for_reloc
1492 get_size_for_reloc(unsigned int, Relobj
*);
1495 // Get the GOT section, creating it if necessary.
1496 Output_data_got
<32, big_endian
>*
1497 got_section(Symbol_table
*, Layout
*);
1499 // Get the GOT PLT section.
1501 got_plt_section() const
1503 gold_assert(this->got_plt_
!= NULL
);
1504 return this->got_plt_
;
1507 // Create a PLT entry for a global symbol.
1509 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1511 // Get the PLT section.
1512 const Output_data_plt_arm
<big_endian
>*
1515 gold_assert(this->plt_
!= NULL
);
1519 // Get the dynamic reloc section, creating it if necessary.
1521 rel_dyn_section(Layout
*);
1523 // Return true if the symbol may need a COPY relocation.
1524 // References from an executable object to non-function symbols
1525 // defined in a dynamic object may need a COPY relocation.
1527 may_need_copy_reloc(Symbol
* gsym
)
1529 return (gsym
->type() != elfcpp::STT_ARM_TFUNC
1530 && gsym
->may_need_copy_reloc());
1533 // Add a potential copy relocation.
1535 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1536 Sized_relobj
<32, big_endian
>* object
,
1537 unsigned int shndx
, Output_section
* output_section
,
1538 Symbol
* sym
, const elfcpp::Rel
<32, big_endian
>& reloc
)
1540 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1541 symtab
->get_sized_symbol
<32>(sym
),
1542 object
, shndx
, output_section
, reloc
,
1543 this->rel_dyn_section(layout
));
1546 // Whether two EABI versions are compatible.
1548 are_eabi_versions_compatible(elfcpp::Elf_Word v1
, elfcpp::Elf_Word v2
);
1550 // Merge processor-specific flags from input object and those in the ELF
1551 // header of the output.
1553 merge_processor_specific_flags(const std::string
&, elfcpp::Elf_Word
);
1556 // Methods to support stub-generations.
1559 // Group input sections for stub generation.
1561 group_sections(Layout
*, section_size_type
, bool);
1563 // Scan a relocation for stub generation.
1565 scan_reloc_for_stub(const Relocate_info
<32, big_endian
>*, unsigned int,
1566 const Sized_symbol
<32>*, unsigned int,
1567 const Symbol_value
<32>*,
1568 elfcpp::Elf_types
<32>::Elf_Swxword
, Arm_address
);
1570 // Scan a relocation section for stub.
1571 template<int sh_type
>
1573 scan_reloc_section_for_stubs(
1574 const Relocate_info
<32, big_endian
>* relinfo
,
1575 const unsigned char* prelocs
,
1577 Output_section
* output_section
,
1578 bool needs_special_offset_handling
,
1579 const unsigned char* view
,
1580 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
1583 // Information about this specific target which we pass to the
1584 // general Target structure.
1585 static const Target::Target_info arm_info
;
1587 // The types of GOT entries needed for this platform.
1590 GOT_TYPE_STANDARD
= 0 // GOT entry for a regular symbol
1593 typedef typename
std::vector
<Stub_table
<big_endian
>*> Stub_table_list
;
1595 // Map input section to Arm_input_section.
1596 typedef Unordered_map
<Input_section_specifier
,
1597 Arm_input_section
<big_endian
>*,
1598 Input_section_specifier::hash
,
1599 Input_section_specifier::equal_to
>
1600 Arm_input_section_map
;
1603 Output_data_got
<32, big_endian
>* got_
;
1605 Output_data_plt_arm
<big_endian
>* plt_
;
1606 // The GOT PLT section.
1607 Output_data_space
* got_plt_
;
1608 // The dynamic reloc section.
1609 Reloc_section
* rel_dyn_
;
1610 // Relocs saved to avoid a COPY reloc.
1611 Copy_relocs
<elfcpp::SHT_REL
, 32, big_endian
> copy_relocs_
;
1612 // Space for variables copied with a COPY reloc.
1613 Output_data_space
* dynbss_
;
1614 // Vector of Stub_tables created.
1615 Stub_table_list stub_tables_
;
1617 const Stub_factory
&stub_factory_
;
1618 // Whether we can use BLX.
1620 // Whether we force PIC branch veneers.
1621 bool should_force_pic_veneer_
;
1622 // Map for locating Arm_input_sections.
1623 Arm_input_section_map arm_input_section_map_
;
1626 template<bool big_endian
>
1627 const Target::Target_info Target_arm
<big_endian
>::arm_info
=
1630 big_endian
, // is_big_endian
1631 elfcpp::EM_ARM
, // machine_code
1632 false, // has_make_symbol
1633 false, // has_resolve
1634 false, // has_code_fill
1635 true, // is_default_stack_executable
1637 "/usr/lib/libc.so.1", // dynamic_linker
1638 0x8000, // default_text_segment_address
1639 0x1000, // abi_pagesize (overridable by -z max-page-size)
1640 0x1000, // common_pagesize (overridable by -z common-page-size)
1641 elfcpp::SHN_UNDEF
, // small_common_shndx
1642 elfcpp::SHN_UNDEF
, // large_common_shndx
1643 0, // small_common_section_flags
1644 0 // large_common_section_flags
1647 // Arm relocate functions class
1650 template<bool big_endian
>
1651 class Arm_relocate_functions
: public Relocate_functions
<32, big_endian
>
1656 STATUS_OKAY
, // No error during relocation.
1657 STATUS_OVERFLOW
, // Relocation oveflow.
1658 STATUS_BAD_RELOC
// Relocation cannot be applied.
1662 typedef Relocate_functions
<32, big_endian
> Base
;
1663 typedef Arm_relocate_functions
<big_endian
> This
;
1665 // Encoding of imm16 argument for movt and movw ARM instructions
1668 // imm16 := imm4 | imm12
1670 // f e d c b a 9 8 7 6 5 4 3 2 1 0 f e d c b a 9 8 7 6 5 4 3 2 1 0
1671 // +-------+---------------+-------+-------+-----------------------+
1672 // | | |imm4 | |imm12 |
1673 // +-------+---------------+-------+-------+-----------------------+
1675 // Extract the relocation addend from VAL based on the ARM
1676 // instruction encoding described above.
1677 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
1678 extract_arm_movw_movt_addend(
1679 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
)
1681 // According to the Elf ABI for ARM Architecture the immediate
1682 // field is sign-extended to form the addend.
1683 return utils::sign_extend
<16>(((val
>> 4) & 0xf000) | (val
& 0xfff));
1686 // Insert X into VAL based on the ARM instruction encoding described
1688 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
1689 insert_val_arm_movw_movt(
1690 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
,
1691 typename
elfcpp::Swap
<32, big_endian
>::Valtype x
)
1695 val
|= (x
& 0xf000) << 4;
1699 // Encoding of imm16 argument for movt and movw Thumb2 instructions
1702 // imm16 := imm4 | i | imm3 | imm8
1704 // f e d c b a 9 8 7 6 5 4 3 2 1 0 f e d c b a 9 8 7 6 5 4 3 2 1 0
1705 // +---------+-+-----------+-------++-+-----+-------+---------------+
1706 // | |i| |imm4 || |imm3 | |imm8 |
1707 // +---------+-+-----------+-------++-+-----+-------+---------------+
1709 // Extract the relocation addend from VAL based on the Thumb2
1710 // instruction encoding described above.
1711 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
1712 extract_thumb_movw_movt_addend(
1713 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
)
1715 // According to the Elf ABI for ARM Architecture the immediate
1716 // field is sign-extended to form the addend.
1717 return utils::sign_extend
<16>(((val
>> 4) & 0xf000)
1718 | ((val
>> 15) & 0x0800)
1719 | ((val
>> 4) & 0x0700)
1723 // Insert X into VAL based on the Thumb2 instruction encoding
1725 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
1726 insert_val_thumb_movw_movt(
1727 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
,
1728 typename
elfcpp::Swap
<32, big_endian
>::Valtype x
)
1731 val
|= (x
& 0xf000) << 4;
1732 val
|= (x
& 0x0800) << 15;
1733 val
|= (x
& 0x0700) << 4;
1734 val
|= (x
& 0x00ff);
1738 // FIXME: This probably only works for Android on ARM v5te. We should
1739 // following GNU ld for the general case.
1740 template<unsigned r_type
>
1741 static inline typename
This::Status
1742 arm_branch_common(unsigned char *view
,
1743 const Sized_relobj
<32, big_endian
>* object
,
1744 const Symbol_value
<32>* psymval
,
1745 Arm_address address
,
1746 Arm_address thumb_bit
)
1748 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
1749 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1750 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
1752 bool insn_is_b
= (((val
>> 28) & 0xf) <= 0xe)
1753 && ((val
& 0x0f000000UL
) == 0x0a000000UL
);
1754 bool insn_is_uncond_bl
= (val
& 0xff000000UL
) == 0xeb000000UL
;
1755 bool insn_is_cond_bl
= (((val
>> 28) & 0xf) < 0xe)
1756 && ((val
& 0x0f000000UL
) == 0x0b000000UL
);
1757 bool insn_is_blx
= (val
& 0xfe000000UL
) == 0xfa000000UL
;
1758 bool insn_is_any_branch
= (val
& 0x0e000000UL
) == 0x0a000000UL
;
1760 if (r_type
== elfcpp::R_ARM_CALL
)
1762 if (!insn_is_uncond_bl
&& !insn_is_blx
)
1763 return This::STATUS_BAD_RELOC
;
1765 else if (r_type
== elfcpp::R_ARM_JUMP24
)
1767 if (!insn_is_b
&& !insn_is_cond_bl
)
1768 return This::STATUS_BAD_RELOC
;
1770 else if (r_type
== elfcpp::R_ARM_PLT32
)
1772 if (!insn_is_any_branch
)
1773 return This::STATUS_BAD_RELOC
;
1778 Valtype addend
= utils::sign_extend
<26>(val
<< 2);
1779 Valtype x
= (psymval
->value(object
, addend
) | thumb_bit
) - address
;
1781 // If target has thumb bit set, we need to either turn the BL
1782 // into a BLX (for ARMv5 or above) or generate a stub.
1786 if (insn_is_uncond_bl
)
1787 val
= (val
& 0xffffff) | 0xfa000000 | ((x
& 2) << 23);
1789 return This::STATUS_BAD_RELOC
;
1792 gold_assert(!insn_is_blx
);
1794 val
= utils::bit_select(val
, (x
>> 2), 0xffffffUL
);
1795 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
1796 return (utils::has_overflow
<26>(x
)
1797 ? This::STATUS_OVERFLOW
: This::STATUS_OKAY
);
1802 // R_ARM_ABS8: S + A
1803 static inline typename
This::Status
1804 abs8(unsigned char *view
,
1805 const Sized_relobj
<32, big_endian
>* object
,
1806 const Symbol_value
<32>* psymval
)
1808 typedef typename
elfcpp::Swap
<8, big_endian
>::Valtype Valtype
;
1809 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
1810 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1811 Valtype val
= elfcpp::Swap
<8, big_endian
>::readval(wv
);
1812 Reltype addend
= utils::sign_extend
<8>(val
);
1813 Reltype x
= psymval
->value(object
, addend
);
1814 val
= utils::bit_select(val
, x
, 0xffU
);
1815 elfcpp::Swap
<8, big_endian
>::writeval(wv
, val
);
1816 return (utils::has_signed_unsigned_overflow
<8>(x
)
1817 ? This::STATUS_OVERFLOW
1818 : This::STATUS_OKAY
);
1821 // R_ARM_THM_ABS5: S + A
1822 static inline typename
This::Status
1823 thm_abs5(unsigned char *view
,
1824 const Sized_relobj
<32, big_endian
>* object
,
1825 const Symbol_value
<32>* psymval
)
1827 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
1828 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
1829 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1830 Valtype val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
1831 Reltype addend
= (val
& 0x7e0U
) >> 6;
1832 Reltype x
= psymval
->value(object
, addend
);
1833 val
= utils::bit_select(val
, x
<< 6, 0x7e0U
);
1834 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
1835 return (utils::has_overflow
<5>(x
)
1836 ? This::STATUS_OVERFLOW
1837 : This::STATUS_OKAY
);
1840 // R_ARM_ABS12: S + A
1841 static inline typename
This::Status
1842 abs12(unsigned char *view
,
1843 const Sized_relobj
<32, big_endian
>* object
,
1844 const Symbol_value
<32>* psymval
)
1846 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
1847 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
1848 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1849 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
1850 Reltype addend
= val
& 0x0fffU
;
1851 Reltype x
= psymval
->value(object
, addend
);
1852 val
= utils::bit_select(val
, x
, 0x0fffU
);
1853 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
1854 return (utils::has_overflow
<12>(x
)
1855 ? This::STATUS_OVERFLOW
1856 : This::STATUS_OKAY
);
1859 // R_ARM_ABS16: S + A
1860 static inline typename
This::Status
1861 abs16(unsigned char *view
,
1862 const Sized_relobj
<32, big_endian
>* object
,
1863 const Symbol_value
<32>* psymval
)
1865 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
1866 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
1867 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1868 Valtype val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
1869 Reltype addend
= utils::sign_extend
<16>(val
);
1870 Reltype x
= psymval
->value(object
, addend
);
1871 val
= utils::bit_select(val
, x
, 0xffffU
);
1872 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
1873 return (utils::has_signed_unsigned_overflow
<16>(x
)
1874 ? This::STATUS_OVERFLOW
1875 : This::STATUS_OKAY
);
1878 // R_ARM_ABS32: (S + A) | T
1879 static inline typename
This::Status
1880 abs32(unsigned char *view
,
1881 const Sized_relobj
<32, big_endian
>* object
,
1882 const Symbol_value
<32>* psymval
,
1883 Arm_address thumb_bit
)
1885 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
1886 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1887 Valtype addend
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
1888 Valtype x
= psymval
->value(object
, addend
) | thumb_bit
;
1889 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
1890 return This::STATUS_OKAY
;
1893 // R_ARM_REL32: (S + A) | T - P
1894 static inline typename
This::Status
1895 rel32(unsigned char *view
,
1896 const Sized_relobj
<32, big_endian
>* object
,
1897 const Symbol_value
<32>* psymval
,
1898 Arm_address address
,
1899 Arm_address thumb_bit
)
1901 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
1902 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1903 Valtype addend
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
1904 Valtype x
= (psymval
->value(object
, addend
) | thumb_bit
) - address
;
1905 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
1906 return This::STATUS_OKAY
;
1909 // R_ARM_THM_CALL: (S + A) | T - P
1910 static inline typename
This::Status
1911 thm_call(unsigned char *view
,
1912 const Sized_relobj
<32, big_endian
>* object
,
1913 const Symbol_value
<32>* psymval
,
1914 Arm_address address
,
1915 Arm_address thumb_bit
)
1917 // A thumb call consists of two instructions.
1918 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
1919 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
1920 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1921 Valtype hi
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
1922 Valtype lo
= elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
1923 // Must be a BL instruction. lo == 11111xxxxxxxxxxx.
1924 gold_assert((lo
& 0xf800) == 0xf800);
1925 Reltype addend
= utils::sign_extend
<23>(((hi
& 0x7ff) << 12)
1926 | ((lo
& 0x7ff) << 1));
1927 Reltype x
= (psymval
->value(object
, addend
) | thumb_bit
) - address
;
1929 // If target has no thumb bit set, we need to either turn the BL
1930 // into a BLX (for ARMv5 or above) or generate a stub.
1933 // This only works for ARMv5 and above with interworking enabled.
1936 hi
= utils::bit_select(hi
, (x
>> 12), 0x7ffU
);
1937 lo
= utils::bit_select(lo
, (x
>> 1), 0x7ffU
);
1938 elfcpp::Swap
<16, big_endian
>::writeval(wv
, hi
);
1939 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, lo
);
1940 return (utils::has_overflow
<23>(x
)
1941 ? This::STATUS_OVERFLOW
1942 : This::STATUS_OKAY
);
1945 // R_ARM_BASE_PREL: B(S) + A - P
1946 static inline typename
This::Status
1947 base_prel(unsigned char* view
,
1949 Arm_address address
)
1951 Base::rel32(view
, origin
- address
);
1955 // R_ARM_BASE_ABS: B(S) + A
1956 static inline typename
This::Status
1957 base_abs(unsigned char* view
,
1960 Base::rel32(view
, origin
);
1964 // R_ARM_GOT_BREL: GOT(S) + A - GOT_ORG
1965 static inline typename
This::Status
1966 got_brel(unsigned char* view
,
1967 typename
elfcpp::Swap
<32, big_endian
>::Valtype got_offset
)
1969 Base::rel32(view
, got_offset
);
1970 return This::STATUS_OKAY
;
1973 // R_ARM_GOT_PREL: GOT(S) + A – P
1974 static inline typename
This::Status
1975 got_prel(unsigned char* view
,
1976 typename
elfcpp::Swap
<32, big_endian
>::Valtype got_offset
,
1977 Arm_address address
)
1979 Base::rel32(view
, got_offset
- address
);
1980 return This::STATUS_OKAY
;
1983 // R_ARM_PLT32: (S + A) | T - P
1984 static inline typename
This::Status
1985 plt32(unsigned char *view
,
1986 const Sized_relobj
<32, big_endian
>* object
,
1987 const Symbol_value
<32>* psymval
,
1988 Arm_address address
,
1989 Arm_address thumb_bit
)
1991 return arm_branch_common
<elfcpp::R_ARM_PLT32
>(view
, object
, psymval
,
1992 address
, thumb_bit
);
1995 // R_ARM_CALL: (S + A) | T - P
1996 static inline typename
This::Status
1997 call(unsigned char *view
,
1998 const Sized_relobj
<32, big_endian
>* object
,
1999 const Symbol_value
<32>* psymval
,
2000 Arm_address address
,
2001 Arm_address thumb_bit
)
2003 return arm_branch_common
<elfcpp::R_ARM_CALL
>(view
, object
, psymval
,
2004 address
, thumb_bit
);
2007 // R_ARM_JUMP24: (S + A) | T - P
2008 static inline typename
This::Status
2009 jump24(unsigned char *view
,
2010 const Sized_relobj
<32, big_endian
>* object
,
2011 const Symbol_value
<32>* psymval
,
2012 Arm_address address
,
2013 Arm_address thumb_bit
)
2015 return arm_branch_common
<elfcpp::R_ARM_JUMP24
>(view
, object
, psymval
,
2016 address
, thumb_bit
);
2019 // R_ARM_PREL: (S + A) | T - P
2020 static inline typename
This::Status
2021 prel31(unsigned char *view
,
2022 const Sized_relobj
<32, big_endian
>* object
,
2023 const Symbol_value
<32>* psymval
,
2024 Arm_address address
,
2025 Arm_address thumb_bit
)
2027 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2028 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2029 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2030 Valtype addend
= utils::sign_extend
<31>(val
);
2031 Valtype x
= (psymval
->value(object
, addend
) | thumb_bit
) - address
;
2032 val
= utils::bit_select(val
, x
, 0x7fffffffU
);
2033 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2034 return (utils::has_overflow
<31>(x
) ?
2035 This::STATUS_OVERFLOW
: This::STATUS_OKAY
);
2038 // R_ARM_MOVW_ABS_NC: (S + A) | T
2039 static inline typename
This::Status
2040 movw_abs_nc(unsigned char *view
,
2041 const Sized_relobj
<32, big_endian
>* object
,
2042 const Symbol_value
<32>* psymval
,
2043 Arm_address thumb_bit
)
2045 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2046 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2047 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2048 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
2049 Valtype x
= psymval
->value(object
, addend
) | thumb_bit
;
2050 val
= This::insert_val_arm_movw_movt(val
, x
);
2051 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2052 return This::STATUS_OKAY
;
2055 // R_ARM_MOVT_ABS: S + A
2056 static inline typename
This::Status
2057 movt_abs(unsigned char *view
,
2058 const Sized_relobj
<32, big_endian
>* object
,
2059 const Symbol_value
<32>* psymval
)
2061 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2062 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2063 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2064 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
2065 Valtype x
= psymval
->value(object
, addend
) >> 16;
2066 val
= This::insert_val_arm_movw_movt(val
, x
);
2067 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2068 return This::STATUS_OKAY
;
2071 // R_ARM_THM_MOVW_ABS_NC: S + A | T
2072 static inline typename
This::Status
2073 thm_movw_abs_nc(unsigned char *view
,
2074 const Sized_relobj
<32, big_endian
>* object
,
2075 const Symbol_value
<32>* psymval
,
2076 Arm_address thumb_bit
)
2078 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
2079 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
2080 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2081 Reltype val
= ((elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
2082 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1));
2083 Reltype addend
= extract_thumb_movw_movt_addend(val
);
2084 Reltype x
= psymval
->value(object
, addend
) | thumb_bit
;
2085 val
= This::insert_val_thumb_movw_movt(val
, x
);
2086 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
2087 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
2088 return This::STATUS_OKAY
;
2091 // R_ARM_THM_MOVT_ABS: S + A
2092 static inline typename
This::Status
2093 thm_movt_abs(unsigned char *view
,
2094 const Sized_relobj
<32, big_endian
>* object
,
2095 const Symbol_value
<32>* psymval
)
2097 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
2098 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
2099 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2100 Reltype val
= ((elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
2101 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1));
2102 Reltype addend
= This::extract_thumb_movw_movt_addend(val
);
2103 Reltype x
= psymval
->value(object
, addend
) >> 16;
2104 val
= This::insert_val_thumb_movw_movt(val
, x
);
2105 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
2106 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
2107 return This::STATUS_OKAY
;
2110 // R_ARM_MOVW_PREL_NC: (S + A) | T - P
2111 static inline typename
This::Status
2112 movw_prel_nc(unsigned char *view
,
2113 const Sized_relobj
<32, big_endian
>* object
,
2114 const Symbol_value
<32>* psymval
,
2115 Arm_address address
,
2116 Arm_address thumb_bit
)
2118 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2119 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2120 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2121 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
2122 Valtype x
= (psymval
->value(object
, addend
) | thumb_bit
) - address
;
2123 val
= This::insert_val_arm_movw_movt(val
, x
);
2124 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2125 return This::STATUS_OKAY
;
2128 // R_ARM_MOVT_PREL: S + A - P
2129 static inline typename
This::Status
2130 movt_prel(unsigned char *view
,
2131 const Sized_relobj
<32, big_endian
>* object
,
2132 const Symbol_value
<32>* psymval
,
2133 Arm_address address
)
2135 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2136 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2137 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2138 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
2139 Valtype x
= (psymval
->value(object
, addend
) - address
) >> 16;
2140 val
= This::insert_val_arm_movw_movt(val
, x
);
2141 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2142 return This::STATUS_OKAY
;
2145 // R_ARM_THM_MOVW_PREL_NC: (S + A) | T - P
2146 static inline typename
This::Status
2147 thm_movw_prel_nc(unsigned char *view
,
2148 const Sized_relobj
<32, big_endian
>* object
,
2149 const Symbol_value
<32>* psymval
,
2150 Arm_address address
,
2151 Arm_address thumb_bit
)
2153 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
2154 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
2155 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2156 Reltype val
= (elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
2157 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
2158 Reltype addend
= This::extract_thumb_movw_movt_addend(val
);
2159 Reltype x
= (psymval
->value(object
, addend
) | thumb_bit
) - address
;
2160 val
= This::insert_val_thumb_movw_movt(val
, x
);
2161 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
2162 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
2163 return This::STATUS_OKAY
;
2166 // R_ARM_THM_MOVT_PREL: S + A - P
2167 static inline typename
This::Status
2168 thm_movt_prel(unsigned char *view
,
2169 const Sized_relobj
<32, big_endian
>* object
,
2170 const Symbol_value
<32>* psymval
,
2171 Arm_address address
)
2173 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
2174 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
2175 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2176 Reltype val
= (elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
2177 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
2178 Reltype addend
= This::extract_thumb_movw_movt_addend(val
);
2179 Reltype x
= (psymval
->value(object
, addend
) - address
) >> 16;
2180 val
= This::insert_val_thumb_movw_movt(val
, x
);
2181 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
2182 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
2183 return This::STATUS_OKAY
;
2187 // Get the GOT section, creating it if necessary.
2189 template<bool big_endian
>
2190 Output_data_got
<32, big_endian
>*
2191 Target_arm
<big_endian
>::got_section(Symbol_table
* symtab
, Layout
* layout
)
2193 if (this->got_
== NULL
)
2195 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
2197 this->got_
= new Output_data_got
<32, big_endian
>();
2200 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
2202 | elfcpp::SHF_WRITE
),
2206 // The old GNU linker creates a .got.plt section. We just
2207 // create another set of data in the .got section. Note that we
2208 // always create a PLT if we create a GOT, although the PLT
2210 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
2211 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
2213 | elfcpp::SHF_WRITE
),
2214 this->got_plt_
, false);
2217 // The first three entries are reserved.
2218 this->got_plt_
->set_current_data_size(3 * 4);
2220 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
2221 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2223 0, 0, elfcpp::STT_OBJECT
,
2225 elfcpp::STV_HIDDEN
, 0,
2231 // Get the dynamic reloc section, creating it if necessary.
2233 template<bool big_endian
>
2234 typename Target_arm
<big_endian
>::Reloc_section
*
2235 Target_arm
<big_endian
>::rel_dyn_section(Layout
* layout
)
2237 if (this->rel_dyn_
== NULL
)
2239 gold_assert(layout
!= NULL
);
2240 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
2241 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
2242 elfcpp::SHF_ALLOC
, this->rel_dyn_
, true);
2244 return this->rel_dyn_
;
2247 // Insn_template methods.
2249 // Return byte size of an instruction template.
2252 Insn_template::size() const
2254 switch (this->type())
2267 // Return alignment of an instruction template.
2270 Insn_template::alignment() const
2272 switch (this->type())
2285 // Stub_template methods.
2287 Stub_template::Stub_template(
2288 Stub_type type
, const Insn_template
* insns
,
2290 : type_(type
), insns_(insns
), insn_count_(insn_count
), alignment_(1),
2291 entry_in_thumb_mode_(false), relocs_()
2295 // Compute byte size and alignment of stub template.
2296 for (size_t i
= 0; i
< insn_count
; i
++)
2298 unsigned insn_alignment
= insns
[i
].alignment();
2299 size_t insn_size
= insns
[i
].size();
2300 gold_assert((offset
& (insn_alignment
- 1)) == 0);
2301 this->alignment_
= std::max(this->alignment_
, insn_alignment
);
2302 switch (insns
[i
].type())
2304 case Insn_template::THUMB16_TYPE
:
2306 this->entry_in_thumb_mode_
= true;
2309 case Insn_template::THUMB32_TYPE
:
2310 if (insns
[i
].r_type() != elfcpp::R_ARM_NONE
)
2311 this->relocs_
.push_back(Reloc(i
, offset
));
2313 this->entry_in_thumb_mode_
= true;
2316 case Insn_template::ARM_TYPE
:
2317 // Handle cases where the target is encoded within the
2319 if (insns
[i
].r_type() == elfcpp::R_ARM_JUMP24
)
2320 this->relocs_
.push_back(Reloc(i
, offset
));
2323 case Insn_template::DATA_TYPE
:
2324 // Entry point cannot be data.
2325 gold_assert(i
!= 0);
2326 this->relocs_
.push_back(Reloc(i
, offset
));
2332 offset
+= insn_size
;
2334 this->size_
= offset
;
2337 // Reloc_stub::Key methods.
2339 // Dump a Key as a string for debugging.
2342 Reloc_stub::Key::name() const
2344 if (this->r_sym_
== invalid_index
)
2346 // Global symbol key name
2347 // <stub-type>:<symbol name>:<addend>.
2348 const std::string sym_name
= this->u_
.symbol
->name();
2349 // We need to print two hex number and two colons. So just add 100 bytes
2350 // to the symbol name size.
2351 size_t len
= sym_name
.size() + 100;
2352 char* buffer
= new char[len
];
2353 int c
= snprintf(buffer
, len
, "%d:%s:%x", this->stub_type_
,
2354 sym_name
.c_str(), this->addend_
);
2355 gold_assert(c
> 0 && c
< static_cast<int>(len
));
2357 return std::string(buffer
);
2361 // local symbol key name
2362 // <stub-type>:<object>:<r_sym>:<addend>.
2363 const size_t len
= 200;
2365 int c
= snprintf(buffer
, len
, "%d:%p:%u:%x", this->stub_type_
,
2366 this->u_
.relobj
, this->r_sym_
, this->addend_
);
2367 gold_assert(c
> 0 && c
< static_cast<int>(len
));
2368 return std::string(buffer
);
2372 // Reloc_stub methods.
2374 // Determine the type of stub needed, if any, for a relocation of R_TYPE at
2375 // LOCATION to DESTINATION.
2376 // This code is based on the arm_type_of_stub function in
2377 // bfd/elf32-arm.c. We have changed the interface a liitle to keep the Stub
2381 Reloc_stub::stub_type_for_reloc(
2382 unsigned int r_type
,
2383 Arm_address location
,
2384 Arm_address destination
,
2385 bool target_is_thumb
)
2387 Stub_type stub_type
= arm_stub_none
;
2389 // This is a bit ugly but we want to avoid using a templated class for
2390 // big and little endianities.
2392 bool should_force_pic_veneer
;
2395 if (parameters
->target().is_big_endian())
2397 const Target_arm
<true>* big_endian_target
=
2398 Target_arm
<true>::default_target();
2399 may_use_blx
= big_endian_target
->may_use_blx();
2400 should_force_pic_veneer
= big_endian_target
->should_force_pic_veneer();
2401 thumb2
= big_endian_target
->using_thumb2();
2402 thumb_only
= big_endian_target
->using_thumb_only();
2406 const Target_arm
<false>* little_endian_target
=
2407 Target_arm
<false>::default_target();
2408 may_use_blx
= little_endian_target
->may_use_blx();
2409 should_force_pic_veneer
= little_endian_target
->should_force_pic_veneer();
2410 thumb2
= little_endian_target
->using_thumb2();
2411 thumb_only
= little_endian_target
->using_thumb_only();
2414 int64_t branch_offset
= (int64_t)destination
- location
;
2416 if (r_type
== elfcpp::R_ARM_THM_CALL
|| r_type
== elfcpp::R_ARM_THM_JUMP24
)
2418 // Handle cases where:
2419 // - this call goes too far (different Thumb/Thumb2 max
2421 // - it's a Thumb->Arm call and blx is not available, or it's a
2422 // Thumb->Arm branch (not bl). A stub is needed in this case.
2424 && (branch_offset
> THM_MAX_FWD_BRANCH_OFFSET
2425 || (branch_offset
< THM_MAX_BWD_BRANCH_OFFSET
)))
2427 && (branch_offset
> THM2_MAX_FWD_BRANCH_OFFSET
2428 || (branch_offset
< THM2_MAX_BWD_BRANCH_OFFSET
)))
2429 || ((!target_is_thumb
)
2430 && (((r_type
== elfcpp::R_ARM_THM_CALL
) && !may_use_blx
)
2431 || (r_type
== elfcpp::R_ARM_THM_JUMP24
))))
2433 if (target_is_thumb
)
2438 stub_type
= (parameters
->options().shared() | should_force_pic_veneer
)
2441 && (r_type
== elfcpp::R_ARM_THM_CALL
))
2442 // V5T and above. Stub starts with ARM code, so
2443 // we must be able to switch mode before
2444 // reaching it, which is only possible for 'bl'
2445 // (ie R_ARM_THM_CALL relocation).
2446 ? arm_stub_long_branch_any_thumb_pic
2447 // On V4T, use Thumb code only.
2448 : arm_stub_long_branch_v4t_thumb_thumb_pic
)
2452 && (r_type
== elfcpp::R_ARM_THM_CALL
))
2453 ? arm_stub_long_branch_any_any
// V5T and above.
2454 : arm_stub_long_branch_v4t_thumb_thumb
); // V4T.
2458 stub_type
= (parameters
->options().shared() | should_force_pic_veneer
)
2459 ? arm_stub_long_branch_thumb_only_pic
// PIC stub.
2460 : arm_stub_long_branch_thumb_only
; // non-PIC stub.
2467 // FIXME: We should check that the input section is from an
2468 // object that has interwork enabled.
2470 stub_type
= (parameters
->options().shared()
2471 || should_force_pic_veneer
)
2474 && (r_type
== elfcpp::R_ARM_THM_CALL
))
2475 ? arm_stub_long_branch_any_arm_pic
// V5T and above.
2476 : arm_stub_long_branch_v4t_thumb_arm_pic
) // V4T.
2480 && (r_type
== elfcpp::R_ARM_THM_CALL
))
2481 ? arm_stub_long_branch_any_any
// V5T and above.
2482 : arm_stub_long_branch_v4t_thumb_arm
); // V4T.
2484 // Handle v4t short branches.
2485 if ((stub_type
== arm_stub_long_branch_v4t_thumb_arm
)
2486 && (branch_offset
<= THM_MAX_FWD_BRANCH_OFFSET
)
2487 && (branch_offset
>= THM_MAX_BWD_BRANCH_OFFSET
))
2488 stub_type
= arm_stub_short_branch_v4t_thumb_arm
;
2492 else if (r_type
== elfcpp::R_ARM_CALL
2493 || r_type
== elfcpp::R_ARM_JUMP24
2494 || r_type
== elfcpp::R_ARM_PLT32
)
2496 if (target_is_thumb
)
2500 // FIXME: We should check that the input section is from an
2501 // object that has interwork enabled.
2503 // We have an extra 2-bytes reach because of
2504 // the mode change (bit 24 (H) of BLX encoding).
2505 if (branch_offset
> (ARM_MAX_FWD_BRANCH_OFFSET
+ 2)
2506 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
)
2507 || ((r_type
== elfcpp::R_ARM_CALL
) && !may_use_blx
)
2508 || (r_type
== elfcpp::R_ARM_JUMP24
)
2509 || (r_type
== elfcpp::R_ARM_PLT32
))
2511 stub_type
= (parameters
->options().shared()
2512 || should_force_pic_veneer
)
2515 ? arm_stub_long_branch_any_thumb_pic
// V5T and above.
2516 : arm_stub_long_branch_v4t_arm_thumb_pic
) // V4T stub.
2520 ? arm_stub_long_branch_any_any
// V5T and above.
2521 : arm_stub_long_branch_v4t_arm_thumb
); // V4T.
2527 if (branch_offset
> ARM_MAX_FWD_BRANCH_OFFSET
2528 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
))
2530 stub_type
= (parameters
->options().shared()
2531 || should_force_pic_veneer
)
2532 ? arm_stub_long_branch_any_arm_pic
// PIC stubs.
2533 : arm_stub_long_branch_any_any
; /// non-PIC.
2541 // Template to implement do_write for a specific target endianity.
2543 template<bool big_endian
>
2545 Reloc_stub::do_fixed_endian_write(unsigned char* view
,
2546 section_size_type view_size
)
2548 const Stub_template
* stub_template
= this->stub_template();
2549 const Insn_template
* insns
= stub_template
->insns();
2551 // FIXME: We do not handle BE8 encoding yet.
2552 unsigned char* pov
= view
;
2553 for (size_t i
= 0; i
< stub_template
->insn_count(); i
++)
2555 switch (insns
[i
].type())
2557 case Insn_template::THUMB16_TYPE
:
2558 // Non-zero reloc addends are only used in Cortex-A8 stubs.
2559 gold_assert(insns
[i
].reloc_addend() == 0);
2560 elfcpp::Swap
<16, big_endian
>::writeval(pov
, insns
[i
].data() & 0xffff);
2562 case Insn_template::THUMB32_TYPE
:
2564 uint32_t hi
= (insns
[i
].data() >> 16) & 0xffff;
2565 uint32_t lo
= insns
[i
].data() & 0xffff;
2566 elfcpp::Swap
<16, big_endian
>::writeval(pov
, hi
);
2567 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lo
);
2570 case Insn_template::ARM_TYPE
:
2571 case Insn_template::DATA_TYPE
:
2572 elfcpp::Swap
<32, big_endian
>::writeval(pov
, insns
[i
].data());
2577 pov
+= insns
[i
].size();
2579 gold_assert(static_cast<section_size_type
>(pov
- view
) == view_size
);
2582 // Write a reloc stub to VIEW with endianity specified by BIG_ENDIAN.
2585 Reloc_stub::do_write(unsigned char* view
, section_size_type view_size
,
2589 this->do_fixed_endian_write
<true>(view
, view_size
);
2591 this->do_fixed_endian_write
<false>(view
, view_size
);
2594 // Stub_factory methods.
2596 Stub_factory::Stub_factory()
2598 // The instruction template sequences are declared as static
2599 // objects and initialized first time the constructor runs.
2601 // Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
2602 // to reach the stub if necessary.
2603 static const Insn_template elf32_arm_stub_long_branch_any_any
[] =
2605 Insn_template::arm_insn(0xe51ff004), // ldr pc, [pc, #-4]
2606 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
2607 // dcd R_ARM_ABS32(X)
2610 // V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
2612 static const Insn_template elf32_arm_stub_long_branch_v4t_arm_thumb
[] =
2614 Insn_template::arm_insn(0xe59fc000), // ldr ip, [pc, #0]
2615 Insn_template::arm_insn(0xe12fff1c), // bx ip
2616 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
2617 // dcd R_ARM_ABS32(X)
2620 // Thumb -> Thumb long branch stub. Used on M-profile architectures.
2621 static const Insn_template elf32_arm_stub_long_branch_thumb_only
[] =
2623 Insn_template::thumb16_insn(0xb401), // push {r0}
2624 Insn_template::thumb16_insn(0x4802), // ldr r0, [pc, #8]
2625 Insn_template::thumb16_insn(0x4684), // mov ip, r0
2626 Insn_template::thumb16_insn(0xbc01), // pop {r0}
2627 Insn_template::thumb16_insn(0x4760), // bx ip
2628 Insn_template::thumb16_insn(0xbf00), // nop
2629 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
2630 // dcd R_ARM_ABS32(X)
2633 // V4T Thumb -> Thumb long branch stub. Using the stack is not
2635 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_thumb
[] =
2637 Insn_template::thumb16_insn(0x4778), // bx pc
2638 Insn_template::thumb16_insn(0x46c0), // nop
2639 Insn_template::arm_insn(0xe59fc000), // ldr ip, [pc, #0]
2640 Insn_template::arm_insn(0xe12fff1c), // bx ip
2641 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
2642 // dcd R_ARM_ABS32(X)
2645 // V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
2647 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_arm
[] =
2649 Insn_template::thumb16_insn(0x4778), // bx pc
2650 Insn_template::thumb16_insn(0x46c0), // nop
2651 Insn_template::arm_insn(0xe51ff004), // ldr pc, [pc, #-4]
2652 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
2653 // dcd R_ARM_ABS32(X)
2656 // V4T Thumb -> ARM short branch stub. Shorter variant of the above
2657 // one, when the destination is close enough.
2658 static const Insn_template elf32_arm_stub_short_branch_v4t_thumb_arm
[] =
2660 Insn_template::thumb16_insn(0x4778), // bx pc
2661 Insn_template::thumb16_insn(0x46c0), // nop
2662 Insn_template::arm_rel_insn(0xea000000, -8), // b (X-8)
2665 // ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
2666 // blx to reach the stub if necessary.
2667 static const Insn_template elf32_arm_stub_long_branch_any_arm_pic
[] =
2669 Insn_template::arm_insn(0xe59fc000), // ldr r12, [pc]
2670 Insn_template::arm_insn(0xe08ff00c), // add pc, pc, ip
2671 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, -4),
2672 // dcd R_ARM_REL32(X-4)
2675 // ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
2676 // blx to reach the stub if necessary. We can not add into pc;
2677 // it is not guaranteed to mode switch (different in ARMv6 and
2679 static const Insn_template elf32_arm_stub_long_branch_any_thumb_pic
[] =
2681 Insn_template::arm_insn(0xe59fc004), // ldr r12, [pc, #4]
2682 Insn_template::arm_insn(0xe08fc00c), // add ip, pc, ip
2683 Insn_template::arm_insn(0xe12fff1c), // bx ip
2684 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, 0),
2685 // dcd R_ARM_REL32(X)
2688 // V4T ARM -> ARM long branch stub, PIC.
2689 static const Insn_template elf32_arm_stub_long_branch_v4t_arm_thumb_pic
[] =
2691 Insn_template::arm_insn(0xe59fc004), // ldr ip, [pc, #4]
2692 Insn_template::arm_insn(0xe08fc00c), // add ip, pc, ip
2693 Insn_template::arm_insn(0xe12fff1c), // bx ip
2694 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, 0),
2695 // dcd R_ARM_REL32(X)
2698 // V4T Thumb -> ARM long branch stub, PIC.
2699 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_arm_pic
[] =
2701 Insn_template::thumb16_insn(0x4778), // bx pc
2702 Insn_template::thumb16_insn(0x46c0), // nop
2703 Insn_template::arm_insn(0xe59fc000), // ldr ip, [pc, #0]
2704 Insn_template::arm_insn(0xe08cf00f), // add pc, ip, pc
2705 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, -4),
2706 // dcd R_ARM_REL32(X)
2709 // Thumb -> Thumb long branch stub, PIC. Used on M-profile
2711 static const Insn_template elf32_arm_stub_long_branch_thumb_only_pic
[] =
2713 Insn_template::thumb16_insn(0xb401), // push {r0}
2714 Insn_template::thumb16_insn(0x4802), // ldr r0, [pc, #8]
2715 Insn_template::thumb16_insn(0x46fc), // mov ip, pc
2716 Insn_template::thumb16_insn(0x4484), // add ip, r0
2717 Insn_template::thumb16_insn(0xbc01), // pop {r0}
2718 Insn_template::thumb16_insn(0x4760), // bx ip
2719 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, 4),
2720 // dcd R_ARM_REL32(X)
2723 // V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not
2725 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_thumb_pic
[] =
2727 Insn_template::thumb16_insn(0x4778), // bx pc
2728 Insn_template::thumb16_insn(0x46c0), // nop
2729 Insn_template::arm_insn(0xe59fc004), // ldr ip, [pc, #4]
2730 Insn_template::arm_insn(0xe08fc00c), // add ip, pc, ip
2731 Insn_template::arm_insn(0xe12fff1c), // bx ip
2732 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, 0),
2733 // dcd R_ARM_REL32(X)
2736 // Cortex-A8 erratum-workaround stubs.
2738 // Stub used for conditional branches (which may be beyond +/-1MB away,
2739 // so we can't use a conditional branch to reach this stub).
2746 static const Insn_template elf32_arm_stub_a8_veneer_b_cond
[] =
2748 Insn_template::thumb16_bcond_insn(0xd001), // b<cond>.n true
2749 Insn_template::thumb32_b_insn(0xf000b800, -4), // b.w after
2750 Insn_template::thumb32_b_insn(0xf000b800, -4) // true:
2754 // Stub used for b.w and bl.w instructions.
2756 static const Insn_template elf32_arm_stub_a8_veneer_b
[] =
2758 Insn_template::thumb32_b_insn(0xf000b800, -4) // b.w dest
2761 static const Insn_template elf32_arm_stub_a8_veneer_bl
[] =
2763 Insn_template::thumb32_b_insn(0xf000b800, -4) // b.w dest
2766 // Stub used for Thumb-2 blx.w instructions. We modified the original blx.w
2767 // instruction (which switches to ARM mode) to point to this stub. Jump to
2768 // the real destination using an ARM-mode branch.
2769 const Insn_template elf32_arm_stub_a8_veneer_blx
[] =
2771 Insn_template::arm_rel_insn(0xea000000, -8) // b dest
2774 // Fill in the stub template look-up table. Stub templates are constructed
2775 // per instance of Stub_factory for fast look-up without locking
2776 // in a thread-enabled environment.
2778 this->stub_templates_
[arm_stub_none
] =
2779 new Stub_template(arm_stub_none
, NULL
, 0);
2781 #define DEF_STUB(x) \
2785 = sizeof(elf32_arm_stub_##x) / sizeof(elf32_arm_stub_##x[0]); \
2786 Stub_type type = arm_stub_##x; \
2787 this->stub_templates_[type] = \
2788 new Stub_template(type, elf32_arm_stub_##x, array_size); \
2796 // Stub_table methods.
2798 // Add a STUB with using KEY. Caller is reponsible for avoid adding
2799 // if already a STUB with the same key has been added.
2801 template<bool big_endian
>
2803 Stub_table
<big_endian
>::add_reloc_stub(
2805 const Reloc_stub::Key
& key
)
2807 const Stub_template
* stub_template
= stub
->stub_template();
2808 gold_assert(stub_template
->type() == key
.stub_type());
2809 this->reloc_stubs_
[key
] = stub
;
2810 if (this->addralign_
< stub_template
->alignment())
2811 this->addralign_
= stub_template
->alignment();
2812 this->has_been_changed_
= true;
2815 template<bool big_endian
>
2817 Stub_table
<big_endian
>::relocate_stubs(
2818 const Relocate_info
<32, big_endian
>* relinfo
,
2819 Target_arm
<big_endian
>* arm_target
,
2820 Output_section
* output_section
,
2821 unsigned char* view
,
2822 Arm_address address
,
2823 section_size_type view_size
)
2825 // If we are passed a view bigger than the stub table's. we need to
2827 gold_assert(address
== this->address()
2829 == static_cast<section_size_type
>(this->data_size())));
2831 for (typename
Reloc_stub_map::const_iterator p
= this->reloc_stubs_
.begin();
2832 p
!= this->reloc_stubs_
.end();
2835 Reloc_stub
* stub
= p
->second
;
2836 const Stub_template
* stub_template
= stub
->stub_template();
2837 if (stub_template
->reloc_count() != 0)
2839 // Adjust view to cover the stub only.
2840 section_size_type offset
= stub
->offset();
2841 section_size_type stub_size
= stub_template
->size();
2842 gold_assert(offset
+ stub_size
<= view_size
);
2844 arm_target
->relocate_stub(stub
, relinfo
, output_section
,
2845 view
+ offset
, address
+ offset
,
2851 // Reset address and file offset.
2853 template<bool big_endian
>
2855 Stub_table
<big_endian
>::do_reset_address_and_file_offset()
2858 uint64_t max_addralign
= 1;
2859 for (typename
Reloc_stub_map::const_iterator p
= this->reloc_stubs_
.begin();
2860 p
!= this->reloc_stubs_
.end();
2863 Reloc_stub
* stub
= p
->second
;
2864 const Stub_template
* stub_template
= stub
->stub_template();
2865 uint64_t stub_addralign
= stub_template
->alignment();
2866 max_addralign
= std::max(max_addralign
, stub_addralign
);
2867 off
= align_address(off
, stub_addralign
);
2868 stub
->set_offset(off
);
2869 stub
->reset_destination_address();
2870 off
+= stub_template
->size();
2873 this->addralign_
= max_addralign
;
2874 this->set_current_data_size_for_child(off
);
2877 // Write out the stubs to file.
2879 template<bool big_endian
>
2881 Stub_table
<big_endian
>::do_write(Output_file
* of
)
2883 off_t offset
= this->offset();
2884 const section_size_type oview_size
=
2885 convert_to_section_size_type(this->data_size());
2886 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2888 for (typename
Reloc_stub_map::const_iterator p
= this->reloc_stubs_
.begin();
2889 p
!= this->reloc_stubs_
.end();
2892 Reloc_stub
* stub
= p
->second
;
2893 Arm_address address
= this->address() + stub
->offset();
2895 == align_address(address
,
2896 stub
->stub_template()->alignment()));
2897 stub
->write(oview
+ stub
->offset(), stub
->stub_template()->size(),
2900 of
->write_output_view(this->offset(), oview_size
, oview
);
2903 // Arm_input_section methods.
2905 // Initialize an Arm_input_section.
2907 template<bool big_endian
>
2909 Arm_input_section
<big_endian
>::init()
2911 Relobj
* relobj
= this->relobj();
2912 unsigned int shndx
= this->shndx();
2914 // Cache these to speed up size and alignment queries. It is too slow
2915 // to call section_addraglin and section_size every time.
2916 this->original_addralign_
= relobj
->section_addralign(shndx
);
2917 this->original_size_
= relobj
->section_size(shndx
);
2919 // We want to make this look like the original input section after
2920 // output sections are finalized.
2921 Output_section
* os
= relobj
->output_section(shndx
);
2922 off_t offset
= relobj
->output_section_offset(shndx
);
2923 gold_assert(os
!= NULL
&& !relobj
->is_output_section_offset_invalid(shndx
));
2924 this->set_address(os
->address() + offset
);
2925 this->set_file_offset(os
->offset() + offset
);
2927 this->set_current_data_size(this->original_size_
);
2928 this->finalize_data_size();
2931 template<bool big_endian
>
2933 Arm_input_section
<big_endian
>::do_write(Output_file
* of
)
2935 // We have to write out the original section content.
2936 section_size_type section_size
;
2937 const unsigned char* section_contents
=
2938 this->relobj()->section_contents(this->shndx(), §ion_size
, false);
2939 of
->write(this->offset(), section_contents
, section_size
);
2941 // If this owns a stub table and it is not empty, write it.
2942 if (this->is_stub_table_owner() && !this->stub_table_
->empty())
2943 this->stub_table_
->write(of
);
2946 // Finalize data size.
2948 template<bool big_endian
>
2950 Arm_input_section
<big_endian
>::set_final_data_size()
2952 // If this owns a stub table, finalize its data size as well.
2953 if (this->is_stub_table_owner())
2955 uint64_t address
= this->address();
2957 // The stub table comes after the original section contents.
2958 address
+= this->original_size_
;
2959 address
= align_address(address
, this->stub_table_
->addralign());
2960 off_t offset
= this->offset() + (address
- this->address());
2961 this->stub_table_
->set_address_and_file_offset(address
, offset
);
2962 address
+= this->stub_table_
->data_size();
2963 gold_assert(address
== this->address() + this->current_data_size());
2966 this->set_data_size(this->current_data_size());
2969 // Reset address and file offset.
2971 template<bool big_endian
>
2973 Arm_input_section
<big_endian
>::do_reset_address_and_file_offset()
2975 // Size of the original input section contents.
2976 off_t off
= convert_types
<off_t
, uint64_t>(this->original_size_
);
2978 // If this is a stub table owner, account for the stub table size.
2979 if (this->is_stub_table_owner())
2981 Stub_table
<big_endian
>* stub_table
= this->stub_table_
;
2983 // Reset the stub table's address and file offset. The
2984 // current data size for child will be updated after that.
2985 stub_table_
->reset_address_and_file_offset();
2986 off
= align_address(off
, stub_table_
->addralign());
2987 off
+= stub_table
->current_data_size();
2990 this->set_current_data_size(off
);
2993 // Arm_output_section methods.
2995 // Create a stub group for input sections from BEGIN to END. OWNER
2996 // points to the input section to be the owner a new stub table.
2998 template<bool big_endian
>
3000 Arm_output_section
<big_endian
>::create_stub_group(
3001 Input_section_list::const_iterator begin
,
3002 Input_section_list::const_iterator end
,
3003 Input_section_list::const_iterator owner
,
3004 Target_arm
<big_endian
>* target
,
3005 std::vector
<Output_relaxed_input_section
*>* new_relaxed_sections
)
3007 // Currently we convert ordinary input sections into relaxed sections only
3008 // at this point but we may want to support creating relaxed input section
3009 // very early. So we check here to see if owner is already a relaxed
3012 Arm_input_section
<big_endian
>* arm_input_section
;
3013 if (owner
->is_relaxed_input_section())
3016 Arm_input_section
<big_endian
>::as_arm_input_section(
3017 owner
->relaxed_input_section());
3021 gold_assert(owner
->is_input_section());
3022 // Create a new relaxed input section.
3024 target
->new_arm_input_section(owner
->relobj(), owner
->shndx());
3025 new_relaxed_sections
->push_back(arm_input_section
);
3028 // Create a stub table.
3029 Stub_table
<big_endian
>* stub_table
=
3030 target
->new_stub_table(arm_input_section
);
3032 arm_input_section
->set_stub_table(stub_table
);
3034 Input_section_list::const_iterator p
= begin
;
3035 Input_section_list::const_iterator prev_p
;
3037 // Look for input sections or relaxed input sections in [begin ... end].
3040 if (p
->is_input_section() || p
->is_relaxed_input_section())
3042 // The stub table information for input sections live
3043 // in their objects.
3044 Arm_relobj
<big_endian
>* arm_relobj
=
3045 Arm_relobj
<big_endian
>::as_arm_relobj(p
->relobj());
3046 arm_relobj
->set_stub_table(p
->shndx(), stub_table
);
3050 while (prev_p
!= end
);
3053 // Group input sections for stub generation. GROUP_SIZE is roughly the limit
3054 // of stub groups. We grow a stub group by adding input section until the
3055 // size is just below GROUP_SIZE. The last input section will be converted
3056 // into a stub table. If STUB_ALWAYS_AFTER_BRANCH is false, we also add
3057 // input section after the stub table, effectively double the group size.
3059 // This is similar to the group_sections() function in elf32-arm.c but is
3060 // implemented differently.
3062 template<bool big_endian
>
3064 Arm_output_section
<big_endian
>::group_sections(
3065 section_size_type group_size
,
3066 bool stubs_always_after_branch
,
3067 Target_arm
<big_endian
>* target
)
3069 // We only care about sections containing code.
3070 if ((this->flags() & elfcpp::SHF_EXECINSTR
) == 0)
3073 // States for grouping.
3076 // No group is being built.
3078 // A group is being built but the stub table is not found yet.
3079 // We keep group a stub group until the size is just under GROUP_SIZE.
3080 // The last input section in the group will be used as the stub table.
3081 FINDING_STUB_SECTION
,
3082 // A group is being built and we have already found a stub table.
3083 // We enter this state to grow a stub group by adding input section
3084 // after the stub table. This effectively doubles the group size.
3088 // Any newly created relaxed sections are stored here.
3089 std::vector
<Output_relaxed_input_section
*> new_relaxed_sections
;
3091 State state
= NO_GROUP
;
3092 section_size_type off
= 0;
3093 section_size_type group_begin_offset
= 0;
3094 section_size_type group_end_offset
= 0;
3095 section_size_type stub_table_end_offset
= 0;
3096 Input_section_list::const_iterator group_begin
=
3097 this->input_sections().end();
3098 Input_section_list::const_iterator stub_table
=
3099 this->input_sections().end();
3100 Input_section_list::const_iterator group_end
= this->input_sections().end();
3101 for (Input_section_list::const_iterator p
= this->input_sections().begin();
3102 p
!= this->input_sections().end();
3105 section_size_type section_begin_offset
=
3106 align_address(off
, p
->addralign());
3107 section_size_type section_end_offset
=
3108 section_begin_offset
+ p
->data_size();
3110 // Check to see if we should group the previously seens sections.
3116 case FINDING_STUB_SECTION
:
3117 // Adding this section makes the group larger than GROUP_SIZE.
3118 if (section_end_offset
- group_begin_offset
>= group_size
)
3120 if (stubs_always_after_branch
)
3122 gold_assert(group_end
!= this->input_sections().end());
3123 this->create_stub_group(group_begin
, group_end
, group_end
,
3124 target
, &new_relaxed_sections
);
3129 // But wait, there's more! Input sections up to
3130 // stub_group_size bytes after the stub table can be
3131 // handled by it too.
3132 state
= HAS_STUB_SECTION
;
3133 stub_table
= group_end
;
3134 stub_table_end_offset
= group_end_offset
;
3139 case HAS_STUB_SECTION
:
3140 // Adding this section makes the post stub-section group larger
3142 if (section_end_offset
- stub_table_end_offset
>= group_size
)
3144 gold_assert(group_end
!= this->input_sections().end());
3145 this->create_stub_group(group_begin
, group_end
, stub_table
,
3146 target
, &new_relaxed_sections
);
3155 // If we see an input section and currently there is no group, start
3156 // a new one. Skip any empty sections.
3157 if ((p
->is_input_section() || p
->is_relaxed_input_section())
3158 && (p
->relobj()->section_size(p
->shndx()) != 0))
3160 if (state
== NO_GROUP
)
3162 state
= FINDING_STUB_SECTION
;
3164 group_begin_offset
= section_begin_offset
;
3167 // Keep track of the last input section seen.
3169 group_end_offset
= section_end_offset
;
3172 off
= section_end_offset
;
3175 // Create a stub group for any ungrouped sections.
3176 if (state
== FINDING_STUB_SECTION
|| state
== HAS_STUB_SECTION
)
3178 gold_assert(group_end
!= this->input_sections().end());
3179 this->create_stub_group(group_begin
, group_end
,
3180 (state
== FINDING_STUB_SECTION
3183 target
, &new_relaxed_sections
);
3186 // Convert input section into relaxed input section in a batch.
3187 if (!new_relaxed_sections
.empty())
3188 this->convert_input_sections_to_relaxed_sections(new_relaxed_sections
);
3190 // Update the section offsets
3191 for (size_t i
= 0; i
< new_relaxed_sections
.size(); ++i
)
3193 Arm_relobj
<big_endian
>* arm_relobj
=
3194 Arm_relobj
<big_endian
>::as_arm_relobj(
3195 new_relaxed_sections
[i
]->relobj());
3196 unsigned int shndx
= new_relaxed_sections
[i
]->shndx();
3197 // Tell Arm_relobj that this input section is converted.
3198 arm_relobj
->convert_input_section_to_relaxed_section(shndx
);
3202 // Arm_relobj methods.
3204 // Scan relocations for stub generation.
3206 template<bool big_endian
>
3208 Arm_relobj
<big_endian
>::scan_sections_for_stubs(
3209 Target_arm
<big_endian
>* arm_target
,
3210 const Symbol_table
* symtab
,
3211 const Layout
* layout
)
3213 unsigned int shnum
= this->shnum();
3214 const unsigned int shdr_size
= elfcpp::Elf_sizes
<32>::shdr_size
;
3216 // Read the section headers.
3217 const unsigned char* pshdrs
= this->get_view(this->elf_file()->shoff(),
3221 // To speed up processing, we set up hash tables for fast lookup of
3222 // input offsets to output addresses.
3223 this->initialize_input_to_output_maps();
3225 const Relobj::Output_sections
& out_sections(this->output_sections());
3227 Relocate_info
<32, big_endian
> relinfo
;
3228 relinfo
.symtab
= symtab
;
3229 relinfo
.layout
= layout
;
3230 relinfo
.object
= this;
3232 const unsigned char* p
= pshdrs
+ shdr_size
;
3233 for (unsigned int i
= 1; i
< shnum
; ++i
, p
+= shdr_size
)
3235 typename
elfcpp::Shdr
<32, big_endian
> shdr(p
);
3237 unsigned int sh_type
= shdr
.get_sh_type();
3238 if (sh_type
!= elfcpp::SHT_REL
&& sh_type
!= elfcpp::SHT_RELA
)
3241 off_t sh_size
= shdr
.get_sh_size();
3245 unsigned int index
= this->adjust_shndx(shdr
.get_sh_info());
3246 if (index
>= this->shnum())
3248 // Ignore reloc section with bad info. This error will be
3249 // reported in the final link.
3253 Output_section
* os
= out_sections
[index
];
3256 // This relocation section is against a section which we
3260 Arm_address output_offset
= this->get_output_section_offset(index
);
3262 if (this->adjust_shndx(shdr
.get_sh_link()) != this->symtab_shndx())
3264 // Ignore reloc section with unexpected symbol table. The
3265 // error will be reported in the final link.
3269 const unsigned char* prelocs
= this->get_view(shdr
.get_sh_offset(),
3270 sh_size
, true, false);
3272 unsigned int reloc_size
;
3273 if (sh_type
== elfcpp::SHT_REL
)
3274 reloc_size
= elfcpp::Elf_sizes
<32>::rel_size
;
3276 reloc_size
= elfcpp::Elf_sizes
<32>::rela_size
;
3278 if (reloc_size
!= shdr
.get_sh_entsize())
3280 // Ignore reloc section with unexpected entsize. The error
3281 // will be reported in the final link.
3285 size_t reloc_count
= sh_size
/ reloc_size
;
3286 if (static_cast<off_t
>(reloc_count
* reloc_size
) != sh_size
)
3288 // Ignore reloc section with uneven size. The error will be
3289 // reported in the final link.
3293 gold_assert(output_offset
!= invalid_address
3294 || this->relocs_must_follow_section_writes());
3296 // Get the section contents. This does work for the case in which
3297 // we modify the contents of an input section. We need to pass the
3298 // output view under such circumstances.
3299 section_size_type input_view_size
= 0;
3300 const unsigned char* input_view
=
3301 this->section_contents(index
, &input_view_size
, false);
3303 relinfo
.reloc_shndx
= i
;
3304 relinfo
.data_shndx
= index
;
3305 arm_target
->scan_section_for_stubs(&relinfo
, sh_type
, prelocs
,
3307 output_offset
== invalid_address
,
3313 // After we've done the relocations, we release the hash tables,
3314 // since we no longer need them.
3315 this->free_input_to_output_maps();
3318 // Count the local symbols. The ARM backend needs to know if a symbol
3319 // is a THUMB function or not. For global symbols, it is easy because
3320 // the Symbol object keeps the ELF symbol type. For local symbol it is
3321 // harder because we cannot access this information. So we override the
3322 // do_count_local_symbol in parent and scan local symbols to mark
3323 // THUMB functions. This is not the most efficient way but I do not want to
3324 // slow down other ports by calling a per symbol targer hook inside
3325 // Sized_relobj<size, big_endian>::do_count_local_symbols.
3327 template<bool big_endian
>
3329 Arm_relobj
<big_endian
>::do_count_local_symbols(
3330 Stringpool_template
<char>* pool
,
3331 Stringpool_template
<char>* dynpool
)
3333 // We need to fix-up the values of any local symbols whose type are
3336 // Ask parent to count the local symbols.
3337 Sized_relobj
<32, big_endian
>::do_count_local_symbols(pool
, dynpool
);
3338 const unsigned int loccount
= this->local_symbol_count();
3342 // Intialize the thumb function bit-vector.
3343 std::vector
<bool> empty_vector(loccount
, false);
3344 this->local_symbol_is_thumb_function_
.swap(empty_vector
);
3346 // Read the symbol table section header.
3347 const unsigned int symtab_shndx
= this->symtab_shndx();
3348 elfcpp::Shdr
<32, big_endian
>
3349 symtabshdr(this, this->elf_file()->section_header(symtab_shndx
));
3350 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
3352 // Read the local symbols.
3353 const int sym_size
=elfcpp::Elf_sizes
<32>::sym_size
;
3354 gold_assert(loccount
== symtabshdr
.get_sh_info());
3355 off_t locsize
= loccount
* sym_size
;
3356 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
3357 locsize
, true, true);
3359 // Loop over the local symbols and mark any local symbols pointing
3360 // to THUMB functions.
3362 // Skip the first dummy symbol.
3364 typename Sized_relobj
<32, big_endian
>::Local_values
* plocal_values
=
3365 this->local_values();
3366 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
3368 elfcpp::Sym
<32, big_endian
> sym(psyms
);
3369 elfcpp::STT st_type
= sym
.get_st_type();
3370 Symbol_value
<32>& lv((*plocal_values
)[i
]);
3371 Arm_address input_value
= lv
.input_value();
3373 if (st_type
== elfcpp::STT_ARM_TFUNC
3374 || (st_type
== elfcpp::STT_FUNC
&& ((input_value
& 1) != 0)))
3376 // This is a THUMB function. Mark this and canonicalize the
3377 // symbol value by setting LSB.
3378 this->local_symbol_is_thumb_function_
[i
] = true;
3379 if ((input_value
& 1) == 0)
3380 lv
.set_input_value(input_value
| 1);
3385 // Relocate sections.
3386 template<bool big_endian
>
3388 Arm_relobj
<big_endian
>::do_relocate_sections(
3389 const Symbol_table
* symtab
,
3390 const Layout
* layout
,
3391 const unsigned char* pshdrs
,
3392 typename Sized_relobj
<32, big_endian
>::Views
* pviews
)
3394 // Call parent to relocate sections.
3395 Sized_relobj
<32, big_endian
>::do_relocate_sections(symtab
, layout
, pshdrs
,
3398 // We do not generate stubs if doing a relocatable link.
3399 if (parameters
->options().relocatable())
3402 // Relocate stub tables.
3403 unsigned int shnum
= this->shnum();
3405 Target_arm
<big_endian
>* arm_target
=
3406 Target_arm
<big_endian
>::default_target();
3408 Relocate_info
<32, big_endian
> relinfo
;
3409 relinfo
.symtab
= symtab
;
3410 relinfo
.layout
= layout
;
3411 relinfo
.object
= this;
3413 for (unsigned int i
= 1; i
< shnum
; ++i
)
3415 Arm_input_section
<big_endian
>* arm_input_section
=
3416 arm_target
->find_arm_input_section(this, i
);
3418 if (arm_input_section
== NULL
3419 || !arm_input_section
->is_stub_table_owner()
3420 || arm_input_section
->stub_table()->empty())
3423 // We cannot discard a section if it owns a stub table.
3424 Output_section
* os
= this->output_section(i
);
3425 gold_assert(os
!= NULL
);
3427 relinfo
.reloc_shndx
= elfcpp::SHN_UNDEF
;
3428 relinfo
.reloc_shdr
= NULL
;
3429 relinfo
.data_shndx
= i
;
3430 relinfo
.data_shdr
= pshdrs
+ i
* elfcpp::Elf_sizes
<32>::shdr_size
;
3432 gold_assert((*pviews
)[i
].view
!= NULL
);
3434 // We are passed the output section view. Adjust it to cover the
3436 Stub_table
<big_endian
>* stub_table
= arm_input_section
->stub_table();
3437 gold_assert((stub_table
->address() >= (*pviews
)[i
].address
)
3438 && ((stub_table
->address() + stub_table
->data_size())
3439 <= (*pviews
)[i
].address
+ (*pviews
)[i
].view_size
));
3441 off_t offset
= stub_table
->address() - (*pviews
)[i
].address
;
3442 unsigned char* view
= (*pviews
)[i
].view
+ offset
;
3443 Arm_address address
= stub_table
->address();
3444 section_size_type view_size
= stub_table
->data_size();
3446 stub_table
->relocate_stubs(&relinfo
, arm_target
, os
, view
, address
,
3451 // Read the symbol information.
3453 template<bool big_endian
>
3455 Arm_relobj
<big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
3457 // Call parent class to read symbol information.
3458 Sized_relobj
<32, big_endian
>::do_read_symbols(sd
);
3460 // Read processor-specific flags in ELF file header.
3461 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
3462 elfcpp::Elf_sizes
<32>::ehdr_size
,
3464 elfcpp::Ehdr
<32, big_endian
> ehdr(pehdr
);
3465 this->processor_specific_flags_
= ehdr
.get_e_flags();
3468 // Arm_dynobj methods.
3470 // Read the symbol information.
3472 template<bool big_endian
>
3474 Arm_dynobj
<big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
3476 // Call parent class to read symbol information.
3477 Sized_dynobj
<32, big_endian
>::do_read_symbols(sd
);
3479 // Read processor-specific flags in ELF file header.
3480 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
3481 elfcpp::Elf_sizes
<32>::ehdr_size
,
3483 elfcpp::Ehdr
<32, big_endian
> ehdr(pehdr
);
3484 this->processor_specific_flags_
= ehdr
.get_e_flags();
3487 // Stub_addend_reader methods.
3489 // Read the addend of a REL relocation of type R_TYPE at VIEW.
3491 template<bool big_endian
>
3492 elfcpp::Elf_types
<32>::Elf_Swxword
3493 Stub_addend_reader
<elfcpp::SHT_REL
, big_endian
>::operator()(
3494 unsigned int r_type
,
3495 const unsigned char* view
,
3496 const typename Reloc_types
<elfcpp::SHT_REL
, 32, big_endian
>::Reloc
&) const
3500 case elfcpp::R_ARM_CALL
:
3501 case elfcpp::R_ARM_JUMP24
:
3502 case elfcpp::R_ARM_PLT32
:
3504 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3505 const Valtype
* wv
= reinterpret_cast<const Valtype
*>(view
);
3506 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3507 return utils::sign_extend
<26>(val
<< 2);
3510 case elfcpp::R_ARM_THM_CALL
:
3511 case elfcpp::R_ARM_THM_JUMP24
:
3512 case elfcpp::R_ARM_THM_XPC22
:
3514 // Fetch the addend. We use the Thumb-2 encoding (backwards
3515 // compatible with Thumb-1) involving the J1 and J2 bits.
3516 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
3517 const Valtype
* wv
= reinterpret_cast<const Valtype
*>(view
);
3518 Valtype upper_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
3519 Valtype lower_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
3521 uint32_t s
= (upper_insn
& (1 << 10)) >> 10;
3522 uint32_t upper
= upper_insn
& 0x3ff;
3523 uint32_t lower
= lower_insn
& 0x7ff;
3524 uint32_t j1
= (lower_insn
& (1 << 13)) >> 13;
3525 uint32_t j2
= (lower_insn
& (1 << 11)) >> 11;
3526 uint32_t i1
= j1
^ s
? 0 : 1;
3527 uint32_t i2
= j2
^ s
? 0 : 1;
3529 return utils::sign_extend
<25>((s
<< 24) | (i1
<< 23) | (i2
<< 22)
3530 | (upper
<< 12) | (lower
<< 1));
3533 case elfcpp::R_ARM_THM_JUMP19
:
3535 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
3536 const Valtype
* wv
= reinterpret_cast<const Valtype
*>(view
);
3537 Valtype upper_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
3538 Valtype lower_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
3540 // Reconstruct the top three bits and squish the two 11 bit pieces
3542 uint32_t S
= (upper_insn
& 0x0400) >> 10;
3543 uint32_t J1
= (lower_insn
& 0x2000) >> 13;
3544 uint32_t J2
= (lower_insn
& 0x0800) >> 11;
3546 (S
<< 8) | (J2
<< 7) | (J1
<< 6) | (upper_insn
& 0x003f);
3547 uint32_t lower
= (lower_insn
& 0x07ff);
3548 return utils::sign_extend
<23>((upper
<< 12) | (lower
<< 1));
3556 // A class to handle the PLT data.
3558 template<bool big_endian
>
3559 class Output_data_plt_arm
: public Output_section_data
3562 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, big_endian
>
3565 Output_data_plt_arm(Layout
*, Output_data_space
*);
3567 // Add an entry to the PLT.
3569 add_entry(Symbol
* gsym
);
3571 // Return the .rel.plt section data.
3572 const Reloc_section
*
3574 { return this->rel_
; }
3578 do_adjust_output_section(Output_section
* os
);
3580 // Write to a map file.
3582 do_print_to_mapfile(Mapfile
* mapfile
) const
3583 { mapfile
->print_output_data(this, _("** PLT")); }
3586 // Template for the first PLT entry.
3587 static const uint32_t first_plt_entry
[5];
3589 // Template for subsequent PLT entries.
3590 static const uint32_t plt_entry
[3];
3592 // Set the final size.
3594 set_final_data_size()
3596 this->set_data_size(sizeof(first_plt_entry
)
3597 + this->count_
* sizeof(plt_entry
));
3600 // Write out the PLT data.
3602 do_write(Output_file
*);
3604 // The reloc section.
3605 Reloc_section
* rel_
;
3606 // The .got.plt section.
3607 Output_data_space
* got_plt_
;
3608 // The number of PLT entries.
3609 unsigned int count_
;
3612 // Create the PLT section. The ordinary .got section is an argument,
3613 // since we need to refer to the start. We also create our own .got
3614 // section just for PLT entries.
3616 template<bool big_endian
>
3617 Output_data_plt_arm
<big_endian
>::Output_data_plt_arm(Layout
* layout
,
3618 Output_data_space
* got_plt
)
3619 : Output_section_data(4), got_plt_(got_plt
), count_(0)
3621 this->rel_
= new Reloc_section(false);
3622 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
3623 elfcpp::SHF_ALLOC
, this->rel_
, true);
3626 template<bool big_endian
>
3628 Output_data_plt_arm
<big_endian
>::do_adjust_output_section(Output_section
* os
)
3633 // Add an entry to the PLT.
3635 template<bool big_endian
>
3637 Output_data_plt_arm
<big_endian
>::add_entry(Symbol
* gsym
)
3639 gold_assert(!gsym
->has_plt_offset());
3641 // Note that when setting the PLT offset we skip the initial
3642 // reserved PLT entry.
3643 gsym
->set_plt_offset((this->count_
) * sizeof(plt_entry
)
3644 + sizeof(first_plt_entry
));
3648 section_offset_type got_offset
= this->got_plt_
->current_data_size();
3650 // Every PLT entry needs a GOT entry which points back to the PLT
3651 // entry (this will be changed by the dynamic linker, normally
3652 // lazily when the function is called).
3653 this->got_plt_
->set_current_data_size(got_offset
+ 4);
3655 // Every PLT entry needs a reloc.
3656 gsym
->set_needs_dynsym_entry();
3657 this->rel_
->add_global(gsym
, elfcpp::R_ARM_JUMP_SLOT
, this->got_plt_
,
3660 // Note that we don't need to save the symbol. The contents of the
3661 // PLT are independent of which symbols are used. The symbols only
3662 // appear in the relocations.
3666 // FIXME: This is not very flexible. Right now this has only been tested
3667 // on armv5te. If we are to support additional architecture features like
3668 // Thumb-2 or BE8, we need to make this more flexible like GNU ld.
3670 // The first entry in the PLT.
3671 template<bool big_endian
>
3672 const uint32_t Output_data_plt_arm
<big_endian
>::first_plt_entry
[5] =
3674 0xe52de004, // str lr, [sp, #-4]!
3675 0xe59fe004, // ldr lr, [pc, #4]
3676 0xe08fe00e, // add lr, pc, lr
3677 0xe5bef008, // ldr pc, [lr, #8]!
3678 0x00000000, // &GOT[0] - .
3681 // Subsequent entries in the PLT.
3683 template<bool big_endian
>
3684 const uint32_t Output_data_plt_arm
<big_endian
>::plt_entry
[3] =
3686 0xe28fc600, // add ip, pc, #0xNN00000
3687 0xe28cca00, // add ip, ip, #0xNN000
3688 0xe5bcf000, // ldr pc, [ip, #0xNNN]!
3691 // Write out the PLT. This uses the hand-coded instructions above,
3692 // and adjusts them as needed. This is all specified by the arm ELF
3693 // Processor Supplement.
3695 template<bool big_endian
>
3697 Output_data_plt_arm
<big_endian
>::do_write(Output_file
* of
)
3699 const off_t offset
= this->offset();
3700 const section_size_type oview_size
=
3701 convert_to_section_size_type(this->data_size());
3702 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
3704 const off_t got_file_offset
= this->got_plt_
->offset();
3705 const section_size_type got_size
=
3706 convert_to_section_size_type(this->got_plt_
->data_size());
3707 unsigned char* const got_view
= of
->get_output_view(got_file_offset
,
3709 unsigned char* pov
= oview
;
3711 Arm_address plt_address
= this->address();
3712 Arm_address got_address
= this->got_plt_
->address();
3714 // Write first PLT entry. All but the last word are constants.
3715 const size_t num_first_plt_words
= (sizeof(first_plt_entry
)
3716 / sizeof(plt_entry
[0]));
3717 for (size_t i
= 0; i
< num_first_plt_words
- 1; i
++)
3718 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ i
* 4, first_plt_entry
[i
]);
3719 // Last word in first PLT entry is &GOT[0] - .
3720 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 16,
3721 got_address
- (plt_address
+ 16));
3722 pov
+= sizeof(first_plt_entry
);
3724 unsigned char* got_pov
= got_view
;
3726 memset(got_pov
, 0, 12);
3729 const int rel_size
= elfcpp::Elf_sizes
<32>::rel_size
;
3730 unsigned int plt_offset
= sizeof(first_plt_entry
);
3731 unsigned int plt_rel_offset
= 0;
3732 unsigned int got_offset
= 12;
3733 const unsigned int count
= this->count_
;
3734 for (unsigned int i
= 0;
3737 pov
+= sizeof(plt_entry
),
3739 plt_offset
+= sizeof(plt_entry
),
3740 plt_rel_offset
+= rel_size
,
3743 // Set and adjust the PLT entry itself.
3744 int32_t offset
= ((got_address
+ got_offset
)
3745 - (plt_address
+ plt_offset
+ 8));
3747 gold_assert(offset
>= 0 && offset
< 0x0fffffff);
3748 uint32_t plt_insn0
= plt_entry
[0] | ((offset
>> 20) & 0xff);
3749 elfcpp::Swap
<32, big_endian
>::writeval(pov
, plt_insn0
);
3750 uint32_t plt_insn1
= plt_entry
[1] | ((offset
>> 12) & 0xff);
3751 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, plt_insn1
);
3752 uint32_t plt_insn2
= plt_entry
[2] | (offset
& 0xfff);
3753 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8, plt_insn2
);
3755 // Set the entry in the GOT.
3756 elfcpp::Swap
<32, big_endian
>::writeval(got_pov
, plt_address
);
3759 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
3760 gold_assert(static_cast<section_size_type
>(got_pov
- got_view
) == got_size
);
3762 of
->write_output_view(offset
, oview_size
, oview
);
3763 of
->write_output_view(got_file_offset
, got_size
, got_view
);
3766 // Create a PLT entry for a global symbol.
3768 template<bool big_endian
>
3770 Target_arm
<big_endian
>::make_plt_entry(Symbol_table
* symtab
, Layout
* layout
,
3773 if (gsym
->has_plt_offset())
3776 if (this->plt_
== NULL
)
3778 // Create the GOT sections first.
3779 this->got_section(symtab
, layout
);
3781 this->plt_
= new Output_data_plt_arm
<big_endian
>(layout
, this->got_plt_
);
3782 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
3784 | elfcpp::SHF_EXECINSTR
),
3787 this->plt_
->add_entry(gsym
);
3790 // Report an unsupported relocation against a local symbol.
3792 template<bool big_endian
>
3794 Target_arm
<big_endian
>::Scan::unsupported_reloc_local(
3795 Sized_relobj
<32, big_endian
>* object
,
3796 unsigned int r_type
)
3798 gold_error(_("%s: unsupported reloc %u against local symbol"),
3799 object
->name().c_str(), r_type
);
3802 // We are about to emit a dynamic relocation of type R_TYPE. If the
3803 // dynamic linker does not support it, issue an error. The GNU linker
3804 // only issues a non-PIC error for an allocated read-only section.
3805 // Here we know the section is allocated, but we don't know that it is
3806 // read-only. But we check for all the relocation types which the
3807 // glibc dynamic linker supports, so it seems appropriate to issue an
3808 // error even if the section is not read-only.
3810 template<bool big_endian
>
3812 Target_arm
<big_endian
>::Scan::check_non_pic(Relobj
* object
,
3813 unsigned int r_type
)
3817 // These are the relocation types supported by glibc for ARM.
3818 case elfcpp::R_ARM_RELATIVE
:
3819 case elfcpp::R_ARM_COPY
:
3820 case elfcpp::R_ARM_GLOB_DAT
:
3821 case elfcpp::R_ARM_JUMP_SLOT
:
3822 case elfcpp::R_ARM_ABS32
:
3823 case elfcpp::R_ARM_ABS32_NOI
:
3824 case elfcpp::R_ARM_PC24
:
3825 // FIXME: The following 3 types are not supported by Android's dynamic
3827 case elfcpp::R_ARM_TLS_DTPMOD32
:
3828 case elfcpp::R_ARM_TLS_DTPOFF32
:
3829 case elfcpp::R_ARM_TLS_TPOFF32
:
3833 // This prevents us from issuing more than one error per reloc
3834 // section. But we can still wind up issuing more than one
3835 // error per object file.
3836 if (this->issued_non_pic_error_
)
3838 object
->error(_("requires unsupported dynamic reloc; "
3839 "recompile with -fPIC"));
3840 this->issued_non_pic_error_
= true;
3843 case elfcpp::R_ARM_NONE
:
3848 // Scan a relocation for a local symbol.
3849 // FIXME: This only handles a subset of relocation types used by Android
3850 // on ARM v5te devices.
3852 template<bool big_endian
>
3854 Target_arm
<big_endian
>::Scan::local(Symbol_table
* symtab
,
3857 Sized_relobj
<32, big_endian
>* object
,
3858 unsigned int data_shndx
,
3859 Output_section
* output_section
,
3860 const elfcpp::Rel
<32, big_endian
>& reloc
,
3861 unsigned int r_type
,
3862 const elfcpp::Sym
<32, big_endian
>&)
3864 r_type
= get_real_reloc_type(r_type
);
3867 case elfcpp::R_ARM_NONE
:
3870 case elfcpp::R_ARM_ABS32
:
3871 case elfcpp::R_ARM_ABS32_NOI
:
3872 // If building a shared library (or a position-independent
3873 // executable), we need to create a dynamic relocation for
3874 // this location. The relocation applied at link time will
3875 // apply the link-time value, so we flag the location with
3876 // an R_ARM_RELATIVE relocation so the dynamic loader can
3877 // relocate it easily.
3878 if (parameters
->options().output_is_position_independent())
3880 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
3881 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
3882 // If we are to add more other reloc types than R_ARM_ABS32,
3883 // we need to add check_non_pic(object, r_type) here.
3884 rel_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_ARM_RELATIVE
,
3885 output_section
, data_shndx
,
3886 reloc
.get_r_offset());
3890 case elfcpp::R_ARM_REL32
:
3891 case elfcpp::R_ARM_THM_CALL
:
3892 case elfcpp::R_ARM_CALL
:
3893 case elfcpp::R_ARM_PREL31
:
3894 case elfcpp::R_ARM_JUMP24
:
3895 case elfcpp::R_ARM_PLT32
:
3896 case elfcpp::R_ARM_THM_ABS5
:
3897 case elfcpp::R_ARM_ABS8
:
3898 case elfcpp::R_ARM_ABS12
:
3899 case elfcpp::R_ARM_ABS16
:
3900 case elfcpp::R_ARM_BASE_ABS
:
3901 case elfcpp::R_ARM_MOVW_ABS_NC
:
3902 case elfcpp::R_ARM_MOVT_ABS
:
3903 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
3904 case elfcpp::R_ARM_THM_MOVT_ABS
:
3905 case elfcpp::R_ARM_MOVW_PREL_NC
:
3906 case elfcpp::R_ARM_MOVT_PREL
:
3907 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
3908 case elfcpp::R_ARM_THM_MOVT_PREL
:
3911 case elfcpp::R_ARM_GOTOFF32
:
3912 // We need a GOT section:
3913 target
->got_section(symtab
, layout
);
3916 case elfcpp::R_ARM_BASE_PREL
:
3917 // FIXME: What about this?
3920 case elfcpp::R_ARM_GOT_BREL
:
3921 case elfcpp::R_ARM_GOT_PREL
:
3923 // The symbol requires a GOT entry.
3924 Output_data_got
<32, big_endian
>* got
=
3925 target
->got_section(symtab
, layout
);
3926 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
3927 if (got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
))
3929 // If we are generating a shared object, we need to add a
3930 // dynamic RELATIVE relocation for this symbol's GOT entry.
3931 if (parameters
->options().output_is_position_independent())
3933 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
3934 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
3935 rel_dyn
->add_local_relative(
3936 object
, r_sym
, elfcpp::R_ARM_RELATIVE
, got
,
3937 object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
));
3943 case elfcpp::R_ARM_TARGET1
:
3944 // This should have been mapped to another type already.
3946 case elfcpp::R_ARM_COPY
:
3947 case elfcpp::R_ARM_GLOB_DAT
:
3948 case elfcpp::R_ARM_JUMP_SLOT
:
3949 case elfcpp::R_ARM_RELATIVE
:
3950 // These are relocations which should only be seen by the
3951 // dynamic linker, and should never be seen here.
3952 gold_error(_("%s: unexpected reloc %u in object file"),
3953 object
->name().c_str(), r_type
);
3957 unsupported_reloc_local(object
, r_type
);
3962 // Report an unsupported relocation against a global symbol.
3964 template<bool big_endian
>
3966 Target_arm
<big_endian
>::Scan::unsupported_reloc_global(
3967 Sized_relobj
<32, big_endian
>* object
,
3968 unsigned int r_type
,
3971 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
3972 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
3975 // Scan a relocation for a global symbol.
3976 // FIXME: This only handles a subset of relocation types used by Android
3977 // on ARM v5te devices.
3979 template<bool big_endian
>
3981 Target_arm
<big_endian
>::Scan::global(Symbol_table
* symtab
,
3984 Sized_relobj
<32, big_endian
>* object
,
3985 unsigned int data_shndx
,
3986 Output_section
* output_section
,
3987 const elfcpp::Rel
<32, big_endian
>& reloc
,
3988 unsigned int r_type
,
3991 r_type
= get_real_reloc_type(r_type
);
3994 case elfcpp::R_ARM_NONE
:
3997 case elfcpp::R_ARM_ABS32
:
3998 case elfcpp::R_ARM_ABS32_NOI
:
4000 // Make a dynamic relocation if necessary.
4001 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
4003 if (target
->may_need_copy_reloc(gsym
))
4005 target
->copy_reloc(symtab
, layout
, object
,
4006 data_shndx
, output_section
, gsym
, reloc
);
4008 else if (gsym
->can_use_relative_reloc(false))
4010 // If we are to add more other reloc types than R_ARM_ABS32,
4011 // we need to add check_non_pic(object, r_type) here.
4012 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
4013 rel_dyn
->add_global_relative(gsym
, elfcpp::R_ARM_RELATIVE
,
4014 output_section
, object
,
4015 data_shndx
, reloc
.get_r_offset());
4019 // If we are to add more other reloc types than R_ARM_ABS32,
4020 // we need to add check_non_pic(object, r_type) here.
4021 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
4022 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
4023 data_shndx
, reloc
.get_r_offset());
4029 case elfcpp::R_ARM_MOVW_ABS_NC
:
4030 case elfcpp::R_ARM_MOVT_ABS
:
4031 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
4032 case elfcpp::R_ARM_THM_MOVT_ABS
:
4033 case elfcpp::R_ARM_MOVW_PREL_NC
:
4034 case elfcpp::R_ARM_MOVT_PREL
:
4035 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
4036 case elfcpp::R_ARM_THM_MOVT_PREL
:
4039 case elfcpp::R_ARM_THM_ABS5
:
4040 case elfcpp::R_ARM_ABS8
:
4041 case elfcpp::R_ARM_ABS12
:
4042 case elfcpp::R_ARM_ABS16
:
4043 case elfcpp::R_ARM_BASE_ABS
:
4045 // No dynamic relocs of this kinds.
4046 // Report the error in case of PIC.
4047 int flags
= Symbol::NON_PIC_REF
;
4048 if (gsym
->type() == elfcpp::STT_FUNC
4049 || gsym
->type() == elfcpp::STT_ARM_TFUNC
)
4050 flags
|= Symbol::FUNCTION_CALL
;
4051 if (gsym
->needs_dynamic_reloc(flags
))
4052 check_non_pic(object
, r_type
);
4056 case elfcpp::R_ARM_REL32
:
4057 case elfcpp::R_ARM_PREL31
:
4059 // Make a dynamic relocation if necessary.
4060 int flags
= Symbol::NON_PIC_REF
;
4061 if (gsym
->needs_dynamic_reloc(flags
))
4063 if (target
->may_need_copy_reloc(gsym
))
4065 target
->copy_reloc(symtab
, layout
, object
,
4066 data_shndx
, output_section
, gsym
, reloc
);
4070 check_non_pic(object
, r_type
);
4071 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
4072 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
4073 data_shndx
, reloc
.get_r_offset());
4079 case elfcpp::R_ARM_JUMP24
:
4080 case elfcpp::R_ARM_THM_CALL
:
4081 case elfcpp::R_ARM_CALL
:
4083 if (Target_arm
<big_endian
>::Scan::symbol_needs_plt_entry(gsym
))
4084 target
->make_plt_entry(symtab
, layout
, gsym
);
4085 // Make a dynamic relocation if necessary.
4086 int flags
= Symbol::NON_PIC_REF
;
4087 if (gsym
->type() == elfcpp::STT_FUNC
4088 || gsym
->type() == elfcpp::STT_ARM_TFUNC
)
4089 flags
|= Symbol::FUNCTION_CALL
;
4090 if (gsym
->needs_dynamic_reloc(flags
))
4092 if (target
->may_need_copy_reloc(gsym
))
4094 target
->copy_reloc(symtab
, layout
, object
,
4095 data_shndx
, output_section
, gsym
,
4100 check_non_pic(object
, r_type
);
4101 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
4102 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
4103 data_shndx
, reloc
.get_r_offset());
4109 case elfcpp::R_ARM_PLT32
:
4110 // If the symbol is fully resolved, this is just a relative
4111 // local reloc. Otherwise we need a PLT entry.
4112 if (gsym
->final_value_is_known())
4114 // If building a shared library, we can also skip the PLT entry
4115 // if the symbol is defined in the output file and is protected
4117 if (gsym
->is_defined()
4118 && !gsym
->is_from_dynobj()
4119 && !gsym
->is_preemptible())
4121 target
->make_plt_entry(symtab
, layout
, gsym
);
4124 case elfcpp::R_ARM_GOTOFF32
:
4125 // We need a GOT section.
4126 target
->got_section(symtab
, layout
);
4129 case elfcpp::R_ARM_BASE_PREL
:
4130 // FIXME: What about this?
4133 case elfcpp::R_ARM_GOT_BREL
:
4134 case elfcpp::R_ARM_GOT_PREL
:
4136 // The symbol requires a GOT entry.
4137 Output_data_got
<32, big_endian
>* got
=
4138 target
->got_section(symtab
, layout
);
4139 if (gsym
->final_value_is_known())
4140 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
4143 // If this symbol is not fully resolved, we need to add a
4144 // GOT entry with a dynamic relocation.
4145 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
4146 if (gsym
->is_from_dynobj()
4147 || gsym
->is_undefined()
4148 || gsym
->is_preemptible())
4149 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
,
4150 rel_dyn
, elfcpp::R_ARM_GLOB_DAT
);
4153 if (got
->add_global(gsym
, GOT_TYPE_STANDARD
))
4154 rel_dyn
->add_global_relative(
4155 gsym
, elfcpp::R_ARM_RELATIVE
, got
,
4156 gsym
->got_offset(GOT_TYPE_STANDARD
));
4162 case elfcpp::R_ARM_TARGET1
:
4163 // This should have been mapped to another type already.
4165 case elfcpp::R_ARM_COPY
:
4166 case elfcpp::R_ARM_GLOB_DAT
:
4167 case elfcpp::R_ARM_JUMP_SLOT
:
4168 case elfcpp::R_ARM_RELATIVE
:
4169 // These are relocations which should only be seen by the
4170 // dynamic linker, and should never be seen here.
4171 gold_error(_("%s: unexpected reloc %u in object file"),
4172 object
->name().c_str(), r_type
);
4176 unsupported_reloc_global(object
, r_type
, gsym
);
4181 // Process relocations for gc.
4183 template<bool big_endian
>
4185 Target_arm
<big_endian
>::gc_process_relocs(Symbol_table
* symtab
,
4187 Sized_relobj
<32, big_endian
>* object
,
4188 unsigned int data_shndx
,
4190 const unsigned char* prelocs
,
4192 Output_section
* output_section
,
4193 bool needs_special_offset_handling
,
4194 size_t local_symbol_count
,
4195 const unsigned char* plocal_symbols
)
4197 typedef Target_arm
<big_endian
> Arm
;
4198 typedef typename Target_arm
<big_endian
>::Scan Scan
;
4200 gold::gc_process_relocs
<32, big_endian
, Arm
, elfcpp::SHT_REL
, Scan
>(
4209 needs_special_offset_handling
,
4214 // Scan relocations for a section.
4216 template<bool big_endian
>
4218 Target_arm
<big_endian
>::scan_relocs(Symbol_table
* symtab
,
4220 Sized_relobj
<32, big_endian
>* object
,
4221 unsigned int data_shndx
,
4222 unsigned int sh_type
,
4223 const unsigned char* prelocs
,
4225 Output_section
* output_section
,
4226 bool needs_special_offset_handling
,
4227 size_t local_symbol_count
,
4228 const unsigned char* plocal_symbols
)
4230 typedef typename Target_arm
<big_endian
>::Scan Scan
;
4231 if (sh_type
== elfcpp::SHT_RELA
)
4233 gold_error(_("%s: unsupported RELA reloc section"),
4234 object
->name().c_str());
4238 gold::scan_relocs
<32, big_endian
, Target_arm
, elfcpp::SHT_REL
, Scan
>(
4247 needs_special_offset_handling
,
4252 // Finalize the sections.
4254 template<bool big_endian
>
4256 Target_arm
<big_endian
>::do_finalize_sections(
4258 const Input_objects
* input_objects
)
4260 // Merge processor-specific flags.
4261 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
4262 p
!= input_objects
->relobj_end();
4265 Arm_relobj
<big_endian
>* arm_relobj
=
4266 Arm_relobj
<big_endian
>::as_arm_relobj(*p
);
4267 this->merge_processor_specific_flags(
4269 arm_relobj
->processor_specific_flags());
4272 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
4273 p
!= input_objects
->dynobj_end();
4276 Arm_dynobj
<big_endian
>* arm_dynobj
=
4277 Arm_dynobj
<big_endian
>::as_arm_dynobj(*p
);
4278 this->merge_processor_specific_flags(
4280 arm_dynobj
->processor_specific_flags());
4283 // Fill in some more dynamic tags.
4284 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
4287 if (this->got_plt_
!= NULL
4288 && this->got_plt_
->output_section() != NULL
)
4289 odyn
->add_section_address(elfcpp::DT_PLTGOT
, this->got_plt_
);
4291 if (this->plt_
!= NULL
4292 && this->plt_
->output_section() != NULL
)
4294 const Output_data
* od
= this->plt_
->rel_plt();
4295 odyn
->add_section_size(elfcpp::DT_PLTRELSZ
, od
);
4296 odyn
->add_section_address(elfcpp::DT_JMPREL
, od
);
4297 odyn
->add_constant(elfcpp::DT_PLTREL
, elfcpp::DT_REL
);
4300 if (this->rel_dyn_
!= NULL
4301 && this->rel_dyn_
->output_section() != NULL
)
4303 const Output_data
* od
= this->rel_dyn_
;
4304 odyn
->add_section_address(elfcpp::DT_REL
, od
);
4305 odyn
->add_section_size(elfcpp::DT_RELSZ
, od
);
4306 odyn
->add_constant(elfcpp::DT_RELENT
,
4307 elfcpp::Elf_sizes
<32>::rel_size
);
4310 if (!parameters
->options().shared())
4312 // The value of the DT_DEBUG tag is filled in by the dynamic
4313 // linker at run time, and used by the debugger.
4314 odyn
->add_constant(elfcpp::DT_DEBUG
, 0);
4318 // Emit any relocs we saved in an attempt to avoid generating COPY
4320 if (this->copy_relocs_
.any_saved_relocs())
4321 this->copy_relocs_
.emit(this->rel_dyn_section(layout
));
4323 // For the ARM target, we need to add a PT_ARM_EXIDX segment for
4324 // the .ARM.exidx section.
4325 if (!layout
->script_options()->saw_phdrs_clause()
4326 && !parameters
->options().relocatable())
4328 Output_section
* exidx_section
=
4329 layout
->find_output_section(".ARM.exidx");
4331 if (exidx_section
!= NULL
4332 && exidx_section
->type() == elfcpp::SHT_ARM_EXIDX
)
4334 gold_assert(layout
->find_output_segment(elfcpp::PT_ARM_EXIDX
, 0, 0)
4336 Output_segment
* exidx_segment
=
4337 layout
->make_output_segment(elfcpp::PT_ARM_EXIDX
, elfcpp::PF_R
);
4338 exidx_segment
->add_output_section(exidx_section
, elfcpp::PF_R
,
4344 // Return whether a direct absolute static relocation needs to be applied.
4345 // In cases where Scan::local() or Scan::global() has created
4346 // a dynamic relocation other than R_ARM_RELATIVE, the addend
4347 // of the relocation is carried in the data, and we must not
4348 // apply the static relocation.
4350 template<bool big_endian
>
4352 Target_arm
<big_endian
>::Relocate::should_apply_static_reloc(
4353 const Sized_symbol
<32>* gsym
,
4356 Output_section
* output_section
)
4358 // If the output section is not allocated, then we didn't call
4359 // scan_relocs, we didn't create a dynamic reloc, and we must apply
4361 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
4364 // For local symbols, we will have created a non-RELATIVE dynamic
4365 // relocation only if (a) the output is position independent,
4366 // (b) the relocation is absolute (not pc- or segment-relative), and
4367 // (c) the relocation is not 32 bits wide.
4369 return !(parameters
->options().output_is_position_independent()
4370 && (ref_flags
& Symbol::ABSOLUTE_REF
)
4373 // For global symbols, we use the same helper routines used in the
4374 // scan pass. If we did not create a dynamic relocation, or if we
4375 // created a RELATIVE dynamic relocation, we should apply the static
4377 bool has_dyn
= gsym
->needs_dynamic_reloc(ref_flags
);
4378 bool is_rel
= (ref_flags
& Symbol::ABSOLUTE_REF
)
4379 && gsym
->can_use_relative_reloc(ref_flags
4380 & Symbol::FUNCTION_CALL
);
4381 return !has_dyn
|| is_rel
;
4384 // Perform a relocation.
4386 template<bool big_endian
>
4388 Target_arm
<big_endian
>::Relocate::relocate(
4389 const Relocate_info
<32, big_endian
>* relinfo
,
4391 Output_section
*output_section
,
4393 const elfcpp::Rel
<32, big_endian
>& rel
,
4394 unsigned int r_type
,
4395 const Sized_symbol
<32>* gsym
,
4396 const Symbol_value
<32>* psymval
,
4397 unsigned char* view
,
4398 Arm_address address
,
4399 section_size_type
/* view_size */ )
4401 typedef Arm_relocate_functions
<big_endian
> Arm_relocate_functions
;
4403 r_type
= get_real_reloc_type(r_type
);
4405 const Arm_relobj
<big_endian
>* object
=
4406 Arm_relobj
<big_endian
>::as_arm_relobj(relinfo
->object
);
4408 // If the final branch target of a relocation is THUMB instruction, this
4409 // is 1. Otherwise it is 0.
4410 Arm_address thumb_bit
= 0;
4411 Symbol_value
<32> symval
;
4412 if (relnum
!= Target_arm
<big_endian
>::fake_relnum_for_stubs
)
4416 // This is a global symbol. Determine if we use PLT and if the
4417 // final target is THUMB.
4418 if (gsym
->use_plt_offset(reloc_is_non_pic(r_type
)))
4420 // This uses a PLT, change the symbol value.
4421 symval
.set_output_value(target
->plt_section()->address()
4422 + gsym
->plt_offset());
4427 // Set thumb bit if symbol:
4428 // -Has type STT_ARM_TFUNC or
4429 // -Has type STT_FUNC, is defined and with LSB in value set.
4431 (((gsym
->type() == elfcpp::STT_ARM_TFUNC
)
4432 || (gsym
->type() == elfcpp::STT_FUNC
4433 && !gsym
->is_undefined()
4434 && ((psymval
->value(object
, 0) & 1) != 0)))
4441 // This is a local symbol. Determine if the final target is THUMB.
4442 // We saved this information when all the local symbols were read.
4443 elfcpp::Elf_types
<32>::Elf_WXword r_info
= rel
.get_r_info();
4444 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(r_info
);
4445 thumb_bit
= object
->local_symbol_is_thumb_function(r_sym
) ? 1 : 0;
4450 // This is a fake relocation synthesized for a stub. It does not have
4451 // a real symbol. We just look at the LSB of the symbol value to
4452 // determine if the target is THUMB or not.
4453 thumb_bit
= ((psymval
->value(object
, 0) & 1) != 0);
4456 // Strip LSB if this points to a THUMB target.
4458 && Target_arm
<big_endian
>::reloc_uses_thumb_bit(r_type
)
4459 && ((psymval
->value(object
, 0) & 1) != 0))
4461 Arm_address stripped_value
=
4462 psymval
->value(object
, 0) & ~static_cast<Arm_address
>(1);
4463 symval
.set_output_value(stripped_value
);
4467 // Get the GOT offset if needed.
4468 // The GOT pointer points to the end of the GOT section.
4469 // We need to subtract the size of the GOT section to get
4470 // the actual offset to use in the relocation.
4471 bool have_got_offset
= false;
4472 unsigned int got_offset
= 0;
4475 case elfcpp::R_ARM_GOT_BREL
:
4476 case elfcpp::R_ARM_GOT_PREL
:
4479 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
4480 got_offset
= (gsym
->got_offset(GOT_TYPE_STANDARD
)
4481 - target
->got_size());
4485 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
4486 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
4487 got_offset
= (object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
)
4488 - target
->got_size());
4490 have_got_offset
= true;
4497 typename
Arm_relocate_functions::Status reloc_status
=
4498 Arm_relocate_functions::STATUS_OKAY
;
4501 case elfcpp::R_ARM_NONE
:
4504 case elfcpp::R_ARM_ABS8
:
4505 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
4507 reloc_status
= Arm_relocate_functions::abs8(view
, object
, psymval
);
4510 case elfcpp::R_ARM_ABS12
:
4511 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
4513 reloc_status
= Arm_relocate_functions::abs12(view
, object
, psymval
);
4516 case elfcpp::R_ARM_ABS16
:
4517 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
4519 reloc_status
= Arm_relocate_functions::abs16(view
, object
, psymval
);
4522 case elfcpp::R_ARM_ABS32
:
4523 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
4525 reloc_status
= Arm_relocate_functions::abs32(view
, object
, psymval
,
4529 case elfcpp::R_ARM_ABS32_NOI
:
4530 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
4532 // No thumb bit for this relocation: (S + A)
4533 reloc_status
= Arm_relocate_functions::abs32(view
, object
, psymval
,
4537 case elfcpp::R_ARM_MOVW_ABS_NC
:
4538 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
4540 reloc_status
= Arm_relocate_functions::movw_abs_nc(view
, object
,
4544 gold_error(_("relocation R_ARM_MOVW_ABS_NC cannot be used when making"
4545 "a shared object; recompile with -fPIC"));
4548 case elfcpp::R_ARM_MOVT_ABS
:
4549 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
4551 reloc_status
= Arm_relocate_functions::movt_abs(view
, object
, psymval
);
4553 gold_error(_("relocation R_ARM_MOVT_ABS cannot be used when making"
4554 "a shared object; recompile with -fPIC"));
4557 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
4558 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
4560 reloc_status
= Arm_relocate_functions::thm_movw_abs_nc(view
, object
,
4564 gold_error(_("relocation R_ARM_THM_MOVW_ABS_NC cannot be used when"
4565 "making a shared object; recompile with -fPIC"));
4568 case elfcpp::R_ARM_THM_MOVT_ABS
:
4569 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
4571 reloc_status
= Arm_relocate_functions::thm_movt_abs(view
, object
,
4574 gold_error(_("relocation R_ARM_THM_MOVT_ABS cannot be used when"
4575 "making a shared object; recompile with -fPIC"));
4578 case elfcpp::R_ARM_MOVW_PREL_NC
:
4579 reloc_status
= Arm_relocate_functions::movw_prel_nc(view
, object
,
4584 case elfcpp::R_ARM_MOVT_PREL
:
4585 reloc_status
= Arm_relocate_functions::movt_prel(view
, object
,
4589 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
4590 reloc_status
= Arm_relocate_functions::thm_movw_prel_nc(view
, object
,
4595 case elfcpp::R_ARM_THM_MOVT_PREL
:
4596 reloc_status
= Arm_relocate_functions::thm_movt_prel(view
, object
,
4600 case elfcpp::R_ARM_REL32
:
4601 reloc_status
= Arm_relocate_functions::rel32(view
, object
, psymval
,
4602 address
, thumb_bit
);
4605 case elfcpp::R_ARM_THM_ABS5
:
4606 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
4608 reloc_status
= Arm_relocate_functions::thm_abs5(view
, object
, psymval
);
4611 case elfcpp::R_ARM_THM_CALL
:
4612 reloc_status
= Arm_relocate_functions::thm_call(view
, object
, psymval
,
4613 address
, thumb_bit
);
4616 case elfcpp::R_ARM_GOTOFF32
:
4618 Arm_address got_origin
;
4619 got_origin
= target
->got_plt_section()->address();
4620 reloc_status
= Arm_relocate_functions::rel32(view
, object
, psymval
,
4621 got_origin
, thumb_bit
);
4625 case elfcpp::R_ARM_BASE_PREL
:
4628 // Get the addressing origin of the output segment defining the
4629 // symbol gsym (AAELF 4.6.1.2 Relocation types)
4630 gold_assert(gsym
!= NULL
);
4631 if (gsym
->source() == Symbol::IN_OUTPUT_SEGMENT
)
4632 origin
= gsym
->output_segment()->vaddr();
4633 else if (gsym
->source () == Symbol::IN_OUTPUT_DATA
)
4634 origin
= gsym
->output_data()->address();
4637 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
4638 _("cannot find origin of R_ARM_BASE_PREL"));
4641 reloc_status
= Arm_relocate_functions::base_prel(view
, origin
, address
);
4645 case elfcpp::R_ARM_BASE_ABS
:
4647 if (!should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
4652 // Get the addressing origin of the output segment defining
4653 // the symbol gsym (AAELF 4.6.1.2 Relocation types).
4655 // R_ARM_BASE_ABS with the NULL symbol will give the
4656 // absolute address of the GOT origin (GOT_ORG) (see ARM IHI
4657 // 0044C (AAELF): 4.6.1.8 Proxy generating relocations).
4658 origin
= target
->got_plt_section()->address();
4659 else if (gsym
->source() == Symbol::IN_OUTPUT_SEGMENT
)
4660 origin
= gsym
->output_segment()->vaddr();
4661 else if (gsym
->source () == Symbol::IN_OUTPUT_DATA
)
4662 origin
= gsym
->output_data()->address();
4665 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
4666 _("cannot find origin of R_ARM_BASE_ABS"));
4670 reloc_status
= Arm_relocate_functions::base_abs(view
, origin
);
4674 case elfcpp::R_ARM_GOT_BREL
:
4675 gold_assert(have_got_offset
);
4676 reloc_status
= Arm_relocate_functions::got_brel(view
, got_offset
);
4679 case elfcpp::R_ARM_GOT_PREL
:
4680 gold_assert(have_got_offset
);
4681 // Get the address origin for GOT PLT, which is allocated right
4682 // after the GOT section, to calculate an absolute address of
4683 // the symbol GOT entry (got_origin + got_offset).
4684 Arm_address got_origin
;
4685 got_origin
= target
->got_plt_section()->address();
4686 reloc_status
= Arm_relocate_functions::got_prel(view
,
4687 got_origin
+ got_offset
,
4691 case elfcpp::R_ARM_PLT32
:
4692 gold_assert(gsym
== NULL
4693 || gsym
->has_plt_offset()
4694 || gsym
->final_value_is_known()
4695 || (gsym
->is_defined()
4696 && !gsym
->is_from_dynobj()
4697 && !gsym
->is_preemptible()));
4698 reloc_status
= Arm_relocate_functions::plt32(view
, object
, psymval
,
4699 address
, thumb_bit
);
4702 case elfcpp::R_ARM_CALL
:
4703 reloc_status
= Arm_relocate_functions::call(view
, object
, psymval
,
4704 address
, thumb_bit
);
4707 case elfcpp::R_ARM_JUMP24
:
4708 reloc_status
= Arm_relocate_functions::jump24(view
, object
, psymval
,
4709 address
, thumb_bit
);
4712 case elfcpp::R_ARM_PREL31
:
4713 reloc_status
= Arm_relocate_functions::prel31(view
, object
, psymval
,
4714 address
, thumb_bit
);
4717 case elfcpp::R_ARM_TARGET1
:
4718 // This should have been mapped to another type already.
4720 case elfcpp::R_ARM_COPY
:
4721 case elfcpp::R_ARM_GLOB_DAT
:
4722 case elfcpp::R_ARM_JUMP_SLOT
:
4723 case elfcpp::R_ARM_RELATIVE
:
4724 // These are relocations which should only be seen by the
4725 // dynamic linker, and should never be seen here.
4726 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
4727 _("unexpected reloc %u in object file"),
4732 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
4733 _("unsupported reloc %u"),
4738 // Report any errors.
4739 switch (reloc_status
)
4741 case Arm_relocate_functions::STATUS_OKAY
:
4743 case Arm_relocate_functions::STATUS_OVERFLOW
:
4744 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
4745 _("relocation overflow in relocation %u"),
4748 case Arm_relocate_functions::STATUS_BAD_RELOC
:
4749 gold_error_at_location(
4753 _("unexpected opcode while processing relocation %u"),
4763 // Relocate section data.
4765 template<bool big_endian
>
4767 Target_arm
<big_endian
>::relocate_section(
4768 const Relocate_info
<32, big_endian
>* relinfo
,
4769 unsigned int sh_type
,
4770 const unsigned char* prelocs
,
4772 Output_section
* output_section
,
4773 bool needs_special_offset_handling
,
4774 unsigned char* view
,
4775 Arm_address address
,
4776 section_size_type view_size
,
4777 const Reloc_symbol_changes
* reloc_symbol_changes
)
4779 typedef typename Target_arm
<big_endian
>::Relocate Arm_relocate
;
4780 gold_assert(sh_type
== elfcpp::SHT_REL
);
4782 Arm_input_section
<big_endian
>* arm_input_section
=
4783 this->find_arm_input_section(relinfo
->object
, relinfo
->data_shndx
);
4785 // This is an ARM input section and the view covers the whole output
4787 if (arm_input_section
!= NULL
)
4789 gold_assert(needs_special_offset_handling
);
4790 Arm_address section_address
= arm_input_section
->address();
4791 section_size_type section_size
= arm_input_section
->data_size();
4793 gold_assert((arm_input_section
->address() >= address
)
4794 && ((arm_input_section
->address()
4795 + arm_input_section
->data_size())
4796 <= (address
+ view_size
)));
4798 off_t offset
= section_address
- address
;
4801 view_size
= section_size
;
4804 gold::relocate_section
<32, big_endian
, Target_arm
, elfcpp::SHT_REL
,
4811 needs_special_offset_handling
,
4815 reloc_symbol_changes
);
4818 // Return the size of a relocation while scanning during a relocatable
4821 template<bool big_endian
>
4823 Target_arm
<big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
4824 unsigned int r_type
,
4827 r_type
= get_real_reloc_type(r_type
);
4830 case elfcpp::R_ARM_NONE
:
4833 case elfcpp::R_ARM_ABS8
:
4836 case elfcpp::R_ARM_ABS16
:
4837 case elfcpp::R_ARM_THM_ABS5
:
4840 case elfcpp::R_ARM_ABS32
:
4841 case elfcpp::R_ARM_ABS32_NOI
:
4842 case elfcpp::R_ARM_ABS12
:
4843 case elfcpp::R_ARM_BASE_ABS
:
4844 case elfcpp::R_ARM_REL32
:
4845 case elfcpp::R_ARM_THM_CALL
:
4846 case elfcpp::R_ARM_GOTOFF32
:
4847 case elfcpp::R_ARM_BASE_PREL
:
4848 case elfcpp::R_ARM_GOT_BREL
:
4849 case elfcpp::R_ARM_GOT_PREL
:
4850 case elfcpp::R_ARM_PLT32
:
4851 case elfcpp::R_ARM_CALL
:
4852 case elfcpp::R_ARM_JUMP24
:
4853 case elfcpp::R_ARM_PREL31
:
4854 case elfcpp::R_ARM_MOVW_ABS_NC
:
4855 case elfcpp::R_ARM_MOVT_ABS
:
4856 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
4857 case elfcpp::R_ARM_THM_MOVT_ABS
:
4858 case elfcpp::R_ARM_MOVW_PREL_NC
:
4859 case elfcpp::R_ARM_MOVT_PREL
:
4860 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
4861 case elfcpp::R_ARM_THM_MOVT_PREL
:
4864 case elfcpp::R_ARM_TARGET1
:
4865 // This should have been mapped to another type already.
4867 case elfcpp::R_ARM_COPY
:
4868 case elfcpp::R_ARM_GLOB_DAT
:
4869 case elfcpp::R_ARM_JUMP_SLOT
:
4870 case elfcpp::R_ARM_RELATIVE
:
4871 // These are relocations which should only be seen by the
4872 // dynamic linker, and should never be seen here.
4873 gold_error(_("%s: unexpected reloc %u in object file"),
4874 object
->name().c_str(), r_type
);
4878 object
->error(_("unsupported reloc %u in object file"), r_type
);
4883 // Scan the relocs during a relocatable link.
4885 template<bool big_endian
>
4887 Target_arm
<big_endian
>::scan_relocatable_relocs(
4888 Symbol_table
* symtab
,
4890 Sized_relobj
<32, big_endian
>* object
,
4891 unsigned int data_shndx
,
4892 unsigned int sh_type
,
4893 const unsigned char* prelocs
,
4895 Output_section
* output_section
,
4896 bool needs_special_offset_handling
,
4897 size_t local_symbol_count
,
4898 const unsigned char* plocal_symbols
,
4899 Relocatable_relocs
* rr
)
4901 gold_assert(sh_type
== elfcpp::SHT_REL
);
4903 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_REL
,
4904 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
4906 gold::scan_relocatable_relocs
<32, big_endian
, elfcpp::SHT_REL
,
4907 Scan_relocatable_relocs
>(
4915 needs_special_offset_handling
,
4921 // Relocate a section during a relocatable link.
4923 template<bool big_endian
>
4925 Target_arm
<big_endian
>::relocate_for_relocatable(
4926 const Relocate_info
<32, big_endian
>* relinfo
,
4927 unsigned int sh_type
,
4928 const unsigned char* prelocs
,
4930 Output_section
* output_section
,
4931 off_t offset_in_output_section
,
4932 const Relocatable_relocs
* rr
,
4933 unsigned char* view
,
4934 Arm_address view_address
,
4935 section_size_type view_size
,
4936 unsigned char* reloc_view
,
4937 section_size_type reloc_view_size
)
4939 gold_assert(sh_type
== elfcpp::SHT_REL
);
4941 gold::relocate_for_relocatable
<32, big_endian
, elfcpp::SHT_REL
>(
4946 offset_in_output_section
,
4955 // Return the value to use for a dynamic symbol which requires special
4956 // treatment. This is how we support equality comparisons of function
4957 // pointers across shared library boundaries, as described in the
4958 // processor specific ABI supplement.
4960 template<bool big_endian
>
4962 Target_arm
<big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
4964 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
4965 return this->plt_section()->address() + gsym
->plt_offset();
4968 // Map platform-specific relocs to real relocs
4970 template<bool big_endian
>
4972 Target_arm
<big_endian
>::get_real_reloc_type (unsigned int r_type
)
4976 case elfcpp::R_ARM_TARGET1
:
4977 // This is either R_ARM_ABS32 or R_ARM_REL32;
4978 return elfcpp::R_ARM_ABS32
;
4980 case elfcpp::R_ARM_TARGET2
:
4981 // This can be any reloc type but ususally is R_ARM_GOT_PREL
4982 return elfcpp::R_ARM_GOT_PREL
;
4989 // Whether if two EABI versions V1 and V2 are compatible.
4991 template<bool big_endian
>
4993 Target_arm
<big_endian
>::are_eabi_versions_compatible(
4994 elfcpp::Elf_Word v1
,
4995 elfcpp::Elf_Word v2
)
4997 // v4 and v5 are the same spec before and after it was released,
4998 // so allow mixing them.
4999 if ((v1
== elfcpp::EF_ARM_EABI_VER4
&& v2
== elfcpp::EF_ARM_EABI_VER5
)
5000 || (v1
== elfcpp::EF_ARM_EABI_VER5
&& v2
== elfcpp::EF_ARM_EABI_VER4
))
5006 // Combine FLAGS from an input object called NAME and the processor-specific
5007 // flags in the ELF header of the output. Much of this is adapted from the
5008 // processor-specific flags merging code in elf32_arm_merge_private_bfd_data
5009 // in bfd/elf32-arm.c.
5011 template<bool big_endian
>
5013 Target_arm
<big_endian
>::merge_processor_specific_flags(
5014 const std::string
& name
,
5015 elfcpp::Elf_Word flags
)
5017 if (this->are_processor_specific_flags_set())
5019 elfcpp::Elf_Word out_flags
= this->processor_specific_flags();
5021 // Nothing to merge if flags equal to those in output.
5022 if (flags
== out_flags
)
5025 // Complain about various flag mismatches.
5026 elfcpp::Elf_Word version1
= elfcpp::arm_eabi_version(flags
);
5027 elfcpp::Elf_Word version2
= elfcpp::arm_eabi_version(out_flags
);
5028 if (!this->are_eabi_versions_compatible(version1
, version2
))
5029 gold_error(_("Source object %s has EABI version %d but output has "
5030 "EABI version %d."),
5032 (flags
& elfcpp::EF_ARM_EABIMASK
) >> 24,
5033 (out_flags
& elfcpp::EF_ARM_EABIMASK
) >> 24);
5037 // If the input is the default architecture and had the default
5038 // flags then do not bother setting the flags for the output
5039 // architecture, instead allow future merges to do this. If no
5040 // future merges ever set these flags then they will retain their
5041 // uninitialised values, which surprise surprise, correspond
5042 // to the default values.
5046 // This is the first time, just copy the flags.
5047 // We only copy the EABI version for now.
5048 this->set_processor_specific_flags(flags
& elfcpp::EF_ARM_EABIMASK
);
5052 // Adjust ELF file header.
5053 template<bool big_endian
>
5055 Target_arm
<big_endian
>::do_adjust_elf_header(
5056 unsigned char* view
,
5059 gold_assert(len
== elfcpp::Elf_sizes
<32>::ehdr_size
);
5061 elfcpp::Ehdr
<32, big_endian
> ehdr(view
);
5062 unsigned char e_ident
[elfcpp::EI_NIDENT
];
5063 memcpy(e_ident
, ehdr
.get_e_ident(), elfcpp::EI_NIDENT
);
5065 if (elfcpp::arm_eabi_version(this->processor_specific_flags())
5066 == elfcpp::EF_ARM_EABI_UNKNOWN
)
5067 e_ident
[elfcpp::EI_OSABI
] = elfcpp::ELFOSABI_ARM
;
5069 e_ident
[elfcpp::EI_OSABI
] = 0;
5070 e_ident
[elfcpp::EI_ABIVERSION
] = 0;
5072 // FIXME: Do EF_ARM_BE8 adjustment.
5074 elfcpp::Ehdr_write
<32, big_endian
> oehdr(view
);
5075 oehdr
.put_e_ident(e_ident
);
5078 // do_make_elf_object to override the same function in the base class.
5079 // We need to use a target-specific sub-class of Sized_relobj<32, big_endian>
5080 // to store ARM specific information. Hence we need to have our own
5081 // ELF object creation.
5083 template<bool big_endian
>
5085 Target_arm
<big_endian
>::do_make_elf_object(
5086 const std::string
& name
,
5087 Input_file
* input_file
,
5088 off_t offset
, const elfcpp::Ehdr
<32, big_endian
>& ehdr
)
5090 int et
= ehdr
.get_e_type();
5091 if (et
== elfcpp::ET_REL
)
5093 Arm_relobj
<big_endian
>* obj
=
5094 new Arm_relobj
<big_endian
>(name
, input_file
, offset
, ehdr
);
5098 else if (et
== elfcpp::ET_DYN
)
5100 Sized_dynobj
<32, big_endian
>* obj
=
5101 new Arm_dynobj
<big_endian
>(name
, input_file
, offset
, ehdr
);
5107 gold_error(_("%s: unsupported ELF file type %d"),
5113 // Return whether a relocation type used the LSB to distinguish THUMB
5115 template<bool big_endian
>
5117 Target_arm
<big_endian
>::reloc_uses_thumb_bit(unsigned int r_type
)
5121 case elfcpp::R_ARM_PC24
:
5122 case elfcpp::R_ARM_ABS32
:
5123 case elfcpp::R_ARM_REL32
:
5124 case elfcpp::R_ARM_SBREL32
:
5125 case elfcpp::R_ARM_THM_CALL
:
5126 case elfcpp::R_ARM_GLOB_DAT
:
5127 case elfcpp::R_ARM_JUMP_SLOT
:
5128 case elfcpp::R_ARM_GOTOFF32
:
5129 case elfcpp::R_ARM_PLT32
:
5130 case elfcpp::R_ARM_CALL
:
5131 case elfcpp::R_ARM_JUMP24
:
5132 case elfcpp::R_ARM_THM_JUMP24
:
5133 case elfcpp::R_ARM_SBREL31
:
5134 case elfcpp::R_ARM_PREL31
:
5135 case elfcpp::R_ARM_MOVW_ABS_NC
:
5136 case elfcpp::R_ARM_MOVW_PREL_NC
:
5137 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
5138 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
5139 case elfcpp::R_ARM_THM_JUMP19
:
5140 case elfcpp::R_ARM_THM_ALU_PREL_11_0
:
5141 case elfcpp::R_ARM_ALU_PC_G0_NC
:
5142 case elfcpp::R_ARM_ALU_PC_G0
:
5143 case elfcpp::R_ARM_ALU_PC_G1_NC
:
5144 case elfcpp::R_ARM_ALU_PC_G1
:
5145 case elfcpp::R_ARM_ALU_PC_G2
:
5146 case elfcpp::R_ARM_ALU_SB_G0_NC
:
5147 case elfcpp::R_ARM_ALU_SB_G0
:
5148 case elfcpp::R_ARM_ALU_SB_G1_NC
:
5149 case elfcpp::R_ARM_ALU_SB_G1
:
5150 case elfcpp::R_ARM_ALU_SB_G2
:
5151 case elfcpp::R_ARM_MOVW_BREL_NC
:
5152 case elfcpp::R_ARM_MOVW_BREL
:
5153 case elfcpp::R_ARM_THM_MOVW_BREL_NC
:
5154 case elfcpp::R_ARM_THM_MOVW_BREL
:
5161 // Stub-generation methods for Target_arm.
5163 // Make a new Arm_input_section object.
5165 template<bool big_endian
>
5166 Arm_input_section
<big_endian
>*
5167 Target_arm
<big_endian
>::new_arm_input_section(
5171 Input_section_specifier
iss(relobj
, shndx
);
5173 Arm_input_section
<big_endian
>* arm_input_section
=
5174 new Arm_input_section
<big_endian
>(relobj
, shndx
);
5175 arm_input_section
->init();
5177 // Register new Arm_input_section in map for look-up.
5178 std::pair
<typename
Arm_input_section_map::iterator
, bool> ins
=
5179 this->arm_input_section_map_
.insert(std::make_pair(iss
, arm_input_section
));
5181 // Make sure that it we have not created another Arm_input_section
5182 // for this input section already.
5183 gold_assert(ins
.second
);
5185 return arm_input_section
;
5188 // Find the Arm_input_section object corresponding to the SHNDX-th input
5189 // section of RELOBJ.
5191 template<bool big_endian
>
5192 Arm_input_section
<big_endian
>*
5193 Target_arm
<big_endian
>::find_arm_input_section(
5195 unsigned int shndx
) const
5197 Input_section_specifier
iss(relobj
, shndx
);
5198 typename
Arm_input_section_map::const_iterator p
=
5199 this->arm_input_section_map_
.find(iss
);
5200 return (p
!= this->arm_input_section_map_
.end()) ? p
->second
: NULL
;
5203 // Make a new stub table.
5205 template<bool big_endian
>
5206 Stub_table
<big_endian
>*
5207 Target_arm
<big_endian
>::new_stub_table(Arm_input_section
<big_endian
>* owner
)
5209 Stub_table
<big_endian
>* stub_table
=
5210 new Stub_table
<big_endian
>(owner
);
5211 this->stub_tables_
.push_back(stub_table
);
5213 stub_table
->set_address(owner
->address() + owner
->data_size());
5214 stub_table
->set_file_offset(owner
->offset() + owner
->data_size());
5215 stub_table
->finalize_data_size();
5220 // Scan a relocation for stub generation.
5222 template<bool big_endian
>
5224 Target_arm
<big_endian
>::scan_reloc_for_stub(
5225 const Relocate_info
<32, big_endian
>* relinfo
,
5226 unsigned int r_type
,
5227 const Sized_symbol
<32>* gsym
,
5229 const Symbol_value
<32>* psymval
,
5230 elfcpp::Elf_types
<32>::Elf_Swxword addend
,
5231 Arm_address address
)
5233 typedef typename Target_arm
<big_endian
>::Relocate Relocate
;
5235 const Arm_relobj
<big_endian
>* arm_relobj
=
5236 Arm_relobj
<big_endian
>::as_arm_relobj(relinfo
->object
);
5238 bool target_is_thumb
;
5239 Symbol_value
<32> symval
;
5242 // This is a global symbol. Determine if we use PLT and if the
5243 // final target is THUMB.
5244 if (gsym
->use_plt_offset(Relocate::reloc_is_non_pic(r_type
)))
5246 // This uses a PLT, change the symbol value.
5247 symval
.set_output_value(this->plt_section()->address()
5248 + gsym
->plt_offset());
5250 target_is_thumb
= false;
5252 else if (gsym
->is_undefined())
5253 // There is no need to generate a stub symbol is undefined.
5258 ((gsym
->type() == elfcpp::STT_ARM_TFUNC
)
5259 || (gsym
->type() == elfcpp::STT_FUNC
5260 && !gsym
->is_undefined()
5261 && ((psymval
->value(arm_relobj
, 0) & 1) != 0)));
5266 // This is a local symbol. Determine if the final target is THUMB.
5267 target_is_thumb
= arm_relobj
->local_symbol_is_thumb_function(r_sym
);
5270 // Strip LSB if this points to a THUMB target.
5272 && Target_arm
<big_endian
>::reloc_uses_thumb_bit(r_type
)
5273 && ((psymval
->value(arm_relobj
, 0) & 1) != 0))
5275 Arm_address stripped_value
=
5276 psymval
->value(arm_relobj
, 0) & ~static_cast<Arm_address
>(1);
5277 symval
.set_output_value(stripped_value
);
5281 // Get the symbol value.
5282 Symbol_value
<32>::Value value
= psymval
->value(arm_relobj
, 0);
5284 // Owing to pipelining, the PC relative branches below actually skip
5285 // two instructions when the branch offset is 0.
5286 Arm_address destination
;
5289 case elfcpp::R_ARM_CALL
:
5290 case elfcpp::R_ARM_JUMP24
:
5291 case elfcpp::R_ARM_PLT32
:
5293 destination
= value
+ addend
+ 8;
5295 case elfcpp::R_ARM_THM_CALL
:
5296 case elfcpp::R_ARM_THM_XPC22
:
5297 case elfcpp::R_ARM_THM_JUMP24
:
5298 case elfcpp::R_ARM_THM_JUMP19
:
5300 destination
= value
+ addend
+ 4;
5306 Stub_type stub_type
=
5307 Reloc_stub::stub_type_for_reloc(r_type
, address
, destination
,
5310 // This reloc does not need a stub.
5311 if (stub_type
== arm_stub_none
)
5314 // Try looking up an existing stub from a stub table.
5315 Stub_table
<big_endian
>* stub_table
=
5316 arm_relobj
->stub_table(relinfo
->data_shndx
);
5317 gold_assert(stub_table
!= NULL
);
5319 // Locate stub by destination.
5320 Reloc_stub::Key
stub_key(stub_type
, gsym
, arm_relobj
, r_sym
, addend
);
5322 // Create a stub if there is not one already
5323 Reloc_stub
* stub
= stub_table
->find_reloc_stub(stub_key
);
5326 // create a new stub and add it to stub table.
5327 stub
= this->stub_factory().make_reloc_stub(stub_type
);
5328 stub_table
->add_reloc_stub(stub
, stub_key
);
5331 // Record the destination address.
5332 stub
->set_destination_address(destination
5333 | (target_is_thumb
? 1 : 0));
5336 // This function scans a relocation sections for stub generation.
5337 // The template parameter Relocate must be a class type which provides
5338 // a single function, relocate(), which implements the machine
5339 // specific part of a relocation.
5341 // BIG_ENDIAN is the endianness of the data. SH_TYPE is the section type:
5342 // SHT_REL or SHT_RELA.
5344 // PRELOCS points to the relocation data. RELOC_COUNT is the number
5345 // of relocs. OUTPUT_SECTION is the output section.
5346 // NEEDS_SPECIAL_OFFSET_HANDLING is true if input offsets need to be
5347 // mapped to output offsets.
5349 // VIEW is the section data, VIEW_ADDRESS is its memory address, and
5350 // VIEW_SIZE is the size. These refer to the input section, unless
5351 // NEEDS_SPECIAL_OFFSET_HANDLING is true, in which case they refer to
5352 // the output section.
5354 template<bool big_endian
>
5355 template<int sh_type
>
5357 Target_arm
<big_endian
>::scan_reloc_section_for_stubs(
5358 const Relocate_info
<32, big_endian
>* relinfo
,
5359 const unsigned char* prelocs
,
5361 Output_section
* output_section
,
5362 bool needs_special_offset_handling
,
5363 const unsigned char* view
,
5364 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
5367 typedef typename Reloc_types
<sh_type
, 32, big_endian
>::Reloc Reltype
;
5368 const int reloc_size
=
5369 Reloc_types
<sh_type
, 32, big_endian
>::reloc_size
;
5371 Arm_relobj
<big_endian
>* arm_object
=
5372 Arm_relobj
<big_endian
>::as_arm_relobj(relinfo
->object
);
5373 unsigned int local_count
= arm_object
->local_symbol_count();
5375 Comdat_behavior comdat_behavior
= CB_UNDETERMINED
;
5377 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
5379 Reltype
reloc(prelocs
);
5381 typename
elfcpp::Elf_types
<32>::Elf_WXword r_info
= reloc
.get_r_info();
5382 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(r_info
);
5383 unsigned int r_type
= elfcpp::elf_r_type
<32>(r_info
);
5385 r_type
= this->get_real_reloc_type(r_type
);
5387 // Only a few relocation types need stubs.
5388 if ((r_type
!= elfcpp::R_ARM_CALL
)
5389 && (r_type
!= elfcpp::R_ARM_JUMP24
)
5390 && (r_type
!= elfcpp::R_ARM_PLT32
)
5391 && (r_type
!= elfcpp::R_ARM_THM_CALL
)
5392 && (r_type
!= elfcpp::R_ARM_THM_XPC22
)
5393 && (r_type
!= elfcpp::R_ARM_THM_JUMP24
)
5394 && (r_type
!= elfcpp::R_ARM_THM_JUMP19
))
5397 section_offset_type offset
=
5398 convert_to_section_size_type(reloc
.get_r_offset());
5400 if (needs_special_offset_handling
)
5402 offset
= output_section
->output_offset(relinfo
->object
,
5403 relinfo
->data_shndx
,
5410 Stub_addend_reader
<sh_type
, big_endian
> stub_addend_reader
;
5411 elfcpp::Elf_types
<32>::Elf_Swxword addend
=
5412 stub_addend_reader(r_type
, view
+ offset
, reloc
);
5414 const Sized_symbol
<32>* sym
;
5416 Symbol_value
<32> symval
;
5417 const Symbol_value
<32> *psymval
;
5418 if (r_sym
< local_count
)
5421 psymval
= arm_object
->local_symbol(r_sym
);
5423 // If the local symbol belongs to a section we are discarding,
5424 // and that section is a debug section, try to find the
5425 // corresponding kept section and map this symbol to its
5426 // counterpart in the kept section. The symbol must not
5427 // correspond to a section we are folding.
5429 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
5431 && shndx
!= elfcpp::SHN_UNDEF
5432 && !arm_object
->is_section_included(shndx
)
5433 && !(relinfo
->symtab
->is_section_folded(arm_object
, shndx
)))
5435 if (comdat_behavior
== CB_UNDETERMINED
)
5438 arm_object
->section_name(relinfo
->data_shndx
);
5439 comdat_behavior
= get_comdat_behavior(name
.c_str());
5441 if (comdat_behavior
== CB_PRETEND
)
5444 typename
elfcpp::Elf_types
<32>::Elf_Addr value
=
5445 arm_object
->map_to_kept_section(shndx
, &found
);
5447 symval
.set_output_value(value
+ psymval
->input_value());
5449 symval
.set_output_value(0);
5453 symval
.set_output_value(0);
5455 symval
.set_no_output_symtab_entry();
5461 const Symbol
* gsym
= arm_object
->global_symbol(r_sym
);
5462 gold_assert(gsym
!= NULL
);
5463 if (gsym
->is_forwarder())
5464 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
5466 sym
= static_cast<const Sized_symbol
<32>*>(gsym
);
5467 if (sym
->has_symtab_index())
5468 symval
.set_output_symtab_index(sym
->symtab_index());
5470 symval
.set_no_output_symtab_entry();
5472 // We need to compute the would-be final value of this global
5474 const Symbol_table
* symtab
= relinfo
->symtab
;
5475 const Sized_symbol
<32>* sized_symbol
=
5476 symtab
->get_sized_symbol
<32>(gsym
);
5477 Symbol_table::Compute_final_value_status status
;
5479 symtab
->compute_final_value
<32>(sized_symbol
, &status
);
5481 // Skip this if the symbol has not output section.
5482 if (status
== Symbol_table::CFVS_NO_OUTPUT_SECTION
)
5485 symval
.set_output_value(value
);
5489 // If symbol is a section symbol, we don't know the actual type of
5490 // destination. Give up.
5491 if (psymval
->is_section_symbol())
5494 this->scan_reloc_for_stub(relinfo
, r_type
, sym
, r_sym
, psymval
,
5495 addend
, view_address
+ offset
);
5499 // Scan an input section for stub generation.
5501 template<bool big_endian
>
5503 Target_arm
<big_endian
>::scan_section_for_stubs(
5504 const Relocate_info
<32, big_endian
>* relinfo
,
5505 unsigned int sh_type
,
5506 const unsigned char* prelocs
,
5508 Output_section
* output_section
,
5509 bool needs_special_offset_handling
,
5510 const unsigned char* view
,
5511 Arm_address view_address
,
5512 section_size_type view_size
)
5514 if (sh_type
== elfcpp::SHT_REL
)
5515 this->scan_reloc_section_for_stubs
<elfcpp::SHT_REL
>(
5520 needs_special_offset_handling
,
5524 else if (sh_type
== elfcpp::SHT_RELA
)
5525 // We do not support RELA type relocations yet. This is provided for
5527 this->scan_reloc_section_for_stubs
<elfcpp::SHT_RELA
>(
5532 needs_special_offset_handling
,
5540 // Group input sections for stub generation.
5542 // We goup input sections in an output sections so that the total size,
5543 // including any padding space due to alignment is smaller than GROUP_SIZE
5544 // unless the only input section in group is bigger than GROUP_SIZE already.
5545 // Then an ARM stub table is created to follow the last input section
5546 // in group. For each group an ARM stub table is created an is placed
5547 // after the last group. If STUB_ALWATS_AFTER_BRANCH is false, we further
5548 // extend the group after the stub table.
5550 template<bool big_endian
>
5552 Target_arm
<big_endian
>::group_sections(
5554 section_size_type group_size
,
5555 bool stubs_always_after_branch
)
5557 // Group input sections and insert stub table
5558 Layout::Section_list section_list
;
5559 layout
->get_allocated_sections(§ion_list
);
5560 for (Layout::Section_list::const_iterator p
= section_list
.begin();
5561 p
!= section_list
.end();
5564 Arm_output_section
<big_endian
>* output_section
=
5565 Arm_output_section
<big_endian
>::as_arm_output_section(*p
);
5566 output_section
->group_sections(group_size
, stubs_always_after_branch
,
5571 // Relaxation hook. This is where we do stub generation.
5573 template<bool big_endian
>
5575 Target_arm
<big_endian
>::do_relax(
5577 const Input_objects
* input_objects
,
5578 Symbol_table
* symtab
,
5581 // No need to generate stubs if this is a relocatable link.
5582 gold_assert(!parameters
->options().relocatable());
5584 // If this is the first pass, we need to group input sections into
5588 // Determine the stub group size. The group size is the absolute
5589 // value of the parameter --stub-group-size. If --stub-group-size
5590 // is passed a negative value, we restict stubs to be always after
5591 // the stubbed branches.
5592 int32_t stub_group_size_param
=
5593 parameters
->options().stub_group_size();
5594 bool stubs_always_after_branch
= stub_group_size_param
< 0;
5595 section_size_type stub_group_size
= abs(stub_group_size_param
);
5597 if (stub_group_size
== 1)
5600 // Thumb branch range is +-4MB has to be used as the default
5601 // maximum size (a given section can contain both ARM and Thumb
5602 // code, so the worst case has to be taken into account).
5604 // This value is 24K less than that, which allows for 2025
5605 // 12-byte stubs. If we exceed that, then we will fail to link.
5606 // The user will have to relink with an explicit group size
5608 stub_group_size
= 4170000;
5611 group_sections(layout
, stub_group_size
, stubs_always_after_branch
);
5614 // clear changed flags for all stub_tables
5615 typedef typename
Stub_table_list::iterator Stub_table_iterator
;
5616 for (Stub_table_iterator sp
= this->stub_tables_
.begin();
5617 sp
!= this->stub_tables_
.end();
5619 (*sp
)->set_has_been_changed(false);
5621 // scan relocs for stubs
5622 for (Input_objects::Relobj_iterator op
= input_objects
->relobj_begin();
5623 op
!= input_objects
->relobj_end();
5626 Arm_relobj
<big_endian
>* arm_relobj
=
5627 Arm_relobj
<big_endian
>::as_arm_relobj(*op
);
5628 arm_relobj
->scan_sections_for_stubs(this, symtab
, layout
);
5631 bool any_stub_table_changed
= false;
5632 for (Stub_table_iterator sp
= this->stub_tables_
.begin();
5633 (sp
!= this->stub_tables_
.end()) && !any_stub_table_changed
;
5636 if ((*sp
)->has_been_changed())
5637 any_stub_table_changed
= true;
5640 return any_stub_table_changed
;
5645 template<bool big_endian
>
5647 Target_arm
<big_endian
>::relocate_stub(
5649 const Relocate_info
<32, big_endian
>* relinfo
,
5650 Output_section
* output_section
,
5651 unsigned char* view
,
5652 Arm_address address
,
5653 section_size_type view_size
)
5656 const Stub_template
* stub_template
= stub
->stub_template();
5657 for (size_t i
= 0; i
< stub_template
->reloc_count(); i
++)
5659 size_t reloc_insn_index
= stub_template
->reloc_insn_index(i
);
5660 const Insn_template
* insn
= &stub_template
->insns()[reloc_insn_index
];
5662 unsigned int r_type
= insn
->r_type();
5663 section_size_type reloc_offset
= stub_template
->reloc_offset(i
);
5664 section_size_type reloc_size
= insn
->size();
5665 gold_assert(reloc_offset
+ reloc_size
<= view_size
);
5667 // This is the address of the stub destination.
5668 Arm_address target
= stub
->reloc_target(i
);
5669 Symbol_value
<32> symval
;
5670 symval
.set_output_value(target
);
5672 // Synthesize a fake reloc just in case. We don't have a symbol so
5674 unsigned char reloc_buffer
[elfcpp::Elf_sizes
<32>::rel_size
];
5675 memset(reloc_buffer
, 0, sizeof(reloc_buffer
));
5676 elfcpp::Rel_write
<32, big_endian
> reloc_write(reloc_buffer
);
5677 reloc_write
.put_r_offset(reloc_offset
);
5678 reloc_write
.put_r_info(elfcpp::elf_r_info
<32>(0, r_type
));
5679 elfcpp::Rel
<32, big_endian
> rel(reloc_buffer
);
5681 relocate
.relocate(relinfo
, this, output_section
,
5682 this->fake_relnum_for_stubs
, rel
, r_type
,
5683 NULL
, &symval
, view
+ reloc_offset
,
5684 address
+ reloc_offset
, reloc_size
);
5688 // The selector for arm object files.
5690 template<bool big_endian
>
5691 class Target_selector_arm
: public Target_selector
5694 Target_selector_arm()
5695 : Target_selector(elfcpp::EM_ARM
, 32, big_endian
,
5696 (big_endian
? "elf32-bigarm" : "elf32-littlearm"))
5700 do_instantiate_target()
5701 { return new Target_arm
<big_endian
>(); }
5704 Target_selector_arm
<false> target_selector_arm
;
5705 Target_selector_arm
<true> target_selector_armbe
;
5707 } // End anonymous namespace.