1 // arm.cc -- arm target support for gold.
3 // Copyright 2009, 2010 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.
38 #include "parameters.h"
45 #include "copy-relocs.h"
47 #include "target-reloc.h"
48 #include "target-select.h"
52 #include "attributes.h"
53 #include "arm-reloc-property.h"
60 template<bool big_endian
>
61 class Output_data_plt_arm
;
63 template<bool big_endian
>
66 template<bool big_endian
>
67 class Arm_input_section
;
69 class Arm_exidx_cantunwind
;
71 class Arm_exidx_merged_section
;
73 class Arm_exidx_fixup
;
75 template<bool big_endian
>
76 class Arm_output_section
;
78 class Arm_exidx_input_section
;
80 template<bool big_endian
>
83 template<bool big_endian
>
84 class Arm_relocate_functions
;
86 template<bool big_endian
>
87 class Arm_output_data_got
;
89 template<bool big_endian
>
93 typedef elfcpp::Elf_types
<32>::Elf_Addr Arm_address
;
95 // Maximum branch offsets for ARM, THUMB and THUMB2.
96 const int32_t ARM_MAX_FWD_BRANCH_OFFSET
= ((((1 << 23) - 1) << 2) + 8);
97 const int32_t ARM_MAX_BWD_BRANCH_OFFSET
= ((-((1 << 23) << 2)) + 8);
98 const int32_t THM_MAX_FWD_BRANCH_OFFSET
= ((1 << 22) -2 + 4);
99 const int32_t THM_MAX_BWD_BRANCH_OFFSET
= (-(1 << 22) + 4);
100 const int32_t THM2_MAX_FWD_BRANCH_OFFSET
= (((1 << 24) - 2) + 4);
101 const int32_t THM2_MAX_BWD_BRANCH_OFFSET
= (-(1 << 24) + 4);
103 // Thread Control Block size.
104 const size_t ARM_TCB_SIZE
= 8;
106 // The arm target class.
108 // This is a very simple port of gold for ARM-EABI. It is intended for
109 // supporting Android only for the time being.
112 // - Implement all static relocation types documented in arm-reloc.def.
113 // - Make PLTs more flexible for different architecture features like
115 // There are probably a lot more.
117 // Ideally we would like to avoid using global variables but this is used
118 // very in many places and sometimes in loops. If we use a function
119 // returning a static instance of Arm_reloc_property_table, it will very
120 // slow in an threaded environment since the static instance needs to be
121 // locked. The pointer is below initialized in the
122 // Target::do_select_as_default_target() hook so that we do not spend time
123 // building the table if we are not linking ARM objects.
125 // An alternative is to to process the information in arm-reloc.def in
126 // compilation time and generate a representation of it in PODs only. That
127 // way we can avoid initialization when the linker starts.
129 Arm_reloc_property_table
*arm_reloc_property_table
= NULL
;
131 // Instruction template class. This class is similar to the insn_sequence
132 // struct in bfd/elf32-arm.c.
137 // Types of instruction templates.
141 // THUMB16_SPECIAL_TYPE is used by sub-classes of Stub for instruction
142 // templates with class-specific semantics. Currently this is used
143 // only by the Cortex_a8_stub class for handling condition codes in
144 // conditional branches.
145 THUMB16_SPECIAL_TYPE
,
151 // Factory methods to create instruction templates in different formats.
153 static const Insn_template
154 thumb16_insn(uint32_t data
)
155 { return Insn_template(data
, THUMB16_TYPE
, elfcpp::R_ARM_NONE
, 0); }
157 // A Thumb conditional branch, in which the proper condition is inserted
158 // when we build the stub.
159 static const Insn_template
160 thumb16_bcond_insn(uint32_t data
)
161 { return Insn_template(data
, THUMB16_SPECIAL_TYPE
, elfcpp::R_ARM_NONE
, 1); }
163 static const Insn_template
164 thumb32_insn(uint32_t data
)
165 { return Insn_template(data
, THUMB32_TYPE
, elfcpp::R_ARM_NONE
, 0); }
167 static const Insn_template
168 thumb32_b_insn(uint32_t data
, int reloc_addend
)
170 return Insn_template(data
, THUMB32_TYPE
, elfcpp::R_ARM_THM_JUMP24
,
174 static const Insn_template
175 arm_insn(uint32_t data
)
176 { return Insn_template(data
, ARM_TYPE
, elfcpp::R_ARM_NONE
, 0); }
178 static const Insn_template
179 arm_rel_insn(unsigned data
, int reloc_addend
)
180 { return Insn_template(data
, ARM_TYPE
, elfcpp::R_ARM_JUMP24
, reloc_addend
); }
182 static const Insn_template
183 data_word(unsigned data
, unsigned int r_type
, int reloc_addend
)
184 { return Insn_template(data
, DATA_TYPE
, r_type
, reloc_addend
); }
186 // Accessors. This class is used for read-only objects so no modifiers
191 { return this->data_
; }
193 // Return the instruction sequence type of this.
196 { return this->type_
; }
198 // Return the ARM relocation type of this.
201 { return this->r_type_
; }
205 { return this->reloc_addend_
; }
207 // Return size of instruction template in bytes.
211 // Return byte-alignment of instruction template.
216 // We make the constructor private to ensure that only the factory
219 Insn_template(unsigned data
, Type type
, unsigned int r_type
, int reloc_addend
)
220 : data_(data
), type_(type
), r_type_(r_type
), reloc_addend_(reloc_addend
)
223 // Instruction specific data. This is used to store information like
224 // some of the instruction bits.
226 // Instruction template type.
228 // Relocation type if there is a relocation or R_ARM_NONE otherwise.
229 unsigned int r_type_
;
230 // Relocation addend.
231 int32_t reloc_addend_
;
234 // Macro for generating code to stub types. One entry per long/short
238 DEF_STUB(long_branch_any_any) \
239 DEF_STUB(long_branch_v4t_arm_thumb) \
240 DEF_STUB(long_branch_thumb_only) \
241 DEF_STUB(long_branch_v4t_thumb_thumb) \
242 DEF_STUB(long_branch_v4t_thumb_arm) \
243 DEF_STUB(short_branch_v4t_thumb_arm) \
244 DEF_STUB(long_branch_any_arm_pic) \
245 DEF_STUB(long_branch_any_thumb_pic) \
246 DEF_STUB(long_branch_v4t_thumb_thumb_pic) \
247 DEF_STUB(long_branch_v4t_arm_thumb_pic) \
248 DEF_STUB(long_branch_v4t_thumb_arm_pic) \
249 DEF_STUB(long_branch_thumb_only_pic) \
250 DEF_STUB(a8_veneer_b_cond) \
251 DEF_STUB(a8_veneer_b) \
252 DEF_STUB(a8_veneer_bl) \
253 DEF_STUB(a8_veneer_blx) \
254 DEF_STUB(v4_veneer_bx)
258 #define DEF_STUB(x) arm_stub_##x,
264 // First reloc stub type.
265 arm_stub_reloc_first
= arm_stub_long_branch_any_any
,
266 // Last reloc stub type.
267 arm_stub_reloc_last
= arm_stub_long_branch_thumb_only_pic
,
269 // First Cortex-A8 stub type.
270 arm_stub_cortex_a8_first
= arm_stub_a8_veneer_b_cond
,
271 // Last Cortex-A8 stub type.
272 arm_stub_cortex_a8_last
= arm_stub_a8_veneer_blx
,
275 arm_stub_type_last
= arm_stub_v4_veneer_bx
279 // Stub template class. Templates are meant to be read-only objects.
280 // A stub template for a stub type contains all read-only attributes
281 // common to all stubs of the same type.
286 Stub_template(Stub_type
, const Insn_template
*, size_t);
294 { return this->type_
; }
296 // Return an array of instruction templates.
299 { return this->insns_
; }
301 // Return size of template in number of instructions.
304 { return this->insn_count_
; }
306 // Return size of template in bytes.
309 { return this->size_
; }
311 // Return alignment of the stub template.
314 { return this->alignment_
; }
316 // Return whether entry point is in thumb mode.
318 entry_in_thumb_mode() const
319 { return this->entry_in_thumb_mode_
; }
321 // Return number of relocations in this template.
324 { return this->relocs_
.size(); }
326 // Return index of the I-th instruction with relocation.
328 reloc_insn_index(size_t i
) const
330 gold_assert(i
< this->relocs_
.size());
331 return this->relocs_
[i
].first
;
334 // Return the offset of the I-th instruction with relocation from the
335 // beginning of the stub.
337 reloc_offset(size_t i
) const
339 gold_assert(i
< this->relocs_
.size());
340 return this->relocs_
[i
].second
;
344 // This contains information about an instruction template with a relocation
345 // and its offset from start of stub.
346 typedef std::pair
<size_t, section_size_type
> Reloc
;
348 // A Stub_template may not be copied. We want to share templates as much
350 Stub_template(const Stub_template
&);
351 Stub_template
& operator=(const Stub_template
&);
355 // Points to an array of Insn_templates.
356 const Insn_template
* insns_
;
357 // Number of Insn_templates in insns_[].
359 // Size of templated instructions in bytes.
361 // Alignment of templated instructions.
363 // Flag to indicate if entry is in thumb mode.
364 bool entry_in_thumb_mode_
;
365 // A table of reloc instruction indices and offsets. We can find these by
366 // looking at the instruction templates but we pre-compute and then stash
367 // them here for speed.
368 std::vector
<Reloc
> relocs_
;
372 // A class for code stubs. This is a base class for different type of
373 // stubs used in the ARM target.
379 static const section_offset_type invalid_offset
=
380 static_cast<section_offset_type
>(-1);
383 Stub(const Stub_template
* stub_template
)
384 : stub_template_(stub_template
), offset_(invalid_offset
)
391 // Return the stub template.
393 stub_template() const
394 { return this->stub_template_
; }
396 // Return offset of code stub from beginning of its containing stub table.
400 gold_assert(this->offset_
!= invalid_offset
);
401 return this->offset_
;
404 // Set offset of code stub from beginning of its containing stub table.
406 set_offset(section_offset_type offset
)
407 { this->offset_
= offset
; }
409 // Return the relocation target address of the i-th relocation in the
410 // stub. This must be defined in a child class.
412 reloc_target(size_t i
)
413 { return this->do_reloc_target(i
); }
415 // Write a stub at output VIEW. BIG_ENDIAN select how a stub is written.
417 write(unsigned char* view
, section_size_type view_size
, bool big_endian
)
418 { this->do_write(view
, view_size
, big_endian
); }
420 // Return the instruction for THUMB16_SPECIAL_TYPE instruction template
421 // for the i-th instruction.
423 thumb16_special(size_t i
)
424 { return this->do_thumb16_special(i
); }
427 // This must be defined in the child class.
429 do_reloc_target(size_t) = 0;
431 // This may be overridden in the child class.
433 do_write(unsigned char* view
, section_size_type view_size
, bool big_endian
)
436 this->do_fixed_endian_write
<true>(view
, view_size
);
438 this->do_fixed_endian_write
<false>(view
, view_size
);
441 // This must be overridden if a child class uses the THUMB16_SPECIAL_TYPE
442 // instruction template.
444 do_thumb16_special(size_t)
445 { gold_unreachable(); }
448 // A template to implement do_write.
449 template<bool big_endian
>
451 do_fixed_endian_write(unsigned char*, section_size_type
);
454 const Stub_template
* stub_template_
;
455 // Offset within the section of containing this stub.
456 section_offset_type offset_
;
459 // Reloc stub class. These are stubs we use to fix up relocation because
460 // of limited branch ranges.
462 class Reloc_stub
: public Stub
465 static const unsigned int invalid_index
= static_cast<unsigned int>(-1);
466 // We assume we never jump to this address.
467 static const Arm_address invalid_address
= static_cast<Arm_address
>(-1);
469 // Return destination address.
471 destination_address() const
473 gold_assert(this->destination_address_
!= this->invalid_address
);
474 return this->destination_address_
;
477 // Set destination address.
479 set_destination_address(Arm_address address
)
481 gold_assert(address
!= this->invalid_address
);
482 this->destination_address_
= address
;
485 // Reset destination address.
487 reset_destination_address()
488 { this->destination_address_
= this->invalid_address
; }
490 // Determine stub type for a branch of a relocation of R_TYPE going
491 // from BRANCH_ADDRESS to BRANCH_TARGET. If TARGET_IS_THUMB is set,
492 // the branch target is a thumb instruction. TARGET is used for look
493 // up ARM-specific linker settings.
495 stub_type_for_reloc(unsigned int r_type
, Arm_address branch_address
,
496 Arm_address branch_target
, bool target_is_thumb
);
498 // Reloc_stub key. A key is logically a triplet of a stub type, a symbol
499 // and an addend. Since we treat global and local symbol differently, we
500 // use a Symbol object for a global symbol and a object-index pair for
505 // If SYMBOL is not null, this is a global symbol, we ignore RELOBJ and
506 // R_SYM. Otherwise, this is a local symbol and RELOBJ must non-NULL
507 // and R_SYM must not be invalid_index.
508 Key(Stub_type stub_type
, const Symbol
* symbol
, const Relobj
* relobj
,
509 unsigned int r_sym
, int32_t addend
)
510 : stub_type_(stub_type
), addend_(addend
)
514 this->r_sym_
= Reloc_stub::invalid_index
;
515 this->u_
.symbol
= symbol
;
519 gold_assert(relobj
!= NULL
&& r_sym
!= invalid_index
);
520 this->r_sym_
= r_sym
;
521 this->u_
.relobj
= relobj
;
528 // Accessors: Keys are meant to be read-only object so no modifiers are
534 { return this->stub_type_
; }
536 // Return the local symbol index or invalid_index.
539 { return this->r_sym_
; }
541 // Return the symbol if there is one.
544 { return this->r_sym_
== invalid_index
? this->u_
.symbol
: NULL
; }
546 // Return the relobj if there is one.
549 { return this->r_sym_
!= invalid_index
? this->u_
.relobj
: NULL
; }
551 // Whether this equals to another key k.
553 eq(const Key
& k
) const
555 return ((this->stub_type_
== k
.stub_type_
)
556 && (this->r_sym_
== k
.r_sym_
)
557 && ((this->r_sym_
!= Reloc_stub::invalid_index
)
558 ? (this->u_
.relobj
== k
.u_
.relobj
)
559 : (this->u_
.symbol
== k
.u_
.symbol
))
560 && (this->addend_
== k
.addend_
));
563 // Return a hash value.
567 return (this->stub_type_
569 ^ gold::string_hash
<char>(
570 (this->r_sym_
!= Reloc_stub::invalid_index
)
571 ? this->u_
.relobj
->name().c_str()
572 : this->u_
.symbol
->name())
576 // Functors for STL associative containers.
580 operator()(const Key
& k
) const
581 { return k
.hash_value(); }
587 operator()(const Key
& k1
, const Key
& k2
) const
588 { return k1
.eq(k2
); }
591 // Name of key. This is mainly for debugging.
597 Stub_type stub_type_
;
598 // If this is a local symbol, this is the index in the defining object.
599 // Otherwise, it is invalid_index for a global symbol.
601 // If r_sym_ is invalid index. This points to a global symbol.
602 // Otherwise, this points a relobj. We used the unsized and target
603 // independent Symbol and Relobj classes instead of Sized_symbol<32> and
604 // Arm_relobj. This is done to avoid making the stub class a template
605 // as most of the stub machinery is endianness-neutral. However, it
606 // may require a bit of casting done by users of this class.
609 const Symbol
* symbol
;
610 const Relobj
* relobj
;
612 // Addend associated with a reloc.
617 // Reloc_stubs are created via a stub factory. So these are protected.
618 Reloc_stub(const Stub_template
* stub_template
)
619 : Stub(stub_template
), destination_address_(invalid_address
)
625 friend class Stub_factory
;
627 // Return the relocation target address of the i-th relocation in the
630 do_reloc_target(size_t i
)
632 // All reloc stub have only one relocation.
634 return this->destination_address_
;
638 // Address of destination.
639 Arm_address destination_address_
;
642 // Cortex-A8 stub class. We need a Cortex-A8 stub to redirect any 32-bit
643 // THUMB branch that meets the following conditions:
645 // 1. The branch straddles across a page boundary. i.e. lower 12-bit of
646 // branch address is 0xffe.
647 // 2. The branch target address is in the same page as the first word of the
649 // 3. The branch follows a 32-bit instruction which is not a branch.
651 // To do the fix up, we need to store the address of the branch instruction
652 // and its target at least. We also need to store the original branch
653 // instruction bits for the condition code in a conditional branch. The
654 // condition code is used in a special instruction template. We also want
655 // to identify input sections needing Cortex-A8 workaround quickly. We store
656 // extra information about object and section index of the code section
657 // containing a branch being fixed up. The information is used to mark
658 // the code section when we finalize the Cortex-A8 stubs.
661 class Cortex_a8_stub
: public Stub
667 // Return the object of the code section containing the branch being fixed
671 { return this->relobj_
; }
673 // Return the section index of the code section containing the branch being
677 { return this->shndx_
; }
679 // Return the source address of stub. This is the address of the original
680 // branch instruction. LSB is 1 always set to indicate that it is a THUMB
683 source_address() const
684 { return this->source_address_
; }
686 // Return the destination address of the stub. This is the branch taken
687 // address of the original branch instruction. LSB is 1 if it is a THUMB
688 // instruction address.
690 destination_address() const
691 { return this->destination_address_
; }
693 // Return the instruction being fixed up.
695 original_insn() const
696 { return this->original_insn_
; }
699 // Cortex_a8_stubs are created via a stub factory. So these are protected.
700 Cortex_a8_stub(const Stub_template
* stub_template
, Relobj
* relobj
,
701 unsigned int shndx
, Arm_address source_address
,
702 Arm_address destination_address
, uint32_t original_insn
)
703 : Stub(stub_template
), relobj_(relobj
), shndx_(shndx
),
704 source_address_(source_address
| 1U),
705 destination_address_(destination_address
),
706 original_insn_(original_insn
)
709 friend class Stub_factory
;
711 // Return the relocation target address of the i-th relocation in the
714 do_reloc_target(size_t i
)
716 if (this->stub_template()->type() == arm_stub_a8_veneer_b_cond
)
718 // The conditional branch veneer has two relocations.
720 return i
== 0 ? this->source_address_
+ 4 : this->destination_address_
;
724 // All other Cortex-A8 stubs have only one relocation.
726 return this->destination_address_
;
730 // Return an instruction for the THUMB16_SPECIAL_TYPE instruction template.
732 do_thumb16_special(size_t);
735 // Object of the code section containing the branch being fixed up.
737 // Section index of the code section containing the branch begin fixed up.
739 // Source address of original branch.
740 Arm_address source_address_
;
741 // Destination address of the original branch.
742 Arm_address destination_address_
;
743 // Original branch instruction. This is needed for copying the condition
744 // code from a condition branch to its stub.
745 uint32_t original_insn_
;
748 // ARMv4 BX Rx branch relocation stub class.
749 class Arm_v4bx_stub
: public Stub
755 // Return the associated register.
758 { return this->reg_
; }
761 // Arm V4BX stubs are created via a stub factory. So these are protected.
762 Arm_v4bx_stub(const Stub_template
* stub_template
, const uint32_t reg
)
763 : Stub(stub_template
), reg_(reg
)
766 friend class Stub_factory
;
768 // Return the relocation target address of the i-th relocation in the
771 do_reloc_target(size_t)
772 { gold_unreachable(); }
774 // This may be overridden in the child class.
776 do_write(unsigned char* view
, section_size_type view_size
, bool big_endian
)
779 this->do_fixed_endian_v4bx_write
<true>(view
, view_size
);
781 this->do_fixed_endian_v4bx_write
<false>(view
, view_size
);
785 // A template to implement do_write.
786 template<bool big_endian
>
788 do_fixed_endian_v4bx_write(unsigned char* view
, section_size_type
)
790 const Insn_template
* insns
= this->stub_template()->insns();
791 elfcpp::Swap
<32, big_endian
>::writeval(view
,
793 + (this->reg_
<< 16)));
794 view
+= insns
[0].size();
795 elfcpp::Swap
<32, big_endian
>::writeval(view
,
796 (insns
[1].data() + this->reg_
));
797 view
+= insns
[1].size();
798 elfcpp::Swap
<32, big_endian
>::writeval(view
,
799 (insns
[2].data() + this->reg_
));
802 // A register index (r0-r14), which is associated with the stub.
806 // Stub factory class.
811 // Return the unique instance of this class.
812 static const Stub_factory
&
815 static Stub_factory singleton
;
819 // Make a relocation stub.
821 make_reloc_stub(Stub_type stub_type
) const
823 gold_assert(stub_type
>= arm_stub_reloc_first
824 && stub_type
<= arm_stub_reloc_last
);
825 return new Reloc_stub(this->stub_templates_
[stub_type
]);
828 // Make a Cortex-A8 stub.
830 make_cortex_a8_stub(Stub_type stub_type
, Relobj
* relobj
, unsigned int shndx
,
831 Arm_address source
, Arm_address destination
,
832 uint32_t original_insn
) const
834 gold_assert(stub_type
>= arm_stub_cortex_a8_first
835 && stub_type
<= arm_stub_cortex_a8_last
);
836 return new Cortex_a8_stub(this->stub_templates_
[stub_type
], relobj
, shndx
,
837 source
, destination
, original_insn
);
840 // Make an ARM V4BX relocation stub.
841 // This method creates a stub from the arm_stub_v4_veneer_bx template only.
843 make_arm_v4bx_stub(uint32_t reg
) const
845 gold_assert(reg
< 0xf);
846 return new Arm_v4bx_stub(this->stub_templates_
[arm_stub_v4_veneer_bx
],
851 // Constructor and destructor are protected since we only return a single
852 // instance created in Stub_factory::get_instance().
856 // A Stub_factory may not be copied since it is a singleton.
857 Stub_factory(const Stub_factory
&);
858 Stub_factory
& operator=(Stub_factory
&);
860 // Stub templates. These are initialized in the constructor.
861 const Stub_template
* stub_templates_
[arm_stub_type_last
+1];
864 // A class to hold stubs for the ARM target.
866 template<bool big_endian
>
867 class Stub_table
: public Output_data
870 Stub_table(Arm_input_section
<big_endian
>* owner
)
871 : Output_data(), owner_(owner
), reloc_stubs_(), reloc_stubs_size_(0),
872 reloc_stubs_addralign_(1), cortex_a8_stubs_(), arm_v4bx_stubs_(0xf),
873 prev_data_size_(0), prev_addralign_(1)
879 // Owner of this stub table.
880 Arm_input_section
<big_endian
>*
882 { return this->owner_
; }
884 // Whether this stub table is empty.
888 return (this->reloc_stubs_
.empty()
889 && this->cortex_a8_stubs_
.empty()
890 && this->arm_v4bx_stubs_
.empty());
893 // Return the current data size.
895 current_data_size() const
896 { return this->current_data_size_for_child(); }
898 // Add a STUB with using KEY. Caller is reponsible for avoid adding
899 // if already a STUB with the same key has been added.
901 add_reloc_stub(Reloc_stub
* stub
, const Reloc_stub::Key
& key
)
903 const Stub_template
* stub_template
= stub
->stub_template();
904 gold_assert(stub_template
->type() == key
.stub_type());
905 this->reloc_stubs_
[key
] = stub
;
907 // Assign stub offset early. We can do this because we never remove
908 // reloc stubs and they are in the beginning of the stub table.
909 uint64_t align
= stub_template
->alignment();
910 this->reloc_stubs_size_
= align_address(this->reloc_stubs_size_
, align
);
911 stub
->set_offset(this->reloc_stubs_size_
);
912 this->reloc_stubs_size_
+= stub_template
->size();
913 this->reloc_stubs_addralign_
=
914 std::max(this->reloc_stubs_addralign_
, align
);
917 // Add a Cortex-A8 STUB that fixes up a THUMB branch at ADDRESS.
918 // Caller is reponsible for avoid adding if already a STUB with the same
919 // address has been added.
921 add_cortex_a8_stub(Arm_address address
, Cortex_a8_stub
* stub
)
923 std::pair
<Arm_address
, Cortex_a8_stub
*> value(address
, stub
);
924 this->cortex_a8_stubs_
.insert(value
);
927 // Add an ARM V4BX relocation stub. A register index will be retrieved
930 add_arm_v4bx_stub(Arm_v4bx_stub
* stub
)
932 gold_assert(stub
!= NULL
&& this->arm_v4bx_stubs_
[stub
->reg()] == NULL
);
933 this->arm_v4bx_stubs_
[stub
->reg()] = stub
;
936 // Remove all Cortex-A8 stubs.
938 remove_all_cortex_a8_stubs();
940 // Look up a relocation stub using KEY. Return NULL if there is none.
942 find_reloc_stub(const Reloc_stub::Key
& key
) const
944 typename
Reloc_stub_map::const_iterator p
= this->reloc_stubs_
.find(key
);
945 return (p
!= this->reloc_stubs_
.end()) ? p
->second
: NULL
;
948 // Look up an arm v4bx relocation stub using the register index.
949 // Return NULL if there is none.
951 find_arm_v4bx_stub(const uint32_t reg
) const
953 gold_assert(reg
< 0xf);
954 return this->arm_v4bx_stubs_
[reg
];
957 // Relocate stubs in this stub table.
959 relocate_stubs(const Relocate_info
<32, big_endian
>*,
960 Target_arm
<big_endian
>*, Output_section
*,
961 unsigned char*, Arm_address
, section_size_type
);
963 // Update data size and alignment at the end of a relaxation pass. Return
964 // true if either data size or alignment is different from that of the
965 // previous relaxation pass.
967 update_data_size_and_addralign();
969 // Finalize stubs. Set the offsets of all stubs and mark input sections
970 // needing the Cortex-A8 workaround.
974 // Apply Cortex-A8 workaround to an address range.
976 apply_cortex_a8_workaround_to_address_range(Target_arm
<big_endian
>*,
977 unsigned char*, Arm_address
,
981 // Write out section contents.
983 do_write(Output_file
*);
985 // Return the required alignment.
988 { return this->prev_addralign_
; }
990 // Reset address and file offset.
992 do_reset_address_and_file_offset()
993 { this->set_current_data_size_for_child(this->prev_data_size_
); }
995 // Set final data size.
997 set_final_data_size()
998 { this->set_data_size(this->current_data_size()); }
1001 // Relocate one stub.
1003 relocate_stub(Stub
*, const Relocate_info
<32, big_endian
>*,
1004 Target_arm
<big_endian
>*, Output_section
*,
1005 unsigned char*, Arm_address
, section_size_type
);
1007 // Unordered map of relocation stubs.
1009 Unordered_map
<Reloc_stub::Key
, Reloc_stub
*, Reloc_stub::Key::hash
,
1010 Reloc_stub::Key::equal_to
>
1013 // List of Cortex-A8 stubs ordered by addresses of branches being
1014 // fixed up in output.
1015 typedef std::map
<Arm_address
, Cortex_a8_stub
*> Cortex_a8_stub_list
;
1016 // List of Arm V4BX relocation stubs ordered by associated registers.
1017 typedef std::vector
<Arm_v4bx_stub
*> Arm_v4bx_stub_list
;
1019 // Owner of this stub table.
1020 Arm_input_section
<big_endian
>* owner_
;
1021 // The relocation stubs.
1022 Reloc_stub_map reloc_stubs_
;
1023 // Size of reloc stubs.
1024 off_t reloc_stubs_size_
;
1025 // Maximum address alignment of reloc stubs.
1026 uint64_t reloc_stubs_addralign_
;
1027 // The cortex_a8_stubs.
1028 Cortex_a8_stub_list cortex_a8_stubs_
;
1029 // The Arm V4BX relocation stubs.
1030 Arm_v4bx_stub_list arm_v4bx_stubs_
;
1031 // data size of this in the previous pass.
1032 off_t prev_data_size_
;
1033 // address alignment of this in the previous pass.
1034 uint64_t prev_addralign_
;
1037 // Arm_exidx_cantunwind class. This represents an EXIDX_CANTUNWIND entry
1038 // we add to the end of an EXIDX input section that goes into the output.
1040 class Arm_exidx_cantunwind
: public Output_section_data
1043 Arm_exidx_cantunwind(Relobj
* relobj
, unsigned int shndx
)
1044 : Output_section_data(8, 4, true), relobj_(relobj
), shndx_(shndx
)
1047 // Return the object containing the section pointed by this.
1050 { return this->relobj_
; }
1052 // Return the section index of the section pointed by this.
1055 { return this->shndx_
; }
1059 do_write(Output_file
* of
)
1061 if (parameters
->target().is_big_endian())
1062 this->do_fixed_endian_write
<true>(of
);
1064 this->do_fixed_endian_write
<false>(of
);
1068 // Implement do_write for a given endianness.
1069 template<bool big_endian
>
1071 do_fixed_endian_write(Output_file
*);
1073 // The object containing the section pointed by this.
1075 // The section index of the section pointed by this.
1076 unsigned int shndx_
;
1079 // During EXIDX coverage fix-up, we compact an EXIDX section. The
1080 // Offset map is used to map input section offset within the EXIDX section
1081 // to the output offset from the start of this EXIDX section.
1083 typedef std::map
<section_offset_type
, section_offset_type
>
1084 Arm_exidx_section_offset_map
;
1086 // Arm_exidx_merged_section class. This represents an EXIDX input section
1087 // with some of its entries merged.
1089 class Arm_exidx_merged_section
: public Output_relaxed_input_section
1092 // Constructor for Arm_exidx_merged_section.
1093 // EXIDX_INPUT_SECTION points to the unmodified EXIDX input section.
1094 // SECTION_OFFSET_MAP points to a section offset map describing how
1095 // parts of the input section are mapped to output. DELETED_BYTES is
1096 // the number of bytes deleted from the EXIDX input section.
1097 Arm_exidx_merged_section(
1098 const Arm_exidx_input_section
& exidx_input_section
,
1099 const Arm_exidx_section_offset_map
& section_offset_map
,
1100 uint32_t deleted_bytes
);
1102 // Return the original EXIDX input section.
1103 const Arm_exidx_input_section
&
1104 exidx_input_section() const
1105 { return this->exidx_input_section_
; }
1107 // Return the section offset map.
1108 const Arm_exidx_section_offset_map
&
1109 section_offset_map() const
1110 { return this->section_offset_map_
; }
1113 // Write merged section into file OF.
1115 do_write(Output_file
* of
);
1118 do_output_offset(const Relobj
*, unsigned int, section_offset_type
,
1119 section_offset_type
*) const;
1122 // Original EXIDX input section.
1123 const Arm_exidx_input_section
& exidx_input_section_
;
1124 // Section offset map.
1125 const Arm_exidx_section_offset_map
& section_offset_map_
;
1128 // A class to wrap an ordinary input section containing executable code.
1130 template<bool big_endian
>
1131 class Arm_input_section
: public Output_relaxed_input_section
1134 Arm_input_section(Relobj
* relobj
, unsigned int shndx
)
1135 : Output_relaxed_input_section(relobj
, shndx
, 1),
1136 original_addralign_(1), original_size_(0), stub_table_(NULL
)
1139 ~Arm_input_section()
1146 // Whether this is a stub table owner.
1148 is_stub_table_owner() const
1149 { return this->stub_table_
!= NULL
&& this->stub_table_
->owner() == this; }
1151 // Return the stub table.
1152 Stub_table
<big_endian
>*
1154 { return this->stub_table_
; }
1156 // Set the stub_table.
1158 set_stub_table(Stub_table
<big_endian
>* stub_table
)
1159 { this->stub_table_
= stub_table
; }
1161 // Downcast a base pointer to an Arm_input_section pointer. This is
1162 // not type-safe but we only use Arm_input_section not the base class.
1163 static Arm_input_section
<big_endian
>*
1164 as_arm_input_section(Output_relaxed_input_section
* poris
)
1165 { return static_cast<Arm_input_section
<big_endian
>*>(poris
); }
1167 // Return the original size of the section.
1169 original_size() const
1170 { return this->original_size_
; }
1173 // Write data to output file.
1175 do_write(Output_file
*);
1177 // Return required alignment of this.
1179 do_addralign() const
1181 if (this->is_stub_table_owner())
1182 return std::max(this->stub_table_
->addralign(),
1183 static_cast<uint64_t>(this->original_addralign_
));
1185 return this->original_addralign_
;
1188 // Finalize data size.
1190 set_final_data_size();
1192 // Reset address and file offset.
1194 do_reset_address_and_file_offset();
1198 do_output_offset(const Relobj
* object
, unsigned int shndx
,
1199 section_offset_type offset
,
1200 section_offset_type
* poutput
) const
1202 if ((object
== this->relobj())
1203 && (shndx
== this->shndx())
1206 convert_types
<section_offset_type
, uint32_t>(this->original_size_
)))
1216 // Copying is not allowed.
1217 Arm_input_section(const Arm_input_section
&);
1218 Arm_input_section
& operator=(const Arm_input_section
&);
1220 // Address alignment of the original input section.
1221 uint32_t original_addralign_
;
1222 // Section size of the original input section.
1223 uint32_t original_size_
;
1225 Stub_table
<big_endian
>* stub_table_
;
1228 // Arm_exidx_fixup class. This is used to define a number of methods
1229 // and keep states for fixing up EXIDX coverage.
1231 class Arm_exidx_fixup
1234 Arm_exidx_fixup(Output_section
* exidx_output_section
,
1235 bool merge_exidx_entries
= true)
1236 : exidx_output_section_(exidx_output_section
), last_unwind_type_(UT_NONE
),
1237 last_inlined_entry_(0), last_input_section_(NULL
),
1238 section_offset_map_(NULL
), first_output_text_section_(NULL
),
1239 merge_exidx_entries_(merge_exidx_entries
)
1243 { delete this->section_offset_map_
; }
1245 // Process an EXIDX section for entry merging. Return number of bytes to
1246 // be deleted in output. If parts of the input EXIDX section are merged
1247 // a heap allocated Arm_exidx_section_offset_map is store in the located
1248 // PSECTION_OFFSET_MAP. The caller owns the map and is reponsible for
1250 template<bool big_endian
>
1252 process_exidx_section(const Arm_exidx_input_section
* exidx_input_section
,
1253 Arm_exidx_section_offset_map
** psection_offset_map
);
1255 // Append an EXIDX_CANTUNWIND entry pointing at the end of the last
1256 // input section, if there is not one already.
1258 add_exidx_cantunwind_as_needed();
1260 // Return the output section for the text section which is linked to the
1261 // first exidx input in output.
1263 first_output_text_section() const
1264 { return this->first_output_text_section_
; }
1267 // Copying is not allowed.
1268 Arm_exidx_fixup(const Arm_exidx_fixup
&);
1269 Arm_exidx_fixup
& operator=(const Arm_exidx_fixup
&);
1271 // Type of EXIDX unwind entry.
1276 // EXIDX_CANTUNWIND.
1277 UT_EXIDX_CANTUNWIND
,
1284 // Process an EXIDX entry. We only care about the second word of the
1285 // entry. Return true if the entry can be deleted.
1287 process_exidx_entry(uint32_t second_word
);
1289 // Update the current section offset map during EXIDX section fix-up.
1290 // If there is no map, create one. INPUT_OFFSET is the offset of a
1291 // reference point, DELETED_BYTES is the number of deleted by in the
1292 // section so far. If DELETE_ENTRY is true, the reference point and
1293 // all offsets after the previous reference point are discarded.
1295 update_offset_map(section_offset_type input_offset
,
1296 section_size_type deleted_bytes
, bool delete_entry
);
1298 // EXIDX output section.
1299 Output_section
* exidx_output_section_
;
1300 // Unwind type of the last EXIDX entry processed.
1301 Unwind_type last_unwind_type_
;
1302 // Last seen inlined EXIDX entry.
1303 uint32_t last_inlined_entry_
;
1304 // Last processed EXIDX input section.
1305 const Arm_exidx_input_section
* last_input_section_
;
1306 // Section offset map created in process_exidx_section.
1307 Arm_exidx_section_offset_map
* section_offset_map_
;
1308 // Output section for the text section which is linked to the first exidx
1310 Output_section
* first_output_text_section_
;
1312 bool merge_exidx_entries_
;
1315 // Arm output section class. This is defined mainly to add a number of
1316 // stub generation methods.
1318 template<bool big_endian
>
1319 class Arm_output_section
: public Output_section
1322 typedef std::vector
<std::pair
<Relobj
*, unsigned int> > Text_section_list
;
1324 Arm_output_section(const char* name
, elfcpp::Elf_Word type
,
1325 elfcpp::Elf_Xword flags
)
1326 : Output_section(name
, type
, flags
)
1329 ~Arm_output_section()
1332 // Group input sections for stub generation.
1334 group_sections(section_size_type
, bool, Target_arm
<big_endian
>*);
1336 // Downcast a base pointer to an Arm_output_section pointer. This is
1337 // not type-safe but we only use Arm_output_section not the base class.
1338 static Arm_output_section
<big_endian
>*
1339 as_arm_output_section(Output_section
* os
)
1340 { return static_cast<Arm_output_section
<big_endian
>*>(os
); }
1342 // Append all input text sections in this into LIST.
1344 append_text_sections_to_list(Text_section_list
* list
);
1346 // Fix EXIDX coverage of this EXIDX output section. SORTED_TEXT_SECTION
1347 // is a list of text input sections sorted in ascending order of their
1348 // output addresses.
1350 fix_exidx_coverage(Layout
* layout
,
1351 const Text_section_list
& sorted_text_section
,
1352 Symbol_table
* symtab
,
1353 bool merge_exidx_entries
);
1357 typedef Output_section::Input_section Input_section
;
1358 typedef Output_section::Input_section_list Input_section_list
;
1360 // Create a stub group.
1361 void create_stub_group(Input_section_list::const_iterator
,
1362 Input_section_list::const_iterator
,
1363 Input_section_list::const_iterator
,
1364 Target_arm
<big_endian
>*,
1365 std::vector
<Output_relaxed_input_section
*>*);
1368 // Arm_exidx_input_section class. This represents an EXIDX input section.
1370 class Arm_exidx_input_section
1373 static const section_offset_type invalid_offset
=
1374 static_cast<section_offset_type
>(-1);
1376 Arm_exidx_input_section(Relobj
* relobj
, unsigned int shndx
,
1377 unsigned int link
, uint32_t size
, uint32_t addralign
)
1378 : relobj_(relobj
), shndx_(shndx
), link_(link
), size_(size
),
1379 addralign_(addralign
)
1382 ~Arm_exidx_input_section()
1385 // Accessors: This is a read-only class.
1387 // Return the object containing this EXIDX input section.
1390 { return this->relobj_
; }
1392 // Return the section index of this EXIDX input section.
1395 { return this->shndx_
; }
1397 // Return the section index of linked text section in the same object.
1400 { return this->link_
; }
1402 // Return size of the EXIDX input section.
1405 { return this->size_
; }
1407 // Reutnr address alignment of EXIDX input section.
1410 { return this->addralign_
; }
1413 // Object containing this.
1415 // Section index of this.
1416 unsigned int shndx_
;
1417 // text section linked to this in the same object.
1419 // Size of this. For ARM 32-bit is sufficient.
1421 // Address alignment of this. For ARM 32-bit is sufficient.
1422 uint32_t addralign_
;
1425 // Arm_relobj class.
1427 template<bool big_endian
>
1428 class Arm_relobj
: public Sized_relobj
<32, big_endian
>
1431 static const Arm_address invalid_address
= static_cast<Arm_address
>(-1);
1433 Arm_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
1434 const typename
elfcpp::Ehdr
<32, big_endian
>& ehdr
)
1435 : Sized_relobj
<32, big_endian
>(name
, input_file
, offset
, ehdr
),
1436 stub_tables_(), local_symbol_is_thumb_function_(),
1437 attributes_section_data_(NULL
), mapping_symbols_info_(),
1438 section_has_cortex_a8_workaround_(NULL
), exidx_section_map_(),
1439 output_local_symbol_count_needs_update_(false),
1440 merge_flags_and_attributes_(true)
1444 { delete this->attributes_section_data_
; }
1446 // Return the stub table of the SHNDX-th section if there is one.
1447 Stub_table
<big_endian
>*
1448 stub_table(unsigned int shndx
) const
1450 gold_assert(shndx
< this->stub_tables_
.size());
1451 return this->stub_tables_
[shndx
];
1454 // Set STUB_TABLE to be the stub_table of the SHNDX-th section.
1456 set_stub_table(unsigned int shndx
, Stub_table
<big_endian
>* stub_table
)
1458 gold_assert(shndx
< this->stub_tables_
.size());
1459 this->stub_tables_
[shndx
] = stub_table
;
1462 // Whether a local symbol is a THUMB function. R_SYM is the symbol table
1463 // index. This is only valid after do_count_local_symbol is called.
1465 local_symbol_is_thumb_function(unsigned int r_sym
) const
1467 gold_assert(r_sym
< this->local_symbol_is_thumb_function_
.size());
1468 return this->local_symbol_is_thumb_function_
[r_sym
];
1471 // Scan all relocation sections for stub generation.
1473 scan_sections_for_stubs(Target_arm
<big_endian
>*, const Symbol_table
*,
1476 // Convert regular input section with index SHNDX to a relaxed section.
1478 convert_input_section_to_relaxed_section(unsigned shndx
)
1480 // The stubs have relocations and we need to process them after writing
1481 // out the stubs. So relocation now must follow section write.
1482 this->set_section_offset(shndx
, -1ULL);
1483 this->set_relocs_must_follow_section_writes();
1486 // Downcast a base pointer to an Arm_relobj pointer. This is
1487 // not type-safe but we only use Arm_relobj not the base class.
1488 static Arm_relobj
<big_endian
>*
1489 as_arm_relobj(Relobj
* relobj
)
1490 { return static_cast<Arm_relobj
<big_endian
>*>(relobj
); }
1492 // Processor-specific flags in ELF file header. This is valid only after
1495 processor_specific_flags() const
1496 { return this->processor_specific_flags_
; }
1498 // Attribute section data This is the contents of the .ARM.attribute section
1500 const Attributes_section_data
*
1501 attributes_section_data() const
1502 { return this->attributes_section_data_
; }
1504 // Mapping symbol location.
1505 typedef std::pair
<unsigned int, Arm_address
> Mapping_symbol_position
;
1507 // Functor for STL container.
1508 struct Mapping_symbol_position_less
1511 operator()(const Mapping_symbol_position
& p1
,
1512 const Mapping_symbol_position
& p2
) const
1514 return (p1
.first
< p2
.first
1515 || (p1
.first
== p2
.first
&& p1
.second
< p2
.second
));
1519 // We only care about the first character of a mapping symbol, so
1520 // we only store that instead of the whole symbol name.
1521 typedef std::map
<Mapping_symbol_position
, char,
1522 Mapping_symbol_position_less
> Mapping_symbols_info
;
1524 // Whether a section contains any Cortex-A8 workaround.
1526 section_has_cortex_a8_workaround(unsigned int shndx
) const
1528 return (this->section_has_cortex_a8_workaround_
!= NULL
1529 && (*this->section_has_cortex_a8_workaround_
)[shndx
]);
1532 // Mark a section that has Cortex-A8 workaround.
1534 mark_section_for_cortex_a8_workaround(unsigned int shndx
)
1536 if (this->section_has_cortex_a8_workaround_
== NULL
)
1537 this->section_has_cortex_a8_workaround_
=
1538 new std::vector
<bool>(this->shnum(), false);
1539 (*this->section_has_cortex_a8_workaround_
)[shndx
] = true;
1542 // Return the EXIDX section of an text section with index SHNDX or NULL
1543 // if the text section has no associated EXIDX section.
1544 const Arm_exidx_input_section
*
1545 exidx_input_section_by_link(unsigned int shndx
) const
1547 Exidx_section_map::const_iterator p
= this->exidx_section_map_
.find(shndx
);
1548 return ((p
!= this->exidx_section_map_
.end()
1549 && p
->second
->link() == shndx
)
1554 // Return the EXIDX section with index SHNDX or NULL if there is none.
1555 const Arm_exidx_input_section
*
1556 exidx_input_section_by_shndx(unsigned shndx
) const
1558 Exidx_section_map::const_iterator p
= this->exidx_section_map_
.find(shndx
);
1559 return ((p
!= this->exidx_section_map_
.end()
1560 && p
->second
->shndx() == shndx
)
1565 // Whether output local symbol count needs updating.
1567 output_local_symbol_count_needs_update() const
1568 { return this->output_local_symbol_count_needs_update_
; }
1570 // Set output_local_symbol_count_needs_update flag to be true.
1572 set_output_local_symbol_count_needs_update()
1573 { this->output_local_symbol_count_needs_update_
= true; }
1575 // Update output local symbol count at the end of relaxation.
1577 update_output_local_symbol_count();
1579 // Whether we want to merge processor-specific flags and attributes.
1581 merge_flags_and_attributes() const
1582 { return this->merge_flags_and_attributes_
; }
1585 // Post constructor setup.
1589 // Call parent's setup method.
1590 Sized_relobj
<32, big_endian
>::do_setup();
1592 // Initialize look-up tables.
1593 Stub_table_list
empty_stub_table_list(this->shnum(), NULL
);
1594 this->stub_tables_
.swap(empty_stub_table_list
);
1597 // Count the local symbols.
1599 do_count_local_symbols(Stringpool_template
<char>*,
1600 Stringpool_template
<char>*);
1603 do_relocate_sections(const Symbol_table
* symtab
, const Layout
* layout
,
1604 const unsigned char* pshdrs
,
1605 typename Sized_relobj
<32, big_endian
>::Views
* pivews
);
1607 // Read the symbol information.
1609 do_read_symbols(Read_symbols_data
* sd
);
1611 // Process relocs for garbage collection.
1613 do_gc_process_relocs(Symbol_table
*, Layout
*, Read_relocs_data
*);
1617 // Whether a section needs to be scanned for relocation stubs.
1619 section_needs_reloc_stub_scanning(const elfcpp::Shdr
<32, big_endian
>&,
1620 const Relobj::Output_sections
&,
1621 const Symbol_table
*, const unsigned char*);
1623 // Whether a section is a scannable text section.
1625 section_is_scannable(const elfcpp::Shdr
<32, big_endian
>&, unsigned int,
1626 const Output_section
*, const Symbol_table
*);
1628 // Whether a section needs to be scanned for the Cortex-A8 erratum.
1630 section_needs_cortex_a8_stub_scanning(const elfcpp::Shdr
<32, big_endian
>&,
1631 unsigned int, Output_section
*,
1632 const Symbol_table
*);
1634 // Scan a section for the Cortex-A8 erratum.
1636 scan_section_for_cortex_a8_erratum(const elfcpp::Shdr
<32, big_endian
>&,
1637 unsigned int, Output_section
*,
1638 Target_arm
<big_endian
>*);
1640 // Find the linked text section of an EXIDX section by looking at the
1641 // first reloction of the EXIDX section. PSHDR points to the section
1642 // headers of a relocation section and PSYMS points to the local symbols.
1643 // PSHNDX points to a location storing the text section index if found.
1644 // Return whether we can find the linked section.
1646 find_linked_text_section(const unsigned char* pshdr
,
1647 const unsigned char* psyms
, unsigned int* pshndx
);
1650 // Make a new Arm_exidx_input_section object for EXIDX section with
1651 // index SHNDX and section header SHDR. TEXT_SHNDX is the section
1652 // index of the linked text section.
1654 make_exidx_input_section(unsigned int shndx
,
1655 const elfcpp::Shdr
<32, big_endian
>& shdr
,
1656 unsigned int text_shndx
);
1658 // Return the output address of either a plain input section or a
1659 // relaxed input section. SHNDX is the section index.
1661 simple_input_section_output_address(unsigned int, Output_section
*);
1663 typedef std::vector
<Stub_table
<big_endian
>*> Stub_table_list
;
1664 typedef Unordered_map
<unsigned int, const Arm_exidx_input_section
*>
1667 // List of stub tables.
1668 Stub_table_list stub_tables_
;
1669 // Bit vector to tell if a local symbol is a thumb function or not.
1670 // This is only valid after do_count_local_symbol is called.
1671 std::vector
<bool> local_symbol_is_thumb_function_
;
1672 // processor-specific flags in ELF file header.
1673 elfcpp::Elf_Word processor_specific_flags_
;
1674 // Object attributes if there is an .ARM.attributes section or NULL.
1675 Attributes_section_data
* attributes_section_data_
;
1676 // Mapping symbols information.
1677 Mapping_symbols_info mapping_symbols_info_
;
1678 // Bitmap to indicate sections with Cortex-A8 workaround or NULL.
1679 std::vector
<bool>* section_has_cortex_a8_workaround_
;
1680 // Map a text section to its associated .ARM.exidx section, if there is one.
1681 Exidx_section_map exidx_section_map_
;
1682 // Whether output local symbol count needs updating.
1683 bool output_local_symbol_count_needs_update_
;
1684 // Whether we merge processor flags and attributes of this object to
1686 bool merge_flags_and_attributes_
;
1689 // Arm_dynobj class.
1691 template<bool big_endian
>
1692 class Arm_dynobj
: public Sized_dynobj
<32, big_endian
>
1695 Arm_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
1696 const elfcpp::Ehdr
<32, big_endian
>& ehdr
)
1697 : Sized_dynobj
<32, big_endian
>(name
, input_file
, offset
, ehdr
),
1698 processor_specific_flags_(0), attributes_section_data_(NULL
)
1702 { delete this->attributes_section_data_
; }
1704 // Downcast a base pointer to an Arm_relobj pointer. This is
1705 // not type-safe but we only use Arm_relobj not the base class.
1706 static Arm_dynobj
<big_endian
>*
1707 as_arm_dynobj(Dynobj
* dynobj
)
1708 { return static_cast<Arm_dynobj
<big_endian
>*>(dynobj
); }
1710 // Processor-specific flags in ELF file header. This is valid only after
1713 processor_specific_flags() const
1714 { return this->processor_specific_flags_
; }
1716 // Attributes section data.
1717 const Attributes_section_data
*
1718 attributes_section_data() const
1719 { return this->attributes_section_data_
; }
1722 // Read the symbol information.
1724 do_read_symbols(Read_symbols_data
* sd
);
1727 // processor-specific flags in ELF file header.
1728 elfcpp::Elf_Word processor_specific_flags_
;
1729 // Object attributes if there is an .ARM.attributes section or NULL.
1730 Attributes_section_data
* attributes_section_data_
;
1733 // Functor to read reloc addends during stub generation.
1735 template<int sh_type
, bool big_endian
>
1736 struct Stub_addend_reader
1738 // Return the addend for a relocation of a particular type. Depending
1739 // on whether this is a REL or RELA relocation, read the addend from a
1740 // view or from a Reloc object.
1741 elfcpp::Elf_types
<32>::Elf_Swxword
1743 unsigned int /* r_type */,
1744 const unsigned char* /* view */,
1745 const typename Reloc_types
<sh_type
,
1746 32, big_endian
>::Reloc
& /* reloc */) const;
1749 // Specialized Stub_addend_reader for SHT_REL type relocation sections.
1751 template<bool big_endian
>
1752 struct Stub_addend_reader
<elfcpp::SHT_REL
, big_endian
>
1754 elfcpp::Elf_types
<32>::Elf_Swxword
1757 const unsigned char*,
1758 const typename Reloc_types
<elfcpp::SHT_REL
, 32, big_endian
>::Reloc
&) const;
1761 // Specialized Stub_addend_reader for RELA type relocation sections.
1762 // We currently do not handle RELA type relocation sections but it is trivial
1763 // to implement the addend reader. This is provided for completeness and to
1764 // make it easier to add support for RELA relocation sections in the future.
1766 template<bool big_endian
>
1767 struct Stub_addend_reader
<elfcpp::SHT_RELA
, big_endian
>
1769 elfcpp::Elf_types
<32>::Elf_Swxword
1772 const unsigned char*,
1773 const typename Reloc_types
<elfcpp::SHT_RELA
, 32,
1774 big_endian
>::Reloc
& reloc
) const
1775 { return reloc
.get_r_addend(); }
1778 // Cortex_a8_reloc class. We keep record of relocation that may need
1779 // the Cortex-A8 erratum workaround.
1781 class Cortex_a8_reloc
1784 Cortex_a8_reloc(Reloc_stub
* reloc_stub
, unsigned r_type
,
1785 Arm_address destination
)
1786 : reloc_stub_(reloc_stub
), r_type_(r_type
), destination_(destination
)
1792 // Accessors: This is a read-only class.
1794 // Return the relocation stub associated with this relocation if there is
1798 { return this->reloc_stub_
; }
1800 // Return the relocation type.
1803 { return this->r_type_
; }
1805 // Return the destination address of the relocation. LSB stores the THUMB
1809 { return this->destination_
; }
1812 // Associated relocation stub if there is one, or NULL.
1813 const Reloc_stub
* reloc_stub_
;
1815 unsigned int r_type_
;
1816 // Destination address of this relocation. LSB is used to distinguish
1818 Arm_address destination_
;
1821 // Arm_output_data_got class. We derive this from Output_data_got to add
1822 // extra methods to handle TLS relocations in a static link.
1824 template<bool big_endian
>
1825 class Arm_output_data_got
: public Output_data_got
<32, big_endian
>
1828 Arm_output_data_got(Symbol_table
* symtab
, Layout
* layout
)
1829 : Output_data_got
<32, big_endian
>(), symbol_table_(symtab
), layout_(layout
)
1832 // Add a static entry for the GOT entry at OFFSET. GSYM is a global
1833 // symbol and R_TYPE is the code of a dynamic relocation that needs to be
1834 // applied in a static link.
1836 add_static_reloc(unsigned int got_offset
, unsigned int r_type
, Symbol
* gsym
)
1837 { this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, gsym
)); }
1839 // Add a static reloc for the GOT entry at OFFSET. RELOBJ is an object
1840 // defining a local symbol with INDEX. R_TYPE is the code of a dynamic
1841 // relocation that needs to be applied in a static link.
1843 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
1844 Sized_relobj
<32, big_endian
>* relobj
, unsigned int index
)
1846 this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, relobj
,
1850 // Add a GOT pair for R_ARM_TLS_GD32. The creates a pair of GOT entries.
1851 // The first one is initialized to be 1, which is the module index for
1852 // the main executable and the second one 0. A reloc of the type
1853 // R_ARM_TLS_DTPOFF32 will be created for the second GOT entry and will
1854 // be applied by gold. GSYM is a global symbol.
1856 add_tls_gd32_with_static_reloc(unsigned int got_type
, Symbol
* gsym
);
1858 // Same as the above but for a local symbol in OBJECT with INDEX.
1860 add_tls_gd32_with_static_reloc(unsigned int got_type
,
1861 Sized_relobj
<32, big_endian
>* object
,
1862 unsigned int index
);
1865 // Write out the GOT table.
1867 do_write(Output_file
*);
1870 // This class represent dynamic relocations that need to be applied by
1871 // gold because we are using TLS relocations in a static link.
1875 Static_reloc(unsigned int got_offset
, unsigned int r_type
, Symbol
* gsym
)
1876 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(true)
1877 { this->u_
.global
.symbol
= gsym
; }
1879 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
1880 Sized_relobj
<32, big_endian
>* relobj
, unsigned int index
)
1881 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(false)
1883 this->u_
.local
.relobj
= relobj
;
1884 this->u_
.local
.index
= index
;
1887 // Return the GOT offset.
1890 { return this->got_offset_
; }
1895 { return this->r_type_
; }
1897 // Whether the symbol is global or not.
1899 symbol_is_global() const
1900 { return this->symbol_is_global_
; }
1902 // For a relocation against a global symbol, the global symbol.
1906 gold_assert(this->symbol_is_global_
);
1907 return this->u_
.global
.symbol
;
1910 // For a relocation against a local symbol, the defining object.
1911 Sized_relobj
<32, big_endian
>*
1914 gold_assert(!this->symbol_is_global_
);
1915 return this->u_
.local
.relobj
;
1918 // For a relocation against a local symbol, the local symbol index.
1922 gold_assert(!this->symbol_is_global_
);
1923 return this->u_
.local
.index
;
1927 // GOT offset of the entry to which this relocation is applied.
1928 unsigned int got_offset_
;
1929 // Type of relocation.
1930 unsigned int r_type_
;
1931 // Whether this relocation is against a global symbol.
1932 bool symbol_is_global_
;
1933 // A global or local symbol.
1938 // For a global symbol, the symbol itself.
1943 // For a local symbol, the object defining object.
1944 Sized_relobj
<32, big_endian
>* relobj
;
1945 // For a local symbol, the symbol index.
1951 // Symbol table of the output object.
1952 Symbol_table
* symbol_table_
;
1953 // Layout of the output object.
1955 // Static relocs to be applied to the GOT.
1956 std::vector
<Static_reloc
> static_relocs_
;
1959 // The ARM target has many relocation types with odd-sizes or incontigious
1960 // bits. The default handling of relocatable relocation cannot process these
1961 // relocations. So we have to extend the default code.
1963 template<bool big_endian
, int sh_type
, typename Classify_reloc
>
1964 class Arm_scan_relocatable_relocs
:
1965 public Default_scan_relocatable_relocs
<sh_type
, Classify_reloc
>
1968 // Return the strategy to use for a local symbol which is a section
1969 // symbol, given the relocation type.
1970 inline Relocatable_relocs::Reloc_strategy
1971 local_section_strategy(unsigned int r_type
, Relobj
*)
1973 if (sh_type
== elfcpp::SHT_RELA
)
1974 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
1977 if (r_type
== elfcpp::R_ARM_TARGET1
1978 || r_type
== elfcpp::R_ARM_TARGET2
)
1980 const Target_arm
<big_endian
>* arm_target
=
1981 Target_arm
<big_endian
>::default_target();
1982 r_type
= arm_target
->get_real_reloc_type(r_type
);
1987 // Relocations that write nothing. These exclude R_ARM_TARGET1
1988 // and R_ARM_TARGET2.
1989 case elfcpp::R_ARM_NONE
:
1990 case elfcpp::R_ARM_V4BX
:
1991 case elfcpp::R_ARM_TLS_GOTDESC
:
1992 case elfcpp::R_ARM_TLS_CALL
:
1993 case elfcpp::R_ARM_TLS_DESCSEQ
:
1994 case elfcpp::R_ARM_THM_TLS_CALL
:
1995 case elfcpp::R_ARM_GOTRELAX
:
1996 case elfcpp::R_ARM_GNU_VTENTRY
:
1997 case elfcpp::R_ARM_GNU_VTINHERIT
:
1998 case elfcpp::R_ARM_THM_TLS_DESCSEQ16
:
1999 case elfcpp::R_ARM_THM_TLS_DESCSEQ32
:
2000 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0
;
2001 // These should have been converted to something else above.
2002 case elfcpp::R_ARM_TARGET1
:
2003 case elfcpp::R_ARM_TARGET2
:
2005 // Relocations that write full 32 bits.
2006 case elfcpp::R_ARM_ABS32
:
2007 case elfcpp::R_ARM_REL32
:
2008 case elfcpp::R_ARM_SBREL32
:
2009 case elfcpp::R_ARM_GOTOFF32
:
2010 case elfcpp::R_ARM_BASE_PREL
:
2011 case elfcpp::R_ARM_GOT_BREL
:
2012 case elfcpp::R_ARM_BASE_ABS
:
2013 case elfcpp::R_ARM_ABS32_NOI
:
2014 case elfcpp::R_ARM_REL32_NOI
:
2015 case elfcpp::R_ARM_PLT32_ABS
:
2016 case elfcpp::R_ARM_GOT_ABS
:
2017 case elfcpp::R_ARM_GOT_PREL
:
2018 case elfcpp::R_ARM_TLS_GD32
:
2019 case elfcpp::R_ARM_TLS_LDM32
:
2020 case elfcpp::R_ARM_TLS_LDO32
:
2021 case elfcpp::R_ARM_TLS_IE32
:
2022 case elfcpp::R_ARM_TLS_LE32
:
2023 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4
;
2025 // For all other static relocations, return RELOC_SPECIAL.
2026 return Relocatable_relocs::RELOC_SPECIAL
;
2032 // Utilities for manipulating integers of up to 32-bits
2036 // Sign extend an n-bit unsigned integer stored in an uint32_t into
2037 // an int32_t. NO_BITS must be between 1 to 32.
2038 template<int no_bits
>
2039 static inline int32_t
2040 sign_extend(uint32_t bits
)
2042 gold_assert(no_bits
>= 0 && no_bits
<= 32);
2044 return static_cast<int32_t>(bits
);
2045 uint32_t mask
= (~((uint32_t) 0)) >> (32 - no_bits
);
2047 uint32_t top_bit
= 1U << (no_bits
- 1);
2048 int32_t as_signed
= static_cast<int32_t>(bits
);
2049 return (bits
& top_bit
) ? as_signed
+ (-top_bit
* 2) : as_signed
;
2052 // Detects overflow of an NO_BITS integer stored in a uint32_t.
2053 template<int no_bits
>
2055 has_overflow(uint32_t bits
)
2057 gold_assert(no_bits
>= 0 && no_bits
<= 32);
2060 int32_t max
= (1 << (no_bits
- 1)) - 1;
2061 int32_t min
= -(1 << (no_bits
- 1));
2062 int32_t as_signed
= static_cast<int32_t>(bits
);
2063 return as_signed
> max
|| as_signed
< min
;
2066 // Detects overflow of an NO_BITS integer stored in a uint32_t when it
2067 // fits in the given number of bits as either a signed or unsigned value.
2068 // For example, has_signed_unsigned_overflow<8> would check
2069 // -128 <= bits <= 255
2070 template<int no_bits
>
2072 has_signed_unsigned_overflow(uint32_t bits
)
2074 gold_assert(no_bits
>= 2 && no_bits
<= 32);
2077 int32_t max
= static_cast<int32_t>((1U << no_bits
) - 1);
2078 int32_t min
= -(1 << (no_bits
- 1));
2079 int32_t as_signed
= static_cast<int32_t>(bits
);
2080 return as_signed
> max
|| as_signed
< min
;
2083 // Select bits from A and B using bits in MASK. For each n in [0..31],
2084 // the n-th bit in the result is chosen from the n-th bits of A and B.
2085 // A zero selects A and a one selects B.
2086 static inline uint32_t
2087 bit_select(uint32_t a
, uint32_t b
, uint32_t mask
)
2088 { return (a
& ~mask
) | (b
& mask
); }
2091 template<bool big_endian
>
2092 class Target_arm
: public Sized_target
<32, big_endian
>
2095 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, big_endian
>
2098 // When were are relocating a stub, we pass this as the relocation number.
2099 static const size_t fake_relnum_for_stubs
= static_cast<size_t>(-1);
2102 : Sized_target
<32, big_endian
>(&arm_info
),
2103 got_(NULL
), plt_(NULL
), got_plt_(NULL
), rel_dyn_(NULL
),
2104 copy_relocs_(elfcpp::R_ARM_COPY
), dynbss_(NULL
),
2105 got_mod_index_offset_(-1U), tls_base_symbol_defined_(false),
2106 stub_tables_(), stub_factory_(Stub_factory::get_instance()),
2107 may_use_blx_(false), should_force_pic_veneer_(false),
2108 arm_input_section_map_(), attributes_section_data_(NULL
),
2109 fix_cortex_a8_(false), cortex_a8_relocs_info_()
2112 // Virtual function which is set to return true by a target if
2113 // it can use relocation types to determine if a function's
2114 // pointer is taken.
2116 can_check_for_function_pointers() const
2119 // Whether a section called SECTION_NAME may have function pointers to
2120 // sections not eligible for safe ICF folding.
2122 section_may_have_icf_unsafe_pointers(const char* section_name
) const
2124 return (!is_prefix_of(".ARM.exidx", section_name
)
2125 && !is_prefix_of(".ARM.extab", section_name
)
2126 && Target::section_may_have_icf_unsafe_pointers(section_name
));
2129 // Whether we can use BLX.
2132 { return this->may_use_blx_
; }
2134 // Set use-BLX flag.
2136 set_may_use_blx(bool value
)
2137 { this->may_use_blx_
= value
; }
2139 // Whether we force PCI branch veneers.
2141 should_force_pic_veneer() const
2142 { return this->should_force_pic_veneer_
; }
2144 // Set PIC veneer flag.
2146 set_should_force_pic_veneer(bool value
)
2147 { this->should_force_pic_veneer_
= value
; }
2149 // Whether we use THUMB-2 instructions.
2151 using_thumb2() const
2153 Object_attribute
* attr
=
2154 this->get_aeabi_object_attribute(elfcpp::Tag_CPU_arch
);
2155 int arch
= attr
->int_value();
2156 return arch
== elfcpp::TAG_CPU_ARCH_V6T2
|| arch
>= elfcpp::TAG_CPU_ARCH_V7
;
2159 // Whether we use THUMB/THUMB-2 instructions only.
2161 using_thumb_only() const
2163 Object_attribute
* attr
=
2164 this->get_aeabi_object_attribute(elfcpp::Tag_CPU_arch
);
2166 if (attr
->int_value() == elfcpp::TAG_CPU_ARCH_V6_M
2167 || attr
->int_value() == elfcpp::TAG_CPU_ARCH_V6S_M
)
2169 if (attr
->int_value() != elfcpp::TAG_CPU_ARCH_V7
2170 && attr
->int_value() != elfcpp::TAG_CPU_ARCH_V7E_M
)
2172 attr
= this->get_aeabi_object_attribute(elfcpp::Tag_CPU_arch_profile
);
2173 return attr
->int_value() == 'M';
2176 // Whether we have an NOP instruction. If not, use mov r0, r0 instead.
2178 may_use_arm_nop() const
2180 Object_attribute
* attr
=
2181 this->get_aeabi_object_attribute(elfcpp::Tag_CPU_arch
);
2182 int arch
= attr
->int_value();
2183 return (arch
== elfcpp::TAG_CPU_ARCH_V6T2
2184 || arch
== elfcpp::TAG_CPU_ARCH_V6K
2185 || arch
== elfcpp::TAG_CPU_ARCH_V7
2186 || arch
== elfcpp::TAG_CPU_ARCH_V7E_M
);
2189 // Whether we have THUMB-2 NOP.W instruction.
2191 may_use_thumb2_nop() const
2193 Object_attribute
* attr
=
2194 this->get_aeabi_object_attribute(elfcpp::Tag_CPU_arch
);
2195 int arch
= attr
->int_value();
2196 return (arch
== elfcpp::TAG_CPU_ARCH_V6T2
2197 || arch
== elfcpp::TAG_CPU_ARCH_V7
2198 || arch
== elfcpp::TAG_CPU_ARCH_V7E_M
);
2201 // Process the relocations to determine unreferenced sections for
2202 // garbage collection.
2204 gc_process_relocs(Symbol_table
* symtab
,
2206 Sized_relobj
<32, big_endian
>* object
,
2207 unsigned int data_shndx
,
2208 unsigned int sh_type
,
2209 const unsigned char* prelocs
,
2211 Output_section
* output_section
,
2212 bool needs_special_offset_handling
,
2213 size_t local_symbol_count
,
2214 const unsigned char* plocal_symbols
);
2216 // Scan the relocations to look for symbol adjustments.
2218 scan_relocs(Symbol_table
* symtab
,
2220 Sized_relobj
<32, big_endian
>* object
,
2221 unsigned int data_shndx
,
2222 unsigned int sh_type
,
2223 const unsigned char* prelocs
,
2225 Output_section
* output_section
,
2226 bool needs_special_offset_handling
,
2227 size_t local_symbol_count
,
2228 const unsigned char* plocal_symbols
);
2230 // Finalize the sections.
2232 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
2234 // Return the value to use for a dynamic symbol which requires special
2237 do_dynsym_value(const Symbol
*) const;
2239 // Relocate a section.
2241 relocate_section(const Relocate_info
<32, big_endian
>*,
2242 unsigned int sh_type
,
2243 const unsigned char* prelocs
,
2245 Output_section
* output_section
,
2246 bool needs_special_offset_handling
,
2247 unsigned char* view
,
2248 Arm_address view_address
,
2249 section_size_type view_size
,
2250 const Reloc_symbol_changes
*);
2252 // Scan the relocs during a relocatable link.
2254 scan_relocatable_relocs(Symbol_table
* symtab
,
2256 Sized_relobj
<32, big_endian
>* object
,
2257 unsigned int data_shndx
,
2258 unsigned int sh_type
,
2259 const unsigned char* prelocs
,
2261 Output_section
* output_section
,
2262 bool needs_special_offset_handling
,
2263 size_t local_symbol_count
,
2264 const unsigned char* plocal_symbols
,
2265 Relocatable_relocs
*);
2267 // Relocate a section during a relocatable link.
2269 relocate_for_relocatable(const Relocate_info
<32, big_endian
>*,
2270 unsigned int sh_type
,
2271 const unsigned char* prelocs
,
2273 Output_section
* output_section
,
2274 off_t offset_in_output_section
,
2275 const Relocatable_relocs
*,
2276 unsigned char* view
,
2277 Arm_address view_address
,
2278 section_size_type view_size
,
2279 unsigned char* reloc_view
,
2280 section_size_type reloc_view_size
);
2282 // Perform target-specific processing in a relocatable link. This is
2283 // only used if we use the relocation strategy RELOC_SPECIAL.
2285 relocate_special_relocatable(const Relocate_info
<32, big_endian
>* relinfo
,
2286 unsigned int sh_type
,
2287 const unsigned char* preloc_in
,
2289 Output_section
* output_section
,
2290 off_t offset_in_output_section
,
2291 unsigned char* view
,
2292 typename
elfcpp::Elf_types
<32>::Elf_Addr
2294 section_size_type view_size
,
2295 unsigned char* preloc_out
);
2297 // Return whether SYM is defined by the ABI.
2299 do_is_defined_by_abi(Symbol
* sym
) const
2300 { return strcmp(sym
->name(), "__tls_get_addr") == 0; }
2302 // Return whether there is a GOT section.
2304 has_got_section() const
2305 { return this->got_
!= NULL
; }
2307 // Return the size of the GOT section.
2311 gold_assert(this->got_
!= NULL
);
2312 return this->got_
->data_size();
2315 // Map platform-specific reloc types
2317 get_real_reloc_type (unsigned int r_type
);
2320 // Methods to support stub-generations.
2323 // Return the stub factory
2325 stub_factory() const
2326 { return this->stub_factory_
; }
2328 // Make a new Arm_input_section object.
2329 Arm_input_section
<big_endian
>*
2330 new_arm_input_section(Relobj
*, unsigned int);
2332 // Find the Arm_input_section object corresponding to the SHNDX-th input
2333 // section of RELOBJ.
2334 Arm_input_section
<big_endian
>*
2335 find_arm_input_section(Relobj
* relobj
, unsigned int shndx
) const;
2337 // Make a new Stub_table
2338 Stub_table
<big_endian
>*
2339 new_stub_table(Arm_input_section
<big_endian
>*);
2341 // Scan a section for stub generation.
2343 scan_section_for_stubs(const Relocate_info
<32, big_endian
>*, unsigned int,
2344 const unsigned char*, size_t, Output_section
*,
2345 bool, const unsigned char*, Arm_address
,
2350 relocate_stub(Stub
*, const Relocate_info
<32, big_endian
>*,
2351 Output_section
*, unsigned char*, Arm_address
,
2354 // Get the default ARM target.
2355 static Target_arm
<big_endian
>*
2358 gold_assert(parameters
->target().machine_code() == elfcpp::EM_ARM
2359 && parameters
->target().is_big_endian() == big_endian
);
2360 return static_cast<Target_arm
<big_endian
>*>(
2361 parameters
->sized_target
<32, big_endian
>());
2364 // Whether NAME belongs to a mapping symbol.
2366 is_mapping_symbol_name(const char* name
)
2370 && (name
[1] == 'a' || name
[1] == 't' || name
[1] == 'd')
2371 && (name
[2] == '\0' || name
[2] == '.'));
2374 // Whether we work around the Cortex-A8 erratum.
2376 fix_cortex_a8() const
2377 { return this->fix_cortex_a8_
; }
2379 // Whether we merge exidx entries in debuginfo.
2381 merge_exidx_entries() const
2382 { return parameters
->options().merge_exidx_entries(); }
2384 // Whether we fix R_ARM_V4BX relocation.
2386 // 1 - replace with MOV instruction (armv4 target)
2387 // 2 - make interworking veneer (>= armv4t targets only)
2388 General_options::Fix_v4bx
2390 { return parameters
->options().fix_v4bx(); }
2392 // Scan a span of THUMB code section for Cortex-A8 erratum.
2394 scan_span_for_cortex_a8_erratum(Arm_relobj
<big_endian
>*, unsigned int,
2395 section_size_type
, section_size_type
,
2396 const unsigned char*, Arm_address
);
2398 // Apply Cortex-A8 workaround to a branch.
2400 apply_cortex_a8_workaround(const Cortex_a8_stub
*, Arm_address
,
2401 unsigned char*, Arm_address
);
2404 // Make an ELF object.
2406 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
2407 const elfcpp::Ehdr
<32, big_endian
>& ehdr
);
2410 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
2411 const elfcpp::Ehdr
<32, !big_endian
>&)
2412 { gold_unreachable(); }
2415 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
2416 const elfcpp::Ehdr
<64, false>&)
2417 { gold_unreachable(); }
2420 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
2421 const elfcpp::Ehdr
<64, true>&)
2422 { gold_unreachable(); }
2424 // Make an output section.
2426 do_make_output_section(const char* name
, elfcpp::Elf_Word type
,
2427 elfcpp::Elf_Xword flags
)
2428 { return new Arm_output_section
<big_endian
>(name
, type
, flags
); }
2431 do_adjust_elf_header(unsigned char* view
, int len
) const;
2433 // We only need to generate stubs, and hence perform relaxation if we are
2434 // not doing relocatable linking.
2436 do_may_relax() const
2437 { return !parameters
->options().relocatable(); }
2440 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*);
2442 // Determine whether an object attribute tag takes an integer, a
2445 do_attribute_arg_type(int tag
) const;
2447 // Reorder tags during output.
2449 do_attributes_order(int num
) const;
2451 // This is called when the target is selected as the default.
2453 do_select_as_default_target()
2455 // No locking is required since there should only be one default target.
2456 // We cannot have both the big-endian and little-endian ARM targets
2458 gold_assert(arm_reloc_property_table
== NULL
);
2459 arm_reloc_property_table
= new Arm_reloc_property_table();
2463 // The class which scans relocations.
2468 : issued_non_pic_error_(false)
2472 local(Symbol_table
* symtab
, Layout
* layout
, Target_arm
* target
,
2473 Sized_relobj
<32, big_endian
>* object
,
2474 unsigned int data_shndx
,
2475 Output_section
* output_section
,
2476 const elfcpp::Rel
<32, big_endian
>& reloc
, unsigned int r_type
,
2477 const elfcpp::Sym
<32, big_endian
>& lsym
);
2480 global(Symbol_table
* symtab
, Layout
* layout
, Target_arm
* target
,
2481 Sized_relobj
<32, big_endian
>* object
,
2482 unsigned int data_shndx
,
2483 Output_section
* output_section
,
2484 const elfcpp::Rel
<32, big_endian
>& reloc
, unsigned int r_type
,
2488 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* , Target_arm
* ,
2489 Sized_relobj
<32, big_endian
>* ,
2492 const elfcpp::Rel
<32, big_endian
>& ,
2494 const elfcpp::Sym
<32, big_endian
>&);
2497 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* , Target_arm
* ,
2498 Sized_relobj
<32, big_endian
>* ,
2501 const elfcpp::Rel
<32, big_endian
>& ,
2502 unsigned int , Symbol
*);
2506 unsupported_reloc_local(Sized_relobj
<32, big_endian
>*,
2507 unsigned int r_type
);
2510 unsupported_reloc_global(Sized_relobj
<32, big_endian
>*,
2511 unsigned int r_type
, Symbol
*);
2514 check_non_pic(Relobj
*, unsigned int r_type
);
2516 // Almost identical to Symbol::needs_plt_entry except that it also
2517 // handles STT_ARM_TFUNC.
2519 symbol_needs_plt_entry(const Symbol
* sym
)
2521 // An undefined symbol from an executable does not need a PLT entry.
2522 if (sym
->is_undefined() && !parameters
->options().shared())
2525 return (!parameters
->doing_static_link()
2526 && (sym
->type() == elfcpp::STT_FUNC
2527 || sym
->type() == elfcpp::STT_ARM_TFUNC
)
2528 && (sym
->is_from_dynobj()
2529 || sym
->is_undefined()
2530 || sym
->is_preemptible()));
2534 possible_function_pointer_reloc(unsigned int r_type
);
2536 // Whether we have issued an error about a non-PIC compilation.
2537 bool issued_non_pic_error_
;
2540 // The class which implements relocation.
2550 // Return whether the static relocation needs to be applied.
2552 should_apply_static_reloc(const Sized_symbol
<32>* gsym
,
2555 Output_section
* output_section
);
2557 // Do a relocation. Return false if the caller should not issue
2558 // any warnings about this relocation.
2560 relocate(const Relocate_info
<32, big_endian
>*, Target_arm
*,
2561 Output_section
*, size_t relnum
,
2562 const elfcpp::Rel
<32, big_endian
>&,
2563 unsigned int r_type
, const Sized_symbol
<32>*,
2564 const Symbol_value
<32>*,
2565 unsigned char*, Arm_address
,
2568 // Return whether we want to pass flag NON_PIC_REF for this
2569 // reloc. This means the relocation type accesses a symbol not via
2572 reloc_is_non_pic (unsigned int r_type
)
2576 // These relocation types reference GOT or PLT entries explicitly.
2577 case elfcpp::R_ARM_GOT_BREL
:
2578 case elfcpp::R_ARM_GOT_ABS
:
2579 case elfcpp::R_ARM_GOT_PREL
:
2580 case elfcpp::R_ARM_GOT_BREL12
:
2581 case elfcpp::R_ARM_PLT32_ABS
:
2582 case elfcpp::R_ARM_TLS_GD32
:
2583 case elfcpp::R_ARM_TLS_LDM32
:
2584 case elfcpp::R_ARM_TLS_IE32
:
2585 case elfcpp::R_ARM_TLS_IE12GP
:
2587 // These relocate types may use PLT entries.
2588 case elfcpp::R_ARM_CALL
:
2589 case elfcpp::R_ARM_THM_CALL
:
2590 case elfcpp::R_ARM_JUMP24
:
2591 case elfcpp::R_ARM_THM_JUMP24
:
2592 case elfcpp::R_ARM_THM_JUMP19
:
2593 case elfcpp::R_ARM_PLT32
:
2594 case elfcpp::R_ARM_THM_XPC22
:
2595 case elfcpp::R_ARM_PREL31
:
2596 case elfcpp::R_ARM_SBREL31
:
2605 // Do a TLS relocation.
2606 inline typename Arm_relocate_functions
<big_endian
>::Status
2607 relocate_tls(const Relocate_info
<32, big_endian
>*, Target_arm
<big_endian
>*,
2608 size_t, const elfcpp::Rel
<32, big_endian
>&, unsigned int,
2609 const Sized_symbol
<32>*, const Symbol_value
<32>*,
2610 unsigned char*, elfcpp::Elf_types
<32>::Elf_Addr
,
2615 // A class which returns the size required for a relocation type,
2616 // used while scanning relocs during a relocatable link.
2617 class Relocatable_size_for_reloc
2621 get_size_for_reloc(unsigned int, Relobj
*);
2624 // Adjust TLS relocation type based on the options and whether this
2625 // is a local symbol.
2626 static tls::Tls_optimization
2627 optimize_tls_reloc(bool is_final
, int r_type
);
2629 // Get the GOT section, creating it if necessary.
2630 Arm_output_data_got
<big_endian
>*
2631 got_section(Symbol_table
*, Layout
*);
2633 // Get the GOT PLT section.
2635 got_plt_section() const
2637 gold_assert(this->got_plt_
!= NULL
);
2638 return this->got_plt_
;
2641 // Create a PLT entry for a global symbol.
2643 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
2645 // Define the _TLS_MODULE_BASE_ symbol in the TLS segment.
2647 define_tls_base_symbol(Symbol_table
*, Layout
*);
2649 // Create a GOT entry for the TLS module index.
2651 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
2652 Sized_relobj
<32, big_endian
>* object
);
2654 // Get the PLT section.
2655 const Output_data_plt_arm
<big_endian
>*
2658 gold_assert(this->plt_
!= NULL
);
2662 // Get the dynamic reloc section, creating it if necessary.
2664 rel_dyn_section(Layout
*);
2666 // Get the section to use for TLS_DESC relocations.
2668 rel_tls_desc_section(Layout
*) const;
2670 // Return true if the symbol may need a COPY relocation.
2671 // References from an executable object to non-function symbols
2672 // defined in a dynamic object may need a COPY relocation.
2674 may_need_copy_reloc(Symbol
* gsym
)
2676 return (gsym
->type() != elfcpp::STT_ARM_TFUNC
2677 && gsym
->may_need_copy_reloc());
2680 // Add a potential copy relocation.
2682 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
2683 Sized_relobj
<32, big_endian
>* object
,
2684 unsigned int shndx
, Output_section
* output_section
,
2685 Symbol
* sym
, const elfcpp::Rel
<32, big_endian
>& reloc
)
2687 this->copy_relocs_
.copy_reloc(symtab
, layout
,
2688 symtab
->get_sized_symbol
<32>(sym
),
2689 object
, shndx
, output_section
, reloc
,
2690 this->rel_dyn_section(layout
));
2693 // Whether two EABI versions are compatible.
2695 are_eabi_versions_compatible(elfcpp::Elf_Word v1
, elfcpp::Elf_Word v2
);
2697 // Merge processor-specific flags from input object and those in the ELF
2698 // header of the output.
2700 merge_processor_specific_flags(const std::string
&, elfcpp::Elf_Word
);
2702 // Get the secondary compatible architecture.
2704 get_secondary_compatible_arch(const Attributes_section_data
*);
2706 // Set the secondary compatible architecture.
2708 set_secondary_compatible_arch(Attributes_section_data
*, int);
2711 tag_cpu_arch_combine(const char*, int, int*, int, int);
2713 // Helper to print AEABI enum tag value.
2715 aeabi_enum_name(unsigned int);
2717 // Return string value for TAG_CPU_name.
2719 tag_cpu_name_value(unsigned int);
2721 // Merge object attributes from input object and those in the output.
2723 merge_object_attributes(const char*, const Attributes_section_data
*);
2725 // Helper to get an AEABI object attribute
2727 get_aeabi_object_attribute(int tag
) const
2729 Attributes_section_data
* pasd
= this->attributes_section_data_
;
2730 gold_assert(pasd
!= NULL
);
2731 Object_attribute
* attr
=
2732 pasd
->get_attribute(Object_attribute::OBJ_ATTR_PROC
, tag
);
2733 gold_assert(attr
!= NULL
);
2738 // Methods to support stub-generations.
2741 // Group input sections for stub generation.
2743 group_sections(Layout
*, section_size_type
, bool);
2745 // Scan a relocation for stub generation.
2747 scan_reloc_for_stub(const Relocate_info
<32, big_endian
>*, unsigned int,
2748 const Sized_symbol
<32>*, unsigned int,
2749 const Symbol_value
<32>*,
2750 elfcpp::Elf_types
<32>::Elf_Swxword
, Arm_address
);
2752 // Scan a relocation section for stub.
2753 template<int sh_type
>
2755 scan_reloc_section_for_stubs(
2756 const Relocate_info
<32, big_endian
>* relinfo
,
2757 const unsigned char* prelocs
,
2759 Output_section
* output_section
,
2760 bool needs_special_offset_handling
,
2761 const unsigned char* view
,
2762 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
2765 // Fix .ARM.exidx section coverage.
2767 fix_exidx_coverage(Layout
*, Arm_output_section
<big_endian
>*, Symbol_table
*);
2769 // Functors for STL set.
2770 struct output_section_address_less_than
2773 operator()(const Output_section
* s1
, const Output_section
* s2
) const
2774 { return s1
->address() < s2
->address(); }
2777 // Information about this specific target which we pass to the
2778 // general Target structure.
2779 static const Target::Target_info arm_info
;
2781 // The types of GOT entries needed for this platform.
2784 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
2785 GOT_TYPE_TLS_NOFFSET
= 1, // GOT entry for negative TLS offset
2786 GOT_TYPE_TLS_OFFSET
= 2, // GOT entry for positive TLS offset
2787 GOT_TYPE_TLS_PAIR
= 3, // GOT entry for TLS module/offset pair
2788 GOT_TYPE_TLS_DESC
= 4 // GOT entry for TLS_DESC pair
2791 typedef typename
std::vector
<Stub_table
<big_endian
>*> Stub_table_list
;
2793 // Map input section to Arm_input_section.
2794 typedef Unordered_map
<Section_id
,
2795 Arm_input_section
<big_endian
>*,
2797 Arm_input_section_map
;
2799 // Map output addresses to relocs for Cortex-A8 erratum.
2800 typedef Unordered_map
<Arm_address
, const Cortex_a8_reloc
*>
2801 Cortex_a8_relocs_info
;
2804 Arm_output_data_got
<big_endian
>* got_
;
2806 Output_data_plt_arm
<big_endian
>* plt_
;
2807 // The GOT PLT section.
2808 Output_data_space
* got_plt_
;
2809 // The dynamic reloc section.
2810 Reloc_section
* rel_dyn_
;
2811 // Relocs saved to avoid a COPY reloc.
2812 Copy_relocs
<elfcpp::SHT_REL
, 32, big_endian
> copy_relocs_
;
2813 // Space for variables copied with a COPY reloc.
2814 Output_data_space
* dynbss_
;
2815 // Offset of the GOT entry for the TLS module index.
2816 unsigned int got_mod_index_offset_
;
2817 // True if the _TLS_MODULE_BASE_ symbol has been defined.
2818 bool tls_base_symbol_defined_
;
2819 // Vector of Stub_tables created.
2820 Stub_table_list stub_tables_
;
2822 const Stub_factory
&stub_factory_
;
2823 // Whether we can use BLX.
2825 // Whether we force PIC branch veneers.
2826 bool should_force_pic_veneer_
;
2827 // Map for locating Arm_input_sections.
2828 Arm_input_section_map arm_input_section_map_
;
2829 // Attributes section data in output.
2830 Attributes_section_data
* attributes_section_data_
;
2831 // Whether we want to fix code for Cortex-A8 erratum.
2832 bool fix_cortex_a8_
;
2833 // Map addresses to relocs for Cortex-A8 erratum.
2834 Cortex_a8_relocs_info cortex_a8_relocs_info_
;
2837 template<bool big_endian
>
2838 const Target::Target_info Target_arm
<big_endian
>::arm_info
=
2841 big_endian
, // is_big_endian
2842 elfcpp::EM_ARM
, // machine_code
2843 false, // has_make_symbol
2844 false, // has_resolve
2845 false, // has_code_fill
2846 true, // is_default_stack_executable
2848 "/usr/lib/libc.so.1", // dynamic_linker
2849 0x8000, // default_text_segment_address
2850 0x1000, // abi_pagesize (overridable by -z max-page-size)
2851 0x1000, // common_pagesize (overridable by -z common-page-size)
2852 elfcpp::SHN_UNDEF
, // small_common_shndx
2853 elfcpp::SHN_UNDEF
, // large_common_shndx
2854 0, // small_common_section_flags
2855 0, // large_common_section_flags
2856 ".ARM.attributes", // attributes_section
2857 "aeabi" // attributes_vendor
2860 // Arm relocate functions class
2863 template<bool big_endian
>
2864 class Arm_relocate_functions
: public Relocate_functions
<32, big_endian
>
2869 STATUS_OKAY
, // No error during relocation.
2870 STATUS_OVERFLOW
, // Relocation oveflow.
2871 STATUS_BAD_RELOC
// Relocation cannot be applied.
2875 typedef Relocate_functions
<32, big_endian
> Base
;
2876 typedef Arm_relocate_functions
<big_endian
> This
;
2878 // Encoding of imm16 argument for movt and movw ARM instructions
2881 // imm16 := imm4 | imm12
2883 // 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
2884 // +-------+---------------+-------+-------+-----------------------+
2885 // | | |imm4 | |imm12 |
2886 // +-------+---------------+-------+-------+-----------------------+
2888 // Extract the relocation addend from VAL based on the ARM
2889 // instruction encoding described above.
2890 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
2891 extract_arm_movw_movt_addend(
2892 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
)
2894 // According to the Elf ABI for ARM Architecture the immediate
2895 // field is sign-extended to form the addend.
2896 return utils::sign_extend
<16>(((val
>> 4) & 0xf000) | (val
& 0xfff));
2899 // Insert X into VAL based on the ARM instruction encoding described
2901 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
2902 insert_val_arm_movw_movt(
2903 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
,
2904 typename
elfcpp::Swap
<32, big_endian
>::Valtype x
)
2908 val
|= (x
& 0xf000) << 4;
2912 // Encoding of imm16 argument for movt and movw Thumb2 instructions
2915 // imm16 := imm4 | i | imm3 | imm8
2917 // 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
2918 // +---------+-+-----------+-------++-+-----+-------+---------------+
2919 // | |i| |imm4 || |imm3 | |imm8 |
2920 // +---------+-+-----------+-------++-+-----+-------+---------------+
2922 // Extract the relocation addend from VAL based on the Thumb2
2923 // instruction encoding described above.
2924 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
2925 extract_thumb_movw_movt_addend(
2926 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
)
2928 // According to the Elf ABI for ARM Architecture the immediate
2929 // field is sign-extended to form the addend.
2930 return utils::sign_extend
<16>(((val
>> 4) & 0xf000)
2931 | ((val
>> 15) & 0x0800)
2932 | ((val
>> 4) & 0x0700)
2936 // Insert X into VAL based on the Thumb2 instruction encoding
2938 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
2939 insert_val_thumb_movw_movt(
2940 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
,
2941 typename
elfcpp::Swap
<32, big_endian
>::Valtype x
)
2944 val
|= (x
& 0xf000) << 4;
2945 val
|= (x
& 0x0800) << 15;
2946 val
|= (x
& 0x0700) << 4;
2947 val
|= (x
& 0x00ff);
2951 // Calculate the smallest constant Kn for the specified residual.
2952 // (see (AAELF 4.6.1.4 Static ARM relocations, Group Relocations, p.32)
2954 calc_grp_kn(typename
elfcpp::Swap
<32, big_endian
>::Valtype residual
)
2960 // Determine the most significant bit in the residual and
2961 // align the resulting value to a 2-bit boundary.
2962 for (msb
= 30; (msb
>= 0) && !(residual
& (3 << msb
)); msb
-= 2)
2964 // The desired shift is now (msb - 6), or zero, whichever
2966 return (((msb
- 6) < 0) ? 0 : (msb
- 6));
2969 // Calculate the final residual for the specified group index.
2970 // If the passed group index is less than zero, the method will return
2971 // the value of the specified residual without any change.
2972 // (see (AAELF 4.6.1.4 Static ARM relocations, Group Relocations, p.32)
2973 static typename
elfcpp::Swap
<32, big_endian
>::Valtype
2974 calc_grp_residual(typename
elfcpp::Swap
<32, big_endian
>::Valtype residual
,
2977 for (int n
= 0; n
<= group
; n
++)
2979 // Calculate which part of the value to mask.
2980 uint32_t shift
= calc_grp_kn(residual
);
2981 // Calculate the residual for the next time around.
2982 residual
&= ~(residual
& (0xff << shift
));
2988 // Calculate the value of Gn for the specified group index.
2989 // We return it in the form of an encoded constant-and-rotation.
2990 // (see (AAELF 4.6.1.4 Static ARM relocations, Group Relocations, p.32)
2991 static typename
elfcpp::Swap
<32, big_endian
>::Valtype
2992 calc_grp_gn(typename
elfcpp::Swap
<32, big_endian
>::Valtype residual
,
2995 typename
elfcpp::Swap
<32, big_endian
>::Valtype gn
= 0;
2998 for (int n
= 0; n
<= group
; n
++)
3000 // Calculate which part of the value to mask.
3001 shift
= calc_grp_kn(residual
);
3002 // Calculate Gn in 32-bit as well as encoded constant-and-rotation form.
3003 gn
= residual
& (0xff << shift
);
3004 // Calculate the residual for the next time around.
3007 // Return Gn in the form of an encoded constant-and-rotation.
3008 return ((gn
>> shift
) | ((gn
<= 0xff ? 0 : (32 - shift
) / 2) << 8));
3012 // Handle ARM long branches.
3013 static typename
This::Status
3014 arm_branch_common(unsigned int, const Relocate_info
<32, big_endian
>*,
3015 unsigned char *, const Sized_symbol
<32>*,
3016 const Arm_relobj
<big_endian
>*, unsigned int,
3017 const Symbol_value
<32>*, Arm_address
, Arm_address
, bool);
3019 // Handle THUMB long branches.
3020 static typename
This::Status
3021 thumb_branch_common(unsigned int, const Relocate_info
<32, big_endian
>*,
3022 unsigned char *, const Sized_symbol
<32>*,
3023 const Arm_relobj
<big_endian
>*, unsigned int,
3024 const Symbol_value
<32>*, Arm_address
, Arm_address
, bool);
3027 // Return the branch offset of a 32-bit THUMB branch.
3028 static inline int32_t
3029 thumb32_branch_offset(uint16_t upper_insn
, uint16_t lower_insn
)
3031 // We use the Thumb-2 encoding (backwards compatible with Thumb-1)
3032 // involving the J1 and J2 bits.
3033 uint32_t s
= (upper_insn
& (1U << 10)) >> 10;
3034 uint32_t upper
= upper_insn
& 0x3ffU
;
3035 uint32_t lower
= lower_insn
& 0x7ffU
;
3036 uint32_t j1
= (lower_insn
& (1U << 13)) >> 13;
3037 uint32_t j2
= (lower_insn
& (1U << 11)) >> 11;
3038 uint32_t i1
= j1
^ s
? 0 : 1;
3039 uint32_t i2
= j2
^ s
? 0 : 1;
3041 return utils::sign_extend
<25>((s
<< 24) | (i1
<< 23) | (i2
<< 22)
3042 | (upper
<< 12) | (lower
<< 1));
3045 // Insert OFFSET to a 32-bit THUMB branch and return the upper instruction.
3046 // UPPER_INSN is the original upper instruction of the branch. Caller is
3047 // responsible for overflow checking and BLX offset adjustment.
3048 static inline uint16_t
3049 thumb32_branch_upper(uint16_t upper_insn
, int32_t offset
)
3051 uint32_t s
= offset
< 0 ? 1 : 0;
3052 uint32_t bits
= static_cast<uint32_t>(offset
);
3053 return (upper_insn
& ~0x7ffU
) | ((bits
>> 12) & 0x3ffU
) | (s
<< 10);
3056 // Insert OFFSET to a 32-bit THUMB branch and return the lower instruction.
3057 // LOWER_INSN is the original lower instruction of the branch. Caller is
3058 // responsible for overflow checking and BLX offset adjustment.
3059 static inline uint16_t
3060 thumb32_branch_lower(uint16_t lower_insn
, int32_t offset
)
3062 uint32_t s
= offset
< 0 ? 1 : 0;
3063 uint32_t bits
= static_cast<uint32_t>(offset
);
3064 return ((lower_insn
& ~0x2fffU
)
3065 | ((((bits
>> 23) & 1) ^ !s
) << 13)
3066 | ((((bits
>> 22) & 1) ^ !s
) << 11)
3067 | ((bits
>> 1) & 0x7ffU
));
3070 // Return the branch offset of a 32-bit THUMB conditional branch.
3071 static inline int32_t
3072 thumb32_cond_branch_offset(uint16_t upper_insn
, uint16_t lower_insn
)
3074 uint32_t s
= (upper_insn
& 0x0400U
) >> 10;
3075 uint32_t j1
= (lower_insn
& 0x2000U
) >> 13;
3076 uint32_t j2
= (lower_insn
& 0x0800U
) >> 11;
3077 uint32_t lower
= (lower_insn
& 0x07ffU
);
3078 uint32_t upper
= (s
<< 8) | (j2
<< 7) | (j1
<< 6) | (upper_insn
& 0x003fU
);
3080 return utils::sign_extend
<21>((upper
<< 12) | (lower
<< 1));
3083 // Insert OFFSET to a 32-bit THUMB conditional branch and return the upper
3084 // instruction. UPPER_INSN is the original upper instruction of the branch.
3085 // Caller is responsible for overflow checking.
3086 static inline uint16_t
3087 thumb32_cond_branch_upper(uint16_t upper_insn
, int32_t offset
)
3089 uint32_t s
= offset
< 0 ? 1 : 0;
3090 uint32_t bits
= static_cast<uint32_t>(offset
);
3091 return (upper_insn
& 0xfbc0U
) | (s
<< 10) | ((bits
& 0x0003f000U
) >> 12);
3094 // Insert OFFSET to a 32-bit THUMB conditional branch and return the lower
3095 // instruction. LOWER_INSN is the original lower instruction of the branch.
3096 // Caller is reponsible for overflow checking.
3097 static inline uint16_t
3098 thumb32_cond_branch_lower(uint16_t lower_insn
, int32_t offset
)
3100 uint32_t bits
= static_cast<uint32_t>(offset
);
3101 uint32_t j2
= (bits
& 0x00080000U
) >> 19;
3102 uint32_t j1
= (bits
& 0x00040000U
) >> 18;
3103 uint32_t lo
= (bits
& 0x00000ffeU
) >> 1;
3105 return (lower_insn
& 0xd000U
) | (j1
<< 13) | (j2
<< 11) | lo
;
3108 // R_ARM_ABS8: S + A
3109 static inline typename
This::Status
3110 abs8(unsigned char *view
,
3111 const Sized_relobj
<32, big_endian
>* object
,
3112 const Symbol_value
<32>* psymval
)
3114 typedef typename
elfcpp::Swap
<8, big_endian
>::Valtype Valtype
;
3115 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
3116 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3117 Valtype val
= elfcpp::Swap
<8, big_endian
>::readval(wv
);
3118 Reltype addend
= utils::sign_extend
<8>(val
);
3119 Reltype x
= psymval
->value(object
, addend
);
3120 val
= utils::bit_select(val
, x
, 0xffU
);
3121 elfcpp::Swap
<8, big_endian
>::writeval(wv
, val
);
3123 // R_ARM_ABS8 permits signed or unsigned results.
3124 int signed_x
= static_cast<int32_t>(x
);
3125 return ((signed_x
< -128 || signed_x
> 255)
3126 ? This::STATUS_OVERFLOW
3127 : This::STATUS_OKAY
);
3130 // R_ARM_THM_ABS5: S + A
3131 static inline typename
This::Status
3132 thm_abs5(unsigned char *view
,
3133 const Sized_relobj
<32, big_endian
>* object
,
3134 const Symbol_value
<32>* psymval
)
3136 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
3137 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
3138 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3139 Valtype val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
3140 Reltype addend
= (val
& 0x7e0U
) >> 6;
3141 Reltype x
= psymval
->value(object
, addend
);
3142 val
= utils::bit_select(val
, x
<< 6, 0x7e0U
);
3143 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
3145 // R_ARM_ABS16 permits signed or unsigned results.
3146 int signed_x
= static_cast<int32_t>(x
);
3147 return ((signed_x
< -32768 || signed_x
> 65535)
3148 ? This::STATUS_OVERFLOW
3149 : This::STATUS_OKAY
);
3152 // R_ARM_ABS12: S + A
3153 static inline typename
This::Status
3154 abs12(unsigned char *view
,
3155 const Sized_relobj
<32, big_endian
>* object
,
3156 const Symbol_value
<32>* psymval
)
3158 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3159 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
3160 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3161 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3162 Reltype addend
= val
& 0x0fffU
;
3163 Reltype x
= psymval
->value(object
, addend
);
3164 val
= utils::bit_select(val
, x
, 0x0fffU
);
3165 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
3166 return (utils::has_overflow
<12>(x
)
3167 ? This::STATUS_OVERFLOW
3168 : This::STATUS_OKAY
);
3171 // R_ARM_ABS16: S + A
3172 static inline typename
This::Status
3173 abs16(unsigned char *view
,
3174 const Sized_relobj
<32, big_endian
>* object
,
3175 const Symbol_value
<32>* psymval
)
3177 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
3178 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
3179 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3180 Valtype val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
3181 Reltype addend
= utils::sign_extend
<16>(val
);
3182 Reltype x
= psymval
->value(object
, addend
);
3183 val
= utils::bit_select(val
, x
, 0xffffU
);
3184 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
3185 return (utils::has_signed_unsigned_overflow
<16>(x
)
3186 ? This::STATUS_OVERFLOW
3187 : This::STATUS_OKAY
);
3190 // R_ARM_ABS32: (S + A) | T
3191 static inline typename
This::Status
3192 abs32(unsigned char *view
,
3193 const Sized_relobj
<32, big_endian
>* object
,
3194 const Symbol_value
<32>* psymval
,
3195 Arm_address thumb_bit
)
3197 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3198 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3199 Valtype addend
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3200 Valtype x
= psymval
->value(object
, addend
) | thumb_bit
;
3201 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
3202 return This::STATUS_OKAY
;
3205 // R_ARM_REL32: (S + A) | T - P
3206 static inline typename
This::Status
3207 rel32(unsigned char *view
,
3208 const Sized_relobj
<32, big_endian
>* object
,
3209 const Symbol_value
<32>* psymval
,
3210 Arm_address address
,
3211 Arm_address thumb_bit
)
3213 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3214 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3215 Valtype addend
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3216 Valtype x
= (psymval
->value(object
, addend
) | thumb_bit
) - address
;
3217 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
3218 return This::STATUS_OKAY
;
3221 // R_ARM_THM_JUMP24: (S + A) | T - P
3222 static typename
This::Status
3223 thm_jump19(unsigned char *view
, const Arm_relobj
<big_endian
>* object
,
3224 const Symbol_value
<32>* psymval
, Arm_address address
,
3225 Arm_address thumb_bit
);
3227 // R_ARM_THM_JUMP6: S + A – P
3228 static inline typename
This::Status
3229 thm_jump6(unsigned char *view
,
3230 const Sized_relobj
<32, big_endian
>* object
,
3231 const Symbol_value
<32>* psymval
,
3232 Arm_address address
)
3234 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
3235 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Reltype
;
3236 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3237 Valtype val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
3238 // bit[9]:bit[7:3]:’0’ (mask: 0x02f8)
3239 Reltype addend
= (((val
& 0x0200) >> 3) | ((val
& 0x00f8) >> 2));
3240 Reltype x
= (psymval
->value(object
, addend
) - address
);
3241 val
= (val
& 0xfd07) | ((x
& 0x0040) << 3) | ((val
& 0x003e) << 2);
3242 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
3243 // CZB does only forward jumps.
3244 return ((x
> 0x007e)
3245 ? This::STATUS_OVERFLOW
3246 : This::STATUS_OKAY
);
3249 // R_ARM_THM_JUMP8: S + A – P
3250 static inline typename
This::Status
3251 thm_jump8(unsigned char *view
,
3252 const Sized_relobj
<32, big_endian
>* object
,
3253 const Symbol_value
<32>* psymval
,
3254 Arm_address address
)
3256 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
3257 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Reltype
;
3258 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3259 Valtype val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
3260 Reltype addend
= utils::sign_extend
<8>((val
& 0x00ff) << 1);
3261 Reltype x
= (psymval
->value(object
, addend
) - address
);
3262 elfcpp::Swap
<16, big_endian
>::writeval(wv
, (val
& 0xff00) | ((x
& 0x01fe) >> 1));
3263 return (utils::has_overflow
<8>(x
)
3264 ? This::STATUS_OVERFLOW
3265 : This::STATUS_OKAY
);
3268 // R_ARM_THM_JUMP11: S + A – P
3269 static inline typename
This::Status
3270 thm_jump11(unsigned char *view
,
3271 const Sized_relobj
<32, big_endian
>* object
,
3272 const Symbol_value
<32>* psymval
,
3273 Arm_address address
)
3275 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
3276 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Reltype
;
3277 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3278 Valtype val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
3279 Reltype addend
= utils::sign_extend
<11>((val
& 0x07ff) << 1);
3280 Reltype x
= (psymval
->value(object
, addend
) - address
);
3281 elfcpp::Swap
<16, big_endian
>::writeval(wv
, (val
& 0xf800) | ((x
& 0x0ffe) >> 1));
3282 return (utils::has_overflow
<11>(x
)
3283 ? This::STATUS_OVERFLOW
3284 : This::STATUS_OKAY
);
3287 // R_ARM_BASE_PREL: B(S) + A - P
3288 static inline typename
This::Status
3289 base_prel(unsigned char* view
,
3291 Arm_address address
)
3293 Base::rel32(view
, origin
- address
);
3297 // R_ARM_BASE_ABS: B(S) + A
3298 static inline typename
This::Status
3299 base_abs(unsigned char* view
,
3302 Base::rel32(view
, origin
);
3306 // R_ARM_GOT_BREL: GOT(S) + A - GOT_ORG
3307 static inline typename
This::Status
3308 got_brel(unsigned char* view
,
3309 typename
elfcpp::Swap
<32, big_endian
>::Valtype got_offset
)
3311 Base::rel32(view
, got_offset
);
3312 return This::STATUS_OKAY
;
3315 // R_ARM_GOT_PREL: GOT(S) + A - P
3316 static inline typename
This::Status
3317 got_prel(unsigned char *view
,
3318 Arm_address got_entry
,
3319 Arm_address address
)
3321 Base::rel32(view
, got_entry
- address
);
3322 return This::STATUS_OKAY
;
3325 // R_ARM_PREL: (S + A) | T - P
3326 static inline typename
This::Status
3327 prel31(unsigned char *view
,
3328 const Sized_relobj
<32, big_endian
>* object
,
3329 const Symbol_value
<32>* psymval
,
3330 Arm_address address
,
3331 Arm_address thumb_bit
)
3333 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3334 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3335 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3336 Valtype addend
= utils::sign_extend
<31>(val
);
3337 Valtype x
= (psymval
->value(object
, addend
) | thumb_bit
) - address
;
3338 val
= utils::bit_select(val
, x
, 0x7fffffffU
);
3339 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
3340 return (utils::has_overflow
<31>(x
) ?
3341 This::STATUS_OVERFLOW
: This::STATUS_OKAY
);
3344 // R_ARM_MOVW_ABS_NC: (S + A) | T (relative address base is )
3345 // R_ARM_MOVW_PREL_NC: (S + A) | T - P
3346 // R_ARM_MOVW_BREL_NC: ((S + A) | T) - B(S)
3347 // R_ARM_MOVW_BREL: ((S + A) | T) - B(S)
3348 static inline typename
This::Status
3349 movw(unsigned char* view
,
3350 const Sized_relobj
<32, big_endian
>* object
,
3351 const Symbol_value
<32>* psymval
,
3352 Arm_address relative_address_base
,
3353 Arm_address thumb_bit
,
3354 bool check_overflow
)
3356 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3357 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3358 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3359 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
3360 Valtype x
= ((psymval
->value(object
, addend
) | thumb_bit
)
3361 - relative_address_base
);
3362 val
= This::insert_val_arm_movw_movt(val
, x
);
3363 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
3364 return ((check_overflow
&& utils::has_overflow
<16>(x
))
3365 ? This::STATUS_OVERFLOW
3366 : This::STATUS_OKAY
);
3369 // R_ARM_MOVT_ABS: S + A (relative address base is 0)
3370 // R_ARM_MOVT_PREL: S + A - P
3371 // R_ARM_MOVT_BREL: S + A - B(S)
3372 static inline typename
This::Status
3373 movt(unsigned char* view
,
3374 const Sized_relobj
<32, big_endian
>* object
,
3375 const Symbol_value
<32>* psymval
,
3376 Arm_address relative_address_base
)
3378 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3379 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3380 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3381 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
3382 Valtype x
= (psymval
->value(object
, addend
) - relative_address_base
) >> 16;
3383 val
= This::insert_val_arm_movw_movt(val
, x
);
3384 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
3385 // FIXME: IHI0044D says that we should check for overflow.
3386 return This::STATUS_OKAY
;
3389 // R_ARM_THM_MOVW_ABS_NC: S + A | T (relative_address_base is 0)
3390 // R_ARM_THM_MOVW_PREL_NC: (S + A) | T - P
3391 // R_ARM_THM_MOVW_BREL_NC: ((S + A) | T) - B(S)
3392 // R_ARM_THM_MOVW_BREL: ((S + A) | T) - B(S)
3393 static inline typename
This::Status
3394 thm_movw(unsigned char *view
,
3395 const Sized_relobj
<32, big_endian
>* object
,
3396 const Symbol_value
<32>* psymval
,
3397 Arm_address relative_address_base
,
3398 Arm_address thumb_bit
,
3399 bool check_overflow
)
3401 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
3402 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
3403 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3404 Reltype val
= (elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
3405 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
3406 Reltype addend
= This::extract_thumb_movw_movt_addend(val
);
3408 (psymval
->value(object
, addend
) | thumb_bit
) - relative_address_base
;
3409 val
= This::insert_val_thumb_movw_movt(val
, x
);
3410 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
3411 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
3412 return ((check_overflow
&& utils::has_overflow
<16>(x
))
3413 ? This::STATUS_OVERFLOW
3414 : This::STATUS_OKAY
);
3417 // R_ARM_THM_MOVT_ABS: S + A (relative address base is 0)
3418 // R_ARM_THM_MOVT_PREL: S + A - P
3419 // R_ARM_THM_MOVT_BREL: S + A - B(S)
3420 static inline typename
This::Status
3421 thm_movt(unsigned char* view
,
3422 const Sized_relobj
<32, big_endian
>* object
,
3423 const Symbol_value
<32>* psymval
,
3424 Arm_address relative_address_base
)
3426 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
3427 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
3428 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3429 Reltype val
= (elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
3430 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
3431 Reltype addend
= This::extract_thumb_movw_movt_addend(val
);
3432 Reltype x
= (psymval
->value(object
, addend
) - relative_address_base
) >> 16;
3433 val
= This::insert_val_thumb_movw_movt(val
, x
);
3434 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
3435 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
3436 return This::STATUS_OKAY
;
3439 // R_ARM_THM_ALU_PREL_11_0: ((S + A) | T) - Pa (Thumb32)
3440 static inline typename
This::Status
3441 thm_alu11(unsigned char* view
,
3442 const Sized_relobj
<32, big_endian
>* object
,
3443 const Symbol_value
<32>* psymval
,
3444 Arm_address address
,
3445 Arm_address thumb_bit
)
3447 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
3448 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
3449 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3450 Reltype insn
= (elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
3451 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
3453 // 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
3454 // -----------------------------------------------------------------------
3455 // ADD{S} 1 1 1 1 0|i|0|1 0 0 0|S|1 1 0 1||0|imm3 |Rd |imm8
3456 // ADDW 1 1 1 1 0|i|1|0 0 0 0|0|1 1 0 1||0|imm3 |Rd |imm8
3457 // ADR[+] 1 1 1 1 0|i|1|0 0 0 0|0|1 1 1 1||0|imm3 |Rd |imm8
3458 // SUB{S} 1 1 1 1 0|i|0|1 1 0 1|S|1 1 0 1||0|imm3 |Rd |imm8
3459 // SUBW 1 1 1 1 0|i|1|0 1 0 1|0|1 1 0 1||0|imm3 |Rd |imm8
3460 // ADR[-] 1 1 1 1 0|i|1|0 1 0 1|0|1 1 1 1||0|imm3 |Rd |imm8
3462 // Determine a sign for the addend.
3463 const int sign
= ((insn
& 0xf8ef0000) == 0xf0ad0000
3464 || (insn
& 0xf8ef0000) == 0xf0af0000) ? -1 : 1;
3465 // Thumb2 addend encoding:
3466 // imm12 := i | imm3 | imm8
3467 int32_t addend
= (insn
& 0xff)
3468 | ((insn
& 0x00007000) >> 4)
3469 | ((insn
& 0x04000000) >> 15);
3470 // Apply a sign to the added.
3473 int32_t x
= (psymval
->value(object
, addend
) | thumb_bit
)
3474 - (address
& 0xfffffffc);
3475 Reltype val
= abs(x
);
3476 // Mask out the value and a distinct part of the ADD/SUB opcode
3477 // (bits 7:5 of opword).
3478 insn
= (insn
& 0xfb0f8f00)
3480 | ((val
& 0x700) << 4)
3481 | ((val
& 0x800) << 15);
3482 // Set the opcode according to whether the value to go in the
3483 // place is negative.
3487 elfcpp::Swap
<16, big_endian
>::writeval(wv
, insn
>> 16);
3488 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, insn
& 0xffff);
3489 return ((val
> 0xfff) ?
3490 This::STATUS_OVERFLOW
: This::STATUS_OKAY
);
3493 // R_ARM_THM_PC8: S + A - Pa (Thumb)
3494 static inline typename
This::Status
3495 thm_pc8(unsigned char* view
,
3496 const Sized_relobj
<32, big_endian
>* object
,
3497 const Symbol_value
<32>* psymval
,
3498 Arm_address address
)
3500 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
3501 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Reltype
;
3502 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3503 Valtype insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
3504 Reltype addend
= ((insn
& 0x00ff) << 2);
3505 int32_t x
= (psymval
->value(object
, addend
) - (address
& 0xfffffffc));
3506 Reltype val
= abs(x
);
3507 insn
= (insn
& 0xff00) | ((val
& 0x03fc) >> 2);
3509 elfcpp::Swap
<16, big_endian
>::writeval(wv
, insn
);
3510 return ((val
> 0x03fc)
3511 ? This::STATUS_OVERFLOW
3512 : This::STATUS_OKAY
);
3515 // R_ARM_THM_PC12: S + A - Pa (Thumb32)
3516 static inline typename
This::Status
3517 thm_pc12(unsigned char* view
,
3518 const Sized_relobj
<32, big_endian
>* object
,
3519 const Symbol_value
<32>* psymval
,
3520 Arm_address address
)
3522 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
3523 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
3524 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3525 Reltype insn
= (elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
3526 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
3527 // Determine a sign for the addend (positive if the U bit is 1).
3528 const int sign
= (insn
& 0x00800000) ? 1 : -1;
3529 int32_t addend
= (insn
& 0xfff);
3530 // Apply a sign to the added.
3533 int32_t x
= (psymval
->value(object
, addend
) - (address
& 0xfffffffc));
3534 Reltype val
= abs(x
);
3535 // Mask out and apply the value and the U bit.
3536 insn
= (insn
& 0xff7ff000) | (val
& 0xfff);
3537 // Set the U bit according to whether the value to go in the
3538 // place is positive.
3542 elfcpp::Swap
<16, big_endian
>::writeval(wv
, insn
>> 16);
3543 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, insn
& 0xffff);
3544 return ((val
> 0xfff) ?
3545 This::STATUS_OVERFLOW
: This::STATUS_OKAY
);
3549 static inline typename
This::Status
3550 v4bx(const Relocate_info
<32, big_endian
>* relinfo
,
3551 unsigned char *view
,
3552 const Arm_relobj
<big_endian
>* object
,
3553 const Arm_address address
,
3554 const bool is_interworking
)
3557 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3558 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3559 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3561 // Ensure that we have a BX instruction.
3562 gold_assert((val
& 0x0ffffff0) == 0x012fff10);
3563 const uint32_t reg
= (val
& 0xf);
3564 if (is_interworking
&& reg
!= 0xf)
3566 Stub_table
<big_endian
>* stub_table
=
3567 object
->stub_table(relinfo
->data_shndx
);
3568 gold_assert(stub_table
!= NULL
);
3570 Arm_v4bx_stub
* stub
= stub_table
->find_arm_v4bx_stub(reg
);
3571 gold_assert(stub
!= NULL
);
3573 int32_t veneer_address
=
3574 stub_table
->address() + stub
->offset() - 8 - address
;
3575 gold_assert((veneer_address
<= ARM_MAX_FWD_BRANCH_OFFSET
)
3576 && (veneer_address
>= ARM_MAX_BWD_BRANCH_OFFSET
));
3577 // Replace with a branch to veneer (B <addr>)
3578 val
= (val
& 0xf0000000) | 0x0a000000
3579 | ((veneer_address
>> 2) & 0x00ffffff);
3583 // Preserve Rm (lowest four bits) and the condition code
3584 // (highest four bits). Other bits encode MOV PC,Rm.
3585 val
= (val
& 0xf000000f) | 0x01a0f000;
3587 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
3588 return This::STATUS_OKAY
;
3591 // R_ARM_ALU_PC_G0_NC: ((S + A) | T) - P
3592 // R_ARM_ALU_PC_G0: ((S + A) | T) - P
3593 // R_ARM_ALU_PC_G1_NC: ((S + A) | T) - P
3594 // R_ARM_ALU_PC_G1: ((S + A) | T) - P
3595 // R_ARM_ALU_PC_G2: ((S + A) | T) - P
3596 // R_ARM_ALU_SB_G0_NC: ((S + A) | T) - B(S)
3597 // R_ARM_ALU_SB_G0: ((S + A) | T) - B(S)
3598 // R_ARM_ALU_SB_G1_NC: ((S + A) | T) - B(S)
3599 // R_ARM_ALU_SB_G1: ((S + A) | T) - B(S)
3600 // R_ARM_ALU_SB_G2: ((S + A) | T) - B(S)
3601 static inline typename
This::Status
3602 arm_grp_alu(unsigned char* view
,
3603 const Sized_relobj
<32, big_endian
>* object
,
3604 const Symbol_value
<32>* psymval
,
3606 Arm_address address
,
3607 Arm_address thumb_bit
,
3608 bool check_overflow
)
3610 gold_assert(group
>= 0 && group
< 3);
3611 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3612 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3613 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3615 // ALU group relocations are allowed only for the ADD/SUB instructions.
3616 // (0x00800000 - ADD, 0x00400000 - SUB)
3617 const Valtype opcode
= insn
& 0x01e00000;
3618 if (opcode
!= 0x00800000 && opcode
!= 0x00400000)
3619 return This::STATUS_BAD_RELOC
;
3621 // Determine a sign for the addend.
3622 const int sign
= (opcode
== 0x00800000) ? 1 : -1;
3623 // shifter = rotate_imm * 2
3624 const uint32_t shifter
= (insn
& 0xf00) >> 7;
3625 // Initial addend value.
3626 int32_t addend
= insn
& 0xff;
3627 // Rotate addend right by shifter.
3628 addend
= (addend
>> shifter
) | (addend
<< (32 - shifter
));
3629 // Apply a sign to the added.
3632 int32_t x
= ((psymval
->value(object
, addend
) | thumb_bit
) - address
);
3633 Valtype gn
= Arm_relocate_functions::calc_grp_gn(abs(x
), group
);
3634 // Check for overflow if required
3636 && (Arm_relocate_functions::calc_grp_residual(abs(x
), group
) != 0))
3637 return This::STATUS_OVERFLOW
;
3639 // Mask out the value and the ADD/SUB part of the opcode; take care
3640 // not to destroy the S bit.
3642 // Set the opcode according to whether the value to go in the
3643 // place is negative.
3644 insn
|= ((x
< 0) ? 0x00400000 : 0x00800000);
3645 // Encode the offset (encoded Gn).
3648 elfcpp::Swap
<32, big_endian
>::writeval(wv
, insn
);
3649 return This::STATUS_OKAY
;
3652 // R_ARM_LDR_PC_G0: S + A - P
3653 // R_ARM_LDR_PC_G1: S + A - P
3654 // R_ARM_LDR_PC_G2: S + A - P
3655 // R_ARM_LDR_SB_G0: S + A - B(S)
3656 // R_ARM_LDR_SB_G1: S + A - B(S)
3657 // R_ARM_LDR_SB_G2: S + A - B(S)
3658 static inline typename
This::Status
3659 arm_grp_ldr(unsigned char* view
,
3660 const Sized_relobj
<32, big_endian
>* object
,
3661 const Symbol_value
<32>* psymval
,
3663 Arm_address address
)
3665 gold_assert(group
>= 0 && group
< 3);
3666 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3667 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3668 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3670 const int sign
= (insn
& 0x00800000) ? 1 : -1;
3671 int32_t addend
= (insn
& 0xfff) * sign
;
3672 int32_t x
= (psymval
->value(object
, addend
) - address
);
3673 // Calculate the relevant G(n-1) value to obtain this stage residual.
3675 Arm_relocate_functions::calc_grp_residual(abs(x
), group
- 1);
3676 if (residual
>= 0x1000)
3677 return This::STATUS_OVERFLOW
;
3679 // Mask out the value and U bit.
3681 // Set the U bit for non-negative values.
3686 elfcpp::Swap
<32, big_endian
>::writeval(wv
, insn
);
3687 return This::STATUS_OKAY
;
3690 // R_ARM_LDRS_PC_G0: S + A - P
3691 // R_ARM_LDRS_PC_G1: S + A - P
3692 // R_ARM_LDRS_PC_G2: S + A - P
3693 // R_ARM_LDRS_SB_G0: S + A - B(S)
3694 // R_ARM_LDRS_SB_G1: S + A - B(S)
3695 // R_ARM_LDRS_SB_G2: S + A - B(S)
3696 static inline typename
This::Status
3697 arm_grp_ldrs(unsigned char* view
,
3698 const Sized_relobj
<32, big_endian
>* object
,
3699 const Symbol_value
<32>* psymval
,
3701 Arm_address address
)
3703 gold_assert(group
>= 0 && group
< 3);
3704 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3705 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3706 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3708 const int sign
= (insn
& 0x00800000) ? 1 : -1;
3709 int32_t addend
= (((insn
& 0xf00) >> 4) + (insn
& 0xf)) * sign
;
3710 int32_t x
= (psymval
->value(object
, addend
) - address
);
3711 // Calculate the relevant G(n-1) value to obtain this stage residual.
3713 Arm_relocate_functions::calc_grp_residual(abs(x
), group
- 1);
3714 if (residual
>= 0x100)
3715 return This::STATUS_OVERFLOW
;
3717 // Mask out the value and U bit.
3719 // Set the U bit for non-negative values.
3722 insn
|= ((residual
& 0xf0) << 4) | (residual
& 0xf);
3724 elfcpp::Swap
<32, big_endian
>::writeval(wv
, insn
);
3725 return This::STATUS_OKAY
;
3728 // R_ARM_LDC_PC_G0: S + A - P
3729 // R_ARM_LDC_PC_G1: S + A - P
3730 // R_ARM_LDC_PC_G2: S + A - P
3731 // R_ARM_LDC_SB_G0: S + A - B(S)
3732 // R_ARM_LDC_SB_G1: S + A - B(S)
3733 // R_ARM_LDC_SB_G2: S + A - B(S)
3734 static inline typename
This::Status
3735 arm_grp_ldc(unsigned char* view
,
3736 const Sized_relobj
<32, big_endian
>* object
,
3737 const Symbol_value
<32>* psymval
,
3739 Arm_address address
)
3741 gold_assert(group
>= 0 && group
< 3);
3742 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3743 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3744 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3746 const int sign
= (insn
& 0x00800000) ? 1 : -1;
3747 int32_t addend
= ((insn
& 0xff) << 2) * sign
;
3748 int32_t x
= (psymval
->value(object
, addend
) - address
);
3749 // Calculate the relevant G(n-1) value to obtain this stage residual.
3751 Arm_relocate_functions::calc_grp_residual(abs(x
), group
- 1);
3752 if ((residual
& 0x3) != 0 || residual
>= 0x400)
3753 return This::STATUS_OVERFLOW
;
3755 // Mask out the value and U bit.
3757 // Set the U bit for non-negative values.
3760 insn
|= (residual
>> 2);
3762 elfcpp::Swap
<32, big_endian
>::writeval(wv
, insn
);
3763 return This::STATUS_OKAY
;
3767 // Relocate ARM long branches. This handles relocation types
3768 // R_ARM_CALL, R_ARM_JUMP24, R_ARM_PLT32 and R_ARM_XPC25.
3769 // If IS_WEAK_UNDEFINED_WITH_PLT is true. The target symbol is weakly
3770 // undefined and we do not use PLT in this relocation. In such a case,
3771 // the branch is converted into an NOP.
3773 template<bool big_endian
>
3774 typename Arm_relocate_functions
<big_endian
>::Status
3775 Arm_relocate_functions
<big_endian
>::arm_branch_common(
3776 unsigned int r_type
,
3777 const Relocate_info
<32, big_endian
>* relinfo
,
3778 unsigned char *view
,
3779 const Sized_symbol
<32>* gsym
,
3780 const Arm_relobj
<big_endian
>* object
,
3782 const Symbol_value
<32>* psymval
,
3783 Arm_address address
,
3784 Arm_address thumb_bit
,
3785 bool is_weakly_undefined_without_plt
)
3787 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3788 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3789 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3791 bool insn_is_b
= (((val
>> 28) & 0xf) <= 0xe)
3792 && ((val
& 0x0f000000UL
) == 0x0a000000UL
);
3793 bool insn_is_uncond_bl
= (val
& 0xff000000UL
) == 0xeb000000UL
;
3794 bool insn_is_cond_bl
= (((val
>> 28) & 0xf) < 0xe)
3795 && ((val
& 0x0f000000UL
) == 0x0b000000UL
);
3796 bool insn_is_blx
= (val
& 0xfe000000UL
) == 0xfa000000UL
;
3797 bool insn_is_any_branch
= (val
& 0x0e000000UL
) == 0x0a000000UL
;
3799 // Check that the instruction is valid.
3800 if (r_type
== elfcpp::R_ARM_CALL
)
3802 if (!insn_is_uncond_bl
&& !insn_is_blx
)
3803 return This::STATUS_BAD_RELOC
;
3805 else if (r_type
== elfcpp::R_ARM_JUMP24
)
3807 if (!insn_is_b
&& !insn_is_cond_bl
)
3808 return This::STATUS_BAD_RELOC
;
3810 else if (r_type
== elfcpp::R_ARM_PLT32
)
3812 if (!insn_is_any_branch
)
3813 return This::STATUS_BAD_RELOC
;
3815 else if (r_type
== elfcpp::R_ARM_XPC25
)
3817 // FIXME: AAELF document IH0044C does not say much about it other
3818 // than it being obsolete.
3819 if (!insn_is_any_branch
)
3820 return This::STATUS_BAD_RELOC
;
3825 // A branch to an undefined weak symbol is turned into a jump to
3826 // the next instruction unless a PLT entry will be created.
3827 // Do the same for local undefined symbols.
3828 // The jump to the next instruction is optimized as a NOP depending
3829 // on the architecture.
3830 const Target_arm
<big_endian
>* arm_target
=
3831 Target_arm
<big_endian
>::default_target();
3832 if (is_weakly_undefined_without_plt
)
3834 gold_assert(!parameters
->options().relocatable());
3835 Valtype cond
= val
& 0xf0000000U
;
3836 if (arm_target
->may_use_arm_nop())
3837 val
= cond
| 0x0320f000;
3839 val
= cond
| 0x01a00000; // Using pre-UAL nop: mov r0, r0.
3840 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
3841 return This::STATUS_OKAY
;
3844 Valtype addend
= utils::sign_extend
<26>(val
<< 2);
3845 Valtype branch_target
= psymval
->value(object
, addend
);
3846 int32_t branch_offset
= branch_target
- address
;
3848 // We need a stub if the branch offset is too large or if we need
3850 bool may_use_blx
= arm_target
->may_use_blx();
3851 Reloc_stub
* stub
= NULL
;
3853 if (!parameters
->options().relocatable()
3854 && (utils::has_overflow
<26>(branch_offset
)
3855 || ((thumb_bit
!= 0)
3856 && !(may_use_blx
&& r_type
== elfcpp::R_ARM_CALL
))))
3858 Valtype unadjusted_branch_target
= psymval
->value(object
, 0);
3860 Stub_type stub_type
=
3861 Reloc_stub::stub_type_for_reloc(r_type
, address
,
3862 unadjusted_branch_target
,
3864 if (stub_type
!= arm_stub_none
)
3866 Stub_table
<big_endian
>* stub_table
=
3867 object
->stub_table(relinfo
->data_shndx
);
3868 gold_assert(stub_table
!= NULL
);
3870 Reloc_stub::Key
stub_key(stub_type
, gsym
, object
, r_sym
, addend
);
3871 stub
= stub_table
->find_reloc_stub(stub_key
);
3872 gold_assert(stub
!= NULL
);
3873 thumb_bit
= stub
->stub_template()->entry_in_thumb_mode() ? 1 : 0;
3874 branch_target
= stub_table
->address() + stub
->offset() + addend
;
3875 branch_offset
= branch_target
- address
;
3876 gold_assert(!utils::has_overflow
<26>(branch_offset
));
3880 // At this point, if we still need to switch mode, the instruction
3881 // must either be a BLX or a BL that can be converted to a BLX.
3885 gold_assert(may_use_blx
&& r_type
== elfcpp::R_ARM_CALL
);
3886 val
= (val
& 0xffffff) | 0xfa000000 | ((branch_offset
& 2) << 23);
3889 val
= utils::bit_select(val
, (branch_offset
>> 2), 0xffffffUL
);
3890 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
3891 return (utils::has_overflow
<26>(branch_offset
)
3892 ? This::STATUS_OVERFLOW
: This::STATUS_OKAY
);
3895 // Relocate THUMB long branches. This handles relocation types
3896 // R_ARM_THM_CALL, R_ARM_THM_JUMP24 and R_ARM_THM_XPC22.
3897 // If IS_WEAK_UNDEFINED_WITH_PLT is true. The target symbol is weakly
3898 // undefined and we do not use PLT in this relocation. In such a case,
3899 // the branch is converted into an NOP.
3901 template<bool big_endian
>
3902 typename Arm_relocate_functions
<big_endian
>::Status
3903 Arm_relocate_functions
<big_endian
>::thumb_branch_common(
3904 unsigned int r_type
,
3905 const Relocate_info
<32, big_endian
>* relinfo
,
3906 unsigned char *view
,
3907 const Sized_symbol
<32>* gsym
,
3908 const Arm_relobj
<big_endian
>* object
,
3910 const Symbol_value
<32>* psymval
,
3911 Arm_address address
,
3912 Arm_address thumb_bit
,
3913 bool is_weakly_undefined_without_plt
)
3915 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
3916 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3917 uint32_t upper_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
3918 uint32_t lower_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
3920 // FIXME: These tests are too loose and do not take THUMB/THUMB-2 difference
3922 bool is_bl_insn
= (lower_insn
& 0x1000U
) == 0x1000U
;
3923 bool is_blx_insn
= (lower_insn
& 0x1000U
) == 0x0000U
;
3925 // Check that the instruction is valid.
3926 if (r_type
== elfcpp::R_ARM_THM_CALL
)
3928 if (!is_bl_insn
&& !is_blx_insn
)
3929 return This::STATUS_BAD_RELOC
;
3931 else if (r_type
== elfcpp::R_ARM_THM_JUMP24
)
3933 // This cannot be a BLX.
3935 return This::STATUS_BAD_RELOC
;
3937 else if (r_type
== elfcpp::R_ARM_THM_XPC22
)
3939 // Check for Thumb to Thumb call.
3941 return This::STATUS_BAD_RELOC
;
3944 gold_warning(_("%s: Thumb BLX instruction targets "
3945 "thumb function '%s'."),
3946 object
->name().c_str(),
3947 (gsym
? gsym
->name() : "(local)"));
3948 // Convert BLX to BL.
3949 lower_insn
|= 0x1000U
;
3955 // A branch to an undefined weak symbol is turned into a jump to
3956 // the next instruction unless a PLT entry will be created.
3957 // The jump to the next instruction is optimized as a NOP.W for
3958 // Thumb-2 enabled architectures.
3959 const Target_arm
<big_endian
>* arm_target
=
3960 Target_arm
<big_endian
>::default_target();
3961 if (is_weakly_undefined_without_plt
)
3963 gold_assert(!parameters
->options().relocatable());
3964 if (arm_target
->may_use_thumb2_nop())
3966 elfcpp::Swap
<16, big_endian
>::writeval(wv
, 0xf3af);
3967 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, 0x8000);
3971 elfcpp::Swap
<16, big_endian
>::writeval(wv
, 0xe000);
3972 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, 0xbf00);
3974 return This::STATUS_OKAY
;
3977 int32_t addend
= This::thumb32_branch_offset(upper_insn
, lower_insn
);
3978 Arm_address branch_target
= psymval
->value(object
, addend
);
3980 // For BLX, bit 1 of target address comes from bit 1 of base address.
3981 bool may_use_blx
= arm_target
->may_use_blx();
3982 if (thumb_bit
== 0 && may_use_blx
)
3983 branch_target
= utils::bit_select(branch_target
, address
, 0x2);
3985 int32_t branch_offset
= branch_target
- address
;
3987 // We need a stub if the branch offset is too large or if we need
3989 bool thumb2
= arm_target
->using_thumb2();
3990 if (!parameters
->options().relocatable()
3991 && ((!thumb2
&& utils::has_overflow
<23>(branch_offset
))
3992 || (thumb2
&& utils::has_overflow
<25>(branch_offset
))
3993 || ((thumb_bit
== 0)
3994 && (((r_type
== elfcpp::R_ARM_THM_CALL
) && !may_use_blx
)
3995 || r_type
== elfcpp::R_ARM_THM_JUMP24
))))
3997 Arm_address unadjusted_branch_target
= psymval
->value(object
, 0);
3999 Stub_type stub_type
=
4000 Reloc_stub::stub_type_for_reloc(r_type
, address
,
4001 unadjusted_branch_target
,
4004 if (stub_type
!= arm_stub_none
)
4006 Stub_table
<big_endian
>* stub_table
=
4007 object
->stub_table(relinfo
->data_shndx
);
4008 gold_assert(stub_table
!= NULL
);
4010 Reloc_stub::Key
stub_key(stub_type
, gsym
, object
, r_sym
, addend
);
4011 Reloc_stub
* stub
= stub_table
->find_reloc_stub(stub_key
);
4012 gold_assert(stub
!= NULL
);
4013 thumb_bit
= stub
->stub_template()->entry_in_thumb_mode() ? 1 : 0;
4014 branch_target
= stub_table
->address() + stub
->offset() + addend
;
4015 if (thumb_bit
== 0 && may_use_blx
)
4016 branch_target
= utils::bit_select(branch_target
, address
, 0x2);
4017 branch_offset
= branch_target
- address
;
4021 // At this point, if we still need to switch mode, the instruction
4022 // must either be a BLX or a BL that can be converted to a BLX.
4025 gold_assert(may_use_blx
4026 && (r_type
== elfcpp::R_ARM_THM_CALL
4027 || r_type
== elfcpp::R_ARM_THM_XPC22
));
4028 // Make sure this is a BLX.
4029 lower_insn
&= ~0x1000U
;
4033 // Make sure this is a BL.
4034 lower_insn
|= 0x1000U
;
4037 // For a BLX instruction, make sure that the relocation is rounded up
4038 // to a word boundary. This follows the semantics of the instruction
4039 // which specifies that bit 1 of the target address will come from bit
4040 // 1 of the base address.
4041 if ((lower_insn
& 0x5000U
) == 0x4000U
)
4042 gold_assert((branch_offset
& 3) == 0);
4044 // Put BRANCH_OFFSET back into the insn. Assumes two's complement.
4045 // We use the Thumb-2 encoding, which is safe even if dealing with
4046 // a Thumb-1 instruction by virtue of our overflow check above. */
4047 upper_insn
= This::thumb32_branch_upper(upper_insn
, branch_offset
);
4048 lower_insn
= This::thumb32_branch_lower(lower_insn
, branch_offset
);
4050 elfcpp::Swap
<16, big_endian
>::writeval(wv
, upper_insn
);
4051 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, lower_insn
);
4053 gold_assert(!utils::has_overflow
<25>(branch_offset
));
4056 ? utils::has_overflow
<25>(branch_offset
)
4057 : utils::has_overflow
<23>(branch_offset
))
4058 ? This::STATUS_OVERFLOW
4059 : This::STATUS_OKAY
);
4062 // Relocate THUMB-2 long conditional branches.
4063 // If IS_WEAK_UNDEFINED_WITH_PLT is true. The target symbol is weakly
4064 // undefined and we do not use PLT in this relocation. In such a case,
4065 // the branch is converted into an NOP.
4067 template<bool big_endian
>
4068 typename Arm_relocate_functions
<big_endian
>::Status
4069 Arm_relocate_functions
<big_endian
>::thm_jump19(
4070 unsigned char *view
,
4071 const Arm_relobj
<big_endian
>* object
,
4072 const Symbol_value
<32>* psymval
,
4073 Arm_address address
,
4074 Arm_address thumb_bit
)
4076 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
4077 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
4078 uint32_t upper_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
4079 uint32_t lower_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
4080 int32_t addend
= This::thumb32_cond_branch_offset(upper_insn
, lower_insn
);
4082 Arm_address branch_target
= psymval
->value(object
, addend
);
4083 int32_t branch_offset
= branch_target
- address
;
4085 // ??? Should handle interworking? GCC might someday try to
4086 // use this for tail calls.
4087 // FIXME: We do support thumb entry to PLT yet.
4090 gold_error(_("conditional branch to PLT in THUMB-2 not supported yet."));
4091 return This::STATUS_BAD_RELOC
;
4094 // Put RELOCATION back into the insn.
4095 upper_insn
= This::thumb32_cond_branch_upper(upper_insn
, branch_offset
);
4096 lower_insn
= This::thumb32_cond_branch_lower(lower_insn
, branch_offset
);
4098 // Put the relocated value back in the object file:
4099 elfcpp::Swap
<16, big_endian
>::writeval(wv
, upper_insn
);
4100 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, lower_insn
);
4102 return (utils::has_overflow
<21>(branch_offset
)
4103 ? This::STATUS_OVERFLOW
4104 : This::STATUS_OKAY
);
4107 // Get the GOT section, creating it if necessary.
4109 template<bool big_endian
>
4110 Arm_output_data_got
<big_endian
>*
4111 Target_arm
<big_endian
>::got_section(Symbol_table
* symtab
, Layout
* layout
)
4113 if (this->got_
== NULL
)
4115 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
4117 this->got_
= new Arm_output_data_got
<big_endian
>(symtab
, layout
);
4120 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
4122 | elfcpp::SHF_WRITE
),
4123 this->got_
, false, false, false,
4125 // The old GNU linker creates a .got.plt section. We just
4126 // create another set of data in the .got section. Note that we
4127 // always create a PLT if we create a GOT, although the PLT
4129 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
4130 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
4132 | elfcpp::SHF_WRITE
),
4133 this->got_plt_
, false, false,
4136 // The first three entries are reserved.
4137 this->got_plt_
->set_current_data_size(3 * 4);
4139 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
4140 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
4141 Symbol_table::PREDEFINED
,
4143 0, 0, elfcpp::STT_OBJECT
,
4145 elfcpp::STV_HIDDEN
, 0,
4151 // Get the dynamic reloc section, creating it if necessary.
4153 template<bool big_endian
>
4154 typename Target_arm
<big_endian
>::Reloc_section
*
4155 Target_arm
<big_endian
>::rel_dyn_section(Layout
* layout
)
4157 if (this->rel_dyn_
== NULL
)
4159 gold_assert(layout
!= NULL
);
4160 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
4161 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
4162 elfcpp::SHF_ALLOC
, this->rel_dyn_
, true,
4163 false, false, false);
4165 return this->rel_dyn_
;
4168 // Insn_template methods.
4170 // Return byte size of an instruction template.
4173 Insn_template::size() const
4175 switch (this->type())
4178 case THUMB16_SPECIAL_TYPE
:
4189 // Return alignment of an instruction template.
4192 Insn_template::alignment() const
4194 switch (this->type())
4197 case THUMB16_SPECIAL_TYPE
:
4208 // Stub_template methods.
4210 Stub_template::Stub_template(
4211 Stub_type type
, const Insn_template
* insns
,
4213 : type_(type
), insns_(insns
), insn_count_(insn_count
), alignment_(1),
4214 entry_in_thumb_mode_(false), relocs_()
4218 // Compute byte size and alignment of stub template.
4219 for (size_t i
= 0; i
< insn_count
; i
++)
4221 unsigned insn_alignment
= insns
[i
].alignment();
4222 size_t insn_size
= insns
[i
].size();
4223 gold_assert((offset
& (insn_alignment
- 1)) == 0);
4224 this->alignment_
= std::max(this->alignment_
, insn_alignment
);
4225 switch (insns
[i
].type())
4227 case Insn_template::THUMB16_TYPE
:
4228 case Insn_template::THUMB16_SPECIAL_TYPE
:
4230 this->entry_in_thumb_mode_
= true;
4233 case Insn_template::THUMB32_TYPE
:
4234 if (insns
[i
].r_type() != elfcpp::R_ARM_NONE
)
4235 this->relocs_
.push_back(Reloc(i
, offset
));
4237 this->entry_in_thumb_mode_
= true;
4240 case Insn_template::ARM_TYPE
:
4241 // Handle cases where the target is encoded within the
4243 if (insns
[i
].r_type() == elfcpp::R_ARM_JUMP24
)
4244 this->relocs_
.push_back(Reloc(i
, offset
));
4247 case Insn_template::DATA_TYPE
:
4248 // Entry point cannot be data.
4249 gold_assert(i
!= 0);
4250 this->relocs_
.push_back(Reloc(i
, offset
));
4256 offset
+= insn_size
;
4258 this->size_
= offset
;
4263 // Template to implement do_write for a specific target endianness.
4265 template<bool big_endian
>
4267 Stub::do_fixed_endian_write(unsigned char* view
, section_size_type view_size
)
4269 const Stub_template
* stub_template
= this->stub_template();
4270 const Insn_template
* insns
= stub_template
->insns();
4272 // FIXME: We do not handle BE8 encoding yet.
4273 unsigned char* pov
= view
;
4274 for (size_t i
= 0; i
< stub_template
->insn_count(); i
++)
4276 switch (insns
[i
].type())
4278 case Insn_template::THUMB16_TYPE
:
4279 elfcpp::Swap
<16, big_endian
>::writeval(pov
, insns
[i
].data() & 0xffff);
4281 case Insn_template::THUMB16_SPECIAL_TYPE
:
4282 elfcpp::Swap
<16, big_endian
>::writeval(
4284 this->thumb16_special(i
));
4286 case Insn_template::THUMB32_TYPE
:
4288 uint32_t hi
= (insns
[i
].data() >> 16) & 0xffff;
4289 uint32_t lo
= insns
[i
].data() & 0xffff;
4290 elfcpp::Swap
<16, big_endian
>::writeval(pov
, hi
);
4291 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lo
);
4294 case Insn_template::ARM_TYPE
:
4295 case Insn_template::DATA_TYPE
:
4296 elfcpp::Swap
<32, big_endian
>::writeval(pov
, insns
[i
].data());
4301 pov
+= insns
[i
].size();
4303 gold_assert(static_cast<section_size_type
>(pov
- view
) == view_size
);
4306 // Reloc_stub::Key methods.
4308 // Dump a Key as a string for debugging.
4311 Reloc_stub::Key::name() const
4313 if (this->r_sym_
== invalid_index
)
4315 // Global symbol key name
4316 // <stub-type>:<symbol name>:<addend>.
4317 const std::string sym_name
= this->u_
.symbol
->name();
4318 // We need to print two hex number and two colons. So just add 100 bytes
4319 // to the symbol name size.
4320 size_t len
= sym_name
.size() + 100;
4321 char* buffer
= new char[len
];
4322 int c
= snprintf(buffer
, len
, "%d:%s:%x", this->stub_type_
,
4323 sym_name
.c_str(), this->addend_
);
4324 gold_assert(c
> 0 && c
< static_cast<int>(len
));
4326 return std::string(buffer
);
4330 // local symbol key name
4331 // <stub-type>:<object>:<r_sym>:<addend>.
4332 const size_t len
= 200;
4334 int c
= snprintf(buffer
, len
, "%d:%p:%u:%x", this->stub_type_
,
4335 this->u_
.relobj
, this->r_sym_
, this->addend_
);
4336 gold_assert(c
> 0 && c
< static_cast<int>(len
));
4337 return std::string(buffer
);
4341 // Reloc_stub methods.
4343 // Determine the type of stub needed, if any, for a relocation of R_TYPE at
4344 // LOCATION to DESTINATION.
4345 // This code is based on the arm_type_of_stub function in
4346 // bfd/elf32-arm.c. We have changed the interface a liitle to keep the Stub
4350 Reloc_stub::stub_type_for_reloc(
4351 unsigned int r_type
,
4352 Arm_address location
,
4353 Arm_address destination
,
4354 bool target_is_thumb
)
4356 Stub_type stub_type
= arm_stub_none
;
4358 // This is a bit ugly but we want to avoid using a templated class for
4359 // big and little endianities.
4361 bool should_force_pic_veneer
;
4364 if (parameters
->target().is_big_endian())
4366 const Target_arm
<true>* big_endian_target
=
4367 Target_arm
<true>::default_target();
4368 may_use_blx
= big_endian_target
->may_use_blx();
4369 should_force_pic_veneer
= big_endian_target
->should_force_pic_veneer();
4370 thumb2
= big_endian_target
->using_thumb2();
4371 thumb_only
= big_endian_target
->using_thumb_only();
4375 const Target_arm
<false>* little_endian_target
=
4376 Target_arm
<false>::default_target();
4377 may_use_blx
= little_endian_target
->may_use_blx();
4378 should_force_pic_veneer
= little_endian_target
->should_force_pic_veneer();
4379 thumb2
= little_endian_target
->using_thumb2();
4380 thumb_only
= little_endian_target
->using_thumb_only();
4383 int64_t branch_offset
;
4384 if (r_type
== elfcpp::R_ARM_THM_CALL
|| r_type
== elfcpp::R_ARM_THM_JUMP24
)
4386 // For THUMB BLX instruction, bit 1 of target comes from bit 1 of the
4387 // base address (instruction address + 4).
4388 if ((r_type
== elfcpp::R_ARM_THM_CALL
) && may_use_blx
&& !target_is_thumb
)
4389 destination
= utils::bit_select(destination
, location
, 0x2);
4390 branch_offset
= static_cast<int64_t>(destination
) - location
;
4392 // Handle cases where:
4393 // - this call goes too far (different Thumb/Thumb2 max
4395 // - it's a Thumb->Arm call and blx is not available, or it's a
4396 // Thumb->Arm branch (not bl). A stub is needed in this case.
4398 && (branch_offset
> THM_MAX_FWD_BRANCH_OFFSET
4399 || (branch_offset
< THM_MAX_BWD_BRANCH_OFFSET
)))
4401 && (branch_offset
> THM2_MAX_FWD_BRANCH_OFFSET
4402 || (branch_offset
< THM2_MAX_BWD_BRANCH_OFFSET
)))
4403 || ((!target_is_thumb
)
4404 && (((r_type
== elfcpp::R_ARM_THM_CALL
) && !may_use_blx
)
4405 || (r_type
== elfcpp::R_ARM_THM_JUMP24
))))
4407 if (target_is_thumb
)
4412 stub_type
= (parameters
->options().shared()
4413 || should_force_pic_veneer
)
4416 && (r_type
== elfcpp::R_ARM_THM_CALL
))
4417 // V5T and above. Stub starts with ARM code, so
4418 // we must be able to switch mode before
4419 // reaching it, which is only possible for 'bl'
4420 // (ie R_ARM_THM_CALL relocation).
4421 ? arm_stub_long_branch_any_thumb_pic
4422 // On V4T, use Thumb code only.
4423 : arm_stub_long_branch_v4t_thumb_thumb_pic
)
4427 && (r_type
== elfcpp::R_ARM_THM_CALL
))
4428 ? arm_stub_long_branch_any_any
// V5T and above.
4429 : arm_stub_long_branch_v4t_thumb_thumb
); // V4T.
4433 stub_type
= (parameters
->options().shared()
4434 || should_force_pic_veneer
)
4435 ? arm_stub_long_branch_thumb_only_pic
// PIC stub.
4436 : arm_stub_long_branch_thumb_only
; // non-PIC stub.
4443 // FIXME: We should check that the input section is from an
4444 // object that has interwork enabled.
4446 stub_type
= (parameters
->options().shared()
4447 || should_force_pic_veneer
)
4450 && (r_type
== elfcpp::R_ARM_THM_CALL
))
4451 ? arm_stub_long_branch_any_arm_pic
// V5T and above.
4452 : arm_stub_long_branch_v4t_thumb_arm_pic
) // V4T.
4456 && (r_type
== elfcpp::R_ARM_THM_CALL
))
4457 ? arm_stub_long_branch_any_any
// V5T and above.
4458 : arm_stub_long_branch_v4t_thumb_arm
); // V4T.
4460 // Handle v4t short branches.
4461 if ((stub_type
== arm_stub_long_branch_v4t_thumb_arm
)
4462 && (branch_offset
<= THM_MAX_FWD_BRANCH_OFFSET
)
4463 && (branch_offset
>= THM_MAX_BWD_BRANCH_OFFSET
))
4464 stub_type
= arm_stub_short_branch_v4t_thumb_arm
;
4468 else if (r_type
== elfcpp::R_ARM_CALL
4469 || r_type
== elfcpp::R_ARM_JUMP24
4470 || r_type
== elfcpp::R_ARM_PLT32
)
4472 branch_offset
= static_cast<int64_t>(destination
) - location
;
4473 if (target_is_thumb
)
4477 // FIXME: We should check that the input section is from an
4478 // object that has interwork enabled.
4480 // We have an extra 2-bytes reach because of
4481 // the mode change (bit 24 (H) of BLX encoding).
4482 if (branch_offset
> (ARM_MAX_FWD_BRANCH_OFFSET
+ 2)
4483 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
)
4484 || ((r_type
== elfcpp::R_ARM_CALL
) && !may_use_blx
)
4485 || (r_type
== elfcpp::R_ARM_JUMP24
)
4486 || (r_type
== elfcpp::R_ARM_PLT32
))
4488 stub_type
= (parameters
->options().shared()
4489 || should_force_pic_veneer
)
4492 ? arm_stub_long_branch_any_thumb_pic
// V5T and above.
4493 : arm_stub_long_branch_v4t_arm_thumb_pic
) // V4T stub.
4497 ? arm_stub_long_branch_any_any
// V5T and above.
4498 : arm_stub_long_branch_v4t_arm_thumb
); // V4T.
4504 if (branch_offset
> ARM_MAX_FWD_BRANCH_OFFSET
4505 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
))
4507 stub_type
= (parameters
->options().shared()
4508 || should_force_pic_veneer
)
4509 ? arm_stub_long_branch_any_arm_pic
// PIC stubs.
4510 : arm_stub_long_branch_any_any
; /// non-PIC.
4518 // Cortex_a8_stub methods.
4520 // Return the instruction for a THUMB16_SPECIAL_TYPE instruction template.
4521 // I is the position of the instruction template in the stub template.
4524 Cortex_a8_stub::do_thumb16_special(size_t i
)
4526 // The only use of this is to copy condition code from a conditional
4527 // branch being worked around to the corresponding conditional branch in
4529 gold_assert(this->stub_template()->type() == arm_stub_a8_veneer_b_cond
4531 uint16_t data
= this->stub_template()->insns()[i
].data();
4532 gold_assert((data
& 0xff00U
) == 0xd000U
);
4533 data
|= ((this->original_insn_
>> 22) & 0xf) << 8;
4537 // Stub_factory methods.
4539 Stub_factory::Stub_factory()
4541 // The instruction template sequences are declared as static
4542 // objects and initialized first time the constructor runs.
4544 // Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
4545 // to reach the stub if necessary.
4546 static const Insn_template elf32_arm_stub_long_branch_any_any
[] =
4548 Insn_template::arm_insn(0xe51ff004), // ldr pc, [pc, #-4]
4549 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
4550 // dcd R_ARM_ABS32(X)
4553 // V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
4555 static const Insn_template elf32_arm_stub_long_branch_v4t_arm_thumb
[] =
4557 Insn_template::arm_insn(0xe59fc000), // ldr ip, [pc, #0]
4558 Insn_template::arm_insn(0xe12fff1c), // bx ip
4559 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
4560 // dcd R_ARM_ABS32(X)
4563 // Thumb -> Thumb long branch stub. Used on M-profile architectures.
4564 static const Insn_template elf32_arm_stub_long_branch_thumb_only
[] =
4566 Insn_template::thumb16_insn(0xb401), // push {r0}
4567 Insn_template::thumb16_insn(0x4802), // ldr r0, [pc, #8]
4568 Insn_template::thumb16_insn(0x4684), // mov ip, r0
4569 Insn_template::thumb16_insn(0xbc01), // pop {r0}
4570 Insn_template::thumb16_insn(0x4760), // bx ip
4571 Insn_template::thumb16_insn(0xbf00), // nop
4572 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
4573 // dcd R_ARM_ABS32(X)
4576 // V4T Thumb -> Thumb long branch stub. Using the stack is not
4578 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_thumb
[] =
4580 Insn_template::thumb16_insn(0x4778), // bx pc
4581 Insn_template::thumb16_insn(0x46c0), // nop
4582 Insn_template::arm_insn(0xe59fc000), // ldr ip, [pc, #0]
4583 Insn_template::arm_insn(0xe12fff1c), // bx ip
4584 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
4585 // dcd R_ARM_ABS32(X)
4588 // V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
4590 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_arm
[] =
4592 Insn_template::thumb16_insn(0x4778), // bx pc
4593 Insn_template::thumb16_insn(0x46c0), // nop
4594 Insn_template::arm_insn(0xe51ff004), // ldr pc, [pc, #-4]
4595 Insn_template::data_word(0, elfcpp::R_ARM_ABS32
, 0),
4596 // dcd R_ARM_ABS32(X)
4599 // V4T Thumb -> ARM short branch stub. Shorter variant of the above
4600 // one, when the destination is close enough.
4601 static const Insn_template elf32_arm_stub_short_branch_v4t_thumb_arm
[] =
4603 Insn_template::thumb16_insn(0x4778), // bx pc
4604 Insn_template::thumb16_insn(0x46c0), // nop
4605 Insn_template::arm_rel_insn(0xea000000, -8), // b (X-8)
4608 // ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
4609 // blx to reach the stub if necessary.
4610 static const Insn_template elf32_arm_stub_long_branch_any_arm_pic
[] =
4612 Insn_template::arm_insn(0xe59fc000), // ldr r12, [pc]
4613 Insn_template::arm_insn(0xe08ff00c), // add pc, pc, ip
4614 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, -4),
4615 // dcd R_ARM_REL32(X-4)
4618 // ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
4619 // blx to reach the stub if necessary. We can not add into pc;
4620 // it is not guaranteed to mode switch (different in ARMv6 and
4622 static const Insn_template elf32_arm_stub_long_branch_any_thumb_pic
[] =
4624 Insn_template::arm_insn(0xe59fc004), // ldr r12, [pc, #4]
4625 Insn_template::arm_insn(0xe08fc00c), // add ip, pc, ip
4626 Insn_template::arm_insn(0xe12fff1c), // bx ip
4627 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, 0),
4628 // dcd R_ARM_REL32(X)
4631 // V4T ARM -> ARM long branch stub, PIC.
4632 static const Insn_template elf32_arm_stub_long_branch_v4t_arm_thumb_pic
[] =
4634 Insn_template::arm_insn(0xe59fc004), // ldr ip, [pc, #4]
4635 Insn_template::arm_insn(0xe08fc00c), // add ip, pc, ip
4636 Insn_template::arm_insn(0xe12fff1c), // bx ip
4637 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, 0),
4638 // dcd R_ARM_REL32(X)
4641 // V4T Thumb -> ARM long branch stub, PIC.
4642 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_arm_pic
[] =
4644 Insn_template::thumb16_insn(0x4778), // bx pc
4645 Insn_template::thumb16_insn(0x46c0), // nop
4646 Insn_template::arm_insn(0xe59fc000), // ldr ip, [pc, #0]
4647 Insn_template::arm_insn(0xe08cf00f), // add pc, ip, pc
4648 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, -4),
4649 // dcd R_ARM_REL32(X)
4652 // Thumb -> Thumb long branch stub, PIC. Used on M-profile
4654 static const Insn_template elf32_arm_stub_long_branch_thumb_only_pic
[] =
4656 Insn_template::thumb16_insn(0xb401), // push {r0}
4657 Insn_template::thumb16_insn(0x4802), // ldr r0, [pc, #8]
4658 Insn_template::thumb16_insn(0x46fc), // mov ip, pc
4659 Insn_template::thumb16_insn(0x4484), // add ip, r0
4660 Insn_template::thumb16_insn(0xbc01), // pop {r0}
4661 Insn_template::thumb16_insn(0x4760), // bx ip
4662 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, 4),
4663 // dcd R_ARM_REL32(X)
4666 // V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not
4668 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_thumb_pic
[] =
4670 Insn_template::thumb16_insn(0x4778), // bx pc
4671 Insn_template::thumb16_insn(0x46c0), // nop
4672 Insn_template::arm_insn(0xe59fc004), // ldr ip, [pc, #4]
4673 Insn_template::arm_insn(0xe08fc00c), // add ip, pc, ip
4674 Insn_template::arm_insn(0xe12fff1c), // bx ip
4675 Insn_template::data_word(0, elfcpp::R_ARM_REL32
, 0),
4676 // dcd R_ARM_REL32(X)
4679 // Cortex-A8 erratum-workaround stubs.
4681 // Stub used for conditional branches (which may be beyond +/-1MB away,
4682 // so we can't use a conditional branch to reach this stub).
4689 static const Insn_template elf32_arm_stub_a8_veneer_b_cond
[] =
4691 Insn_template::thumb16_bcond_insn(0xd001), // b<cond>.n true
4692 Insn_template::thumb32_b_insn(0xf000b800, -4), // b.w after
4693 Insn_template::thumb32_b_insn(0xf000b800, -4) // true:
4697 // Stub used for b.w and bl.w instructions.
4699 static const Insn_template elf32_arm_stub_a8_veneer_b
[] =
4701 Insn_template::thumb32_b_insn(0xf000b800, -4) // b.w dest
4704 static const Insn_template elf32_arm_stub_a8_veneer_bl
[] =
4706 Insn_template::thumb32_b_insn(0xf000b800, -4) // b.w dest
4709 // Stub used for Thumb-2 blx.w instructions. We modified the original blx.w
4710 // instruction (which switches to ARM mode) to point to this stub. Jump to
4711 // the real destination using an ARM-mode branch.
4712 static const Insn_template elf32_arm_stub_a8_veneer_blx
[] =
4714 Insn_template::arm_rel_insn(0xea000000, -8) // b dest
4717 // Stub used to provide an interworking for R_ARM_V4BX relocation
4718 // (bx r[n] instruction).
4719 static const Insn_template elf32_arm_stub_v4_veneer_bx
[] =
4721 Insn_template::arm_insn(0xe3100001), // tst r<n>, #1
4722 Insn_template::arm_insn(0x01a0f000), // moveq pc, r<n>
4723 Insn_template::arm_insn(0xe12fff10) // bx r<n>
4726 // Fill in the stub template look-up table. Stub templates are constructed
4727 // per instance of Stub_factory for fast look-up without locking
4728 // in a thread-enabled environment.
4730 this->stub_templates_
[arm_stub_none
] =
4731 new Stub_template(arm_stub_none
, NULL
, 0);
4733 #define DEF_STUB(x) \
4737 = sizeof(elf32_arm_stub_##x) / sizeof(elf32_arm_stub_##x[0]); \
4738 Stub_type type = arm_stub_##x; \
4739 this->stub_templates_[type] = \
4740 new Stub_template(type, elf32_arm_stub_##x, array_size); \
4748 // Stub_table methods.
4750 // Removel all Cortex-A8 stub.
4752 template<bool big_endian
>
4754 Stub_table
<big_endian
>::remove_all_cortex_a8_stubs()
4756 for (Cortex_a8_stub_list::iterator p
= this->cortex_a8_stubs_
.begin();
4757 p
!= this->cortex_a8_stubs_
.end();
4760 this->cortex_a8_stubs_
.clear();
4763 // Relocate one stub. This is a helper for Stub_table::relocate_stubs().
4765 template<bool big_endian
>
4767 Stub_table
<big_endian
>::relocate_stub(
4769 const Relocate_info
<32, big_endian
>* relinfo
,
4770 Target_arm
<big_endian
>* arm_target
,
4771 Output_section
* output_section
,
4772 unsigned char* view
,
4773 Arm_address address
,
4774 section_size_type view_size
)
4776 const Stub_template
* stub_template
= stub
->stub_template();
4777 if (stub_template
->reloc_count() != 0)
4779 // Adjust view to cover the stub only.
4780 section_size_type offset
= stub
->offset();
4781 section_size_type stub_size
= stub_template
->size();
4782 gold_assert(offset
+ stub_size
<= view_size
);
4784 arm_target
->relocate_stub(stub
, relinfo
, output_section
, view
+ offset
,
4785 address
+ offset
, stub_size
);
4789 // Relocate all stubs in this stub table.
4791 template<bool big_endian
>
4793 Stub_table
<big_endian
>::relocate_stubs(
4794 const Relocate_info
<32, big_endian
>* relinfo
,
4795 Target_arm
<big_endian
>* arm_target
,
4796 Output_section
* output_section
,
4797 unsigned char* view
,
4798 Arm_address address
,
4799 section_size_type view_size
)
4801 // If we are passed a view bigger than the stub table's. we need to
4803 gold_assert(address
== this->address()
4805 == static_cast<section_size_type
>(this->data_size())));
4807 // Relocate all relocation stubs.
4808 for (typename
Reloc_stub_map::const_iterator p
= this->reloc_stubs_
.begin();
4809 p
!= this->reloc_stubs_
.end();
4811 this->relocate_stub(p
->second
, relinfo
, arm_target
, output_section
, view
,
4812 address
, view_size
);
4814 // Relocate all Cortex-A8 stubs.
4815 for (Cortex_a8_stub_list::iterator p
= this->cortex_a8_stubs_
.begin();
4816 p
!= this->cortex_a8_stubs_
.end();
4818 this->relocate_stub(p
->second
, relinfo
, arm_target
, output_section
, view
,
4819 address
, view_size
);
4821 // Relocate all ARM V4BX stubs.
4822 for (Arm_v4bx_stub_list::iterator p
= this->arm_v4bx_stubs_
.begin();
4823 p
!= this->arm_v4bx_stubs_
.end();
4827 this->relocate_stub(*p
, relinfo
, arm_target
, output_section
, view
,
4828 address
, view_size
);
4832 // Write out the stubs to file.
4834 template<bool big_endian
>
4836 Stub_table
<big_endian
>::do_write(Output_file
* of
)
4838 off_t offset
= this->offset();
4839 const section_size_type oview_size
=
4840 convert_to_section_size_type(this->data_size());
4841 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4843 // Write relocation stubs.
4844 for (typename
Reloc_stub_map::const_iterator p
= this->reloc_stubs_
.begin();
4845 p
!= this->reloc_stubs_
.end();
4848 Reloc_stub
* stub
= p
->second
;
4849 Arm_address address
= this->address() + stub
->offset();
4851 == align_address(address
,
4852 stub
->stub_template()->alignment()));
4853 stub
->write(oview
+ stub
->offset(), stub
->stub_template()->size(),
4857 // Write Cortex-A8 stubs.
4858 for (Cortex_a8_stub_list::const_iterator p
= this->cortex_a8_stubs_
.begin();
4859 p
!= this->cortex_a8_stubs_
.end();
4862 Cortex_a8_stub
* stub
= p
->second
;
4863 Arm_address address
= this->address() + stub
->offset();
4865 == align_address(address
,
4866 stub
->stub_template()->alignment()));
4867 stub
->write(oview
+ stub
->offset(), stub
->stub_template()->size(),
4871 // Write ARM V4BX relocation stubs.
4872 for (Arm_v4bx_stub_list::const_iterator p
= this->arm_v4bx_stubs_
.begin();
4873 p
!= this->arm_v4bx_stubs_
.end();
4879 Arm_address address
= this->address() + (*p
)->offset();
4881 == align_address(address
,
4882 (*p
)->stub_template()->alignment()));
4883 (*p
)->write(oview
+ (*p
)->offset(), (*p
)->stub_template()->size(),
4887 of
->write_output_view(this->offset(), oview_size
, oview
);
4890 // Update the data size and address alignment of the stub table at the end
4891 // of a relaxation pass. Return true if either the data size or the
4892 // alignment changed in this relaxation pass.
4894 template<bool big_endian
>
4896 Stub_table
<big_endian
>::update_data_size_and_addralign()
4898 // Go over all stubs in table to compute data size and address alignment.
4899 off_t size
= this->reloc_stubs_size_
;
4900 unsigned addralign
= this->reloc_stubs_addralign_
;
4902 for (Cortex_a8_stub_list::const_iterator p
= this->cortex_a8_stubs_
.begin();
4903 p
!= this->cortex_a8_stubs_
.end();
4906 const Stub_template
* stub_template
= p
->second
->stub_template();
4907 addralign
= std::max(addralign
, stub_template
->alignment());
4908 size
= (align_address(size
, stub_template
->alignment())
4909 + stub_template
->size());
4912 for (Arm_v4bx_stub_list::const_iterator p
= this->arm_v4bx_stubs_
.begin();
4913 p
!= this->arm_v4bx_stubs_
.end();
4919 const Stub_template
* stub_template
= (*p
)->stub_template();
4920 addralign
= std::max(addralign
, stub_template
->alignment());
4921 size
= (align_address(size
, stub_template
->alignment())
4922 + stub_template
->size());
4925 // Check if either data size or alignment changed in this pass.
4926 // Update prev_data_size_ and prev_addralign_. These will be used
4927 // as the current data size and address alignment for the next pass.
4928 bool changed
= size
!= this->prev_data_size_
;
4929 this->prev_data_size_
= size
;
4931 if (addralign
!= this->prev_addralign_
)
4933 this->prev_addralign_
= addralign
;
4938 // Finalize the stubs. This sets the offsets of the stubs within the stub
4939 // table. It also marks all input sections needing Cortex-A8 workaround.
4941 template<bool big_endian
>
4943 Stub_table
<big_endian
>::finalize_stubs()
4945 off_t off
= this->reloc_stubs_size_
;
4946 for (Cortex_a8_stub_list::const_iterator p
= this->cortex_a8_stubs_
.begin();
4947 p
!= this->cortex_a8_stubs_
.end();
4950 Cortex_a8_stub
* stub
= p
->second
;
4951 const Stub_template
* stub_template
= stub
->stub_template();
4952 uint64_t stub_addralign
= stub_template
->alignment();
4953 off
= align_address(off
, stub_addralign
);
4954 stub
->set_offset(off
);
4955 off
+= stub_template
->size();
4957 // Mark input section so that we can determine later if a code section
4958 // needs the Cortex-A8 workaround quickly.
4959 Arm_relobj
<big_endian
>* arm_relobj
=
4960 Arm_relobj
<big_endian
>::as_arm_relobj(stub
->relobj());
4961 arm_relobj
->mark_section_for_cortex_a8_workaround(stub
->shndx());
4964 for (Arm_v4bx_stub_list::const_iterator p
= this->arm_v4bx_stubs_
.begin();
4965 p
!= this->arm_v4bx_stubs_
.end();
4971 const Stub_template
* stub_template
= (*p
)->stub_template();
4972 uint64_t stub_addralign
= stub_template
->alignment();
4973 off
= align_address(off
, stub_addralign
);
4974 (*p
)->set_offset(off
);
4975 off
+= stub_template
->size();
4978 gold_assert(off
<= this->prev_data_size_
);
4981 // Apply Cortex-A8 workaround to an address range between VIEW_ADDRESS
4982 // and VIEW_ADDRESS + VIEW_SIZE - 1. VIEW points to the mapped address
4983 // of the address range seen by the linker.
4985 template<bool big_endian
>
4987 Stub_table
<big_endian
>::apply_cortex_a8_workaround_to_address_range(
4988 Target_arm
<big_endian
>* arm_target
,
4989 unsigned char* view
,
4990 Arm_address view_address
,
4991 section_size_type view_size
)
4993 // Cortex-A8 stubs are sorted by addresses of branches being fixed up.
4994 for (Cortex_a8_stub_list::const_iterator p
=
4995 this->cortex_a8_stubs_
.lower_bound(view_address
);
4996 ((p
!= this->cortex_a8_stubs_
.end())
4997 && (p
->first
< (view_address
+ view_size
)));
5000 // We do not store the THUMB bit in the LSB of either the branch address
5001 // or the stub offset. There is no need to strip the LSB.
5002 Arm_address branch_address
= p
->first
;
5003 const Cortex_a8_stub
* stub
= p
->second
;
5004 Arm_address stub_address
= this->address() + stub
->offset();
5006 // Offset of the branch instruction relative to this view.
5007 section_size_type offset
=
5008 convert_to_section_size_type(branch_address
- view_address
);
5009 gold_assert((offset
+ 4) <= view_size
);
5011 arm_target
->apply_cortex_a8_workaround(stub
, stub_address
,
5012 view
+ offset
, branch_address
);
5016 // Arm_input_section methods.
5018 // Initialize an Arm_input_section.
5020 template<bool big_endian
>
5022 Arm_input_section
<big_endian
>::init()
5024 Relobj
* relobj
= this->relobj();
5025 unsigned int shndx
= this->shndx();
5027 // Cache these to speed up size and alignment queries. It is too slow
5028 // to call section_addraglin and section_size every time.
5029 this->original_addralign_
=
5030 convert_types
<uint32_t, uint64_t>(relobj
->section_addralign(shndx
));
5031 this->original_size_
=
5032 convert_types
<uint32_t, uint64_t>(relobj
->section_size(shndx
));
5034 // We want to make this look like the original input section after
5035 // output sections are finalized.
5036 Output_section
* os
= relobj
->output_section(shndx
);
5037 off_t offset
= relobj
->output_section_offset(shndx
);
5038 gold_assert(os
!= NULL
&& !relobj
->is_output_section_offset_invalid(shndx
));
5039 this->set_address(os
->address() + offset
);
5040 this->set_file_offset(os
->offset() + offset
);
5042 this->set_current_data_size(this->original_size_
);
5043 this->finalize_data_size();
5046 template<bool big_endian
>
5048 Arm_input_section
<big_endian
>::do_write(Output_file
* of
)
5050 // We have to write out the original section content.
5051 section_size_type section_size
;
5052 const unsigned char* section_contents
=
5053 this->relobj()->section_contents(this->shndx(), §ion_size
, false);
5054 of
->write(this->offset(), section_contents
, section_size
);
5056 // If this owns a stub table and it is not empty, write it.
5057 if (this->is_stub_table_owner() && !this->stub_table_
->empty())
5058 this->stub_table_
->write(of
);
5061 // Finalize data size.
5063 template<bool big_endian
>
5065 Arm_input_section
<big_endian
>::set_final_data_size()
5067 off_t off
= convert_types
<off_t
, uint64_t>(this->original_size_
);
5069 if (this->is_stub_table_owner())
5071 this->stub_table_
->finalize_data_size();
5072 off
= align_address(off
, this->stub_table_
->addralign());
5073 off
+= this->stub_table_
->data_size();
5075 this->set_data_size(off
);
5078 // Reset address and file offset.
5080 template<bool big_endian
>
5082 Arm_input_section
<big_endian
>::do_reset_address_and_file_offset()
5084 // Size of the original input section contents.
5085 off_t off
= convert_types
<off_t
, uint64_t>(this->original_size_
);
5087 // If this is a stub table owner, account for the stub table size.
5088 if (this->is_stub_table_owner())
5090 Stub_table
<big_endian
>* stub_table
= this->stub_table_
;
5092 // Reset the stub table's address and file offset. The
5093 // current data size for child will be updated after that.
5094 stub_table_
->reset_address_and_file_offset();
5095 off
= align_address(off
, stub_table_
->addralign());
5096 off
+= stub_table
->current_data_size();
5099 this->set_current_data_size(off
);
5102 // Arm_exidx_cantunwind methods.
5104 // Write this to Output file OF for a fixed endianness.
5106 template<bool big_endian
>
5108 Arm_exidx_cantunwind::do_fixed_endian_write(Output_file
* of
)
5110 off_t offset
= this->offset();
5111 const section_size_type oview_size
= 8;
5112 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
5114 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
5115 Valtype
* wv
= reinterpret_cast<Valtype
*>(oview
);
5117 Output_section
* os
= this->relobj_
->output_section(this->shndx_
);
5118 gold_assert(os
!= NULL
);
5120 Arm_relobj
<big_endian
>* arm_relobj
=
5121 Arm_relobj
<big_endian
>::as_arm_relobj(this->relobj_
);
5122 Arm_address output_offset
=
5123 arm_relobj
->get_output_section_offset(this->shndx_
);
5124 Arm_address section_start
;
5125 if (output_offset
!= Arm_relobj
<big_endian
>::invalid_address
)
5126 section_start
= os
->address() + output_offset
;
5129 // Currently this only happens for a relaxed section.
5130 const Output_relaxed_input_section
* poris
=
5131 os
->find_relaxed_input_section(this->relobj_
, this->shndx_
);
5132 gold_assert(poris
!= NULL
);
5133 section_start
= poris
->address();
5136 // We always append this to the end of an EXIDX section.
5137 Arm_address output_address
=
5138 section_start
+ this->relobj_
->section_size(this->shndx_
);
5140 // Write out the entry. The first word either points to the beginning
5141 // or after the end of a text section. The second word is the special
5142 // EXIDX_CANTUNWIND value.
5143 uint32_t prel31_offset
= output_address
- this->address();
5144 if (utils::has_overflow
<31>(offset
))
5145 gold_error(_("PREL31 overflow in EXIDX_CANTUNWIND entry"));
5146 elfcpp::Swap
<32, big_endian
>::writeval(wv
, prel31_offset
& 0x7fffffffU
);
5147 elfcpp::Swap
<32, big_endian
>::writeval(wv
+ 1, elfcpp::EXIDX_CANTUNWIND
);
5149 of
->write_output_view(this->offset(), oview_size
, oview
);
5152 // Arm_exidx_merged_section methods.
5154 // Constructor for Arm_exidx_merged_section.
5155 // EXIDX_INPUT_SECTION points to the unmodified EXIDX input section.
5156 // SECTION_OFFSET_MAP points to a section offset map describing how
5157 // parts of the input section are mapped to output. DELETED_BYTES is
5158 // the number of bytes deleted from the EXIDX input section.
5160 Arm_exidx_merged_section::Arm_exidx_merged_section(
5161 const Arm_exidx_input_section
& exidx_input_section
,
5162 const Arm_exidx_section_offset_map
& section_offset_map
,
5163 uint32_t deleted_bytes
)
5164 : Output_relaxed_input_section(exidx_input_section
.relobj(),
5165 exidx_input_section
.shndx(),
5166 exidx_input_section
.addralign()),
5167 exidx_input_section_(exidx_input_section
),
5168 section_offset_map_(section_offset_map
)
5170 // Fix size here so that we do not need to implement set_final_data_size.
5171 this->set_data_size(exidx_input_section
.size() - deleted_bytes
);
5172 this->fix_data_size();
5175 // Given an input OBJECT, an input section index SHNDX within that
5176 // object, and an OFFSET relative to the start of that input
5177 // section, return whether or not the corresponding offset within
5178 // the output section is known. If this function returns true, it
5179 // sets *POUTPUT to the output offset. The value -1 indicates that
5180 // this input offset is being discarded.
5183 Arm_exidx_merged_section::do_output_offset(
5184 const Relobj
* relobj
,
5186 section_offset_type offset
,
5187 section_offset_type
* poutput
) const
5189 // We only handle offsets for the original EXIDX input section.
5190 if (relobj
!= this->exidx_input_section_
.relobj()
5191 || shndx
!= this->exidx_input_section_
.shndx())
5194 section_offset_type section_size
=
5195 convert_types
<section_offset_type
>(this->exidx_input_section_
.size());
5196 if (offset
< 0 || offset
>= section_size
)
5197 // Input offset is out of valid range.
5201 // We need to look up the section offset map to determine the output
5202 // offset. Find the reference point in map that is first offset
5203 // bigger than or equal to this offset.
5204 Arm_exidx_section_offset_map::const_iterator p
=
5205 this->section_offset_map_
.lower_bound(offset
);
5207 // The section offset maps are build such that this should not happen if
5208 // input offset is in the valid range.
5209 gold_assert(p
!= this->section_offset_map_
.end());
5211 // We need to check if this is dropped.
5212 section_offset_type ref
= p
->first
;
5213 section_offset_type mapped_ref
= p
->second
;
5215 if (mapped_ref
!= Arm_exidx_input_section::invalid_offset
)
5216 // Offset is present in output.
5217 *poutput
= mapped_ref
+ (offset
- ref
);
5219 // Offset is discarded owing to EXIDX entry merging.
5226 // Write this to output file OF.
5229 Arm_exidx_merged_section::do_write(Output_file
* of
)
5231 // If we retain or discard the whole EXIDX input section, we would
5233 gold_assert(this->data_size() != this->exidx_input_section_
.size()
5234 && this->data_size() != 0);
5236 off_t offset
= this->offset();
5237 const section_size_type oview_size
= this->data_size();
5238 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
5240 Output_section
* os
= this->relobj()->output_section(this->shndx());
5241 gold_assert(os
!= NULL
);
5243 // Get contents of EXIDX input section.
5244 section_size_type section_size
;
5245 const unsigned char* section_contents
=
5246 this->relobj()->section_contents(this->shndx(), §ion_size
, false);
5247 gold_assert(section_size
== this->exidx_input_section_
.size());
5249 // Go over spans of input offsets and write only those that are not
5251 section_offset_type in_start
= 0;
5252 section_offset_type out_start
= 0;
5253 for(Arm_exidx_section_offset_map::const_iterator p
=
5254 this->section_offset_map_
.begin();
5255 p
!= this->section_offset_map_
.end();
5258 section_offset_type in_end
= p
->first
;
5259 gold_assert(in_end
>= in_start
);
5260 section_offset_type out_end
= p
->second
;
5261 size_t in_chunk_size
= convert_types
<size_t>(in_end
- in_start
+ 1);
5264 size_t out_chunk_size
=
5265 convert_types
<size_t>(out_end
- out_start
+ 1);
5266 gold_assert(out_chunk_size
== in_chunk_size
);
5267 memcpy(oview
+ out_start
, section_contents
+ in_start
,
5269 out_start
+= out_chunk_size
;
5271 in_start
+= in_chunk_size
;
5274 gold_assert(convert_to_section_size_type(out_start
) == oview_size
);
5275 of
->write_output_view(this->offset(), oview_size
, oview
);
5278 // Arm_exidx_fixup methods.
5280 // Append an EXIDX_CANTUNWIND in the current output section if the last entry
5281 // is not an EXIDX_CANTUNWIND entry already. The new EXIDX_CANTUNWIND entry
5282 // points to the end of the last seen EXIDX section.
5285 Arm_exidx_fixup::add_exidx_cantunwind_as_needed()
5287 if (this->last_unwind_type_
!= UT_EXIDX_CANTUNWIND
5288 && this->last_input_section_
!= NULL
)
5290 Relobj
* relobj
= this->last_input_section_
->relobj();
5291 unsigned int text_shndx
= this->last_input_section_
->link();
5292 Arm_exidx_cantunwind
* cantunwind
=
5293 new Arm_exidx_cantunwind(relobj
, text_shndx
);
5294 this->exidx_output_section_
->add_output_section_data(cantunwind
);
5295 this->last_unwind_type_
= UT_EXIDX_CANTUNWIND
;
5299 // Process an EXIDX section entry in input. Return whether this entry
5300 // can be deleted in the output. SECOND_WORD in the second word of the
5304 Arm_exidx_fixup::process_exidx_entry(uint32_t second_word
)
5307 if (second_word
== elfcpp::EXIDX_CANTUNWIND
)
5309 // Merge if previous entry is also an EXIDX_CANTUNWIND.
5310 delete_entry
= this->last_unwind_type_
== UT_EXIDX_CANTUNWIND
;
5311 this->last_unwind_type_
= UT_EXIDX_CANTUNWIND
;
5313 else if ((second_word
& 0x80000000) != 0)
5315 // Inlined unwinding data. Merge if equal to previous.
5316 delete_entry
= (merge_exidx_entries_
5317 && this->last_unwind_type_
== UT_INLINED_ENTRY
5318 && this->last_inlined_entry_
== second_word
);
5319 this->last_unwind_type_
= UT_INLINED_ENTRY
;
5320 this->last_inlined_entry_
= second_word
;
5324 // Normal table entry. In theory we could merge these too,
5325 // but duplicate entries are likely to be much less common.
5326 delete_entry
= false;
5327 this->last_unwind_type_
= UT_NORMAL_ENTRY
;
5329 return delete_entry
;
5332 // Update the current section offset map during EXIDX section fix-up.
5333 // If there is no map, create one. INPUT_OFFSET is the offset of a
5334 // reference point, DELETED_BYTES is the number of deleted by in the
5335 // section so far. If DELETE_ENTRY is true, the reference point and
5336 // all offsets after the previous reference point are discarded.
5339 Arm_exidx_fixup::update_offset_map(
5340 section_offset_type input_offset
,
5341 section_size_type deleted_bytes
,
5344 if (this->section_offset_map_
== NULL
)
5345 this->section_offset_map_
= new Arm_exidx_section_offset_map();
5346 section_offset_type output_offset
;
5348 output_offset
= Arm_exidx_input_section::invalid_offset
;
5350 output_offset
= input_offset
- deleted_bytes
;
5351 (*this->section_offset_map_
)[input_offset
] = output_offset
;
5354 // Process EXIDX_INPUT_SECTION for EXIDX entry merging. Return the number of
5355 // bytes deleted. If some entries are merged, also store a pointer to a newly
5356 // created Arm_exidx_section_offset_map object in *PSECTION_OFFSET_MAP. The
5357 // caller owns the map and is responsible for releasing it after use.
5359 template<bool big_endian
>
5361 Arm_exidx_fixup::process_exidx_section(
5362 const Arm_exidx_input_section
* exidx_input_section
,
5363 Arm_exidx_section_offset_map
** psection_offset_map
)
5365 Relobj
* relobj
= exidx_input_section
->relobj();
5366 unsigned shndx
= exidx_input_section
->shndx();
5367 section_size_type section_size
;
5368 const unsigned char* section_contents
=
5369 relobj
->section_contents(shndx
, §ion_size
, false);
5371 if ((section_size
% 8) != 0)
5373 // Something is wrong with this section. Better not touch it.
5374 gold_error(_("uneven .ARM.exidx section size in %s section %u"),
5375 relobj
->name().c_str(), shndx
);
5376 this->last_input_section_
= exidx_input_section
;
5377 this->last_unwind_type_
= UT_NONE
;
5381 uint32_t deleted_bytes
= 0;
5382 bool prev_delete_entry
= false;
5383 gold_assert(this->section_offset_map_
== NULL
);
5385 for (section_size_type i
= 0; i
< section_size
; i
+= 8)
5387 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
5389 reinterpret_cast<const Valtype
*>(section_contents
+ i
+ 4);
5390 uint32_t second_word
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5392 bool delete_entry
= this->process_exidx_entry(second_word
);
5394 // Entry deletion causes changes in output offsets. We use a std::map
5395 // to record these. And entry (x, y) means input offset x
5396 // is mapped to output offset y. If y is invalid_offset, then x is
5397 // dropped in the output. Because of the way std::map::lower_bound
5398 // works, we record the last offset in a region w.r.t to keeping or
5399 // dropping. If there is no entry (x0, y0) for an input offset x0,
5400 // the output offset y0 of it is determined by the output offset y1 of
5401 // the smallest input offset x1 > x0 that there is an (x1, y1) entry
5402 // in the map. If y1 is not -1, then y0 = y1 + x0 - x1. Othewise, y1
5404 if (delete_entry
!= prev_delete_entry
&& i
!= 0)
5405 this->update_offset_map(i
- 1, deleted_bytes
, prev_delete_entry
);
5407 // Update total deleted bytes for this entry.
5411 prev_delete_entry
= delete_entry
;
5414 // If section offset map is not NULL, make an entry for the end of
5416 if (this->section_offset_map_
!= NULL
)
5417 update_offset_map(section_size
- 1, deleted_bytes
, prev_delete_entry
);
5419 *psection_offset_map
= this->section_offset_map_
;
5420 this->section_offset_map_
= NULL
;
5421 this->last_input_section_
= exidx_input_section
;
5423 // Set the first output text section so that we can link the EXIDX output
5424 // section to it. Ignore any EXIDX input section that is completely merged.
5425 if (this->first_output_text_section_
== NULL
5426 && deleted_bytes
!= section_size
)
5428 unsigned int link
= exidx_input_section
->link();
5429 Output_section
* os
= relobj
->output_section(link
);
5430 gold_assert(os
!= NULL
);
5431 this->first_output_text_section_
= os
;
5434 return deleted_bytes
;
5437 // Arm_output_section methods.
5439 // Create a stub group for input sections from BEGIN to END. OWNER
5440 // points to the input section to be the owner a new stub table.
5442 template<bool big_endian
>
5444 Arm_output_section
<big_endian
>::create_stub_group(
5445 Input_section_list::const_iterator begin
,
5446 Input_section_list::const_iterator end
,
5447 Input_section_list::const_iterator owner
,
5448 Target_arm
<big_endian
>* target
,
5449 std::vector
<Output_relaxed_input_section
*>* new_relaxed_sections
)
5451 // We use a different kind of relaxed section in an EXIDX section.
5452 // The static casting from Output_relaxed_input_section to
5453 // Arm_input_section is invalid in an EXIDX section. We are okay
5454 // because we should not be calling this for an EXIDX section.
5455 gold_assert(this->type() != elfcpp::SHT_ARM_EXIDX
);
5457 // Currently we convert ordinary input sections into relaxed sections only
5458 // at this point but we may want to support creating relaxed input section
5459 // very early. So we check here to see if owner is already a relaxed
5462 Arm_input_section
<big_endian
>* arm_input_section
;
5463 if (owner
->is_relaxed_input_section())
5466 Arm_input_section
<big_endian
>::as_arm_input_section(
5467 owner
->relaxed_input_section());
5471 gold_assert(owner
->is_input_section());
5472 // Create a new relaxed input section.
5474 target
->new_arm_input_section(owner
->relobj(), owner
->shndx());
5475 new_relaxed_sections
->push_back(arm_input_section
);
5478 // Create a stub table.
5479 Stub_table
<big_endian
>* stub_table
=
5480 target
->new_stub_table(arm_input_section
);
5482 arm_input_section
->set_stub_table(stub_table
);
5484 Input_section_list::const_iterator p
= begin
;
5485 Input_section_list::const_iterator prev_p
;
5487 // Look for input sections or relaxed input sections in [begin ... end].
5490 if (p
->is_input_section() || p
->is_relaxed_input_section())
5492 // The stub table information for input sections live
5493 // in their objects.
5494 Arm_relobj
<big_endian
>* arm_relobj
=
5495 Arm_relobj
<big_endian
>::as_arm_relobj(p
->relobj());
5496 arm_relobj
->set_stub_table(p
->shndx(), stub_table
);
5500 while (prev_p
!= end
);
5503 // Group input sections for stub generation. GROUP_SIZE is roughly the limit
5504 // of stub groups. We grow a stub group by adding input section until the
5505 // size is just below GROUP_SIZE. The last input section will be converted
5506 // into a stub table. If STUB_ALWAYS_AFTER_BRANCH is false, we also add
5507 // input section after the stub table, effectively double the group size.
5509 // This is similar to the group_sections() function in elf32-arm.c but is
5510 // implemented differently.
5512 template<bool big_endian
>
5514 Arm_output_section
<big_endian
>::group_sections(
5515 section_size_type group_size
,
5516 bool stubs_always_after_branch
,
5517 Target_arm
<big_endian
>* target
)
5519 // We only care about sections containing code.
5520 if ((this->flags() & elfcpp::SHF_EXECINSTR
) == 0)
5523 // States for grouping.
5526 // No group is being built.
5528 // A group is being built but the stub table is not found yet.
5529 // We keep group a stub group until the size is just under GROUP_SIZE.
5530 // The last input section in the group will be used as the stub table.
5531 FINDING_STUB_SECTION
,
5532 // A group is being built and we have already found a stub table.
5533 // We enter this state to grow a stub group by adding input section
5534 // after the stub table. This effectively doubles the group size.
5538 // Any newly created relaxed sections are stored here.
5539 std::vector
<Output_relaxed_input_section
*> new_relaxed_sections
;
5541 State state
= NO_GROUP
;
5542 section_size_type off
= 0;
5543 section_size_type group_begin_offset
= 0;
5544 section_size_type group_end_offset
= 0;
5545 section_size_type stub_table_end_offset
= 0;
5546 Input_section_list::const_iterator group_begin
=
5547 this->input_sections().end();
5548 Input_section_list::const_iterator stub_table
=
5549 this->input_sections().end();
5550 Input_section_list::const_iterator group_end
= this->input_sections().end();
5551 for (Input_section_list::const_iterator p
= this->input_sections().begin();
5552 p
!= this->input_sections().end();
5555 section_size_type section_begin_offset
=
5556 align_address(off
, p
->addralign());
5557 section_size_type section_end_offset
=
5558 section_begin_offset
+ p
->data_size();
5560 // Check to see if we should group the previously seens sections.
5566 case FINDING_STUB_SECTION
:
5567 // Adding this section makes the group larger than GROUP_SIZE.
5568 if (section_end_offset
- group_begin_offset
>= group_size
)
5570 if (stubs_always_after_branch
)
5572 gold_assert(group_end
!= this->input_sections().end());
5573 this->create_stub_group(group_begin
, group_end
, group_end
,
5574 target
, &new_relaxed_sections
);
5579 // But wait, there's more! Input sections up to
5580 // stub_group_size bytes after the stub table can be
5581 // handled by it too.
5582 state
= HAS_STUB_SECTION
;
5583 stub_table
= group_end
;
5584 stub_table_end_offset
= group_end_offset
;
5589 case HAS_STUB_SECTION
:
5590 // Adding this section makes the post stub-section group larger
5592 if (section_end_offset
- stub_table_end_offset
>= group_size
)
5594 gold_assert(group_end
!= this->input_sections().end());
5595 this->create_stub_group(group_begin
, group_end
, stub_table
,
5596 target
, &new_relaxed_sections
);
5605 // If we see an input section and currently there is no group, start
5606 // a new one. Skip any empty sections.
5607 if ((p
->is_input_section() || p
->is_relaxed_input_section())
5608 && (p
->relobj()->section_size(p
->shndx()) != 0))
5610 if (state
== NO_GROUP
)
5612 state
= FINDING_STUB_SECTION
;
5614 group_begin_offset
= section_begin_offset
;
5617 // Keep track of the last input section seen.
5619 group_end_offset
= section_end_offset
;
5622 off
= section_end_offset
;
5625 // Create a stub group for any ungrouped sections.
5626 if (state
== FINDING_STUB_SECTION
|| state
== HAS_STUB_SECTION
)
5628 gold_assert(group_end
!= this->input_sections().end());
5629 this->create_stub_group(group_begin
, group_end
,
5630 (state
== FINDING_STUB_SECTION
5633 target
, &new_relaxed_sections
);
5636 // Convert input section into relaxed input section in a batch.
5637 if (!new_relaxed_sections
.empty())
5638 this->convert_input_sections_to_relaxed_sections(new_relaxed_sections
);
5640 // Update the section offsets
5641 for (size_t i
= 0; i
< new_relaxed_sections
.size(); ++i
)
5643 Arm_relobj
<big_endian
>* arm_relobj
=
5644 Arm_relobj
<big_endian
>::as_arm_relobj(
5645 new_relaxed_sections
[i
]->relobj());
5646 unsigned int shndx
= new_relaxed_sections
[i
]->shndx();
5647 // Tell Arm_relobj that this input section is converted.
5648 arm_relobj
->convert_input_section_to_relaxed_section(shndx
);
5652 // Append non empty text sections in this to LIST in ascending
5653 // order of their position in this.
5655 template<bool big_endian
>
5657 Arm_output_section
<big_endian
>::append_text_sections_to_list(
5658 Text_section_list
* list
)
5660 // We only care about text sections.
5661 if ((this->flags() & elfcpp::SHF_EXECINSTR
) == 0)
5664 gold_assert((this->flags() & elfcpp::SHF_ALLOC
) != 0);
5666 for (Input_section_list::const_iterator p
= this->input_sections().begin();
5667 p
!= this->input_sections().end();
5670 // We only care about plain or relaxed input sections. We also
5671 // ignore any merged sections.
5672 if ((p
->is_input_section() || p
->is_relaxed_input_section())
5673 && p
->data_size() != 0)
5674 list
->push_back(Text_section_list::value_type(p
->relobj(),
5679 template<bool big_endian
>
5681 Arm_output_section
<big_endian
>::fix_exidx_coverage(
5683 const Text_section_list
& sorted_text_sections
,
5684 Symbol_table
* symtab
,
5685 bool merge_exidx_entries
)
5687 // We should only do this for the EXIDX output section.
5688 gold_assert(this->type() == elfcpp::SHT_ARM_EXIDX
);
5690 // We don't want the relaxation loop to undo these changes, so we discard
5691 // the current saved states and take another one after the fix-up.
5692 this->discard_states();
5694 // Remove all input sections.
5695 uint64_t address
= this->address();
5696 typedef std::list
<Output_section::Input_section
> Input_section_list
;
5697 Input_section_list input_sections
;
5698 this->reset_address_and_file_offset();
5699 this->get_input_sections(address
, std::string(""), &input_sections
);
5701 if (!this->input_sections().empty())
5702 gold_error(_("Found non-EXIDX input sections in EXIDX output section"));
5704 // Go through all the known input sections and record them.
5705 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_id_set
;
5706 typedef Unordered_map
<Section_id
, const Output_section::Input_section
*,
5707 Section_id_hash
> Text_to_exidx_map
;
5708 Text_to_exidx_map text_to_exidx_map
;
5709 for (Input_section_list::const_iterator p
= input_sections
.begin();
5710 p
!= input_sections
.end();
5713 // This should never happen. At this point, we should only see
5714 // plain EXIDX input sections.
5715 gold_assert(!p
->is_relaxed_input_section());
5716 text_to_exidx_map
[Section_id(p
->relobj(), p
->shndx())] = &(*p
);
5719 Arm_exidx_fixup
exidx_fixup(this, merge_exidx_entries
);
5721 // Go over the sorted text sections.
5722 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_id_set
;
5723 Section_id_set processed_input_sections
;
5724 for (Text_section_list::const_iterator p
= sorted_text_sections
.begin();
5725 p
!= sorted_text_sections
.end();
5728 Relobj
* relobj
= p
->first
;
5729 unsigned int shndx
= p
->second
;
5731 Arm_relobj
<big_endian
>* arm_relobj
=
5732 Arm_relobj
<big_endian
>::as_arm_relobj(relobj
);
5733 const Arm_exidx_input_section
* exidx_input_section
=
5734 arm_relobj
->exidx_input_section_by_link(shndx
);
5736 // If this text section has no EXIDX section, force an EXIDX_CANTUNWIND
5737 // entry pointing to the end of the last seen EXIDX section.
5738 if (exidx_input_section
== NULL
)
5740 exidx_fixup
.add_exidx_cantunwind_as_needed();
5744 Relobj
* exidx_relobj
= exidx_input_section
->relobj();
5745 unsigned int exidx_shndx
= exidx_input_section
->shndx();
5746 Section_id
sid(exidx_relobj
, exidx_shndx
);
5747 Text_to_exidx_map::const_iterator iter
= text_to_exidx_map
.find(sid
);
5748 if (iter
== text_to_exidx_map
.end())
5750 // This is odd. We have not seen this EXIDX input section before.
5751 // We cannot do fix-up. If we saw a SECTIONS clause in a script,
5752 // issue a warning instead. We assume the user knows what he
5753 // or she is doing. Otherwise, this is an error.
5754 if (layout
->script_options()->saw_sections_clause())
5755 gold_warning(_("unwinding may not work because EXIDX input section"
5756 " %u of %s is not in EXIDX output section"),
5757 exidx_shndx
, exidx_relobj
->name().c_str());
5759 gold_error(_("unwinding may not work because EXIDX input section"
5760 " %u of %s is not in EXIDX output section"),
5761 exidx_shndx
, exidx_relobj
->name().c_str());
5763 exidx_fixup
.add_exidx_cantunwind_as_needed();
5767 // Fix up coverage and append input section to output data list.
5768 Arm_exidx_section_offset_map
* section_offset_map
= NULL
;
5769 uint32_t deleted_bytes
=
5770 exidx_fixup
.process_exidx_section
<big_endian
>(exidx_input_section
,
5771 §ion_offset_map
);
5773 if (deleted_bytes
== exidx_input_section
->size())
5775 // The whole EXIDX section got merged. Remove it from output.
5776 gold_assert(section_offset_map
== NULL
);
5777 exidx_relobj
->set_output_section(exidx_shndx
, NULL
);
5779 // All local symbols defined in this input section will be dropped.
5780 // We need to adjust output local symbol count.
5781 arm_relobj
->set_output_local_symbol_count_needs_update();
5783 else if (deleted_bytes
> 0)
5785 // Some entries are merged. We need to convert this EXIDX input
5786 // section into a relaxed section.
5787 gold_assert(section_offset_map
!= NULL
);
5788 Arm_exidx_merged_section
* merged_section
=
5789 new Arm_exidx_merged_section(*exidx_input_section
,
5790 *section_offset_map
, deleted_bytes
);
5791 this->add_relaxed_input_section(merged_section
);
5792 arm_relobj
->convert_input_section_to_relaxed_section(exidx_shndx
);
5794 // All local symbols defined in discarded portions of this input
5795 // section will be dropped. We need to adjust output local symbol
5797 arm_relobj
->set_output_local_symbol_count_needs_update();
5801 // Just add back the EXIDX input section.
5802 gold_assert(section_offset_map
== NULL
);
5803 const Output_section::Input_section
* pis
= iter
->second
;
5804 gold_assert(pis
->is_input_section());
5805 this->add_script_input_section(*pis
);
5808 processed_input_sections
.insert(Section_id(exidx_relobj
, exidx_shndx
));
5811 // Insert an EXIDX_CANTUNWIND entry at the end of output if necessary.
5812 exidx_fixup
.add_exidx_cantunwind_as_needed();
5814 // Remove any known EXIDX input sections that are not processed.
5815 for (Input_section_list::const_iterator p
= input_sections
.begin();
5816 p
!= input_sections
.end();
5819 if (processed_input_sections
.find(Section_id(p
->relobj(), p
->shndx()))
5820 == processed_input_sections
.end())
5822 // We only discard a known EXIDX section because its linked
5823 // text section has been folded by ICF.
5824 Arm_relobj
<big_endian
>* arm_relobj
=
5825 Arm_relobj
<big_endian
>::as_arm_relobj(p
->relobj());
5826 const Arm_exidx_input_section
* exidx_input_section
=
5827 arm_relobj
->exidx_input_section_by_shndx(p
->shndx());
5828 gold_assert(exidx_input_section
!= NULL
);
5829 unsigned int text_shndx
= exidx_input_section
->link();
5830 gold_assert(symtab
->is_section_folded(p
->relobj(), text_shndx
));
5832 // Remove this from link. We also need to recount the
5834 p
->relobj()->set_output_section(p
->shndx(), NULL
);
5835 arm_relobj
->set_output_local_symbol_count_needs_update();
5839 // Link exidx output section to the first seen output section and
5840 // set correct entry size.
5841 this->set_link_section(exidx_fixup
.first_output_text_section());
5842 this->set_entsize(8);
5844 // Make changes permanent.
5845 this->save_states();
5846 this->set_section_offsets_need_adjustment();
5849 // Arm_relobj methods.
5851 // Determine if an input section is scannable for stub processing. SHDR is
5852 // the header of the section and SHNDX is the section index. OS is the output
5853 // section for the input section and SYMTAB is the global symbol table used to
5854 // look up ICF information.
5856 template<bool big_endian
>
5858 Arm_relobj
<big_endian
>::section_is_scannable(
5859 const elfcpp::Shdr
<32, big_endian
>& shdr
,
5861 const Output_section
* os
,
5862 const Symbol_table
*symtab
)
5864 // Skip any empty sections, unallocated sections or sections whose
5865 // type are not SHT_PROGBITS.
5866 if (shdr
.get_sh_size() == 0
5867 || (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) == 0
5868 || shdr
.get_sh_type() != elfcpp::SHT_PROGBITS
)
5871 // Skip any discarded or ICF'ed sections.
5872 if (os
== NULL
|| symtab
->is_section_folded(this, shndx
))
5875 // If this requires special offset handling, check to see if it is
5876 // a relaxed section. If this is not, then it is a merged section that
5877 // we cannot handle.
5878 if (this->is_output_section_offset_invalid(shndx
))
5880 const Output_relaxed_input_section
* poris
=
5881 os
->find_relaxed_input_section(this, shndx
);
5889 // Determine if we want to scan the SHNDX-th section for relocation stubs.
5890 // This is a helper for Arm_relobj::scan_sections_for_stubs() below.
5892 template<bool big_endian
>
5894 Arm_relobj
<big_endian
>::section_needs_reloc_stub_scanning(
5895 const elfcpp::Shdr
<32, big_endian
>& shdr
,
5896 const Relobj::Output_sections
& out_sections
,
5897 const Symbol_table
*symtab
,
5898 const unsigned char* pshdrs
)
5900 unsigned int sh_type
= shdr
.get_sh_type();
5901 if (sh_type
!= elfcpp::SHT_REL
&& sh_type
!= elfcpp::SHT_RELA
)
5904 // Ignore empty section.
5905 off_t sh_size
= shdr
.get_sh_size();
5909 // Ignore reloc section with unexpected symbol table. The
5910 // error will be reported in the final link.
5911 if (this->adjust_shndx(shdr
.get_sh_link()) != this->symtab_shndx())
5914 unsigned int reloc_size
;
5915 if (sh_type
== elfcpp::SHT_REL
)
5916 reloc_size
= elfcpp::Elf_sizes
<32>::rel_size
;
5918 reloc_size
= elfcpp::Elf_sizes
<32>::rela_size
;
5920 // Ignore reloc section with unexpected entsize or uneven size.
5921 // The error will be reported in the final link.
5922 if (reloc_size
!= shdr
.get_sh_entsize() || sh_size
% reloc_size
!= 0)
5925 // Ignore reloc section with bad info. This error will be
5926 // reported in the final link.
5927 unsigned int index
= this->adjust_shndx(shdr
.get_sh_info());
5928 if (index
>= this->shnum())
5931 const unsigned int shdr_size
= elfcpp::Elf_sizes
<32>::shdr_size
;
5932 const elfcpp::Shdr
<32, big_endian
> text_shdr(pshdrs
+ index
* shdr_size
);
5933 return this->section_is_scannable(text_shdr
, index
,
5934 out_sections
[index
], symtab
);
5937 // Return the output address of either a plain input section or a relaxed
5938 // input section. SHNDX is the section index. We define and use this
5939 // instead of calling Output_section::output_address because that is slow
5940 // for large output.
5942 template<bool big_endian
>
5944 Arm_relobj
<big_endian
>::simple_input_section_output_address(
5948 if (this->is_output_section_offset_invalid(shndx
))
5950 const Output_relaxed_input_section
* poris
=
5951 os
->find_relaxed_input_section(this, shndx
);
5952 // We do not handle merged sections here.
5953 gold_assert(poris
!= NULL
);
5954 return poris
->address();
5957 return os
->address() + this->get_output_section_offset(shndx
);
5960 // Determine if we want to scan the SHNDX-th section for non-relocation stubs.
5961 // This is a helper for Arm_relobj::scan_sections_for_stubs() below.
5963 template<bool big_endian
>
5965 Arm_relobj
<big_endian
>::section_needs_cortex_a8_stub_scanning(
5966 const elfcpp::Shdr
<32, big_endian
>& shdr
,
5969 const Symbol_table
* symtab
)
5971 if (!this->section_is_scannable(shdr
, shndx
, os
, symtab
))
5974 // If the section does not cross any 4K-boundaries, it does not need to
5976 Arm_address address
= this->simple_input_section_output_address(shndx
, os
);
5977 if ((address
& ~0xfffU
) == ((address
+ shdr
.get_sh_size() - 1) & ~0xfffU
))
5983 // Scan a section for Cortex-A8 workaround.
5985 template<bool big_endian
>
5987 Arm_relobj
<big_endian
>::scan_section_for_cortex_a8_erratum(
5988 const elfcpp::Shdr
<32, big_endian
>& shdr
,
5991 Target_arm
<big_endian
>* arm_target
)
5993 // Look for the first mapping symbol in this section. It should be
5995 Mapping_symbol_position
section_start(shndx
, 0);
5996 typename
Mapping_symbols_info::const_iterator p
=
5997 this->mapping_symbols_info_
.lower_bound(section_start
);
5999 // There are no mapping symbols for this section. Treat it as a data-only
6000 // section. Issue a warning if section is marked as containing
6002 if (p
== this->mapping_symbols_info_
.end() || p
->first
.first
!= shndx
)
6004 if ((this->section_flags(shndx
) & elfcpp::SHF_EXECINSTR
) != 0)
6005 gold_warning(_("cannot scan executable section %u of %s for Cortex-A8 "
6006 "erratum because it has no mapping symbols."),
6007 shndx
, this->name().c_str());
6011 Arm_address output_address
=
6012 this->simple_input_section_output_address(shndx
, os
);
6014 // Get the section contents.
6015 section_size_type input_view_size
= 0;
6016 const unsigned char* input_view
=
6017 this->section_contents(shndx
, &input_view_size
, false);
6019 // We need to go through the mapping symbols to determine what to
6020 // scan. There are two reasons. First, we should look at THUMB code and
6021 // THUMB code only. Second, we only want to look at the 4K-page boundary
6022 // to speed up the scanning.
6024 while (p
!= this->mapping_symbols_info_
.end()
6025 && p
->first
.first
== shndx
)
6027 typename
Mapping_symbols_info::const_iterator next
=
6028 this->mapping_symbols_info_
.upper_bound(p
->first
);
6030 // Only scan part of a section with THUMB code.
6031 if (p
->second
== 't')
6033 // Determine the end of this range.
6034 section_size_type span_start
=
6035 convert_to_section_size_type(p
->first
.second
);
6036 section_size_type span_end
;
6037 if (next
!= this->mapping_symbols_info_
.end()
6038 && next
->first
.first
== shndx
)
6039 span_end
= convert_to_section_size_type(next
->first
.second
);
6041 span_end
= convert_to_section_size_type(shdr
.get_sh_size());
6043 if (((span_start
+ output_address
) & ~0xfffUL
)
6044 != ((span_end
+ output_address
- 1) & ~0xfffUL
))
6046 arm_target
->scan_span_for_cortex_a8_erratum(this, shndx
,
6047 span_start
, span_end
,
6057 // Scan relocations for stub generation.
6059 template<bool big_endian
>
6061 Arm_relobj
<big_endian
>::scan_sections_for_stubs(
6062 Target_arm
<big_endian
>* arm_target
,
6063 const Symbol_table
* symtab
,
6064 const Layout
* layout
)
6066 unsigned int shnum
= this->shnum();
6067 const unsigned int shdr_size
= elfcpp::Elf_sizes
<32>::shdr_size
;
6069 // Read the section headers.
6070 const unsigned char* pshdrs
= this->get_view(this->elf_file()->shoff(),
6074 // To speed up processing, we set up hash tables for fast lookup of
6075 // input offsets to output addresses.
6076 this->initialize_input_to_output_maps();
6078 const Relobj::Output_sections
& out_sections(this->output_sections());
6080 Relocate_info
<32, big_endian
> relinfo
;
6081 relinfo
.symtab
= symtab
;
6082 relinfo
.layout
= layout
;
6083 relinfo
.object
= this;
6085 // Do relocation stubs scanning.
6086 const unsigned char* p
= pshdrs
+ shdr_size
;
6087 for (unsigned int i
= 1; i
< shnum
; ++i
, p
+= shdr_size
)
6089 const elfcpp::Shdr
<32, big_endian
> shdr(p
);
6090 if (this->section_needs_reloc_stub_scanning(shdr
, out_sections
, symtab
,
6093 unsigned int index
= this->adjust_shndx(shdr
.get_sh_info());
6094 Arm_address output_offset
= this->get_output_section_offset(index
);
6095 Arm_address output_address
;
6096 if (output_offset
!= invalid_address
)
6097 output_address
= out_sections
[index
]->address() + output_offset
;
6100 // Currently this only happens for a relaxed section.
6101 const Output_relaxed_input_section
* poris
=
6102 out_sections
[index
]->find_relaxed_input_section(this, index
);
6103 gold_assert(poris
!= NULL
);
6104 output_address
= poris
->address();
6107 // Get the relocations.
6108 const unsigned char* prelocs
= this->get_view(shdr
.get_sh_offset(),
6112 // Get the section contents. This does work for the case in which
6113 // we modify the contents of an input section. We need to pass the
6114 // output view under such circumstances.
6115 section_size_type input_view_size
= 0;
6116 const unsigned char* input_view
=
6117 this->section_contents(index
, &input_view_size
, false);
6119 relinfo
.reloc_shndx
= i
;
6120 relinfo
.data_shndx
= index
;
6121 unsigned int sh_type
= shdr
.get_sh_type();
6122 unsigned int reloc_size
;
6123 if (sh_type
== elfcpp::SHT_REL
)
6124 reloc_size
= elfcpp::Elf_sizes
<32>::rel_size
;
6126 reloc_size
= elfcpp::Elf_sizes
<32>::rela_size
;
6128 Output_section
* os
= out_sections
[index
];
6129 arm_target
->scan_section_for_stubs(&relinfo
, sh_type
, prelocs
,
6130 shdr
.get_sh_size() / reloc_size
,
6132 output_offset
== invalid_address
,
6133 input_view
, output_address
,
6138 // Do Cortex-A8 erratum stubs scanning. This has to be done for a section
6139 // after its relocation section, if there is one, is processed for
6140 // relocation stubs. Merging this loop with the one above would have been
6141 // complicated since we would have had to make sure that relocation stub
6142 // scanning is done first.
6143 if (arm_target
->fix_cortex_a8())
6145 const unsigned char* p
= pshdrs
+ shdr_size
;
6146 for (unsigned int i
= 1; i
< shnum
; ++i
, p
+= shdr_size
)
6148 const elfcpp::Shdr
<32, big_endian
> shdr(p
);
6149 if (this->section_needs_cortex_a8_stub_scanning(shdr
, i
,
6152 this->scan_section_for_cortex_a8_erratum(shdr
, i
, out_sections
[i
],
6157 // After we've done the relocations, we release the hash tables,
6158 // since we no longer need them.
6159 this->free_input_to_output_maps();
6162 // Count the local symbols. The ARM backend needs to know if a symbol
6163 // is a THUMB function or not. For global symbols, it is easy because
6164 // the Symbol object keeps the ELF symbol type. For local symbol it is
6165 // harder because we cannot access this information. So we override the
6166 // do_count_local_symbol in parent and scan local symbols to mark
6167 // THUMB functions. This is not the most efficient way but I do not want to
6168 // slow down other ports by calling a per symbol targer hook inside
6169 // Sized_relobj<size, big_endian>::do_count_local_symbols.
6171 template<bool big_endian
>
6173 Arm_relobj
<big_endian
>::do_count_local_symbols(
6174 Stringpool_template
<char>* pool
,
6175 Stringpool_template
<char>* dynpool
)
6177 // We need to fix-up the values of any local symbols whose type are
6180 // Ask parent to count the local symbols.
6181 Sized_relobj
<32, big_endian
>::do_count_local_symbols(pool
, dynpool
);
6182 const unsigned int loccount
= this->local_symbol_count();
6186 // Intialize the thumb function bit-vector.
6187 std::vector
<bool> empty_vector(loccount
, false);
6188 this->local_symbol_is_thumb_function_
.swap(empty_vector
);
6190 // Read the symbol table section header.
6191 const unsigned int symtab_shndx
= this->symtab_shndx();
6192 elfcpp::Shdr
<32, big_endian
>
6193 symtabshdr(this, this->elf_file()->section_header(symtab_shndx
));
6194 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
6196 // Read the local symbols.
6197 const int sym_size
=elfcpp::Elf_sizes
<32>::sym_size
;
6198 gold_assert(loccount
== symtabshdr
.get_sh_info());
6199 off_t locsize
= loccount
* sym_size
;
6200 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
6201 locsize
, true, true);
6203 // For mapping symbol processing, we need to read the symbol names.
6204 unsigned int strtab_shndx
= this->adjust_shndx(symtabshdr
.get_sh_link());
6205 if (strtab_shndx
>= this->shnum())
6207 this->error(_("invalid symbol table name index: %u"), strtab_shndx
);
6211 elfcpp::Shdr
<32, big_endian
>
6212 strtabshdr(this, this->elf_file()->section_header(strtab_shndx
));
6213 if (strtabshdr
.get_sh_type() != elfcpp::SHT_STRTAB
)
6215 this->error(_("symbol table name section has wrong type: %u"),
6216 static_cast<unsigned int>(strtabshdr
.get_sh_type()));
6219 const char* pnames
=
6220 reinterpret_cast<const char*>(this->get_view(strtabshdr
.get_sh_offset(),
6221 strtabshdr
.get_sh_size(),
6224 // Loop over the local symbols and mark any local symbols pointing
6225 // to THUMB functions.
6227 // Skip the first dummy symbol.
6229 typename Sized_relobj
<32, big_endian
>::Local_values
* plocal_values
=
6230 this->local_values();
6231 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
6233 elfcpp::Sym
<32, big_endian
> sym(psyms
);
6234 elfcpp::STT st_type
= sym
.get_st_type();
6235 Symbol_value
<32>& lv((*plocal_values
)[i
]);
6236 Arm_address input_value
= lv
.input_value();
6238 // Check to see if this is a mapping symbol.
6239 const char* sym_name
= pnames
+ sym
.get_st_name();
6240 if (Target_arm
<big_endian
>::is_mapping_symbol_name(sym_name
))
6243 unsigned int input_shndx
=
6244 this->adjust_sym_shndx(i
, sym
.get_st_shndx(), &is_ordinary
);
6245 gold_assert(is_ordinary
);
6247 // Strip of LSB in case this is a THUMB symbol.
6248 Mapping_symbol_position
msp(input_shndx
, input_value
& ~1U);
6249 this->mapping_symbols_info_
[msp
] = sym_name
[1];
6252 if (st_type
== elfcpp::STT_ARM_TFUNC
6253 || (st_type
== elfcpp::STT_FUNC
&& ((input_value
& 1) != 0)))
6255 // This is a THUMB function. Mark this and canonicalize the
6256 // symbol value by setting LSB.
6257 this->local_symbol_is_thumb_function_
[i
] = true;
6258 if ((input_value
& 1) == 0)
6259 lv
.set_input_value(input_value
| 1);
6264 // Relocate sections.
6265 template<bool big_endian
>
6267 Arm_relobj
<big_endian
>::do_relocate_sections(
6268 const Symbol_table
* symtab
,
6269 const Layout
* layout
,
6270 const unsigned char* pshdrs
,
6271 typename Sized_relobj
<32, big_endian
>::Views
* pviews
)
6273 // Call parent to relocate sections.
6274 Sized_relobj
<32, big_endian
>::do_relocate_sections(symtab
, layout
, pshdrs
,
6277 // We do not generate stubs if doing a relocatable link.
6278 if (parameters
->options().relocatable())
6281 // Relocate stub tables.
6282 unsigned int shnum
= this->shnum();
6284 Target_arm
<big_endian
>* arm_target
=
6285 Target_arm
<big_endian
>::default_target();
6287 Relocate_info
<32, big_endian
> relinfo
;
6288 relinfo
.symtab
= symtab
;
6289 relinfo
.layout
= layout
;
6290 relinfo
.object
= this;
6292 for (unsigned int i
= 1; i
< shnum
; ++i
)
6294 Arm_input_section
<big_endian
>* arm_input_section
=
6295 arm_target
->find_arm_input_section(this, i
);
6297 if (arm_input_section
!= NULL
6298 && arm_input_section
->is_stub_table_owner()
6299 && !arm_input_section
->stub_table()->empty())
6301 // We cannot discard a section if it owns a stub table.
6302 Output_section
* os
= this->output_section(i
);
6303 gold_assert(os
!= NULL
);
6305 relinfo
.reloc_shndx
= elfcpp::SHN_UNDEF
;
6306 relinfo
.reloc_shdr
= NULL
;
6307 relinfo
.data_shndx
= i
;
6308 relinfo
.data_shdr
= pshdrs
+ i
* elfcpp::Elf_sizes
<32>::shdr_size
;
6310 gold_assert((*pviews
)[i
].view
!= NULL
);
6312 // We are passed the output section view. Adjust it to cover the
6314 Stub_table
<big_endian
>* stub_table
= arm_input_section
->stub_table();
6315 gold_assert((stub_table
->address() >= (*pviews
)[i
].address
)
6316 && ((stub_table
->address() + stub_table
->data_size())
6317 <= (*pviews
)[i
].address
+ (*pviews
)[i
].view_size
));
6319 off_t offset
= stub_table
->address() - (*pviews
)[i
].address
;
6320 unsigned char* view
= (*pviews
)[i
].view
+ offset
;
6321 Arm_address address
= stub_table
->address();
6322 section_size_type view_size
= stub_table
->data_size();
6324 stub_table
->relocate_stubs(&relinfo
, arm_target
, os
, view
, address
,
6328 // Apply Cortex A8 workaround if applicable.
6329 if (this->section_has_cortex_a8_workaround(i
))
6331 unsigned char* view
= (*pviews
)[i
].view
;
6332 Arm_address view_address
= (*pviews
)[i
].address
;
6333 section_size_type view_size
= (*pviews
)[i
].view_size
;
6334 Stub_table
<big_endian
>* stub_table
= this->stub_tables_
[i
];
6336 // Adjust view to cover section.
6337 Output_section
* os
= this->output_section(i
);
6338 gold_assert(os
!= NULL
);
6339 Arm_address section_address
=
6340 this->simple_input_section_output_address(i
, os
);
6341 uint64_t section_size
= this->section_size(i
);
6343 gold_assert(section_address
>= view_address
6344 && ((section_address
+ section_size
)
6345 <= (view_address
+ view_size
)));
6347 unsigned char* section_view
= view
+ (section_address
- view_address
);
6349 // Apply the Cortex-A8 workaround to the output address range
6350 // corresponding to this input section.
6351 stub_table
->apply_cortex_a8_workaround_to_address_range(
6360 // Find the linked text section of an EXIDX section by looking the the first
6361 // relocation. 4.4.1 of the EHABI specifications says that an EXIDX section
6362 // must be linked to to its associated code section via the sh_link field of
6363 // its section header. However, some tools are broken and the link is not
6364 // always set. LD just drops such an EXIDX section silently, causing the
6365 // associated code not unwindabled. Here we try a little bit harder to
6366 // discover the linked code section.
6368 // PSHDR points to the section header of a relocation section of an EXIDX
6369 // section. If we can find a linked text section, return true and
6370 // store the text section index in the location PSHNDX. Otherwise
6373 template<bool big_endian
>
6375 Arm_relobj
<big_endian
>::find_linked_text_section(
6376 const unsigned char* pshdr
,
6377 const unsigned char* psyms
,
6378 unsigned int* pshndx
)
6380 elfcpp::Shdr
<32, big_endian
> shdr(pshdr
);
6382 // If there is no relocation, we cannot find the linked text section.
6384 if (shdr
.get_sh_type() == elfcpp::SHT_REL
)
6385 reloc_size
= elfcpp::Elf_sizes
<32>::rel_size
;
6387 reloc_size
= elfcpp::Elf_sizes
<32>::rela_size
;
6388 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
6390 // Get the relocations.
6391 const unsigned char* prelocs
=
6392 this->get_view(shdr
.get_sh_offset(), shdr
.get_sh_size(), true, false);
6394 // Find the REL31 relocation for the first word of the first EXIDX entry.
6395 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
6397 Arm_address r_offset
;
6398 typename
elfcpp::Elf_types
<32>::Elf_WXword r_info
;
6399 if (shdr
.get_sh_type() == elfcpp::SHT_REL
)
6401 typename
elfcpp::Rel
<32, big_endian
> reloc(prelocs
);
6402 r_info
= reloc
.get_r_info();
6403 r_offset
= reloc
.get_r_offset();
6407 typename
elfcpp::Rela
<32, big_endian
> reloc(prelocs
);
6408 r_info
= reloc
.get_r_info();
6409 r_offset
= reloc
.get_r_offset();
6412 unsigned int r_type
= elfcpp::elf_r_type
<32>(r_info
);
6413 if (r_type
!= elfcpp::R_ARM_PREL31
&& r_type
!= elfcpp::R_ARM_SBREL31
)
6416 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(r_info
);
6418 || r_sym
>= this->local_symbol_count()
6422 // This is the relocation for the first word of the first EXIDX entry.
6423 // We expect to see a local section symbol.
6424 const int sym_size
= elfcpp::Elf_sizes
<32>::sym_size
;
6425 elfcpp::Sym
<32, big_endian
> sym(psyms
+ r_sym
* sym_size
);
6426 if (sym
.get_st_type() == elfcpp::STT_SECTION
)
6430 this->adjust_sym_shndx(r_sym
, sym
.get_st_shndx(), &is_ordinary
);
6431 gold_assert(is_ordinary
);
6441 // Make an EXIDX input section object for an EXIDX section whose index is
6442 // SHNDX. SHDR is the section header of the EXIDX section and TEXT_SHNDX
6443 // is the section index of the linked text section.
6445 template<bool big_endian
>
6447 Arm_relobj
<big_endian
>::make_exidx_input_section(
6449 const elfcpp::Shdr
<32, big_endian
>& shdr
,
6450 unsigned int text_shndx
)
6452 // Issue an error and ignore this EXIDX section if it points to a text
6453 // section already has an EXIDX section.
6454 if (this->exidx_section_map_
[text_shndx
] != NULL
)
6456 gold_error(_("EXIDX sections %u and %u both link to text section %u "
6458 shndx
, this->exidx_section_map_
[text_shndx
]->shndx(),
6459 text_shndx
, this->name().c_str());
6463 // Create an Arm_exidx_input_section object for this EXIDX section.
6464 Arm_exidx_input_section
* exidx_input_section
=
6465 new Arm_exidx_input_section(this, shndx
, text_shndx
, shdr
.get_sh_size(),
6466 shdr
.get_sh_addralign());
6467 this->exidx_section_map_
[text_shndx
] = exidx_input_section
;
6469 // Also map the EXIDX section index to this.
6470 gold_assert(this->exidx_section_map_
[shndx
] == NULL
);
6471 this->exidx_section_map_
[shndx
] = exidx_input_section
;
6474 // Read the symbol information.
6476 template<bool big_endian
>
6478 Arm_relobj
<big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
6480 // Call parent class to read symbol information.
6481 Sized_relobj
<32, big_endian
>::do_read_symbols(sd
);
6483 // If this input file is a binary file, it has no processor
6484 // specific flags and attributes section.
6485 Input_file::Format format
= this->input_file()->format();
6486 if (format
!= Input_file::FORMAT_ELF
)
6488 gold_assert(format
== Input_file::FORMAT_BINARY
);
6489 this->merge_flags_and_attributes_
= false;
6493 // Read processor-specific flags in ELF file header.
6494 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
6495 elfcpp::Elf_sizes
<32>::ehdr_size
,
6497 elfcpp::Ehdr
<32, big_endian
> ehdr(pehdr
);
6498 this->processor_specific_flags_
= ehdr
.get_e_flags();
6500 // Go over the section headers and look for .ARM.attributes and .ARM.exidx
6502 std::vector
<unsigned int> deferred_exidx_sections
;
6503 const size_t shdr_size
= elfcpp::Elf_sizes
<32>::shdr_size
;
6504 const unsigned char* pshdrs
= sd
->section_headers
->data();
6505 const unsigned char *ps
= pshdrs
+ shdr_size
;
6506 bool must_merge_flags_and_attributes
= false;
6507 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
6509 elfcpp::Shdr
<32, big_endian
> shdr(ps
);
6511 // Sometimes an object has no contents except the section name string
6512 // table and an empty symbol table with the undefined symbol. We
6513 // don't want to merge processor-specific flags from such an object.
6514 if (shdr
.get_sh_type() == elfcpp::SHT_SYMTAB
)
6516 // Symbol table is not empty.
6517 const elfcpp::Elf_types
<32>::Elf_WXword sym_size
=
6518 elfcpp::Elf_sizes
<32>::sym_size
;
6519 if (shdr
.get_sh_size() > sym_size
)
6520 must_merge_flags_and_attributes
= true;
6522 else if (shdr
.get_sh_type() != elfcpp::SHT_STRTAB
)
6523 // If this is neither an empty symbol table nor a string table,
6525 must_merge_flags_and_attributes
= true;
6527 if (shdr
.get_sh_type() == elfcpp::SHT_ARM_ATTRIBUTES
)
6529 gold_assert(this->attributes_section_data_
== NULL
);
6530 section_offset_type section_offset
= shdr
.get_sh_offset();
6531 section_size_type section_size
=
6532 convert_to_section_size_type(shdr
.get_sh_size());
6533 File_view
* view
= this->get_lasting_view(section_offset
,
6534 section_size
, true, false);
6535 this->attributes_section_data_
=
6536 new Attributes_section_data(view
->data(), section_size
);
6538 else if (shdr
.get_sh_type() == elfcpp::SHT_ARM_EXIDX
)
6540 unsigned int text_shndx
= this->adjust_shndx(shdr
.get_sh_link());
6541 if (text_shndx
>= this->shnum())
6542 gold_error(_("EXIDX section %u linked to invalid section %u"),
6544 else if (text_shndx
== elfcpp::SHN_UNDEF
)
6545 deferred_exidx_sections
.push_back(i
);
6547 this->make_exidx_input_section(i
, shdr
, text_shndx
);
6552 if (!must_merge_flags_and_attributes
)
6554 this->merge_flags_and_attributes_
= false;
6558 // Some tools are broken and they do not set the link of EXIDX sections.
6559 // We look at the first relocation to figure out the linked sections.
6560 if (!deferred_exidx_sections
.empty())
6562 // We need to go over the section headers again to find the mapping
6563 // from sections being relocated to their relocation sections. This is
6564 // a bit inefficient as we could do that in the loop above. However,
6565 // we do not expect any deferred EXIDX sections normally. So we do not
6566 // want to slow down the most common path.
6567 typedef Unordered_map
<unsigned int, unsigned int> Reloc_map
;
6568 Reloc_map reloc_map
;
6569 ps
= pshdrs
+ shdr_size
;
6570 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
6572 elfcpp::Shdr
<32, big_endian
> shdr(ps
);
6573 elfcpp::Elf_Word sh_type
= shdr
.get_sh_type();
6574 if (sh_type
== elfcpp::SHT_REL
|| sh_type
== elfcpp::SHT_RELA
)
6576 unsigned int info_shndx
= this->adjust_shndx(shdr
.get_sh_info());
6577 if (info_shndx
>= this->shnum())
6578 gold_error(_("relocation section %u has invalid info %u"),
6580 Reloc_map::value_type
value(info_shndx
, i
);
6581 std::pair
<Reloc_map::iterator
, bool> result
=
6582 reloc_map
.insert(value
);
6584 gold_error(_("section %u has multiple relocation sections "
6586 info_shndx
, i
, reloc_map
[info_shndx
]);
6590 // Read the symbol table section header.
6591 const unsigned int symtab_shndx
= this->symtab_shndx();
6592 elfcpp::Shdr
<32, big_endian
>
6593 symtabshdr(this, this->elf_file()->section_header(symtab_shndx
));
6594 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
6596 // Read the local symbols.
6597 const int sym_size
=elfcpp::Elf_sizes
<32>::sym_size
;
6598 const unsigned int loccount
= this->local_symbol_count();
6599 gold_assert(loccount
== symtabshdr
.get_sh_info());
6600 off_t locsize
= loccount
* sym_size
;
6601 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
6602 locsize
, true, true);
6604 // Process the deferred EXIDX sections.
6605 for(unsigned int i
= 0; i
< deferred_exidx_sections
.size(); ++i
)
6607 unsigned int shndx
= deferred_exidx_sections
[i
];
6608 elfcpp::Shdr
<32, big_endian
> shdr(pshdrs
+ shndx
* shdr_size
);
6609 unsigned int text_shndx
;
6610 Reloc_map::const_iterator it
= reloc_map
.find(shndx
);
6611 if (it
!= reloc_map
.end()
6612 && find_linked_text_section(pshdrs
+ it
->second
* shdr_size
,
6613 psyms
, &text_shndx
))
6614 this->make_exidx_input_section(shndx
, shdr
, text_shndx
);
6616 gold_error(_("EXIDX section %u has no linked text section."),
6622 // Process relocations for garbage collection. The ARM target uses .ARM.exidx
6623 // sections for unwinding. These sections are referenced implicitly by
6624 // text sections linked in the section headers. If we ignore these implict
6625 // references, the .ARM.exidx sections and any .ARM.extab sections they use
6626 // will be garbage-collected incorrectly. Hence we override the same function
6627 // in the base class to handle these implicit references.
6629 template<bool big_endian
>
6631 Arm_relobj
<big_endian
>::do_gc_process_relocs(Symbol_table
* symtab
,
6633 Read_relocs_data
* rd
)
6635 // First, call base class method to process relocations in this object.
6636 Sized_relobj
<32, big_endian
>::do_gc_process_relocs(symtab
, layout
, rd
);
6638 // If --gc-sections is not specified, there is nothing more to do.
6639 // This happens when --icf is used but --gc-sections is not.
6640 if (!parameters
->options().gc_sections())
6643 unsigned int shnum
= this->shnum();
6644 const unsigned int shdr_size
= elfcpp::Elf_sizes
<32>::shdr_size
;
6645 const unsigned char* pshdrs
= this->get_view(this->elf_file()->shoff(),
6649 // Scan section headers for sections of type SHT_ARM_EXIDX. Add references
6650 // to these from the linked text sections.
6651 const unsigned char* ps
= pshdrs
+ shdr_size
;
6652 for (unsigned int i
= 1; i
< shnum
; ++i
, ps
+= shdr_size
)
6654 elfcpp::Shdr
<32, big_endian
> shdr(ps
);
6655 if (shdr
.get_sh_type() == elfcpp::SHT_ARM_EXIDX
)
6657 // Found an .ARM.exidx section, add it to the set of reachable
6658 // sections from its linked text section.
6659 unsigned int text_shndx
= this->adjust_shndx(shdr
.get_sh_link());
6660 symtab
->gc()->add_reference(this, text_shndx
, this, i
);
6665 // Update output local symbol count. Owing to EXIDX entry merging, some local
6666 // symbols will be removed in output. Adjust output local symbol count
6667 // accordingly. We can only changed the static output local symbol count. It
6668 // is too late to change the dynamic symbols.
6670 template<bool big_endian
>
6672 Arm_relobj
<big_endian
>::update_output_local_symbol_count()
6674 // Caller should check that this needs updating. We want caller checking
6675 // because output_local_symbol_count_needs_update() is most likely inlined.
6676 gold_assert(this->output_local_symbol_count_needs_update_
);
6678 gold_assert(this->symtab_shndx() != -1U);
6679 if (this->symtab_shndx() == 0)
6681 // This object has no symbols. Weird but legal.
6685 // Read the symbol table section header.
6686 const unsigned int symtab_shndx
= this->symtab_shndx();
6687 elfcpp::Shdr
<32, big_endian
>
6688 symtabshdr(this, this->elf_file()->section_header(symtab_shndx
));
6689 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
6691 // Read the local symbols.
6692 const int sym_size
= elfcpp::Elf_sizes
<32>::sym_size
;
6693 const unsigned int loccount
= this->local_symbol_count();
6694 gold_assert(loccount
== symtabshdr
.get_sh_info());
6695 off_t locsize
= loccount
* sym_size
;
6696 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
6697 locsize
, true, true);
6699 // Loop over the local symbols.
6701 typedef typename Sized_relobj
<32, big_endian
>::Output_sections
6703 const Output_sections
& out_sections(this->output_sections());
6704 unsigned int shnum
= this->shnum();
6705 unsigned int count
= 0;
6706 // Skip the first, dummy, symbol.
6708 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
6710 elfcpp::Sym
<32, big_endian
> sym(psyms
);
6712 Symbol_value
<32>& lv((*this->local_values())[i
]);
6714 // This local symbol was already discarded by do_count_local_symbols.
6715 if (lv
.is_output_symtab_index_set() && !lv
.has_output_symtab_entry())
6719 unsigned int shndx
= this->adjust_sym_shndx(i
, sym
.get_st_shndx(),
6724 Output_section
* os
= out_sections
[shndx
];
6726 // This local symbol no longer has an output section. Discard it.
6729 lv
.set_no_output_symtab_entry();
6733 // Currently we only discard parts of EXIDX input sections.
6734 // We explicitly check for a merged EXIDX input section to avoid
6735 // calling Output_section_data::output_offset unless necessary.
6736 if ((this->get_output_section_offset(shndx
) == invalid_address
)
6737 && (this->exidx_input_section_by_shndx(shndx
) != NULL
))
6739 section_offset_type output_offset
=
6740 os
->output_offset(this, shndx
, lv
.input_value());
6741 if (output_offset
== -1)
6743 // This symbol is defined in a part of an EXIDX input section
6744 // that is discarded due to entry merging.
6745 lv
.set_no_output_symtab_entry();
6754 this->set_output_local_symbol_count(count
);
6755 this->output_local_symbol_count_needs_update_
= false;
6758 // Arm_dynobj methods.
6760 // Read the symbol information.
6762 template<bool big_endian
>
6764 Arm_dynobj
<big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
6766 // Call parent class to read symbol information.
6767 Sized_dynobj
<32, big_endian
>::do_read_symbols(sd
);
6769 // Read processor-specific flags in ELF file header.
6770 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
6771 elfcpp::Elf_sizes
<32>::ehdr_size
,
6773 elfcpp::Ehdr
<32, big_endian
> ehdr(pehdr
);
6774 this->processor_specific_flags_
= ehdr
.get_e_flags();
6776 // Read the attributes section if there is one.
6777 // We read from the end because gas seems to put it near the end of
6778 // the section headers.
6779 const size_t shdr_size
= elfcpp::Elf_sizes
<32>::shdr_size
;
6780 const unsigned char *ps
=
6781 sd
->section_headers
->data() + shdr_size
* (this->shnum() - 1);
6782 for (unsigned int i
= this->shnum(); i
> 0; --i
, ps
-= shdr_size
)
6784 elfcpp::Shdr
<32, big_endian
> shdr(ps
);
6785 if (shdr
.get_sh_type() == elfcpp::SHT_ARM_ATTRIBUTES
)
6787 section_offset_type section_offset
= shdr
.get_sh_offset();
6788 section_size_type section_size
=
6789 convert_to_section_size_type(shdr
.get_sh_size());
6790 File_view
* view
= this->get_lasting_view(section_offset
,
6791 section_size
, true, false);
6792 this->attributes_section_data_
=
6793 new Attributes_section_data(view
->data(), section_size
);
6799 // Stub_addend_reader methods.
6801 // Read the addend of a REL relocation of type R_TYPE at VIEW.
6803 template<bool big_endian
>
6804 elfcpp::Elf_types
<32>::Elf_Swxword
6805 Stub_addend_reader
<elfcpp::SHT_REL
, big_endian
>::operator()(
6806 unsigned int r_type
,
6807 const unsigned char* view
,
6808 const typename Reloc_types
<elfcpp::SHT_REL
, 32, big_endian
>::Reloc
&) const
6810 typedef struct Arm_relocate_functions
<big_endian
> RelocFuncs
;
6814 case elfcpp::R_ARM_CALL
:
6815 case elfcpp::R_ARM_JUMP24
:
6816 case elfcpp::R_ARM_PLT32
:
6818 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
6819 const Valtype
* wv
= reinterpret_cast<const Valtype
*>(view
);
6820 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
6821 return utils::sign_extend
<26>(val
<< 2);
6824 case elfcpp::R_ARM_THM_CALL
:
6825 case elfcpp::R_ARM_THM_JUMP24
:
6826 case elfcpp::R_ARM_THM_XPC22
:
6828 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
6829 const Valtype
* wv
= reinterpret_cast<const Valtype
*>(view
);
6830 Valtype upper_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
6831 Valtype lower_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
6832 return RelocFuncs::thumb32_branch_offset(upper_insn
, lower_insn
);
6835 case elfcpp::R_ARM_THM_JUMP19
:
6837 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
6838 const Valtype
* wv
= reinterpret_cast<const Valtype
*>(view
);
6839 Valtype upper_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
6840 Valtype lower_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
6841 return RelocFuncs::thumb32_cond_branch_offset(upper_insn
, lower_insn
);
6849 // Arm_output_data_got methods.
6851 // Add a GOT pair for R_ARM_TLS_GD32. The creates a pair of GOT entries.
6852 // The first one is initialized to be 1, which is the module index for
6853 // the main executable and the second one 0. A reloc of the type
6854 // R_ARM_TLS_DTPOFF32 will be created for the second GOT entry and will
6855 // be applied by gold. GSYM is a global symbol.
6857 template<bool big_endian
>
6859 Arm_output_data_got
<big_endian
>::add_tls_gd32_with_static_reloc(
6860 unsigned int got_type
,
6863 if (gsym
->has_got_offset(got_type
))
6866 // We are doing a static link. Just mark it as belong to module 1,
6868 unsigned int got_offset
= this->add_constant(1);
6869 gsym
->set_got_offset(got_type
, got_offset
);
6870 got_offset
= this->add_constant(0);
6871 this->static_relocs_
.push_back(Static_reloc(got_offset
,
6872 elfcpp::R_ARM_TLS_DTPOFF32
,
6876 // Same as the above but for a local symbol.
6878 template<bool big_endian
>
6880 Arm_output_data_got
<big_endian
>::add_tls_gd32_with_static_reloc(
6881 unsigned int got_type
,
6882 Sized_relobj
<32, big_endian
>* object
,
6885 if (object
->local_has_got_offset(index
, got_type
))
6888 // We are doing a static link. Just mark it as belong to module 1,
6890 unsigned int got_offset
= this->add_constant(1);
6891 object
->set_local_got_offset(index
, got_type
, got_offset
);
6892 got_offset
= this->add_constant(0);
6893 this->static_relocs_
.push_back(Static_reloc(got_offset
,
6894 elfcpp::R_ARM_TLS_DTPOFF32
,
6898 template<bool big_endian
>
6900 Arm_output_data_got
<big_endian
>::do_write(Output_file
* of
)
6902 // Call parent to write out GOT.
6903 Output_data_got
<32, big_endian
>::do_write(of
);
6905 // We are done if there is no fix up.
6906 if (this->static_relocs_
.empty())
6909 gold_assert(parameters
->doing_static_link());
6911 const off_t offset
= this->offset();
6912 const section_size_type oview_size
=
6913 convert_to_section_size_type(this->data_size());
6914 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6916 Output_segment
* tls_segment
= this->layout_
->tls_segment();
6917 gold_assert(tls_segment
!= NULL
);
6919 // The thread pointer $tp points to the TCB, which is followed by the
6920 // TLS. So we need to adjust $tp relative addressing by this amount.
6921 Arm_address aligned_tcb_size
=
6922 align_address(ARM_TCB_SIZE
, tls_segment
->maximum_alignment());
6924 for (size_t i
= 0; i
< this->static_relocs_
.size(); ++i
)
6926 Static_reloc
& reloc(this->static_relocs_
[i
]);
6929 if (!reloc
.symbol_is_global())
6931 Sized_relobj
<32, big_endian
>* object
= reloc
.relobj();
6932 const Symbol_value
<32>* psymval
=
6933 reloc
.relobj()->local_symbol(reloc
.index());
6935 // We are doing static linking. Issue an error and skip this
6936 // relocation if the symbol is undefined or in a discarded_section.
6938 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
6939 if ((shndx
== elfcpp::SHN_UNDEF
)
6941 && shndx
!= elfcpp::SHN_UNDEF
6942 && !object
->is_section_included(shndx
)
6943 && !this->symbol_table_
->is_section_folded(object
, shndx
)))
6945 gold_error(_("undefined or discarded local symbol %u from "
6946 " object %s in GOT"),
6947 reloc
.index(), reloc
.relobj()->name().c_str());
6951 value
= psymval
->value(object
, 0);
6955 const Symbol
* gsym
= reloc
.symbol();
6956 gold_assert(gsym
!= NULL
);
6957 if (gsym
->is_forwarder())
6958 gsym
= this->symbol_table_
->resolve_forwards(gsym
);
6960 // We are doing static linking. Issue an error and skip this
6961 // relocation if the symbol is undefined or in a discarded_section
6962 // unless it is a weakly_undefined symbol.
6963 if ((gsym
->is_defined_in_discarded_section()
6964 || gsym
->is_undefined())
6965 && !gsym
->is_weak_undefined())
6967 gold_error(_("undefined or discarded symbol %s in GOT"),
6972 if (!gsym
->is_weak_undefined())
6974 const Sized_symbol
<32>* sym
=
6975 static_cast<const Sized_symbol
<32>*>(gsym
);
6976 value
= sym
->value();
6982 unsigned got_offset
= reloc
.got_offset();
6983 gold_assert(got_offset
< oview_size
);
6985 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
6986 Valtype
* wv
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6988 switch (reloc
.r_type())
6990 case elfcpp::R_ARM_TLS_DTPOFF32
:
6993 case elfcpp::R_ARM_TLS_TPOFF32
:
6994 x
= value
+ aligned_tcb_size
;
6999 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
7002 of
->write_output_view(offset
, oview_size
, oview
);
7005 // A class to handle the PLT data.
7007 template<bool big_endian
>
7008 class Output_data_plt_arm
: public Output_section_data
7011 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, big_endian
>
7014 Output_data_plt_arm(Layout
*, Output_data_space
*);
7016 // Add an entry to the PLT.
7018 add_entry(Symbol
* gsym
);
7020 // Return the .rel.plt section data.
7021 const Reloc_section
*
7023 { return this->rel_
; }
7027 do_adjust_output_section(Output_section
* os
);
7029 // Write to a map file.
7031 do_print_to_mapfile(Mapfile
* mapfile
) const
7032 { mapfile
->print_output_data(this, _("** PLT")); }
7035 // Template for the first PLT entry.
7036 static const uint32_t first_plt_entry
[5];
7038 // Template for subsequent PLT entries.
7039 static const uint32_t plt_entry
[3];
7041 // Set the final size.
7043 set_final_data_size()
7045 this->set_data_size(sizeof(first_plt_entry
)
7046 + this->count_
* sizeof(plt_entry
));
7049 // Write out the PLT data.
7051 do_write(Output_file
*);
7053 // The reloc section.
7054 Reloc_section
* rel_
;
7055 // The .got.plt section.
7056 Output_data_space
* got_plt_
;
7057 // The number of PLT entries.
7058 unsigned int count_
;
7061 // Create the PLT section. The ordinary .got section is an argument,
7062 // since we need to refer to the start. We also create our own .got
7063 // section just for PLT entries.
7065 template<bool big_endian
>
7066 Output_data_plt_arm
<big_endian
>::Output_data_plt_arm(Layout
* layout
,
7067 Output_data_space
* got_plt
)
7068 : Output_section_data(4), got_plt_(got_plt
), count_(0)
7070 this->rel_
= new Reloc_section(false);
7071 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
7072 elfcpp::SHF_ALLOC
, this->rel_
, true, false,
7076 template<bool big_endian
>
7078 Output_data_plt_arm
<big_endian
>::do_adjust_output_section(Output_section
* os
)
7083 // Add an entry to the PLT.
7085 template<bool big_endian
>
7087 Output_data_plt_arm
<big_endian
>::add_entry(Symbol
* gsym
)
7089 gold_assert(!gsym
->has_plt_offset());
7091 // Note that when setting the PLT offset we skip the initial
7092 // reserved PLT entry.
7093 gsym
->set_plt_offset((this->count_
) * sizeof(plt_entry
)
7094 + sizeof(first_plt_entry
));
7098 section_offset_type got_offset
= this->got_plt_
->current_data_size();
7100 // Every PLT entry needs a GOT entry which points back to the PLT
7101 // entry (this will be changed by the dynamic linker, normally
7102 // lazily when the function is called).
7103 this->got_plt_
->set_current_data_size(got_offset
+ 4);
7105 // Every PLT entry needs a reloc.
7106 gsym
->set_needs_dynsym_entry();
7107 this->rel_
->add_global(gsym
, elfcpp::R_ARM_JUMP_SLOT
, this->got_plt_
,
7110 // Note that we don't need to save the symbol. The contents of the
7111 // PLT are independent of which symbols are used. The symbols only
7112 // appear in the relocations.
7116 // FIXME: This is not very flexible. Right now this has only been tested
7117 // on armv5te. If we are to support additional architecture features like
7118 // Thumb-2 or BE8, we need to make this more flexible like GNU ld.
7120 // The first entry in the PLT.
7121 template<bool big_endian
>
7122 const uint32_t Output_data_plt_arm
<big_endian
>::first_plt_entry
[5] =
7124 0xe52de004, // str lr, [sp, #-4]!
7125 0xe59fe004, // ldr lr, [pc, #4]
7126 0xe08fe00e, // add lr, pc, lr
7127 0xe5bef008, // ldr pc, [lr, #8]!
7128 0x00000000, // &GOT[0] - .
7131 // Subsequent entries in the PLT.
7133 template<bool big_endian
>
7134 const uint32_t Output_data_plt_arm
<big_endian
>::plt_entry
[3] =
7136 0xe28fc600, // add ip, pc, #0xNN00000
7137 0xe28cca00, // add ip, ip, #0xNN000
7138 0xe5bcf000, // ldr pc, [ip, #0xNNN]!
7141 // Write out the PLT. This uses the hand-coded instructions above,
7142 // and adjusts them as needed. This is all specified by the arm ELF
7143 // Processor Supplement.
7145 template<bool big_endian
>
7147 Output_data_plt_arm
<big_endian
>::do_write(Output_file
* of
)
7149 const off_t offset
= this->offset();
7150 const section_size_type oview_size
=
7151 convert_to_section_size_type(this->data_size());
7152 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
7154 const off_t got_file_offset
= this->got_plt_
->offset();
7155 const section_size_type got_size
=
7156 convert_to_section_size_type(this->got_plt_
->data_size());
7157 unsigned char* const got_view
= of
->get_output_view(got_file_offset
,
7159 unsigned char* pov
= oview
;
7161 Arm_address plt_address
= this->address();
7162 Arm_address got_address
= this->got_plt_
->address();
7164 // Write first PLT entry. All but the last word are constants.
7165 const size_t num_first_plt_words
= (sizeof(first_plt_entry
)
7166 / sizeof(plt_entry
[0]));
7167 for (size_t i
= 0; i
< num_first_plt_words
- 1; i
++)
7168 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ i
* 4, first_plt_entry
[i
]);
7169 // Last word in first PLT entry is &GOT[0] - .
7170 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 16,
7171 got_address
- (plt_address
+ 16));
7172 pov
+= sizeof(first_plt_entry
);
7174 unsigned char* got_pov
= got_view
;
7176 memset(got_pov
, 0, 12);
7179 const int rel_size
= elfcpp::Elf_sizes
<32>::rel_size
;
7180 unsigned int plt_offset
= sizeof(first_plt_entry
);
7181 unsigned int plt_rel_offset
= 0;
7182 unsigned int got_offset
= 12;
7183 const unsigned int count
= this->count_
;
7184 for (unsigned int i
= 0;
7187 pov
+= sizeof(plt_entry
),
7189 plt_offset
+= sizeof(plt_entry
),
7190 plt_rel_offset
+= rel_size
,
7193 // Set and adjust the PLT entry itself.
7194 int32_t offset
= ((got_address
+ got_offset
)
7195 - (plt_address
+ plt_offset
+ 8));
7197 gold_assert(offset
>= 0 && offset
< 0x0fffffff);
7198 uint32_t plt_insn0
= plt_entry
[0] | ((offset
>> 20) & 0xff);
7199 elfcpp::Swap
<32, big_endian
>::writeval(pov
, plt_insn0
);
7200 uint32_t plt_insn1
= plt_entry
[1] | ((offset
>> 12) & 0xff);
7201 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, plt_insn1
);
7202 uint32_t plt_insn2
= plt_entry
[2] | (offset
& 0xfff);
7203 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8, plt_insn2
);
7205 // Set the entry in the GOT.
7206 elfcpp::Swap
<32, big_endian
>::writeval(got_pov
, plt_address
);
7209 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
7210 gold_assert(static_cast<section_size_type
>(got_pov
- got_view
) == got_size
);
7212 of
->write_output_view(offset
, oview_size
, oview
);
7213 of
->write_output_view(got_file_offset
, got_size
, got_view
);
7216 // Create a PLT entry for a global symbol.
7218 template<bool big_endian
>
7220 Target_arm
<big_endian
>::make_plt_entry(Symbol_table
* symtab
, Layout
* layout
,
7223 if (gsym
->has_plt_offset())
7226 if (this->plt_
== NULL
)
7228 // Create the GOT sections first.
7229 this->got_section(symtab
, layout
);
7231 this->plt_
= new Output_data_plt_arm
<big_endian
>(layout
, this->got_plt_
);
7232 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
7234 | elfcpp::SHF_EXECINSTR
),
7235 this->plt_
, false, false, false, false);
7237 this->plt_
->add_entry(gsym
);
7240 // Get the section to use for TLS_DESC relocations.
7242 template<bool big_endian
>
7243 typename Target_arm
<big_endian
>::Reloc_section
*
7244 Target_arm
<big_endian
>::rel_tls_desc_section(Layout
* layout
) const
7246 return this->plt_section()->rel_tls_desc(layout
);
7249 // Define the _TLS_MODULE_BASE_ symbol in the TLS segment.
7251 template<bool big_endian
>
7253 Target_arm
<big_endian
>::define_tls_base_symbol(
7254 Symbol_table
* symtab
,
7257 if (this->tls_base_symbol_defined_
)
7260 Output_segment
* tls_segment
= layout
->tls_segment();
7261 if (tls_segment
!= NULL
)
7263 bool is_exec
= parameters
->options().output_is_executable();
7264 symtab
->define_in_output_segment("_TLS_MODULE_BASE_", NULL
,
7265 Symbol_table::PREDEFINED
,
7269 elfcpp::STV_HIDDEN
, 0,
7271 ? Symbol::SEGMENT_END
7272 : Symbol::SEGMENT_START
),
7275 this->tls_base_symbol_defined_
= true;
7278 // Create a GOT entry for the TLS module index.
7280 template<bool big_endian
>
7282 Target_arm
<big_endian
>::got_mod_index_entry(
7283 Symbol_table
* symtab
,
7285 Sized_relobj
<32, big_endian
>* object
)
7287 if (this->got_mod_index_offset_
== -1U)
7289 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
7290 Arm_output_data_got
<big_endian
>* got
= this->got_section(symtab
, layout
);
7291 unsigned int got_offset
;
7292 if (!parameters
->doing_static_link())
7294 got_offset
= got
->add_constant(0);
7295 Reloc_section
* rel_dyn
= this->rel_dyn_section(layout
);
7296 rel_dyn
->add_local(object
, 0, elfcpp::R_ARM_TLS_DTPMOD32
, got
,
7301 // We are doing a static link. Just mark it as belong to module 1,
7303 got_offset
= got
->add_constant(1);
7306 got
->add_constant(0);
7307 this->got_mod_index_offset_
= got_offset
;
7309 return this->got_mod_index_offset_
;
7312 // Optimize the TLS relocation type based on what we know about the
7313 // symbol. IS_FINAL is true if the final address of this symbol is
7314 // known at link time.
7316 template<bool big_endian
>
7317 tls::Tls_optimization
7318 Target_arm
<big_endian
>::optimize_tls_reloc(bool, int)
7320 // FIXME: Currently we do not do any TLS optimization.
7321 return tls::TLSOPT_NONE
;
7324 // Report an unsupported relocation against a local symbol.
7326 template<bool big_endian
>
7328 Target_arm
<big_endian
>::Scan::unsupported_reloc_local(
7329 Sized_relobj
<32, big_endian
>* object
,
7330 unsigned int r_type
)
7332 gold_error(_("%s: unsupported reloc %u against local symbol"),
7333 object
->name().c_str(), r_type
);
7336 // We are about to emit a dynamic relocation of type R_TYPE. If the
7337 // dynamic linker does not support it, issue an error. The GNU linker
7338 // only issues a non-PIC error for an allocated read-only section.
7339 // Here we know the section is allocated, but we don't know that it is
7340 // read-only. But we check for all the relocation types which the
7341 // glibc dynamic linker supports, so it seems appropriate to issue an
7342 // error even if the section is not read-only.
7344 template<bool big_endian
>
7346 Target_arm
<big_endian
>::Scan::check_non_pic(Relobj
* object
,
7347 unsigned int r_type
)
7351 // These are the relocation types supported by glibc for ARM.
7352 case elfcpp::R_ARM_RELATIVE
:
7353 case elfcpp::R_ARM_COPY
:
7354 case elfcpp::R_ARM_GLOB_DAT
:
7355 case elfcpp::R_ARM_JUMP_SLOT
:
7356 case elfcpp::R_ARM_ABS32
:
7357 case elfcpp::R_ARM_ABS32_NOI
:
7358 case elfcpp::R_ARM_PC24
:
7359 // FIXME: The following 3 types are not supported by Android's dynamic
7361 case elfcpp::R_ARM_TLS_DTPMOD32
:
7362 case elfcpp::R_ARM_TLS_DTPOFF32
:
7363 case elfcpp::R_ARM_TLS_TPOFF32
:
7368 // This prevents us from issuing more than one error per reloc
7369 // section. But we can still wind up issuing more than one
7370 // error per object file.
7371 if (this->issued_non_pic_error_
)
7373 const Arm_reloc_property
* reloc_property
=
7374 arm_reloc_property_table
->get_reloc_property(r_type
);
7375 gold_assert(reloc_property
!= NULL
);
7376 object
->error(_("requires unsupported dynamic reloc %s; "
7377 "recompile with -fPIC"),
7378 reloc_property
->name().c_str());
7379 this->issued_non_pic_error_
= true;
7383 case elfcpp::R_ARM_NONE
:
7388 // Scan a relocation for a local symbol.
7389 // FIXME: This only handles a subset of relocation types used by Android
7390 // on ARM v5te devices.
7392 template<bool big_endian
>
7394 Target_arm
<big_endian
>::Scan::local(Symbol_table
* symtab
,
7397 Sized_relobj
<32, big_endian
>* object
,
7398 unsigned int data_shndx
,
7399 Output_section
* output_section
,
7400 const elfcpp::Rel
<32, big_endian
>& reloc
,
7401 unsigned int r_type
,
7402 const elfcpp::Sym
<32, big_endian
>& lsym
)
7404 r_type
= get_real_reloc_type(r_type
);
7407 case elfcpp::R_ARM_NONE
:
7408 case elfcpp::R_ARM_V4BX
:
7409 case elfcpp::R_ARM_GNU_VTENTRY
:
7410 case elfcpp::R_ARM_GNU_VTINHERIT
:
7413 case elfcpp::R_ARM_ABS32
:
7414 case elfcpp::R_ARM_ABS32_NOI
:
7415 // If building a shared library (or a position-independent
7416 // executable), we need to create a dynamic relocation for
7417 // this location. The relocation applied at link time will
7418 // apply the link-time value, so we flag the location with
7419 // an R_ARM_RELATIVE relocation so the dynamic loader can
7420 // relocate it easily.
7421 if (parameters
->options().output_is_position_independent())
7423 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
7424 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
7425 // If we are to add more other reloc types than R_ARM_ABS32,
7426 // we need to add check_non_pic(object, r_type) here.
7427 rel_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_ARM_RELATIVE
,
7428 output_section
, data_shndx
,
7429 reloc
.get_r_offset());
7433 case elfcpp::R_ARM_ABS16
:
7434 case elfcpp::R_ARM_ABS12
:
7435 case elfcpp::R_ARM_THM_ABS5
:
7436 case elfcpp::R_ARM_ABS8
:
7437 case elfcpp::R_ARM_BASE_ABS
:
7438 case elfcpp::R_ARM_MOVW_ABS_NC
:
7439 case elfcpp::R_ARM_MOVT_ABS
:
7440 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
7441 case elfcpp::R_ARM_THM_MOVT_ABS
:
7442 // If building a shared library (or a position-independent
7443 // executable), we need to create a dynamic relocation for
7444 // this location. Because the addend needs to remain in the
7445 // data section, we need to be careful not to apply this
7446 // relocation statically.
7447 if (parameters
->options().output_is_position_independent())
7449 check_non_pic(object
, r_type
);
7450 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
7451 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
7452 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
7453 rel_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
7454 data_shndx
, reloc
.get_r_offset());
7457 gold_assert(lsym
.get_st_value() == 0);
7458 unsigned int shndx
= lsym
.get_st_shndx();
7460 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
7463 object
->error(_("section symbol %u has bad shndx %u"),
7466 rel_dyn
->add_local_section(object
, shndx
,
7467 r_type
, output_section
,
7468 data_shndx
, reloc
.get_r_offset());
7473 case elfcpp::R_ARM_PC24
:
7474 case elfcpp::R_ARM_REL32
:
7475 case elfcpp::R_ARM_LDR_PC_G0
:
7476 case elfcpp::R_ARM_SBREL32
:
7477 case elfcpp::R_ARM_THM_CALL
:
7478 case elfcpp::R_ARM_THM_PC8
:
7479 case elfcpp::R_ARM_BASE_PREL
:
7480 case elfcpp::R_ARM_PLT32
:
7481 case elfcpp::R_ARM_CALL
:
7482 case elfcpp::R_ARM_JUMP24
:
7483 case elfcpp::R_ARM_THM_JUMP24
:
7484 case elfcpp::R_ARM_LDR_SBREL_11_0_NC
:
7485 case elfcpp::R_ARM_ALU_SBREL_19_12_NC
:
7486 case elfcpp::R_ARM_ALU_SBREL_27_20_CK
:
7487 case elfcpp::R_ARM_SBREL31
:
7488 case elfcpp::R_ARM_PREL31
:
7489 case elfcpp::R_ARM_MOVW_PREL_NC
:
7490 case elfcpp::R_ARM_MOVT_PREL
:
7491 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
7492 case elfcpp::R_ARM_THM_MOVT_PREL
:
7493 case elfcpp::R_ARM_THM_JUMP19
:
7494 case elfcpp::R_ARM_THM_JUMP6
:
7495 case elfcpp::R_ARM_THM_ALU_PREL_11_0
:
7496 case elfcpp::R_ARM_THM_PC12
:
7497 case elfcpp::R_ARM_REL32_NOI
:
7498 case elfcpp::R_ARM_ALU_PC_G0_NC
:
7499 case elfcpp::R_ARM_ALU_PC_G0
:
7500 case elfcpp::R_ARM_ALU_PC_G1_NC
:
7501 case elfcpp::R_ARM_ALU_PC_G1
:
7502 case elfcpp::R_ARM_ALU_PC_G2
:
7503 case elfcpp::R_ARM_LDR_PC_G1
:
7504 case elfcpp::R_ARM_LDR_PC_G2
:
7505 case elfcpp::R_ARM_LDRS_PC_G0
:
7506 case elfcpp::R_ARM_LDRS_PC_G1
:
7507 case elfcpp::R_ARM_LDRS_PC_G2
:
7508 case elfcpp::R_ARM_LDC_PC_G0
:
7509 case elfcpp::R_ARM_LDC_PC_G1
:
7510 case elfcpp::R_ARM_LDC_PC_G2
:
7511 case elfcpp::R_ARM_ALU_SB_G0_NC
:
7512 case elfcpp::R_ARM_ALU_SB_G0
:
7513 case elfcpp::R_ARM_ALU_SB_G1_NC
:
7514 case elfcpp::R_ARM_ALU_SB_G1
:
7515 case elfcpp::R_ARM_ALU_SB_G2
:
7516 case elfcpp::R_ARM_LDR_SB_G0
:
7517 case elfcpp::R_ARM_LDR_SB_G1
:
7518 case elfcpp::R_ARM_LDR_SB_G2
:
7519 case elfcpp::R_ARM_LDRS_SB_G0
:
7520 case elfcpp::R_ARM_LDRS_SB_G1
:
7521 case elfcpp::R_ARM_LDRS_SB_G2
:
7522 case elfcpp::R_ARM_LDC_SB_G0
:
7523 case elfcpp::R_ARM_LDC_SB_G1
:
7524 case elfcpp::R_ARM_LDC_SB_G2
:
7525 case elfcpp::R_ARM_MOVW_BREL_NC
:
7526 case elfcpp::R_ARM_MOVT_BREL
:
7527 case elfcpp::R_ARM_MOVW_BREL
:
7528 case elfcpp::R_ARM_THM_MOVW_BREL_NC
:
7529 case elfcpp::R_ARM_THM_MOVT_BREL
:
7530 case elfcpp::R_ARM_THM_MOVW_BREL
:
7531 case elfcpp::R_ARM_THM_JUMP11
:
7532 case elfcpp::R_ARM_THM_JUMP8
:
7533 // We don't need to do anything for a relative addressing relocation
7534 // against a local symbol if it does not reference the GOT.
7537 case elfcpp::R_ARM_GOTOFF32
:
7538 case elfcpp::R_ARM_GOTOFF12
:
7539 // We need a GOT section:
7540 target
->got_section(symtab
, layout
);
7543 case elfcpp::R_ARM_GOT_BREL
:
7544 case elfcpp::R_ARM_GOT_PREL
:
7546 // The symbol requires a GOT entry.
7547 Arm_output_data_got
<big_endian
>* got
=
7548 target
->got_section(symtab
, layout
);
7549 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
7550 if (got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
))
7552 // If we are generating a shared object, we need to add a
7553 // dynamic RELATIVE relocation for this symbol's GOT entry.
7554 if (parameters
->options().output_is_position_independent())
7556 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
7557 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
7558 rel_dyn
->add_local_relative(
7559 object
, r_sym
, elfcpp::R_ARM_RELATIVE
, got
,
7560 object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
));
7566 case elfcpp::R_ARM_TARGET1
:
7567 case elfcpp::R_ARM_TARGET2
:
7568 // This should have been mapped to another type already.
7570 case elfcpp::R_ARM_COPY
:
7571 case elfcpp::R_ARM_GLOB_DAT
:
7572 case elfcpp::R_ARM_JUMP_SLOT
:
7573 case elfcpp::R_ARM_RELATIVE
:
7574 // These are relocations which should only be seen by the
7575 // dynamic linker, and should never be seen here.
7576 gold_error(_("%s: unexpected reloc %u in object file"),
7577 object
->name().c_str(), r_type
);
7581 // These are initial TLS relocs, which are expected when
7583 case elfcpp::R_ARM_TLS_GD32
: // Global-dynamic
7584 case elfcpp::R_ARM_TLS_LDM32
: // Local-dynamic
7585 case elfcpp::R_ARM_TLS_LDO32
: // Alternate local-dynamic
7586 case elfcpp::R_ARM_TLS_IE32
: // Initial-exec
7587 case elfcpp::R_ARM_TLS_LE32
: // Local-exec
7589 bool output_is_shared
= parameters
->options().shared();
7590 const tls::Tls_optimization optimized_type
7591 = Target_arm
<big_endian
>::optimize_tls_reloc(!output_is_shared
,
7595 case elfcpp::R_ARM_TLS_GD32
: // Global-dynamic
7596 if (optimized_type
== tls::TLSOPT_NONE
)
7598 // Create a pair of GOT entries for the module index and
7599 // dtv-relative offset.
7600 Arm_output_data_got
<big_endian
>* got
7601 = target
->got_section(symtab
, layout
);
7602 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
7603 unsigned int shndx
= lsym
.get_st_shndx();
7605 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
7608 object
->error(_("local symbol %u has bad shndx %u"),
7613 if (!parameters
->doing_static_link())
7614 got
->add_local_pair_with_rel(object
, r_sym
, shndx
,
7616 target
->rel_dyn_section(layout
),
7617 elfcpp::R_ARM_TLS_DTPMOD32
, 0);
7619 got
->add_tls_gd32_with_static_reloc(GOT_TYPE_TLS_PAIR
,
7623 // FIXME: TLS optimization not supported yet.
7627 case elfcpp::R_ARM_TLS_LDM32
: // Local-dynamic
7628 if (optimized_type
== tls::TLSOPT_NONE
)
7630 // Create a GOT entry for the module index.
7631 target
->got_mod_index_entry(symtab
, layout
, object
);
7634 // FIXME: TLS optimization not supported yet.
7638 case elfcpp::R_ARM_TLS_LDO32
: // Alternate local-dynamic
7641 case elfcpp::R_ARM_TLS_IE32
: // Initial-exec
7642 layout
->set_has_static_tls();
7643 if (optimized_type
== tls::TLSOPT_NONE
)
7645 // Create a GOT entry for the tp-relative offset.
7646 Arm_output_data_got
<big_endian
>* got
7647 = target
->got_section(symtab
, layout
);
7648 unsigned int r_sym
=
7649 elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
7650 if (!parameters
->doing_static_link())
7651 got
->add_local_with_rel(object
, r_sym
, GOT_TYPE_TLS_OFFSET
,
7652 target
->rel_dyn_section(layout
),
7653 elfcpp::R_ARM_TLS_TPOFF32
);
7654 else if (!object
->local_has_got_offset(r_sym
,
7655 GOT_TYPE_TLS_OFFSET
))
7657 got
->add_local(object
, r_sym
, GOT_TYPE_TLS_OFFSET
);
7658 unsigned int got_offset
=
7659 object
->local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
);
7660 got
->add_static_reloc(got_offset
,
7661 elfcpp::R_ARM_TLS_TPOFF32
, object
,
7666 // FIXME: TLS optimization not supported yet.
7670 case elfcpp::R_ARM_TLS_LE32
: // Local-exec
7671 layout
->set_has_static_tls();
7672 if (output_is_shared
)
7674 // We need to create a dynamic relocation.
7675 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
7676 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
7677 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
7678 rel_dyn
->add_local(object
, r_sym
, elfcpp::R_ARM_TLS_TPOFF32
,
7679 output_section
, data_shndx
,
7680 reloc
.get_r_offset());
7691 unsupported_reloc_local(object
, r_type
);
7696 // Report an unsupported relocation against a global symbol.
7698 template<bool big_endian
>
7700 Target_arm
<big_endian
>::Scan::unsupported_reloc_global(
7701 Sized_relobj
<32, big_endian
>* object
,
7702 unsigned int r_type
,
7705 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
7706 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
7709 template<bool big_endian
>
7711 Target_arm
<big_endian
>::Scan::possible_function_pointer_reloc(
7712 unsigned int r_type
)
7716 case elfcpp::R_ARM_PC24
:
7717 case elfcpp::R_ARM_THM_CALL
:
7718 case elfcpp::R_ARM_PLT32
:
7719 case elfcpp::R_ARM_CALL
:
7720 case elfcpp::R_ARM_JUMP24
:
7721 case elfcpp::R_ARM_THM_JUMP24
:
7722 case elfcpp::R_ARM_SBREL31
:
7723 case elfcpp::R_ARM_PREL31
:
7724 case elfcpp::R_ARM_THM_JUMP19
:
7725 case elfcpp::R_ARM_THM_JUMP6
:
7726 case elfcpp::R_ARM_THM_JUMP11
:
7727 case elfcpp::R_ARM_THM_JUMP8
:
7728 // All the relocations above are branches except SBREL31 and PREL31.
7732 // Be conservative and assume this is a function pointer.
7737 template<bool big_endian
>
7739 Target_arm
<big_endian
>::Scan::local_reloc_may_be_function_pointer(
7742 Target_arm
<big_endian
>* target
,
7743 Sized_relobj
<32, big_endian
>*,
7746 const elfcpp::Rel
<32, big_endian
>&,
7747 unsigned int r_type
,
7748 const elfcpp::Sym
<32, big_endian
>&)
7750 r_type
= target
->get_real_reloc_type(r_type
);
7751 return possible_function_pointer_reloc(r_type
);
7754 template<bool big_endian
>
7756 Target_arm
<big_endian
>::Scan::global_reloc_may_be_function_pointer(
7759 Target_arm
<big_endian
>* target
,
7760 Sized_relobj
<32, big_endian
>*,
7763 const elfcpp::Rel
<32, big_endian
>&,
7764 unsigned int r_type
,
7767 // GOT is not a function.
7768 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
7771 r_type
= target
->get_real_reloc_type(r_type
);
7772 return possible_function_pointer_reloc(r_type
);
7775 // Scan a relocation for a global symbol.
7777 template<bool big_endian
>
7779 Target_arm
<big_endian
>::Scan::global(Symbol_table
* symtab
,
7782 Sized_relobj
<32, big_endian
>* object
,
7783 unsigned int data_shndx
,
7784 Output_section
* output_section
,
7785 const elfcpp::Rel
<32, big_endian
>& reloc
,
7786 unsigned int r_type
,
7789 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
7790 // section. We check here to avoid creating a dynamic reloc against
7791 // _GLOBAL_OFFSET_TABLE_.
7792 if (!target
->has_got_section()
7793 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
7794 target
->got_section(symtab
, layout
);
7796 r_type
= get_real_reloc_type(r_type
);
7799 case elfcpp::R_ARM_NONE
:
7800 case elfcpp::R_ARM_V4BX
:
7801 case elfcpp::R_ARM_GNU_VTENTRY
:
7802 case elfcpp::R_ARM_GNU_VTINHERIT
:
7805 case elfcpp::R_ARM_ABS32
:
7806 case elfcpp::R_ARM_ABS16
:
7807 case elfcpp::R_ARM_ABS12
:
7808 case elfcpp::R_ARM_THM_ABS5
:
7809 case elfcpp::R_ARM_ABS8
:
7810 case elfcpp::R_ARM_BASE_ABS
:
7811 case elfcpp::R_ARM_MOVW_ABS_NC
:
7812 case elfcpp::R_ARM_MOVT_ABS
:
7813 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
7814 case elfcpp::R_ARM_THM_MOVT_ABS
:
7815 case elfcpp::R_ARM_ABS32_NOI
:
7816 // Absolute addressing relocations.
7818 // Make a PLT entry if necessary.
7819 if (this->symbol_needs_plt_entry(gsym
))
7821 target
->make_plt_entry(symtab
, layout
, gsym
);
7822 // Since this is not a PC-relative relocation, we may be
7823 // taking the address of a function. In that case we need to
7824 // set the entry in the dynamic symbol table to the address of
7826 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
7827 gsym
->set_needs_dynsym_value();
7829 // Make a dynamic relocation if necessary.
7830 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
7832 if (gsym
->may_need_copy_reloc())
7834 target
->copy_reloc(symtab
, layout
, object
,
7835 data_shndx
, output_section
, gsym
, reloc
);
7837 else if ((r_type
== elfcpp::R_ARM_ABS32
7838 || r_type
== elfcpp::R_ARM_ABS32_NOI
)
7839 && gsym
->can_use_relative_reloc(false))
7841 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
7842 rel_dyn
->add_global_relative(gsym
, elfcpp::R_ARM_RELATIVE
,
7843 output_section
, object
,
7844 data_shndx
, reloc
.get_r_offset());
7848 check_non_pic(object
, r_type
);
7849 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
7850 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
7851 data_shndx
, reloc
.get_r_offset());
7857 case elfcpp::R_ARM_GOTOFF32
:
7858 case elfcpp::R_ARM_GOTOFF12
:
7859 // We need a GOT section.
7860 target
->got_section(symtab
, layout
);
7863 case elfcpp::R_ARM_REL32
:
7864 case elfcpp::R_ARM_LDR_PC_G0
:
7865 case elfcpp::R_ARM_SBREL32
:
7866 case elfcpp::R_ARM_THM_PC8
:
7867 case elfcpp::R_ARM_BASE_PREL
:
7868 case elfcpp::R_ARM_LDR_SBREL_11_0_NC
:
7869 case elfcpp::R_ARM_ALU_SBREL_19_12_NC
:
7870 case elfcpp::R_ARM_ALU_SBREL_27_20_CK
:
7871 case elfcpp::R_ARM_MOVW_PREL_NC
:
7872 case elfcpp::R_ARM_MOVT_PREL
:
7873 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
7874 case elfcpp::R_ARM_THM_MOVT_PREL
:
7875 case elfcpp::R_ARM_THM_ALU_PREL_11_0
:
7876 case elfcpp::R_ARM_THM_PC12
:
7877 case elfcpp::R_ARM_REL32_NOI
:
7878 case elfcpp::R_ARM_ALU_PC_G0_NC
:
7879 case elfcpp::R_ARM_ALU_PC_G0
:
7880 case elfcpp::R_ARM_ALU_PC_G1_NC
:
7881 case elfcpp::R_ARM_ALU_PC_G1
:
7882 case elfcpp::R_ARM_ALU_PC_G2
:
7883 case elfcpp::R_ARM_LDR_PC_G1
:
7884 case elfcpp::R_ARM_LDR_PC_G2
:
7885 case elfcpp::R_ARM_LDRS_PC_G0
:
7886 case elfcpp::R_ARM_LDRS_PC_G1
:
7887 case elfcpp::R_ARM_LDRS_PC_G2
:
7888 case elfcpp::R_ARM_LDC_PC_G0
:
7889 case elfcpp::R_ARM_LDC_PC_G1
:
7890 case elfcpp::R_ARM_LDC_PC_G2
:
7891 case elfcpp::R_ARM_ALU_SB_G0_NC
:
7892 case elfcpp::R_ARM_ALU_SB_G0
:
7893 case elfcpp::R_ARM_ALU_SB_G1_NC
:
7894 case elfcpp::R_ARM_ALU_SB_G1
:
7895 case elfcpp::R_ARM_ALU_SB_G2
:
7896 case elfcpp::R_ARM_LDR_SB_G0
:
7897 case elfcpp::R_ARM_LDR_SB_G1
:
7898 case elfcpp::R_ARM_LDR_SB_G2
:
7899 case elfcpp::R_ARM_LDRS_SB_G0
:
7900 case elfcpp::R_ARM_LDRS_SB_G1
:
7901 case elfcpp::R_ARM_LDRS_SB_G2
:
7902 case elfcpp::R_ARM_LDC_SB_G0
:
7903 case elfcpp::R_ARM_LDC_SB_G1
:
7904 case elfcpp::R_ARM_LDC_SB_G2
:
7905 case elfcpp::R_ARM_MOVW_BREL_NC
:
7906 case elfcpp::R_ARM_MOVT_BREL
:
7907 case elfcpp::R_ARM_MOVW_BREL
:
7908 case elfcpp::R_ARM_THM_MOVW_BREL_NC
:
7909 case elfcpp::R_ARM_THM_MOVT_BREL
:
7910 case elfcpp::R_ARM_THM_MOVW_BREL
:
7911 // Relative addressing relocations.
7913 // Make a dynamic relocation if necessary.
7914 int flags
= Symbol::NON_PIC_REF
;
7915 if (gsym
->needs_dynamic_reloc(flags
))
7917 if (target
->may_need_copy_reloc(gsym
))
7919 target
->copy_reloc(symtab
, layout
, object
,
7920 data_shndx
, output_section
, gsym
, reloc
);
7924 check_non_pic(object
, r_type
);
7925 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
7926 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
7927 data_shndx
, reloc
.get_r_offset());
7933 case elfcpp::R_ARM_PC24
:
7934 case elfcpp::R_ARM_THM_CALL
:
7935 case elfcpp::R_ARM_PLT32
:
7936 case elfcpp::R_ARM_CALL
:
7937 case elfcpp::R_ARM_JUMP24
:
7938 case elfcpp::R_ARM_THM_JUMP24
:
7939 case elfcpp::R_ARM_SBREL31
:
7940 case elfcpp::R_ARM_PREL31
:
7941 case elfcpp::R_ARM_THM_JUMP19
:
7942 case elfcpp::R_ARM_THM_JUMP6
:
7943 case elfcpp::R_ARM_THM_JUMP11
:
7944 case elfcpp::R_ARM_THM_JUMP8
:
7945 // All the relocation above are branches except for the PREL31 ones.
7946 // A PREL31 relocation can point to a personality function in a shared
7947 // library. In that case we want to use a PLT because we want to
7948 // call the personality routine and the dyanmic linkers we care about
7949 // do not support dynamic PREL31 relocations. An REL31 relocation may
7950 // point to a function whose unwinding behaviour is being described but
7951 // we will not mistakenly generate a PLT for that because we should use
7952 // a local section symbol.
7954 // If the symbol is fully resolved, this is just a relative
7955 // local reloc. Otherwise we need a PLT entry.
7956 if (gsym
->final_value_is_known())
7958 // If building a shared library, we can also skip the PLT entry
7959 // if the symbol is defined in the output file and is protected
7961 if (gsym
->is_defined()
7962 && !gsym
->is_from_dynobj()
7963 && !gsym
->is_preemptible())
7965 target
->make_plt_entry(symtab
, layout
, gsym
);
7968 case elfcpp::R_ARM_GOT_BREL
:
7969 case elfcpp::R_ARM_GOT_ABS
:
7970 case elfcpp::R_ARM_GOT_PREL
:
7972 // The symbol requires a GOT entry.
7973 Arm_output_data_got
<big_endian
>* got
=
7974 target
->got_section(symtab
, layout
);
7975 if (gsym
->final_value_is_known())
7976 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
7979 // If this symbol is not fully resolved, we need to add a
7980 // GOT entry with a dynamic relocation.
7981 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
7982 if (gsym
->is_from_dynobj()
7983 || gsym
->is_undefined()
7984 || gsym
->is_preemptible())
7985 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
,
7986 rel_dyn
, elfcpp::R_ARM_GLOB_DAT
);
7989 if (got
->add_global(gsym
, GOT_TYPE_STANDARD
))
7990 rel_dyn
->add_global_relative(
7991 gsym
, elfcpp::R_ARM_RELATIVE
, got
,
7992 gsym
->got_offset(GOT_TYPE_STANDARD
));
7998 case elfcpp::R_ARM_TARGET1
:
7999 case elfcpp::R_ARM_TARGET2
:
8000 // These should have been mapped to other types already.
8002 case elfcpp::R_ARM_COPY
:
8003 case elfcpp::R_ARM_GLOB_DAT
:
8004 case elfcpp::R_ARM_JUMP_SLOT
:
8005 case elfcpp::R_ARM_RELATIVE
:
8006 // These are relocations which should only be seen by the
8007 // dynamic linker, and should never be seen here.
8008 gold_error(_("%s: unexpected reloc %u in object file"),
8009 object
->name().c_str(), r_type
);
8012 // These are initial tls relocs, which are expected when
8014 case elfcpp::R_ARM_TLS_GD32
: // Global-dynamic
8015 case elfcpp::R_ARM_TLS_LDM32
: // Local-dynamic
8016 case elfcpp::R_ARM_TLS_LDO32
: // Alternate local-dynamic
8017 case elfcpp::R_ARM_TLS_IE32
: // Initial-exec
8018 case elfcpp::R_ARM_TLS_LE32
: // Local-exec
8020 const bool is_final
= gsym
->final_value_is_known();
8021 const tls::Tls_optimization optimized_type
8022 = Target_arm
<big_endian
>::optimize_tls_reloc(is_final
, r_type
);
8025 case elfcpp::R_ARM_TLS_GD32
: // Global-dynamic
8026 if (optimized_type
== tls::TLSOPT_NONE
)
8028 // Create a pair of GOT entries for the module index and
8029 // dtv-relative offset.
8030 Arm_output_data_got
<big_endian
>* got
8031 = target
->got_section(symtab
, layout
);
8032 if (!parameters
->doing_static_link())
8033 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_PAIR
,
8034 target
->rel_dyn_section(layout
),
8035 elfcpp::R_ARM_TLS_DTPMOD32
,
8036 elfcpp::R_ARM_TLS_DTPOFF32
);
8038 got
->add_tls_gd32_with_static_reloc(GOT_TYPE_TLS_PAIR
, gsym
);
8041 // FIXME: TLS optimization not supported yet.
8045 case elfcpp::R_ARM_TLS_LDM32
: // Local-dynamic
8046 if (optimized_type
== tls::TLSOPT_NONE
)
8048 // Create a GOT entry for the module index.
8049 target
->got_mod_index_entry(symtab
, layout
, object
);
8052 // FIXME: TLS optimization not supported yet.
8056 case elfcpp::R_ARM_TLS_LDO32
: // Alternate local-dynamic
8059 case elfcpp::R_ARM_TLS_IE32
: // Initial-exec
8060 layout
->set_has_static_tls();
8061 if (optimized_type
== tls::TLSOPT_NONE
)
8063 // Create a GOT entry for the tp-relative offset.
8064 Arm_output_data_got
<big_endian
>* got
8065 = target
->got_section(symtab
, layout
);
8066 if (!parameters
->doing_static_link())
8067 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
8068 target
->rel_dyn_section(layout
),
8069 elfcpp::R_ARM_TLS_TPOFF32
);
8070 else if (!gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
))
8072 got
->add_global(gsym
, GOT_TYPE_TLS_OFFSET
);
8073 unsigned int got_offset
=
8074 gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
8075 got
->add_static_reloc(got_offset
,
8076 elfcpp::R_ARM_TLS_TPOFF32
, gsym
);
8080 // FIXME: TLS optimization not supported yet.
8084 case elfcpp::R_ARM_TLS_LE32
: // Local-exec
8085 layout
->set_has_static_tls();
8086 if (parameters
->options().shared())
8088 // We need to create a dynamic relocation.
8089 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
8090 rel_dyn
->add_global(gsym
, elfcpp::R_ARM_TLS_TPOFF32
,
8091 output_section
, object
,
8092 data_shndx
, reloc
.get_r_offset());
8103 unsupported_reloc_global(object
, r_type
, gsym
);
8108 // Process relocations for gc.
8110 template<bool big_endian
>
8112 Target_arm
<big_endian
>::gc_process_relocs(Symbol_table
* symtab
,
8114 Sized_relobj
<32, big_endian
>* object
,
8115 unsigned int data_shndx
,
8117 const unsigned char* prelocs
,
8119 Output_section
* output_section
,
8120 bool needs_special_offset_handling
,
8121 size_t local_symbol_count
,
8122 const unsigned char* plocal_symbols
)
8124 typedef Target_arm
<big_endian
> Arm
;
8125 typedef typename Target_arm
<big_endian
>::Scan Scan
;
8127 gold::gc_process_relocs
<32, big_endian
, Arm
, elfcpp::SHT_REL
, Scan
>(
8136 needs_special_offset_handling
,
8141 // Scan relocations for a section.
8143 template<bool big_endian
>
8145 Target_arm
<big_endian
>::scan_relocs(Symbol_table
* symtab
,
8147 Sized_relobj
<32, big_endian
>* object
,
8148 unsigned int data_shndx
,
8149 unsigned int sh_type
,
8150 const unsigned char* prelocs
,
8152 Output_section
* output_section
,
8153 bool needs_special_offset_handling
,
8154 size_t local_symbol_count
,
8155 const unsigned char* plocal_symbols
)
8157 typedef typename Target_arm
<big_endian
>::Scan Scan
;
8158 if (sh_type
== elfcpp::SHT_RELA
)
8160 gold_error(_("%s: unsupported RELA reloc section"),
8161 object
->name().c_str());
8165 gold::scan_relocs
<32, big_endian
, Target_arm
, elfcpp::SHT_REL
, Scan
>(
8174 needs_special_offset_handling
,
8179 // Finalize the sections.
8181 template<bool big_endian
>
8183 Target_arm
<big_endian
>::do_finalize_sections(
8185 const Input_objects
* input_objects
,
8186 Symbol_table
* symtab
)
8188 bool merged_any_attributes
= false;
8189 // Merge processor-specific flags.
8190 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8191 p
!= input_objects
->relobj_end();
8194 Arm_relobj
<big_endian
>* arm_relobj
=
8195 Arm_relobj
<big_endian
>::as_arm_relobj(*p
);
8196 if (arm_relobj
->merge_flags_and_attributes())
8198 this->merge_processor_specific_flags(
8200 arm_relobj
->processor_specific_flags());
8201 this->merge_object_attributes(arm_relobj
->name().c_str(),
8202 arm_relobj
->attributes_section_data());
8203 merged_any_attributes
= true;
8207 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
8208 p
!= input_objects
->dynobj_end();
8211 Arm_dynobj
<big_endian
>* arm_dynobj
=
8212 Arm_dynobj
<big_endian
>::as_arm_dynobj(*p
);
8213 this->merge_processor_specific_flags(
8215 arm_dynobj
->processor_specific_flags());
8216 this->merge_object_attributes(arm_dynobj
->name().c_str(),
8217 arm_dynobj
->attributes_section_data());
8218 merged_any_attributes
= true;
8221 // Create an empty uninitialized attribute section if we still don't have it
8222 // at this moment. This happens if there is no attributes sections in all
8224 if (this->attributes_section_data_
== NULL
)
8225 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
8228 const Object_attribute
* cpu_arch_attr
=
8229 this->get_aeabi_object_attribute(elfcpp::Tag_CPU_arch
);
8230 if (cpu_arch_attr
->int_value() > elfcpp::TAG_CPU_ARCH_V4
)
8231 this->set_may_use_blx(true);
8233 // Check if we need to use Cortex-A8 workaround.
8234 if (parameters
->options().user_set_fix_cortex_a8())
8235 this->fix_cortex_a8_
= parameters
->options().fix_cortex_a8();
8238 // If neither --fix-cortex-a8 nor --no-fix-cortex-a8 is used, turn on
8239 // Cortex-A8 erratum workaround for ARMv7-A or ARMv7 with unknown
8241 const Object_attribute
* cpu_arch_profile_attr
=
8242 this->get_aeabi_object_attribute(elfcpp::Tag_CPU_arch_profile
);
8243 this->fix_cortex_a8_
=
8244 (cpu_arch_attr
->int_value() == elfcpp::TAG_CPU_ARCH_V7
8245 && (cpu_arch_profile_attr
->int_value() == 'A'
8246 || cpu_arch_profile_attr
->int_value() == 0));
8249 // Check if we can use V4BX interworking.
8250 // The V4BX interworking stub contains BX instruction,
8251 // which is not specified for some profiles.
8252 if (this->fix_v4bx() == General_options::FIX_V4BX_INTERWORKING
8253 && !this->may_use_blx())
8254 gold_error(_("unable to provide V4BX reloc interworking fix up; "
8255 "the target profile does not support BX instruction"));
8257 // Fill in some more dynamic tags.
8258 const Reloc_section
* rel_plt
= (this->plt_
== NULL
8260 : this->plt_
->rel_plt());
8261 layout
->add_target_dynamic_tags(true, this->got_plt_
, rel_plt
,
8262 this->rel_dyn_
, true, false);
8264 // Emit any relocs we saved in an attempt to avoid generating COPY
8266 if (this->copy_relocs_
.any_saved_relocs())
8267 this->copy_relocs_
.emit(this->rel_dyn_section(layout
));
8269 // Handle the .ARM.exidx section.
8270 Output_section
* exidx_section
= layout
->find_output_section(".ARM.exidx");
8271 if (exidx_section
!= NULL
8272 && exidx_section
->type() == elfcpp::SHT_ARM_EXIDX
8273 && !parameters
->options().relocatable())
8275 // Create __exidx_start and __exdix_end symbols.
8276 symtab
->define_in_output_data("__exidx_start", NULL
,
8277 Symbol_table::PREDEFINED
,
8278 exidx_section
, 0, 0, elfcpp::STT_OBJECT
,
8279 elfcpp::STB_GLOBAL
, elfcpp::STV_HIDDEN
, 0,
8281 symtab
->define_in_output_data("__exidx_end", NULL
,
8282 Symbol_table::PREDEFINED
,
8283 exidx_section
, 0, 0, elfcpp::STT_OBJECT
,
8284 elfcpp::STB_GLOBAL
, elfcpp::STV_HIDDEN
, 0,
8287 // For the ARM target, we need to add a PT_ARM_EXIDX segment for
8288 // the .ARM.exidx section.
8289 if (!layout
->script_options()->saw_phdrs_clause())
8291 gold_assert(layout
->find_output_segment(elfcpp::PT_ARM_EXIDX
, 0, 0)
8293 Output_segment
* exidx_segment
=
8294 layout
->make_output_segment(elfcpp::PT_ARM_EXIDX
, elfcpp::PF_R
);
8295 exidx_segment
->add_output_section(exidx_section
, elfcpp::PF_R
,
8300 // Create an .ARM.attributes section if we have merged any attributes
8302 if (merged_any_attributes
)
8304 Output_attributes_section_data
* attributes_section
=
8305 new Output_attributes_section_data(*this->attributes_section_data_
);
8306 layout
->add_output_section_data(".ARM.attributes",
8307 elfcpp::SHT_ARM_ATTRIBUTES
, 0,
8308 attributes_section
, false, false, false,
8313 // Return whether a direct absolute static relocation needs to be applied.
8314 // In cases where Scan::local() or Scan::global() has created
8315 // a dynamic relocation other than R_ARM_RELATIVE, the addend
8316 // of the relocation is carried in the data, and we must not
8317 // apply the static relocation.
8319 template<bool big_endian
>
8321 Target_arm
<big_endian
>::Relocate::should_apply_static_reloc(
8322 const Sized_symbol
<32>* gsym
,
8325 Output_section
* output_section
)
8327 // If the output section is not allocated, then we didn't call
8328 // scan_relocs, we didn't create a dynamic reloc, and we must apply
8330 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
8333 // For local symbols, we will have created a non-RELATIVE dynamic
8334 // relocation only if (a) the output is position independent,
8335 // (b) the relocation is absolute (not pc- or segment-relative), and
8336 // (c) the relocation is not 32 bits wide.
8338 return !(parameters
->options().output_is_position_independent()
8339 && (ref_flags
& Symbol::ABSOLUTE_REF
)
8342 // For global symbols, we use the same helper routines used in the
8343 // scan pass. If we did not create a dynamic relocation, or if we
8344 // created a RELATIVE dynamic relocation, we should apply the static
8346 bool has_dyn
= gsym
->needs_dynamic_reloc(ref_flags
);
8347 bool is_rel
= (ref_flags
& Symbol::ABSOLUTE_REF
)
8348 && gsym
->can_use_relative_reloc(ref_flags
8349 & Symbol::FUNCTION_CALL
);
8350 return !has_dyn
|| is_rel
;
8353 // Perform a relocation.
8355 template<bool big_endian
>
8357 Target_arm
<big_endian
>::Relocate::relocate(
8358 const Relocate_info
<32, big_endian
>* relinfo
,
8360 Output_section
*output_section
,
8362 const elfcpp::Rel
<32, big_endian
>& rel
,
8363 unsigned int r_type
,
8364 const Sized_symbol
<32>* gsym
,
8365 const Symbol_value
<32>* psymval
,
8366 unsigned char* view
,
8367 Arm_address address
,
8368 section_size_type view_size
)
8370 typedef Arm_relocate_functions
<big_endian
> Arm_relocate_functions
;
8372 r_type
= get_real_reloc_type(r_type
);
8373 const Arm_reloc_property
* reloc_property
=
8374 arm_reloc_property_table
->get_implemented_static_reloc_property(r_type
);
8375 if (reloc_property
== NULL
)
8377 std::string reloc_name
=
8378 arm_reloc_property_table
->reloc_name_in_error_message(r_type
);
8379 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
8380 _("cannot relocate %s in object file"),
8381 reloc_name
.c_str());
8385 const Arm_relobj
<big_endian
>* object
=
8386 Arm_relobj
<big_endian
>::as_arm_relobj(relinfo
->object
);
8388 // If the final branch target of a relocation is THUMB instruction, this
8389 // is 1. Otherwise it is 0.
8390 Arm_address thumb_bit
= 0;
8391 Symbol_value
<32> symval
;
8392 bool is_weakly_undefined_without_plt
= false;
8393 if (relnum
!= Target_arm
<big_endian
>::fake_relnum_for_stubs
)
8397 // This is a global symbol. Determine if we use PLT and if the
8398 // final target is THUMB.
8399 if (gsym
->use_plt_offset(reloc_is_non_pic(r_type
)))
8401 // This uses a PLT, change the symbol value.
8402 symval
.set_output_value(target
->plt_section()->address()
8403 + gsym
->plt_offset());
8406 else if (gsym
->is_weak_undefined())
8408 // This is a weakly undefined symbol and we do not use PLT
8409 // for this relocation. A branch targeting this symbol will
8410 // be converted into an NOP.
8411 is_weakly_undefined_without_plt
= true;
8415 // Set thumb bit if symbol:
8416 // -Has type STT_ARM_TFUNC or
8417 // -Has type STT_FUNC, is defined and with LSB in value set.
8419 (((gsym
->type() == elfcpp::STT_ARM_TFUNC
)
8420 || (gsym
->type() == elfcpp::STT_FUNC
8421 && !gsym
->is_undefined()
8422 && ((psymval
->value(object
, 0) & 1) != 0)))
8429 // This is a local symbol. Determine if the final target is THUMB.
8430 // We saved this information when all the local symbols were read.
8431 elfcpp::Elf_types
<32>::Elf_WXword r_info
= rel
.get_r_info();
8432 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(r_info
);
8433 thumb_bit
= object
->local_symbol_is_thumb_function(r_sym
) ? 1 : 0;
8438 // This is a fake relocation synthesized for a stub. It does not have
8439 // a real symbol. We just look at the LSB of the symbol value to
8440 // determine if the target is THUMB or not.
8441 thumb_bit
= ((psymval
->value(object
, 0) & 1) != 0);
8444 // Strip LSB if this points to a THUMB target.
8446 && reloc_property
->uses_thumb_bit()
8447 && ((psymval
->value(object
, 0) & 1) != 0))
8449 Arm_address stripped_value
=
8450 psymval
->value(object
, 0) & ~static_cast<Arm_address
>(1);
8451 symval
.set_output_value(stripped_value
);
8455 // Get the GOT offset if needed.
8456 // The GOT pointer points to the end of the GOT section.
8457 // We need to subtract the size of the GOT section to get
8458 // the actual offset to use in the relocation.
8459 bool have_got_offset
= false;
8460 unsigned int got_offset
= 0;
8463 case elfcpp::R_ARM_GOT_BREL
:
8464 case elfcpp::R_ARM_GOT_PREL
:
8467 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
8468 got_offset
= (gsym
->got_offset(GOT_TYPE_STANDARD
)
8469 - target
->got_size());
8473 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
8474 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
8475 got_offset
= (object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
)
8476 - target
->got_size());
8478 have_got_offset
= true;
8485 // To look up relocation stubs, we need to pass the symbol table index of
8487 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
8489 // Get the addressing origin of the output segment defining the
8490 // symbol gsym if needed (AAELF 4.6.1.2 Relocation types).
8491 Arm_address sym_origin
= 0;
8492 if (reloc_property
->uses_symbol_base())
8494 if (r_type
== elfcpp::R_ARM_BASE_ABS
&& gsym
== NULL
)
8495 // R_ARM_BASE_ABS with the NULL symbol will give the
8496 // absolute address of the GOT origin (GOT_ORG) (see ARM IHI
8497 // 0044C (AAELF): 4.6.1.8 Proxy generating relocations).
8498 sym_origin
= target
->got_plt_section()->address();
8499 else if (gsym
== NULL
)
8501 else if (gsym
->source() == Symbol::IN_OUTPUT_SEGMENT
)
8502 sym_origin
= gsym
->output_segment()->vaddr();
8503 else if (gsym
->source() == Symbol::IN_OUTPUT_DATA
)
8504 sym_origin
= gsym
->output_data()->address();
8506 // TODO: Assumes the segment base to be zero for the global symbols
8507 // till the proper support for the segment-base-relative addressing
8508 // will be implemented. This is consistent with GNU ld.
8511 // For relative addressing relocation, find out the relative address base.
8512 Arm_address relative_address_base
= 0;
8513 switch(reloc_property
->relative_address_base())
8515 case Arm_reloc_property::RAB_NONE
:
8516 // Relocations with relative address bases RAB_TLS and RAB_tp are
8517 // handled by relocate_tls. So we do not need to do anything here.
8518 case Arm_reloc_property::RAB_TLS
:
8519 case Arm_reloc_property::RAB_tp
:
8521 case Arm_reloc_property::RAB_B_S
:
8522 relative_address_base
= sym_origin
;
8524 case Arm_reloc_property::RAB_GOT_ORG
:
8525 relative_address_base
= target
->got_plt_section()->address();
8527 case Arm_reloc_property::RAB_P
:
8528 relative_address_base
= address
;
8530 case Arm_reloc_property::RAB_Pa
:
8531 relative_address_base
= address
& 0xfffffffcU
;
8537 typename
Arm_relocate_functions::Status reloc_status
=
8538 Arm_relocate_functions::STATUS_OKAY
;
8539 bool check_overflow
= reloc_property
->checks_overflow();
8542 case elfcpp::R_ARM_NONE
:
8545 case elfcpp::R_ARM_ABS8
:
8546 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
8548 reloc_status
= Arm_relocate_functions::abs8(view
, object
, psymval
);
8551 case elfcpp::R_ARM_ABS12
:
8552 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
8554 reloc_status
= Arm_relocate_functions::abs12(view
, object
, psymval
);
8557 case elfcpp::R_ARM_ABS16
:
8558 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
8560 reloc_status
= Arm_relocate_functions::abs16(view
, object
, psymval
);
8563 case elfcpp::R_ARM_ABS32
:
8564 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
8566 reloc_status
= Arm_relocate_functions::abs32(view
, object
, psymval
,
8570 case elfcpp::R_ARM_ABS32_NOI
:
8571 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
8573 // No thumb bit for this relocation: (S + A)
8574 reloc_status
= Arm_relocate_functions::abs32(view
, object
, psymval
,
8578 case elfcpp::R_ARM_MOVW_ABS_NC
:
8579 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
8581 reloc_status
= Arm_relocate_functions::movw(view
, object
, psymval
,
8586 case elfcpp::R_ARM_MOVT_ABS
:
8587 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
8589 reloc_status
= Arm_relocate_functions::movt(view
, object
, psymval
, 0);
8592 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
8593 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
8595 reloc_status
= Arm_relocate_functions::thm_movw(view
, object
, psymval
,
8596 0, thumb_bit
, false);
8599 case elfcpp::R_ARM_THM_MOVT_ABS
:
8600 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
8602 reloc_status
= Arm_relocate_functions::thm_movt(view
, object
,
8606 case elfcpp::R_ARM_MOVW_PREL_NC
:
8607 case elfcpp::R_ARM_MOVW_BREL_NC
:
8608 case elfcpp::R_ARM_MOVW_BREL
:
8610 Arm_relocate_functions::movw(view
, object
, psymval
,
8611 relative_address_base
, thumb_bit
,
8615 case elfcpp::R_ARM_MOVT_PREL
:
8616 case elfcpp::R_ARM_MOVT_BREL
:
8618 Arm_relocate_functions::movt(view
, object
, psymval
,
8619 relative_address_base
);
8622 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
8623 case elfcpp::R_ARM_THM_MOVW_BREL_NC
:
8624 case elfcpp::R_ARM_THM_MOVW_BREL
:
8626 Arm_relocate_functions::thm_movw(view
, object
, psymval
,
8627 relative_address_base
,
8628 thumb_bit
, check_overflow
);
8631 case elfcpp::R_ARM_THM_MOVT_PREL
:
8632 case elfcpp::R_ARM_THM_MOVT_BREL
:
8634 Arm_relocate_functions::thm_movt(view
, object
, psymval
,
8635 relative_address_base
);
8638 case elfcpp::R_ARM_REL32
:
8639 reloc_status
= Arm_relocate_functions::rel32(view
, object
, psymval
,
8640 address
, thumb_bit
);
8643 case elfcpp::R_ARM_THM_ABS5
:
8644 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
8646 reloc_status
= Arm_relocate_functions::thm_abs5(view
, object
, psymval
);
8649 // Thumb long branches.
8650 case elfcpp::R_ARM_THM_CALL
:
8651 case elfcpp::R_ARM_THM_XPC22
:
8652 case elfcpp::R_ARM_THM_JUMP24
:
8654 Arm_relocate_functions::thumb_branch_common(
8655 r_type
, relinfo
, view
, gsym
, object
, r_sym
, psymval
, address
,
8656 thumb_bit
, is_weakly_undefined_without_plt
);
8659 case elfcpp::R_ARM_GOTOFF32
:
8661 Arm_address got_origin
;
8662 got_origin
= target
->got_plt_section()->address();
8663 reloc_status
= Arm_relocate_functions::rel32(view
, object
, psymval
,
8664 got_origin
, thumb_bit
);
8668 case elfcpp::R_ARM_BASE_PREL
:
8669 gold_assert(gsym
!= NULL
);
8671 Arm_relocate_functions::base_prel(view
, sym_origin
, address
);
8674 case elfcpp::R_ARM_BASE_ABS
:
8676 if (!should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
8680 reloc_status
= Arm_relocate_functions::base_abs(view
, sym_origin
);
8684 case elfcpp::R_ARM_GOT_BREL
:
8685 gold_assert(have_got_offset
);
8686 reloc_status
= Arm_relocate_functions::got_brel(view
, got_offset
);
8689 case elfcpp::R_ARM_GOT_PREL
:
8690 gold_assert(have_got_offset
);
8691 // Get the address origin for GOT PLT, which is allocated right
8692 // after the GOT section, to calculate an absolute address of
8693 // the symbol GOT entry (got_origin + got_offset).
8694 Arm_address got_origin
;
8695 got_origin
= target
->got_plt_section()->address();
8696 reloc_status
= Arm_relocate_functions::got_prel(view
,
8697 got_origin
+ got_offset
,
8701 case elfcpp::R_ARM_PLT32
:
8702 case elfcpp::R_ARM_CALL
:
8703 case elfcpp::R_ARM_JUMP24
:
8704 case elfcpp::R_ARM_XPC25
:
8705 gold_assert(gsym
== NULL
8706 || gsym
->has_plt_offset()
8707 || gsym
->final_value_is_known()
8708 || (gsym
->is_defined()
8709 && !gsym
->is_from_dynobj()
8710 && !gsym
->is_preemptible()));
8712 Arm_relocate_functions::arm_branch_common(
8713 r_type
, relinfo
, view
, gsym
, object
, r_sym
, psymval
, address
,
8714 thumb_bit
, is_weakly_undefined_without_plt
);
8717 case elfcpp::R_ARM_THM_JUMP19
:
8719 Arm_relocate_functions::thm_jump19(view
, object
, psymval
, address
,
8723 case elfcpp::R_ARM_THM_JUMP6
:
8725 Arm_relocate_functions::thm_jump6(view
, object
, psymval
, address
);
8728 case elfcpp::R_ARM_THM_JUMP8
:
8730 Arm_relocate_functions::thm_jump8(view
, object
, psymval
, address
);
8733 case elfcpp::R_ARM_THM_JUMP11
:
8735 Arm_relocate_functions::thm_jump11(view
, object
, psymval
, address
);
8738 case elfcpp::R_ARM_PREL31
:
8739 reloc_status
= Arm_relocate_functions::prel31(view
, object
, psymval
,
8740 address
, thumb_bit
);
8743 case elfcpp::R_ARM_V4BX
:
8744 if (target
->fix_v4bx() > General_options::FIX_V4BX_NONE
)
8746 const bool is_v4bx_interworking
=
8747 (target
->fix_v4bx() == General_options::FIX_V4BX_INTERWORKING
);
8749 Arm_relocate_functions::v4bx(relinfo
, view
, object
, address
,
8750 is_v4bx_interworking
);
8754 case elfcpp::R_ARM_THM_PC8
:
8756 Arm_relocate_functions::thm_pc8(view
, object
, psymval
, address
);
8759 case elfcpp::R_ARM_THM_PC12
:
8761 Arm_relocate_functions::thm_pc12(view
, object
, psymval
, address
);
8764 case elfcpp::R_ARM_THM_ALU_PREL_11_0
:
8766 Arm_relocate_functions::thm_alu11(view
, object
, psymval
, address
,
8770 case elfcpp::R_ARM_ALU_PC_G0_NC
:
8771 case elfcpp::R_ARM_ALU_PC_G0
:
8772 case elfcpp::R_ARM_ALU_PC_G1_NC
:
8773 case elfcpp::R_ARM_ALU_PC_G1
:
8774 case elfcpp::R_ARM_ALU_PC_G2
:
8775 case elfcpp::R_ARM_ALU_SB_G0_NC
:
8776 case elfcpp::R_ARM_ALU_SB_G0
:
8777 case elfcpp::R_ARM_ALU_SB_G1_NC
:
8778 case elfcpp::R_ARM_ALU_SB_G1
:
8779 case elfcpp::R_ARM_ALU_SB_G2
:
8781 Arm_relocate_functions::arm_grp_alu(view
, object
, psymval
,
8782 reloc_property
->group_index(),
8783 relative_address_base
,
8784 thumb_bit
, check_overflow
);
8787 case elfcpp::R_ARM_LDR_PC_G0
:
8788 case elfcpp::R_ARM_LDR_PC_G1
:
8789 case elfcpp::R_ARM_LDR_PC_G2
:
8790 case elfcpp::R_ARM_LDR_SB_G0
:
8791 case elfcpp::R_ARM_LDR_SB_G1
:
8792 case elfcpp::R_ARM_LDR_SB_G2
:
8794 Arm_relocate_functions::arm_grp_ldr(view
, object
, psymval
,
8795 reloc_property
->group_index(),
8796 relative_address_base
);
8799 case elfcpp::R_ARM_LDRS_PC_G0
:
8800 case elfcpp::R_ARM_LDRS_PC_G1
:
8801 case elfcpp::R_ARM_LDRS_PC_G2
:
8802 case elfcpp::R_ARM_LDRS_SB_G0
:
8803 case elfcpp::R_ARM_LDRS_SB_G1
:
8804 case elfcpp::R_ARM_LDRS_SB_G2
:
8806 Arm_relocate_functions::arm_grp_ldrs(view
, object
, psymval
,
8807 reloc_property
->group_index(),
8808 relative_address_base
);
8811 case elfcpp::R_ARM_LDC_PC_G0
:
8812 case elfcpp::R_ARM_LDC_PC_G1
:
8813 case elfcpp::R_ARM_LDC_PC_G2
:
8814 case elfcpp::R_ARM_LDC_SB_G0
:
8815 case elfcpp::R_ARM_LDC_SB_G1
:
8816 case elfcpp::R_ARM_LDC_SB_G2
:
8818 Arm_relocate_functions::arm_grp_ldc(view
, object
, psymval
,
8819 reloc_property
->group_index(),
8820 relative_address_base
);
8823 // These are initial tls relocs, which are expected when
8825 case elfcpp::R_ARM_TLS_GD32
: // Global-dynamic
8826 case elfcpp::R_ARM_TLS_LDM32
: // Local-dynamic
8827 case elfcpp::R_ARM_TLS_LDO32
: // Alternate local-dynamic
8828 case elfcpp::R_ARM_TLS_IE32
: // Initial-exec
8829 case elfcpp::R_ARM_TLS_LE32
: // Local-exec
8831 this->relocate_tls(relinfo
, target
, relnum
, rel
, r_type
, gsym
, psymval
,
8832 view
, address
, view_size
);
8839 // Report any errors.
8840 switch (reloc_status
)
8842 case Arm_relocate_functions::STATUS_OKAY
:
8844 case Arm_relocate_functions::STATUS_OVERFLOW
:
8845 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
8846 _("relocation overflow in %s"),
8847 reloc_property
->name().c_str());
8849 case Arm_relocate_functions::STATUS_BAD_RELOC
:
8850 gold_error_at_location(
8854 _("unexpected opcode while processing relocation %s"),
8855 reloc_property
->name().c_str());
8864 // Perform a TLS relocation.
8866 template<bool big_endian
>
8867 inline typename Arm_relocate_functions
<big_endian
>::Status
8868 Target_arm
<big_endian
>::Relocate::relocate_tls(
8869 const Relocate_info
<32, big_endian
>* relinfo
,
8870 Target_arm
<big_endian
>* target
,
8872 const elfcpp::Rel
<32, big_endian
>& rel
,
8873 unsigned int r_type
,
8874 const Sized_symbol
<32>* gsym
,
8875 const Symbol_value
<32>* psymval
,
8876 unsigned char* view
,
8877 elfcpp::Elf_types
<32>::Elf_Addr address
,
8878 section_size_type
/*view_size*/ )
8880 typedef Arm_relocate_functions
<big_endian
> ArmRelocFuncs
;
8881 typedef Relocate_functions
<32, big_endian
> RelocFuncs
;
8882 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
8884 const Sized_relobj
<32, big_endian
>* object
= relinfo
->object
;
8886 elfcpp::Elf_types
<32>::Elf_Addr value
= psymval
->value(object
, 0);
8888 const bool is_final
= (gsym
== NULL
8889 ? !parameters
->options().shared()
8890 : gsym
->final_value_is_known());
8891 const tls::Tls_optimization optimized_type
8892 = Target_arm
<big_endian
>::optimize_tls_reloc(is_final
, r_type
);
8895 case elfcpp::R_ARM_TLS_GD32
: // Global-dynamic
8897 unsigned int got_type
= GOT_TYPE_TLS_PAIR
;
8898 unsigned int got_offset
;
8901 gold_assert(gsym
->has_got_offset(got_type
));
8902 got_offset
= gsym
->got_offset(got_type
) - target
->got_size();
8906 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
8907 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
8908 got_offset
= (object
->local_got_offset(r_sym
, got_type
)
8909 - target
->got_size());
8911 if (optimized_type
== tls::TLSOPT_NONE
)
8913 Arm_address got_entry
=
8914 target
->got_plt_section()->address() + got_offset
;
8916 // Relocate the field with the PC relative offset of the pair of
8918 RelocFuncs::pcrel32(view
, got_entry
, address
);
8919 return ArmRelocFuncs::STATUS_OKAY
;
8924 case elfcpp::R_ARM_TLS_LDM32
: // Local-dynamic
8925 if (optimized_type
== tls::TLSOPT_NONE
)
8927 // Relocate the field with the offset of the GOT entry for
8928 // the module index.
8929 unsigned int got_offset
;
8930 got_offset
= (target
->got_mod_index_entry(NULL
, NULL
, NULL
)
8931 - target
->got_size());
8932 Arm_address got_entry
=
8933 target
->got_plt_section()->address() + got_offset
;
8935 // Relocate the field with the PC relative offset of the pair of
8937 RelocFuncs::pcrel32(view
, got_entry
, address
);
8938 return ArmRelocFuncs::STATUS_OKAY
;
8942 case elfcpp::R_ARM_TLS_LDO32
: // Alternate local-dynamic
8943 RelocFuncs::rel32(view
, value
);
8944 return ArmRelocFuncs::STATUS_OKAY
;
8946 case elfcpp::R_ARM_TLS_IE32
: // Initial-exec
8947 if (optimized_type
== tls::TLSOPT_NONE
)
8949 // Relocate the field with the offset of the GOT entry for
8950 // the tp-relative offset of the symbol.
8951 unsigned int got_type
= GOT_TYPE_TLS_OFFSET
;
8952 unsigned int got_offset
;
8955 gold_assert(gsym
->has_got_offset(got_type
));
8956 got_offset
= gsym
->got_offset(got_type
);
8960 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
8961 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
8962 got_offset
= object
->local_got_offset(r_sym
, got_type
);
8965 // All GOT offsets are relative to the end of the GOT.
8966 got_offset
-= target
->got_size();
8968 Arm_address got_entry
=
8969 target
->got_plt_section()->address() + got_offset
;
8971 // Relocate the field with the PC relative offset of the GOT entry.
8972 RelocFuncs::pcrel32(view
, got_entry
, address
);
8973 return ArmRelocFuncs::STATUS_OKAY
;
8977 case elfcpp::R_ARM_TLS_LE32
: // Local-exec
8978 // If we're creating a shared library, a dynamic relocation will
8979 // have been created for this location, so do not apply it now.
8980 if (!parameters
->options().shared())
8982 gold_assert(tls_segment
!= NULL
);
8984 // $tp points to the TCB, which is followed by the TLS, so we
8985 // need to add TCB size to the offset.
8986 Arm_address aligned_tcb_size
=
8987 align_address(ARM_TCB_SIZE
, tls_segment
->maximum_alignment());
8988 RelocFuncs::rel32(view
, value
+ aligned_tcb_size
);
8991 return ArmRelocFuncs::STATUS_OKAY
;
8997 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
8998 _("unsupported reloc %u"),
9000 return ArmRelocFuncs::STATUS_BAD_RELOC
;
9003 // Relocate section data.
9005 template<bool big_endian
>
9007 Target_arm
<big_endian
>::relocate_section(
9008 const Relocate_info
<32, big_endian
>* relinfo
,
9009 unsigned int sh_type
,
9010 const unsigned char* prelocs
,
9012 Output_section
* output_section
,
9013 bool needs_special_offset_handling
,
9014 unsigned char* view
,
9015 Arm_address address
,
9016 section_size_type view_size
,
9017 const Reloc_symbol_changes
* reloc_symbol_changes
)
9019 typedef typename Target_arm
<big_endian
>::Relocate Arm_relocate
;
9020 gold_assert(sh_type
== elfcpp::SHT_REL
);
9022 // See if we are relocating a relaxed input section. If so, the view
9023 // covers the whole output section and we need to adjust accordingly.
9024 if (needs_special_offset_handling
)
9026 const Output_relaxed_input_section
* poris
=
9027 output_section
->find_relaxed_input_section(relinfo
->object
,
9028 relinfo
->data_shndx
);
9031 Arm_address section_address
= poris
->address();
9032 section_size_type section_size
= poris
->data_size();
9034 gold_assert((section_address
>= address
)
9035 && ((section_address
+ section_size
)
9036 <= (address
+ view_size
)));
9038 off_t offset
= section_address
- address
;
9041 view_size
= section_size
;
9045 gold::relocate_section
<32, big_endian
, Target_arm
, elfcpp::SHT_REL
,
9052 needs_special_offset_handling
,
9056 reloc_symbol_changes
);
9059 // Return the size of a relocation while scanning during a relocatable
9062 template<bool big_endian
>
9064 Target_arm
<big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
9065 unsigned int r_type
,
9068 r_type
= get_real_reloc_type(r_type
);
9069 const Arm_reloc_property
* arp
=
9070 arm_reloc_property_table
->get_implemented_static_reloc_property(r_type
);
9075 std::string reloc_name
=
9076 arm_reloc_property_table
->reloc_name_in_error_message(r_type
);
9077 gold_error(_("%s: unexpected %s in object file"),
9078 object
->name().c_str(), reloc_name
.c_str());
9083 // Scan the relocs during a relocatable link.
9085 template<bool big_endian
>
9087 Target_arm
<big_endian
>::scan_relocatable_relocs(
9088 Symbol_table
* symtab
,
9090 Sized_relobj
<32, big_endian
>* object
,
9091 unsigned int data_shndx
,
9092 unsigned int sh_type
,
9093 const unsigned char* prelocs
,
9095 Output_section
* output_section
,
9096 bool needs_special_offset_handling
,
9097 size_t local_symbol_count
,
9098 const unsigned char* plocal_symbols
,
9099 Relocatable_relocs
* rr
)
9101 gold_assert(sh_type
== elfcpp::SHT_REL
);
9103 typedef Arm_scan_relocatable_relocs
<big_endian
, elfcpp::SHT_REL
,
9104 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
9106 gold::scan_relocatable_relocs
<32, big_endian
, elfcpp::SHT_REL
,
9107 Scan_relocatable_relocs
>(
9115 needs_special_offset_handling
,
9121 // Relocate a section during a relocatable link.
9123 template<bool big_endian
>
9125 Target_arm
<big_endian
>::relocate_for_relocatable(
9126 const Relocate_info
<32, big_endian
>* relinfo
,
9127 unsigned int sh_type
,
9128 const unsigned char* prelocs
,
9130 Output_section
* output_section
,
9131 off_t offset_in_output_section
,
9132 const Relocatable_relocs
* rr
,
9133 unsigned char* view
,
9134 Arm_address view_address
,
9135 section_size_type view_size
,
9136 unsigned char* reloc_view
,
9137 section_size_type reloc_view_size
)
9139 gold_assert(sh_type
== elfcpp::SHT_REL
);
9141 gold::relocate_for_relocatable
<32, big_endian
, elfcpp::SHT_REL
>(
9146 offset_in_output_section
,
9155 // Perform target-specific processing in a relocatable link. This is
9156 // only used if we use the relocation strategy RELOC_SPECIAL.
9158 template<bool big_endian
>
9160 Target_arm
<big_endian
>::relocate_special_relocatable(
9161 const Relocate_info
<32, big_endian
>* relinfo
,
9162 unsigned int sh_type
,
9163 const unsigned char* preloc_in
,
9165 Output_section
* output_section
,
9166 off_t offset_in_output_section
,
9167 unsigned char* view
,
9168 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
9170 unsigned char* preloc_out
)
9172 // We can only handle REL type relocation sections.
9173 gold_assert(sh_type
== elfcpp::SHT_REL
);
9175 typedef typename Reloc_types
<elfcpp::SHT_REL
, 32, big_endian
>::Reloc Reltype
;
9176 typedef typename Reloc_types
<elfcpp::SHT_REL
, 32, big_endian
>::Reloc_write
9178 const Arm_address invalid_address
= static_cast<Arm_address
>(0) - 1;
9180 const Arm_relobj
<big_endian
>* object
=
9181 Arm_relobj
<big_endian
>::as_arm_relobj(relinfo
->object
);
9182 const unsigned int local_count
= object
->local_symbol_count();
9184 Reltype
reloc(preloc_in
);
9185 Reltype_write
reloc_write(preloc_out
);
9187 elfcpp::Elf_types
<32>::Elf_WXword r_info
= reloc
.get_r_info();
9188 const unsigned int r_sym
= elfcpp::elf_r_sym
<32>(r_info
);
9189 const unsigned int r_type
= elfcpp::elf_r_type
<32>(r_info
);
9191 const Arm_reloc_property
* arp
=
9192 arm_reloc_property_table
->get_implemented_static_reloc_property(r_type
);
9193 gold_assert(arp
!= NULL
);
9195 // Get the new symbol index.
9196 // We only use RELOC_SPECIAL strategy in local relocations.
9197 gold_assert(r_sym
< local_count
);
9199 // We are adjusting a section symbol. We need to find
9200 // the symbol table index of the section symbol for
9201 // the output section corresponding to input section
9202 // in which this symbol is defined.
9204 unsigned int shndx
= object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
9205 gold_assert(is_ordinary
);
9206 Output_section
* os
= object
->output_section(shndx
);
9207 gold_assert(os
!= NULL
);
9208 gold_assert(os
->needs_symtab_index());
9209 unsigned int new_symndx
= os
->symtab_index();
9211 // Get the new offset--the location in the output section where
9212 // this relocation should be applied.
9214 Arm_address offset
= reloc
.get_r_offset();
9215 Arm_address new_offset
;
9216 if (offset_in_output_section
!= invalid_address
)
9217 new_offset
= offset
+ offset_in_output_section
;
9220 section_offset_type sot_offset
=
9221 convert_types
<section_offset_type
, Arm_address
>(offset
);
9222 section_offset_type new_sot_offset
=
9223 output_section
->output_offset(object
, relinfo
->data_shndx
,
9225 gold_assert(new_sot_offset
!= -1);
9226 new_offset
= new_sot_offset
;
9229 // In an object file, r_offset is an offset within the section.
9230 // In an executable or dynamic object, generated by
9231 // --emit-relocs, r_offset is an absolute address.
9232 if (!parameters
->options().relocatable())
9234 new_offset
+= view_address
;
9235 if (offset_in_output_section
!= invalid_address
)
9236 new_offset
-= offset_in_output_section
;
9239 reloc_write
.put_r_offset(new_offset
);
9240 reloc_write
.put_r_info(elfcpp::elf_r_info
<32>(new_symndx
, r_type
));
9242 // Handle the reloc addend.
9243 // The relocation uses a section symbol in the input file.
9244 // We are adjusting it to use a section symbol in the output
9245 // file. The input section symbol refers to some address in
9246 // the input section. We need the relocation in the output
9247 // file to refer to that same address. This adjustment to
9248 // the addend is the same calculation we use for a simple
9249 // absolute relocation for the input section symbol.
9251 const Symbol_value
<32>* psymval
= object
->local_symbol(r_sym
);
9253 // Handle THUMB bit.
9254 Symbol_value
<32> symval
;
9255 Arm_address thumb_bit
=
9256 object
->local_symbol_is_thumb_function(r_sym
) ? 1 : 0;
9258 && arp
->uses_thumb_bit()
9259 && ((psymval
->value(object
, 0) & 1) != 0))
9261 Arm_address stripped_value
=
9262 psymval
->value(object
, 0) & ~static_cast<Arm_address
>(1);
9263 symval
.set_output_value(stripped_value
);
9267 unsigned char* paddend
= view
+ offset
;
9268 typename Arm_relocate_functions
<big_endian
>::Status reloc_status
=
9269 Arm_relocate_functions
<big_endian
>::STATUS_OKAY
;
9272 case elfcpp::R_ARM_ABS8
:
9273 reloc_status
= Arm_relocate_functions
<big_endian
>::abs8(paddend
, object
,
9277 case elfcpp::R_ARM_ABS12
:
9278 reloc_status
= Arm_relocate_functions
<big_endian
>::abs12(paddend
, object
,
9282 case elfcpp::R_ARM_ABS16
:
9283 reloc_status
= Arm_relocate_functions
<big_endian
>::abs16(paddend
, object
,
9287 case elfcpp::R_ARM_THM_ABS5
:
9288 reloc_status
= Arm_relocate_functions
<big_endian
>::thm_abs5(paddend
,
9293 case elfcpp::R_ARM_MOVW_ABS_NC
:
9294 case elfcpp::R_ARM_MOVW_PREL_NC
:
9295 case elfcpp::R_ARM_MOVW_BREL_NC
:
9296 case elfcpp::R_ARM_MOVW_BREL
:
9297 reloc_status
= Arm_relocate_functions
<big_endian
>::movw(
9298 paddend
, object
, psymval
, 0, thumb_bit
, arp
->checks_overflow());
9301 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
9302 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
9303 case elfcpp::R_ARM_THM_MOVW_BREL_NC
:
9304 case elfcpp::R_ARM_THM_MOVW_BREL
:
9305 reloc_status
= Arm_relocate_functions
<big_endian
>::thm_movw(
9306 paddend
, object
, psymval
, 0, thumb_bit
, arp
->checks_overflow());
9309 case elfcpp::R_ARM_THM_CALL
:
9310 case elfcpp::R_ARM_THM_XPC22
:
9311 case elfcpp::R_ARM_THM_JUMP24
:
9313 Arm_relocate_functions
<big_endian
>::thumb_branch_common(
9314 r_type
, relinfo
, paddend
, NULL
, object
, 0, psymval
, 0, thumb_bit
,
9318 case elfcpp::R_ARM_PLT32
:
9319 case elfcpp::R_ARM_CALL
:
9320 case elfcpp::R_ARM_JUMP24
:
9321 case elfcpp::R_ARM_XPC25
:
9323 Arm_relocate_functions
<big_endian
>::arm_branch_common(
9324 r_type
, relinfo
, paddend
, NULL
, object
, 0, psymval
, 0, thumb_bit
,
9328 case elfcpp::R_ARM_THM_JUMP19
:
9330 Arm_relocate_functions
<big_endian
>::thm_jump19(paddend
, object
,
9331 psymval
, 0, thumb_bit
);
9334 case elfcpp::R_ARM_THM_JUMP6
:
9336 Arm_relocate_functions
<big_endian
>::thm_jump6(paddend
, object
, psymval
,
9340 case elfcpp::R_ARM_THM_JUMP8
:
9342 Arm_relocate_functions
<big_endian
>::thm_jump8(paddend
, object
, psymval
,
9346 case elfcpp::R_ARM_THM_JUMP11
:
9348 Arm_relocate_functions
<big_endian
>::thm_jump11(paddend
, object
, psymval
,
9352 case elfcpp::R_ARM_PREL31
:
9354 Arm_relocate_functions
<big_endian
>::prel31(paddend
, object
, psymval
, 0,
9358 case elfcpp::R_ARM_THM_PC8
:
9360 Arm_relocate_functions
<big_endian
>::thm_pc8(paddend
, object
, psymval
,
9364 case elfcpp::R_ARM_THM_PC12
:
9366 Arm_relocate_functions
<big_endian
>::thm_pc12(paddend
, object
, psymval
,
9370 case elfcpp::R_ARM_THM_ALU_PREL_11_0
:
9372 Arm_relocate_functions
<big_endian
>::thm_alu11(paddend
, object
, psymval
,
9376 // These relocation truncate relocation results so we cannot handle them
9377 // in a relocatable link.
9378 case elfcpp::R_ARM_MOVT_ABS
:
9379 case elfcpp::R_ARM_THM_MOVT_ABS
:
9380 case elfcpp::R_ARM_MOVT_PREL
:
9381 case elfcpp::R_ARM_MOVT_BREL
:
9382 case elfcpp::R_ARM_THM_MOVT_PREL
:
9383 case elfcpp::R_ARM_THM_MOVT_BREL
:
9384 case elfcpp::R_ARM_ALU_PC_G0_NC
:
9385 case elfcpp::R_ARM_ALU_PC_G0
:
9386 case elfcpp::R_ARM_ALU_PC_G1_NC
:
9387 case elfcpp::R_ARM_ALU_PC_G1
:
9388 case elfcpp::R_ARM_ALU_PC_G2
:
9389 case elfcpp::R_ARM_ALU_SB_G0_NC
:
9390 case elfcpp::R_ARM_ALU_SB_G0
:
9391 case elfcpp::R_ARM_ALU_SB_G1_NC
:
9392 case elfcpp::R_ARM_ALU_SB_G1
:
9393 case elfcpp::R_ARM_ALU_SB_G2
:
9394 case elfcpp::R_ARM_LDR_PC_G0
:
9395 case elfcpp::R_ARM_LDR_PC_G1
:
9396 case elfcpp::R_ARM_LDR_PC_G2
:
9397 case elfcpp::R_ARM_LDR_SB_G0
:
9398 case elfcpp::R_ARM_LDR_SB_G1
:
9399 case elfcpp::R_ARM_LDR_SB_G2
:
9400 case elfcpp::R_ARM_LDRS_PC_G0
:
9401 case elfcpp::R_ARM_LDRS_PC_G1
:
9402 case elfcpp::R_ARM_LDRS_PC_G2
:
9403 case elfcpp::R_ARM_LDRS_SB_G0
:
9404 case elfcpp::R_ARM_LDRS_SB_G1
:
9405 case elfcpp::R_ARM_LDRS_SB_G2
:
9406 case elfcpp::R_ARM_LDC_PC_G0
:
9407 case elfcpp::R_ARM_LDC_PC_G1
:
9408 case elfcpp::R_ARM_LDC_PC_G2
:
9409 case elfcpp::R_ARM_LDC_SB_G0
:
9410 case elfcpp::R_ARM_LDC_SB_G1
:
9411 case elfcpp::R_ARM_LDC_SB_G2
:
9412 gold_error(_("cannot handle %s in a relocatable link"),
9413 arp
->name().c_str());
9420 // Report any errors.
9421 switch (reloc_status
)
9423 case Arm_relocate_functions
<big_endian
>::STATUS_OKAY
:
9425 case Arm_relocate_functions
<big_endian
>::STATUS_OVERFLOW
:
9426 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
9427 _("relocation overflow in %s"),
9428 arp
->name().c_str());
9430 case Arm_relocate_functions
<big_endian
>::STATUS_BAD_RELOC
:
9431 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
9432 _("unexpected opcode while processing relocation %s"),
9433 arp
->name().c_str());
9440 // Return the value to use for a dynamic symbol which requires special
9441 // treatment. This is how we support equality comparisons of function
9442 // pointers across shared library boundaries, as described in the
9443 // processor specific ABI supplement.
9445 template<bool big_endian
>
9447 Target_arm
<big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
9449 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
9450 return this->plt_section()->address() + gsym
->plt_offset();
9453 // Map platform-specific relocs to real relocs
9455 template<bool big_endian
>
9457 Target_arm
<big_endian
>::get_real_reloc_type (unsigned int r_type
)
9461 case elfcpp::R_ARM_TARGET1
:
9462 // This is either R_ARM_ABS32 or R_ARM_REL32;
9463 return elfcpp::R_ARM_ABS32
;
9465 case elfcpp::R_ARM_TARGET2
:
9466 // This can be any reloc type but ususally is R_ARM_GOT_PREL
9467 return elfcpp::R_ARM_GOT_PREL
;
9474 // Whether if two EABI versions V1 and V2 are compatible.
9476 template<bool big_endian
>
9478 Target_arm
<big_endian
>::are_eabi_versions_compatible(
9479 elfcpp::Elf_Word v1
,
9480 elfcpp::Elf_Word v2
)
9482 // v4 and v5 are the same spec before and after it was released,
9483 // so allow mixing them.
9484 if ((v1
== elfcpp::EF_ARM_EABI_UNKNOWN
|| v2
== elfcpp::EF_ARM_EABI_UNKNOWN
)
9485 || (v1
== elfcpp::EF_ARM_EABI_VER4
&& v2
== elfcpp::EF_ARM_EABI_VER5
)
9486 || (v1
== elfcpp::EF_ARM_EABI_VER5
&& v2
== elfcpp::EF_ARM_EABI_VER4
))
9492 // Combine FLAGS from an input object called NAME and the processor-specific
9493 // flags in the ELF header of the output. Much of this is adapted from the
9494 // processor-specific flags merging code in elf32_arm_merge_private_bfd_data
9495 // in bfd/elf32-arm.c.
9497 template<bool big_endian
>
9499 Target_arm
<big_endian
>::merge_processor_specific_flags(
9500 const std::string
& name
,
9501 elfcpp::Elf_Word flags
)
9503 if (this->are_processor_specific_flags_set())
9505 elfcpp::Elf_Word out_flags
= this->processor_specific_flags();
9507 // Nothing to merge if flags equal to those in output.
9508 if (flags
== out_flags
)
9511 // Complain about various flag mismatches.
9512 elfcpp::Elf_Word version1
= elfcpp::arm_eabi_version(flags
);
9513 elfcpp::Elf_Word version2
= elfcpp::arm_eabi_version(out_flags
);
9514 if (!this->are_eabi_versions_compatible(version1
, version2
)
9515 && parameters
->options().warn_mismatch())
9516 gold_error(_("Source object %s has EABI version %d but output has "
9517 "EABI version %d."),
9519 (flags
& elfcpp::EF_ARM_EABIMASK
) >> 24,
9520 (out_flags
& elfcpp::EF_ARM_EABIMASK
) >> 24);
9524 // If the input is the default architecture and had the default
9525 // flags then do not bother setting the flags for the output
9526 // architecture, instead allow future merges to do this. If no
9527 // future merges ever set these flags then they will retain their
9528 // uninitialised values, which surprise surprise, correspond
9529 // to the default values.
9533 // This is the first time, just copy the flags.
9534 // We only copy the EABI version for now.
9535 this->set_processor_specific_flags(flags
& elfcpp::EF_ARM_EABIMASK
);
9539 // Adjust ELF file header.
9540 template<bool big_endian
>
9542 Target_arm
<big_endian
>::do_adjust_elf_header(
9543 unsigned char* view
,
9546 gold_assert(len
== elfcpp::Elf_sizes
<32>::ehdr_size
);
9548 elfcpp::Ehdr
<32, big_endian
> ehdr(view
);
9549 unsigned char e_ident
[elfcpp::EI_NIDENT
];
9550 memcpy(e_ident
, ehdr
.get_e_ident(), elfcpp::EI_NIDENT
);
9552 if (elfcpp::arm_eabi_version(this->processor_specific_flags())
9553 == elfcpp::EF_ARM_EABI_UNKNOWN
)
9554 e_ident
[elfcpp::EI_OSABI
] = elfcpp::ELFOSABI_ARM
;
9556 e_ident
[elfcpp::EI_OSABI
] = 0;
9557 e_ident
[elfcpp::EI_ABIVERSION
] = 0;
9559 // FIXME: Do EF_ARM_BE8 adjustment.
9561 elfcpp::Ehdr_write
<32, big_endian
> oehdr(view
);
9562 oehdr
.put_e_ident(e_ident
);
9565 // do_make_elf_object to override the same function in the base class.
9566 // We need to use a target-specific sub-class of Sized_relobj<32, big_endian>
9567 // to store ARM specific information. Hence we need to have our own
9568 // ELF object creation.
9570 template<bool big_endian
>
9572 Target_arm
<big_endian
>::do_make_elf_object(
9573 const std::string
& name
,
9574 Input_file
* input_file
,
9575 off_t offset
, const elfcpp::Ehdr
<32, big_endian
>& ehdr
)
9577 int et
= ehdr
.get_e_type();
9578 if (et
== elfcpp::ET_REL
)
9580 Arm_relobj
<big_endian
>* obj
=
9581 new Arm_relobj
<big_endian
>(name
, input_file
, offset
, ehdr
);
9585 else if (et
== elfcpp::ET_DYN
)
9587 Sized_dynobj
<32, big_endian
>* obj
=
9588 new Arm_dynobj
<big_endian
>(name
, input_file
, offset
, ehdr
);
9594 gold_error(_("%s: unsupported ELF file type %d"),
9600 // Read the architecture from the Tag_also_compatible_with attribute, if any.
9601 // Returns -1 if no architecture could be read.
9602 // This is adapted from get_secondary_compatible_arch() in bfd/elf32-arm.c.
9604 template<bool big_endian
>
9606 Target_arm
<big_endian
>::get_secondary_compatible_arch(
9607 const Attributes_section_data
* pasd
)
9609 const Object_attribute
*known_attributes
=
9610 pasd
->known_attributes(Object_attribute::OBJ_ATTR_PROC
);
9612 // Note: the tag and its argument below are uleb128 values, though
9613 // currently-defined values fit in one byte for each.
9614 const std::string
& sv
=
9615 known_attributes
[elfcpp::Tag_also_compatible_with
].string_value();
9617 && sv
.data()[0] == elfcpp::Tag_CPU_arch
9618 && (sv
.data()[1] & 128) != 128)
9619 return sv
.data()[1];
9621 // This tag is "safely ignorable", so don't complain if it looks funny.
9625 // Set, or unset, the architecture of the Tag_also_compatible_with attribute.
9626 // The tag is removed if ARCH is -1.
9627 // This is adapted from set_secondary_compatible_arch() in bfd/elf32-arm.c.
9629 template<bool big_endian
>
9631 Target_arm
<big_endian
>::set_secondary_compatible_arch(
9632 Attributes_section_data
* pasd
,
9635 Object_attribute
*known_attributes
=
9636 pasd
->known_attributes(Object_attribute::OBJ_ATTR_PROC
);
9640 known_attributes
[elfcpp::Tag_also_compatible_with
].set_string_value("");
9644 // Note: the tag and its argument below are uleb128 values, though
9645 // currently-defined values fit in one byte for each.
9647 sv
[0] = elfcpp::Tag_CPU_arch
;
9648 gold_assert(arch
!= 0);
9652 known_attributes
[elfcpp::Tag_also_compatible_with
].set_string_value(sv
);
9655 // Combine two values for Tag_CPU_arch, taking secondary compatibility tags
9657 // This is adapted from tag_cpu_arch_combine() in bfd/elf32-arm.c.
9659 template<bool big_endian
>
9661 Target_arm
<big_endian
>::tag_cpu_arch_combine(
9664 int* secondary_compat_out
,
9666 int secondary_compat
)
9668 #define T(X) elfcpp::TAG_CPU_ARCH_##X
9669 static const int v6t2
[] =
9681 static const int v6k
[] =
9694 static const int v7
[] =
9708 static const int v6_m
[] =
9723 static const int v6s_m
[] =
9739 static const int v7e_m
[] =
9756 static const int v4t_plus_v6_m
[] =
9772 T(V4T_PLUS_V6_M
) // V4T plus V6_M.
9774 static const int *comb
[] =
9782 // Pseudo-architecture.
9786 // Check we've not got a higher architecture than we know about.
9788 if (oldtag
>= elfcpp::MAX_TAG_CPU_ARCH
|| newtag
>= elfcpp::MAX_TAG_CPU_ARCH
)
9790 gold_error(_("%s: unknown CPU architecture"), name
);
9794 // Override old tag if we have a Tag_also_compatible_with on the output.
9796 if ((oldtag
== T(V6_M
) && *secondary_compat_out
== T(V4T
))
9797 || (oldtag
== T(V4T
) && *secondary_compat_out
== T(V6_M
)))
9798 oldtag
= T(V4T_PLUS_V6_M
);
9800 // And override the new tag if we have a Tag_also_compatible_with on the
9803 if ((newtag
== T(V6_M
) && secondary_compat
== T(V4T
))
9804 || (newtag
== T(V4T
) && secondary_compat
== T(V6_M
)))
9805 newtag
= T(V4T_PLUS_V6_M
);
9807 // Architectures before V6KZ add features monotonically.
9808 int tagh
= std::max(oldtag
, newtag
);
9809 if (tagh
<= elfcpp::TAG_CPU_ARCH_V6KZ
)
9812 int tagl
= std::min(oldtag
, newtag
);
9813 int result
= comb
[tagh
- T(V6T2
)][tagl
];
9815 // Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
9816 // as the canonical version.
9817 if (result
== T(V4T_PLUS_V6_M
))
9820 *secondary_compat_out
= T(V6_M
);
9823 *secondary_compat_out
= -1;
9827 gold_error(_("%s: conflicting CPU architectures %d/%d"),
9828 name
, oldtag
, newtag
);
9836 // Helper to print AEABI enum tag value.
9838 template<bool big_endian
>
9840 Target_arm
<big_endian
>::aeabi_enum_name(unsigned int value
)
9842 static const char *aeabi_enum_names
[] =
9843 { "", "variable-size", "32-bit", "" };
9844 const size_t aeabi_enum_names_size
=
9845 sizeof(aeabi_enum_names
) / sizeof(aeabi_enum_names
[0]);
9847 if (value
< aeabi_enum_names_size
)
9848 return std::string(aeabi_enum_names
[value
]);
9852 sprintf(buffer
, "<unknown value %u>", value
);
9853 return std::string(buffer
);
9857 // Return the string value to store in TAG_CPU_name.
9859 template<bool big_endian
>
9861 Target_arm
<big_endian
>::tag_cpu_name_value(unsigned int value
)
9863 static const char *name_table
[] = {
9864 // These aren't real CPU names, but we can't guess
9865 // that from the architecture version alone.
9881 const size_t name_table_size
= sizeof(name_table
) / sizeof(name_table
[0]);
9883 if (value
< name_table_size
)
9884 return std::string(name_table
[value
]);
9888 sprintf(buffer
, "<unknown CPU value %u>", value
);
9889 return std::string(buffer
);
9893 // Merge object attributes from input file called NAME with those of the
9894 // output. The input object attributes are in the object pointed by PASD.
9896 template<bool big_endian
>
9898 Target_arm
<big_endian
>::merge_object_attributes(
9900 const Attributes_section_data
* pasd
)
9902 // Return if there is no attributes section data.
9906 // If output has no object attributes, just copy.
9907 const int vendor
= Object_attribute::OBJ_ATTR_PROC
;
9908 if (this->attributes_section_data_
== NULL
)
9910 this->attributes_section_data_
= new Attributes_section_data(*pasd
);
9911 Object_attribute
* out_attr
=
9912 this->attributes_section_data_
->known_attributes(vendor
);
9914 // We do not output objects with Tag_MPextension_use_legacy - we move
9915 // the attribute's value to Tag_MPextension_use. */
9916 if (out_attr
[elfcpp::Tag_MPextension_use_legacy
].int_value() != 0)
9918 if (out_attr
[elfcpp::Tag_MPextension_use
].int_value() != 0
9919 && out_attr
[elfcpp::Tag_MPextension_use_legacy
].int_value()
9920 != out_attr
[elfcpp::Tag_MPextension_use
].int_value())
9922 gold_error(_("%s has both the current and legacy "
9923 "Tag_MPextension_use attributes"),
9927 out_attr
[elfcpp::Tag_MPextension_use
] =
9928 out_attr
[elfcpp::Tag_MPextension_use_legacy
];
9929 out_attr
[elfcpp::Tag_MPextension_use_legacy
].set_type(0);
9930 out_attr
[elfcpp::Tag_MPextension_use_legacy
].set_int_value(0);
9936 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
9937 Object_attribute
* out_attr
=
9938 this->attributes_section_data_
->known_attributes(vendor
);
9940 // This needs to happen before Tag_ABI_FP_number_model is merged. */
9941 if (in_attr
[elfcpp::Tag_ABI_VFP_args
].int_value()
9942 != out_attr
[elfcpp::Tag_ABI_VFP_args
].int_value())
9944 // Ignore mismatches if the object doesn't use floating point. */
9945 if (out_attr
[elfcpp::Tag_ABI_FP_number_model
].int_value() == 0)
9946 out_attr
[elfcpp::Tag_ABI_VFP_args
].set_int_value(
9947 in_attr
[elfcpp::Tag_ABI_VFP_args
].int_value());
9948 else if (in_attr
[elfcpp::Tag_ABI_FP_number_model
].int_value() != 0
9949 && parameters
->options().warn_mismatch())
9950 gold_error(_("%s uses VFP register arguments, output does not"),
9954 for (int i
= 4; i
< Vendor_object_attributes::NUM_KNOWN_ATTRIBUTES
; ++i
)
9956 // Merge this attribute with existing attributes.
9959 case elfcpp::Tag_CPU_raw_name
:
9960 case elfcpp::Tag_CPU_name
:
9961 // These are merged after Tag_CPU_arch.
9964 case elfcpp::Tag_ABI_optimization_goals
:
9965 case elfcpp::Tag_ABI_FP_optimization_goals
:
9966 // Use the first value seen.
9969 case elfcpp::Tag_CPU_arch
:
9971 unsigned int saved_out_attr
= out_attr
->int_value();
9972 // Merge Tag_CPU_arch and Tag_also_compatible_with.
9973 int secondary_compat
=
9974 this->get_secondary_compatible_arch(pasd
);
9975 int secondary_compat_out
=
9976 this->get_secondary_compatible_arch(
9977 this->attributes_section_data_
);
9978 out_attr
[i
].set_int_value(
9979 tag_cpu_arch_combine(name
, out_attr
[i
].int_value(),
9980 &secondary_compat_out
,
9981 in_attr
[i
].int_value(),
9983 this->set_secondary_compatible_arch(this->attributes_section_data_
,
9984 secondary_compat_out
);
9986 // Merge Tag_CPU_name and Tag_CPU_raw_name.
9987 if (out_attr
[i
].int_value() == saved_out_attr
)
9988 ; // Leave the names alone.
9989 else if (out_attr
[i
].int_value() == in_attr
[i
].int_value())
9991 // The output architecture has been changed to match the
9992 // input architecture. Use the input names.
9993 out_attr
[elfcpp::Tag_CPU_name
].set_string_value(
9994 in_attr
[elfcpp::Tag_CPU_name
].string_value());
9995 out_attr
[elfcpp::Tag_CPU_raw_name
].set_string_value(
9996 in_attr
[elfcpp::Tag_CPU_raw_name
].string_value());
10000 out_attr
[elfcpp::Tag_CPU_name
].set_string_value("");
10001 out_attr
[elfcpp::Tag_CPU_raw_name
].set_string_value("");
10004 // If we still don't have a value for Tag_CPU_name,
10005 // make one up now. Tag_CPU_raw_name remains blank.
10006 if (out_attr
[elfcpp::Tag_CPU_name
].string_value() == "")
10008 const std::string cpu_name
=
10009 this->tag_cpu_name_value(out_attr
[i
].int_value());
10010 // FIXME: If we see an unknown CPU, this will be set
10011 // to "<unknown CPU n>", where n is the attribute value.
10012 // This is different from BFD, which leaves the name alone.
10013 out_attr
[elfcpp::Tag_CPU_name
].set_string_value(cpu_name
);
10018 case elfcpp::Tag_ARM_ISA_use
:
10019 case elfcpp::Tag_THUMB_ISA_use
:
10020 case elfcpp::Tag_WMMX_arch
:
10021 case elfcpp::Tag_Advanced_SIMD_arch
:
10022 // ??? Do Advanced_SIMD (NEON) and WMMX conflict?
10023 case elfcpp::Tag_ABI_FP_rounding
:
10024 case elfcpp::Tag_ABI_FP_exceptions
:
10025 case elfcpp::Tag_ABI_FP_user_exceptions
:
10026 case elfcpp::Tag_ABI_FP_number_model
:
10027 case elfcpp::Tag_VFP_HP_extension
:
10028 case elfcpp::Tag_CPU_unaligned_access
:
10029 case elfcpp::Tag_T2EE_use
:
10030 case elfcpp::Tag_Virtualization_use
:
10031 case elfcpp::Tag_MPextension_use
:
10032 // Use the largest value specified.
10033 if (in_attr
[i
].int_value() > out_attr
[i
].int_value())
10034 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
10037 case elfcpp::Tag_ABI_align8_preserved
:
10038 case elfcpp::Tag_ABI_PCS_RO_data
:
10039 // Use the smallest value specified.
10040 if (in_attr
[i
].int_value() < out_attr
[i
].int_value())
10041 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
10044 case elfcpp::Tag_ABI_align8_needed
:
10045 if ((in_attr
[i
].int_value() > 0 || out_attr
[i
].int_value() > 0)
10046 && (in_attr
[elfcpp::Tag_ABI_align8_preserved
].int_value() == 0
10047 || (out_attr
[elfcpp::Tag_ABI_align8_preserved
].int_value()
10050 // This error message should be enabled once all non-conformant
10051 // binaries in the toolchain have had the attributes set
10053 // gold_error(_("output 8-byte data alignment conflicts with %s"),
10057 case elfcpp::Tag_ABI_FP_denormal
:
10058 case elfcpp::Tag_ABI_PCS_GOT_use
:
10060 // These tags have 0 = don't care, 1 = strong requirement,
10061 // 2 = weak requirement.
10062 static const int order_021
[3] = {0, 2, 1};
10064 // Use the "greatest" from the sequence 0, 2, 1, or the largest
10065 // value if greater than 2 (for future-proofing).
10066 if ((in_attr
[i
].int_value() > 2
10067 && in_attr
[i
].int_value() > out_attr
[i
].int_value())
10068 || (in_attr
[i
].int_value() <= 2
10069 && out_attr
[i
].int_value() <= 2
10070 && (order_021
[in_attr
[i
].int_value()]
10071 > order_021
[out_attr
[i
].int_value()])))
10072 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
10076 case elfcpp::Tag_CPU_arch_profile
:
10077 if (out_attr
[i
].int_value() != in_attr
[i
].int_value())
10079 // 0 will merge with anything.
10080 // 'A' and 'S' merge to 'A'.
10081 // 'R' and 'S' merge to 'R'.
10082 // 'M' and 'A|R|S' is an error.
10083 if (out_attr
[i
].int_value() == 0
10084 || (out_attr
[i
].int_value() == 'S'
10085 && (in_attr
[i
].int_value() == 'A'
10086 || in_attr
[i
].int_value() == 'R')))
10087 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
10088 else if (in_attr
[i
].int_value() == 0
10089 || (in_attr
[i
].int_value() == 'S'
10090 && (out_attr
[i
].int_value() == 'A'
10091 || out_attr
[i
].int_value() == 'R')))
10093 else if (parameters
->options().warn_mismatch())
10096 (_("conflicting architecture profiles %c/%c"),
10097 in_attr
[i
].int_value() ? in_attr
[i
].int_value() : '0',
10098 out_attr
[i
].int_value() ? out_attr
[i
].int_value() : '0');
10102 case elfcpp::Tag_VFP_arch
:
10104 static const struct
10108 } vfp_versions
[7] =
10119 // Values greater than 6 aren't defined, so just pick the
10121 if (in_attr
[i
].int_value() > 6
10122 && in_attr
[i
].int_value() > out_attr
[i
].int_value())
10124 *out_attr
= *in_attr
;
10127 // The output uses the superset of input features
10128 // (ISA version) and registers.
10129 int ver
= std::max(vfp_versions
[in_attr
[i
].int_value()].ver
,
10130 vfp_versions
[out_attr
[i
].int_value()].ver
);
10131 int regs
= std::max(vfp_versions
[in_attr
[i
].int_value()].regs
,
10132 vfp_versions
[out_attr
[i
].int_value()].regs
);
10133 // This assumes all possible supersets are also a valid
10136 for (newval
= 6; newval
> 0; newval
--)
10138 if (regs
== vfp_versions
[newval
].regs
10139 && ver
== vfp_versions
[newval
].ver
)
10142 out_attr
[i
].set_int_value(newval
);
10145 case elfcpp::Tag_PCS_config
:
10146 if (out_attr
[i
].int_value() == 0)
10147 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
10148 else if (in_attr
[i
].int_value() != 0
10149 && out_attr
[i
].int_value() != 0
10150 && parameters
->options().warn_mismatch())
10152 // It's sometimes ok to mix different configs, so this is only
10154 gold_warning(_("%s: conflicting platform configuration"), name
);
10157 case elfcpp::Tag_ABI_PCS_R9_use
:
10158 if (in_attr
[i
].int_value() != out_attr
[i
].int_value()
10159 && out_attr
[i
].int_value() != elfcpp::AEABI_R9_unused
10160 && in_attr
[i
].int_value() != elfcpp::AEABI_R9_unused
10161 && parameters
->options().warn_mismatch())
10163 gold_error(_("%s: conflicting use of R9"), name
);
10165 if (out_attr
[i
].int_value() == elfcpp::AEABI_R9_unused
)
10166 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
10168 case elfcpp::Tag_ABI_PCS_RW_data
:
10169 if (in_attr
[i
].int_value() == elfcpp::AEABI_PCS_RW_data_SBrel
10170 && (in_attr
[elfcpp::Tag_ABI_PCS_R9_use
].int_value()
10171 != elfcpp::AEABI_R9_SB
)
10172 && (out_attr
[elfcpp::Tag_ABI_PCS_R9_use
].int_value()
10173 != elfcpp::AEABI_R9_unused
)
10174 && parameters
->options().warn_mismatch())
10176 gold_error(_("%s: SB relative addressing conflicts with use "
10180 // Use the smallest value specified.
10181 if (in_attr
[i
].int_value() < out_attr
[i
].int_value())
10182 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
10184 case elfcpp::Tag_ABI_PCS_wchar_t
:
10185 // FIXME: Make it possible to turn off this warning.
10186 if (out_attr
[i
].int_value()
10187 && in_attr
[i
].int_value()
10188 && out_attr
[i
].int_value() != in_attr
[i
].int_value()
10189 && parameters
->options().warn_mismatch())
10191 gold_warning(_("%s uses %u-byte wchar_t yet the output is to "
10192 "use %u-byte wchar_t; use of wchar_t values "
10193 "across objects may fail"),
10194 name
, in_attr
[i
].int_value(),
10195 out_attr
[i
].int_value());
10197 else if (in_attr
[i
].int_value() && !out_attr
[i
].int_value())
10198 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
10200 case elfcpp::Tag_ABI_enum_size
:
10201 if (in_attr
[i
].int_value() != elfcpp::AEABI_enum_unused
)
10203 if (out_attr
[i
].int_value() == elfcpp::AEABI_enum_unused
10204 || out_attr
[i
].int_value() == elfcpp::AEABI_enum_forced_wide
)
10206 // The existing object is compatible with anything.
10207 // Use whatever requirements the new object has.
10208 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
10210 // FIXME: Make it possible to turn off this warning.
10211 else if (in_attr
[i
].int_value() != elfcpp::AEABI_enum_forced_wide
10212 && out_attr
[i
].int_value() != in_attr
[i
].int_value()
10213 && parameters
->options().warn_mismatch())
10215 unsigned int in_value
= in_attr
[i
].int_value();
10216 unsigned int out_value
= out_attr
[i
].int_value();
10217 gold_warning(_("%s uses %s enums yet the output is to use "
10218 "%s enums; use of enum values across objects "
10221 this->aeabi_enum_name(in_value
).c_str(),
10222 this->aeabi_enum_name(out_value
).c_str());
10226 case elfcpp::Tag_ABI_VFP_args
:
10229 case elfcpp::Tag_ABI_WMMX_args
:
10230 if (in_attr
[i
].int_value() != out_attr
[i
].int_value()
10231 && parameters
->options().warn_mismatch())
10233 gold_error(_("%s uses iWMMXt register arguments, output does "
10238 case Object_attribute::Tag_compatibility
:
10239 // Merged in target-independent code.
10241 case elfcpp::Tag_ABI_HardFP_use
:
10242 // 1 (SP) and 2 (DP) conflict, so combine to 3 (SP & DP).
10243 if ((in_attr
[i
].int_value() == 1 && out_attr
[i
].int_value() == 2)
10244 || (in_attr
[i
].int_value() == 2 && out_attr
[i
].int_value() == 1))
10245 out_attr
[i
].set_int_value(3);
10246 else if (in_attr
[i
].int_value() > out_attr
[i
].int_value())
10247 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
10249 case elfcpp::Tag_ABI_FP_16bit_format
:
10250 if (in_attr
[i
].int_value() != 0 && out_attr
[i
].int_value() != 0)
10252 if (in_attr
[i
].int_value() != out_attr
[i
].int_value()
10253 && parameters
->options().warn_mismatch())
10254 gold_error(_("fp16 format mismatch between %s and output"),
10257 if (in_attr
[i
].int_value() != 0)
10258 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
10261 case elfcpp::Tag_DIV_use
:
10262 // This tag is set to zero if we can use UDIV and SDIV in Thumb
10263 // mode on a v7-M or v7-R CPU; to one if we can not use UDIV or
10264 // SDIV at all; and to two if we can use UDIV or SDIV on a v7-A
10265 // CPU. We will merge as follows: If the input attribute's value
10266 // is one then the output attribute's value remains unchanged. If
10267 // the input attribute's value is zero or two then if the output
10268 // attribute's value is one the output value is set to the input
10269 // value, otherwise the output value must be the same as the
10271 if (in_attr
[i
].int_value() != 1 && out_attr
[i
].int_value() != 1)
10273 if (in_attr
[i
].int_value() != out_attr
[i
].int_value())
10275 gold_error(_("DIV usage mismatch between %s and output"),
10280 if (in_attr
[i
].int_value() != 1)
10281 out_attr
[i
].set_int_value(in_attr
[i
].int_value());
10285 case elfcpp::Tag_MPextension_use_legacy
:
10286 // We don't output objects with Tag_MPextension_use_legacy - we
10287 // move the value to Tag_MPextension_use.
10288 if (in_attr
[i
].int_value() != 0
10289 && in_attr
[elfcpp::Tag_MPextension_use
].int_value() != 0)
10291 if (in_attr
[elfcpp::Tag_MPextension_use
].int_value()
10292 != in_attr
[i
].int_value())
10294 gold_error(_("%s has has both the current and legacy "
10295 "Tag_MPextension_use attributes"),
10300 if (in_attr
[i
].int_value()
10301 > out_attr
[elfcpp::Tag_MPextension_use
].int_value())
10302 out_attr
[elfcpp::Tag_MPextension_use
] = in_attr
[i
];
10306 case elfcpp::Tag_nodefaults
:
10307 // This tag is set if it exists, but the value is unused (and is
10308 // typically zero). We don't actually need to do anything here -
10309 // the merge happens automatically when the type flags are merged
10312 case elfcpp::Tag_also_compatible_with
:
10313 // Already done in Tag_CPU_arch.
10315 case elfcpp::Tag_conformance
:
10316 // Keep the attribute if it matches. Throw it away otherwise.
10317 // No attribute means no claim to conform.
10318 if (in_attr
[i
].string_value() != out_attr
[i
].string_value())
10319 out_attr
[i
].set_string_value("");
10324 const char* err_object
= NULL
;
10326 // The "known_obj_attributes" table does contain some undefined
10327 // attributes. Ensure that there are unused.
10328 if (out_attr
[i
].int_value() != 0
10329 || out_attr
[i
].string_value() != "")
10330 err_object
= "output";
10331 else if (in_attr
[i
].int_value() != 0
10332 || in_attr
[i
].string_value() != "")
10335 if (err_object
!= NULL
10336 && parameters
->options().warn_mismatch())
10338 // Attribute numbers >=64 (mod 128) can be safely ignored.
10339 if ((i
& 127) < 64)
10340 gold_error(_("%s: unknown mandatory EABI object attribute "
10344 gold_warning(_("%s: unknown EABI object attribute %d"),
10348 // Only pass on attributes that match in both inputs.
10349 if (!in_attr
[i
].matches(out_attr
[i
]))
10351 out_attr
[i
].set_int_value(0);
10352 out_attr
[i
].set_string_value("");
10357 // If out_attr was copied from in_attr then it won't have a type yet.
10358 if (in_attr
[i
].type() && !out_attr
[i
].type())
10359 out_attr
[i
].set_type(in_attr
[i
].type());
10362 // Merge Tag_compatibility attributes and any common GNU ones.
10363 this->attributes_section_data_
->merge(name
, pasd
);
10365 // Check for any attributes not known on ARM.
10366 typedef Vendor_object_attributes::Other_attributes Other_attributes
;
10367 const Other_attributes
* in_other_attributes
= pasd
->other_attributes(vendor
);
10368 Other_attributes::const_iterator in_iter
= in_other_attributes
->begin();
10369 Other_attributes
* out_other_attributes
=
10370 this->attributes_section_data_
->other_attributes(vendor
);
10371 Other_attributes::iterator out_iter
= out_other_attributes
->begin();
10373 while (in_iter
!= in_other_attributes
->end()
10374 || out_iter
!= out_other_attributes
->end())
10376 const char* err_object
= NULL
;
10379 // The tags for each list are in numerical order.
10380 // If the tags are equal, then merge.
10381 if (out_iter
!= out_other_attributes
->end()
10382 && (in_iter
== in_other_attributes
->end()
10383 || in_iter
->first
> out_iter
->first
))
10385 // This attribute only exists in output. We can't merge, and we
10386 // don't know what the tag means, so delete it.
10387 err_object
= "output";
10388 err_tag
= out_iter
->first
;
10389 int saved_tag
= out_iter
->first
;
10390 delete out_iter
->second
;
10391 out_other_attributes
->erase(out_iter
);
10392 out_iter
= out_other_attributes
->upper_bound(saved_tag
);
10394 else if (in_iter
!= in_other_attributes
->end()
10395 && (out_iter
!= out_other_attributes
->end()
10396 || in_iter
->first
< out_iter
->first
))
10398 // This attribute only exists in input. We can't merge, and we
10399 // don't know what the tag means, so ignore it.
10401 err_tag
= in_iter
->first
;
10404 else // The tags are equal.
10406 // As present, all attributes in the list are unknown, and
10407 // therefore can't be merged meaningfully.
10408 err_object
= "output";
10409 err_tag
= out_iter
->first
;
10411 // Only pass on attributes that match in both inputs.
10412 if (!in_iter
->second
->matches(*(out_iter
->second
)))
10414 // No match. Delete the attribute.
10415 int saved_tag
= out_iter
->first
;
10416 delete out_iter
->second
;
10417 out_other_attributes
->erase(out_iter
);
10418 out_iter
= out_other_attributes
->upper_bound(saved_tag
);
10422 // Matched. Keep the attribute and move to the next.
10428 if (err_object
&& parameters
->options().warn_mismatch())
10430 // Attribute numbers >=64 (mod 128) can be safely ignored. */
10431 if ((err_tag
& 127) < 64)
10433 gold_error(_("%s: unknown mandatory EABI object attribute %d"),
10434 err_object
, err_tag
);
10438 gold_warning(_("%s: unknown EABI object attribute %d"),
10439 err_object
, err_tag
);
10445 // Stub-generation methods for Target_arm.
10447 // Make a new Arm_input_section object.
10449 template<bool big_endian
>
10450 Arm_input_section
<big_endian
>*
10451 Target_arm
<big_endian
>::new_arm_input_section(
10453 unsigned int shndx
)
10455 Section_id
sid(relobj
, shndx
);
10457 Arm_input_section
<big_endian
>* arm_input_section
=
10458 new Arm_input_section
<big_endian
>(relobj
, shndx
);
10459 arm_input_section
->init();
10461 // Register new Arm_input_section in map for look-up.
10462 std::pair
<typename
Arm_input_section_map::iterator
, bool> ins
=
10463 this->arm_input_section_map_
.insert(std::make_pair(sid
, arm_input_section
));
10465 // Make sure that it we have not created another Arm_input_section
10466 // for this input section already.
10467 gold_assert(ins
.second
);
10469 return arm_input_section
;
10472 // Find the Arm_input_section object corresponding to the SHNDX-th input
10473 // section of RELOBJ.
10475 template<bool big_endian
>
10476 Arm_input_section
<big_endian
>*
10477 Target_arm
<big_endian
>::find_arm_input_section(
10479 unsigned int shndx
) const
10481 Section_id
sid(relobj
, shndx
);
10482 typename
Arm_input_section_map::const_iterator p
=
10483 this->arm_input_section_map_
.find(sid
);
10484 return (p
!= this->arm_input_section_map_
.end()) ? p
->second
: NULL
;
10487 // Make a new stub table.
10489 template<bool big_endian
>
10490 Stub_table
<big_endian
>*
10491 Target_arm
<big_endian
>::new_stub_table(Arm_input_section
<big_endian
>* owner
)
10493 Stub_table
<big_endian
>* stub_table
=
10494 new Stub_table
<big_endian
>(owner
);
10495 this->stub_tables_
.push_back(stub_table
);
10497 stub_table
->set_address(owner
->address() + owner
->data_size());
10498 stub_table
->set_file_offset(owner
->offset() + owner
->data_size());
10499 stub_table
->finalize_data_size();
10504 // Scan a relocation for stub generation.
10506 template<bool big_endian
>
10508 Target_arm
<big_endian
>::scan_reloc_for_stub(
10509 const Relocate_info
<32, big_endian
>* relinfo
,
10510 unsigned int r_type
,
10511 const Sized_symbol
<32>* gsym
,
10512 unsigned int r_sym
,
10513 const Symbol_value
<32>* psymval
,
10514 elfcpp::Elf_types
<32>::Elf_Swxword addend
,
10515 Arm_address address
)
10517 typedef typename Target_arm
<big_endian
>::Relocate Relocate
;
10519 const Arm_relobj
<big_endian
>* arm_relobj
=
10520 Arm_relobj
<big_endian
>::as_arm_relobj(relinfo
->object
);
10522 bool target_is_thumb
;
10523 Symbol_value
<32> symval
;
10526 // This is a global symbol. Determine if we use PLT and if the
10527 // final target is THUMB.
10528 if (gsym
->use_plt_offset(Relocate::reloc_is_non_pic(r_type
)))
10530 // This uses a PLT, change the symbol value.
10531 symval
.set_output_value(this->plt_section()->address()
10532 + gsym
->plt_offset());
10534 target_is_thumb
= false;
10536 else if (gsym
->is_undefined())
10537 // There is no need to generate a stub symbol is undefined.
10542 ((gsym
->type() == elfcpp::STT_ARM_TFUNC
)
10543 || (gsym
->type() == elfcpp::STT_FUNC
10544 && !gsym
->is_undefined()
10545 && ((psymval
->value(arm_relobj
, 0) & 1) != 0)));
10550 // This is a local symbol. Determine if the final target is THUMB.
10551 target_is_thumb
= arm_relobj
->local_symbol_is_thumb_function(r_sym
);
10554 // Strip LSB if this points to a THUMB target.
10555 const Arm_reloc_property
* reloc_property
=
10556 arm_reloc_property_table
->get_implemented_static_reloc_property(r_type
);
10557 gold_assert(reloc_property
!= NULL
);
10558 if (target_is_thumb
10559 && reloc_property
->uses_thumb_bit()
10560 && ((psymval
->value(arm_relobj
, 0) & 1) != 0))
10562 Arm_address stripped_value
=
10563 psymval
->value(arm_relobj
, 0) & ~static_cast<Arm_address
>(1);
10564 symval
.set_output_value(stripped_value
);
10568 // Get the symbol value.
10569 Symbol_value
<32>::Value value
= psymval
->value(arm_relobj
, 0);
10571 // Owing to pipelining, the PC relative branches below actually skip
10572 // two instructions when the branch offset is 0.
10573 Arm_address destination
;
10576 case elfcpp::R_ARM_CALL
:
10577 case elfcpp::R_ARM_JUMP24
:
10578 case elfcpp::R_ARM_PLT32
:
10580 destination
= value
+ addend
+ 8;
10582 case elfcpp::R_ARM_THM_CALL
:
10583 case elfcpp::R_ARM_THM_XPC22
:
10584 case elfcpp::R_ARM_THM_JUMP24
:
10585 case elfcpp::R_ARM_THM_JUMP19
:
10587 destination
= value
+ addend
+ 4;
10590 gold_unreachable();
10593 Reloc_stub
* stub
= NULL
;
10594 Stub_type stub_type
=
10595 Reloc_stub::stub_type_for_reloc(r_type
, address
, destination
,
10597 if (stub_type
!= arm_stub_none
)
10599 // Try looking up an existing stub from a stub table.
10600 Stub_table
<big_endian
>* stub_table
=
10601 arm_relobj
->stub_table(relinfo
->data_shndx
);
10602 gold_assert(stub_table
!= NULL
);
10604 // Locate stub by destination.
10605 Reloc_stub::Key
stub_key(stub_type
, gsym
, arm_relobj
, r_sym
, addend
);
10607 // Create a stub if there is not one already
10608 stub
= stub_table
->find_reloc_stub(stub_key
);
10611 // create a new stub and add it to stub table.
10612 stub
= this->stub_factory().make_reloc_stub(stub_type
);
10613 stub_table
->add_reloc_stub(stub
, stub_key
);
10616 // Record the destination address.
10617 stub
->set_destination_address(destination
10618 | (target_is_thumb
? 1 : 0));
10621 // For Cortex-A8, we need to record a relocation at 4K page boundary.
10622 if (this->fix_cortex_a8_
10623 && (r_type
== elfcpp::R_ARM_THM_JUMP24
10624 || r_type
== elfcpp::R_ARM_THM_JUMP19
10625 || r_type
== elfcpp::R_ARM_THM_CALL
10626 || r_type
== elfcpp::R_ARM_THM_XPC22
)
10627 && (address
& 0xfffU
) == 0xffeU
)
10629 // Found a candidate. Note we haven't checked the destination is
10630 // within 4K here: if we do so (and don't create a record) we can't
10631 // tell that a branch should have been relocated when scanning later.
10632 this->cortex_a8_relocs_info_
[address
] =
10633 new Cortex_a8_reloc(stub
, r_type
,
10634 destination
| (target_is_thumb
? 1 : 0));
10638 // This function scans a relocation sections for stub generation.
10639 // The template parameter Relocate must be a class type which provides
10640 // a single function, relocate(), which implements the machine
10641 // specific part of a relocation.
10643 // BIG_ENDIAN is the endianness of the data. SH_TYPE is the section type:
10644 // SHT_REL or SHT_RELA.
10646 // PRELOCS points to the relocation data. RELOC_COUNT is the number
10647 // of relocs. OUTPUT_SECTION is the output section.
10648 // NEEDS_SPECIAL_OFFSET_HANDLING is true if input offsets need to be
10649 // mapped to output offsets.
10651 // VIEW is the section data, VIEW_ADDRESS is its memory address, and
10652 // VIEW_SIZE is the size. These refer to the input section, unless
10653 // NEEDS_SPECIAL_OFFSET_HANDLING is true, in which case they refer to
10654 // the output section.
10656 template<bool big_endian
>
10657 template<int sh_type
>
10659 Target_arm
<big_endian
>::scan_reloc_section_for_stubs(
10660 const Relocate_info
<32, big_endian
>* relinfo
,
10661 const unsigned char* prelocs
,
10662 size_t reloc_count
,
10663 Output_section
* output_section
,
10664 bool needs_special_offset_handling
,
10665 const unsigned char* view
,
10666 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
10669 typedef typename Reloc_types
<sh_type
, 32, big_endian
>::Reloc Reltype
;
10670 const int reloc_size
=
10671 Reloc_types
<sh_type
, 32, big_endian
>::reloc_size
;
10673 Arm_relobj
<big_endian
>* arm_object
=
10674 Arm_relobj
<big_endian
>::as_arm_relobj(relinfo
->object
);
10675 unsigned int local_count
= arm_object
->local_symbol_count();
10677 Comdat_behavior comdat_behavior
= CB_UNDETERMINED
;
10679 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
10681 Reltype
reloc(prelocs
);
10683 typename
elfcpp::Elf_types
<32>::Elf_WXword r_info
= reloc
.get_r_info();
10684 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(r_info
);
10685 unsigned int r_type
= elfcpp::elf_r_type
<32>(r_info
);
10687 r_type
= this->get_real_reloc_type(r_type
);
10689 // Only a few relocation types need stubs.
10690 if ((r_type
!= elfcpp::R_ARM_CALL
)
10691 && (r_type
!= elfcpp::R_ARM_JUMP24
)
10692 && (r_type
!= elfcpp::R_ARM_PLT32
)
10693 && (r_type
!= elfcpp::R_ARM_THM_CALL
)
10694 && (r_type
!= elfcpp::R_ARM_THM_XPC22
)
10695 && (r_type
!= elfcpp::R_ARM_THM_JUMP24
)
10696 && (r_type
!= elfcpp::R_ARM_THM_JUMP19
)
10697 && (r_type
!= elfcpp::R_ARM_V4BX
))
10700 section_offset_type offset
=
10701 convert_to_section_size_type(reloc
.get_r_offset());
10703 if (needs_special_offset_handling
)
10705 offset
= output_section
->output_offset(relinfo
->object
,
10706 relinfo
->data_shndx
,
10712 // Create a v4bx stub if --fix-v4bx-interworking is used.
10713 if (r_type
== elfcpp::R_ARM_V4BX
)
10715 if (this->fix_v4bx() == General_options::FIX_V4BX_INTERWORKING
)
10717 // Get the BX instruction.
10718 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10719 const Valtype
* wv
=
10720 reinterpret_cast<const Valtype
*>(view
+ offset
);
10721 elfcpp::Elf_types
<32>::Elf_Swxword insn
=
10722 elfcpp::Swap
<32, big_endian
>::readval(wv
);
10723 const uint32_t reg
= (insn
& 0xf);
10727 // Try looking up an existing stub from a stub table.
10728 Stub_table
<big_endian
>* stub_table
=
10729 arm_object
->stub_table(relinfo
->data_shndx
);
10730 gold_assert(stub_table
!= NULL
);
10732 if (stub_table
->find_arm_v4bx_stub(reg
) == NULL
)
10734 // create a new stub and add it to stub table.
10735 Arm_v4bx_stub
* stub
=
10736 this->stub_factory().make_arm_v4bx_stub(reg
);
10737 gold_assert(stub
!= NULL
);
10738 stub_table
->add_arm_v4bx_stub(stub
);
10746 Stub_addend_reader
<sh_type
, big_endian
> stub_addend_reader
;
10747 elfcpp::Elf_types
<32>::Elf_Swxword addend
=
10748 stub_addend_reader(r_type
, view
+ offset
, reloc
);
10750 const Sized_symbol
<32>* sym
;
10752 Symbol_value
<32> symval
;
10753 const Symbol_value
<32> *psymval
;
10754 if (r_sym
< local_count
)
10757 psymval
= arm_object
->local_symbol(r_sym
);
10759 // If the local symbol belongs to a section we are discarding,
10760 // and that section is a debug section, try to find the
10761 // corresponding kept section and map this symbol to its
10762 // counterpart in the kept section. The symbol must not
10763 // correspond to a section we are folding.
10765 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
10767 && shndx
!= elfcpp::SHN_UNDEF
10768 && !arm_object
->is_section_included(shndx
)
10769 && !(relinfo
->symtab
->is_section_folded(arm_object
, shndx
)))
10771 if (comdat_behavior
== CB_UNDETERMINED
)
10774 arm_object
->section_name(relinfo
->data_shndx
);
10775 comdat_behavior
= get_comdat_behavior(name
.c_str());
10777 if (comdat_behavior
== CB_PRETEND
)
10780 typename
elfcpp::Elf_types
<32>::Elf_Addr value
=
10781 arm_object
->map_to_kept_section(shndx
, &found
);
10783 symval
.set_output_value(value
+ psymval
->input_value());
10785 symval
.set_output_value(0);
10789 symval
.set_output_value(0);
10791 symval
.set_no_output_symtab_entry();
10797 const Symbol
* gsym
= arm_object
->global_symbol(r_sym
);
10798 gold_assert(gsym
!= NULL
);
10799 if (gsym
->is_forwarder())
10800 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
10802 sym
= static_cast<const Sized_symbol
<32>*>(gsym
);
10803 if (sym
->has_symtab_index())
10804 symval
.set_output_symtab_index(sym
->symtab_index());
10806 symval
.set_no_output_symtab_entry();
10808 // We need to compute the would-be final value of this global
10810 const Symbol_table
* symtab
= relinfo
->symtab
;
10811 const Sized_symbol
<32>* sized_symbol
=
10812 symtab
->get_sized_symbol
<32>(gsym
);
10813 Symbol_table::Compute_final_value_status status
;
10814 Arm_address value
=
10815 symtab
->compute_final_value
<32>(sized_symbol
, &status
);
10817 // Skip this if the symbol has not output section.
10818 if (status
== Symbol_table::CFVS_NO_OUTPUT_SECTION
)
10821 symval
.set_output_value(value
);
10825 // If symbol is a section symbol, we don't know the actual type of
10826 // destination. Give up.
10827 if (psymval
->is_section_symbol())
10830 this->scan_reloc_for_stub(relinfo
, r_type
, sym
, r_sym
, psymval
,
10831 addend
, view_address
+ offset
);
10835 // Scan an input section for stub generation.
10837 template<bool big_endian
>
10839 Target_arm
<big_endian
>::scan_section_for_stubs(
10840 const Relocate_info
<32, big_endian
>* relinfo
,
10841 unsigned int sh_type
,
10842 const unsigned char* prelocs
,
10843 size_t reloc_count
,
10844 Output_section
* output_section
,
10845 bool needs_special_offset_handling
,
10846 const unsigned char* view
,
10847 Arm_address view_address
,
10848 section_size_type view_size
)
10850 if (sh_type
== elfcpp::SHT_REL
)
10851 this->scan_reloc_section_for_stubs
<elfcpp::SHT_REL
>(
10856 needs_special_offset_handling
,
10860 else if (sh_type
== elfcpp::SHT_RELA
)
10861 // We do not support RELA type relocations yet. This is provided for
10863 this->scan_reloc_section_for_stubs
<elfcpp::SHT_RELA
>(
10868 needs_special_offset_handling
,
10873 gold_unreachable();
10876 // Group input sections for stub generation.
10878 // We goup input sections in an output sections so that the total size,
10879 // including any padding space due to alignment is smaller than GROUP_SIZE
10880 // unless the only input section in group is bigger than GROUP_SIZE already.
10881 // Then an ARM stub table is created to follow the last input section
10882 // in group. For each group an ARM stub table is created an is placed
10883 // after the last group. If STUB_ALWATS_AFTER_BRANCH is false, we further
10884 // extend the group after the stub table.
10886 template<bool big_endian
>
10888 Target_arm
<big_endian
>::group_sections(
10890 section_size_type group_size
,
10891 bool stubs_always_after_branch
)
10893 // Group input sections and insert stub table
10894 Layout::Section_list section_list
;
10895 layout
->get_allocated_sections(§ion_list
);
10896 for (Layout::Section_list::const_iterator p
= section_list
.begin();
10897 p
!= section_list
.end();
10900 Arm_output_section
<big_endian
>* output_section
=
10901 Arm_output_section
<big_endian
>::as_arm_output_section(*p
);
10902 output_section
->group_sections(group_size
, stubs_always_after_branch
,
10907 // Relaxation hook. This is where we do stub generation.
10909 template<bool big_endian
>
10911 Target_arm
<big_endian
>::do_relax(
10913 const Input_objects
* input_objects
,
10914 Symbol_table
* symtab
,
10917 // No need to generate stubs if this is a relocatable link.
10918 gold_assert(!parameters
->options().relocatable());
10920 // If this is the first pass, we need to group input sections into
10922 bool done_exidx_fixup
= false;
10923 typedef typename
Stub_table_list::iterator Stub_table_iterator
;
10926 // Determine the stub group size. The group size is the absolute
10927 // value of the parameter --stub-group-size. If --stub-group-size
10928 // is passed a negative value, we restict stubs to be always after
10929 // the stubbed branches.
10930 int32_t stub_group_size_param
=
10931 parameters
->options().stub_group_size();
10932 bool stubs_always_after_branch
= stub_group_size_param
< 0;
10933 section_size_type stub_group_size
= abs(stub_group_size_param
);
10935 if (stub_group_size
== 1)
10938 // Thumb branch range is +-4MB has to be used as the default
10939 // maximum size (a given section can contain both ARM and Thumb
10940 // code, so the worst case has to be taken into account). If we are
10941 // fixing cortex-a8 errata, the branch range has to be even smaller,
10942 // since wide conditional branch has a range of +-1MB only.
10944 // This value is 48K less than that, which allows for 4096
10945 // 12-byte stubs. If we exceed that, then we will fail to link.
10946 // The user will have to relink with an explicit group size
10948 stub_group_size
= 4145152;
10951 // The Cortex-A8 erratum fix depends on stubs not being in the same 4K
10952 // page as the first half of a 32-bit branch straddling two 4K pages.
10953 // This is a crude way of enforcing that. In addition, long conditional
10954 // branches of THUMB-2 have a range of +-1M. If we are fixing cortex-A8
10955 // erratum, limit the group size to (1M - 12k) to avoid unreachable
10956 // cortex-A8 stubs from long conditional branches.
10957 if (this->fix_cortex_a8_
)
10959 stubs_always_after_branch
= true;
10960 const section_size_type cortex_a8_group_size
= 1024 * (1024 - 12);
10961 stub_group_size
= std::max(stub_group_size
, cortex_a8_group_size
);
10964 group_sections(layout
, stub_group_size
, stubs_always_after_branch
);
10966 // Also fix .ARM.exidx section coverage.
10967 Output_section
* os
= layout
->find_output_section(".ARM.exidx");
10968 if (os
!= NULL
&& os
->type() == elfcpp::SHT_ARM_EXIDX
)
10970 Arm_output_section
<big_endian
>* exidx_output_section
=
10971 Arm_output_section
<big_endian
>::as_arm_output_section(os
);
10972 this->fix_exidx_coverage(layout
, exidx_output_section
, symtab
);
10973 done_exidx_fixup
= true;
10978 // If this is not the first pass, addresses and file offsets have
10979 // been reset at this point, set them here.
10980 for (Stub_table_iterator sp
= this->stub_tables_
.begin();
10981 sp
!= this->stub_tables_
.end();
10984 Arm_input_section
<big_endian
>* owner
= (*sp
)->owner();
10985 off_t off
= align_address(owner
->original_size(),
10986 (*sp
)->addralign());
10987 (*sp
)->set_address_and_file_offset(owner
->address() + off
,
10988 owner
->offset() + off
);
10992 // The Cortex-A8 stubs are sensitive to layout of code sections. At the
10993 // beginning of each relaxation pass, just blow away all the stubs.
10994 // Alternatively, we could selectively remove only the stubs and reloc
10995 // information for code sections that have moved since the last pass.
10996 // That would require more book-keeping.
10997 if (this->fix_cortex_a8_
)
10999 // Clear all Cortex-A8 reloc information.
11000 for (typename
Cortex_a8_relocs_info::const_iterator p
=
11001 this->cortex_a8_relocs_info_
.begin();
11002 p
!= this->cortex_a8_relocs_info_
.end();
11005 this->cortex_a8_relocs_info_
.clear();
11007 // Remove all Cortex-A8 stubs.
11008 for (Stub_table_iterator sp
= this->stub_tables_
.begin();
11009 sp
!= this->stub_tables_
.end();
11011 (*sp
)->remove_all_cortex_a8_stubs();
11014 // Scan relocs for relocation stubs
11015 for (Input_objects::Relobj_iterator op
= input_objects
->relobj_begin();
11016 op
!= input_objects
->relobj_end();
11019 Arm_relobj
<big_endian
>* arm_relobj
=
11020 Arm_relobj
<big_endian
>::as_arm_relobj(*op
);
11021 arm_relobj
->scan_sections_for_stubs(this, symtab
, layout
);
11024 // Check all stub tables to see if any of them have their data sizes
11025 // or addresses alignments changed. These are the only things that
11027 bool any_stub_table_changed
= false;
11028 Unordered_set
<const Output_section
*> sections_needing_adjustment
;
11029 for (Stub_table_iterator sp
= this->stub_tables_
.begin();
11030 (sp
!= this->stub_tables_
.end()) && !any_stub_table_changed
;
11033 if ((*sp
)->update_data_size_and_addralign())
11035 // Update data size of stub table owner.
11036 Arm_input_section
<big_endian
>* owner
= (*sp
)->owner();
11037 uint64_t address
= owner
->address();
11038 off_t offset
= owner
->offset();
11039 owner
->reset_address_and_file_offset();
11040 owner
->set_address_and_file_offset(address
, offset
);
11042 sections_needing_adjustment
.insert(owner
->output_section());
11043 any_stub_table_changed
= true;
11047 // Output_section_data::output_section() returns a const pointer but we
11048 // need to update output sections, so we record all output sections needing
11049 // update above and scan the sections here to find out what sections need
11051 for(Layout::Section_list::const_iterator p
= layout
->section_list().begin();
11052 p
!= layout
->section_list().end();
11055 if (sections_needing_adjustment
.find(*p
)
11056 != sections_needing_adjustment
.end())
11057 (*p
)->set_section_offsets_need_adjustment();
11060 // Stop relaxation if no EXIDX fix-up and no stub table change.
11061 bool continue_relaxation
= done_exidx_fixup
|| any_stub_table_changed
;
11063 // Finalize the stubs in the last relaxation pass.
11064 if (!continue_relaxation
)
11066 for (Stub_table_iterator sp
= this->stub_tables_
.begin();
11067 (sp
!= this->stub_tables_
.end()) && !any_stub_table_changed
;
11069 (*sp
)->finalize_stubs();
11071 // Update output local symbol counts of objects if necessary.
11072 for (Input_objects::Relobj_iterator op
= input_objects
->relobj_begin();
11073 op
!= input_objects
->relobj_end();
11076 Arm_relobj
<big_endian
>* arm_relobj
=
11077 Arm_relobj
<big_endian
>::as_arm_relobj(*op
);
11079 // Update output local symbol counts. We need to discard local
11080 // symbols defined in parts of input sections that are discarded by
11082 if (arm_relobj
->output_local_symbol_count_needs_update())
11083 arm_relobj
->update_output_local_symbol_count();
11087 return continue_relaxation
;
11090 // Relocate a stub.
11092 template<bool big_endian
>
11094 Target_arm
<big_endian
>::relocate_stub(
11096 const Relocate_info
<32, big_endian
>* relinfo
,
11097 Output_section
* output_section
,
11098 unsigned char* view
,
11099 Arm_address address
,
11100 section_size_type view_size
)
11103 const Stub_template
* stub_template
= stub
->stub_template();
11104 for (size_t i
= 0; i
< stub_template
->reloc_count(); i
++)
11106 size_t reloc_insn_index
= stub_template
->reloc_insn_index(i
);
11107 const Insn_template
* insn
= &stub_template
->insns()[reloc_insn_index
];
11109 unsigned int r_type
= insn
->r_type();
11110 section_size_type reloc_offset
= stub_template
->reloc_offset(i
);
11111 section_size_type reloc_size
= insn
->size();
11112 gold_assert(reloc_offset
+ reloc_size
<= view_size
);
11114 // This is the address of the stub destination.
11115 Arm_address target
= stub
->reloc_target(i
) + insn
->reloc_addend();
11116 Symbol_value
<32> symval
;
11117 symval
.set_output_value(target
);
11119 // Synthesize a fake reloc just in case. We don't have a symbol so
11121 unsigned char reloc_buffer
[elfcpp::Elf_sizes
<32>::rel_size
];
11122 memset(reloc_buffer
, 0, sizeof(reloc_buffer
));
11123 elfcpp::Rel_write
<32, big_endian
> reloc_write(reloc_buffer
);
11124 reloc_write
.put_r_offset(reloc_offset
);
11125 reloc_write
.put_r_info(elfcpp::elf_r_info
<32>(0, r_type
));
11126 elfcpp::Rel
<32, big_endian
> rel(reloc_buffer
);
11128 relocate
.relocate(relinfo
, this, output_section
,
11129 this->fake_relnum_for_stubs
, rel
, r_type
,
11130 NULL
, &symval
, view
+ reloc_offset
,
11131 address
+ reloc_offset
, reloc_size
);
11135 // Determine whether an object attribute tag takes an integer, a
11138 template<bool big_endian
>
11140 Target_arm
<big_endian
>::do_attribute_arg_type(int tag
) const
11142 if (tag
== Object_attribute::Tag_compatibility
)
11143 return (Object_attribute::ATTR_TYPE_FLAG_INT_VAL
11144 | Object_attribute::ATTR_TYPE_FLAG_STR_VAL
);
11145 else if (tag
== elfcpp::Tag_nodefaults
)
11146 return (Object_attribute::ATTR_TYPE_FLAG_INT_VAL
11147 | Object_attribute::ATTR_TYPE_FLAG_NO_DEFAULT
);
11148 else if (tag
== elfcpp::Tag_CPU_raw_name
|| tag
== elfcpp::Tag_CPU_name
)
11149 return Object_attribute::ATTR_TYPE_FLAG_STR_VAL
;
11151 return Object_attribute::ATTR_TYPE_FLAG_INT_VAL
;
11153 return ((tag
& 1) != 0
11154 ? Object_attribute::ATTR_TYPE_FLAG_STR_VAL
11155 : Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
11158 // Reorder attributes.
11160 // The ABI defines that Tag_conformance should be emitted first, and that
11161 // Tag_nodefaults should be second (if either is defined). This sets those
11162 // two positions, and bumps up the position of all the remaining tags to
11165 template<bool big_endian
>
11167 Target_arm
<big_endian
>::do_attributes_order(int num
) const
11169 // Reorder the known object attributes in output. We want to move
11170 // Tag_conformance to position 4 and Tag_conformance to position 5
11171 // and shift eveything between 4 .. Tag_conformance - 1 to make room.
11173 return elfcpp::Tag_conformance
;
11175 return elfcpp::Tag_nodefaults
;
11176 if ((num
- 2) < elfcpp::Tag_nodefaults
)
11178 if ((num
- 1) < elfcpp::Tag_conformance
)
11183 // Scan a span of THUMB code for Cortex-A8 erratum.
11185 template<bool big_endian
>
11187 Target_arm
<big_endian
>::scan_span_for_cortex_a8_erratum(
11188 Arm_relobj
<big_endian
>* arm_relobj
,
11189 unsigned int shndx
,
11190 section_size_type span_start
,
11191 section_size_type span_end
,
11192 const unsigned char* view
,
11193 Arm_address address
)
11195 // Scan for 32-bit Thumb-2 branches which span two 4K regions, where:
11197 // The opcode is BLX.W, BL.W, B.W, Bcc.W
11198 // The branch target is in the same 4KB region as the
11199 // first half of the branch.
11200 // The instruction before the branch is a 32-bit
11201 // length non-branch instruction.
11202 section_size_type i
= span_start
;
11203 bool last_was_32bit
= false;
11204 bool last_was_branch
= false;
11205 while (i
< span_end
)
11207 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
11208 const Valtype
* wv
= reinterpret_cast<const Valtype
*>(view
+ i
);
11209 uint32_t insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
11210 bool is_blx
= false, is_b
= false;
11211 bool is_bl
= false, is_bcc
= false;
11213 bool insn_32bit
= (insn
& 0xe000) == 0xe000 && (insn
& 0x1800) != 0x0000;
11216 // Load the rest of the insn (in manual-friendly order).
11217 insn
= (insn
<< 16) | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
11219 // Encoding T4: B<c>.W.
11220 is_b
= (insn
& 0xf800d000U
) == 0xf0009000U
;
11221 // Encoding T1: BL<c>.W.
11222 is_bl
= (insn
& 0xf800d000U
) == 0xf000d000U
;
11223 // Encoding T2: BLX<c>.W.
11224 is_blx
= (insn
& 0xf800d000U
) == 0xf000c000U
;
11225 // Encoding T3: B<c>.W (not permitted in IT block).
11226 is_bcc
= ((insn
& 0xf800d000U
) == 0xf0008000U
11227 && (insn
& 0x07f00000U
) != 0x03800000U
);
11230 bool is_32bit_branch
= is_b
|| is_bl
|| is_blx
|| is_bcc
;
11232 // If this instruction is a 32-bit THUMB branch that crosses a 4K
11233 // page boundary and it follows 32-bit non-branch instruction,
11234 // we need to work around.
11235 if (is_32bit_branch
11236 && ((address
+ i
) & 0xfffU
) == 0xffeU
11238 && !last_was_branch
)
11240 // Check to see if there is a relocation stub for this branch.
11241 bool force_target_arm
= false;
11242 bool force_target_thumb
= false;
11243 const Cortex_a8_reloc
* cortex_a8_reloc
= NULL
;
11244 Cortex_a8_relocs_info::const_iterator p
=
11245 this->cortex_a8_relocs_info_
.find(address
+ i
);
11247 if (p
!= this->cortex_a8_relocs_info_
.end())
11249 cortex_a8_reloc
= p
->second
;
11250 bool target_is_thumb
= (cortex_a8_reloc
->destination() & 1) != 0;
11252 if (cortex_a8_reloc
->r_type() == elfcpp::R_ARM_THM_CALL
11253 && !target_is_thumb
)
11254 force_target_arm
= true;
11255 else if (cortex_a8_reloc
->r_type() == elfcpp::R_ARM_THM_CALL
11256 && target_is_thumb
)
11257 force_target_thumb
= true;
11261 Stub_type stub_type
= arm_stub_none
;
11263 // Check if we have an offending branch instruction.
11264 uint16_t upper_insn
= (insn
>> 16) & 0xffffU
;
11265 uint16_t lower_insn
= insn
& 0xffffU
;
11266 typedef struct Arm_relocate_functions
<big_endian
> RelocFuncs
;
11268 if (cortex_a8_reloc
!= NULL
11269 && cortex_a8_reloc
->reloc_stub() != NULL
)
11270 // We've already made a stub for this instruction, e.g.
11271 // it's a long branch or a Thumb->ARM stub. Assume that
11272 // stub will suffice to work around the A8 erratum (see
11273 // setting of always_after_branch above).
11277 offset
= RelocFuncs::thumb32_cond_branch_offset(upper_insn
,
11279 stub_type
= arm_stub_a8_veneer_b_cond
;
11281 else if (is_b
|| is_bl
|| is_blx
)
11283 offset
= RelocFuncs::thumb32_branch_offset(upper_insn
,
11288 stub_type
= (is_blx
11289 ? arm_stub_a8_veneer_blx
11291 ? arm_stub_a8_veneer_bl
11292 : arm_stub_a8_veneer_b
));
11295 if (stub_type
!= arm_stub_none
)
11297 Arm_address pc_for_insn
= address
+ i
+ 4;
11299 // The original instruction is a BL, but the target is
11300 // an ARM instruction. If we were not making a stub,
11301 // the BL would have been converted to a BLX. Use the
11302 // BLX stub instead in that case.
11303 if (this->may_use_blx() && force_target_arm
11304 && stub_type
== arm_stub_a8_veneer_bl
)
11306 stub_type
= arm_stub_a8_veneer_blx
;
11310 // Conversely, if the original instruction was
11311 // BLX but the target is Thumb mode, use the BL stub.
11312 else if (force_target_thumb
11313 && stub_type
== arm_stub_a8_veneer_blx
)
11315 stub_type
= arm_stub_a8_veneer_bl
;
11323 // If we found a relocation, use the proper destination,
11324 // not the offset in the (unrelocated) instruction.
11325 // Note this is always done if we switched the stub type above.
11326 if (cortex_a8_reloc
!= NULL
)
11327 offset
= (off_t
) (cortex_a8_reloc
->destination() - pc_for_insn
);
11329 Arm_address target
= (pc_for_insn
+ offset
) | (is_blx
? 0 : 1);
11331 // Add a new stub if destination address in in the same page.
11332 if (((address
+ i
) & ~0xfffU
) == (target
& ~0xfffU
))
11334 Cortex_a8_stub
* stub
=
11335 this->stub_factory_
.make_cortex_a8_stub(stub_type
,
11339 Stub_table
<big_endian
>* stub_table
=
11340 arm_relobj
->stub_table(shndx
);
11341 gold_assert(stub_table
!= NULL
);
11342 stub_table
->add_cortex_a8_stub(address
+ i
, stub
);
11347 i
+= insn_32bit
? 4 : 2;
11348 last_was_32bit
= insn_32bit
;
11349 last_was_branch
= is_32bit_branch
;
11353 // Apply the Cortex-A8 workaround.
11355 template<bool big_endian
>
11357 Target_arm
<big_endian
>::apply_cortex_a8_workaround(
11358 const Cortex_a8_stub
* stub
,
11359 Arm_address stub_address
,
11360 unsigned char* insn_view
,
11361 Arm_address insn_address
)
11363 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
11364 Valtype
* wv
= reinterpret_cast<Valtype
*>(insn_view
);
11365 Valtype upper_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
11366 Valtype lower_insn
= elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
11367 off_t branch_offset
= stub_address
- (insn_address
+ 4);
11369 typedef struct Arm_relocate_functions
<big_endian
> RelocFuncs
;
11370 switch (stub
->stub_template()->type())
11372 case arm_stub_a8_veneer_b_cond
:
11373 // For a conditional branch, we re-write it to be a uncondition
11374 // branch to the stub. We use the THUMB-2 encoding here.
11375 upper_insn
= 0xf000U
;
11376 lower_insn
= 0xb800U
;
11378 case arm_stub_a8_veneer_b
:
11379 case arm_stub_a8_veneer_bl
:
11380 case arm_stub_a8_veneer_blx
:
11381 if ((lower_insn
& 0x5000U
) == 0x4000U
)
11382 // For a BLX instruction, make sure that the relocation is
11383 // rounded up to a word boundary. This follows the semantics of
11384 // the instruction which specifies that bit 1 of the target
11385 // address will come from bit 1 of the base address.
11386 branch_offset
= (branch_offset
+ 2) & ~3;
11388 // Put BRANCH_OFFSET back into the insn.
11389 gold_assert(!utils::has_overflow
<25>(branch_offset
));
11390 upper_insn
= RelocFuncs::thumb32_branch_upper(upper_insn
, branch_offset
);
11391 lower_insn
= RelocFuncs::thumb32_branch_lower(lower_insn
, branch_offset
);
11395 gold_unreachable();
11398 // Put the relocated value back in the object file:
11399 elfcpp::Swap
<16, big_endian
>::writeval(wv
, upper_insn
);
11400 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, lower_insn
);
11403 template<bool big_endian
>
11404 class Target_selector_arm
: public Target_selector
11407 Target_selector_arm()
11408 : Target_selector(elfcpp::EM_ARM
, 32, big_endian
,
11409 (big_endian
? "elf32-bigarm" : "elf32-littlearm"))
11413 do_instantiate_target()
11414 { return new Target_arm
<big_endian
>(); }
11417 // Fix .ARM.exidx section coverage.
11419 template<bool big_endian
>
11421 Target_arm
<big_endian
>::fix_exidx_coverage(
11423 Arm_output_section
<big_endian
>* exidx_section
,
11424 Symbol_table
* symtab
)
11426 // We need to look at all the input sections in output in ascending
11427 // order of of output address. We do that by building a sorted list
11428 // of output sections by addresses. Then we looks at the output sections
11429 // in order. The input sections in an output section are already sorted
11430 // by addresses within the output section.
11432 typedef std::set
<Output_section
*, output_section_address_less_than
>
11433 Sorted_output_section_list
;
11434 Sorted_output_section_list sorted_output_sections
;
11435 Layout::Section_list section_list
;
11436 layout
->get_allocated_sections(§ion_list
);
11437 for (Layout::Section_list::const_iterator p
= section_list
.begin();
11438 p
!= section_list
.end();
11441 // We only care about output sections that contain executable code.
11442 if (((*p
)->flags() & elfcpp::SHF_EXECINSTR
) != 0)
11443 sorted_output_sections
.insert(*p
);
11446 // Go over the output sections in ascending order of output addresses.
11447 typedef typename Arm_output_section
<big_endian
>::Text_section_list
11449 Text_section_list sorted_text_sections
;
11450 for(typename
Sorted_output_section_list::iterator p
=
11451 sorted_output_sections
.begin();
11452 p
!= sorted_output_sections
.end();
11455 Arm_output_section
<big_endian
>* arm_output_section
=
11456 Arm_output_section
<big_endian
>::as_arm_output_section(*p
);
11457 arm_output_section
->append_text_sections_to_list(&sorted_text_sections
);
11460 exidx_section
->fix_exidx_coverage(layout
, sorted_text_sections
, symtab
,
11461 merge_exidx_entries());
11464 Target_selector_arm
<false> target_selector_arm
;
11465 Target_selector_arm
<true> target_selector_armbe
;
11467 } // End anonymous namespace.