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"
49 #include "attributes.h"
56 template<bool big_endian
>
57 class Output_data_plt_arm
;
59 template<bool big_endian
>
62 template<bool big_endian
>
63 class Arm_input_section
;
65 template<bool big_endian
>
66 class Arm_output_section
;
68 template<bool big_endian
>
71 template<bool big_endian
>
75 typedef elfcpp::Elf_types
<32>::Elf_Addr Arm_address
;
77 // Maximum branch offsets for ARM, THUMB and THUMB2.
78 const int32_t ARM_MAX_FWD_BRANCH_OFFSET
= ((((1 << 23) - 1) << 2) + 8);
79 const int32_t ARM_MAX_BWD_BRANCH_OFFSET
= ((-((1 << 23) << 2)) + 8);
80 const int32_t THM_MAX_FWD_BRANCH_OFFSET
= ((1 << 22) -2 + 4);
81 const int32_t THM_MAX_BWD_BRANCH_OFFSET
= (-(1 << 22) + 4);
82 const int32_t THM2_MAX_FWD_BRANCH_OFFSET
= (((1 << 24) - 2) + 4);
83 const int32_t THM2_MAX_BWD_BRANCH_OFFSET
= (-(1 << 24) + 4);
85 // The arm target class.
87 // This is a very simple port of gold for ARM-EABI. It is intended for
88 // supporting Android only for the time being. Only these relocation types
117 // R_ARM_THM_MOVW_ABS_NC
118 // R_ARM_THM_MOVT_ABS
119 // R_ARM_MOVW_PREL_NC
121 // R_ARM_THM_MOVW_PREL_NC
122 // R_ARM_THM_MOVT_PREL
125 // - Support more relocation types as needed.
126 // - Make PLTs more flexible for different architecture features like
128 // There are probably a lot more.
130 // Instruction template class. This class is similar to the insn_sequence
131 // struct in bfd/elf32-arm.c.
136 // Types of instruction templates.
140 // THUMB16_SPECIAL_TYPE is used by sub-classes of Stub for instruction
141 // templates with class-specific semantics. Currently this is used
142 // only by the Cortex_a8_stub class for handling condition codes in
143 // conditional branches.
144 THUMB16_SPECIAL_TYPE
,
150 // Factory methods to create instruction templates in different formats.
152 static const Insn_template
153 thumb16_insn(uint32_t data
)
154 { return Insn_template(data
, THUMB16_TYPE
, elfcpp::R_ARM_NONE
, 0); }
156 // A Thumb conditional branch, in which the proper condition is inserted
157 // when we build the stub.
158 static const Insn_template
159 thumb16_bcond_insn(uint32_t data
)
160 { return Insn_template(data
, THUMB16_SPECIAL_TYPE
, elfcpp::R_ARM_NONE
, 1); }
162 static const Insn_template
163 thumb32_insn(uint32_t data
)
164 { return Insn_template(data
, THUMB32_TYPE
, elfcpp::R_ARM_NONE
, 0); }
166 static const Insn_template
167 thumb32_b_insn(uint32_t data
, int reloc_addend
)
169 return Insn_template(data
, THUMB32_TYPE
, elfcpp::R_ARM_THM_JUMP24
,
173 static const Insn_template
174 arm_insn(uint32_t data
)
175 { return Insn_template(data
, ARM_TYPE
, elfcpp::R_ARM_NONE
, 0); }
177 static const Insn_template
178 arm_rel_insn(unsigned data
, int reloc_addend
)
179 { return Insn_template(data
, ARM_TYPE
, elfcpp::R_ARM_JUMP24
, reloc_addend
); }
181 static const Insn_template
182 data_word(unsigned data
, unsigned int r_type
, int reloc_addend
)
183 { return Insn_template(data
, DATA_TYPE
, r_type
, reloc_addend
); }
185 // Accessors. This class is used for read-only objects so no modifiers
190 { return this->data_
; }
192 // Return the instruction sequence type of this.
195 { return this->type_
; }
197 // Return the ARM relocation type of this.
200 { return this->r_type_
; }
204 { return this->reloc_addend_
; }
206 // Return size of instruction template in bytes.
210 // Return byte-alignment of instruction template.
215 // We make the constructor private to ensure that only the factory
218 Insn_template(unsigned data
, Type type
, unsigned int r_type
, int reloc_addend
)
219 : data_(data
), type_(type
), r_type_(r_type
), reloc_addend_(reloc_addend
)
222 // Instruction specific data. This is used to store information like
223 // some of the instruction bits.
225 // Instruction template type.
227 // Relocation type if there is a relocation or R_ARM_NONE otherwise.
228 unsigned int r_type_
;
229 // Relocation addend.
230 int32_t reloc_addend_
;
233 // Macro for generating code to stub types. One entry per long/short
237 DEF_STUB(long_branch_any_any) \
238 DEF_STUB(long_branch_v4t_arm_thumb) \
239 DEF_STUB(long_branch_thumb_only) \
240 DEF_STUB(long_branch_v4t_thumb_thumb) \
241 DEF_STUB(long_branch_v4t_thumb_arm) \
242 DEF_STUB(short_branch_v4t_thumb_arm) \
243 DEF_STUB(long_branch_any_arm_pic) \
244 DEF_STUB(long_branch_any_thumb_pic) \
245 DEF_STUB(long_branch_v4t_thumb_thumb_pic) \
246 DEF_STUB(long_branch_v4t_arm_thumb_pic) \
247 DEF_STUB(long_branch_v4t_thumb_arm_pic) \
248 DEF_STUB(long_branch_thumb_only_pic) \
249 DEF_STUB(a8_veneer_b_cond) \
250 DEF_STUB(a8_veneer_b) \
251 DEF_STUB(a8_veneer_bl) \
252 DEF_STUB(a8_veneer_blx)
256 #define DEF_STUB(x) arm_stub_##x,
262 // First reloc stub type.
263 arm_stub_reloc_first
= arm_stub_long_branch_any_any
,
264 // Last reloc stub type.
265 arm_stub_reloc_last
= arm_stub_long_branch_thumb_only_pic
,
267 // First Cortex-A8 stub type.
268 arm_stub_cortex_a8_first
= arm_stub_a8_veneer_b_cond
,
269 // Last Cortex-A8 stub type.
270 arm_stub_cortex_a8_last
= arm_stub_a8_veneer_blx
,
273 arm_stub_type_last
= arm_stub_a8_veneer_blx
277 // Stub template class. Templates are meant to be read-only objects.
278 // A stub template for a stub type contains all read-only attributes
279 // common to all stubs of the same type.
284 Stub_template(Stub_type
, const Insn_template
*, size_t);
292 { return this->type_
; }
294 // Return an array of instruction templates.
297 { return this->insns_
; }
299 // Return size of template in number of instructions.
302 { return this->insn_count_
; }
304 // Return size of template in bytes.
307 { return this->size_
; }
309 // Return alignment of the stub template.
312 { return this->alignment_
; }
314 // Return whether entry point is in thumb mode.
316 entry_in_thumb_mode() const
317 { return this->entry_in_thumb_mode_
; }
319 // Return number of relocations in this template.
322 { return this->relocs_
.size(); }
324 // Return index of the I-th instruction with relocation.
326 reloc_insn_index(size_t i
) const
328 gold_assert(i
< this->relocs_
.size());
329 return this->relocs_
[i
].first
;
332 // Return the offset of the I-th instruction with relocation from the
333 // beginning of the stub.
335 reloc_offset(size_t i
) const
337 gold_assert(i
< this->relocs_
.size());
338 return this->relocs_
[i
].second
;
342 // This contains information about an instruction template with a relocation
343 // and its offset from start of stub.
344 typedef std::pair
<size_t, section_size_type
> Reloc
;
346 // A Stub_template may not be copied. We want to share templates as much
348 Stub_template(const Stub_template
&);
349 Stub_template
& operator=(const Stub_template
&);
353 // Points to an array of Insn_templates.
354 const Insn_template
* insns_
;
355 // Number of Insn_templates in insns_[].
357 // Size of templated instructions in bytes.
359 // Alignment of templated instructions.
361 // Flag to indicate if entry is in thumb mode.
362 bool entry_in_thumb_mode_
;
363 // A table of reloc instruction indices and offsets. We can find these by
364 // looking at the instruction templates but we pre-compute and then stash
365 // them here for speed.
366 std::vector
<Reloc
> relocs_
;
370 // A class for code stubs. This is a base class for different type of
371 // stubs used in the ARM target.
377 static const section_offset_type invalid_offset
=
378 static_cast<section_offset_type
>(-1);
381 Stub(const Stub_template
* stub_template
)
382 : stub_template_(stub_template
), offset_(invalid_offset
)
389 // Return the stub template.
391 stub_template() const
392 { return this->stub_template_
; }
394 // Return offset of code stub from beginning of its containing stub table.
398 gold_assert(this->offset_
!= invalid_offset
);
399 return this->offset_
;
402 // Set offset of code stub from beginning of its containing stub table.
404 set_offset(section_offset_type offset
)
405 { this->offset_
= offset
; }
407 // Return the relocation target address of the i-th relocation in the
408 // stub. This must be defined in a child class.
410 reloc_target(size_t i
)
411 { return this->do_reloc_target(i
); }
413 // Write a stub at output VIEW. BIG_ENDIAN select how a stub is written.
415 write(unsigned char* view
, section_size_type view_size
, bool big_endian
)
416 { this->do_write(view
, view_size
, big_endian
); }
418 // Return the instruction for THUMB16_SPECIAL_TYPE instruction template
419 // for the i-th instruction.
421 thumb16_special(size_t i
)
422 { return this->do_thumb16_special(i
); }
425 // This must be defined in the child class.
427 do_reloc_target(size_t) = 0;
429 // This may be overridden in the child class.
431 do_write(unsigned char* view
, section_size_type view_size
, bool big_endian
)
434 this->do_fixed_endian_write
<true>(view
, view_size
);
436 this->do_fixed_endian_write
<false>(view
, view_size
);
439 // This must be overridden if a child class uses the THUMB16_SPECIAL_TYPE
440 // instruction template.
442 do_thumb16_special(size_t)
443 { gold_unreachable(); }
446 // A template to implement do_write.
447 template<bool big_endian
>
449 do_fixed_endian_write(unsigned char*, section_size_type
);
452 const Stub_template
* stub_template_
;
453 // Offset within the section of containing this stub.
454 section_offset_type offset_
;
457 // Reloc stub class. These are stubs we use to fix up relocation because
458 // of limited branch ranges.
460 class Reloc_stub
: public Stub
463 static const unsigned int invalid_index
= static_cast<unsigned int>(-1);
464 // We assume we never jump to this address.
465 static const Arm_address invalid_address
= static_cast<Arm_address
>(-1);
467 // Return destination address.
469 destination_address() const
471 gold_assert(this->destination_address_
!= this->invalid_address
);
472 return this->destination_address_
;
475 // Set destination address.
477 set_destination_address(Arm_address address
)
479 gold_assert(address
!= this->invalid_address
);
480 this->destination_address_
= address
;
483 // Reset destination address.
485 reset_destination_address()
486 { this->destination_address_
= this->invalid_address
; }
488 // Determine stub type for a branch of a relocation of R_TYPE going
489 // from BRANCH_ADDRESS to BRANCH_TARGET. If TARGET_IS_THUMB is set,
490 // the branch target is a thumb instruction. TARGET is used for look
491 // up ARM-specific linker settings.
493 stub_type_for_reloc(unsigned int r_type
, Arm_address branch_address
,
494 Arm_address branch_target
, bool target_is_thumb
);
496 // Reloc_stub key. A key is logically a triplet of a stub type, a symbol
497 // and an addend. Since we treat global and local symbol differently, we
498 // use a Symbol object for a global symbol and a object-index pair for
503 // If SYMBOL is not null, this is a global symbol, we ignore RELOBJ and
504 // R_SYM. Otherwise, this is a local symbol and RELOBJ must non-NULL
505 // and R_SYM must not be invalid_index.
506 Key(Stub_type stub_type
, const Symbol
* symbol
, const Relobj
* relobj
,
507 unsigned int r_sym
, int32_t addend
)
508 : stub_type_(stub_type
), addend_(addend
)
512 this->r_sym_
= Reloc_stub::invalid_index
;
513 this->u_
.symbol
= symbol
;
517 gold_assert(relobj
!= NULL
&& r_sym
!= invalid_index
);
518 this->r_sym_
= r_sym
;
519 this->u_
.relobj
= relobj
;
526 // Accessors: Keys are meant to be read-only object so no modifiers are
532 { return this->stub_type_
; }
534 // Return the local symbol index or invalid_index.
537 { return this->r_sym_
; }
539 // Return the symbol if there is one.
542 { return this->r_sym_
== invalid_index
? this->u_
.symbol
: NULL
; }
544 // Return the relobj if there is one.
547 { return this->r_sym_
!= invalid_index
? this->u_
.relobj
: NULL
; }
549 // Whether this equals to another key k.
551 eq(const Key
& k
) const
553 return ((this->stub_type_
== k
.stub_type_
)
554 && (this->r_sym_
== k
.r_sym_
)
555 && ((this->r_sym_
!= Reloc_stub::invalid_index
)
556 ? (this->u_
.relobj
== k
.u_
.relobj
)
557 : (this->u_
.symbol
== k
.u_
.symbol
))
558 && (this->addend_
== k
.addend_
));
561 // Return a hash value.
565 return (this->stub_type_
567 ^ gold::string_hash
<char>(
568 (this->r_sym_
!= Reloc_stub::invalid_index
)
569 ? this->u_
.relobj
->name().c_str()
570 : this->u_
.symbol
->name())
574 // Functors for STL associative containers.
578 operator()(const Key
& k
) const
579 { return k
.hash_value(); }
585 operator()(const Key
& k1
, const Key
& k2
) const
586 { return k1
.eq(k2
); }
589 // Name of key. This is mainly for debugging.
595 Stub_type stub_type_
;
596 // If this is a local symbol, this is the index in the defining object.
597 // Otherwise, it is invalid_index for a global symbol.
599 // If r_sym_ is invalid index. This points to a global symbol.
600 // Otherwise, this points a relobj. We used the unsized and target
601 // independent Symbol and Relobj classes instead of Sized_symbol<32> and
602 // Arm_relobj. This is done to avoid making the stub class a template
603 // as most of the stub machinery is endianity-neutral. However, it
604 // may require a bit of casting done by users of this class.
607 const Symbol
* symbol
;
608 const Relobj
* relobj
;
610 // Addend associated with a reloc.
615 // Reloc_stubs are created via a stub factory. So these are protected.
616 Reloc_stub(const Stub_template
* stub_template
)
617 : Stub(stub_template
), destination_address_(invalid_address
)
623 friend class Stub_factory
;
625 // Return the relocation target address of the i-th relocation in the
628 do_reloc_target(size_t i
)
630 // All reloc stub have only one relocation.
632 return this->destination_address_
;
636 // Address of destination.
637 Arm_address destination_address_
;
640 // Cortex-A8 stub class. We need a Cortex-A8 stub to redirect any 32-bit
641 // THUMB branch that meets the following conditions:
643 // 1. The branch straddles across a page boundary. i.e. lower 12-bit of
644 // branch address is 0xffe.
645 // 2. The branch target address is in the same page as the first word of the
647 // 3. The branch follows a 32-bit instruction which is not a branch.
649 // To do the fix up, we need to store the address of the branch instruction
650 // and its target at least. We also need to store the original branch
651 // instruction bits for the condition code in a conditional branch. The
652 // condition code is used in a special instruction template. We also want
653 // to identify input sections needing Cortex-A8 workaround quickly. We store
654 // extra information about object and section index of the code section
655 // containing a branch being fixed up. The information is used to mark
656 // the code section when we finalize the Cortex-A8 stubs.
659 class Cortex_a8_stub
: public Stub
665 // Return the object of the code section containing the branch being fixed
669 { return this->relobj_
; }
671 // Return the section index of the code section containing the branch being
675 { return this->shndx_
; }
677 // Return the source address of stub. This is the address of the original
678 // branch instruction. LSB is 1 always set to indicate that it is a THUMB
681 source_address() const
682 { return this->source_address_
; }
684 // Return the destination address of the stub. This is the branch taken
685 // address of the original branch instruction. LSB is 1 if it is a THUMB
686 // instruction address.
688 destination_address() const
689 { return this->destination_address_
; }
691 // Return the instruction being fixed up.
693 original_insn() const
694 { return this->original_insn_
; }
697 // Cortex_a8_stubs are created via a stub factory. So these are protected.
698 Cortex_a8_stub(const Stub_template
* stub_template
, Relobj
* relobj
,
699 unsigned int shndx
, Arm_address source_address
,
700 Arm_address destination_address
, uint32_t original_insn
)
701 : Stub(stub_template
), relobj_(relobj
), shndx_(shndx
),
702 source_address_(source_address
| 1U),
703 destination_address_(destination_address
),
704 original_insn_(original_insn
)
707 friend class Stub_factory
;
709 // Return the relocation target address of the i-th relocation in the
712 do_reloc_target(size_t i
)
714 if (this->stub_template()->type() == arm_stub_a8_veneer_b_cond
)
716 // The conditional branch veneer has two relocations.
718 return i
== 0 ? this->source_address_
+ 4 : this->destination_address_
;
722 // All other Cortex-A8 stubs have only one relocation.
724 return this->destination_address_
;
728 // Return an instruction for the THUMB16_SPECIAL_TYPE instruction template.
730 do_thumb16_special(size_t);
733 // Object of the code section containing the branch being fixed up.
735 // Section index of the code section containing the branch begin fixed up.
737 // Source address of original branch.
738 Arm_address source_address_
;
739 // Destination address of the original branch.
740 Arm_address destination_address_
;
741 // Original branch instruction. This is needed for copying the condition
742 // code from a condition branch to its stub.
743 uint32_t original_insn_
;
746 // Stub factory class.
751 // Return the unique instance of this class.
752 static const Stub_factory
&
755 static Stub_factory singleton
;
759 // Make a relocation stub.
761 make_reloc_stub(Stub_type stub_type
) const
763 gold_assert(stub_type
>= arm_stub_reloc_first
764 && stub_type
<= arm_stub_reloc_last
);
765 return new Reloc_stub(this->stub_templates_
[stub_type
]);
768 // Make a Cortex-A8 stub.
770 make_cortex_a8_stub(Stub_type stub_type
, Relobj
* relobj
, unsigned int shndx
,
771 Arm_address source
, Arm_address destination
,
772 uint32_t original_insn
) const
774 gold_assert(stub_type
>= arm_stub_cortex_a8_first
775 && stub_type
<= arm_stub_cortex_a8_last
);
776 return new Cortex_a8_stub(this->stub_templates_
[stub_type
], relobj
, shndx
,
777 source
, destination
, original_insn
);
781 // Constructor and destructor are protected since we only return a single
782 // instance created in Stub_factory::get_instance().
786 // A Stub_factory may not be copied since it is a singleton.
787 Stub_factory(const Stub_factory
&);
788 Stub_factory
& operator=(Stub_factory
&);
790 // Stub templates. These are initialized in the constructor.
791 const Stub_template
* stub_templates_
[arm_stub_type_last
+1];
794 // A class to hold stubs for the ARM target.
796 template<bool big_endian
>
797 class Stub_table
: public Output_data
800 Stub_table(Arm_input_section
<big_endian
>* owner
)
801 : Output_data(), addralign_(1), owner_(owner
), has_been_changed_(false),
808 // Owner of this stub table.
809 Arm_input_section
<big_endian
>*
811 { return this->owner_
; }
813 // Whether this stub table is empty.
816 { return this->reloc_stubs_
.empty(); }
818 // Whether this has been changed.
820 has_been_changed() const
821 { return this->has_been_changed_
; }
823 // Set the has-been-changed flag.
825 set_has_been_changed(bool value
)
826 { this->has_been_changed_
= value
; }
828 // Return the current data size.
830 current_data_size() const
831 { return this->current_data_size_for_child(); }
833 // Add a STUB with using KEY. Caller is reponsible for avoid adding
834 // if already a STUB with the same key has been added.
836 add_reloc_stub(Reloc_stub
* stub
, const Reloc_stub::Key
& key
);
838 // Look up a relocation stub using KEY. Return NULL if there is none.
840 find_reloc_stub(const Reloc_stub::Key
& key
) const
842 typename
Reloc_stub_map::const_iterator p
= this->reloc_stubs_
.find(key
);
843 return (p
!= this->reloc_stubs_
.end()) ? p
->second
: NULL
;
846 // Relocate stubs in this stub table.
848 relocate_stubs(const Relocate_info
<32, big_endian
>*,
849 Target_arm
<big_endian
>*, Output_section
*,
850 unsigned char*, Arm_address
, section_size_type
);
853 // Write out section contents.
855 do_write(Output_file
*);
857 // Return the required alignment.
860 { return this->addralign_
; }
862 // Finalize data size.
864 set_final_data_size()
865 { this->set_data_size(this->current_data_size_for_child()); }
867 // Reset address and file offset.
869 do_reset_address_and_file_offset();
872 // Unordered map of stubs.
874 Unordered_map
<Reloc_stub::Key
, Reloc_stub
*, Reloc_stub::Key::hash
,
875 Reloc_stub::Key::equal_to
>
880 // Owner of this stub table.
881 Arm_input_section
<big_endian
>* owner_
;
882 // This is set to true during relaxiong if the size of the stub table
884 bool has_been_changed_
;
885 // The relocation stubs.
886 Reloc_stub_map reloc_stubs_
;
889 // A class to wrap an ordinary input section containing executable code.
891 template<bool big_endian
>
892 class Arm_input_section
: public Output_relaxed_input_section
895 Arm_input_section(Relobj
* relobj
, unsigned int shndx
)
896 : Output_relaxed_input_section(relobj
, shndx
, 1),
897 original_addralign_(1), original_size_(0), stub_table_(NULL
)
907 // Whether this is a stub table owner.
909 is_stub_table_owner() const
910 { return this->stub_table_
!= NULL
&& this->stub_table_
->owner() == this; }
912 // Return the stub table.
913 Stub_table
<big_endian
>*
915 { return this->stub_table_
; }
917 // Set the stub_table.
919 set_stub_table(Stub_table
<big_endian
>* stub_table
)
920 { this->stub_table_
= stub_table
; }
922 // Downcast a base pointer to an Arm_input_section pointer. This is
923 // not type-safe but we only use Arm_input_section not the base class.
924 static Arm_input_section
<big_endian
>*
925 as_arm_input_section(Output_relaxed_input_section
* poris
)
926 { return static_cast<Arm_input_section
<big_endian
>*>(poris
); }
929 // Write data to output file.
931 do_write(Output_file
*);
933 // Return required alignment of this.
937 if (this->is_stub_table_owner())
938 return std::max(this->stub_table_
->addralign(),
939 this->original_addralign_
);
941 return this->original_addralign_
;
944 // Finalize data size.
946 set_final_data_size();
948 // Reset address and file offset.
950 do_reset_address_and_file_offset();
954 do_output_offset(const Relobj
* object
, unsigned int shndx
,
955 section_offset_type offset
,
956 section_offset_type
* poutput
) const
958 if ((object
== this->relobj())
959 && (shndx
== this->shndx())
961 && (convert_types
<uint64_t, section_offset_type
>(offset
)
962 <= this->original_size_
))
972 // Copying is not allowed.
973 Arm_input_section(const Arm_input_section
&);
974 Arm_input_section
& operator=(const Arm_input_section
&);
976 // Address alignment of the original input section.
977 uint64_t original_addralign_
;
978 // Section size of the original input section.
979 uint64_t original_size_
;
981 Stub_table
<big_endian
>* stub_table_
;
984 // Arm output section class. This is defined mainly to add a number of
985 // stub generation methods.
987 template<bool big_endian
>
988 class Arm_output_section
: public Output_section
991 Arm_output_section(const char* name
, elfcpp::Elf_Word type
,
992 elfcpp::Elf_Xword flags
)
993 : Output_section(name
, type
, flags
)
996 ~Arm_output_section()
999 // Group input sections for stub generation.
1001 group_sections(section_size_type
, bool, Target_arm
<big_endian
>*);
1003 // Downcast a base pointer to an Arm_output_section pointer. This is
1004 // not type-safe but we only use Arm_output_section not the base class.
1005 static Arm_output_section
<big_endian
>*
1006 as_arm_output_section(Output_section
* os
)
1007 { return static_cast<Arm_output_section
<big_endian
>*>(os
); }
1011 typedef Output_section::Input_section Input_section
;
1012 typedef Output_section::Input_section_list Input_section_list
;
1014 // Create a stub group.
1015 void create_stub_group(Input_section_list::const_iterator
,
1016 Input_section_list::const_iterator
,
1017 Input_section_list::const_iterator
,
1018 Target_arm
<big_endian
>*,
1019 std::vector
<Output_relaxed_input_section
*>*);
1022 // Arm_relobj class.
1024 template<bool big_endian
>
1025 class Arm_relobj
: public Sized_relobj
<32, big_endian
>
1028 static const Arm_address invalid_address
= static_cast<Arm_address
>(-1);
1030 Arm_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
1031 const typename
elfcpp::Ehdr
<32, big_endian
>& ehdr
)
1032 : Sized_relobj
<32, big_endian
>(name
, input_file
, offset
, ehdr
),
1033 stub_tables_(), local_symbol_is_thumb_function_(),
1034 attributes_section_data_(NULL
)
1038 { delete this->attributes_section_data_
; }
1040 // Return the stub table of the SHNDX-th section if there is one.
1041 Stub_table
<big_endian
>*
1042 stub_table(unsigned int shndx
) const
1044 gold_assert(shndx
< this->stub_tables_
.size());
1045 return this->stub_tables_
[shndx
];
1048 // Set STUB_TABLE to be the stub_table of the SHNDX-th section.
1050 set_stub_table(unsigned int shndx
, Stub_table
<big_endian
>* stub_table
)
1052 gold_assert(shndx
< this->stub_tables_
.size());
1053 this->stub_tables_
[shndx
] = stub_table
;
1056 // Whether a local symbol is a THUMB function. R_SYM is the symbol table
1057 // index. This is only valid after do_count_local_symbol is called.
1059 local_symbol_is_thumb_function(unsigned int r_sym
) const
1061 gold_assert(r_sym
< this->local_symbol_is_thumb_function_
.size());
1062 return this->local_symbol_is_thumb_function_
[r_sym
];
1065 // Scan all relocation sections for stub generation.
1067 scan_sections_for_stubs(Target_arm
<big_endian
>*, const Symbol_table
*,
1070 // Convert regular input section with index SHNDX to a relaxed section.
1072 convert_input_section_to_relaxed_section(unsigned shndx
)
1074 // The stubs have relocations and we need to process them after writing
1075 // out the stubs. So relocation now must follow section write.
1076 this->invalidate_section_offset(shndx
);
1077 this->set_relocs_must_follow_section_writes();
1080 // Downcast a base pointer to an Arm_relobj pointer. This is
1081 // not type-safe but we only use Arm_relobj not the base class.
1082 static Arm_relobj
<big_endian
>*
1083 as_arm_relobj(Relobj
* relobj
)
1084 { return static_cast<Arm_relobj
<big_endian
>*>(relobj
); }
1086 // Processor-specific flags in ELF file header. This is valid only after
1089 processor_specific_flags() const
1090 { return this->processor_specific_flags_
; }
1092 // Attribute section data This is the contents of the .ARM.attribute section
1094 const Attributes_section_data
*
1095 attributes_section_data() const
1096 { return this->attributes_section_data_
; }
1099 // Post constructor setup.
1103 // Call parent's setup method.
1104 Sized_relobj
<32, big_endian
>::do_setup();
1106 // Initialize look-up tables.
1107 Stub_table_list
empty_stub_table_list(this->shnum(), NULL
);
1108 this->stub_tables_
.swap(empty_stub_table_list
);
1111 // Count the local symbols.
1113 do_count_local_symbols(Stringpool_template
<char>*,
1114 Stringpool_template
<char>*);
1117 do_relocate_sections(const Symbol_table
* symtab
, const Layout
* layout
,
1118 const unsigned char* pshdrs
,
1119 typename Sized_relobj
<32, big_endian
>::Views
* pivews
);
1121 // Read the symbol information.
1123 do_read_symbols(Read_symbols_data
* sd
);
1126 // List of stub tables.
1127 typedef std::vector
<Stub_table
<big_endian
>*> Stub_table_list
;
1128 Stub_table_list stub_tables_
;
1129 // Bit vector to tell if a local symbol is a thumb function or not.
1130 // This is only valid after do_count_local_symbol is called.
1131 std::vector
<bool> local_symbol_is_thumb_function_
;
1132 // processor-specific flags in ELF file header.
1133 elfcpp::Elf_Word processor_specific_flags_
;
1134 // Object attributes if there is an .ARM.attributes section or NULL.
1135 Attributes_section_data
* attributes_section_data_
;
1138 // Arm_dynobj class.
1140 template<bool big_endian
>
1141 class Arm_dynobj
: public Sized_dynobj
<32, big_endian
>
1144 Arm_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
1145 const elfcpp::Ehdr
<32, big_endian
>& ehdr
)
1146 : Sized_dynobj
<32, big_endian
>(name
, input_file
, offset
, ehdr
),
1147 processor_specific_flags_(0), attributes_section_data_(NULL
)
1151 { delete this->attributes_section_data_
; }
1153 // Downcast a base pointer to an Arm_relobj pointer. This is
1154 // not type-safe but we only use Arm_relobj not the base class.
1155 static Arm_dynobj
<big_endian
>*
1156 as_arm_dynobj(Dynobj
* dynobj
)
1157 { return static_cast<Arm_dynobj
<big_endian
>*>(dynobj
); }
1159 // Processor-specific flags in ELF file header. This is valid only after
1162 processor_specific_flags() const
1163 { return this->processor_specific_flags_
; }
1165 // Attributes section data.
1166 const Attributes_section_data
*
1167 attributes_section_data() const
1168 { return this->attributes_section_data_
; }
1171 // Read the symbol information.
1173 do_read_symbols(Read_symbols_data
* sd
);
1176 // processor-specific flags in ELF file header.
1177 elfcpp::Elf_Word processor_specific_flags_
;
1178 // Object attributes if there is an .ARM.attributes section or NULL.
1179 Attributes_section_data
* attributes_section_data_
;
1182 // Functor to read reloc addends during stub generation.
1184 template<int sh_type
, bool big_endian
>
1185 struct Stub_addend_reader
1187 // Return the addend for a relocation of a particular type. Depending
1188 // on whether this is a REL or RELA relocation, read the addend from a
1189 // view or from a Reloc object.
1190 elfcpp::Elf_types
<32>::Elf_Swxword
1192 unsigned int /* r_type */,
1193 const unsigned char* /* view */,
1194 const typename Reloc_types
<sh_type
,
1195 32, big_endian
>::Reloc
& /* reloc */) const;
1198 // Specialized Stub_addend_reader for SHT_REL type relocation sections.
1200 template<bool big_endian
>
1201 struct Stub_addend_reader
<elfcpp::SHT_REL
, big_endian
>
1203 elfcpp::Elf_types
<32>::Elf_Swxword
1206 const unsigned char*,
1207 const typename Reloc_types
<elfcpp::SHT_REL
, 32, big_endian
>::Reloc
&) const;
1210 // Specialized Stub_addend_reader for RELA type relocation sections.
1211 // We currently do not handle RELA type relocation sections but it is trivial
1212 // to implement the addend reader. This is provided for completeness and to
1213 // make it easier to add support for RELA relocation sections in the future.
1215 template<bool big_endian
>
1216 struct Stub_addend_reader
<elfcpp::SHT_RELA
, big_endian
>
1218 elfcpp::Elf_types
<32>::Elf_Swxword
1221 const unsigned char*,
1222 const typename Reloc_types
<elfcpp::SHT_RELA
, 32,
1223 big_endian
>::Reloc
& reloc
) const
1224 { return reloc
.get_r_addend(); }
1227 // Utilities for manipulating integers of up to 32-bits
1231 // Sign extend an n-bit unsigned integer stored in an uint32_t into
1232 // an int32_t. NO_BITS must be between 1 to 32.
1233 template<int no_bits
>
1234 static inline int32_t
1235 sign_extend(uint32_t bits
)
1237 gold_assert(no_bits
>= 0 && no_bits
<= 32);
1239 return static_cast<int32_t>(bits
);
1240 uint32_t mask
= (~((uint32_t) 0)) >> (32 - no_bits
);
1242 uint32_t top_bit
= 1U << (no_bits
- 1);
1243 int32_t as_signed
= static_cast<int32_t>(bits
);
1244 return (bits
& top_bit
) ? as_signed
+ (-top_bit
* 2) : as_signed
;
1247 // Detects overflow of an NO_BITS integer stored in a uint32_t.
1248 template<int no_bits
>
1250 has_overflow(uint32_t bits
)
1252 gold_assert(no_bits
>= 0 && no_bits
<= 32);
1255 int32_t max
= (1 << (no_bits
- 1)) - 1;
1256 int32_t min
= -(1 << (no_bits
- 1));
1257 int32_t as_signed
= static_cast<int32_t>(bits
);
1258 return as_signed
> max
|| as_signed
< min
;
1261 // Detects overflow of an NO_BITS integer stored in a uint32_t when it
1262 // fits in the given number of bits as either a signed or unsigned value.
1263 // For example, has_signed_unsigned_overflow<8> would check
1264 // -128 <= bits <= 255
1265 template<int no_bits
>
1267 has_signed_unsigned_overflow(uint32_t bits
)
1269 gold_assert(no_bits
>= 2 && no_bits
<= 32);
1272 int32_t max
= static_cast<int32_t>((1U << no_bits
) - 1);
1273 int32_t min
= -(1 << (no_bits
- 1));
1274 int32_t as_signed
= static_cast<int32_t>(bits
);
1275 return as_signed
> max
|| as_signed
< min
;
1278 // Select bits from A and B using bits in MASK. For each n in [0..31],
1279 // the n-th bit in the result is chosen from the n-th bits of A and B.
1280 // A zero selects A and a one selects B.
1281 static inline uint32_t
1282 bit_select(uint32_t a
, uint32_t b
, uint32_t mask
)
1283 { return (a
& ~mask
) | (b
& mask
); }
1286 template<bool big_endian
>
1287 class Target_arm
: public Sized_target
<32, big_endian
>
1290 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, big_endian
>
1293 // When were are relocating a stub, we pass this as the relocation number.
1294 static const size_t fake_relnum_for_stubs
= static_cast<size_t>(-1);
1297 : Sized_target
<32, big_endian
>(&arm_info
),
1298 got_(NULL
), plt_(NULL
), got_plt_(NULL
), rel_dyn_(NULL
),
1299 copy_relocs_(elfcpp::R_ARM_COPY
), dynbss_(NULL
), stub_tables_(),
1300 stub_factory_(Stub_factory::get_instance()), may_use_blx_(false),
1301 should_force_pic_veneer_(false), arm_input_section_map_(),
1302 attributes_section_data_(NULL
)
1305 // Whether we can use BLX.
1308 { return this->may_use_blx_
; }
1310 // Set use-BLX flag.
1312 set_may_use_blx(bool value
)
1313 { this->may_use_blx_
= value
; }
1315 // Whether we force PCI branch veneers.
1317 should_force_pic_veneer() const
1318 { return this->should_force_pic_veneer_
; }
1320 // Set PIC veneer flag.
1322 set_should_force_pic_veneer(bool value
)
1323 { this->should_force_pic_veneer_
= value
; }
1325 // Whether we use THUMB-2 instructions.
1327 using_thumb2() const
1329 Object_attribute
* attr
=
1330 this->get_aeabi_object_attribute(elfcpp::Tag_CPU_arch
);
1331 int arch
= attr
->int_value();
1332 return arch
== elfcpp::TAG_CPU_ARCH_V6T2
|| arch
>= elfcpp::TAG_CPU_ARCH_V7
;
1335 // Whether we use THUMB/THUMB-2 instructions only.
1337 using_thumb_only() const
1339 Object_attribute
* attr
=
1340 this->get_aeabi_object_attribute(elfcpp::Tag_CPU_arch
);
1341 if (attr
->int_value() != elfcpp::TAG_CPU_ARCH_V7
1342 && attr
->int_value() != elfcpp::TAG_CPU_ARCH_V7E_M
)
1344 attr
= this->get_aeabi_object_attribute(elfcpp::Tag_CPU_arch_profile
);
1345 return attr
->int_value() == 'M';
1348 // Whether we have an NOP instruction. If not, use mov r0, r0 instead.
1350 may_use_arm_nop() const
1352 Object_attribute
* attr
=
1353 this->get_aeabi_object_attribute(elfcpp::Tag_CPU_arch
);
1354 int arch
= attr
->int_value();
1355 return (arch
== elfcpp::TAG_CPU_ARCH_V6T2
1356 || arch
== elfcpp::TAG_CPU_ARCH_V6K
1357 || arch
== elfcpp::TAG_CPU_ARCH_V7
1358 || arch
== elfcpp::TAG_CPU_ARCH_V7E_M
);
1361 // Whether we have THUMB-2 NOP.W instruction.
1363 may_use_thumb2_nop() const
1365 Object_attribute
* attr
=
1366 this->get_aeabi_object_attribute(elfcpp::Tag_CPU_arch
);
1367 int arch
= attr
->int_value();
1368 return (arch
== elfcpp::TAG_CPU_ARCH_V6T2
1369 || arch
== elfcpp::TAG_CPU_ARCH_V7
1370 || arch
== elfcpp::TAG_CPU_ARCH_V7E_M
);
1373 // Process the relocations to determine unreferenced sections for
1374 // garbage collection.
1376 gc_process_relocs(Symbol_table
* symtab
,
1378 Sized_relobj
<32, big_endian
>* object
,
1379 unsigned int data_shndx
,
1380 unsigned int sh_type
,
1381 const unsigned char* prelocs
,
1383 Output_section
* output_section
,
1384 bool needs_special_offset_handling
,
1385 size_t local_symbol_count
,
1386 const unsigned char* plocal_symbols
);
1388 // Scan the relocations to look for symbol adjustments.
1390 scan_relocs(Symbol_table
* symtab
,
1392 Sized_relobj
<32, big_endian
>* object
,
1393 unsigned int data_shndx
,
1394 unsigned int sh_type
,
1395 const unsigned char* prelocs
,
1397 Output_section
* output_section
,
1398 bool needs_special_offset_handling
,
1399 size_t local_symbol_count
,
1400 const unsigned char* plocal_symbols
);
1402 // Finalize the sections.
1404 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
1406 // Return the value to use for a dynamic symbol which requires special
1409 do_dynsym_value(const Symbol
*) const;
1411 // Relocate a section.
1413 relocate_section(const Relocate_info
<32, big_endian
>*,
1414 unsigned int sh_type
,
1415 const unsigned char* prelocs
,
1417 Output_section
* output_section
,
1418 bool needs_special_offset_handling
,
1419 unsigned char* view
,
1420 Arm_address view_address
,
1421 section_size_type view_size
,
1422 const Reloc_symbol_changes
*);
1424 // Scan the relocs during a relocatable link.
1426 scan_relocatable_relocs(Symbol_table
* symtab
,
1428 Sized_relobj
<32, big_endian
>* object
,
1429 unsigned int data_shndx
,
1430 unsigned int sh_type
,
1431 const unsigned char* prelocs
,
1433 Output_section
* output_section
,
1434 bool needs_special_offset_handling
,
1435 size_t local_symbol_count
,
1436 const unsigned char* plocal_symbols
,
1437 Relocatable_relocs
*);
1439 // Relocate a section during a relocatable link.
1441 relocate_for_relocatable(const Relocate_info
<32, big_endian
>*,
1442 unsigned int sh_type
,
1443 const unsigned char* prelocs
,
1445 Output_section
* output_section
,
1446 off_t offset_in_output_section
,
1447 const Relocatable_relocs
*,
1448 unsigned char* view
,
1449 Arm_address view_address
,
1450 section_size_type view_size
,
1451 unsigned char* reloc_view
,
1452 section_size_type reloc_view_size
);
1454 // Return whether SYM is defined by the ABI.
1456 do_is_defined_by_abi(Symbol
* sym
) const
1457 { return strcmp(sym
->name(), "__tls_get_addr") == 0; }
1459 // Return the size of the GOT section.
1463 gold_assert(this->got_
!= NULL
);
1464 return this->got_
->data_size();
1467 // Map platform-specific reloc types
1469 get_real_reloc_type (unsigned int r_type
);
1472 // Methods to support stub-generations.
1475 // Return the stub factory
1477 stub_factory() const
1478 { return this->stub_factory_
; }
1480 // Make a new Arm_input_section object.
1481 Arm_input_section
<big_endian
>*
1482 new_arm_input_section(Relobj
*, unsigned int);
1484 // Find the Arm_input_section object corresponding to the SHNDX-th input
1485 // section of RELOBJ.
1486 Arm_input_section
<big_endian
>*
1487 find_arm_input_section(Relobj
* relobj
, unsigned int shndx
) const;
1489 // Make a new Stub_table
1490 Stub_table
<big_endian
>*
1491 new_stub_table(Arm_input_section
<big_endian
>*);
1493 // Scan a section for stub generation.
1495 scan_section_for_stubs(const Relocate_info
<32, big_endian
>*, unsigned int,
1496 const unsigned char*, size_t, Output_section
*,
1497 bool, const unsigned char*, Arm_address
,
1502 relocate_stub(Reloc_stub
*, const Relocate_info
<32, big_endian
>*,
1503 Output_section
*, unsigned char*, Arm_address
,
1506 // Get the default ARM target.
1507 static Target_arm
<big_endian
>*
1510 gold_assert(parameters
->target().machine_code() == elfcpp::EM_ARM
1511 && parameters
->target().is_big_endian() == big_endian
);
1512 return static_cast<Target_arm
<big_endian
>*>(
1513 parameters
->sized_target
<32, big_endian
>());
1516 // Whether relocation type uses LSB to distinguish THUMB addresses.
1518 reloc_uses_thumb_bit(unsigned int r_type
);
1521 // Make an ELF object.
1523 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
1524 const elfcpp::Ehdr
<32, big_endian
>& ehdr
);
1527 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
1528 const elfcpp::Ehdr
<32, !big_endian
>&)
1529 { gold_unreachable(); }
1532 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
1533 const elfcpp::Ehdr
<64, false>&)
1534 { gold_unreachable(); }
1537 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
1538 const elfcpp::Ehdr
<64, true>&)
1539 { gold_unreachable(); }
1541 // Make an output section.
1543 do_make_output_section(const char* name
, elfcpp::Elf_Word type
,
1544 elfcpp::Elf_Xword flags
)
1545 { return new Arm_output_section
<big_endian
>(name
, type
, flags
); }
1548 do_adjust_elf_header(unsigned char* view
, int len
) const;
1550 // We only need to generate stubs, and hence perform relaxation if we are
1551 // not doing relocatable linking.
1553 do_may_relax() const
1554 { return !parameters
->options().relocatable(); }
1557 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*);
1559 // Determine whether an object attribute tag takes an integer, a
1562 do_attribute_arg_type(int tag
) const;
1564 // Reorder tags during output.
1566 do_attributes_order(int num
) const;
1569 // The class which scans relocations.
1574 : issued_non_pic_error_(false)
1578 local(Symbol_table
* symtab
, Layout
* layout
, Target_arm
* target
,
1579 Sized_relobj
<32, big_endian
>* object
,
1580 unsigned int data_shndx
,
1581 Output_section
* output_section
,
1582 const elfcpp::Rel
<32, big_endian
>& reloc
, unsigned int r_type
,
1583 const elfcpp::Sym
<32, big_endian
>& lsym
);
1586 global(Symbol_table
* symtab
, Layout
* layout
, Target_arm
* target
,
1587 Sized_relobj
<32, big_endian
>* object
,
1588 unsigned int data_shndx
,
1589 Output_section
* output_section
,
1590 const elfcpp::Rel
<32, big_endian
>& reloc
, unsigned int r_type
,
1595 unsupported_reloc_local(Sized_relobj
<32, big_endian
>*,
1596 unsigned int r_type
);
1599 unsupported_reloc_global(Sized_relobj
<32, big_endian
>*,
1600 unsigned int r_type
, Symbol
*);
1603 check_non_pic(Relobj
*, unsigned int r_type
);
1605 // Almost identical to Symbol::needs_plt_entry except that it also
1606 // handles STT_ARM_TFUNC.
1608 symbol_needs_plt_entry(const Symbol
* sym
)
1610 // An undefined symbol from an executable does not need a PLT entry.
1611 if (sym
->is_undefined() && !parameters
->options().shared())
1614 return (!parameters
->doing_static_link()
1615 && (sym
->type() == elfcpp::STT_FUNC
1616 || sym
->type() == elfcpp::STT_ARM_TFUNC
)
1617 && (sym
->is_from_dynobj()
1618 || sym
->is_undefined()
1619 || sym
->is_preemptible()));
1622 // Whether we have issued an error about a non-PIC compilation.
1623 bool issued_non_pic_error_
;
1626 // The class which implements relocation.
1636 // Return whether the static relocation needs to be applied.
1638 should_apply_static_reloc(const Sized_symbol
<32>* gsym
,
1641 Output_section
* output_section
);
1643 // Do a relocation. Return false if the caller should not issue
1644 // any warnings about this relocation.
1646 relocate(const Relocate_info
<32, big_endian
>*, Target_arm
*,
1647 Output_section
*, size_t relnum
,
1648 const elfcpp::Rel
<32, big_endian
>&,
1649 unsigned int r_type
, const Sized_symbol
<32>*,
1650 const Symbol_value
<32>*,
1651 unsigned char*, Arm_address
,
1654 // Return whether we want to pass flag NON_PIC_REF for this
1655 // reloc. This means the relocation type accesses a symbol not via
1658 reloc_is_non_pic (unsigned int r_type
)
1662 // These relocation types reference GOT or PLT entries explicitly.
1663 case elfcpp::R_ARM_GOT_BREL
:
1664 case elfcpp::R_ARM_GOT_ABS
:
1665 case elfcpp::R_ARM_GOT_PREL
:
1666 case elfcpp::R_ARM_GOT_BREL12
:
1667 case elfcpp::R_ARM_PLT32_ABS
:
1668 case elfcpp::R_ARM_TLS_GD32
:
1669 case elfcpp::R_ARM_TLS_LDM32
:
1670 case elfcpp::R_ARM_TLS_IE32
:
1671 case elfcpp::R_ARM_TLS_IE12GP
:
1673 // These relocate types may use PLT entries.
1674 case elfcpp::R_ARM_CALL
:
1675 case elfcpp::R_ARM_THM_CALL
:
1676 case elfcpp::R_ARM_JUMP24
:
1677 case elfcpp::R_ARM_THM_JUMP24
:
1678 case elfcpp::R_ARM_THM_JUMP19
:
1679 case elfcpp::R_ARM_PLT32
:
1680 case elfcpp::R_ARM_THM_XPC22
:
1689 // A class which returns the size required for a relocation type,
1690 // used while scanning relocs during a relocatable link.
1691 class Relocatable_size_for_reloc
1695 get_size_for_reloc(unsigned int, Relobj
*);
1698 // Get the GOT section, creating it if necessary.
1699 Output_data_got
<32, big_endian
>*
1700 got_section(Symbol_table
*, Layout
*);
1702 // Get the GOT PLT section.
1704 got_plt_section() const
1706 gold_assert(this->got_plt_
!= NULL
);
1707 return this->got_plt_
;
1710 // Create a PLT entry for a global symbol.
1712 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1714 // Get the PLT section.
1715 const Output_data_plt_arm
<big_endian
>*
1718 gold_assert(this->plt_
!= NULL
);
1722 // Get the dynamic reloc section, creating it if necessary.
1724 rel_dyn_section(Layout
*);
1726 // Return true if the symbol may need a COPY relocation.
1727 // References from an executable object to non-function symbols
1728 // defined in a dynamic object may need a COPY relocation.
1730 may_need_copy_reloc(Symbol
* gsym
)
1732 return (gsym
->type() != elfcpp::STT_ARM_TFUNC
1733 && gsym
->may_need_copy_reloc());
1736 // Add a potential copy relocation.
1738 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1739 Sized_relobj
<32, big_endian
>* object
,
1740 unsigned int shndx
, Output_section
* output_section
,
1741 Symbol
* sym
, const elfcpp::Rel
<32, big_endian
>& reloc
)
1743 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1744 symtab
->get_sized_symbol
<32>(sym
),
1745 object
, shndx
, output_section
, reloc
,
1746 this->rel_dyn_section(layout
));
1749 // Whether two EABI versions are compatible.
1751 are_eabi_versions_compatible(elfcpp::Elf_Word v1
, elfcpp::Elf_Word v2
);
1753 // Merge processor-specific flags from input object and those in the ELF
1754 // header of the output.
1756 merge_processor_specific_flags(const std::string
&, elfcpp::Elf_Word
);
1758 // Get the secondary compatible architecture.
1760 get_secondary_compatible_arch(const Attributes_section_data
*);
1762 // Set the secondary compatible architecture.
1764 set_secondary_compatible_arch(Attributes_section_data
*, int);
1767 tag_cpu_arch_combine(const char*, int, int*, int, int);
1769 // Helper to print AEABI enum tag value.
1771 aeabi_enum_name(unsigned int);
1773 // Return string value for TAG_CPU_name.
1775 tag_cpu_name_value(unsigned int);
1777 // Merge object attributes from input object and those in the output.
1779 merge_object_attributes(const char*, const Attributes_section_data
*);
1781 // Helper to get an AEABI object attribute
1783 get_aeabi_object_attribute(int tag
) const
1785 Attributes_section_data
* pasd
= this->attributes_section_data_
;
1786 gold_assert(pasd
!= NULL
);
1787 Object_attribute
* attr
=
1788 pasd
->get_attribute(Object_attribute::OBJ_ATTR_PROC
, tag
);
1789 gold_assert(attr
!= NULL
);
1794 // Methods to support stub-generations.
1797 // Group input sections for stub generation.
1799 group_sections(Layout
*, section_size_type
, bool);
1801 // Scan a relocation for stub generation.
1803 scan_reloc_for_stub(const Relocate_info
<32, big_endian
>*, unsigned int,
1804 const Sized_symbol
<32>*, unsigned int,
1805 const Symbol_value
<32>*,
1806 elfcpp::Elf_types
<32>::Elf_Swxword
, Arm_address
);
1808 // Scan a relocation section for stub.
1809 template<int sh_type
>
1811 scan_reloc_section_for_stubs(
1812 const Relocate_info
<32, big_endian
>* relinfo
,
1813 const unsigned char* prelocs
,
1815 Output_section
* output_section
,
1816 bool needs_special_offset_handling
,
1817 const unsigned char* view
,
1818 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
1821 // Information about this specific target which we pass to the
1822 // general Target structure.
1823 static const Target::Target_info arm_info
;
1825 // The types of GOT entries needed for this platform.
1828 GOT_TYPE_STANDARD
= 0 // GOT entry for a regular symbol
1831 typedef typename
std::vector
<Stub_table
<big_endian
>*> Stub_table_list
;
1833 // Map input section to Arm_input_section.
1834 typedef Unordered_map
<Input_section_specifier
,
1835 Arm_input_section
<big_endian
>*,
1836 Input_section_specifier::hash
,
1837 Input_section_specifier::equal_to
>
1838 Arm_input_section_map
;
1841 Output_data_got
<32, big_endian
>* got_
;
1843 Output_data_plt_arm
<big_endian
>* plt_
;
1844 // The GOT PLT section.
1845 Output_data_space
* got_plt_
;
1846 // The dynamic reloc section.
1847 Reloc_section
* rel_dyn_
;
1848 // Relocs saved to avoid a COPY reloc.
1849 Copy_relocs
<elfcpp::SHT_REL
, 32, big_endian
> copy_relocs_
;
1850 // Space for variables copied with a COPY reloc.
1851 Output_data_space
* dynbss_
;
1852 // Vector of Stub_tables created.
1853 Stub_table_list stub_tables_
;
1855 const Stub_factory
&stub_factory_
;
1856 // Whether we can use BLX.
1858 // Whether we force PIC branch veneers.
1859 bool should_force_pic_veneer_
;
1860 // Map for locating Arm_input_sections.
1861 Arm_input_section_map arm_input_section_map_
;
1862 // Attributes section data in output.
1863 Attributes_section_data
* attributes_section_data_
;
1866 template<bool big_endian
>
1867 const Target::Target_info Target_arm
<big_endian
>::arm_info
=
1870 big_endian
, // is_big_endian
1871 elfcpp::EM_ARM
, // machine_code
1872 false, // has_make_symbol
1873 false, // has_resolve
1874 false, // has_code_fill
1875 true, // is_default_stack_executable
1877 "/usr/lib/libc.so.1", // dynamic_linker
1878 0x8000, // default_text_segment_address
1879 0x1000, // abi_pagesize (overridable by -z max-page-size)
1880 0x1000, // common_pagesize (overridable by -z common-page-size)
1881 elfcpp::SHN_UNDEF
, // small_common_shndx
1882 elfcpp::SHN_UNDEF
, // large_common_shndx
1883 0, // small_common_section_flags
1884 0, // large_common_section_flags
1885 ".ARM.attributes", // attributes_section
1886 "aeabi" // attributes_vendor
1889 // Arm relocate functions class
1892 template<bool big_endian
>
1893 class Arm_relocate_functions
: public Relocate_functions
<32, big_endian
>
1898 STATUS_OKAY
, // No error during relocation.
1899 STATUS_OVERFLOW
, // Relocation oveflow.
1900 STATUS_BAD_RELOC
// Relocation cannot be applied.
1904 typedef Relocate_functions
<32, big_endian
> Base
;
1905 typedef Arm_relocate_functions
<big_endian
> This
;
1907 // Encoding of imm16 argument for movt and movw ARM instructions
1910 // imm16 := imm4 | imm12
1912 // 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
1913 // +-------+---------------+-------+-------+-----------------------+
1914 // | | |imm4 | |imm12 |
1915 // +-------+---------------+-------+-------+-----------------------+
1917 // Extract the relocation addend from VAL based on the ARM
1918 // instruction encoding described above.
1919 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
1920 extract_arm_movw_movt_addend(
1921 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
)
1923 // According to the Elf ABI for ARM Architecture the immediate
1924 // field is sign-extended to form the addend.
1925 return utils::sign_extend
<16>(((val
>> 4) & 0xf000) | (val
& 0xfff));
1928 // Insert X into VAL based on the ARM instruction encoding described
1930 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
1931 insert_val_arm_movw_movt(
1932 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
,
1933 typename
elfcpp::Swap
<32, big_endian
>::Valtype x
)
1937 val
|= (x
& 0xf000) << 4;
1941 // Encoding of imm16 argument for movt and movw Thumb2 instructions
1944 // imm16 := imm4 | i | imm3 | imm8
1946 // 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
1947 // +---------+-+-----------+-------++-+-----+-------+---------------+
1948 // | |i| |imm4 || |imm3 | |imm8 |
1949 // +---------+-+-----------+-------++-+-----+-------+---------------+
1951 // Extract the relocation addend from VAL based on the Thumb2
1952 // instruction encoding described above.
1953 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
1954 extract_thumb_movw_movt_addend(
1955 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
)
1957 // According to the Elf ABI for ARM Architecture the immediate
1958 // field is sign-extended to form the addend.
1959 return utils::sign_extend
<16>(((val
>> 4) & 0xf000)
1960 | ((val
>> 15) & 0x0800)
1961 | ((val
>> 4) & 0x0700)
1965 // Insert X into VAL based on the Thumb2 instruction encoding
1967 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
1968 insert_val_thumb_movw_movt(
1969 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
,
1970 typename
elfcpp::Swap
<32, big_endian
>::Valtype x
)
1973 val
|= (x
& 0xf000) << 4;
1974 val
|= (x
& 0x0800) << 15;
1975 val
|= (x
& 0x0700) << 4;
1976 val
|= (x
& 0x00ff);
1980 // Handle ARM long branches.
1981 static typename
This::Status
1982 arm_branch_common(unsigned int, const Relocate_info
<32, big_endian
>*,
1983 unsigned char *, const Sized_symbol
<32>*,
1984 const Arm_relobj
<big_endian
>*, unsigned int,
1985 const Symbol_value
<32>*, Arm_address
, Arm_address
, bool);
1987 // Handle THUMB long branches.
1988 static typename
This::Status
1989 thumb_branch_common(unsigned int, const Relocate_info
<32, big_endian
>*,
1990 unsigned char *, const Sized_symbol
<32>*,
1991 const Arm_relobj
<big_endian
>*, unsigned int,
1992 const Symbol_value
<32>*, Arm_address
, Arm_address
, bool);
1996 // R_ARM_ABS8: S + A
1997 static inline typename
This::Status
1998 abs8(unsigned char *view
,
1999 const Sized_relobj
<32, big_endian
>* object
,
2000 const Symbol_value
<32>* psymval
)
2002 typedef typename
elfcpp::Swap
<8, big_endian
>::Valtype Valtype
;
2003 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
2004 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2005 Valtype val
= elfcpp::Swap
<8, big_endian
>::readval(wv
);
2006 Reltype addend
= utils::sign_extend
<8>(val
);
2007 Reltype x
= psymval
->value(object
, addend
);
2008 val
= utils::bit_select(val
, x
, 0xffU
);
2009 elfcpp::Swap
<8, big_endian
>::writeval(wv
, val
);
2010 return (utils::has_signed_unsigned_overflow
<8>(x
)
2011 ? This::STATUS_OVERFLOW
2012 : This::STATUS_OKAY
);
2015 // R_ARM_THM_ABS5: S + A
2016 static inline typename
This::Status
2017 thm_abs5(unsigned char *view
,
2018 const Sized_relobj
<32, big_endian
>* object
,
2019 const Symbol_value
<32>* psymval
)
2021 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
2022 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
2023 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2024 Valtype val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
2025 Reltype addend
= (val
& 0x7e0U
) >> 6;
2026 Reltype x
= psymval
->value(object
, addend
);
2027 val
= utils::bit_select(val
, x
<< 6, 0x7e0U
);
2028 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
2029 return (utils::has_overflow
<5>(x
)
2030 ? This::STATUS_OVERFLOW
2031 : This::STATUS_OKAY
);
2034 // R_ARM_ABS12: S + A
2035 static inline typename
This::Status
2036 abs12(unsigned char *view
,
2037 const Sized_relobj
<32, big_endian
>* object
,
2038 const Symbol_value
<32>* psymval
)
2040 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2041 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
2042 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2043 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2044 Reltype addend
= val
& 0x0fffU
;
2045 Reltype x
= psymval
->value(object
, addend
);
2046 val
= utils::bit_select(val
, x
, 0x0fffU
);
2047 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2048 return (utils::has_overflow
<12>(x
)
2049 ? This::STATUS_OVERFLOW
2050 : This::STATUS_OKAY
);
2053 // R_ARM_ABS16: S + A
2054 static inline typename
This::Status
2055 abs16(unsigned char *view
,
2056 const Sized_relobj
<32, big_endian
>* object
,
2057 const Symbol_value
<32>* psymval
)
2059 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
2060 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
2061 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2062 Valtype val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
2063 Reltype addend
= utils::sign_extend
<16>(val
);
2064 Reltype x
= psymval
->value(object
, addend
);
2065 val
= utils::bit_select(val
, x
, 0xffffU
);
2066 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
2067 return (utils::has_signed_unsigned_overflow
<16>(x
)
2068 ? This::STATUS_OVERFLOW
2069 : This::STATUS_OKAY
);
2072 // R_ARM_ABS32: (S + A) | T
2073 static inline typename
This::Status
2074 abs32(unsigned char *view
,
2075 const Sized_relobj
<32, big_endian
>* object
,
2076 const Symbol_value
<32>* psymval
,
2077 Arm_address thumb_bit
)
2079 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2080 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2081 Valtype addend
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2082 Valtype x
= psymval
->value(object
, addend
) | thumb_bit
;
2083 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
2084 return This::STATUS_OKAY
;
2087 // R_ARM_REL32: (S + A) | T - P
2088 static inline typename
This::Status
2089 rel32(unsigned char *view
,
2090 const Sized_relobj
<32, big_endian
>* object
,
2091 const Symbol_value
<32>* psymval
,
2092 Arm_address address
,
2093 Arm_address thumb_bit
)
2095 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2096 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2097 Valtype addend
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2098 Valtype x
= (psymval
->value(object
, addend
) | thumb_bit
) - address
;
2099 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
2100 return This::STATUS_OKAY
;
2103 // R_ARM_THM_CALL: (S + A) | T - P
2104 static inline typename
This::Status
2105 thm_call(const Relocate_info
<32, big_endian
>* relinfo
, unsigned char *view
,
2106 const Sized_symbol
<32>* gsym
, const Arm_relobj
<big_endian
>* object
,
2107 unsigned int r_sym
, const Symbol_value
<32>* psymval
,
2108 Arm_address address
, Arm_address thumb_bit
,
2109 bool is_weakly_undefined_without_plt
)
2111 return thumb_branch_common(elfcpp::R_ARM_THM_CALL
, relinfo
, view
, gsym
,
2112 object
, r_sym
, psymval
, address
, thumb_bit
,
2113 is_weakly_undefined_without_plt
);
2116 // R_ARM_THM_JUMP24: (S + A) | T - P
2117 static inline typename
This::Status
2118 thm_jump24(const Relocate_info
<32, big_endian
>* relinfo
, unsigned char *view
,
2119 const Sized_symbol
<32>* gsym
, const Arm_relobj
<big_endian
>* object
,
2120 unsigned int r_sym
, const Symbol_value
<32>* psymval
,
2121 Arm_address address
, Arm_address thumb_bit
,
2122 bool is_weakly_undefined_without_plt
)
2124 return thumb_branch_common(elfcpp::R_ARM_THM_JUMP24
, relinfo
, view
, gsym
,
2125 object
, r_sym
, psymval
, address
, thumb_bit
,
2126 is_weakly_undefined_without_plt
);
2129 // R_ARM_THM_XPC22: (S + A) | T - P
2130 static inline typename
This::Status
2131 thm_xpc22(const Relocate_info
<32, big_endian
>* relinfo
, unsigned char *view
,
2132 const Sized_symbol
<32>* gsym
, const Arm_relobj
<big_endian
>* object
,
2133 unsigned int r_sym
, const Symbol_value
<32>* psymval
,
2134 Arm_address address
, Arm_address thumb_bit
,
2135 bool is_weakly_undefined_without_plt
)
2137 return thumb_branch_common(elfcpp::R_ARM_THM_XPC22
, relinfo
, view
, gsym
,
2138 object
, r_sym
, psymval
, address
, thumb_bit
,
2139 is_weakly_undefined_without_plt
);
2142 // R_ARM_BASE_PREL: B(S) + A - P
2143 static inline typename
This::Status
2144 base_prel(unsigned char* view
,
2146 Arm_address address
)
2148 Base::rel32(view
, origin
- address
);
2152 // R_ARM_BASE_ABS: B(S) + A
2153 static inline typename
This::Status
2154 base_abs(unsigned char* view
,
2157 Base::rel32(view
, origin
);
2161 // R_ARM_GOT_BREL: GOT(S) + A - GOT_ORG
2162 static inline typename
This::Status
2163 got_brel(unsigned char* view
,
2164 typename
elfcpp::Swap
<32, big_endian
>::Valtype got_offset
)
2166 Base::rel32(view
, got_offset
);
2167 return This::STATUS_OKAY
;
2170 // R_ARM_GOT_PREL: GOT(S) + A - P
2171 static inline typename
This::Status
2172 got_prel(unsigned char *view
,
2173 Arm_address got_entry
,
2174 Arm_address address
)
2176 Base::rel32(view
, got_entry
- address
);
2177 return This::STATUS_OKAY
;
2180 // R_ARM_PLT32: (S + A) | T - P
2181 static inline typename
This::Status
2182 plt32(const Relocate_info
<32, big_endian
>* relinfo
,
2183 unsigned char *view
,
2184 const Sized_symbol
<32>* gsym
,
2185 const Arm_relobj
<big_endian
>* object
,
2187 const Symbol_value
<32>* psymval
,
2188 Arm_address address
,
2189 Arm_address thumb_bit
,
2190 bool is_weakly_undefined_without_plt
)
2192 return arm_branch_common(elfcpp::R_ARM_PLT32
, relinfo
, view
, gsym
,
2193 object
, r_sym
, psymval
, address
, thumb_bit
,
2194 is_weakly_undefined_without_plt
);
2197 // R_ARM_XPC25: (S + A) | T - P
2198 static inline typename
This::Status
2199 xpc25(const Relocate_info
<32, big_endian
>* relinfo
,
2200 unsigned char *view
,
2201 const Sized_symbol
<32>* gsym
,
2202 const Arm_relobj
<big_endian
>* object
,
2204 const Symbol_value
<32>* psymval
,
2205 Arm_address address
,
2206 Arm_address thumb_bit
,
2207 bool is_weakly_undefined_without_plt
)
2209 return arm_branch_common(elfcpp::R_ARM_XPC25
, relinfo
, view
, gsym
,
2210 object
, r_sym
, psymval
, address
, thumb_bit
,
2211 is_weakly_undefined_without_plt
);
2214 // R_ARM_CALL: (S + A) | T - P
2215 static inline typename
This::Status
2216 call(const Relocate_info
<32, big_endian
>* relinfo
,
2217 unsigned char *view
,
2218 const Sized_symbol
<32>* gsym
,
2219 const Arm_relobj
<big_endian
>* object
,
2221 const Symbol_value
<32>* psymval
,
2222 Arm_address address
,
2223 Arm_address thumb_bit
,
2224 bool is_weakly_undefined_without_plt
)
2226 return arm_branch_common(elfcpp::R_ARM_CALL
, relinfo
, view
, gsym
,
2227 object
, r_sym
, psymval
, address
, thumb_bit
,
2228 is_weakly_undefined_without_plt
);
2231 // R_ARM_JUMP24: (S + A) | T - P
2232 static inline typename
This::Status
2233 jump24(const Relocate_info
<32, big_endian
>* relinfo
,
2234 unsigned char *view
,
2235 const Sized_symbol
<32>* gsym
,
2236 const Arm_relobj
<big_endian
>* object
,
2238 const Symbol_value
<32>* psymval
,
2239 Arm_address address
,
2240 Arm_address thumb_bit
,
2241 bool is_weakly_undefined_without_plt
)
2243 return arm_branch_common(elfcpp::R_ARM_JUMP24
, relinfo
, view
, gsym
,
2244 object
, r_sym
, psymval
, address
, thumb_bit
,
2245 is_weakly_undefined_without_plt
);
2248 // R_ARM_PREL: (S + A) | T - P
2249 static inline typename
This::Status
2250 prel31(unsigned char *view
,
2251 const Sized_relobj
<32, big_endian
>* object
,
2252 const Symbol_value
<32>* psymval
,
2253 Arm_address address
,
2254 Arm_address thumb_bit
)
2256 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2257 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2258 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2259 Valtype addend
= utils::sign_extend
<31>(val
);
2260 Valtype x
= (psymval
->value(object
, addend
) | thumb_bit
) - address
;
2261 val
= utils::bit_select(val
, x
, 0x7fffffffU
);
2262 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2263 return (utils::has_overflow
<31>(x
) ?
2264 This::STATUS_OVERFLOW
: This::STATUS_OKAY
);
2267 // R_ARM_MOVW_ABS_NC: (S + A) | T
2268 static inline typename
This::Status
2269 movw_abs_nc(unsigned char *view
,
2270 const Sized_relobj
<32, big_endian
>* object
,
2271 const Symbol_value
<32>* psymval
,
2272 Arm_address thumb_bit
)
2274 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2275 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2276 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2277 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
2278 Valtype x
= psymval
->value(object
, addend
) | thumb_bit
;
2279 val
= This::insert_val_arm_movw_movt(val
, x
);
2280 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2281 return This::STATUS_OKAY
;
2284 // R_ARM_MOVT_ABS: S + A
2285 static inline typename
This::Status
2286 movt_abs(unsigned char *view
,
2287 const Sized_relobj
<32, big_endian
>* object
,
2288 const Symbol_value
<32>* psymval
)
2290 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2291 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2292 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2293 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
2294 Valtype x
= psymval
->value(object
, addend
) >> 16;
2295 val
= This::insert_val_arm_movw_movt(val
, x
);
2296 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2297 return This::STATUS_OKAY
;
2300 // R_ARM_THM_MOVW_ABS_NC: S + A | T
2301 static inline typename
This::Status
2302 thm_movw_abs_nc(unsigned char *view
,
2303 const Sized_relobj
<32, big_endian
>* object
,
2304 const Symbol_value
<32>* psymval
,
2305 Arm_address thumb_bit
)
2307 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
2308 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
2309 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2310 Reltype val
= ((elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
2311 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1));
2312 Reltype addend
= extract_thumb_movw_movt_addend(val
);
2313 Reltype x
= psymval
->value(object
, addend
) | thumb_bit
;
2314 val
= This::insert_val_thumb_movw_movt(val
, x
);
2315 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
2316 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
2317 return This::STATUS_OKAY
;
2320 // R_ARM_THM_MOVT_ABS: S + A
2321 static inline typename
This::Status
2322 thm_movt_abs(unsigned char *view
,
2323 const Sized_relobj
<32, big_endian
>* object
,
2324 const Symbol_value
<32>* psymval
)
2326 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
2327 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
2328 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2329 Reltype val
= ((elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
2330 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1));
2331 Reltype addend
= This::extract_thumb_movw_movt_addend(val
);
2332 Reltype x
= psymval
->value(object
, addend
) >> 16;
2333 val
= This::insert_val_thumb_movw_movt(val
, x
);
2334 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
2335 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
2336 return This::STATUS_OKAY
;
2339 // R_ARM_MOVW_PREL_NC: (S + A) | T - P
2340 static inline typename
This::Status
2341 movw_prel_nc(unsigned char *view
,
2342 const Sized_relobj
<32, big_endian
>* object
,
2343 const Symbol_value
<32>* psymval
,
2344 Arm_address address
,
2345 Arm_address thumb_bit
)
2347 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2348 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2349 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2350 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
2351 Valtype x
= (psymval
->value(object
, addend
) | thumb_bit
) - address
;
2352 val
= This::insert_val_arm_movw_movt(val
, x
);
2353 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2354 return This::STATUS_OKAY
;
2357 // R_ARM_MOVT_PREL: S + A - P
2358 static inline typename
This::Status
2359 movt_prel(unsigned char *view
,
2360 const Sized_relobj
<32, big_endian
>* object
,
2361 const Symbol_value
<32>* psymval
,
2362 Arm_address address
)
2364 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2365 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2366 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2367 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
2368 Valtype x
= (psymval
->value(object
, addend
) - address
) >> 16;
2369 val
= This::insert_val_arm_movw_movt(val
, x
);
2370 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2371 return This::STATUS_OKAY
;
2374 // R_ARM_THM_MOVW_PREL_NC: (S + A) | T - P
2375 static inline typename
This::Status
2376 thm_movw_prel_nc(unsigned char *view
,
2377 const Sized_relobj
<32, big_endian
>* object
,
2378 const Symbol_value
<32>* psymval
,
2379 Arm_address address
,
2380 Arm_address thumb_bit
)
2382 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
2383 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
2384 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2385 Reltype val
= (elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
2386 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
2387 Reltype addend
= This::extract_thumb_movw_movt_addend(val
);
2388 Reltype x
= (psymval
->value(object
, addend
) | thumb_bit
) - address
;
2389 val
= This::insert_val_thumb_movw_movt(val
, x
);
2390 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
2391 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
2392 return This::STATUS_OKAY
;
2395 // R_ARM_THM_MOVT_PREL: S + A - P
2396 static inline typename
This::Status
2397 thm_movt_prel(unsigned char *view
,
2398 const Sized_relobj
<32, big_endian
>* object
,
2399 const Symbol_value
<32>* psymval
,
2400 Arm_address address
)
2402 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
2403 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
2404 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2405 Reltype val
= (elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
2406 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
2407 Reltype addend
= This::extract_thumb_movw_movt_addend(val
);
2408 Reltype x
= (psymval
->value(object
, addend
) - address
) >> 16;
2409 val
= This::insert_val_thumb_movw_movt(val
, x
);
2410 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
2411 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
2412 return This::STATUS_OKAY
;
2416 // Relocate ARM long branches. This handles relocation types
2417 // R_ARM_CALL, R_ARM_JUMP24, R_ARM_PLT32 and R_ARM_XPC25.
2418 // If IS_WEAK_UNDEFINED_WITH_PLT is true. The target symbol is weakly
2419 // undefined and we do not use PLT in this relocation. In such a case,
2420 // the branch is converted into an NOP.
2422 template<bool big_endian
>
2423 typename Arm_relocate_functions
<big_endian
>::Status
2424 Arm_relocate_functions
<big_endian
>::arm_branch_common(
2425 unsigned int r_type
,
2426 const Relocate_info
<32, big_endian
>* relinfo
,
2427 unsigned char *view
,
2428 const Sized_symbol
<32>* gsym
,
2429 const Arm_relobj
<big_endian
>* object
,
2431 const Symbol_value
<32>* psymval
,
2432 Arm_address address
,
2433 Arm_address thumb_bit
,
2434 bool is_weakly_undefined_without_plt
)
2436 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2437 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2438 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2440 bool insn_is_b
= (((val
>> 28) & 0xf) <= 0xe)
2441 && ((val
& 0x0f000000UL
) == 0x0a000000UL
);
2442 bool insn_is_uncond_bl
= (val
& 0xff000000UL
) == 0xeb000000UL
;
2443 bool insn_is_cond_bl
= (((val
>> 28) & 0xf) < 0xe)
2444 && ((val
& 0x0f000000UL
) == 0x0b000000UL
);
2445 bool insn_is_blx
= (val
& 0xfe000000UL
) == 0xfa000000UL
;
2446 bool insn_is_any_branch
= (val
& 0x0e000000UL
) == 0x0a000000UL
;
2448 // Check that the instruction is valid.
2449 if (r_type
== elfcpp::R_ARM_CALL
)
2451 if (!insn_is_uncond_bl
&& !insn_is_blx
)
2452 return This::STATUS_BAD_RELOC
;
2454 else if (r_type
== elfcpp::R_ARM_JUMP24
)
2456 if (!insn_is_b
&& !insn_is_cond_bl
)
2457 return This::STATUS_BAD_RELOC
;
2459 else if (r_type
== elfcpp::R_ARM_PLT32
)
2461 if (!insn_is_any_branch
)
2462 return This::STATUS_BAD_RELOC
;
2464 else if (r_type
== elfcpp::R_ARM_XPC25
)
2466 // FIXME: AAELF document IH0044C does not say much about it other
2467 // than it being obsolete.
2468 if (!insn_is_any_branch
)
2469 return This::STATUS_BAD_RELOC
;
2474 // A branch to an undefined weak symbol is turned into a jump to
2475 // the next instruction unless a PLT entry will be created.
2476 // Do the same for local undefined symbols.
2477 // The jump to the next instruction is optimized as a NOP depending
2478 // on the architecture.
2479 const Target_arm
<big_endian
>* arm_target
=
2480 Target_arm
<big_endian
>::default_target();
2481 if (is_weakly_undefined_without_plt
)
2483 Valtype cond
= val
& 0xf0000000U
;
2484 if (arm_target
->may_use_arm_nop())
2485 val
= cond
| 0x0320f000;
2487 val
= cond
| 0x01a00000; // Using pre-UAL nop: mov r0, r0.
2488 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2489 return This::STATUS_OKAY
;
2492 Valtype addend
= utils::sign_extend
<26>(val
<< 2);
2493 Valtype branch_target
= psymval
->value(object
, addend
);
2494 int32_t branch_offset
= branch_target
- address
;
2496 // We need a stub if the branch offset is too large or if we need
2498 bool may_use_blx
= arm_target
->may_use_blx();
2499 Reloc_stub
* stub
= NULL
;
2500 if ((branch_offset
> ARM_MAX_FWD_BRANCH_OFFSET
)
2501 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
)
2502 || ((thumb_bit
!= 0) && !(may_use_blx
&& r_type
== elfcpp::R_ARM_CALL
)))
2504 Stub_type stub_type
=
2505 Reloc_stub::stub_type_for_reloc(r_type
, address
, branch_target
,
2507 if (stub_type
!= arm_stub_none
)
2509 Stub_table
<big_endian
>* stub_table
=
2510 object
->stub_table(relinfo
->data_shndx
);
2511 gold_assert(stub_table
!= NULL
);
2513 Reloc_stub::Key
stub_key(stub_type
, gsym
, object
, r_sym
, addend
);
2514 stub
= stub_table
->find_reloc_stub(stub_key
);
2515 gold_assert(stub
!= NULL
);
2516 thumb_bit
= stub
->stub_template()->entry_in_thumb_mode() ? 1 : 0;
2517 branch_target
= stub_table
->address() + stub
->offset() + addend
;
2518 branch_offset
= branch_target
- address
;
2519 gold_assert((branch_offset
<= ARM_MAX_FWD_BRANCH_OFFSET
)
2520 && (branch_offset
>= ARM_MAX_BWD_BRANCH_OFFSET
));
2524 // At this point, if we still need to switch mode, the instruction
2525 // must either be a BLX or a BL that can be converted to a BLX.
2529 gold_assert(may_use_blx
&& r_type
== elfcpp::R_ARM_CALL
);
2530 val
= (val
& 0xffffff) | 0xfa000000 | ((branch_offset
& 2) << 23);
2533 val
= utils::bit_select(val
, (branch_offset
>> 2), 0xffffffUL
);
2534 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2535 return (utils::has_overflow
<26>(branch_offset
)
2536 ? This::STATUS_OVERFLOW
: This::STATUS_OKAY
);
2539 // Relocate THUMB long branches. This handles relocation types
2540 // R_ARM_THM_CALL, R_ARM_THM_JUMP24 and R_ARM_THM_XPC22.
2541 // If IS_WEAK_UNDEFINED_WITH_PLT is true. The target symbol is weakly
2542 // undefined and we do not use PLT in this relocation. In such a case,
2543 // the branch is converted into an NOP.
2545 template<bool big_endian
>
2546 typename Arm_relocate_functions
<big_endian
>::Status
2547 Arm_relocate_functions
<big_endian
>::thumb_branch_common(
2548 unsigned int r_type
,
2549 const Relocate_info
<32, big_endian
>* relinfo
,
2550 unsigned char *view
,
2551 const Sized_symbol
<32>* gsym
,
2552 const Arm_relobj
<big_endian
>* object
,
2554 const Symbol_value
<32>* psymval
,
2555 Arm_address address
,
2556 Arm_address thumb_bit
,
2557 bool is_weakly_undefined_without_plt
)
2559 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
2560 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2561 uint32_t upper_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
2562 uint32_t lower_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
2564 // FIXME: These tests are too loose and do not take THUMB/THUMB-2 difference
2566 bool is_bl_insn
= (lower_insn
& 0x1000U
) == 0x1000U
;
2567 bool is_blx_insn
= (lower_insn
& 0x1000U
) == 0x0000U
;
2569 // Check that the instruction is valid.
2570 if (r_type
== elfcpp::R_ARM_THM_CALL
)
2572 if (!is_bl_insn
&& !is_blx_insn
)
2573 return This::STATUS_BAD_RELOC
;
2575 else if (r_type
== elfcpp::R_ARM_THM_JUMP24
)
2577 // This cannot be a BLX.
2579 return This::STATUS_BAD_RELOC
;
2581 else if (r_type
== elfcpp::R_ARM_THM_XPC22
)
2583 // Check for Thumb to Thumb call.
2585 return This::STATUS_BAD_RELOC
;
2588 gold_warning(_("%s: Thumb BLX instruction targets "
2589 "thumb function '%s'."),
2590 object
->name().c_str(),
2591 (gsym
? gsym
->name() : "(local)"));
2592 // Convert BLX to BL.
2593 lower_insn
|= 0x1000U
;
2599 // A branch to an undefined weak symbol is turned into a jump to
2600 // the next instruction unless a PLT entry will be created.
2601 // The jump to the next instruction is optimized as a NOP.W for
2602 // Thumb-2 enabled architectures.
2603 const Target_arm
<big_endian
>* arm_target
=
2604 Target_arm
<big_endian
>::default_target();
2605 if (is_weakly_undefined_without_plt
)
2607 if (arm_target
->may_use_thumb2_nop())
2609 elfcpp::Swap
<16, big_endian
>::writeval(wv
, 0xf3af);
2610 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, 0x8000);
2614 elfcpp::Swap
<16, big_endian
>::writeval(wv
, 0xe000);
2615 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, 0xbf00);
2617 return This::STATUS_OKAY
;
2620 // Fetch the addend. We use the Thumb-2 encoding (backwards compatible
2621 // with Thumb-1) involving the J1 and J2 bits.
2622 uint32_t s
= (upper_insn
& (1 << 10)) >> 10;
2623 uint32_t upper
= upper_insn
& 0x3ff;
2624 uint32_t lower
= lower_insn
& 0x7ff;
2625 uint32_t j1
= (lower_insn
& (1 << 13)) >> 13;
2626 uint32_t j2
= (lower_insn
& (1 << 11)) >> 11;
2627 uint32_t i1
= j1
^ s
? 0 : 1;
2628 uint32_t i2
= j2
^ s
? 0 : 1;
2630 int32_t addend
= (i1
<< 23) | (i2
<< 22) | (upper
<< 12) | (lower
<< 1);
2632 addend
= (addend
| ((s
? 0 : 1) << 24)) - (1 << 24);
2634 Arm_address branch_target
= psymval
->value(object
, addend
);
2635 int32_t branch_offset
= branch_target
- address
;
2637 // We need a stub if the branch offset is too large or if we need
2639 bool may_use_blx
= arm_target
->may_use_blx();
2640 bool thumb2
= arm_target
->using_thumb2();
2642 && (branch_offset
> THM_MAX_FWD_BRANCH_OFFSET
2643 || (branch_offset
< THM_MAX_BWD_BRANCH_OFFSET
)))
2645 && (branch_offset
> THM2_MAX_FWD_BRANCH_OFFSET
2646 || (branch_offset
< THM2_MAX_BWD_BRANCH_OFFSET
)))
2647 || ((thumb_bit
== 0)
2648 && (((r_type
== elfcpp::R_ARM_THM_CALL
) && !may_use_blx
)
2649 || r_type
== elfcpp::R_ARM_THM_JUMP24
)))
2651 Stub_type stub_type
=
2652 Reloc_stub::stub_type_for_reloc(r_type
, address
, branch_target
,
2654 if (stub_type
!= arm_stub_none
)
2656 Stub_table
<big_endian
>* stub_table
=
2657 object
->stub_table(relinfo
->data_shndx
);
2658 gold_assert(stub_table
!= NULL
);
2660 Reloc_stub::Key
stub_key(stub_type
, gsym
, object
, r_sym
, addend
);
2661 Reloc_stub
* stub
= stub_table
->find_reloc_stub(stub_key
);
2662 gold_assert(stub
!= NULL
);
2663 thumb_bit
= stub
->stub_template()->entry_in_thumb_mode() ? 1 : 0;
2664 branch_target
= stub_table
->address() + stub
->offset() + addend
;
2665 branch_offset
= branch_target
- address
;
2669 // At this point, if we still need to switch mode, the instruction
2670 // must either be a BLX or a BL that can be converted to a BLX.
2673 gold_assert(may_use_blx
2674 && (r_type
== elfcpp::R_ARM_THM_CALL
2675 || r_type
== elfcpp::R_ARM_THM_XPC22
));
2676 // Make sure this is a BLX.
2677 lower_insn
&= ~0x1000U
;
2681 // Make sure this is a BL.
2682 lower_insn
|= 0x1000U
;
2685 uint32_t reloc_sign
= (branch_offset
< 0) ? 1 : 0;
2686 uint32_t relocation
= static_cast<uint32_t>(branch_offset
);
2688 if ((lower_insn
& 0x5000U
) == 0x4000U
)
2689 // For a BLX instruction, make sure that the relocation is rounded up
2690 // to a word boundary. This follows the semantics of the instruction
2691 // which specifies that bit 1 of the target address will come from bit
2692 // 1 of the base address.
2693 relocation
= (relocation
+ 2U) & ~3U;
2695 // Put BRANCH_OFFSET back into the insn. Assumes two's complement.
2696 // We use the Thumb-2 encoding, which is safe even if dealing with
2697 // a Thumb-1 instruction by virtue of our overflow check above. */
2698 upper_insn
= (upper_insn
& ~0x7ffU
)
2699 | ((relocation
>> 12) & 0x3ffU
)
2700 | (reloc_sign
<< 10);
2701 lower_insn
= (lower_insn
& ~0x2fffU
)
2702 | (((!((relocation
>> 23) & 1U)) ^ reloc_sign
) << 13)
2703 | (((!((relocation
>> 22) & 1U)) ^ reloc_sign
) << 11)
2704 | ((relocation
>> 1) & 0x7ffU
);
2706 elfcpp::Swap
<16, big_endian
>::writeval(wv
, upper_insn
);
2707 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, lower_insn
);
2710 ? utils::has_overflow
<25>(relocation
)
2711 : utils::has_overflow
<23>(relocation
))
2712 ? This::STATUS_OVERFLOW
2713 : This::STATUS_OKAY
);
2716 // Get the GOT section, creating it if necessary.
2718 template<bool big_endian
>
2719 Output_data_got
<32, big_endian
>*
2720 Target_arm
<big_endian
>::got_section(Symbol_table
* symtab
, Layout
* layout
)
2722 if (this->got_
== NULL
)
2724 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
2726 this->got_
= new Output_data_got
<32, big_endian
>();
2729 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
2731 | elfcpp::SHF_WRITE
),
2732 this->got_
, false, true, true,
2735 // The old GNU linker creates a .got.plt section. We just
2736 // create another set of data in the .got section. Note that we
2737 // always create a PLT if we create a GOT, although the PLT
2739 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
2740 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
2742 | elfcpp::SHF_WRITE
),
2743 this->got_plt_
, false, false,
2746 // The first three entries are reserved.
2747 this->got_plt_
->set_current_data_size(3 * 4);
2749 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
2750 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2751 Symbol_table::PREDEFINED
,
2753 0, 0, elfcpp::STT_OBJECT
,
2755 elfcpp::STV_HIDDEN
, 0,
2761 // Get the dynamic reloc section, creating it if necessary.
2763 template<bool big_endian
>
2764 typename Target_arm
<big_endian
>::Reloc_section
*
2765 Target_arm
<big_endian
>::rel_dyn_section(Layout
* layout
)
2767 if (this->rel_dyn_
== NULL
)
2769 gold_assert(layout
!= NULL
);
2770 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
2771 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
2772 elfcpp::SHF_ALLOC
, this->rel_dyn_
, true,
2773 false, false, false);
2775 return this->rel_dyn_
;
2778 // Insn_template methods.
2780 // Return byte size of an instruction template.
2783 Insn_template::size() const
2785 switch (this->type())
2798 // Return alignment of an instruction template.
2801 Insn_template::alignment() const
2803 switch (this->type())
2816 // Stub_template methods.
2818 Stub_template::Stub_template(
2819 Stub_type type
, const Insn_template
* insns
,
2821 : type_(type
), insns_(insns
), insn_count_(insn_count
), alignment_(1),
2822 entry_in_thumb_mode_(false), relocs_()
2826 // Compute byte size and alignment of stub template.
2827 for (size_t i
= 0; i
< insn_count
; i
++)
2829 unsigned insn_alignment
= insns
[i
].alignment();
2830 size_t insn_size
= insns
[i
].size();
2831 gold_assert((offset
& (insn_alignment
- 1)) == 0);
2832 this->alignment_
= std::max(this->alignment_
, insn_alignment
);
2833 switch (insns
[i
].type())
2835 case Insn_template::THUMB16_TYPE
:
2837 this->entry_in_thumb_mode_
= true;
2840 case Insn_template::THUMB32_TYPE
:
2841 if (insns
[i
].r_type() != elfcpp::R_ARM_NONE
)
2842 this->relocs_
.push_back(Reloc(i
, offset
));
2844 this->entry_in_thumb_mode_
= true;
2847 case Insn_template::ARM_TYPE
:
2848 // Handle cases where the target is encoded within the
2850 if (insns
[i
].r_type() == elfcpp::R_ARM_JUMP24
)
2851 this->relocs_
.push_back(Reloc(i
, offset
));
2854 case Insn_template::DATA_TYPE
:
2855 // Entry point cannot be data.
2856 gold_assert(i
!= 0);
2857 this->relocs_
.push_back(Reloc(i
, offset
));
2863 offset
+= insn_size
;
2865 this->size_
= offset
;
2870 // Template to implement do_write for a specific target endianity.
2872 template<bool big_endian
>
2874 Stub::do_fixed_endian_write(unsigned char* view
, section_size_type view_size
)
2876 const Stub_template
* stub_template
= this->stub_template();
2877 const Insn_template
* insns
= stub_template
->insns();
2879 // FIXME: We do not handle BE8 encoding yet.
2880 unsigned char* pov
= view
;
2881 for (size_t i
= 0; i
< stub_template
->insn_count(); i
++)
2883 switch (insns
[i
].type())
2885 case Insn_template::THUMB16_TYPE
:
2886 elfcpp::Swap
<16, big_endian
>::writeval(pov
, insns
[i
].data() & 0xffff);
2888 case Insn_template::THUMB16_SPECIAL_TYPE
:
2889 elfcpp::Swap
<16, big_endian
>::writeval(
2891 this->thumb16_special(i
));
2893 case Insn_template::THUMB32_TYPE
:
2895 uint32_t hi
= (insns
[i
].data() >> 16) & 0xffff;
2896 uint32_t lo
= insns
[i
].data() & 0xffff;
2897 elfcpp::Swap
<16, big_endian
>::writeval(pov
, hi
);
2898 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lo
);
2901 case Insn_template::ARM_TYPE
:
2902 case Insn_template::DATA_TYPE
:
2903 elfcpp::Swap
<32, big_endian
>::writeval(pov
, insns
[i
].data());
2908 pov
+= insns
[i
].size();
2910 gold_assert(static_cast<section_size_type
>(pov
- view
) == view_size
);
2913 // Reloc_stub::Key methods.
2915 // Dump a Key as a string for debugging.
2918 Reloc_stub::Key::name() const
2920 if (this->r_sym_
== invalid_index
)
2922 // Global symbol key name
2923 // <stub-type>:<symbol name>:<addend>.
2924 const std::string sym_name
= this->u_
.symbol
->name();
2925 // We need to print two hex number and two colons. So just add 100 bytes
2926 // to the symbol name size.
2927 size_t len
= sym_name
.size() + 100;
2928 char* buffer
= new char[len
];
2929 int c
= snprintf(buffer
, len
, "%d:%s:%x", this->stub_type_
,
2930 sym_name
.c_str(), this->addend_
);
2931 gold_assert(c
> 0 && c
< static_cast<int>(len
));
2933 return std::string(buffer
);
2937 // local symbol key name
2938 // <stub-type>:<object>:<r_sym>:<addend>.
2939 const size_t len
= 200;
2941 int c
= snprintf(buffer
, len
, "%d:%p:%u:%x", this->stub_type_
,
2942 this->u_
.relobj
, this->r_sym_
, this->addend_
);
2943 gold_assert(c
> 0 && c
< static_cast<int>(len
));
2944 return std::string(buffer
);
2948 // Reloc_stub methods.
2950 // Determine the type of stub needed, if any, for a relocation of R_TYPE at
2951 // LOCATION to DESTINATION.
2952 // This code is based on the arm_type_of_stub function in
2953 // bfd/elf32-arm.c. We have changed the interface a liitle to keep the Stub
2957 Reloc_stub::stub_type_for_reloc(
2958 unsigned int r_type
,
2959 Arm_address location
,
2960 Arm_address destination
,
2961 bool target_is_thumb
)
2963 Stub_type stub_type
= arm_stub_none
;
2965 // This is a bit ugly but we want to avoid using a templated class for
2966 // big and little endianities.
2968 bool should_force_pic_veneer
;
2971 if (parameters
->target().is_big_endian())
2973 const Target_arm
<true>* big_endian_target
=
2974 Target_arm
<true>::default_target();
2975 may_use_blx
= big_endian_target
->may_use_blx();
2976 should_force_pic_veneer
= big_endian_target
->should_force_pic_veneer();
2977 thumb2
= big_endian_target
->using_thumb2();
2978 thumb_only
= big_endian_target
->using_thumb_only();
2982 const Target_arm
<false>* little_endian_target
=
2983 Target_arm
<false>::default_target();
2984 may_use_blx
= little_endian_target
->may_use_blx();
2985 should_force_pic_veneer
= little_endian_target
->should_force_pic_veneer();
2986 thumb2
= little_endian_target
->using_thumb2();
2987 thumb_only
= little_endian_target
->using_thumb_only();
2990 int64_t branch_offset
= (int64_t)destination
- location
;
2992 if (r_type
== elfcpp::R_ARM_THM_CALL
|| r_type
== elfcpp::R_ARM_THM_JUMP24
)
2994 // Handle cases where:
2995 // - this call goes too far (different Thumb/Thumb2 max
2997 // - it's a Thumb->Arm call and blx is not available, or it's a
2998 // Thumb->Arm branch (not bl). A stub is needed in this case.
3000 && (branch_offset
> THM_MAX_FWD_BRANCH_OFFSET
3001 || (branch_offset
< THM_MAX_BWD_BRANCH_OFFSET
)))
3003 && (branch_offset
> THM2_MAX_FWD_BRANCH_OFFSET
3004 || (branch_offset
< THM2_MAX_BWD_BRANCH_OFFSET
)))
3005 || ((!target_is_thumb
)
3006 && (((r_type
== elfcpp::R_ARM_THM_CALL
) && !may_use_blx
)
3007 || (r_type
== elfcpp::R_ARM_THM_JUMP24
))))
3009 if (target_is_thumb
)
3014 stub_type
= (parameters
->options().shared()
3015 || should_force_pic_veneer
)
3018 && (r_type
== elfcpp::R_ARM_THM_CALL
))
3019 // V5T and above. Stub starts with ARM code, so
3020 // we must be able to switch mode before
3021 // reaching it, which is only possible for 'bl'
3022 // (ie R_ARM_THM_CALL relocation).
3023 ? arm_stub_long_branch_any_thumb_pic
3024 // On V4T, use Thumb code only.
3025 : arm_stub_long_branch_v4t_thumb_thumb_pic
)
3029 && (r_type
== elfcpp::R_ARM_THM_CALL
))
3030 ? arm_stub_long_branch_any_any
// V5T and above.
3031 : arm_stub_long_branch_v4t_thumb_thumb
); // V4T.
3035 stub_type
= (parameters
->options().shared()
3036 || should_force_pic_veneer
)
3037 ? arm_stub_long_branch_thumb_only_pic
// PIC stub.
3038 : arm_stub_long_branch_thumb_only
; // non-PIC stub.
3045 // FIXME: We should check that the input section is from an
3046 // object that has interwork enabled.
3048 stub_type
= (parameters
->options().shared()
3049 || should_force_pic_veneer
)
3052 && (r_type
== elfcpp::R_ARM_THM_CALL
))
3053 ? arm_stub_long_branch_any_arm_pic
// V5T and above.
3054 : arm_stub_long_branch_v4t_thumb_arm_pic
) // V4T.
3058 && (r_type
== elfcpp::R_ARM_THM_CALL
))
3059 ? arm_stub_long_branch_any_any
// V5T and above.
3060 : arm_stub_long_branch_v4t_thumb_arm
); // V4T.
3062 // Handle v4t short branches.
3063 if ((stub_type
== arm_stub_long_branch_v4t_thumb_arm
)
3064 && (branch_offset
<= THM_MAX_FWD_BRANCH_OFFSET
)
3065 && (branch_offset
>= THM_MAX_BWD_BRANCH_OFFSET
))
3066 stub_type
= arm_stub_short_branch_v4t_thumb_arm
;
3070 else if (r_type
== elfcpp::R_ARM_CALL
3071 || r_type
== elfcpp::R_ARM_JUMP24
3072 || r_type
== elfcpp::R_ARM_PLT32
)
3074 if (target_is_thumb
)
3078 // FIXME: We should check that the input section is from an
3079 // object that has interwork enabled.
3081 // We have an extra 2-bytes reach because of
3082 // the mode change (bit 24 (H) of BLX encoding).
3083 if (branch_offset
> (ARM_MAX_FWD_BRANCH_OFFSET
+ 2)
3084 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
)
3085 || ((r_type
== elfcpp::R_ARM_CALL
) && !may_use_blx
)
3086 || (r_type
== elfcpp::R_ARM_JUMP24
)
3087 || (r_type
== elfcpp::R_ARM_PLT32
))
3089 stub_type
= (parameters
->options().shared()
3090 || should_force_pic_veneer
)
3093 ? arm_stub_long_branch_any_thumb_pic
// V5T and above.
3094 : arm_stub_long_branch_v4t_arm_thumb_pic
) // V4T stub.
3098 ? arm_stub_long_branch_any_any
// V5T and above.
3099 : arm_stub_long_branch_v4t_arm_thumb
); // V4T.
3105 if (branch_offset
> ARM_MAX_FWD_BRANCH_OFFSET
3106 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
))
3108 stub_type
= (parameters
->options().shared()
3109 || should_force_pic_veneer
)
3110 ? arm_stub_long_branch_any_arm_pic
// PIC stubs.
3111 : arm_stub_long_branch_any_any
; /// non-PIC.
3119 // Cortex_a8_stub methods.
3121 // Return the instruction for a THUMB16_SPECIAL_TYPE instruction template.
3122 // I is the position of the instruction template in the stub template.
3125 Cortex_a8_stub::do_thumb16_special(size_t i
)
3127 // The only use of this is to copy condition code from a conditional
3128 // branch being worked around to the corresponding conditional branch in
3130 gold_assert(this->stub_template()->type() == arm_stub_a8_veneer_b_cond
3132 uint16_t data
= this->stub_template()->insns()[i
].data();
3133 gold_assert((data
& 0xff00U
) == 0xd000U
);
3134 data
|= ((this->original_insn_
>> 22) & 0xf) << 8;
3138 // Stub_factory methods.
3140 Stub_factory::Stub_factory()
3142 // The instruction template sequences are declared as static
3143 // objects and initialized first time the constructor runs.
3145 // Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
3146 // to reach the stub if necessary.
3147 static const Insn_template elf32_arm_stub_long_branch_any_any
[] =
3149 Insn_template::arm_insn(0xe51ff004), // ldr pc, [pc, #-4]
3150 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
3151 // dcd R_ARM_ABS32(X)
3154 // V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
3156 static const Insn_template elf32_arm_stub_long_branch_v4t_arm_thumb
[] =
3158 Insn_template::arm_insn(0xe59fc000), // ldr ip, [pc, #0]
3159 Insn_template::arm_insn(0xe12fff1c), // bx ip
3160 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
3161 // dcd R_ARM_ABS32(X)
3164 // Thumb -> Thumb long branch stub. Used on M-profile architectures.
3165 static const Insn_template elf32_arm_stub_long_branch_thumb_only
[] =
3167 Insn_template::thumb16_insn(0xb401), // push {r0}
3168 Insn_template::thumb16_insn(0x4802), // ldr r0, [pc, #8]
3169 Insn_template::thumb16_insn(0x4684), // mov ip, r0
3170 Insn_template::thumb16_insn(0xbc01), // pop {r0}
3171 Insn_template::thumb16_insn(0x4760), // bx ip
3172 Insn_template::thumb16_insn(0xbf00), // nop
3173 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
3174 // dcd R_ARM_ABS32(X)
3177 // V4T Thumb -> Thumb long branch stub. Using the stack is not
3179 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_thumb
[] =
3181 Insn_template::thumb16_insn(0x4778), // bx pc
3182 Insn_template::thumb16_insn(0x46c0), // nop
3183 Insn_template::arm_insn(0xe59fc000), // ldr ip, [pc, #0]
3184 Insn_template::arm_insn(0xe12fff1c), // bx ip
3185 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
3186 // dcd R_ARM_ABS32(X)
3189 // V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
3191 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_arm
[] =
3193 Insn_template::thumb16_insn(0x4778), // bx pc
3194 Insn_template::thumb16_insn(0x46c0), // nop
3195 Insn_template::arm_insn(0xe51ff004), // ldr pc, [pc, #-4]
3196 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
3197 // dcd R_ARM_ABS32(X)
3200 // V4T Thumb -> ARM short branch stub. Shorter variant of the above
3201 // one, when the destination is close enough.
3202 static const Insn_template elf32_arm_stub_short_branch_v4t_thumb_arm
[] =
3204 Insn_template::thumb16_insn(0x4778), // bx pc
3205 Insn_template::thumb16_insn(0x46c0), // nop
3206 Insn_template::arm_rel_insn(0xea000000, -8), // b (X-8)
3209 // ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
3210 // blx to reach the stub if necessary.
3211 static const Insn_template elf32_arm_stub_long_branch_any_arm_pic
[] =
3213 Insn_template::arm_insn(0xe59fc000), // ldr r12, [pc]
3214 Insn_template::arm_insn(0xe08ff00c), // add pc, pc, ip
3215 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, -4),
3216 // dcd R_ARM_REL32(X-4)
3219 // ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
3220 // blx to reach the stub if necessary. We can not add into pc;
3221 // it is not guaranteed to mode switch (different in ARMv6 and
3223 static const Insn_template elf32_arm_stub_long_branch_any_thumb_pic
[] =
3225 Insn_template::arm_insn(0xe59fc004), // ldr r12, [pc, #4]
3226 Insn_template::arm_insn(0xe08fc00c), // add ip, pc, ip
3227 Insn_template::arm_insn(0xe12fff1c), // bx ip
3228 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, 0),
3229 // dcd R_ARM_REL32(X)
3232 // V4T ARM -> ARM long branch stub, PIC.
3233 static const Insn_template elf32_arm_stub_long_branch_v4t_arm_thumb_pic
[] =
3235 Insn_template::arm_insn(0xe59fc004), // ldr ip, [pc, #4]
3236 Insn_template::arm_insn(0xe08fc00c), // add ip, pc, ip
3237 Insn_template::arm_insn(0xe12fff1c), // bx ip
3238 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, 0),
3239 // dcd R_ARM_REL32(X)
3242 // V4T Thumb -> ARM long branch stub, PIC.
3243 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_arm_pic
[] =
3245 Insn_template::thumb16_insn(0x4778), // bx pc
3246 Insn_template::thumb16_insn(0x46c0), // nop
3247 Insn_template::arm_insn(0xe59fc000), // ldr ip, [pc, #0]
3248 Insn_template::arm_insn(0xe08cf00f), // add pc, ip, pc
3249 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, -4),
3250 // dcd R_ARM_REL32(X)
3253 // Thumb -> Thumb long branch stub, PIC. Used on M-profile
3255 static const Insn_template elf32_arm_stub_long_branch_thumb_only_pic
[] =
3257 Insn_template::thumb16_insn(0xb401), // push {r0}
3258 Insn_template::thumb16_insn(0x4802), // ldr r0, [pc, #8]
3259 Insn_template::thumb16_insn(0x46fc), // mov ip, pc
3260 Insn_template::thumb16_insn(0x4484), // add ip, r0
3261 Insn_template::thumb16_insn(0xbc01), // pop {r0}
3262 Insn_template::thumb16_insn(0x4760), // bx ip
3263 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, 4),
3264 // dcd R_ARM_REL32(X)
3267 // V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not
3269 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_thumb_pic
[] =
3271 Insn_template::thumb16_insn(0x4778), // bx pc
3272 Insn_template::thumb16_insn(0x46c0), // nop
3273 Insn_template::arm_insn(0xe59fc004), // ldr ip, [pc, #4]
3274 Insn_template::arm_insn(0xe08fc00c), // add ip, pc, ip
3275 Insn_template::arm_insn(0xe12fff1c), // bx ip
3276 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, 0),
3277 // dcd R_ARM_REL32(X)
3280 // Cortex-A8 erratum-workaround stubs.
3282 // Stub used for conditional branches (which may be beyond +/-1MB away,
3283 // so we can't use a conditional branch to reach this stub).
3290 static const Insn_template elf32_arm_stub_a8_veneer_b_cond
[] =
3292 Insn_template::thumb16_bcond_insn(0xd001), // b<cond>.n true
3293 Insn_template::thumb32_b_insn(0xf000b800, -4), // b.w after
3294 Insn_template::thumb32_b_insn(0xf000b800, -4) // true:
3298 // Stub used for b.w and bl.w instructions.
3300 static const Insn_template elf32_arm_stub_a8_veneer_b
[] =
3302 Insn_template::thumb32_b_insn(0xf000b800, -4) // b.w dest
3305 static const Insn_template elf32_arm_stub_a8_veneer_bl
[] =
3307 Insn_template::thumb32_b_insn(0xf000b800, -4) // b.w dest
3310 // Stub used for Thumb-2 blx.w instructions. We modified the original blx.w
3311 // instruction (which switches to ARM mode) to point to this stub. Jump to
3312 // the real destination using an ARM-mode branch.
3313 static const Insn_template elf32_arm_stub_a8_veneer_blx
[] =
3315 Insn_template::arm_rel_insn(0xea000000, -8) // b dest
3318 // Fill in the stub template look-up table. Stub templates are constructed
3319 // per instance of Stub_factory for fast look-up without locking
3320 // in a thread-enabled environment.
3322 this->stub_templates_
[arm_stub_none
] =
3323 new Stub_template(arm_stub_none
, NULL
, 0);
3325 #define DEF_STUB(x) \
3329 = sizeof(elf32_arm_stub_##x) / sizeof(elf32_arm_stub_##x[0]); \
3330 Stub_type type = arm_stub_##x; \
3331 this->stub_templates_[type] = \
3332 new Stub_template(type, elf32_arm_stub_##x, array_size); \
3340 // Stub_table methods.
3342 // Add a STUB with using KEY. Caller is reponsible for avoid adding
3343 // if already a STUB with the same key has been added.
3345 template<bool big_endian
>
3347 Stub_table
<big_endian
>::add_reloc_stub(
3349 const Reloc_stub::Key
& key
)
3351 const Stub_template
* stub_template
= stub
->stub_template();
3352 gold_assert(stub_template
->type() == key
.stub_type());
3353 this->reloc_stubs_
[key
] = stub
;
3354 if (this->addralign_
< stub_template
->alignment())
3355 this->addralign_
= stub_template
->alignment();
3356 this->has_been_changed_
= true;
3359 template<bool big_endian
>
3361 Stub_table
<big_endian
>::relocate_stubs(
3362 const Relocate_info
<32, big_endian
>* relinfo
,
3363 Target_arm
<big_endian
>* arm_target
,
3364 Output_section
* output_section
,
3365 unsigned char* view
,
3366 Arm_address address
,
3367 section_size_type view_size
)
3369 // If we are passed a view bigger than the stub table's. we need to
3371 gold_assert(address
== this->address()
3373 == static_cast<section_size_type
>(this->data_size())));
3375 for (typename
Reloc_stub_map::const_iterator p
= this->reloc_stubs_
.begin();
3376 p
!= this->reloc_stubs_
.end();
3379 Reloc_stub
* stub
= p
->second
;
3380 const Stub_template
* stub_template
= stub
->stub_template();
3381 if (stub_template
->reloc_count() != 0)
3383 // Adjust view to cover the stub only.
3384 section_size_type offset
= stub
->offset();
3385 section_size_type stub_size
= stub_template
->size();
3386 gold_assert(offset
+ stub_size
<= view_size
);
3388 arm_target
->relocate_stub(stub
, relinfo
, output_section
,
3389 view
+ offset
, address
+ offset
,
3395 // Reset address and file offset.
3397 template<bool big_endian
>
3399 Stub_table
<big_endian
>::do_reset_address_and_file_offset()
3402 uint64_t max_addralign
= 1;
3403 for (typename
Reloc_stub_map::const_iterator p
= this->reloc_stubs_
.begin();
3404 p
!= this->reloc_stubs_
.end();
3407 Reloc_stub
* stub
= p
->second
;
3408 const Stub_template
* stub_template
= stub
->stub_template();
3409 uint64_t stub_addralign
= stub_template
->alignment();
3410 max_addralign
= std::max(max_addralign
, stub_addralign
);
3411 off
= align_address(off
, stub_addralign
);
3412 stub
->set_offset(off
);
3413 stub
->reset_destination_address();
3414 off
+= stub_template
->size();
3417 this->addralign_
= max_addralign
;
3418 this->set_current_data_size_for_child(off
);
3421 // Write out the stubs to file.
3423 template<bool big_endian
>
3425 Stub_table
<big_endian
>::do_write(Output_file
* of
)
3427 off_t offset
= this->offset();
3428 const section_size_type oview_size
=
3429 convert_to_section_size_type(this->data_size());
3430 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
3432 for (typename
Reloc_stub_map::const_iterator p
= this->reloc_stubs_
.begin();
3433 p
!= this->reloc_stubs_
.end();
3436 Reloc_stub
* stub
= p
->second
;
3437 Arm_address address
= this->address() + stub
->offset();
3439 == align_address(address
,
3440 stub
->stub_template()->alignment()));
3441 stub
->write(oview
+ stub
->offset(), stub
->stub_template()->size(),
3444 of
->write_output_view(this->offset(), oview_size
, oview
);
3447 // Arm_input_section methods.
3449 // Initialize an Arm_input_section.
3451 template<bool big_endian
>
3453 Arm_input_section
<big_endian
>::init()
3455 Relobj
* relobj
= this->relobj();
3456 unsigned int shndx
= this->shndx();
3458 // Cache these to speed up size and alignment queries. It is too slow
3459 // to call section_addraglin and section_size every time.
3460 this->original_addralign_
= relobj
->section_addralign(shndx
);
3461 this->original_size_
= relobj
->section_size(shndx
);
3463 // We want to make this look like the original input section after
3464 // output sections are finalized.
3465 Output_section
* os
= relobj
->output_section(shndx
);
3466 off_t offset
= relobj
->output_section_offset(shndx
);
3467 gold_assert(os
!= NULL
&& !relobj
->is_output_section_offset_invalid(shndx
));
3468 this->set_address(os
->address() + offset
);
3469 this->set_file_offset(os
->offset() + offset
);
3471 this->set_current_data_size(this->original_size_
);
3472 this->finalize_data_size();
3475 template<bool big_endian
>
3477 Arm_input_section
<big_endian
>::do_write(Output_file
* of
)
3479 // We have to write out the original section content.
3480 section_size_type section_size
;
3481 const unsigned char* section_contents
=
3482 this->relobj()->section_contents(this->shndx(), §ion_size
, false);
3483 of
->write(this->offset(), section_contents
, section_size
);
3485 // If this owns a stub table and it is not empty, write it.
3486 if (this->is_stub_table_owner() && !this->stub_table_
->empty())
3487 this->stub_table_
->write(of
);
3490 // Finalize data size.
3492 template<bool big_endian
>
3494 Arm_input_section
<big_endian
>::set_final_data_size()
3496 // If this owns a stub table, finalize its data size as well.
3497 if (this->is_stub_table_owner())
3499 uint64_t address
= this->address();
3501 // The stub table comes after the original section contents.
3502 address
+= this->original_size_
;
3503 address
= align_address(address
, this->stub_table_
->addralign());
3504 off_t offset
= this->offset() + (address
- this->address());
3505 this->stub_table_
->set_address_and_file_offset(address
, offset
);
3506 address
+= this->stub_table_
->data_size();
3507 gold_assert(address
== this->address() + this->current_data_size());
3510 this->set_data_size(this->current_data_size());
3513 // Reset address and file offset.
3515 template<bool big_endian
>
3517 Arm_input_section
<big_endian
>::do_reset_address_and_file_offset()
3519 // Size of the original input section contents.
3520 off_t off
= convert_types
<off_t
, uint64_t>(this->original_size_
);
3522 // If this is a stub table owner, account for the stub table size.
3523 if (this->is_stub_table_owner())
3525 Stub_table
<big_endian
>* stub_table
= this->stub_table_
;
3527 // Reset the stub table's address and file offset. The
3528 // current data size for child will be updated after that.
3529 stub_table_
->reset_address_and_file_offset();
3530 off
= align_address(off
, stub_table_
->addralign());
3531 off
+= stub_table
->current_data_size();
3534 this->set_current_data_size(off
);
3537 // Arm_output_section methods.
3539 // Create a stub group for input sections from BEGIN to END. OWNER
3540 // points to the input section to be the owner a new stub table.
3542 template<bool big_endian
>
3544 Arm_output_section
<big_endian
>::create_stub_group(
3545 Input_section_list::const_iterator begin
,
3546 Input_section_list::const_iterator end
,
3547 Input_section_list::const_iterator owner
,
3548 Target_arm
<big_endian
>* target
,
3549 std::vector
<Output_relaxed_input_section
*>* new_relaxed_sections
)
3551 // Currently we convert ordinary input sections into relaxed sections only
3552 // at this point but we may want to support creating relaxed input section
3553 // very early. So we check here to see if owner is already a relaxed
3556 Arm_input_section
<big_endian
>* arm_input_section
;
3557 if (owner
->is_relaxed_input_section())
3560 Arm_input_section
<big_endian
>::as_arm_input_section(
3561 owner
->relaxed_input_section());
3565 gold_assert(owner
->is_input_section());
3566 // Create a new relaxed input section.
3568 target
->new_arm_input_section(owner
->relobj(), owner
->shndx());
3569 new_relaxed_sections
->push_back(arm_input_section
);
3572 // Create a stub table.
3573 Stub_table
<big_endian
>* stub_table
=
3574 target
->new_stub_table(arm_input_section
);
3576 arm_input_section
->set_stub_table(stub_table
);
3578 Input_section_list::const_iterator p
= begin
;
3579 Input_section_list::const_iterator prev_p
;
3581 // Look for input sections or relaxed input sections in [begin ... end].
3584 if (p
->is_input_section() || p
->is_relaxed_input_section())
3586 // The stub table information for input sections live
3587 // in their objects.
3588 Arm_relobj
<big_endian
>* arm_relobj
=
3589 Arm_relobj
<big_endian
>::as_arm_relobj(p
->relobj());
3590 arm_relobj
->set_stub_table(p
->shndx(), stub_table
);
3594 while (prev_p
!= end
);
3597 // Group input sections for stub generation. GROUP_SIZE is roughly the limit
3598 // of stub groups. We grow a stub group by adding input section until the
3599 // size is just below GROUP_SIZE. The last input section will be converted
3600 // into a stub table. If STUB_ALWAYS_AFTER_BRANCH is false, we also add
3601 // input section after the stub table, effectively double the group size.
3603 // This is similar to the group_sections() function in elf32-arm.c but is
3604 // implemented differently.
3606 template<bool big_endian
>
3608 Arm_output_section
<big_endian
>::group_sections(
3609 section_size_type group_size
,
3610 bool stubs_always_after_branch
,
3611 Target_arm
<big_endian
>* target
)
3613 // We only care about sections containing code.
3614 if ((this->flags() & elfcpp::SHF_EXECINSTR
) == 0)
3617 // States for grouping.
3620 // No group is being built.
3622 // A group is being built but the stub table is not found yet.
3623 // We keep group a stub group until the size is just under GROUP_SIZE.
3624 // The last input section in the group will be used as the stub table.
3625 FINDING_STUB_SECTION
,
3626 // A group is being built and we have already found a stub table.
3627 // We enter this state to grow a stub group by adding input section
3628 // after the stub table. This effectively doubles the group size.
3632 // Any newly created relaxed sections are stored here.
3633 std::vector
<Output_relaxed_input_section
*> new_relaxed_sections
;
3635 State state
= NO_GROUP
;
3636 section_size_type off
= 0;
3637 section_size_type group_begin_offset
= 0;
3638 section_size_type group_end_offset
= 0;
3639 section_size_type stub_table_end_offset
= 0;
3640 Input_section_list::const_iterator group_begin
=
3641 this->input_sections().end();
3642 Input_section_list::const_iterator stub_table
=
3643 this->input_sections().end();
3644 Input_section_list::const_iterator group_end
= this->input_sections().end();
3645 for (Input_section_list::const_iterator p
= this->input_sections().begin();
3646 p
!= this->input_sections().end();
3649 section_size_type section_begin_offset
=
3650 align_address(off
, p
->addralign());
3651 section_size_type section_end_offset
=
3652 section_begin_offset
+ p
->data_size();
3654 // Check to see if we should group the previously seens sections.
3660 case FINDING_STUB_SECTION
:
3661 // Adding this section makes the group larger than GROUP_SIZE.
3662 if (section_end_offset
- group_begin_offset
>= group_size
)
3664 if (stubs_always_after_branch
)
3666 gold_assert(group_end
!= this->input_sections().end());
3667 this->create_stub_group(group_begin
, group_end
, group_end
,
3668 target
, &new_relaxed_sections
);
3673 // But wait, there's more! Input sections up to
3674 // stub_group_size bytes after the stub table can be
3675 // handled by it too.
3676 state
= HAS_STUB_SECTION
;
3677 stub_table
= group_end
;
3678 stub_table_end_offset
= group_end_offset
;
3683 case HAS_STUB_SECTION
:
3684 // Adding this section makes the post stub-section group larger
3686 if (section_end_offset
- stub_table_end_offset
>= group_size
)
3688 gold_assert(group_end
!= this->input_sections().end());
3689 this->create_stub_group(group_begin
, group_end
, stub_table
,
3690 target
, &new_relaxed_sections
);
3699 // If we see an input section and currently there is no group, start
3700 // a new one. Skip any empty sections.
3701 if ((p
->is_input_section() || p
->is_relaxed_input_section())
3702 && (p
->relobj()->section_size(p
->shndx()) != 0))
3704 if (state
== NO_GROUP
)
3706 state
= FINDING_STUB_SECTION
;
3708 group_begin_offset
= section_begin_offset
;
3711 // Keep track of the last input section seen.
3713 group_end_offset
= section_end_offset
;
3716 off
= section_end_offset
;
3719 // Create a stub group for any ungrouped sections.
3720 if (state
== FINDING_STUB_SECTION
|| state
== HAS_STUB_SECTION
)
3722 gold_assert(group_end
!= this->input_sections().end());
3723 this->create_stub_group(group_begin
, group_end
,
3724 (state
== FINDING_STUB_SECTION
3727 target
, &new_relaxed_sections
);
3730 // Convert input section into relaxed input section in a batch.
3731 if (!new_relaxed_sections
.empty())
3732 this->convert_input_sections_to_relaxed_sections(new_relaxed_sections
);
3734 // Update the section offsets
3735 for (size_t i
= 0; i
< new_relaxed_sections
.size(); ++i
)
3737 Arm_relobj
<big_endian
>* arm_relobj
=
3738 Arm_relobj
<big_endian
>::as_arm_relobj(
3739 new_relaxed_sections
[i
]->relobj());
3740 unsigned int shndx
= new_relaxed_sections
[i
]->shndx();
3741 // Tell Arm_relobj that this input section is converted.
3742 arm_relobj
->convert_input_section_to_relaxed_section(shndx
);
3746 // Arm_relobj methods.
3748 // Scan relocations for stub generation.
3750 template<bool big_endian
>
3752 Arm_relobj
<big_endian
>::scan_sections_for_stubs(
3753 Target_arm
<big_endian
>* arm_target
,
3754 const Symbol_table
* symtab
,
3755 const Layout
* layout
)
3757 unsigned int shnum
= this->shnum();
3758 const unsigned int shdr_size
= elfcpp::Elf_sizes
<32>::shdr_size
;
3760 // Read the section headers.
3761 const unsigned char* pshdrs
= this->get_view(this->elf_file()->shoff(),
3765 // To speed up processing, we set up hash tables for fast lookup of
3766 // input offsets to output addresses.
3767 this->initialize_input_to_output_maps();
3769 const Relobj::Output_sections
& out_sections(this->output_sections());
3771 Relocate_info
<32, big_endian
> relinfo
;
3772 relinfo
.symtab
= symtab
;
3773 relinfo
.layout
= layout
;
3774 relinfo
.object
= this;
3776 const unsigned char* p
= pshdrs
+ shdr_size
;
3777 for (unsigned int i
= 1; i
< shnum
; ++i
, p
+= shdr_size
)
3779 typename
elfcpp::Shdr
<32, big_endian
> shdr(p
);
3781 unsigned int sh_type
= shdr
.get_sh_type();
3782 if (sh_type
!= elfcpp::SHT_REL
&& sh_type
!= elfcpp::SHT_RELA
)
3785 off_t sh_size
= shdr
.get_sh_size();
3789 unsigned int index
= this->adjust_shndx(shdr
.get_sh_info());
3790 if (index
>= this->shnum())
3792 // Ignore reloc section with bad info. This error will be
3793 // reported in the final link.
3797 Output_section
* os
= out_sections
[index
];
3799 || symtab
->is_section_folded(this, index
))
3801 // This relocation section is against a section which we
3802 // discarded or if the section is folded into another
3803 // section due to ICF.
3806 Arm_address output_offset
= this->get_output_section_offset(index
);
3808 if (this->adjust_shndx(shdr
.get_sh_link()) != this->symtab_shndx())
3810 // Ignore reloc section with unexpected symbol table. The
3811 // error will be reported in the final link.
3815 const unsigned char* prelocs
= this->get_view(shdr
.get_sh_offset(),
3816 sh_size
, true, false);
3818 unsigned int reloc_size
;
3819 if (sh_type
== elfcpp::SHT_REL
)
3820 reloc_size
= elfcpp::Elf_sizes
<32>::rel_size
;
3822 reloc_size
= elfcpp::Elf_sizes
<32>::rela_size
;
3824 if (reloc_size
!= shdr
.get_sh_entsize())
3826 // Ignore reloc section with unexpected entsize. The error
3827 // will be reported in the final link.
3831 size_t reloc_count
= sh_size
/ reloc_size
;
3832 if (static_cast<off_t
>(reloc_count
* reloc_size
) != sh_size
)
3834 // Ignore reloc section with uneven size. The error will be
3835 // reported in the final link.
3839 gold_assert(output_offset
!= invalid_address
3840 || this->relocs_must_follow_section_writes());
3842 // Get the section contents. This does work for the case in which
3843 // we modify the contents of an input section. We need to pass the
3844 // output view under such circumstances.
3845 section_size_type input_view_size
= 0;
3846 const unsigned char* input_view
=
3847 this->section_contents(index
, &input_view_size
, false);
3849 relinfo
.reloc_shndx
= i
;
3850 relinfo
.data_shndx
= index
;
3851 arm_target
->scan_section_for_stubs(&relinfo
, sh_type
, prelocs
,
3853 output_offset
== invalid_address
,
3859 // After we've done the relocations, we release the hash tables,
3860 // since we no longer need them.
3861 this->free_input_to_output_maps();
3864 // Count the local symbols. The ARM backend needs to know if a symbol
3865 // is a THUMB function or not. For global symbols, it is easy because
3866 // the Symbol object keeps the ELF symbol type. For local symbol it is
3867 // harder because we cannot access this information. So we override the
3868 // do_count_local_symbol in parent and scan local symbols to mark
3869 // THUMB functions. This is not the most efficient way but I do not want to
3870 // slow down other ports by calling a per symbol targer hook inside
3871 // Sized_relobj<size, big_endian>::do_count_local_symbols.
3873 template<bool big_endian
>
3875 Arm_relobj
<big_endian
>::do_count_local_symbols(
3876 Stringpool_template
<char>* pool
,
3877 Stringpool_template
<char>* dynpool
)
3879 // We need to fix-up the values of any local symbols whose type are
3882 // Ask parent to count the local symbols.
3883 Sized_relobj
<32, big_endian
>::do_count_local_symbols(pool
, dynpool
);
3884 const unsigned int loccount
= this->local_symbol_count();
3888 // Intialize the thumb function bit-vector.
3889 std::vector
<bool> empty_vector(loccount
, false);
3890 this->local_symbol_is_thumb_function_
.swap(empty_vector
);
3892 // Read the symbol table section header.
3893 const unsigned int symtab_shndx
= this->symtab_shndx();
3894 elfcpp::Shdr
<32, big_endian
>
3895 symtabshdr(this, this->elf_file()->section_header(symtab_shndx
));
3896 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
3898 // Read the local symbols.
3899 const int sym_size
=elfcpp::Elf_sizes
<32>::sym_size
;
3900 gold_assert(loccount
== symtabshdr
.get_sh_info());
3901 off_t locsize
= loccount
* sym_size
;
3902 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
3903 locsize
, true, true);
3905 // Loop over the local symbols and mark any local symbols pointing
3906 // to THUMB functions.
3908 // Skip the first dummy symbol.
3910 typename Sized_relobj
<32, big_endian
>::Local_values
* plocal_values
=
3911 this->local_values();
3912 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
3914 elfcpp::Sym
<32, big_endian
> sym(psyms
);
3915 elfcpp::STT st_type
= sym
.get_st_type();
3916 Symbol_value
<32>& lv((*plocal_values
)[i
]);
3917 Arm_address input_value
= lv
.input_value();
3919 if (st_type
== elfcpp::STT_ARM_TFUNC
3920 || (st_type
== elfcpp::STT_FUNC
&& ((input_value
& 1) != 0)))
3922 // This is a THUMB function. Mark this and canonicalize the
3923 // symbol value by setting LSB.
3924 this->local_symbol_is_thumb_function_
[i
] = true;
3925 if ((input_value
& 1) == 0)
3926 lv
.set_input_value(input_value
| 1);
3931 // Relocate sections.
3932 template<bool big_endian
>
3934 Arm_relobj
<big_endian
>::do_relocate_sections(
3935 const Symbol_table
* symtab
,
3936 const Layout
* layout
,
3937 const unsigned char* pshdrs
,
3938 typename Sized_relobj
<32, big_endian
>::Views
* pviews
)
3940 // Call parent to relocate sections.
3941 Sized_relobj
<32, big_endian
>::do_relocate_sections(symtab
, layout
, pshdrs
,
3944 // We do not generate stubs if doing a relocatable link.
3945 if (parameters
->options().relocatable())
3948 // Relocate stub tables.
3949 unsigned int shnum
= this->shnum();
3951 Target_arm
<big_endian
>* arm_target
=
3952 Target_arm
<big_endian
>::default_target();
3954 Relocate_info
<32, big_endian
> relinfo
;
3955 relinfo
.symtab
= symtab
;
3956 relinfo
.layout
= layout
;
3957 relinfo
.object
= this;
3959 for (unsigned int i
= 1; i
< shnum
; ++i
)
3961 Arm_input_section
<big_endian
>* arm_input_section
=
3962 arm_target
->find_arm_input_section(this, i
);
3964 if (arm_input_section
== NULL
3965 || !arm_input_section
->is_stub_table_owner()
3966 || arm_input_section
->stub_table()->empty())
3969 // We cannot discard a section if it owns a stub table.
3970 Output_section
* os
= this->output_section(i
);
3971 gold_assert(os
!= NULL
);
3973 relinfo
.reloc_shndx
= elfcpp::SHN_UNDEF
;
3974 relinfo
.reloc_shdr
= NULL
;
3975 relinfo
.data_shndx
= i
;
3976 relinfo
.data_shdr
= pshdrs
+ i
* elfcpp::Elf_sizes
<32>::shdr_size
;
3978 gold_assert((*pviews
)[i
].view
!= NULL
);
3980 // We are passed the output section view. Adjust it to cover the
3982 Stub_table
<big_endian
>* stub_table
= arm_input_section
->stub_table();
3983 gold_assert((stub_table
->address() >= (*pviews
)[i
].address
)
3984 && ((stub_table
->address() + stub_table
->data_size())
3985 <= (*pviews
)[i
].address
+ (*pviews
)[i
].view_size
));
3987 off_t offset
= stub_table
->address() - (*pviews
)[i
].address
;
3988 unsigned char* view
= (*pviews
)[i
].view
+ offset
;
3989 Arm_address address
= stub_table
->address();
3990 section_size_type view_size
= stub_table
->data_size();
3992 stub_table
->relocate_stubs(&relinfo
, arm_target
, os
, view
, address
,
3997 // Helper functions for both Arm_relobj and Arm_dynobj to read ARM
4000 template<bool big_endian
>
4001 Attributes_section_data
*
4002 read_arm_attributes_section(
4004 Read_symbols_data
*sd
)
4006 // Read the attributes section if there is one.
4007 // We read from the end because gas seems to put it near the end of
4008 // the section headers.
4009 const size_t shdr_size
= elfcpp::Elf_sizes
<32>::shdr_size
;
4010 const unsigned char *ps
=
4011 sd
->section_headers
->data() + shdr_size
* (object
->shnum() - 1);
4012 for (unsigned int i
= object
->shnum(); i
> 0; --i
, ps
-= shdr_size
)
4014 elfcpp::Shdr
<32, big_endian
> shdr(ps
);
4015 if (shdr
.get_sh_type() == elfcpp::SHT_ARM_ATTRIBUTES
)
4017 section_offset_type section_offset
= shdr
.get_sh_offset();
4018 section_size_type section_size
=
4019 convert_to_section_size_type(shdr
.get_sh_size());
4020 File_view
* view
= object
->get_lasting_view(section_offset
,
4021 section_size
, true, false);
4022 return new Attributes_section_data(view
->data(), section_size
);
4028 // Read the symbol information.
4030 template<bool big_endian
>
4032 Arm_relobj
<big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
4034 // Call parent class to read symbol information.
4035 Sized_relobj
<32, big_endian
>::do_read_symbols(sd
);
4037 // Read processor-specific flags in ELF file header.
4038 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
4039 elfcpp::Elf_sizes
<32>::ehdr_size
,
4041 elfcpp::Ehdr
<32, big_endian
> ehdr(pehdr
);
4042 this->processor_specific_flags_
= ehdr
.get_e_flags();
4043 this->attributes_section_data_
=
4044 read_arm_attributes_section
<big_endian
>(this, sd
);
4047 // Arm_dynobj methods.
4049 // Read the symbol information.
4051 template<bool big_endian
>
4053 Arm_dynobj
<big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
4055 // Call parent class to read symbol information.
4056 Sized_dynobj
<32, big_endian
>::do_read_symbols(sd
);
4058 // Read processor-specific flags in ELF file header.
4059 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
4060 elfcpp::Elf_sizes
<32>::ehdr_size
,
4062 elfcpp::Ehdr
<32, big_endian
> ehdr(pehdr
);
4063 this->processor_specific_flags_
= ehdr
.get_e_flags();
4064 this->attributes_section_data_
=
4065 read_arm_attributes_section
<big_endian
>(this, sd
);
4068 // Stub_addend_reader methods.
4070 // Read the addend of a REL relocation of type R_TYPE at VIEW.
4072 template<bool big_endian
>
4073 elfcpp::Elf_types
<32>::Elf_Swxword
4074 Stub_addend_reader
<elfcpp::SHT_REL
, big_endian
>::operator()(
4075 unsigned int r_type
,
4076 const unsigned char* view
,
4077 const typename Reloc_types
<elfcpp::SHT_REL
, 32, big_endian
>::Reloc
&) const
4081 case elfcpp::R_ARM_CALL
:
4082 case elfcpp::R_ARM_JUMP24
:
4083 case elfcpp::R_ARM_PLT32
:
4085 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
4086 const Valtype
* wv
= reinterpret_cast<const Valtype
*>(view
);
4087 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4088 return utils::sign_extend
<26>(val
<< 2);
4091 case elfcpp::R_ARM_THM_CALL
:
4092 case elfcpp::R_ARM_THM_JUMP24
:
4093 case elfcpp::R_ARM_THM_XPC22
:
4095 // Fetch the addend. We use the Thumb-2 encoding (backwards
4096 // compatible with Thumb-1) involving the J1 and J2 bits.
4097 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
4098 const Valtype
* wv
= reinterpret_cast<const Valtype
*>(view
);
4099 Valtype upper_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
4100 Valtype lower_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
4102 uint32_t s
= (upper_insn
& (1 << 10)) >> 10;
4103 uint32_t upper
= upper_insn
& 0x3ff;
4104 uint32_t lower
= lower_insn
& 0x7ff;
4105 uint32_t j1
= (lower_insn
& (1 << 13)) >> 13;
4106 uint32_t j2
= (lower_insn
& (1 << 11)) >> 11;
4107 uint32_t i1
= j1
^ s
? 0 : 1;
4108 uint32_t i2
= j2
^ s
? 0 : 1;
4110 return utils::sign_extend
<25>((s
<< 24) | (i1
<< 23) | (i2
<< 22)
4111 | (upper
<< 12) | (lower
<< 1));
4114 case elfcpp::R_ARM_THM_JUMP19
:
4116 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
4117 const Valtype
* wv
= reinterpret_cast<const Valtype
*>(view
);
4118 Valtype upper_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
4119 Valtype lower_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
4121 // Reconstruct the top three bits and squish the two 11 bit pieces
4123 uint32_t S
= (upper_insn
& 0x0400) >> 10;
4124 uint32_t J1
= (lower_insn
& 0x2000) >> 13;
4125 uint32_t J2
= (lower_insn
& 0x0800) >> 11;
4127 (S
<< 8) | (J2
<< 7) | (J1
<< 6) | (upper_insn
& 0x003f);
4128 uint32_t lower
= (lower_insn
& 0x07ff);
4129 return utils::sign_extend
<23>((upper
<< 12) | (lower
<< 1));
4137 // A class to handle the PLT data.
4139 template<bool big_endian
>
4140 class Output_data_plt_arm
: public Output_section_data
4143 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, big_endian
>
4146 Output_data_plt_arm(Layout
*, Output_data_space
*);
4148 // Add an entry to the PLT.
4150 add_entry(Symbol
* gsym
);
4152 // Return the .rel.plt section data.
4153 const Reloc_section
*
4155 { return this->rel_
; }
4159 do_adjust_output_section(Output_section
* os
);
4161 // Write to a map file.
4163 do_print_to_mapfile(Mapfile
* mapfile
) const
4164 { mapfile
->print_output_data(this, _("** PLT")); }
4167 // Template for the first PLT entry.
4168 static const uint32_t first_plt_entry
[5];
4170 // Template for subsequent PLT entries.
4171 static const uint32_t plt_entry
[3];
4173 // Set the final size.
4175 set_final_data_size()
4177 this->set_data_size(sizeof(first_plt_entry
)
4178 + this->count_
* sizeof(plt_entry
));
4181 // Write out the PLT data.
4183 do_write(Output_file
*);
4185 // The reloc section.
4186 Reloc_section
* rel_
;
4187 // The .got.plt section.
4188 Output_data_space
* got_plt_
;
4189 // The number of PLT entries.
4190 unsigned int count_
;
4193 // Create the PLT section. The ordinary .got section is an argument,
4194 // since we need to refer to the start. We also create our own .got
4195 // section just for PLT entries.
4197 template<bool big_endian
>
4198 Output_data_plt_arm
<big_endian
>::Output_data_plt_arm(Layout
* layout
,
4199 Output_data_space
* got_plt
)
4200 : Output_section_data(4), got_plt_(got_plt
), count_(0)
4202 this->rel_
= new Reloc_section(false);
4203 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
4204 elfcpp::SHF_ALLOC
, this->rel_
, true, false,
4208 template<bool big_endian
>
4210 Output_data_plt_arm
<big_endian
>::do_adjust_output_section(Output_section
* os
)
4215 // Add an entry to the PLT.
4217 template<bool big_endian
>
4219 Output_data_plt_arm
<big_endian
>::add_entry(Symbol
* gsym
)
4221 gold_assert(!gsym
->has_plt_offset());
4223 // Note that when setting the PLT offset we skip the initial
4224 // reserved PLT entry.
4225 gsym
->set_plt_offset((this->count_
) * sizeof(plt_entry
)
4226 + sizeof(first_plt_entry
));
4230 section_offset_type got_offset
= this->got_plt_
->current_data_size();
4232 // Every PLT entry needs a GOT entry which points back to the PLT
4233 // entry (this will be changed by the dynamic linker, normally
4234 // lazily when the function is called).
4235 this->got_plt_
->set_current_data_size(got_offset
+ 4);
4237 // Every PLT entry needs a reloc.
4238 gsym
->set_needs_dynsym_entry();
4239 this->rel_
->add_global(gsym
, elfcpp::R_ARM_JUMP_SLOT
, this->got_plt_
,
4242 // Note that we don't need to save the symbol. The contents of the
4243 // PLT are independent of which symbols are used. The symbols only
4244 // appear in the relocations.
4248 // FIXME: This is not very flexible. Right now this has only been tested
4249 // on armv5te. If we are to support additional architecture features like
4250 // Thumb-2 or BE8, we need to make this more flexible like GNU ld.
4252 // The first entry in the PLT.
4253 template<bool big_endian
>
4254 const uint32_t Output_data_plt_arm
<big_endian
>::first_plt_entry
[5] =
4256 0xe52de004, // str lr, [sp, #-4]!
4257 0xe59fe004, // ldr lr, [pc, #4]
4258 0xe08fe00e, // add lr, pc, lr
4259 0xe5bef008, // ldr pc, [lr, #8]!
4260 0x00000000, // &GOT[0] - .
4263 // Subsequent entries in the PLT.
4265 template<bool big_endian
>
4266 const uint32_t Output_data_plt_arm
<big_endian
>::plt_entry
[3] =
4268 0xe28fc600, // add ip, pc, #0xNN00000
4269 0xe28cca00, // add ip, ip, #0xNN000
4270 0xe5bcf000, // ldr pc, [ip, #0xNNN]!
4273 // Write out the PLT. This uses the hand-coded instructions above,
4274 // and adjusts them as needed. This is all specified by the arm ELF
4275 // Processor Supplement.
4277 template<bool big_endian
>
4279 Output_data_plt_arm
<big_endian
>::do_write(Output_file
* of
)
4281 const off_t offset
= this->offset();
4282 const section_size_type oview_size
=
4283 convert_to_section_size_type(this->data_size());
4284 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4286 const off_t got_file_offset
= this->got_plt_
->offset();
4287 const section_size_type got_size
=
4288 convert_to_section_size_type(this->got_plt_
->data_size());
4289 unsigned char* const got_view
= of
->get_output_view(got_file_offset
,
4291 unsigned char* pov
= oview
;
4293 Arm_address plt_address
= this->address();
4294 Arm_address got_address
= this->got_plt_
->address();
4296 // Write first PLT entry. All but the last word are constants.
4297 const size_t num_first_plt_words
= (sizeof(first_plt_entry
)
4298 / sizeof(plt_entry
[0]));
4299 for (size_t i
= 0; i
< num_first_plt_words
- 1; i
++)
4300 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ i
* 4, first_plt_entry
[i
]);
4301 // Last word in first PLT entry is &GOT[0] - .
4302 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 16,
4303 got_address
- (plt_address
+ 16));
4304 pov
+= sizeof(first_plt_entry
);
4306 unsigned char* got_pov
= got_view
;
4308 memset(got_pov
, 0, 12);
4311 const int rel_size
= elfcpp::Elf_sizes
<32>::rel_size
;
4312 unsigned int plt_offset
= sizeof(first_plt_entry
);
4313 unsigned int plt_rel_offset
= 0;
4314 unsigned int got_offset
= 12;
4315 const unsigned int count
= this->count_
;
4316 for (unsigned int i
= 0;
4319 pov
+= sizeof(plt_entry
),
4321 plt_offset
+= sizeof(plt_entry
),
4322 plt_rel_offset
+= rel_size
,
4325 // Set and adjust the PLT entry itself.
4326 int32_t offset
= ((got_address
+ got_offset
)
4327 - (plt_address
+ plt_offset
+ 8));
4329 gold_assert(offset
>= 0 && offset
< 0x0fffffff);
4330 uint32_t plt_insn0
= plt_entry
[0] | ((offset
>> 20) & 0xff);
4331 elfcpp::Swap
<32, big_endian
>::writeval(pov
, plt_insn0
);
4332 uint32_t plt_insn1
= plt_entry
[1] | ((offset
>> 12) & 0xff);
4333 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, plt_insn1
);
4334 uint32_t plt_insn2
= plt_entry
[2] | (offset
& 0xfff);
4335 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8, plt_insn2
);
4337 // Set the entry in the GOT.
4338 elfcpp::Swap
<32, big_endian
>::writeval(got_pov
, plt_address
);
4341 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
4342 gold_assert(static_cast<section_size_type
>(got_pov
- got_view
) == got_size
);
4344 of
->write_output_view(offset
, oview_size
, oview
);
4345 of
->write_output_view(got_file_offset
, got_size
, got_view
);
4348 // Create a PLT entry for a global symbol.
4350 template<bool big_endian
>
4352 Target_arm
<big_endian
>::make_plt_entry(Symbol_table
* symtab
, Layout
* layout
,
4355 if (gsym
->has_plt_offset())
4358 if (this->plt_
== NULL
)
4360 // Create the GOT sections first.
4361 this->got_section(symtab
, layout
);
4363 this->plt_
= new Output_data_plt_arm
<big_endian
>(layout
, this->got_plt_
);
4364 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
4366 | elfcpp::SHF_EXECINSTR
),
4367 this->plt_
, false, false, false, false);
4369 this->plt_
->add_entry(gsym
);
4372 // Report an unsupported relocation against a local symbol.
4374 template<bool big_endian
>
4376 Target_arm
<big_endian
>::Scan::unsupported_reloc_local(
4377 Sized_relobj
<32, big_endian
>* object
,
4378 unsigned int r_type
)
4380 gold_error(_("%s: unsupported reloc %u against local symbol"),
4381 object
->name().c_str(), r_type
);
4384 // We are about to emit a dynamic relocation of type R_TYPE. If the
4385 // dynamic linker does not support it, issue an error. The GNU linker
4386 // only issues a non-PIC error for an allocated read-only section.
4387 // Here we know the section is allocated, but we don't know that it is
4388 // read-only. But we check for all the relocation types which the
4389 // glibc dynamic linker supports, so it seems appropriate to issue an
4390 // error even if the section is not read-only.
4392 template<bool big_endian
>
4394 Target_arm
<big_endian
>::Scan::check_non_pic(Relobj
* object
,
4395 unsigned int r_type
)
4399 // These are the relocation types supported by glibc for ARM.
4400 case elfcpp::R_ARM_RELATIVE
:
4401 case elfcpp::R_ARM_COPY
:
4402 case elfcpp::R_ARM_GLOB_DAT
:
4403 case elfcpp::R_ARM_JUMP_SLOT
:
4404 case elfcpp::R_ARM_ABS32
:
4405 case elfcpp::R_ARM_ABS32_NOI
:
4406 case elfcpp::R_ARM_PC24
:
4407 // FIXME: The following 3 types are not supported by Android's dynamic
4409 case elfcpp::R_ARM_TLS_DTPMOD32
:
4410 case elfcpp::R_ARM_TLS_DTPOFF32
:
4411 case elfcpp::R_ARM_TLS_TPOFF32
:
4415 // This prevents us from issuing more than one error per reloc
4416 // section. But we can still wind up issuing more than one
4417 // error per object file.
4418 if (this->issued_non_pic_error_
)
4420 object
->error(_("requires unsupported dynamic reloc; "
4421 "recompile with -fPIC"));
4422 this->issued_non_pic_error_
= true;
4425 case elfcpp::R_ARM_NONE
:
4430 // Scan a relocation for a local symbol.
4431 // FIXME: This only handles a subset of relocation types used by Android
4432 // on ARM v5te devices.
4434 template<bool big_endian
>
4436 Target_arm
<big_endian
>::Scan::local(Symbol_table
* symtab
,
4439 Sized_relobj
<32, big_endian
>* object
,
4440 unsigned int data_shndx
,
4441 Output_section
* output_section
,
4442 const elfcpp::Rel
<32, big_endian
>& reloc
,
4443 unsigned int r_type
,
4444 const elfcpp::Sym
<32, big_endian
>&)
4446 r_type
= get_real_reloc_type(r_type
);
4449 case elfcpp::R_ARM_NONE
:
4452 case elfcpp::R_ARM_ABS32
:
4453 case elfcpp::R_ARM_ABS32_NOI
:
4454 // If building a shared library (or a position-independent
4455 // executable), we need to create a dynamic relocation for
4456 // this location. The relocation applied at link time will
4457 // apply the link-time value, so we flag the location with
4458 // an R_ARM_RELATIVE relocation so the dynamic loader can
4459 // relocate it easily.
4460 if (parameters
->options().output_is_position_independent())
4462 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
4463 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
4464 // If we are to add more other reloc types than R_ARM_ABS32,
4465 // we need to add check_non_pic(object, r_type) here.
4466 rel_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_ARM_RELATIVE
,
4467 output_section
, data_shndx
,
4468 reloc
.get_r_offset());
4472 case elfcpp::R_ARM_REL32
:
4473 case elfcpp::R_ARM_THM_CALL
:
4474 case elfcpp::R_ARM_CALL
:
4475 case elfcpp::R_ARM_PREL31
:
4476 case elfcpp::R_ARM_JUMP24
:
4477 case elfcpp::R_ARM_PLT32
:
4478 case elfcpp::R_ARM_THM_ABS5
:
4479 case elfcpp::R_ARM_ABS8
:
4480 case elfcpp::R_ARM_ABS12
:
4481 case elfcpp::R_ARM_ABS16
:
4482 case elfcpp::R_ARM_BASE_ABS
:
4483 case elfcpp::R_ARM_MOVW_ABS_NC
:
4484 case elfcpp::R_ARM_MOVT_ABS
:
4485 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
4486 case elfcpp::R_ARM_THM_MOVT_ABS
:
4487 case elfcpp::R_ARM_MOVW_PREL_NC
:
4488 case elfcpp::R_ARM_MOVT_PREL
:
4489 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
4490 case elfcpp::R_ARM_THM_MOVT_PREL
:
4493 case elfcpp::R_ARM_GOTOFF32
:
4494 // We need a GOT section:
4495 target
->got_section(symtab
, layout
);
4498 case elfcpp::R_ARM_BASE_PREL
:
4499 // FIXME: What about this?
4502 case elfcpp::R_ARM_GOT_BREL
:
4503 case elfcpp::R_ARM_GOT_PREL
:
4505 // The symbol requires a GOT entry.
4506 Output_data_got
<32, big_endian
>* got
=
4507 target
->got_section(symtab
, layout
);
4508 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
4509 if (got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
))
4511 // If we are generating a shared object, we need to add a
4512 // dynamic RELATIVE relocation for this symbol's GOT entry.
4513 if (parameters
->options().output_is_position_independent())
4515 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
4516 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
4517 rel_dyn
->add_local_relative(
4518 object
, r_sym
, elfcpp::R_ARM_RELATIVE
, got
,
4519 object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
));
4525 case elfcpp::R_ARM_TARGET1
:
4526 // This should have been mapped to another type already.
4528 case elfcpp::R_ARM_COPY
:
4529 case elfcpp::R_ARM_GLOB_DAT
:
4530 case elfcpp::R_ARM_JUMP_SLOT
:
4531 case elfcpp::R_ARM_RELATIVE
:
4532 // These are relocations which should only be seen by the
4533 // dynamic linker, and should never be seen here.
4534 gold_error(_("%s: unexpected reloc %u in object file"),
4535 object
->name().c_str(), r_type
);
4539 unsupported_reloc_local(object
, r_type
);
4544 // Report an unsupported relocation against a global symbol.
4546 template<bool big_endian
>
4548 Target_arm
<big_endian
>::Scan::unsupported_reloc_global(
4549 Sized_relobj
<32, big_endian
>* object
,
4550 unsigned int r_type
,
4553 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
4554 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
4557 // Scan a relocation for a global symbol.
4558 // FIXME: This only handles a subset of relocation types used by Android
4559 // on ARM v5te devices.
4561 template<bool big_endian
>
4563 Target_arm
<big_endian
>::Scan::global(Symbol_table
* symtab
,
4566 Sized_relobj
<32, big_endian
>* object
,
4567 unsigned int data_shndx
,
4568 Output_section
* output_section
,
4569 const elfcpp::Rel
<32, big_endian
>& reloc
,
4570 unsigned int r_type
,
4573 r_type
= get_real_reloc_type(r_type
);
4576 case elfcpp::R_ARM_NONE
:
4579 case elfcpp::R_ARM_ABS32
:
4580 case elfcpp::R_ARM_ABS32_NOI
:
4582 // Make a dynamic relocation if necessary.
4583 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
4585 if (target
->may_need_copy_reloc(gsym
))
4587 target
->copy_reloc(symtab
, layout
, object
,
4588 data_shndx
, output_section
, gsym
, reloc
);
4590 else if (gsym
->can_use_relative_reloc(false))
4592 // If we are to add more other reloc types than R_ARM_ABS32,
4593 // we need to add check_non_pic(object, r_type) here.
4594 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
4595 rel_dyn
->add_global_relative(gsym
, elfcpp::R_ARM_RELATIVE
,
4596 output_section
, object
,
4597 data_shndx
, reloc
.get_r_offset());
4601 // If we are to add more other reloc types than R_ARM_ABS32,
4602 // we need to add check_non_pic(object, r_type) here.
4603 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
4604 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
4605 data_shndx
, reloc
.get_r_offset());
4611 case elfcpp::R_ARM_MOVW_ABS_NC
:
4612 case elfcpp::R_ARM_MOVT_ABS
:
4613 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
4614 case elfcpp::R_ARM_THM_MOVT_ABS
:
4615 case elfcpp::R_ARM_MOVW_PREL_NC
:
4616 case elfcpp::R_ARM_MOVT_PREL
:
4617 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
4618 case elfcpp::R_ARM_THM_MOVT_PREL
:
4621 case elfcpp::R_ARM_THM_ABS5
:
4622 case elfcpp::R_ARM_ABS8
:
4623 case elfcpp::R_ARM_ABS12
:
4624 case elfcpp::R_ARM_ABS16
:
4625 case elfcpp::R_ARM_BASE_ABS
:
4627 // No dynamic relocs of this kinds.
4628 // Report the error in case of PIC.
4629 int flags
= Symbol::NON_PIC_REF
;
4630 if (gsym
->type() == elfcpp::STT_FUNC
4631 || gsym
->type() == elfcpp::STT_ARM_TFUNC
)
4632 flags
|= Symbol::FUNCTION_CALL
;
4633 if (gsym
->needs_dynamic_reloc(flags
))
4634 check_non_pic(object
, r_type
);
4638 case elfcpp::R_ARM_REL32
:
4639 case elfcpp::R_ARM_PREL31
:
4641 // Make a dynamic relocation if necessary.
4642 int flags
= Symbol::NON_PIC_REF
;
4643 if (gsym
->needs_dynamic_reloc(flags
))
4645 if (target
->may_need_copy_reloc(gsym
))
4647 target
->copy_reloc(symtab
, layout
, object
,
4648 data_shndx
, output_section
, gsym
, reloc
);
4652 check_non_pic(object
, r_type
);
4653 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
4654 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
4655 data_shndx
, reloc
.get_r_offset());
4661 case elfcpp::R_ARM_JUMP24
:
4662 case elfcpp::R_ARM_THM_JUMP24
:
4663 case elfcpp::R_ARM_CALL
:
4664 case elfcpp::R_ARM_THM_CALL
:
4666 if (Target_arm
<big_endian
>::Scan::symbol_needs_plt_entry(gsym
))
4667 target
->make_plt_entry(symtab
, layout
, gsym
);
4670 // Check to see if this is a function that would need a PLT
4671 // but does not get one because the function symbol is untyped.
4672 // This happens in assembly code missing a proper .type directive.
4673 if ((!gsym
->is_undefined() || parameters
->options().shared())
4674 && !parameters
->doing_static_link()
4675 && gsym
->type() == elfcpp::STT_NOTYPE
4676 && (gsym
->is_from_dynobj()
4677 || gsym
->is_undefined()
4678 || gsym
->is_preemptible()))
4679 gold_error(_("%s is not a function."),
4680 gsym
->demangled_name().c_str());
4684 case elfcpp::R_ARM_PLT32
:
4685 // If the symbol is fully resolved, this is just a relative
4686 // local reloc. Otherwise we need a PLT entry.
4687 if (gsym
->final_value_is_known())
4689 // If building a shared library, we can also skip the PLT entry
4690 // if the symbol is defined in the output file and is protected
4692 if (gsym
->is_defined()
4693 && !gsym
->is_from_dynobj()
4694 && !gsym
->is_preemptible())
4696 target
->make_plt_entry(symtab
, layout
, gsym
);
4699 case elfcpp::R_ARM_GOTOFF32
:
4700 // We need a GOT section.
4701 target
->got_section(symtab
, layout
);
4704 case elfcpp::R_ARM_BASE_PREL
:
4705 // FIXME: What about this?
4708 case elfcpp::R_ARM_GOT_BREL
:
4709 case elfcpp::R_ARM_GOT_PREL
:
4711 // The symbol requires a GOT entry.
4712 Output_data_got
<32, big_endian
>* got
=
4713 target
->got_section(symtab
, layout
);
4714 if (gsym
->final_value_is_known())
4715 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
4718 // If this symbol is not fully resolved, we need to add a
4719 // GOT entry with a dynamic relocation.
4720 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
4721 if (gsym
->is_from_dynobj()
4722 || gsym
->is_undefined()
4723 || gsym
->is_preemptible())
4724 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
,
4725 rel_dyn
, elfcpp::R_ARM_GLOB_DAT
);
4728 if (got
->add_global(gsym
, GOT_TYPE_STANDARD
))
4729 rel_dyn
->add_global_relative(
4730 gsym
, elfcpp::R_ARM_RELATIVE
, got
,
4731 gsym
->got_offset(GOT_TYPE_STANDARD
));
4737 case elfcpp::R_ARM_TARGET1
:
4738 // This should have been mapped to another type already.
4740 case elfcpp::R_ARM_COPY
:
4741 case elfcpp::R_ARM_GLOB_DAT
:
4742 case elfcpp::R_ARM_JUMP_SLOT
:
4743 case elfcpp::R_ARM_RELATIVE
:
4744 // These are relocations which should only be seen by the
4745 // dynamic linker, and should never be seen here.
4746 gold_error(_("%s: unexpected reloc %u in object file"),
4747 object
->name().c_str(), r_type
);
4751 unsupported_reloc_global(object
, r_type
, gsym
);
4756 // Process relocations for gc.
4758 template<bool big_endian
>
4760 Target_arm
<big_endian
>::gc_process_relocs(Symbol_table
* symtab
,
4762 Sized_relobj
<32, big_endian
>* object
,
4763 unsigned int data_shndx
,
4765 const unsigned char* prelocs
,
4767 Output_section
* output_section
,
4768 bool needs_special_offset_handling
,
4769 size_t local_symbol_count
,
4770 const unsigned char* plocal_symbols
)
4772 typedef Target_arm
<big_endian
> Arm
;
4773 typedef typename Target_arm
<big_endian
>::Scan Scan
;
4775 gold::gc_process_relocs
<32, big_endian
, Arm
, elfcpp::SHT_REL
, Scan
>(
4784 needs_special_offset_handling
,
4789 // Scan relocations for a section.
4791 template<bool big_endian
>
4793 Target_arm
<big_endian
>::scan_relocs(Symbol_table
* symtab
,
4795 Sized_relobj
<32, big_endian
>* object
,
4796 unsigned int data_shndx
,
4797 unsigned int sh_type
,
4798 const unsigned char* prelocs
,
4800 Output_section
* output_section
,
4801 bool needs_special_offset_handling
,
4802 size_t local_symbol_count
,
4803 const unsigned char* plocal_symbols
)
4805 typedef typename Target_arm
<big_endian
>::Scan Scan
;
4806 if (sh_type
== elfcpp::SHT_RELA
)
4808 gold_error(_("%s: unsupported RELA reloc section"),
4809 object
->name().c_str());
4813 gold::scan_relocs
<32, big_endian
, Target_arm
, elfcpp::SHT_REL
, Scan
>(
4822 needs_special_offset_handling
,
4827 // Finalize the sections.
4829 template<bool big_endian
>
4831 Target_arm
<big_endian
>::do_finalize_sections(
4833 const Input_objects
* input_objects
,
4834 Symbol_table
* symtab
)
4836 // Merge processor-specific flags.
4837 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
4838 p
!= input_objects
->relobj_end();
4841 Arm_relobj
<big_endian
>* arm_relobj
=
4842 Arm_relobj
<big_endian
>::as_arm_relobj(*p
);
4843 this->merge_processor_specific_flags(
4845 arm_relobj
->processor_specific_flags());
4846 this->merge_object_attributes(arm_relobj
->name().c_str(),
4847 arm_relobj
->attributes_section_data());
4851 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
4852 p
!= input_objects
->dynobj_end();
4855 Arm_dynobj
<big_endian
>* arm_dynobj
=
4856 Arm_dynobj
<big_endian
>::as_arm_dynobj(*p
);
4857 this->merge_processor_specific_flags(
4859 arm_dynobj
->processor_specific_flags());
4860 this->merge_object_attributes(arm_dynobj
->name().c_str(),
4861 arm_dynobj
->attributes_section_data());
4865 Object_attribute
* attr
=
4866 this->get_aeabi_object_attribute(elfcpp::Tag_CPU_arch
);
4867 if (attr
->int_value() > elfcpp::TAG_CPU_ARCH_V4
)
4868 this->set_may_use_blx(true);
4870 // Fill in some more dynamic tags.
4871 const Reloc_section
* rel_plt
= (this->plt_
== NULL
4873 : this->plt_
->rel_plt());
4874 layout
->add_target_dynamic_tags(true, this->got_plt_
, rel_plt
,
4875 this->rel_dyn_
, true);
4877 // Emit any relocs we saved in an attempt to avoid generating COPY
4879 if (this->copy_relocs_
.any_saved_relocs())
4880 this->copy_relocs_
.emit(this->rel_dyn_section(layout
));
4882 // Handle the .ARM.exidx section.
4883 Output_section
* exidx_section
= layout
->find_output_section(".ARM.exidx");
4884 if (exidx_section
!= NULL
4885 && exidx_section
->type() == elfcpp::SHT_ARM_EXIDX
4886 && !parameters
->options().relocatable())
4888 // Create __exidx_start and __exdix_end symbols.
4889 symtab
->define_in_output_data("__exidx_start", NULL
,
4890 Symbol_table::PREDEFINED
,
4891 exidx_section
, 0, 0, elfcpp::STT_OBJECT
,
4892 elfcpp::STB_GLOBAL
, elfcpp::STV_HIDDEN
, 0,
4894 symtab
->define_in_output_data("__exidx_end", NULL
,
4895 Symbol_table::PREDEFINED
,
4896 exidx_section
, 0, 0, elfcpp::STT_OBJECT
,
4897 elfcpp::STB_GLOBAL
, elfcpp::STV_HIDDEN
, 0,
4900 // For the ARM target, we need to add a PT_ARM_EXIDX segment for
4901 // the .ARM.exidx section.
4902 if (!layout
->script_options()->saw_phdrs_clause())
4904 gold_assert(layout
->find_output_segment(elfcpp::PT_ARM_EXIDX
, 0, 0)
4906 Output_segment
* exidx_segment
=
4907 layout
->make_output_segment(elfcpp::PT_ARM_EXIDX
, elfcpp::PF_R
);
4908 exidx_segment
->add_output_section(exidx_section
, elfcpp::PF_R
,
4913 // Create an .ARM.attributes section if there is not one already.
4914 Output_attributes_section_data
* attributes_section
=
4915 new Output_attributes_section_data(*this->attributes_section_data_
);
4916 layout
->add_output_section_data(".ARM.attributes",
4917 elfcpp::SHT_ARM_ATTRIBUTES
, 0,
4918 attributes_section
, false, false, false,
4922 // Return whether a direct absolute static relocation needs to be applied.
4923 // In cases where Scan::local() or Scan::global() has created
4924 // a dynamic relocation other than R_ARM_RELATIVE, the addend
4925 // of the relocation is carried in the data, and we must not
4926 // apply the static relocation.
4928 template<bool big_endian
>
4930 Target_arm
<big_endian
>::Relocate::should_apply_static_reloc(
4931 const Sized_symbol
<32>* gsym
,
4934 Output_section
* output_section
)
4936 // If the output section is not allocated, then we didn't call
4937 // scan_relocs, we didn't create a dynamic reloc, and we must apply
4939 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
4942 // For local symbols, we will have created a non-RELATIVE dynamic
4943 // relocation only if (a) the output is position independent,
4944 // (b) the relocation is absolute (not pc- or segment-relative), and
4945 // (c) the relocation is not 32 bits wide.
4947 return !(parameters
->options().output_is_position_independent()
4948 && (ref_flags
& Symbol::ABSOLUTE_REF
)
4951 // For global symbols, we use the same helper routines used in the
4952 // scan pass. If we did not create a dynamic relocation, or if we
4953 // created a RELATIVE dynamic relocation, we should apply the static
4955 bool has_dyn
= gsym
->needs_dynamic_reloc(ref_flags
);
4956 bool is_rel
= (ref_flags
& Symbol::ABSOLUTE_REF
)
4957 && gsym
->can_use_relative_reloc(ref_flags
4958 & Symbol::FUNCTION_CALL
);
4959 return !has_dyn
|| is_rel
;
4962 // Perform a relocation.
4964 template<bool big_endian
>
4966 Target_arm
<big_endian
>::Relocate::relocate(
4967 const Relocate_info
<32, big_endian
>* relinfo
,
4969 Output_section
*output_section
,
4971 const elfcpp::Rel
<32, big_endian
>& rel
,
4972 unsigned int r_type
,
4973 const Sized_symbol
<32>* gsym
,
4974 const Symbol_value
<32>* psymval
,
4975 unsigned char* view
,
4976 Arm_address address
,
4977 section_size_type
/* view_size */ )
4979 typedef Arm_relocate_functions
<big_endian
> Arm_relocate_functions
;
4981 r_type
= get_real_reloc_type(r_type
);
4983 const Arm_relobj
<big_endian
>* object
=
4984 Arm_relobj
<big_endian
>::as_arm_relobj(relinfo
->object
);
4986 // If the final branch target of a relocation is THUMB instruction, this
4987 // is 1. Otherwise it is 0.
4988 Arm_address thumb_bit
= 0;
4989 Symbol_value
<32> symval
;
4990 bool is_weakly_undefined_without_plt
= false;
4991 if (relnum
!= Target_arm
<big_endian
>::fake_relnum_for_stubs
)
4995 // This is a global symbol. Determine if we use PLT and if the
4996 // final target is THUMB.
4997 if (gsym
->use_plt_offset(reloc_is_non_pic(r_type
)))
4999 // This uses a PLT, change the symbol value.
5000 symval
.set_output_value(target
->plt_section()->address()
5001 + gsym
->plt_offset());
5004 else if (gsym
->is_weak_undefined())
5006 // This is a weakly undefined symbol and we do not use PLT
5007 // for this relocation. A branch targeting this symbol will
5008 // be converted into an NOP.
5009 is_weakly_undefined_without_plt
= true;
5013 // Set thumb bit if symbol:
5014 // -Has type STT_ARM_TFUNC or
5015 // -Has type STT_FUNC, is defined and with LSB in value set.
5017 (((gsym
->type() == elfcpp::STT_ARM_TFUNC
)
5018 || (gsym
->type() == elfcpp::STT_FUNC
5019 && !gsym
->is_undefined()
5020 && ((psymval
->value(object
, 0) & 1) != 0)))
5027 // This is a local symbol. Determine if the final target is THUMB.
5028 // We saved this information when all the local symbols were read.
5029 elfcpp::Elf_types
<32>::Elf_WXword r_info
= rel
.get_r_info();
5030 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(r_info
);
5031 thumb_bit
= object
->local_symbol_is_thumb_function(r_sym
) ? 1 : 0;
5036 // This is a fake relocation synthesized for a stub. It does not have
5037 // a real symbol. We just look at the LSB of the symbol value to
5038 // determine if the target is THUMB or not.
5039 thumb_bit
= ((psymval
->value(object
, 0) & 1) != 0);
5042 // Strip LSB if this points to a THUMB target.
5044 && Target_arm
<big_endian
>::reloc_uses_thumb_bit(r_type
)
5045 && ((psymval
->value(object
, 0) & 1) != 0))
5047 Arm_address stripped_value
=
5048 psymval
->value(object
, 0) & ~static_cast<Arm_address
>(1);
5049 symval
.set_output_value(stripped_value
);
5053 // Get the GOT offset if needed.
5054 // The GOT pointer points to the end of the GOT section.
5055 // We need to subtract the size of the GOT section to get
5056 // the actual offset to use in the relocation.
5057 bool have_got_offset
= false;
5058 unsigned int got_offset
= 0;
5061 case elfcpp::R_ARM_GOT_BREL
:
5062 case elfcpp::R_ARM_GOT_PREL
:
5065 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
5066 got_offset
= (gsym
->got_offset(GOT_TYPE_STANDARD
)
5067 - target
->got_size());
5071 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
5072 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
5073 got_offset
= (object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
)
5074 - target
->got_size());
5076 have_got_offset
= true;
5083 // To look up relocation stubs, we need to pass the symbol table index of
5085 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
5087 typename
Arm_relocate_functions::Status reloc_status
=
5088 Arm_relocate_functions::STATUS_OKAY
;
5091 case elfcpp::R_ARM_NONE
:
5094 case elfcpp::R_ARM_ABS8
:
5095 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
5097 reloc_status
= Arm_relocate_functions::abs8(view
, object
, psymval
);
5100 case elfcpp::R_ARM_ABS12
:
5101 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
5103 reloc_status
= Arm_relocate_functions::abs12(view
, object
, psymval
);
5106 case elfcpp::R_ARM_ABS16
:
5107 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
5109 reloc_status
= Arm_relocate_functions::abs16(view
, object
, psymval
);
5112 case elfcpp::R_ARM_ABS32
:
5113 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
5115 reloc_status
= Arm_relocate_functions::abs32(view
, object
, psymval
,
5119 case elfcpp::R_ARM_ABS32_NOI
:
5120 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
5122 // No thumb bit for this relocation: (S + A)
5123 reloc_status
= Arm_relocate_functions::abs32(view
, object
, psymval
,
5127 case elfcpp::R_ARM_MOVW_ABS_NC
:
5128 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
5130 reloc_status
= Arm_relocate_functions::movw_abs_nc(view
, object
,
5134 gold_error(_("relocation R_ARM_MOVW_ABS_NC cannot be used when making"
5135 "a shared object; recompile with -fPIC"));
5138 case elfcpp::R_ARM_MOVT_ABS
:
5139 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
5141 reloc_status
= Arm_relocate_functions::movt_abs(view
, object
, psymval
);
5143 gold_error(_("relocation R_ARM_MOVT_ABS cannot be used when making"
5144 "a shared object; recompile with -fPIC"));
5147 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
5148 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
5150 reloc_status
= Arm_relocate_functions::thm_movw_abs_nc(view
, object
,
5154 gold_error(_("relocation R_ARM_THM_MOVW_ABS_NC cannot be used when"
5155 "making a shared object; recompile with -fPIC"));
5158 case elfcpp::R_ARM_THM_MOVT_ABS
:
5159 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
5161 reloc_status
= Arm_relocate_functions::thm_movt_abs(view
, object
,
5164 gold_error(_("relocation R_ARM_THM_MOVT_ABS cannot be used when"
5165 "making a shared object; recompile with -fPIC"));
5168 case elfcpp::R_ARM_MOVW_PREL_NC
:
5169 reloc_status
= Arm_relocate_functions::movw_prel_nc(view
, object
,
5174 case elfcpp::R_ARM_MOVT_PREL
:
5175 reloc_status
= Arm_relocate_functions::movt_prel(view
, object
,
5179 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
5180 reloc_status
= Arm_relocate_functions::thm_movw_prel_nc(view
, object
,
5185 case elfcpp::R_ARM_THM_MOVT_PREL
:
5186 reloc_status
= Arm_relocate_functions::thm_movt_prel(view
, object
,
5190 case elfcpp::R_ARM_REL32
:
5191 reloc_status
= Arm_relocate_functions::rel32(view
, object
, psymval
,
5192 address
, thumb_bit
);
5195 case elfcpp::R_ARM_THM_ABS5
:
5196 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
5198 reloc_status
= Arm_relocate_functions::thm_abs5(view
, object
, psymval
);
5201 case elfcpp::R_ARM_THM_CALL
:
5203 Arm_relocate_functions::thm_call(relinfo
, view
, gsym
, object
, r_sym
,
5204 psymval
, address
, thumb_bit
,
5205 is_weakly_undefined_without_plt
);
5208 case elfcpp::R_ARM_XPC25
:
5210 Arm_relocate_functions::xpc25(relinfo
, view
, gsym
, object
, r_sym
,
5211 psymval
, address
, thumb_bit
,
5212 is_weakly_undefined_without_plt
);
5215 case elfcpp::R_ARM_THM_XPC22
:
5217 Arm_relocate_functions::thm_xpc22(relinfo
, view
, gsym
, object
, r_sym
,
5218 psymval
, address
, thumb_bit
,
5219 is_weakly_undefined_without_plt
);
5222 case elfcpp::R_ARM_GOTOFF32
:
5224 Arm_address got_origin
;
5225 got_origin
= target
->got_plt_section()->address();
5226 reloc_status
= Arm_relocate_functions::rel32(view
, object
, psymval
,
5227 got_origin
, thumb_bit
);
5231 case elfcpp::R_ARM_BASE_PREL
:
5234 // Get the addressing origin of the output segment defining the
5235 // symbol gsym (AAELF 4.6.1.2 Relocation types)
5236 gold_assert(gsym
!= NULL
);
5237 if (gsym
->source() == Symbol::IN_OUTPUT_SEGMENT
)
5238 origin
= gsym
->output_segment()->vaddr();
5239 else if (gsym
->source () == Symbol::IN_OUTPUT_DATA
)
5240 origin
= gsym
->output_data()->address();
5243 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
5244 _("cannot find origin of R_ARM_BASE_PREL"));
5247 reloc_status
= Arm_relocate_functions::base_prel(view
, origin
, address
);
5251 case elfcpp::R_ARM_BASE_ABS
:
5253 if (!should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
5258 // Get the addressing origin of the output segment defining
5259 // the symbol gsym (AAELF 4.6.1.2 Relocation types).
5261 // R_ARM_BASE_ABS with the NULL symbol will give the
5262 // absolute address of the GOT origin (GOT_ORG) (see ARM IHI
5263 // 0044C (AAELF): 4.6.1.8 Proxy generating relocations).
5264 origin
= target
->got_plt_section()->address();
5265 else if (gsym
->source() == Symbol::IN_OUTPUT_SEGMENT
)
5266 origin
= gsym
->output_segment()->vaddr();
5267 else if (gsym
->source () == Symbol::IN_OUTPUT_DATA
)
5268 origin
= gsym
->output_data()->address();
5271 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
5272 _("cannot find origin of R_ARM_BASE_ABS"));
5276 reloc_status
= Arm_relocate_functions::base_abs(view
, origin
);
5280 case elfcpp::R_ARM_GOT_BREL
:
5281 gold_assert(have_got_offset
);
5282 reloc_status
= Arm_relocate_functions::got_brel(view
, got_offset
);
5285 case elfcpp::R_ARM_GOT_PREL
:
5286 gold_assert(have_got_offset
);
5287 // Get the address origin for GOT PLT, which is allocated right
5288 // after the GOT section, to calculate an absolute address of
5289 // the symbol GOT entry (got_origin + got_offset).
5290 Arm_address got_origin
;
5291 got_origin
= target
->got_plt_section()->address();
5292 reloc_status
= Arm_relocate_functions::got_prel(view
,
5293 got_origin
+ got_offset
,
5297 case elfcpp::R_ARM_PLT32
:
5298 gold_assert(gsym
== NULL
5299 || gsym
->has_plt_offset()
5300 || gsym
->final_value_is_known()
5301 || (gsym
->is_defined()
5302 && !gsym
->is_from_dynobj()
5303 && !gsym
->is_preemptible()));
5305 Arm_relocate_functions::plt32(relinfo
, view
, gsym
, object
, r_sym
,
5306 psymval
, address
, thumb_bit
,
5307 is_weakly_undefined_without_plt
);
5310 case elfcpp::R_ARM_CALL
:
5312 Arm_relocate_functions::call(relinfo
, view
, gsym
, object
, r_sym
,
5313 psymval
, address
, thumb_bit
,
5314 is_weakly_undefined_without_plt
);
5317 case elfcpp::R_ARM_JUMP24
:
5319 Arm_relocate_functions::jump24(relinfo
, view
, gsym
, object
, r_sym
,
5320 psymval
, address
, thumb_bit
,
5321 is_weakly_undefined_without_plt
);
5324 case elfcpp::R_ARM_THM_JUMP24
:
5326 Arm_relocate_functions::thm_jump24(relinfo
, view
, gsym
, object
, r_sym
,
5327 psymval
, address
, thumb_bit
,
5328 is_weakly_undefined_without_plt
);
5331 case elfcpp::R_ARM_PREL31
:
5332 reloc_status
= Arm_relocate_functions::prel31(view
, object
, psymval
,
5333 address
, thumb_bit
);
5336 case elfcpp::R_ARM_TARGET1
:
5337 // This should have been mapped to another type already.
5339 case elfcpp::R_ARM_COPY
:
5340 case elfcpp::R_ARM_GLOB_DAT
:
5341 case elfcpp::R_ARM_JUMP_SLOT
:
5342 case elfcpp::R_ARM_RELATIVE
:
5343 // These are relocations which should only be seen by the
5344 // dynamic linker, and should never be seen here.
5345 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
5346 _("unexpected reloc %u in object file"),
5351 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
5352 _("unsupported reloc %u"),
5357 // Report any errors.
5358 switch (reloc_status
)
5360 case Arm_relocate_functions::STATUS_OKAY
:
5362 case Arm_relocate_functions::STATUS_OVERFLOW
:
5363 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
5364 _("relocation overflow in relocation %u"),
5367 case Arm_relocate_functions::STATUS_BAD_RELOC
:
5368 gold_error_at_location(
5372 _("unexpected opcode while processing relocation %u"),
5382 // Relocate section data.
5384 template<bool big_endian
>
5386 Target_arm
<big_endian
>::relocate_section(
5387 const Relocate_info
<32, big_endian
>* relinfo
,
5388 unsigned int sh_type
,
5389 const unsigned char* prelocs
,
5391 Output_section
* output_section
,
5392 bool needs_special_offset_handling
,
5393 unsigned char* view
,
5394 Arm_address address
,
5395 section_size_type view_size
,
5396 const Reloc_symbol_changes
* reloc_symbol_changes
)
5398 typedef typename Target_arm
<big_endian
>::Relocate Arm_relocate
;
5399 gold_assert(sh_type
== elfcpp::SHT_REL
);
5401 Arm_input_section
<big_endian
>* arm_input_section
=
5402 this->find_arm_input_section(relinfo
->object
, relinfo
->data_shndx
);
5404 // This is an ARM input section and the view covers the whole output
5406 if (arm_input_section
!= NULL
)
5408 gold_assert(needs_special_offset_handling
);
5409 Arm_address section_address
= arm_input_section
->address();
5410 section_size_type section_size
= arm_input_section
->data_size();
5412 gold_assert((arm_input_section
->address() >= address
)
5413 && ((arm_input_section
->address()
5414 + arm_input_section
->data_size())
5415 <= (address
+ view_size
)));
5417 off_t offset
= section_address
- address
;
5420 view_size
= section_size
;
5423 gold::relocate_section
<32, big_endian
, Target_arm
, elfcpp::SHT_REL
,
5430 needs_special_offset_handling
,
5434 reloc_symbol_changes
);
5437 // Return the size of a relocation while scanning during a relocatable
5440 template<bool big_endian
>
5442 Target_arm
<big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
5443 unsigned int r_type
,
5446 r_type
= get_real_reloc_type(r_type
);
5449 case elfcpp::R_ARM_NONE
:
5452 case elfcpp::R_ARM_ABS8
:
5455 case elfcpp::R_ARM_ABS16
:
5456 case elfcpp::R_ARM_THM_ABS5
:
5459 case elfcpp::R_ARM_ABS32
:
5460 case elfcpp::R_ARM_ABS32_NOI
:
5461 case elfcpp::R_ARM_ABS12
:
5462 case elfcpp::R_ARM_BASE_ABS
:
5463 case elfcpp::R_ARM_REL32
:
5464 case elfcpp::R_ARM_THM_CALL
:
5465 case elfcpp::R_ARM_GOTOFF32
:
5466 case elfcpp::R_ARM_BASE_PREL
:
5467 case elfcpp::R_ARM_GOT_BREL
:
5468 case elfcpp::R_ARM_GOT_PREL
:
5469 case elfcpp::R_ARM_PLT32
:
5470 case elfcpp::R_ARM_CALL
:
5471 case elfcpp::R_ARM_JUMP24
:
5472 case elfcpp::R_ARM_PREL31
:
5473 case elfcpp::R_ARM_MOVW_ABS_NC
:
5474 case elfcpp::R_ARM_MOVT_ABS
:
5475 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
5476 case elfcpp::R_ARM_THM_MOVT_ABS
:
5477 case elfcpp::R_ARM_MOVW_PREL_NC
:
5478 case elfcpp::R_ARM_MOVT_PREL
:
5479 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
5480 case elfcpp::R_ARM_THM_MOVT_PREL
:
5483 case elfcpp::R_ARM_TARGET1
:
5484 // This should have been mapped to another type already.
5486 case elfcpp::R_ARM_COPY
:
5487 case elfcpp::R_ARM_GLOB_DAT
:
5488 case elfcpp::R_ARM_JUMP_SLOT
:
5489 case elfcpp::R_ARM_RELATIVE
:
5490 // These are relocations which should only be seen by the
5491 // dynamic linker, and should never be seen here.
5492 gold_error(_("%s: unexpected reloc %u in object file"),
5493 object
->name().c_str(), r_type
);
5497 object
->error(_("unsupported reloc %u in object file"), r_type
);
5502 // Scan the relocs during a relocatable link.
5504 template<bool big_endian
>
5506 Target_arm
<big_endian
>::scan_relocatable_relocs(
5507 Symbol_table
* symtab
,
5509 Sized_relobj
<32, big_endian
>* object
,
5510 unsigned int data_shndx
,
5511 unsigned int sh_type
,
5512 const unsigned char* prelocs
,
5514 Output_section
* output_section
,
5515 bool needs_special_offset_handling
,
5516 size_t local_symbol_count
,
5517 const unsigned char* plocal_symbols
,
5518 Relocatable_relocs
* rr
)
5520 gold_assert(sh_type
== elfcpp::SHT_REL
);
5522 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_REL
,
5523 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
5525 gold::scan_relocatable_relocs
<32, big_endian
, elfcpp::SHT_REL
,
5526 Scan_relocatable_relocs
>(
5534 needs_special_offset_handling
,
5540 // Relocate a section during a relocatable link.
5542 template<bool big_endian
>
5544 Target_arm
<big_endian
>::relocate_for_relocatable(
5545 const Relocate_info
<32, big_endian
>* relinfo
,
5546 unsigned int sh_type
,
5547 const unsigned char* prelocs
,
5549 Output_section
* output_section
,
5550 off_t offset_in_output_section
,
5551 const Relocatable_relocs
* rr
,
5552 unsigned char* view
,
5553 Arm_address view_address
,
5554 section_size_type view_size
,
5555 unsigned char* reloc_view
,
5556 section_size_type reloc_view_size
)
5558 gold_assert(sh_type
== elfcpp::SHT_REL
);
5560 gold::relocate_for_relocatable
<32, big_endian
, elfcpp::SHT_REL
>(
5565 offset_in_output_section
,
5574 // Return the value to use for a dynamic symbol which requires special
5575 // treatment. This is how we support equality comparisons of function
5576 // pointers across shared library boundaries, as described in the
5577 // processor specific ABI supplement.
5579 template<bool big_endian
>
5581 Target_arm
<big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
5583 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
5584 return this->plt_section()->address() + gsym
->plt_offset();
5587 // Map platform-specific relocs to real relocs
5589 template<bool big_endian
>
5591 Target_arm
<big_endian
>::get_real_reloc_type (unsigned int r_type
)
5595 case elfcpp::R_ARM_TARGET1
:
5596 // This is either R_ARM_ABS32 or R_ARM_REL32;
5597 return elfcpp::R_ARM_ABS32
;
5599 case elfcpp::R_ARM_TARGET2
:
5600 // This can be any reloc type but ususally is R_ARM_GOT_PREL
5601 return elfcpp::R_ARM_GOT_PREL
;
5608 // Whether if two EABI versions V1 and V2 are compatible.
5610 template<bool big_endian
>
5612 Target_arm
<big_endian
>::are_eabi_versions_compatible(
5613 elfcpp::Elf_Word v1
,
5614 elfcpp::Elf_Word v2
)
5616 // v4 and v5 are the same spec before and after it was released,
5617 // so allow mixing them.
5618 if ((v1
== elfcpp::EF_ARM_EABI_VER4
&& v2
== elfcpp::EF_ARM_EABI_VER5
)
5619 || (v1
== elfcpp::EF_ARM_EABI_VER5
&& v2
== elfcpp::EF_ARM_EABI_VER4
))
5625 // Combine FLAGS from an input object called NAME and the processor-specific
5626 // flags in the ELF header of the output. Much of this is adapted from the
5627 // processor-specific flags merging code in elf32_arm_merge_private_bfd_data
5628 // in bfd/elf32-arm.c.
5630 template<bool big_endian
>
5632 Target_arm
<big_endian
>::merge_processor_specific_flags(
5633 const std::string
& name
,
5634 elfcpp::Elf_Word flags
)
5636 if (this->are_processor_specific_flags_set())
5638 elfcpp::Elf_Word out_flags
= this->processor_specific_flags();
5640 // Nothing to merge if flags equal to those in output.
5641 if (flags
== out_flags
)
5644 // Complain about various flag mismatches.
5645 elfcpp::Elf_Word version1
= elfcpp::arm_eabi_version(flags
);
5646 elfcpp::Elf_Word version2
= elfcpp::arm_eabi_version(out_flags
);
5647 if (!this->are_eabi_versions_compatible(version1
, version2
))
5648 gold_error(_("Source object %s has EABI version %d but output has "
5649 "EABI version %d."),
5651 (flags
& elfcpp::EF_ARM_EABIMASK
) >> 24,
5652 (out_flags
& elfcpp::EF_ARM_EABIMASK
) >> 24);
5656 // If the input is the default architecture and had the default
5657 // flags then do not bother setting the flags for the output
5658 // architecture, instead allow future merges to do this. If no
5659 // future merges ever set these flags then they will retain their
5660 // uninitialised values, which surprise surprise, correspond
5661 // to the default values.
5665 // This is the first time, just copy the flags.
5666 // We only copy the EABI version for now.
5667 this->set_processor_specific_flags(flags
& elfcpp::EF_ARM_EABIMASK
);
5671 // Adjust ELF file header.
5672 template<bool big_endian
>
5674 Target_arm
<big_endian
>::do_adjust_elf_header(
5675 unsigned char* view
,
5678 gold_assert(len
== elfcpp::Elf_sizes
<32>::ehdr_size
);
5680 elfcpp::Ehdr
<32, big_endian
> ehdr(view
);
5681 unsigned char e_ident
[elfcpp::EI_NIDENT
];
5682 memcpy(e_ident
, ehdr
.get_e_ident(), elfcpp::EI_NIDENT
);
5684 if (elfcpp::arm_eabi_version(this->processor_specific_flags())
5685 == elfcpp::EF_ARM_EABI_UNKNOWN
)
5686 e_ident
[elfcpp::EI_OSABI
] = elfcpp::ELFOSABI_ARM
;
5688 e_ident
[elfcpp::EI_OSABI
] = 0;
5689 e_ident
[elfcpp::EI_ABIVERSION
] = 0;
5691 // FIXME: Do EF_ARM_BE8 adjustment.
5693 elfcpp::Ehdr_write
<32, big_endian
> oehdr(view
);
5694 oehdr
.put_e_ident(e_ident
);
5697 // do_make_elf_object to override the same function in the base class.
5698 // We need to use a target-specific sub-class of Sized_relobj<32, big_endian>
5699 // to store ARM specific information. Hence we need to have our own
5700 // ELF object creation.
5702 template<bool big_endian
>
5704 Target_arm
<big_endian
>::do_make_elf_object(
5705 const std::string
& name
,
5706 Input_file
* input_file
,
5707 off_t offset
, const elfcpp::Ehdr
<32, big_endian
>& ehdr
)
5709 int et
= ehdr
.get_e_type();
5710 if (et
== elfcpp::ET_REL
)
5712 Arm_relobj
<big_endian
>* obj
=
5713 new Arm_relobj
<big_endian
>(name
, input_file
, offset
, ehdr
);
5717 else if (et
== elfcpp::ET_DYN
)
5719 Sized_dynobj
<32, big_endian
>* obj
=
5720 new Arm_dynobj
<big_endian
>(name
, input_file
, offset
, ehdr
);
5726 gold_error(_("%s: unsupported ELF file type %d"),
5732 // Read the architecture from the Tag_also_compatible_with attribute, if any.
5733 // Returns -1 if no architecture could be read.
5734 // This is adapted from get_secondary_compatible_arch() in bfd/elf32-arm.c.
5736 template<bool big_endian
>
5738 Target_arm
<big_endian
>::get_secondary_compatible_arch(
5739 const Attributes_section_data
* pasd
)
5741 const Object_attribute
*known_attributes
=
5742 pasd
->known_attributes(Object_attribute::OBJ_ATTR_PROC
);
5744 // Note: the tag and its argument below are uleb128 values, though
5745 // currently-defined values fit in one byte for each.
5746 const std::string
& sv
=
5747 known_attributes
[elfcpp::Tag_also_compatible_with
].string_value();
5749 && sv
.data()[0] == elfcpp::Tag_CPU_arch
5750 && (sv
.data()[1] & 128) != 128)
5751 return sv
.data()[1];
5753 // This tag is "safely ignorable", so don't complain if it looks funny.
5757 // Set, or unset, the architecture of the Tag_also_compatible_with attribute.
5758 // The tag is removed if ARCH is -1.
5759 // This is adapted from set_secondary_compatible_arch() in bfd/elf32-arm.c.
5761 template<bool big_endian
>
5763 Target_arm
<big_endian
>::set_secondary_compatible_arch(
5764 Attributes_section_data
* pasd
,
5767 Object_attribute
*known_attributes
=
5768 pasd
->known_attributes(Object_attribute::OBJ_ATTR_PROC
);
5772 known_attributes
[elfcpp::Tag_also_compatible_with
].set_string_value("");
5776 // Note: the tag and its argument below are uleb128 values, though
5777 // currently-defined values fit in one byte for each.
5779 sv
[0] = elfcpp::Tag_CPU_arch
;
5780 gold_assert(arch
!= 0);
5784 known_attributes
[elfcpp::Tag_also_compatible_with
].set_string_value(sv
);
5787 // Combine two values for Tag_CPU_arch, taking secondary compatibility tags
5789 // This is adapted from tag_cpu_arch_combine() in bfd/elf32-arm.c.
5791 template<bool big_endian
>
5793 Target_arm
<big_endian
>::tag_cpu_arch_combine(
5796 int* secondary_compat_out
,
5798 int secondary_compat
)
5800 #define T(X) elfcpp::TAG_CPU_ARCH_##X
5801 static const int v6t2
[] =
5813 static const int v6k
[] =
5826 static const int v7
[] =
5840 static const int v6_m
[] =
5855 static const int v6s_m
[] =
5871 static const int v7e_m
[] =
5888 static const int v4t_plus_v6_m
[] =
5904 T(V4T_PLUS_V6_M
) // V4T plus V6_M.
5906 static const int *comb
[] =
5914 // Pseudo-architecture.
5918 // Check we've not got a higher architecture than we know about.
5920 if (oldtag
>= elfcpp::MAX_TAG_CPU_ARCH
|| newtag
>= elfcpp::MAX_TAG_CPU_ARCH
)
5922 gold_error(_("%s: unknown CPU architecture"), name
);
5926 // Override old tag if we have a Tag_also_compatible_with on the output.
5928 if ((oldtag
== T(V6_M
) && *secondary_compat_out
== T(V4T
))
5929 || (oldtag
== T(V4T
) && *secondary_compat_out
== T(V6_M
)))
5930 oldtag
= T(V4T_PLUS_V6_M
);
5932 // And override the new tag if we have a Tag_also_compatible_with on the
5935 if ((newtag
== T(V6_M
) && secondary_compat
== T(V4T
))
5936 || (newtag
== T(V4T
) && secondary_compat
== T(V6_M
)))
5937 newtag
= T(V4T_PLUS_V6_M
);
5939 // Architectures before V6KZ add features monotonically.
5940 int tagh
= std::max(oldtag
, newtag
);
5941 if (tagh
<= elfcpp::TAG_CPU_ARCH_V6KZ
)
5944 int tagl
= std::min(oldtag
, newtag
);
5945 int result
= comb
[tagh
- T(V6T2
)][tagl
];
5947 // Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
5948 // as the canonical version.
5949 if (result
== T(V4T_PLUS_V6_M
))
5952 *secondary_compat_out
= T(V6_M
);
5955 *secondary_compat_out
= -1;
5959 gold_error(_("%s: conflicting CPU architectures %d/%d"),
5960 name
, oldtag
, newtag
);
5968 // Helper to print AEABI enum tag value.
5970 template<bool big_endian
>
5972 Target_arm
<big_endian
>::aeabi_enum_name(unsigned int value
)
5974 static const char *aeabi_enum_names
[] =
5975 { "", "variable-size", "32-bit", "" };
5976 const size_t aeabi_enum_names_size
=
5977 sizeof(aeabi_enum_names
) / sizeof(aeabi_enum_names
[0]);
5979 if (value
< aeabi_enum_names_size
)
5980 return std::string(aeabi_enum_names
[value
]);
5984 sprintf(buffer
, "<unknown value %u>", value
);
5985 return std::string(buffer
);
5989 // Return the string value to store in TAG_CPU_name.
5991 template<bool big_endian
>
5993 Target_arm
<big_endian
>::tag_cpu_name_value(unsigned int value
)
5995 static const char *name_table
[] = {
5996 // These aren't real CPU names, but we can't guess
5997 // that from the architecture version alone.
6013 const size_t name_table_size
= sizeof(name_table
) / sizeof(name_table
[0]);
6015 if (value
< name_table_size
)
6016 return std::string(name_table
[value
]);
6020 sprintf(buffer
, "<unknown CPU value %u>", value
);
6021 return std::string(buffer
);
6025 // Merge object attributes from input file called NAME with those of the
6026 // output. The input object attributes are in the object pointed by PASD.
6028 template<bool big_endian
>
6030 Target_arm
<big_endian
>::merge_object_attributes(
6032 const Attributes_section_data
* pasd
)
6034 // Return if there is no attributes section data.
6038 // If output has no object attributes, just copy.
6039 if (this->attributes_section_data_
== NULL
)
6041 this->attributes_section_data_
= new Attributes_section_data(*pasd
);
6045 const int vendor
= Object_attribute::OBJ_ATTR_PROC
;
6046 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
6047 Object_attribute
* out_attr
=
6048 this->attributes_section_data_
->known_attributes(vendor
);
6050 // This needs to happen before Tag_ABI_FP_number_model is merged. */
6051 if (in_attr
[elfcpp::Tag_ABI_VFP_args
].int_value()
6052 != out_attr
[elfcpp::Tag_ABI_VFP_args
].int_value())
6054 // Ignore mismatches if the object doesn't use floating point. */
6055 if (out_attr
[elfcpp::Tag_ABI_FP_number_model
].int_value() == 0)
6056 out_attr
[elfcpp::Tag_ABI_VFP_args
].set_int_value(
6057 in_attr
[elfcpp::Tag_ABI_VFP_args
].int_value());
6058 else if (in_attr
[elfcpp::Tag_ABI_FP_number_model
].int_value() != 0)
6059 gold_error(_("%s uses VFP register arguments, output does not"),
6063 for (int i
= 4; i
< Vendor_object_attributes::NUM_KNOWN_ATTRIBUTES
; ++i
)
6065 // Merge this attribute with existing attributes.
6068 case elfcpp::Tag_CPU_raw_name
:
6069 case elfcpp::Tag_CPU_name
:
6070 // These are merged after Tag_CPU_arch.
6073 case elfcpp::Tag_ABI_optimization_goals
:
6074 case elfcpp::Tag_ABI_FP_optimization_goals
:
6075 // Use the first value seen.
6078 case elfcpp::Tag_CPU_arch
:
6080 unsigned int saved_out_attr
= out_attr
->int_value();
6081 // Merge Tag_CPU_arch and Tag_also_compatible_with.
6082 int secondary_compat
=
6083 this->get_secondary_compatible_arch(pasd
);
6084 int secondary_compat_out
=
6085 this->get_secondary_compatible_arch(
6086 this->attributes_section_data_
);
6087 out_attr
[i
].set_int_value(
6088 tag_cpu_arch_combine(name
, out_attr
[i
].int_value(),
6089 &secondary_compat_out
,
6090 in_attr
[i
].int_value(),
6092 this->set_secondary_compatible_arch(this->attributes_section_data_
,
6093 secondary_compat_out
);
6095 // Merge Tag_CPU_name and Tag_CPU_raw_name.
6096 if (out_attr
[i
].int_value() == saved_out_attr
)
6097 ; // Leave the names alone.
6098 else if (out_attr
[i
].int_value() == in_attr
[i
].int_value())
6100 // The output architecture has been changed to match the
6101 // input architecture. Use the input names.
6102 out_attr
[elfcpp::Tag_CPU_name
].set_string_value(
6103 in_attr
[elfcpp::Tag_CPU_name
].string_value());
6104 out_attr
[elfcpp::Tag_CPU_raw_name
].set_string_value(
6105 in_attr
[elfcpp::Tag_CPU_raw_name
].string_value());
6109 out_attr
[elfcpp::Tag_CPU_name
].set_string_value("");
6110 out_attr
[elfcpp::Tag_CPU_raw_name
].set_string_value("");
6113 // If we still don't have a value for Tag_CPU_name,
6114 // make one up now. Tag_CPU_raw_name remains blank.
6115 if (out_attr
[elfcpp::Tag_CPU_name
].string_value() == "")
6117 const std::string cpu_name
=
6118 this->tag_cpu_name_value(out_attr
[i
].int_value());
6119 // FIXME: If we see an unknown CPU, this will be set
6120 // to "<unknown CPU n>", where n is the attribute value.
6121 // This is different from BFD, which leaves the name alone.
6122 out_attr
[elfcpp::Tag_CPU_name
].set_string_value(cpu_name
);
6127 case elfcpp::Tag_ARM_ISA_use
:
6128 case elfcpp::Tag_THUMB_ISA_use
:
6129 case elfcpp::Tag_WMMX_arch
:
6130 case elfcpp::Tag_Advanced_SIMD_arch
:
6131 // ??? Do Advanced_SIMD (NEON) and WMMX conflict?
6132 case elfcpp::Tag_ABI_FP_rounding
:
6133 case elfcpp::Tag_ABI_FP_exceptions
:
6134 case elfcpp::Tag_ABI_FP_user_exceptions
:
6135 case elfcpp::Tag_ABI_FP_number_model
:
6136 case elfcpp::Tag_VFP_HP_extension
:
6137 case elfcpp::Tag_CPU_unaligned_access
:
6138 case elfcpp::Tag_T2EE_use
:
6139 case elfcpp::Tag_Virtualization_use
:
6140 case elfcpp::Tag_MPextension_use
:
6141 // Use the largest value specified.
6142 if (in_attr
[i
].int_value() > out_attr
[i
].int_value())
6143 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
6146 case elfcpp::Tag_ABI_align8_preserved
:
6147 case elfcpp::Tag_ABI_PCS_RO_data
:
6148 // Use the smallest value specified.
6149 if (in_attr
[i
].int_value() < out_attr
[i
].int_value())
6150 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
6153 case elfcpp::Tag_ABI_align8_needed
:
6154 if ((in_attr
[i
].int_value() > 0 || out_attr
[i
].int_value() > 0)
6155 && (in_attr
[elfcpp::Tag_ABI_align8_preserved
].int_value() == 0
6156 || (out_attr
[elfcpp::Tag_ABI_align8_preserved
].int_value()
6159 // This error message should be enabled once all non-conformant
6160 // binaries in the toolchain have had the attributes set
6162 // gold_error(_("output 8-byte data alignment conflicts with %s"),
6166 case elfcpp::Tag_ABI_FP_denormal
:
6167 case elfcpp::Tag_ABI_PCS_GOT_use
:
6169 // These tags have 0 = don't care, 1 = strong requirement,
6170 // 2 = weak requirement.
6171 static const int order_021
[3] = {0, 2, 1};
6173 // Use the "greatest" from the sequence 0, 2, 1, or the largest
6174 // value if greater than 2 (for future-proofing).
6175 if ((in_attr
[i
].int_value() > 2
6176 && in_attr
[i
].int_value() > out_attr
[i
].int_value())
6177 || (in_attr
[i
].int_value() <= 2
6178 && out_attr
[i
].int_value() <= 2
6179 && (order_021
[in_attr
[i
].int_value()]
6180 > order_021
[out_attr
[i
].int_value()])))
6181 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
6185 case elfcpp::Tag_CPU_arch_profile
:
6186 if (out_attr
[i
].int_value() != in_attr
[i
].int_value())
6188 // 0 will merge with anything.
6189 // 'A' and 'S' merge to 'A'.
6190 // 'R' and 'S' merge to 'R'.
6191 // 'M' and 'A|R|S' is an error.
6192 if (out_attr
[i
].int_value() == 0
6193 || (out_attr
[i
].int_value() == 'S'
6194 && (in_attr
[i
].int_value() == 'A'
6195 || in_attr
[i
].int_value() == 'R')))
6196 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
6197 else if (in_attr
[i
].int_value() == 0
6198 || (in_attr
[i
].int_value() == 'S'
6199 && (out_attr
[i
].int_value() == 'A'
6200 || out_attr
[i
].int_value() == 'R')))
6205 (_("conflicting architecture profiles %c/%c"),
6206 in_attr
[i
].int_value() ? in_attr
[i
].int_value() : '0',
6207 out_attr
[i
].int_value() ? out_attr
[i
].int_value() : '0');
6211 case elfcpp::Tag_VFP_arch
:
6228 // Values greater than 6 aren't defined, so just pick the
6230 if (in_attr
[i
].int_value() > 6
6231 && in_attr
[i
].int_value() > out_attr
[i
].int_value())
6233 *out_attr
= *in_attr
;
6236 // The output uses the superset of input features
6237 // (ISA version) and registers.
6238 int ver
= std::max(vfp_versions
[in_attr
[i
].int_value()].ver
,
6239 vfp_versions
[out_attr
[i
].int_value()].ver
);
6240 int regs
= std::max(vfp_versions
[in_attr
[i
].int_value()].regs
,
6241 vfp_versions
[out_attr
[i
].int_value()].regs
);
6242 // This assumes all possible supersets are also a valid
6245 for (newval
= 6; newval
> 0; newval
--)
6247 if (regs
== vfp_versions
[newval
].regs
6248 && ver
== vfp_versions
[newval
].ver
)
6251 out_attr
[i
].set_int_value(newval
);
6254 case elfcpp::Tag_PCS_config
:
6255 if (out_attr
[i
].int_value() == 0)
6256 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
6257 else if (in_attr
[i
].int_value() != 0 && out_attr
[i
].int_value() != 0)
6259 // It's sometimes ok to mix different configs, so this is only
6261 gold_warning(_("%s: conflicting platform configuration"), name
);
6264 case elfcpp::Tag_ABI_PCS_R9_use
:
6265 if (in_attr
[i
].int_value() != out_attr
[i
].int_value()
6266 && out_attr
[i
].int_value() != elfcpp::AEABI_R9_unused
6267 && in_attr
[i
].int_value() != elfcpp::AEABI_R9_unused
)
6269 gold_error(_("%s: conflicting use of R9"), name
);
6271 if (out_attr
[i
].int_value() == elfcpp::AEABI_R9_unused
)
6272 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
6274 case elfcpp::Tag_ABI_PCS_RW_data
:
6275 if (in_attr
[i
].int_value() == elfcpp::AEABI_PCS_RW_data_SBrel
6276 && (in_attr
[elfcpp::Tag_ABI_PCS_R9_use
].int_value()
6277 != elfcpp::AEABI_R9_SB
)
6278 && (out_attr
[elfcpp::Tag_ABI_PCS_R9_use
].int_value()
6279 != elfcpp::AEABI_R9_unused
))
6281 gold_error(_("%s: SB relative addressing conflicts with use "
6285 // Use the smallest value specified.
6286 if (in_attr
[i
].int_value() < out_attr
[i
].int_value())
6287 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
6289 case elfcpp::Tag_ABI_PCS_wchar_t
:
6290 // FIXME: Make it possible to turn off this warning.
6291 if (out_attr
[i
].int_value()
6292 && in_attr
[i
].int_value()
6293 && out_attr
[i
].int_value() != in_attr
[i
].int_value())
6295 gold_warning(_("%s uses %u-byte wchar_t yet the output is to "
6296 "use %u-byte wchar_t; use of wchar_t values "
6297 "across objects may fail"),
6298 name
, in_attr
[i
].int_value(),
6299 out_attr
[i
].int_value());
6301 else if (in_attr
[i
].int_value() && !out_attr
[i
].int_value())
6302 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
6304 case elfcpp::Tag_ABI_enum_size
:
6305 if (in_attr
[i
].int_value() != elfcpp::AEABI_enum_unused
)
6307 if (out_attr
[i
].int_value() == elfcpp::AEABI_enum_unused
6308 || out_attr
[i
].int_value() == elfcpp::AEABI_enum_forced_wide
)
6310 // The existing object is compatible with anything.
6311 // Use whatever requirements the new object has.
6312 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
6314 // FIXME: Make it possible to turn off this warning.
6315 else if (in_attr
[i
].int_value() != elfcpp::AEABI_enum_forced_wide
6316 && out_attr
[i
].int_value() != in_attr
[i
].int_value())
6318 unsigned int in_value
= in_attr
[i
].int_value();
6319 unsigned int out_value
= out_attr
[i
].int_value();
6320 gold_warning(_("%s uses %s enums yet the output is to use "
6321 "%s enums; use of enum values across objects "
6324 this->aeabi_enum_name(in_value
).c_str(),
6325 this->aeabi_enum_name(out_value
).c_str());
6329 case elfcpp::Tag_ABI_VFP_args
:
6332 case elfcpp::Tag_ABI_WMMX_args
:
6333 if (in_attr
[i
].int_value() != out_attr
[i
].int_value())
6335 gold_error(_("%s uses iWMMXt register arguments, output does "
6340 case Object_attribute::Tag_compatibility
:
6341 // Merged in target-independent code.
6343 case elfcpp::Tag_ABI_HardFP_use
:
6344 // 1 (SP) and 2 (DP) conflict, so combine to 3 (SP & DP).
6345 if ((in_attr
[i
].int_value() == 1 && out_attr
[i
].int_value() == 2)
6346 || (in_attr
[i
].int_value() == 2 && out_attr
[i
].int_value() == 1))
6347 out_attr
[i
].set_int_value(3);
6348 else if (in_attr
[i
].int_value() > out_attr
[i
].int_value())
6349 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
6351 case elfcpp::Tag_ABI_FP_16bit_format
:
6352 if (in_attr
[i
].int_value() != 0 && out_attr
[i
].int_value() != 0)
6354 if (in_attr
[i
].int_value() != out_attr
[i
].int_value())
6355 gold_error(_("fp16 format mismatch between %s and output"),
6358 if (in_attr
[i
].int_value() != 0)
6359 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
6362 case elfcpp::Tag_nodefaults
:
6363 // This tag is set if it exists, but the value is unused (and is
6364 // typically zero). We don't actually need to do anything here -
6365 // the merge happens automatically when the type flags are merged
6368 case elfcpp::Tag_also_compatible_with
:
6369 // Already done in Tag_CPU_arch.
6371 case elfcpp::Tag_conformance
:
6372 // Keep the attribute if it matches. Throw it away otherwise.
6373 // No attribute means no claim to conform.
6374 if (in_attr
[i
].string_value() != out_attr
[i
].string_value())
6375 out_attr
[i
].set_string_value("");
6380 const char* err_object
= NULL
;
6382 // The "known_obj_attributes" table does contain some undefined
6383 // attributes. Ensure that there are unused.
6384 if (out_attr
[i
].int_value() != 0
6385 || out_attr
[i
].string_value() != "")
6386 err_object
= "output";
6387 else if (in_attr
[i
].int_value() != 0
6388 || in_attr
[i
].string_value() != "")
6391 if (err_object
!= NULL
)
6393 // Attribute numbers >=64 (mod 128) can be safely ignored.
6395 gold_error(_("%s: unknown mandatory EABI object attribute "
6399 gold_warning(_("%s: unknown EABI object attribute %d"),
6403 // Only pass on attributes that match in both inputs.
6404 if (!in_attr
[i
].matches(out_attr
[i
]))
6406 out_attr
[i
].set_int_value(0);
6407 out_attr
[i
].set_string_value("");
6412 // If out_attr was copied from in_attr then it won't have a type yet.
6413 if (in_attr
[i
].type() && !out_attr
[i
].type())
6414 out_attr
[i
].set_type(in_attr
[i
].type());
6417 // Merge Tag_compatibility attributes and any common GNU ones.
6418 this->attributes_section_data_
->merge(name
, pasd
);
6420 // Check for any attributes not known on ARM.
6421 typedef Vendor_object_attributes::Other_attributes Other_attributes
;
6422 const Other_attributes
* in_other_attributes
= pasd
->other_attributes(vendor
);
6423 Other_attributes::const_iterator in_iter
= in_other_attributes
->begin();
6424 Other_attributes
* out_other_attributes
=
6425 this->attributes_section_data_
->other_attributes(vendor
);
6426 Other_attributes::iterator out_iter
= out_other_attributes
->begin();
6428 while (in_iter
!= in_other_attributes
->end()
6429 || out_iter
!= out_other_attributes
->end())
6431 const char* err_object
= NULL
;
6434 // The tags for each list are in numerical order.
6435 // If the tags are equal, then merge.
6436 if (out_iter
!= out_other_attributes
->end()
6437 && (in_iter
== in_other_attributes
->end()
6438 || in_iter
->first
> out_iter
->first
))
6440 // This attribute only exists in output. We can't merge, and we
6441 // don't know what the tag means, so delete it.
6442 err_object
= "output";
6443 err_tag
= out_iter
->first
;
6444 int saved_tag
= out_iter
->first
;
6445 delete out_iter
->second
;
6446 out_other_attributes
->erase(out_iter
);
6447 out_iter
= out_other_attributes
->upper_bound(saved_tag
);
6449 else if (in_iter
!= in_other_attributes
->end()
6450 && (out_iter
!= out_other_attributes
->end()
6451 || in_iter
->first
< out_iter
->first
))
6453 // This attribute only exists in input. We can't merge, and we
6454 // don't know what the tag means, so ignore it.
6456 err_tag
= in_iter
->first
;
6459 else // The tags are equal.
6461 // As present, all attributes in the list are unknown, and
6462 // therefore can't be merged meaningfully.
6463 err_object
= "output";
6464 err_tag
= out_iter
->first
;
6466 // Only pass on attributes that match in both inputs.
6467 if (!in_iter
->second
->matches(*(out_iter
->second
)))
6469 // No match. Delete the attribute.
6470 int saved_tag
= out_iter
->first
;
6471 delete out_iter
->second
;
6472 out_other_attributes
->erase(out_iter
);
6473 out_iter
= out_other_attributes
->upper_bound(saved_tag
);
6477 // Matched. Keep the attribute and move to the next.
6485 // Attribute numbers >=64 (mod 128) can be safely ignored. */
6486 if ((err_tag
& 127) < 64)
6488 gold_error(_("%s: unknown mandatory EABI object attribute %d"),
6489 err_object
, err_tag
);
6493 gold_warning(_("%s: unknown EABI object attribute %d"),
6494 err_object
, err_tag
);
6500 // Return whether a relocation type used the LSB to distinguish THUMB
6502 template<bool big_endian
>
6504 Target_arm
<big_endian
>::reloc_uses_thumb_bit(unsigned int r_type
)
6508 case elfcpp::R_ARM_PC24
:
6509 case elfcpp::R_ARM_ABS32
:
6510 case elfcpp::R_ARM_REL32
:
6511 case elfcpp::R_ARM_SBREL32
:
6512 case elfcpp::R_ARM_THM_CALL
:
6513 case elfcpp::R_ARM_GLOB_DAT
:
6514 case elfcpp::R_ARM_JUMP_SLOT
:
6515 case elfcpp::R_ARM_GOTOFF32
:
6516 case elfcpp::R_ARM_PLT32
:
6517 case elfcpp::R_ARM_CALL
:
6518 case elfcpp::R_ARM_JUMP24
:
6519 case elfcpp::R_ARM_THM_JUMP24
:
6520 case elfcpp::R_ARM_SBREL31
:
6521 case elfcpp::R_ARM_PREL31
:
6522 case elfcpp::R_ARM_MOVW_ABS_NC
:
6523 case elfcpp::R_ARM_MOVW_PREL_NC
:
6524 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
6525 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
6526 case elfcpp::R_ARM_THM_JUMP19
:
6527 case elfcpp::R_ARM_THM_ALU_PREL_11_0
:
6528 case elfcpp::R_ARM_ALU_PC_G0_NC
:
6529 case elfcpp::R_ARM_ALU_PC_G0
:
6530 case elfcpp::R_ARM_ALU_PC_G1_NC
:
6531 case elfcpp::R_ARM_ALU_PC_G1
:
6532 case elfcpp::R_ARM_ALU_PC_G2
:
6533 case elfcpp::R_ARM_ALU_SB_G0_NC
:
6534 case elfcpp::R_ARM_ALU_SB_G0
:
6535 case elfcpp::R_ARM_ALU_SB_G1_NC
:
6536 case elfcpp::R_ARM_ALU_SB_G1
:
6537 case elfcpp::R_ARM_ALU_SB_G2
:
6538 case elfcpp::R_ARM_MOVW_BREL_NC
:
6539 case elfcpp::R_ARM_MOVW_BREL
:
6540 case elfcpp::R_ARM_THM_MOVW_BREL_NC
:
6541 case elfcpp::R_ARM_THM_MOVW_BREL
:
6548 // Stub-generation methods for Target_arm.
6550 // Make a new Arm_input_section object.
6552 template<bool big_endian
>
6553 Arm_input_section
<big_endian
>*
6554 Target_arm
<big_endian
>::new_arm_input_section(
6558 Input_section_specifier
iss(relobj
, shndx
);
6560 Arm_input_section
<big_endian
>* arm_input_section
=
6561 new Arm_input_section
<big_endian
>(relobj
, shndx
);
6562 arm_input_section
->init();
6564 // Register new Arm_input_section in map for look-up.
6565 std::pair
<typename
Arm_input_section_map::iterator
, bool> ins
=
6566 this->arm_input_section_map_
.insert(std::make_pair(iss
, arm_input_section
));
6568 // Make sure that it we have not created another Arm_input_section
6569 // for this input section already.
6570 gold_assert(ins
.second
);
6572 return arm_input_section
;
6575 // Find the Arm_input_section object corresponding to the SHNDX-th input
6576 // section of RELOBJ.
6578 template<bool big_endian
>
6579 Arm_input_section
<big_endian
>*
6580 Target_arm
<big_endian
>::find_arm_input_section(
6582 unsigned int shndx
) const
6584 Input_section_specifier
iss(relobj
, shndx
);
6585 typename
Arm_input_section_map::const_iterator p
=
6586 this->arm_input_section_map_
.find(iss
);
6587 return (p
!= this->arm_input_section_map_
.end()) ? p
->second
: NULL
;
6590 // Make a new stub table.
6592 template<bool big_endian
>
6593 Stub_table
<big_endian
>*
6594 Target_arm
<big_endian
>::new_stub_table(Arm_input_section
<big_endian
>* owner
)
6596 Stub_table
<big_endian
>* stub_table
=
6597 new Stub_table
<big_endian
>(owner
);
6598 this->stub_tables_
.push_back(stub_table
);
6600 stub_table
->set_address(owner
->address() + owner
->data_size());
6601 stub_table
->set_file_offset(owner
->offset() + owner
->data_size());
6602 stub_table
->finalize_data_size();
6607 // Scan a relocation for stub generation.
6609 template<bool big_endian
>
6611 Target_arm
<big_endian
>::scan_reloc_for_stub(
6612 const Relocate_info
<32, big_endian
>* relinfo
,
6613 unsigned int r_type
,
6614 const Sized_symbol
<32>* gsym
,
6616 const Symbol_value
<32>* psymval
,
6617 elfcpp::Elf_types
<32>::Elf_Swxword addend
,
6618 Arm_address address
)
6620 typedef typename Target_arm
<big_endian
>::Relocate Relocate
;
6622 const Arm_relobj
<big_endian
>* arm_relobj
=
6623 Arm_relobj
<big_endian
>::as_arm_relobj(relinfo
->object
);
6625 bool target_is_thumb
;
6626 Symbol_value
<32> symval
;
6629 // This is a global symbol. Determine if we use PLT and if the
6630 // final target is THUMB.
6631 if (gsym
->use_plt_offset(Relocate::reloc_is_non_pic(r_type
)))
6633 // This uses a PLT, change the symbol value.
6634 symval
.set_output_value(this->plt_section()->address()
6635 + gsym
->plt_offset());
6637 target_is_thumb
= false;
6639 else if (gsym
->is_undefined())
6640 // There is no need to generate a stub symbol is undefined.
6645 ((gsym
->type() == elfcpp::STT_ARM_TFUNC
)
6646 || (gsym
->type() == elfcpp::STT_FUNC
6647 && !gsym
->is_undefined()
6648 && ((psymval
->value(arm_relobj
, 0) & 1) != 0)));
6653 // This is a local symbol. Determine if the final target is THUMB.
6654 target_is_thumb
= arm_relobj
->local_symbol_is_thumb_function(r_sym
);
6657 // Strip LSB if this points to a THUMB target.
6659 && Target_arm
<big_endian
>::reloc_uses_thumb_bit(r_type
)
6660 && ((psymval
->value(arm_relobj
, 0) & 1) != 0))
6662 Arm_address stripped_value
=
6663 psymval
->value(arm_relobj
, 0) & ~static_cast<Arm_address
>(1);
6664 symval
.set_output_value(stripped_value
);
6668 // Get the symbol value.
6669 Symbol_value
<32>::Value value
= psymval
->value(arm_relobj
, 0);
6671 // Owing to pipelining, the PC relative branches below actually skip
6672 // two instructions when the branch offset is 0.
6673 Arm_address destination
;
6676 case elfcpp::R_ARM_CALL
:
6677 case elfcpp::R_ARM_JUMP24
:
6678 case elfcpp::R_ARM_PLT32
:
6680 destination
= value
+ addend
+ 8;
6682 case elfcpp::R_ARM_THM_CALL
:
6683 case elfcpp::R_ARM_THM_XPC22
:
6684 case elfcpp::R_ARM_THM_JUMP24
:
6685 case elfcpp::R_ARM_THM_JUMP19
:
6687 destination
= value
+ addend
+ 4;
6693 Stub_type stub_type
=
6694 Reloc_stub::stub_type_for_reloc(r_type
, address
, destination
,
6697 // This reloc does not need a stub.
6698 if (stub_type
== arm_stub_none
)
6701 // Try looking up an existing stub from a stub table.
6702 Stub_table
<big_endian
>* stub_table
=
6703 arm_relobj
->stub_table(relinfo
->data_shndx
);
6704 gold_assert(stub_table
!= NULL
);
6706 // Locate stub by destination.
6707 Reloc_stub::Key
stub_key(stub_type
, gsym
, arm_relobj
, r_sym
, addend
);
6709 // Create a stub if there is not one already
6710 Reloc_stub
* stub
= stub_table
->find_reloc_stub(stub_key
);
6713 // create a new stub and add it to stub table.
6714 stub
= this->stub_factory().make_reloc_stub(stub_type
);
6715 stub_table
->add_reloc_stub(stub
, stub_key
);
6718 // Record the destination address.
6719 stub
->set_destination_address(destination
6720 | (target_is_thumb
? 1 : 0));
6723 // This function scans a relocation sections for stub generation.
6724 // The template parameter Relocate must be a class type which provides
6725 // a single function, relocate(), which implements the machine
6726 // specific part of a relocation.
6728 // BIG_ENDIAN is the endianness of the data. SH_TYPE is the section type:
6729 // SHT_REL or SHT_RELA.
6731 // PRELOCS points to the relocation data. RELOC_COUNT is the number
6732 // of relocs. OUTPUT_SECTION is the output section.
6733 // NEEDS_SPECIAL_OFFSET_HANDLING is true if input offsets need to be
6734 // mapped to output offsets.
6736 // VIEW is the section data, VIEW_ADDRESS is its memory address, and
6737 // VIEW_SIZE is the size. These refer to the input section, unless
6738 // NEEDS_SPECIAL_OFFSET_HANDLING is true, in which case they refer to
6739 // the output section.
6741 template<bool big_endian
>
6742 template<int sh_type
>
6744 Target_arm
<big_endian
>::scan_reloc_section_for_stubs(
6745 const Relocate_info
<32, big_endian
>* relinfo
,
6746 const unsigned char* prelocs
,
6748 Output_section
* output_section
,
6749 bool needs_special_offset_handling
,
6750 const unsigned char* view
,
6751 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
6754 typedef typename Reloc_types
<sh_type
, 32, big_endian
>::Reloc Reltype
;
6755 const int reloc_size
=
6756 Reloc_types
<sh_type
, 32, big_endian
>::reloc_size
;
6758 Arm_relobj
<big_endian
>* arm_object
=
6759 Arm_relobj
<big_endian
>::as_arm_relobj(relinfo
->object
);
6760 unsigned int local_count
= arm_object
->local_symbol_count();
6762 Comdat_behavior comdat_behavior
= CB_UNDETERMINED
;
6764 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
6766 Reltype
reloc(prelocs
);
6768 typename
elfcpp::Elf_types
<32>::Elf_WXword r_info
= reloc
.get_r_info();
6769 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(r_info
);
6770 unsigned int r_type
= elfcpp::elf_r_type
<32>(r_info
);
6772 r_type
= this->get_real_reloc_type(r_type
);
6774 // Only a few relocation types need stubs.
6775 if ((r_type
!= elfcpp::R_ARM_CALL
)
6776 && (r_type
!= elfcpp::R_ARM_JUMP24
)
6777 && (r_type
!= elfcpp::R_ARM_PLT32
)
6778 && (r_type
!= elfcpp::R_ARM_THM_CALL
)
6779 && (r_type
!= elfcpp::R_ARM_THM_XPC22
)
6780 && (r_type
!= elfcpp::R_ARM_THM_JUMP24
)
6781 && (r_type
!= elfcpp::R_ARM_THM_JUMP19
))
6784 section_offset_type offset
=
6785 convert_to_section_size_type(reloc
.get_r_offset());
6787 if (needs_special_offset_handling
)
6789 offset
= output_section
->output_offset(relinfo
->object
,
6790 relinfo
->data_shndx
,
6797 Stub_addend_reader
<sh_type
, big_endian
> stub_addend_reader
;
6798 elfcpp::Elf_types
<32>::Elf_Swxword addend
=
6799 stub_addend_reader(r_type
, view
+ offset
, reloc
);
6801 const Sized_symbol
<32>* sym
;
6803 Symbol_value
<32> symval
;
6804 const Symbol_value
<32> *psymval
;
6805 if (r_sym
< local_count
)
6808 psymval
= arm_object
->local_symbol(r_sym
);
6810 // If the local symbol belongs to a section we are discarding,
6811 // and that section is a debug section, try to find the
6812 // corresponding kept section and map this symbol to its
6813 // counterpart in the kept section. The symbol must not
6814 // correspond to a section we are folding.
6816 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
6818 && shndx
!= elfcpp::SHN_UNDEF
6819 && !arm_object
->is_section_included(shndx
)
6820 && !(relinfo
->symtab
->is_section_folded(arm_object
, shndx
)))
6822 if (comdat_behavior
== CB_UNDETERMINED
)
6825 arm_object
->section_name(relinfo
->data_shndx
);
6826 comdat_behavior
= get_comdat_behavior(name
.c_str());
6828 if (comdat_behavior
== CB_PRETEND
)
6831 typename
elfcpp::Elf_types
<32>::Elf_Addr value
=
6832 arm_object
->map_to_kept_section(shndx
, &found
);
6834 symval
.set_output_value(value
+ psymval
->input_value());
6836 symval
.set_output_value(0);
6840 symval
.set_output_value(0);
6842 symval
.set_no_output_symtab_entry();
6848 const Symbol
* gsym
= arm_object
->global_symbol(r_sym
);
6849 gold_assert(gsym
!= NULL
);
6850 if (gsym
->is_forwarder())
6851 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
6853 sym
= static_cast<const Sized_symbol
<32>*>(gsym
);
6854 if (sym
->has_symtab_index())
6855 symval
.set_output_symtab_index(sym
->symtab_index());
6857 symval
.set_no_output_symtab_entry();
6859 // We need to compute the would-be final value of this global
6861 const Symbol_table
* symtab
= relinfo
->symtab
;
6862 const Sized_symbol
<32>* sized_symbol
=
6863 symtab
->get_sized_symbol
<32>(gsym
);
6864 Symbol_table::Compute_final_value_status status
;
6866 symtab
->compute_final_value
<32>(sized_symbol
, &status
);
6868 // Skip this if the symbol has not output section.
6869 if (status
== Symbol_table::CFVS_NO_OUTPUT_SECTION
)
6872 symval
.set_output_value(value
);
6876 // If symbol is a section symbol, we don't know the actual type of
6877 // destination. Give up.
6878 if (psymval
->is_section_symbol())
6881 this->scan_reloc_for_stub(relinfo
, r_type
, sym
, r_sym
, psymval
,
6882 addend
, view_address
+ offset
);
6886 // Scan an input section for stub generation.
6888 template<bool big_endian
>
6890 Target_arm
<big_endian
>::scan_section_for_stubs(
6891 const Relocate_info
<32, big_endian
>* relinfo
,
6892 unsigned int sh_type
,
6893 const unsigned char* prelocs
,
6895 Output_section
* output_section
,
6896 bool needs_special_offset_handling
,
6897 const unsigned char* view
,
6898 Arm_address view_address
,
6899 section_size_type view_size
)
6901 if (sh_type
== elfcpp::SHT_REL
)
6902 this->scan_reloc_section_for_stubs
<elfcpp::SHT_REL
>(
6907 needs_special_offset_handling
,
6911 else if (sh_type
== elfcpp::SHT_RELA
)
6912 // We do not support RELA type relocations yet. This is provided for
6914 this->scan_reloc_section_for_stubs
<elfcpp::SHT_RELA
>(
6919 needs_special_offset_handling
,
6927 // Group input sections for stub generation.
6929 // We goup input sections in an output sections so that the total size,
6930 // including any padding space due to alignment is smaller than GROUP_SIZE
6931 // unless the only input section in group is bigger than GROUP_SIZE already.
6932 // Then an ARM stub table is created to follow the last input section
6933 // in group. For each group an ARM stub table is created an is placed
6934 // after the last group. If STUB_ALWATS_AFTER_BRANCH is false, we further
6935 // extend the group after the stub table.
6937 template<bool big_endian
>
6939 Target_arm
<big_endian
>::group_sections(
6941 section_size_type group_size
,
6942 bool stubs_always_after_branch
)
6944 // Group input sections and insert stub table
6945 Layout::Section_list section_list
;
6946 layout
->get_allocated_sections(§ion_list
);
6947 for (Layout::Section_list::const_iterator p
= section_list
.begin();
6948 p
!= section_list
.end();
6951 Arm_output_section
<big_endian
>* output_section
=
6952 Arm_output_section
<big_endian
>::as_arm_output_section(*p
);
6953 output_section
->group_sections(group_size
, stubs_always_after_branch
,
6958 // Relaxation hook. This is where we do stub generation.
6960 template<bool big_endian
>
6962 Target_arm
<big_endian
>::do_relax(
6964 const Input_objects
* input_objects
,
6965 Symbol_table
* symtab
,
6968 // No need to generate stubs if this is a relocatable link.
6969 gold_assert(!parameters
->options().relocatable());
6971 // If this is the first pass, we need to group input sections into
6975 // Determine the stub group size. The group size is the absolute
6976 // value of the parameter --stub-group-size. If --stub-group-size
6977 // is passed a negative value, we restict stubs to be always after
6978 // the stubbed branches.
6979 int32_t stub_group_size_param
=
6980 parameters
->options().stub_group_size();
6981 bool stubs_always_after_branch
= stub_group_size_param
< 0;
6982 section_size_type stub_group_size
= abs(stub_group_size_param
);
6984 if (stub_group_size
== 1)
6987 // Thumb branch range is +-4MB has to be used as the default
6988 // maximum size (a given section can contain both ARM and Thumb
6989 // code, so the worst case has to be taken into account).
6991 // This value is 24K less than that, which allows for 2025
6992 // 12-byte stubs. If we exceed that, then we will fail to link.
6993 // The user will have to relink with an explicit group size
6995 stub_group_size
= 4170000;
6998 group_sections(layout
, stub_group_size
, stubs_always_after_branch
);
7001 // clear changed flags for all stub_tables
7002 typedef typename
Stub_table_list::iterator Stub_table_iterator
;
7003 for (Stub_table_iterator sp
= this->stub_tables_
.begin();
7004 sp
!= this->stub_tables_
.end();
7006 (*sp
)->set_has_been_changed(false);
7008 // scan relocs for stubs
7009 for (Input_objects::Relobj_iterator op
= input_objects
->relobj_begin();
7010 op
!= input_objects
->relobj_end();
7013 Arm_relobj
<big_endian
>* arm_relobj
=
7014 Arm_relobj
<big_endian
>::as_arm_relobj(*op
);
7015 arm_relobj
->scan_sections_for_stubs(this, symtab
, layout
);
7018 bool any_stub_table_changed
= false;
7019 for (Stub_table_iterator sp
= this->stub_tables_
.begin();
7020 (sp
!= this->stub_tables_
.end()) && !any_stub_table_changed
;
7023 if ((*sp
)->has_been_changed())
7024 any_stub_table_changed
= true;
7027 return any_stub_table_changed
;
7032 template<bool big_endian
>
7034 Target_arm
<big_endian
>::relocate_stub(
7036 const Relocate_info
<32, big_endian
>* relinfo
,
7037 Output_section
* output_section
,
7038 unsigned char* view
,
7039 Arm_address address
,
7040 section_size_type view_size
)
7043 const Stub_template
* stub_template
= stub
->stub_template();
7044 for (size_t i
= 0; i
< stub_template
->reloc_count(); i
++)
7046 size_t reloc_insn_index
= stub_template
->reloc_insn_index(i
);
7047 const Insn_template
* insn
= &stub_template
->insns()[reloc_insn_index
];
7049 unsigned int r_type
= insn
->r_type();
7050 section_size_type reloc_offset
= stub_template
->reloc_offset(i
);
7051 section_size_type reloc_size
= insn
->size();
7052 gold_assert(reloc_offset
+ reloc_size
<= view_size
);
7054 // This is the address of the stub destination.
7055 Arm_address target
= stub
->reloc_target(i
);
7056 Symbol_value
<32> symval
;
7057 symval
.set_output_value(target
);
7059 // Synthesize a fake reloc just in case. We don't have a symbol so
7061 unsigned char reloc_buffer
[elfcpp::Elf_sizes
<32>::rel_size
];
7062 memset(reloc_buffer
, 0, sizeof(reloc_buffer
));
7063 elfcpp::Rel_write
<32, big_endian
> reloc_write(reloc_buffer
);
7064 reloc_write
.put_r_offset(reloc_offset
);
7065 reloc_write
.put_r_info(elfcpp::elf_r_info
<32>(0, r_type
));
7066 elfcpp::Rel
<32, big_endian
> rel(reloc_buffer
);
7068 relocate
.relocate(relinfo
, this, output_section
,
7069 this->fake_relnum_for_stubs
, rel
, r_type
,
7070 NULL
, &symval
, view
+ reloc_offset
,
7071 address
+ reloc_offset
, reloc_size
);
7075 // Determine whether an object attribute tag takes an integer, a
7078 template<bool big_endian
>
7080 Target_arm
<big_endian
>::do_attribute_arg_type(int tag
) const
7082 if (tag
== Object_attribute::Tag_compatibility
)
7083 return (Object_attribute::ATTR_TYPE_FLAG_INT_VAL
7084 | Object_attribute::ATTR_TYPE_FLAG_STR_VAL
);
7085 else if (tag
== elfcpp::Tag_nodefaults
)
7086 return (Object_attribute::ATTR_TYPE_FLAG_INT_VAL
7087 | Object_attribute::ATTR_TYPE_FLAG_NO_DEFAULT
);
7088 else if (tag
== elfcpp::Tag_CPU_raw_name
|| tag
== elfcpp::Tag_CPU_name
)
7089 return Object_attribute::ATTR_TYPE_FLAG_STR_VAL
;
7091 return Object_attribute::ATTR_TYPE_FLAG_INT_VAL
;
7093 return ((tag
& 1) != 0
7094 ? Object_attribute::ATTR_TYPE_FLAG_STR_VAL
7095 : Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
7098 // Reorder attributes.
7100 // The ABI defines that Tag_conformance should be emitted first, and that
7101 // Tag_nodefaults should be second (if either is defined). This sets those
7102 // two positions, and bumps up the position of all the remaining tags to
7105 template<bool big_endian
>
7107 Target_arm
<big_endian
>::do_attributes_order(int num
) const
7109 // Reorder the known object attributes in output. We want to move
7110 // Tag_conformance to position 4 and Tag_conformance to position 5
7111 // and shift eveything between 4 .. Tag_conformance - 1 to make room.
7113 return elfcpp::Tag_conformance
;
7115 return elfcpp::Tag_nodefaults
;
7116 if ((num
- 2) < elfcpp::Tag_nodefaults
)
7118 if ((num
- 1) < elfcpp::Tag_conformance
)
7123 template<bool big_endian
>
7124 class Target_selector_arm
: public Target_selector
7127 Target_selector_arm()
7128 : Target_selector(elfcpp::EM_ARM
, 32, big_endian
,
7129 (big_endian
? "elf32-bigarm" : "elf32-littlearm"))
7133 do_instantiate_target()
7134 { return new Target_arm
<big_endian
>(); }
7137 Target_selector_arm
<false> target_selector_arm
;
7138 Target_selector_arm
<true> target_selector_armbe
;
7140 } // End anonymous namespace.