1 // arm.cc -- arm target support for gold.
3 // Copyright 2009 Free Software Foundation, Inc.
4 // Written by Doug Kwan <dougkwan@google.com> based on the i386 code
5 // by Ian Lance Taylor <iant@google.com>.
6 // This file also contains borrowed and adapted code from
9 // This file is part of gold.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 3 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
24 // MA 02110-1301, USA.
35 #include "parameters.h"
42 #include "copy-relocs.h"
44 #include "target-reloc.h"
45 #include "target-select.h"
55 template<bool big_endian>
56 class Output_data_plt_arm;
58 template<bool big_endian>
61 template<bool big_endian>
62 class Arm_input_section;
64 template<bool big_endian>
65 class Arm_output_section;
67 template<bool big_endian>
70 template<bool big_endian>
74 typedef elfcpp::Elf_types<32>::Elf_Addr Arm_address;
76 // Maximum branch offsets for ARM, THUMB and THUMB2.
77 const int32_t ARM_MAX_FWD_BRANCH_OFFSET = ((((1 << 23) - 1) << 2) + 8);
78 const int32_t ARM_MAX_BWD_BRANCH_OFFSET = ((-((1 << 23) << 2)) + 8);
79 const int32_t THM_MAX_FWD_BRANCH_OFFSET = ((1 << 22) -2 + 4);
80 const int32_t THM_MAX_BWD_BRANCH_OFFSET = (-(1 << 22) + 4);
81 const int32_t THM2_MAX_FWD_BRANCH_OFFSET = (((1 << 24) - 2) + 4);
82 const int32_t THM2_MAX_BWD_BRANCH_OFFSET = (-(1 << 24) + 4);
84 // The arm target class.
86 // This is a very simple port of gold for ARM-EABI. It is intended for
87 // supporting Android only for the time being. Only these relocation types
116 // R_ARM_THM_MOVW_ABS_NC
117 // R_ARM_THM_MOVT_ABS
118 // R_ARM_MOVW_PREL_NC
120 // R_ARM_THM_MOVW_PREL_NC
121 // R_ARM_THM_MOVT_PREL
124 // - Generate various branch stubs.
125 // - Support interworking.
126 // - Define section symbols __exidx_start and __exidx_stop.
127 // - Support more relocation types as needed.
128 // - Make PLTs more flexible for different architecture features like
130 // There are probably a lot more.
132 // Instruction template class. This class is similar to the insn_sequence
133 // struct in bfd/elf32-arm.c.
138 // Types of instruction templates.
147 // Factory methods to create instrunction templates in different formats.
149 static const Insn_template
150 thumb16_insn(uint32_t data)
151 { return Insn_template(data, THUMB16_TYPE, elfcpp::R_ARM_NONE, 0); }
153 // A bit of a hack. A Thumb conditional branch, in which the proper
154 // condition is inserted when we build the stub.
155 static const Insn_template
156 thumb16_bcond_insn(uint32_t data)
157 { return Insn_template(data, THUMB16_TYPE, elfcpp::R_ARM_NONE, 1); }
159 static const Insn_template
160 thumb32_insn(uint32_t data)
161 { return Insn_template(data, THUMB32_TYPE, elfcpp::R_ARM_NONE, 0); }
163 static const Insn_template
164 thumb32_b_insn(uint32_t data, int reloc_addend)
166 return Insn_template(data, THUMB32_TYPE, elfcpp::R_ARM_THM_JUMP24,
170 static const Insn_template
171 arm_insn(uint32_t data)
172 { return Insn_template(data, ARM_TYPE, elfcpp::R_ARM_NONE, 0); }
174 static const Insn_template
175 arm_rel_insn(unsigned data, int reloc_addend)
176 { return Insn_template(data, ARM_TYPE, elfcpp::R_ARM_JUMP24, reloc_addend); }
178 static const Insn_template
179 data_word(unsigned data, unsigned int r_type, int reloc_addend)
180 { return Insn_template(data, DATA_TYPE, r_type, reloc_addend); }
182 // Accessors. This class is used for read-only objects so no modifiers
187 { return this->data_; }
189 // Return the instruction sequence type of this.
192 { return this->type_; }
194 // Return the ARM relocation type of this.
197 { return this->r_type_; }
201 { return this->reloc_addend_; }
203 // Return size of instrunction template in bytes.
207 // Return byte-alignment of instrunction template.
212 // We make the constructor private to ensure that only the factory
215 Insn_template(unsigned data, Type type, unsigned int r_type, int reloc_addend)
216 : data_(data), type_(type), r_type_(r_type), reloc_addend_(reloc_addend)
219 // Instruction specific data. This is used to store information like
220 // some of the instruction bits.
222 // Instruction template type.
224 // Relocation type if there is a relocation or R_ARM_NONE otherwise.
225 unsigned int r_type_;
226 // Relocation addend.
227 int32_t reloc_addend_;
230 // Macro for generating code to stub types. One entry per long/short
234 DEF_STUB(long_branch_any_any) \
235 DEF_STUB(long_branch_v4t_arm_thumb) \
236 DEF_STUB(long_branch_thumb_only) \
237 DEF_STUB(long_branch_v4t_thumb_thumb) \
238 DEF_STUB(long_branch_v4t_thumb_arm) \
239 DEF_STUB(short_branch_v4t_thumb_arm) \
240 DEF_STUB(long_branch_any_arm_pic) \
241 DEF_STUB(long_branch_any_thumb_pic) \
242 DEF_STUB(long_branch_v4t_thumb_thumb_pic) \
243 DEF_STUB(long_branch_v4t_arm_thumb_pic) \
244 DEF_STUB(long_branch_v4t_thumb_arm_pic) \
245 DEF_STUB(long_branch_thumb_only_pic) \
246 DEF_STUB(a8_veneer_b_cond) \
247 DEF_STUB(a8_veneer_b) \
248 DEF_STUB(a8_veneer_bl) \
249 DEF_STUB(a8_veneer_blx)
253 #define DEF_STUB(x) arm_stub_##x,
259 // First reloc stub type.
260 arm_stub_reloc_first = arm_stub_long_branch_any_any,
261 // Last reloc stub type.
262 arm_stub_reloc_last = arm_stub_long_branch_thumb_only_pic,
264 // First Cortex-A8 stub type.
265 arm_stub_cortex_a8_first = arm_stub_a8_veneer_b_cond,
266 // Last Cortex-A8 stub type.
267 arm_stub_cortex_a8_last = arm_stub_a8_veneer_blx,
270 arm_stub_type_last = arm_stub_a8_veneer_blx
274 // Stub template class. Templates are meant to be read-only objects.
275 // A stub template for a stub type contains all read-only attributes
276 // common to all stubs of the same type.
281 Stub_template(Stub_type, const Insn_template*, size_t);
289 { return this->type_; }
291 // Return an array of instruction templates.
294 { return this->insns_; }
296 // Return size of template in number of instructions.
299 { return this->insn_count_; }
301 // Return size of template in bytes.
304 { return this->size_; }
306 // Return alignment of the stub template.
309 { return this->alignment_; }
311 // Return whether entry point is in thumb mode.
313 entry_in_thumb_mode() const
314 { return this->entry_in_thumb_mode_; }
316 // Return number of relocations in this template.
319 { return this->relocs_.size(); }
321 // Return index of the I-th instruction with relocation.
323 reloc_insn_index(size_t i) const
325 gold_assert(i < this->relocs_.size());
326 return this->relocs_[i].first;
329 // Return the offset of the I-th instruction with relocation from the
330 // beginning of the stub.
332 reloc_offset(size_t i) const
334 gold_assert(i < this->relocs_.size());
335 return this->relocs_[i].second;
339 // This contains information about an instruction template with a relocation
340 // and its offset from start of stub.
341 typedef std::pair<size_t, section_size_type> Reloc;
343 // A Stub_template may not be copied. We want to share templates as much
345 Stub_template(const Stub_template&);
346 Stub_template& operator=(const Stub_template&);
350 // Points to an array of Insn_templates.
351 const Insn_template* insns_;
352 // Number of Insn_templates in insns_[].
354 // Size of templated instructions in bytes.
356 // Alignment of templated instructions.
358 // Flag to indicate if entry is in thumb mode.
359 bool entry_in_thumb_mode_;
360 // A table of reloc instruction indices and offsets. We can find these by
361 // looking at the instruction templates but we pre-compute and then stash
362 // them here for speed.
363 std::vector<Reloc> relocs_;
367 // A class for code stubs. This is a base class for different type of
368 // stubs used in the ARM target.
374 static const section_offset_type invalid_offset =
375 static_cast<section_offset_type>(-1);
378 Stub(const Stub_template* stub_template)
379 : stub_template_(stub_template), offset_(invalid_offset)
386 // Return the stub template.
388 stub_template() const
389 { return this->stub_template_; }
391 // Return offset of code stub from beginning of its containing stub table.
395 gold_assert(this->offset_ != invalid_offset);
396 return this->offset_;
399 // Set offset of code stub from beginning of its containing stub table.
401 set_offset(section_offset_type offset)
402 { this->offset_ = offset; }
404 // Return the relocation target address of the i-th relocation in the
405 // stub. This must be defined in a child class.
407 reloc_target(size_t i)
408 { return this->do_reloc_target(i); }
410 // Write a stub at output VIEW. BIG_ENDIAN select how a stub is written.
412 write(unsigned char* view, section_size_type view_size, bool big_endian)
413 { this->do_write(view, view_size, big_endian); }
416 // This must be defined in the child class.
418 do_reloc_target(size_t) = 0;
420 // This must be defined in the child class.
422 do_write(unsigned char*, section_size_type, bool) = 0;
426 const Stub_template* stub_template_;
427 // Offset within the section of containing this stub.
428 section_offset_type offset_;
431 // Reloc stub class. These are stubs we use to fix up relocation because
432 // of limited branch ranges.
434 class Reloc_stub : public Stub
437 static const unsigned int invalid_index = static_cast<unsigned int>(-1);
438 // We assume we never jump to this address.
439 static const Arm_address invalid_address = static_cast<Arm_address>(-1);
441 // Return destination address.
443 destination_address() const
445 gold_assert(this->destination_address_ != this->invalid_address);
446 return this->destination_address_;
449 // Set destination address.
451 set_destination_address(Arm_address address)
453 gold_assert(address != this->invalid_address);
454 this->destination_address_ = address;
457 // Reset destination address.
459 reset_destination_address()
460 { this->destination_address_ = this->invalid_address; }
462 // Determine stub type for a branch of a relocation of R_TYPE going
463 // from BRANCH_ADDRESS to BRANCH_TARGET. If TARGET_IS_THUMB is set,
464 // the branch target is a thumb instruction. TARGET is used for look
465 // up ARM-specific linker settings.
467 stub_type_for_reloc(unsigned int r_type, Arm_address branch_address,
468 Arm_address branch_target, bool target_is_thumb);
470 // Reloc_stub key. A key is logically a triplet of a stub type, a symbol
471 // and an addend. Since we treat global and local symbol differently, we
472 // use a Symbol object for a global symbol and a object-index pair for
477 // If SYMBOL is not null, this is a global symbol, we ignore RELOBJ and
478 // R_SYM. Otherwise, this is a local symbol and RELOBJ must non-NULL
479 // and R_SYM must not be invalid_index.
480 Key(Stub_type stub_type, const Symbol* symbol, const Relobj* relobj,
481 unsigned int r_sym, int32_t addend)
482 : stub_type_(stub_type), addend_(addend)
486 this->r_sym_ = Reloc_stub::invalid_index;
487 this->u_.symbol = symbol;
491 gold_assert(relobj != NULL && r_sym != invalid_index);
492 this->r_sym_ = r_sym;
493 this->u_.relobj = relobj;
500 // Accessors: Keys are meant to be read-only object so no modifiers are
506 { return this->stub_type_; }
508 // Return the local symbol index or invalid_index.
511 { return this->r_sym_; }
513 // Return the symbol if there is one.
516 { return this->r_sym_ == invalid_index ? this->u_.symbol : NULL; }
518 // Return the relobj if there is one.
521 { return this->r_sym_ != invalid_index ? this->u_.relobj : NULL; }
523 // Whether this equals to another key k.
525 eq(const Key& k) const
527 return ((this->stub_type_ == k.stub_type_)
528 && (this->r_sym_ == k.r_sym_)
529 && ((this->r_sym_ != Reloc_stub::invalid_index)
530 ? (this->u_.relobj == k.u_.relobj)
531 : (this->u_.symbol == k.u_.symbol))
532 && (this->addend_ == k.addend_));
535 // Return a hash value.
539 return (this->stub_type_
541 ^ gold::string_hash<char>(
542 (this->r_sym_ != Reloc_stub::invalid_index)
543 ? this->u_.relobj->name().c_str()
544 : this->u_.symbol->name())
548 // Functors for STL associative containers.
552 operator()(const Key& k) const
553 { return k.hash_value(); }
559 operator()(const Key& k1, const Key& k2) const
560 { return k1.eq(k2); }
563 // Name of key. This is mainly for debugging.
569 Stub_type stub_type_;
570 // If this is a local symbol, this is the index in the defining object.
571 // Otherwise, it is invalid_index for a global symbol.
573 // If r_sym_ is invalid index. This points to a global symbol.
574 // Otherwise, this points a relobj. We used the unsized and target
575 // independent Symbol and Relobj classes instead of Arm_symbol and
576 // Arm_relobj. This is done to avoid making the stub class a template
577 // as most of the stub machinery is endianity-neutral. However, it
578 // may require a bit of casting done by users of this class.
581 const Symbol* symbol;
582 const Relobj* relobj;
584 // Addend associated with a reloc.
589 // Reloc_stubs are created via a stub factory. So these are protected.
590 Reloc_stub(const Stub_template* stub_template)
591 : Stub(stub_template), destination_address_(invalid_address)
597 friend class Stub_factory;
600 // Return the relocation target address of the i-th relocation in the
603 do_reloc_target(size_t i)
605 // All reloc stub have only one relocation.
607 return this->destination_address_;
610 // A template to implement do_write below.
611 template<bool big_endian>
613 do_fixed_endian_write(unsigned char*, section_size_type);
617 do_write(unsigned char* view, section_size_type view_size, bool big_endian);
619 // Address of destination.
620 Arm_address destination_address_;
623 // Stub factory class.
628 // Return the unique instance of this class.
629 static const Stub_factory&
632 static Stub_factory singleton;
636 // Make a relocation stub.
638 make_reloc_stub(Stub_type stub_type) const
640 gold_assert(stub_type >= arm_stub_reloc_first
641 && stub_type <= arm_stub_reloc_last);
642 return new Reloc_stub(this->stub_templates_[stub_type]);
646 // Constructor and destructor are protected since we only return a single
647 // instance created in Stub_factory::get_instance().
651 // A Stub_factory may not be copied since it is a singleton.
652 Stub_factory(const Stub_factory&);
653 Stub_factory& operator=(Stub_factory&);
655 // Stub templates. These are initialized in the constructor.
656 const Stub_template* stub_templates_[arm_stub_type_last+1];
659 // A class to hold stubs for the ARM target.
661 template<bool big_endian>
662 class Stub_table : public Output_data
665 Stub_table(Arm_input_section<big_endian>* owner)
666 : Output_data(), addralign_(1), owner_(owner), has_been_changed_(false),
673 // Owner of this stub table.
674 Arm_input_section<big_endian>*
676 { return this->owner_; }
678 // Whether this stub table is empty.
681 { return this->reloc_stubs_.empty(); }
683 // Whether this has been changed.
685 has_been_changed() const
686 { return this->has_been_changed_; }
688 // Set the has-been-changed flag.
690 set_has_been_changed(bool value)
691 { this->has_been_changed_ = value; }
693 // Return the current data size.
695 current_data_size() const
696 { return this->current_data_size_for_child(); }
698 // Add a STUB with using KEY. Caller is reponsible for avoid adding
699 // if already a STUB with the same key has been added.
701 add_reloc_stub(Reloc_stub* stub, const Reloc_stub::Key& key);
703 // Look up a relocation stub using KEY. Return NULL if there is none.
705 find_reloc_stub(const Reloc_stub::Key& key) const
707 typename Reloc_stub_map::const_iterator p = this->reloc_stubs_.find(key);
708 return (p != this->reloc_stubs_.end()) ? p->second : NULL;
711 // Relocate stubs in this stub table.
713 relocate_stubs(const Relocate_info<32, big_endian>*,
714 Target_arm<big_endian>*, Output_section*,
715 unsigned char*, Arm_address, section_size_type);
718 // Write out section contents.
720 do_write(Output_file*);
722 // Return the required alignment.
725 { return this->addralign_; }
727 // Finalize data size.
729 set_final_data_size()
730 { this->set_data_size(this->current_data_size_for_child()); }
732 // Reset address and file offset.
734 do_reset_address_and_file_offset();
737 // Unordered map of stubs.
739 Unordered_map<Reloc_stub::Key, Reloc_stub*, Reloc_stub::Key::hash,
740 Reloc_stub::Key::equal_to>
745 // Owner of this stub table.
746 Arm_input_section<big_endian>* owner_;
747 // This is set to true during relaxiong if the size of the stub table
749 bool has_been_changed_;
750 // The relocation stubs.
751 Reloc_stub_map reloc_stubs_;
754 // A class to wrap an ordinary input section containing executable code.
756 template<bool big_endian>
757 class Arm_input_section : public Output_relaxed_input_section
760 Arm_input_section(Relobj* relobj, unsigned int shndx)
761 : Output_relaxed_input_section(relobj, shndx, 1),
762 original_addralign_(1), original_size_(0), stub_table_(NULL)
772 // Whether this is a stub table owner.
774 is_stub_table_owner() const
775 { return this->stub_table_ != NULL && this->stub_table_->owner() == this; }
777 // Return the stub table.
778 Stub_table<big_endian>*
780 { return this->stub_table_; }
782 // Set the stub_table.
784 set_stub_table(Stub_table<big_endian>* stub_table)
785 { this->stub_table_ = stub_table; }
787 // Downcast a base pointer to an Arm_input_section pointer. This is
788 // not type-safe but we only use Arm_input_section not the base class.
789 static Arm_input_section<big_endian>*
790 as_arm_input_section(Output_relaxed_input_section* poris)
791 { return static_cast<Arm_input_section<big_endian>*>(poris); }
794 // Write data to output file.
796 do_write(Output_file*);
798 // Return required alignment of this.
802 if (this->is_stub_table_owner())
803 return std::max(this->stub_table_->addralign(),
804 this->original_addralign_);
806 return this->original_addralign_;
809 // Finalize data size.
811 set_final_data_size();
813 // Reset address and file offset.
815 do_reset_address_and_file_offset();
819 do_output_offset(const Relobj* object, unsigned int shndx,
820 section_offset_type offset,
821 section_offset_type* poutput) const
823 if ((object == this->relobj())
824 && (shndx == this->shndx())
826 && (convert_types<uint64_t, section_offset_type>(offset)
827 <= this->original_size_))
837 // Copying is not allowed.
838 Arm_input_section(const Arm_input_section&);
839 Arm_input_section& operator=(const Arm_input_section&);
841 // Address alignment of the original input section.
842 uint64_t original_addralign_;
843 // Section size of the original input section.
844 uint64_t original_size_;
846 Stub_table<big_endian>* stub_table_;
849 // Arm output section class. This is defined mainly to add a number of
850 // stub generation methods.
852 template<bool big_endian>
853 class Arm_output_section : public Output_section
856 Arm_output_section(const char* name, elfcpp::Elf_Word type,
857 elfcpp::Elf_Xword flags)
858 : Output_section(name, type, flags)
861 ~Arm_output_section()
864 // Group input sections for stub generation.
866 group_sections(section_size_type, bool, Target_arm<big_endian>*);
868 // Downcast a base pointer to an Arm_output_section pointer. This is
869 // not type-safe but we only use Arm_output_section not the base class.
870 static Arm_output_section<big_endian>*
871 as_arm_output_section(Output_section* os)
872 { return static_cast<Arm_output_section<big_endian>*>(os); }
876 typedef Output_section::Input_section Input_section;
877 typedef Output_section::Input_section_list Input_section_list;
879 // Create a stub group.
880 void create_stub_group(Input_section_list::const_iterator,
881 Input_section_list::const_iterator,
882 Input_section_list::const_iterator,
883 Target_arm<big_endian>*,
884 std::vector<Output_relaxed_input_section*>*);
889 template<bool big_endian>
890 class Arm_relobj : public Sized_relobj<32, big_endian>
893 static const Arm_address invalid_address = static_cast<Arm_address>(-1);
895 Arm_relobj(const std::string& name, Input_file* input_file, off_t offset,
896 const typename elfcpp::Ehdr<32, big_endian>& ehdr)
897 : Sized_relobj<32, big_endian>(name, input_file, offset, ehdr),
898 stub_tables_(), local_symbol_is_thumb_function_()
904 // Return the stub table of the SHNDX-th section if there is one.
905 Stub_table<big_endian>*
906 stub_table(unsigned int shndx) const
908 gold_assert(shndx < this->stub_tables_.size());
909 return this->stub_tables_[shndx];
912 // Set STUB_TABLE to be the stub_table of the SHNDX-th section.
914 set_stub_table(unsigned int shndx, Stub_table<big_endian>* stub_table)
916 gold_assert(shndx < this->stub_tables_.size());
917 this->stub_tables_[shndx] = stub_table;
920 // Whether a local symbol is a THUMB function. R_SYM is the symbol table
921 // index. This is only valid after do_count_local_symbol is called.
923 local_symbol_is_thumb_function(unsigned int r_sym) const
925 gold_assert(r_sym < this->local_symbol_is_thumb_function_.size());
926 return this->local_symbol_is_thumb_function_[r_sym];
929 // Scan all relocation sections for stub generation.
931 scan_sections_for_stubs(Target_arm<big_endian>*, const Symbol_table*,
934 // Convert regular input section with index SHNDX to a relaxed section.
936 convert_input_section_to_relaxed_section(unsigned shndx)
938 // The stubs have relocations and we need to process them after writing
939 // out the stubs. So relocation now must follow section write.
940 this->invalidate_section_offset(shndx);
941 this->set_relocs_must_follow_section_writes();
944 // Downcast a base pointer to an Arm_relobj pointer. This is
945 // not type-safe but we only use Arm_relobj not the base class.
946 static Arm_relobj<big_endian>*
947 as_arm_relobj(Relobj* relobj)
948 { return static_cast<Arm_relobj<big_endian>*>(relobj); }
951 // Post constructor setup.
955 // Call parent's setup method.
956 Sized_relobj<32, big_endian>::do_setup();
958 // Initialize look-up tables.
959 Stub_table_list empty_stub_table_list(this->shnum(), NULL);
960 this->stub_tables_.swap(empty_stub_table_list);
963 // Count the local symbols.
965 do_count_local_symbols(Stringpool_template<char>*,
966 Stringpool_template<char>*);
969 do_relocate_sections(const General_options& options,
970 const Symbol_table* symtab, const Layout* layout,
971 const unsigned char* pshdrs,
972 typename Sized_relobj<32, big_endian>::Views* pivews);
975 // List of stub tables.
976 typedef std::vector<Stub_table<big_endian>*> Stub_table_list;
977 Stub_table_list stub_tables_;
978 // Bit vector to tell if a local symbol is a thumb function or not.
979 // This is only valid after do_count_local_symbol is called.
980 std::vector<bool> local_symbol_is_thumb_function_;
983 // Utilities for manipulating integers of up to 32-bits
987 // Sign extend an n-bit unsigned integer stored in an uint32_t into
988 // an int32_t. NO_BITS must be between 1 to 32.
989 template<int no_bits>
990 static inline int32_t
991 sign_extend(uint32_t bits)
993 gold_assert(no_bits >= 0 && no_bits <= 32);
995 return static_cast<int32_t>(bits);
996 uint32_t mask = (~((uint32_t) 0)) >> (32 - no_bits);
998 uint32_t top_bit = 1U << (no_bits - 1);
999 int32_t as_signed = static_cast<int32_t>(bits);
1000 return (bits & top_bit) ? as_signed + (-top_bit * 2) : as_signed;
1003 // Detects overflow of an NO_BITS integer stored in a uint32_t.
1004 template<int no_bits>
1006 has_overflow(uint32_t bits)
1008 gold_assert(no_bits >= 0 && no_bits <= 32);
1011 int32_t max = (1 << (no_bits - 1)) - 1;
1012 int32_t min = -(1 << (no_bits - 1));
1013 int32_t as_signed = static_cast<int32_t>(bits);
1014 return as_signed > max || as_signed < min;
1017 // Detects overflow of an NO_BITS integer stored in a uint32_t when it
1018 // fits in the given number of bits as either a signed or unsigned value.
1019 // For example, has_signed_unsigned_overflow<8> would check
1020 // -128 <= bits <= 255
1021 template<int no_bits>
1023 has_signed_unsigned_overflow(uint32_t bits)
1025 gold_assert(no_bits >= 2 && no_bits <= 32);
1028 int32_t max = static_cast<int32_t>((1U << no_bits) - 1);
1029 int32_t min = -(1 << (no_bits - 1));
1030 int32_t as_signed = static_cast<int32_t>(bits);
1031 return as_signed > max || as_signed < min;
1034 // Select bits from A and B using bits in MASK. For each n in [0..31],
1035 // the n-th bit in the result is chosen from the n-th bits of A and B.
1036 // A zero selects A and a one selects B.
1037 static inline uint32_t
1038 bit_select(uint32_t a, uint32_t b, uint32_t mask)
1039 { return (a & ~mask) | (b & mask); }
1042 template<bool big_endian>
1043 class Target_arm : public Sized_target<32, big_endian>
1046 typedef Output_data_reloc<elfcpp::SHT_REL, true, 32, big_endian>
1050 : Sized_target<32, big_endian>(&arm_info),
1051 got_(NULL), plt_(NULL), got_plt_(NULL), rel_dyn_(NULL),
1052 copy_relocs_(elfcpp::R_ARM_COPY), dynbss_(NULL),
1053 may_use_blx_(true), should_force_pic_veneer_(false)
1056 // Whether we can use BLX.
1059 { return this->may_use_blx_; }
1061 // Set use-BLX flag.
1063 set_may_use_blx(bool value)
1064 { this->may_use_blx_ = value; }
1066 // Whether we force PCI branch veneers.
1068 should_force_pic_veneer() const
1069 { return this->should_force_pic_veneer_; }
1071 // Set PIC veneer flag.
1073 set_should_force_pic_veneer(bool value)
1074 { this->should_force_pic_veneer_ = value; }
1076 // Whether we use THUMB-2 instructions.
1078 using_thumb2() const
1080 // FIXME: This should not hard-coded.
1084 // Whether we use THUMB/THUMB-2 instructions only.
1086 using_thumb_only() const
1088 // FIXME: This should not hard-coded.
1092 // Process the relocations to determine unreferenced sections for
1093 // garbage collection.
1095 gc_process_relocs(Symbol_table* symtab,
1097 Sized_relobj<32, big_endian>* object,
1098 unsigned int data_shndx,
1099 unsigned int sh_type,
1100 const unsigned char* prelocs,
1102 Output_section* output_section,
1103 bool needs_special_offset_handling,
1104 size_t local_symbol_count,
1105 const unsigned char* plocal_symbols);
1107 // Scan the relocations to look for symbol adjustments.
1109 scan_relocs(Symbol_table* symtab,
1111 Sized_relobj<32, big_endian>* object,
1112 unsigned int data_shndx,
1113 unsigned int sh_type,
1114 const unsigned char* prelocs,
1116 Output_section* output_section,
1117 bool needs_special_offset_handling,
1118 size_t local_symbol_count,
1119 const unsigned char* plocal_symbols);
1121 // Finalize the sections.
1123 do_finalize_sections(Layout*);
1125 // Return the value to use for a dynamic symbol which requires special
1128 do_dynsym_value(const Symbol*) const;
1130 // Relocate a section.
1132 relocate_section(const Relocate_info<32, big_endian>*,
1133 unsigned int sh_type,
1134 const unsigned char* prelocs,
1136 Output_section* output_section,
1137 bool needs_special_offset_handling,
1138 unsigned char* view,
1139 Arm_address view_address,
1140 section_size_type view_size,
1141 const Reloc_symbol_changes*);
1143 // Scan the relocs during a relocatable link.
1145 scan_relocatable_relocs(Symbol_table* symtab,
1147 Sized_relobj<32, big_endian>* object,
1148 unsigned int data_shndx,
1149 unsigned int sh_type,
1150 const unsigned char* prelocs,
1152 Output_section* output_section,
1153 bool needs_special_offset_handling,
1154 size_t local_symbol_count,
1155 const unsigned char* plocal_symbols,
1156 Relocatable_relocs*);
1158 // Relocate a section during a relocatable link.
1160 relocate_for_relocatable(const Relocate_info<32, big_endian>*,
1161 unsigned int sh_type,
1162 const unsigned char* prelocs,
1164 Output_section* output_section,
1165 off_t offset_in_output_section,
1166 const Relocatable_relocs*,
1167 unsigned char* view,
1168 Arm_address view_address,
1169 section_size_type view_size,
1170 unsigned char* reloc_view,
1171 section_size_type reloc_view_size);
1173 // Return whether SYM is defined by the ABI.
1175 do_is_defined_by_abi(Symbol* sym) const
1176 { return strcmp(sym->name(), "__tls_get_addr") == 0; }
1178 // Return the size of the GOT section.
1182 gold_assert(this->got_ != NULL);
1183 return this->got_->data_size();
1186 // Map platform-specific reloc types
1188 get_real_reloc_type (unsigned int r_type);
1190 // Get the default ARM target.
1191 static const Target_arm<big_endian>&
1194 gold_assert(parameters->target().machine_code() == elfcpp::EM_ARM
1195 && parameters->target().is_big_endian() == big_endian);
1196 return static_cast<const Target_arm<big_endian>&>(parameters->target());
1200 // The class which scans relocations.
1205 : issued_non_pic_error_(false)
1209 local(Symbol_table* symtab, Layout* layout, Target_arm* target,
1210 Sized_relobj<32, big_endian>* object,
1211 unsigned int data_shndx,
1212 Output_section* output_section,
1213 const elfcpp::Rel<32, big_endian>& reloc, unsigned int r_type,
1214 const elfcpp::Sym<32, big_endian>& lsym);
1217 global(Symbol_table* symtab, Layout* layout, Target_arm* target,
1218 Sized_relobj<32, big_endian>* object,
1219 unsigned int data_shndx,
1220 Output_section* output_section,
1221 const elfcpp::Rel<32, big_endian>& reloc, unsigned int r_type,
1226 unsupported_reloc_local(Sized_relobj<32, big_endian>*,
1227 unsigned int r_type);
1230 unsupported_reloc_global(Sized_relobj<32, big_endian>*,
1231 unsigned int r_type, Symbol*);
1234 check_non_pic(Relobj*, unsigned int r_type);
1236 // Almost identical to Symbol::needs_plt_entry except that it also
1237 // handles STT_ARM_TFUNC.
1239 symbol_needs_plt_entry(const Symbol* sym)
1241 // An undefined symbol from an executable does not need a PLT entry.
1242 if (sym->is_undefined() && !parameters->options().shared())
1245 return (!parameters->doing_static_link()
1246 && (sym->type() == elfcpp::STT_FUNC
1247 || sym->type() == elfcpp::STT_ARM_TFUNC)
1248 && (sym->is_from_dynobj()
1249 || sym->is_undefined()
1250 || sym->is_preemptible()));
1253 // Whether we have issued an error about a non-PIC compilation.
1254 bool issued_non_pic_error_;
1257 // The class which implements relocation.
1267 // Return whether the static relocation needs to be applied.
1269 should_apply_static_reloc(const Sized_symbol<32>* gsym,
1272 Output_section* output_section);
1274 // Do a relocation. Return false if the caller should not issue
1275 // any warnings about this relocation.
1277 relocate(const Relocate_info<32, big_endian>*, Target_arm*,
1278 Output_section*, size_t relnum,
1279 const elfcpp::Rel<32, big_endian>&,
1280 unsigned int r_type, const Sized_symbol<32>*,
1281 const Symbol_value<32>*,
1282 unsigned char*, Arm_address,
1285 // Return whether we want to pass flag NON_PIC_REF for this
1288 reloc_is_non_pic (unsigned int r_type)
1292 case elfcpp::R_ARM_REL32:
1293 case elfcpp::R_ARM_THM_CALL:
1294 case elfcpp::R_ARM_CALL:
1295 case elfcpp::R_ARM_JUMP24:
1296 case elfcpp::R_ARM_PREL31:
1297 case elfcpp::R_ARM_THM_ABS5:
1298 case elfcpp::R_ARM_ABS8:
1299 case elfcpp::R_ARM_ABS12:
1300 case elfcpp::R_ARM_ABS16:
1301 case elfcpp::R_ARM_BASE_ABS:
1309 // A class which returns the size required for a relocation type,
1310 // used while scanning relocs during a relocatable link.
1311 class Relocatable_size_for_reloc
1315 get_size_for_reloc(unsigned int, Relobj*);
1318 // Get the GOT section, creating it if necessary.
1319 Output_data_got<32, big_endian>*
1320 got_section(Symbol_table*, Layout*);
1322 // Get the GOT PLT section.
1324 got_plt_section() const
1326 gold_assert(this->got_plt_ != NULL);
1327 return this->got_plt_;
1330 // Create a PLT entry for a global symbol.
1332 make_plt_entry(Symbol_table*, Layout*, Symbol*);
1334 // Get the PLT section.
1335 const Output_data_plt_arm<big_endian>*
1338 gold_assert(this->plt_ != NULL);
1342 // Get the dynamic reloc section, creating it if necessary.
1344 rel_dyn_section(Layout*);
1346 // Return true if the symbol may need a COPY relocation.
1347 // References from an executable object to non-function symbols
1348 // defined in a dynamic object may need a COPY relocation.
1350 may_need_copy_reloc(Symbol* gsym)
1352 return (gsym->type() != elfcpp::STT_ARM_TFUNC
1353 && gsym->may_need_copy_reloc());
1356 // Add a potential copy relocation.
1358 copy_reloc(Symbol_table* symtab, Layout* layout,
1359 Sized_relobj<32, big_endian>* object,
1360 unsigned int shndx, Output_section* output_section,
1361 Symbol* sym, const elfcpp::Rel<32, big_endian>& reloc)
1363 this->copy_relocs_.copy_reloc(symtab, layout,
1364 symtab->get_sized_symbol<32>(sym),
1365 object, shndx, output_section, reloc,
1366 this->rel_dyn_section(layout));
1369 // Information about this specific target which we pass to the
1370 // general Target structure.
1371 static const Target::Target_info arm_info;
1373 // The types of GOT entries needed for this platform.
1376 GOT_TYPE_STANDARD = 0 // GOT entry for a regular symbol
1380 Output_data_got<32, big_endian>* got_;
1382 Output_data_plt_arm<big_endian>* plt_;
1383 // The GOT PLT section.
1384 Output_data_space* got_plt_;
1385 // The dynamic reloc section.
1386 Reloc_section* rel_dyn_;
1387 // Relocs saved to avoid a COPY reloc.
1388 Copy_relocs<elfcpp::SHT_REL, 32, big_endian> copy_relocs_;
1389 // Space for variables copied with a COPY reloc.
1390 Output_data_space* dynbss_;
1391 // Whether we can use BLX.
1393 // Whether we force PIC branch veneers.
1394 bool should_force_pic_veneer_;
1397 template<bool big_endian>
1398 const Target::Target_info Target_arm<big_endian>::arm_info =
1401 big_endian, // is_big_endian
1402 elfcpp::EM_ARM, // machine_code
1403 false, // has_make_symbol
1404 false, // has_resolve
1405 false, // has_code_fill
1406 true, // is_default_stack_executable
1408 "/usr/lib/libc.so.1", // dynamic_linker
1409 0x8000, // default_text_segment_address
1410 0x1000, // abi_pagesize (overridable by -z max-page-size)
1411 0x1000, // common_pagesize (overridable by -z common-page-size)
1412 elfcpp::SHN_UNDEF, // small_common_shndx
1413 elfcpp::SHN_UNDEF, // large_common_shndx
1414 0, // small_common_section_flags
1415 0 // large_common_section_flags
1418 // Arm relocate functions class
1421 template<bool big_endian>
1422 class Arm_relocate_functions : public Relocate_functions<32, big_endian>
1427 STATUS_OKAY, // No error during relocation.
1428 STATUS_OVERFLOW, // Relocation oveflow.
1429 STATUS_BAD_RELOC // Relocation cannot be applied.
1433 typedef Relocate_functions<32, big_endian> Base;
1434 typedef Arm_relocate_functions<big_endian> This;
1436 // Get an symbol value of *PSYMVAL with an ADDEND. This is a wrapper
1437 // to Symbol_value::value(). If HAS_THUMB_BIT is true, that LSB is used
1438 // to distinguish ARM and THUMB functions and it is treated specially.
1439 static inline Symbol_value<32>::Value
1440 arm_symbol_value (const Sized_relobj<32, big_endian> *object,
1441 const Symbol_value<32>* psymval,
1442 Symbol_value<32>::Value addend,
1445 typedef Symbol_value<32>::Value Valtype;
1449 Valtype raw = psymval->value(object, 0);
1450 Valtype thumb_bit = raw & 1;
1451 return ((raw & ~((Valtype) 1)) + addend) | thumb_bit;
1454 return psymval->value(object, addend);
1457 // Encoding of imm16 argument for movt and movw ARM instructions
1460 // imm16 := imm4 | imm12
1462 // 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
1463 // +-------+---------------+-------+-------+-----------------------+
1464 // | | |imm4 | |imm12 |
1465 // +-------+---------------+-------+-------+-----------------------+
1467 // Extract the relocation addend from VAL based on the ARM
1468 // instruction encoding described above.
1469 static inline typename elfcpp::Swap<32, big_endian>::Valtype
1470 extract_arm_movw_movt_addend(
1471 typename elfcpp::Swap<32, big_endian>::Valtype val)
1473 // According to the Elf ABI for ARM Architecture the immediate
1474 // field is sign-extended to form the addend.
1475 return utils::sign_extend<16>(((val >> 4) & 0xf000) | (val & 0xfff));
1478 // Insert X into VAL based on the ARM instruction encoding described
1480 static inline typename elfcpp::Swap<32, big_endian>::Valtype
1481 insert_val_arm_movw_movt(
1482 typename elfcpp::Swap<32, big_endian>::Valtype val,
1483 typename elfcpp::Swap<32, big_endian>::Valtype x)
1487 val |= (x & 0xf000) << 4;
1491 // Encoding of imm16 argument for movt and movw Thumb2 instructions
1494 // imm16 := imm4 | i | imm3 | imm8
1496 // 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
1497 // +---------+-+-----------+-------++-+-----+-------+---------------+
1498 // | |i| |imm4 || |imm3 | |imm8 |
1499 // +---------+-+-----------+-------++-+-----+-------+---------------+
1501 // Extract the relocation addend from VAL based on the Thumb2
1502 // instruction encoding described above.
1503 static inline typename elfcpp::Swap<32, big_endian>::Valtype
1504 extract_thumb_movw_movt_addend(
1505 typename elfcpp::Swap<32, big_endian>::Valtype val)
1507 // According to the Elf ABI for ARM Architecture the immediate
1508 // field is sign-extended to form the addend.
1509 return utils::sign_extend<16>(((val >> 4) & 0xf000)
1510 | ((val >> 15) & 0x0800)
1511 | ((val >> 4) & 0x0700)
1515 // Insert X into VAL based on the Thumb2 instruction encoding
1517 static inline typename elfcpp::Swap<32, big_endian>::Valtype
1518 insert_val_thumb_movw_movt(
1519 typename elfcpp::Swap<32, big_endian>::Valtype val,
1520 typename elfcpp::Swap<32, big_endian>::Valtype x)
1523 val |= (x & 0xf000) << 4;
1524 val |= (x & 0x0800) << 15;
1525 val |= (x & 0x0700) << 4;
1526 val |= (x & 0x00ff);
1530 // FIXME: This probably only works for Android on ARM v5te. We should
1531 // following GNU ld for the general case.
1532 template<unsigned r_type>
1533 static inline typename This::Status
1534 arm_branch_common(unsigned char *view,
1535 const Sized_relobj<32, big_endian>* object,
1536 const Symbol_value<32>* psymval,
1537 Arm_address address,
1540 typedef typename elfcpp::Swap<32, big_endian>::Valtype Valtype;
1541 Valtype* wv = reinterpret_cast<Valtype*>(view);
1542 Valtype val = elfcpp::Swap<32, big_endian>::readval(wv);
1544 bool insn_is_b = (((val >> 28) & 0xf) <= 0xe)
1545 && ((val & 0x0f000000UL) == 0x0a000000UL);
1546 bool insn_is_uncond_bl = (val & 0xff000000UL) == 0xeb000000UL;
1547 bool insn_is_cond_bl = (((val >> 28) & 0xf) < 0xe)
1548 && ((val & 0x0f000000UL) == 0x0b000000UL);
1549 bool insn_is_blx = (val & 0xfe000000UL) == 0xfa000000UL;
1550 bool insn_is_any_branch = (val & 0x0e000000UL) == 0x0a000000UL;
1552 if (r_type == elfcpp::R_ARM_CALL)
1554 if (!insn_is_uncond_bl && !insn_is_blx)
1555 return This::STATUS_BAD_RELOC;
1557 else if (r_type == elfcpp::R_ARM_JUMP24)
1559 if (!insn_is_b && !insn_is_cond_bl)
1560 return This::STATUS_BAD_RELOC;
1562 else if (r_type == elfcpp::R_ARM_PLT32)
1564 if (!insn_is_any_branch)
1565 return This::STATUS_BAD_RELOC;
1570 Valtype addend = utils::sign_extend<26>(val << 2);
1571 Valtype x = (This::arm_symbol_value(object, psymval, addend, has_thumb_bit)
1574 // If target has thumb bit set, we need to either turn the BL
1575 // into a BLX (for ARMv5 or above) or generate a stub.
1579 if (insn_is_uncond_bl)
1580 val = (val & 0xffffff) | 0xfa000000 | ((x & 2) << 23);
1582 return This::STATUS_BAD_RELOC;
1585 gold_assert(!insn_is_blx);
1587 val = utils::bit_select(val, (x >> 2), 0xffffffUL);
1588 elfcpp::Swap<32, big_endian>::writeval(wv, val);
1589 return (utils::has_overflow<26>(x)
1590 ? This::STATUS_OVERFLOW : This::STATUS_OKAY);
1595 // R_ARM_ABS8: S + A
1596 static inline typename This::Status
1597 abs8(unsigned char *view,
1598 const Sized_relobj<32, big_endian>* object,
1599 const Symbol_value<32>* psymval)
1601 typedef typename elfcpp::Swap<8, big_endian>::Valtype Valtype;
1602 typedef typename elfcpp::Swap<32, big_endian>::Valtype Reltype;
1603 Valtype* wv = reinterpret_cast<Valtype*>(view);
1604 Valtype val = elfcpp::Swap<8, big_endian>::readval(wv);
1605 Reltype addend = utils::sign_extend<8>(val);
1606 Reltype x = This::arm_symbol_value(object, psymval, addend, false);
1607 val = utils::bit_select(val, x, 0xffU);
1608 elfcpp::Swap<8, big_endian>::writeval(wv, val);
1609 return (utils::has_signed_unsigned_overflow<8>(x)
1610 ? This::STATUS_OVERFLOW
1611 : This::STATUS_OKAY);
1614 // R_ARM_THM_ABS5: S + A
1615 static inline typename This::Status
1616 thm_abs5(unsigned char *view,
1617 const Sized_relobj<32, big_endian>* object,
1618 const Symbol_value<32>* psymval)
1620 typedef typename elfcpp::Swap<16, big_endian>::Valtype Valtype;
1621 typedef typename elfcpp::Swap<32, big_endian>::Valtype Reltype;
1622 Valtype* wv = reinterpret_cast<Valtype*>(view);
1623 Valtype val = elfcpp::Swap<16, big_endian>::readval(wv);
1624 Reltype addend = (val & 0x7e0U) >> 6;
1625 Reltype x = This::arm_symbol_value(object, psymval, addend, false);
1626 val = utils::bit_select(val, x << 6, 0x7e0U);
1627 elfcpp::Swap<16, big_endian>::writeval(wv, val);
1628 return (utils::has_overflow<5>(x)
1629 ? This::STATUS_OVERFLOW
1630 : This::STATUS_OKAY);
1633 // R_ARM_ABS12: S + A
1634 static inline typename This::Status
1635 abs12(unsigned char *view,
1636 const Sized_relobj<32, big_endian>* object,
1637 const Symbol_value<32>* psymval)
1639 typedef typename elfcpp::Swap<32, big_endian>::Valtype Valtype;
1640 typedef typename elfcpp::Swap<32, big_endian>::Valtype Reltype;
1641 Valtype* wv = reinterpret_cast<Valtype*>(view);
1642 Valtype val = elfcpp::Swap<32, big_endian>::readval(wv);
1643 Reltype addend = val & 0x0fffU;
1644 Reltype x = This::arm_symbol_value(object, psymval, addend, false);
1645 val = utils::bit_select(val, x, 0x0fffU);
1646 elfcpp::Swap<32, big_endian>::writeval(wv, val);
1647 return (utils::has_overflow<12>(x)
1648 ? This::STATUS_OVERFLOW
1649 : This::STATUS_OKAY);
1652 // R_ARM_ABS16: S + A
1653 static inline typename This::Status
1654 abs16(unsigned char *view,
1655 const Sized_relobj<32, big_endian>* object,
1656 const Symbol_value<32>* psymval)
1658 typedef typename elfcpp::Swap<16, big_endian>::Valtype Valtype;
1659 typedef typename elfcpp::Swap<32, big_endian>::Valtype Reltype;
1660 Valtype* wv = reinterpret_cast<Valtype*>(view);
1661 Valtype val = elfcpp::Swap<16, big_endian>::readval(wv);
1662 Reltype addend = utils::sign_extend<16>(val);
1663 Reltype x = This::arm_symbol_value(object, psymval, addend, false);
1664 val = utils::bit_select(val, x, 0xffffU);
1665 elfcpp::Swap<16, big_endian>::writeval(wv, val);
1666 return (utils::has_signed_unsigned_overflow<16>(x)
1667 ? This::STATUS_OVERFLOW
1668 : This::STATUS_OKAY);
1671 // R_ARM_ABS32: (S + A) | T
1672 static inline typename This::Status
1673 abs32(unsigned char *view,
1674 const Sized_relobj<32, big_endian>* object,
1675 const Symbol_value<32>* psymval,
1678 typedef typename elfcpp::Swap<32, big_endian>::Valtype Valtype;
1679 Valtype* wv = reinterpret_cast<Valtype*>(view);
1680 Valtype addend = elfcpp::Swap<32, big_endian>::readval(wv);
1681 Valtype x = This::arm_symbol_value(object, psymval, addend, has_thumb_bit);
1682 elfcpp::Swap<32, big_endian>::writeval(wv, x);
1683 return This::STATUS_OKAY;
1686 // R_ARM_REL32: (S + A) | T - P
1687 static inline typename This::Status
1688 rel32(unsigned char *view,
1689 const Sized_relobj<32, big_endian>* object,
1690 const Symbol_value<32>* psymval,
1691 Arm_address address,
1694 typedef typename elfcpp::Swap<32, big_endian>::Valtype Valtype;
1695 Valtype* wv = reinterpret_cast<Valtype*>(view);
1696 Valtype addend = elfcpp::Swap<32, big_endian>::readval(wv);
1697 Valtype x = (This::arm_symbol_value(object, psymval, addend, has_thumb_bit)
1699 elfcpp::Swap<32, big_endian>::writeval(wv, x);
1700 return This::STATUS_OKAY;
1703 // R_ARM_THM_CALL: (S + A) | T - P
1704 static inline typename This::Status
1705 thm_call(unsigned char *view,
1706 const Sized_relobj<32, big_endian>* object,
1707 const Symbol_value<32>* psymval,
1708 Arm_address address,
1711 // A thumb call consists of two instructions.
1712 typedef typename elfcpp::Swap<16, big_endian>::Valtype Valtype;
1713 typedef typename elfcpp::Swap<32, big_endian>::Valtype Reltype;
1714 Valtype* wv = reinterpret_cast<Valtype*>(view);
1715 Valtype hi = elfcpp::Swap<16, big_endian>::readval(wv);
1716 Valtype lo = elfcpp::Swap<16, big_endian>::readval(wv + 1);
1717 // Must be a BL instruction. lo == 11111xxxxxxxxxxx.
1718 gold_assert((lo & 0xf800) == 0xf800);
1719 Reltype addend = utils::sign_extend<23>(((hi & 0x7ff) << 12)
1720 | ((lo & 0x7ff) << 1));
1721 Reltype x = (This::arm_symbol_value(object, psymval, addend, has_thumb_bit)
1724 // If target has no thumb bit set, we need to either turn the BL
1725 // into a BLX (for ARMv5 or above) or generate a stub.
1728 // This only works for ARMv5 and above with interworking enabled.
1731 hi = utils::bit_select(hi, (x >> 12), 0x7ffU);
1732 lo = utils::bit_select(lo, (x >> 1), 0x7ffU);
1733 elfcpp::Swap<16, big_endian>::writeval(wv, hi);
1734 elfcpp::Swap<16, big_endian>::writeval(wv + 1, lo);
1735 return (utils::has_overflow<23>(x)
1736 ? This::STATUS_OVERFLOW
1737 : This::STATUS_OKAY);
1740 // R_ARM_BASE_PREL: B(S) + A - P
1741 static inline typename This::Status
1742 base_prel(unsigned char* view,
1744 Arm_address address)
1746 Base::rel32(view, origin - address);
1750 // R_ARM_BASE_ABS: B(S) + A
1751 static inline typename This::Status
1752 base_abs(unsigned char* view,
1755 Base::rel32(view, origin);
1759 // R_ARM_GOT_BREL: GOT(S) + A - GOT_ORG
1760 static inline typename This::Status
1761 got_brel(unsigned char* view,
1762 typename elfcpp::Swap<32, big_endian>::Valtype got_offset)
1764 Base::rel32(view, got_offset);
1765 return This::STATUS_OKAY;
1768 // R_ARM_GOT_PREL: GOT(S) + A – P
1769 static inline typename This::Status
1770 got_prel(unsigned char* view,
1771 typename elfcpp::Swap<32, big_endian>::Valtype got_offset,
1772 Arm_address address)
1774 Base::rel32(view, got_offset - address);
1775 return This::STATUS_OKAY;
1778 // R_ARM_PLT32: (S + A) | T - P
1779 static inline typename This::Status
1780 plt32(unsigned char *view,
1781 const Sized_relobj<32, big_endian>* object,
1782 const Symbol_value<32>* psymval,
1783 Arm_address address,
1786 return arm_branch_common<elfcpp::R_ARM_PLT32>(view, object, psymval,
1787 address, has_thumb_bit);
1790 // R_ARM_CALL: (S + A) | T - P
1791 static inline typename This::Status
1792 call(unsigned char *view,
1793 const Sized_relobj<32, big_endian>* object,
1794 const Symbol_value<32>* psymval,
1795 Arm_address address,
1798 return arm_branch_common<elfcpp::R_ARM_CALL>(view, object, psymval,
1799 address, has_thumb_bit);
1802 // R_ARM_JUMP24: (S + A) | T - P
1803 static inline typename This::Status
1804 jump24(unsigned char *view,
1805 const Sized_relobj<32, big_endian>* object,
1806 const Symbol_value<32>* psymval,
1807 Arm_address address,
1810 return arm_branch_common<elfcpp::R_ARM_JUMP24>(view, object, psymval,
1811 address, has_thumb_bit);
1814 // R_ARM_PREL: (S + A) | T - P
1815 static inline typename This::Status
1816 prel31(unsigned char *view,
1817 const Sized_relobj<32, big_endian>* object,
1818 const Symbol_value<32>* psymval,
1819 Arm_address address,
1822 typedef typename elfcpp::Swap<32, big_endian>::Valtype Valtype;
1823 Valtype* wv = reinterpret_cast<Valtype*>(view);
1824 Valtype val = elfcpp::Swap<32, big_endian>::readval(wv);
1825 Valtype addend = utils::sign_extend<31>(val);
1826 Valtype x = (This::arm_symbol_value(object, psymval, addend, has_thumb_bit)
1828 val = utils::bit_select(val, x, 0x7fffffffU);
1829 elfcpp::Swap<32, big_endian>::writeval(wv, val);
1830 return (utils::has_overflow<31>(x) ?
1831 This::STATUS_OVERFLOW : This::STATUS_OKAY);
1834 // R_ARM_MOVW_ABS_NC: (S + A) | T
1835 static inline typename This::Status
1836 movw_abs_nc(unsigned char *view,
1837 const Sized_relobj<32, big_endian>* object,
1838 const Symbol_value<32>* psymval,
1841 typedef typename elfcpp::Swap<32, big_endian>::Valtype Valtype;
1842 Valtype* wv = reinterpret_cast<Valtype*>(view);
1843 Valtype val = elfcpp::Swap<32, big_endian>::readval(wv);
1844 Valtype addend = This::extract_arm_movw_movt_addend(val);
1845 Valtype x = This::arm_symbol_value(object, psymval, addend, has_thumb_bit);
1846 val = This::insert_val_arm_movw_movt(val, x);
1847 elfcpp::Swap<32, big_endian>::writeval(wv, val);
1848 return This::STATUS_OKAY;
1851 // R_ARM_MOVT_ABS: S + A
1852 static inline typename This::Status
1853 movt_abs(unsigned char *view,
1854 const Sized_relobj<32, big_endian>* object,
1855 const Symbol_value<32>* psymval)
1857 typedef typename elfcpp::Swap<32, big_endian>::Valtype Valtype;
1858 Valtype* wv = reinterpret_cast<Valtype*>(view);
1859 Valtype val = elfcpp::Swap<32, big_endian>::readval(wv);
1860 Valtype addend = This::extract_arm_movw_movt_addend(val);
1861 Valtype x = This::arm_symbol_value(object, psymval, addend, 0) >> 16;
1862 val = This::insert_val_arm_movw_movt(val, x);
1863 elfcpp::Swap<32, big_endian>::writeval(wv, val);
1864 return This::STATUS_OKAY;
1867 // R_ARM_THM_MOVW_ABS_NC: S + A | T
1868 static inline typename This::Status
1869 thm_movw_abs_nc(unsigned char *view,
1870 const Sized_relobj<32, big_endian>* object,
1871 const Symbol_value<32>* psymval,
1874 typedef typename elfcpp::Swap<16, big_endian>::Valtype Valtype;
1875 typedef typename elfcpp::Swap<32, big_endian>::Valtype Reltype;
1876 Valtype* wv = reinterpret_cast<Valtype*>(view);
1877 Reltype val = ((elfcpp::Swap<16, big_endian>::readval(wv) << 16)
1878 | elfcpp::Swap<16, big_endian>::readval(wv + 1));
1879 Reltype addend = extract_thumb_movw_movt_addend(val);
1880 Reltype x = This::arm_symbol_value(object, psymval, addend, has_thumb_bit);
1881 val = This::insert_val_thumb_movw_movt(val, x);
1882 elfcpp::Swap<16, big_endian>::writeval(wv, val >> 16);
1883 elfcpp::Swap<16, big_endian>::writeval(wv + 1, val & 0xffff);
1884 return This::STATUS_OKAY;
1887 // R_ARM_THM_MOVT_ABS: S + A
1888 static inline typename This::Status
1889 thm_movt_abs(unsigned char *view,
1890 const Sized_relobj<32, big_endian>* object,
1891 const Symbol_value<32>* psymval)
1893 typedef typename elfcpp::Swap<16, big_endian>::Valtype Valtype;
1894 typedef typename elfcpp::Swap<32, big_endian>::Valtype Reltype;
1895 Valtype* wv = reinterpret_cast<Valtype*>(view);
1896 Reltype val = ((elfcpp::Swap<16, big_endian>::readval(wv) << 16)
1897 | elfcpp::Swap<16, big_endian>::readval(wv + 1));
1898 Reltype addend = This::extract_thumb_movw_movt_addend(val);
1899 Reltype x = This::arm_symbol_value(object, psymval, addend, 0) >> 16;
1900 val = This::insert_val_thumb_movw_movt(val, x);
1901 elfcpp::Swap<16, big_endian>::writeval(wv, val >> 16);
1902 elfcpp::Swap<16, big_endian>::writeval(wv + 1, val & 0xffff);
1903 return This::STATUS_OKAY;
1906 // R_ARM_MOVW_PREL_NC: (S + A) | T - P
1907 static inline typename This::Status
1908 movw_prel_nc(unsigned char *view,
1909 const Sized_relobj<32, big_endian>* object,
1910 const Symbol_value<32>* psymval,
1911 Arm_address address,
1914 typedef typename elfcpp::Swap<32, big_endian>::Valtype Valtype;
1915 Valtype* wv = reinterpret_cast<Valtype*>(view);
1916 Valtype val = elfcpp::Swap<32, big_endian>::readval(wv);
1917 Valtype addend = This::extract_arm_movw_movt_addend(val);
1918 Valtype x = (This::arm_symbol_value(object, psymval, addend, has_thumb_bit)
1920 val = This::insert_val_arm_movw_movt(val, x);
1921 elfcpp::Swap<32, big_endian>::writeval(wv, val);
1922 return This::STATUS_OKAY;
1925 // R_ARM_MOVT_PREL: S + A - P
1926 static inline typename This::Status
1927 movt_prel(unsigned char *view,
1928 const Sized_relobj<32, big_endian>* object,
1929 const Symbol_value<32>* psymval,
1930 Arm_address address)
1932 typedef typename elfcpp::Swap<32, big_endian>::Valtype Valtype;
1933 Valtype* wv = reinterpret_cast<Valtype*>(view);
1934 Valtype val = elfcpp::Swap<32, big_endian>::readval(wv);
1935 Valtype addend = This::extract_arm_movw_movt_addend(val);
1936 Valtype x = (This::arm_symbol_value(object, psymval, addend, 0)
1938 val = This::insert_val_arm_movw_movt(val, x);
1939 elfcpp::Swap<32, big_endian>::writeval(wv, val);
1940 return This::STATUS_OKAY;
1943 // R_ARM_THM_MOVW_PREL_NC: (S + A) | T - P
1944 static inline typename This::Status
1945 thm_movw_prel_nc(unsigned char *view,
1946 const Sized_relobj<32, big_endian>* object,
1947 const Symbol_value<32>* psymval,
1948 Arm_address address,
1951 typedef typename elfcpp::Swap<16, big_endian>::Valtype Valtype;
1952 typedef typename elfcpp::Swap<32, big_endian>::Valtype Reltype;
1953 Valtype* wv = reinterpret_cast<Valtype*>(view);
1954 Reltype val = (elfcpp::Swap<16, big_endian>::readval(wv) << 16)
1955 | elfcpp::Swap<16, big_endian>::readval(wv + 1);
1956 Reltype addend = This::extract_thumb_movw_movt_addend(val);
1957 Reltype x = (This::arm_symbol_value(object, psymval, addend, has_thumb_bit)
1959 val = This::insert_val_thumb_movw_movt(val, x);
1960 elfcpp::Swap<16, big_endian>::writeval(wv, val >> 16);
1961 elfcpp::Swap<16, big_endian>::writeval(wv + 1, val & 0xffff);
1962 return This::STATUS_OKAY;
1965 // R_ARM_THM_MOVT_PREL: S + A - P
1966 static inline typename This::Status
1967 thm_movt_prel(unsigned char *view,
1968 const Sized_relobj<32, big_endian>* object,
1969 const Symbol_value<32>* psymval,
1970 Arm_address address)
1972 typedef typename elfcpp::Swap<16, big_endian>::Valtype Valtype;
1973 typedef typename elfcpp::Swap<32, big_endian>::Valtype Reltype;
1974 Valtype* wv = reinterpret_cast<Valtype*>(view);
1975 Reltype val = (elfcpp::Swap<16, big_endian>::readval(wv) << 16)
1976 | elfcpp::Swap<16, big_endian>::readval(wv + 1);
1977 Reltype addend = This::extract_thumb_movw_movt_addend(val);
1978 Reltype x = (This::arm_symbol_value(object, psymval, addend, 0)
1980 val = This::insert_val_thumb_movw_movt(val, x);
1981 elfcpp::Swap<16, big_endian>::writeval(wv, val >> 16);
1982 elfcpp::Swap<16, big_endian>::writeval(wv + 1, val & 0xffff);
1983 return This::STATUS_OKAY;
1987 // Get the GOT section, creating it if necessary.
1989 template<bool big_endian>
1990 Output_data_got<32, big_endian>*
1991 Target_arm<big_endian>::got_section(Symbol_table* symtab, Layout* layout)
1993 if (this->got_ == NULL)
1995 gold_assert(symtab != NULL && layout != NULL);
1997 this->got_ = new Output_data_got<32, big_endian>();
2000 os = layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
2002 | elfcpp::SHF_WRITE),
2006 // The old GNU linker creates a .got.plt section. We just
2007 // create another set of data in the .got section. Note that we
2008 // always create a PLT if we create a GOT, although the PLT
2010 this->got_plt_ = new Output_data_space(4, "** GOT PLT");
2011 os = layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
2013 | elfcpp::SHF_WRITE),
2017 // The first three entries are reserved.
2018 this->got_plt_->set_current_data_size(3 * 4);
2020 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
2021 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
2023 0, 0, elfcpp::STT_OBJECT,
2025 elfcpp::STV_HIDDEN, 0,
2031 // Get the dynamic reloc section, creating it if necessary.
2033 template<bool big_endian>
2034 typename Target_arm<big_endian>::Reloc_section*
2035 Target_arm<big_endian>::rel_dyn_section(Layout* layout)
2037 if (this->rel_dyn_ == NULL)
2039 gold_assert(layout != NULL);
2040 this->rel_dyn_ = new Reloc_section(parameters->options().combreloc());
2041 layout->add_output_section_data(".rel.dyn", elfcpp::SHT_REL,
2042 elfcpp::SHF_ALLOC, this->rel_dyn_);
2044 return this->rel_dyn_;
2047 // Insn_template methods.
2049 // Return byte size of an instruction template.
2052 Insn_template::size() const
2054 switch (this->type())
2067 // Return alignment of an instruction template.
2070 Insn_template::alignment() const
2072 switch (this->type())
2085 // Stub_template methods.
2087 Stub_template::Stub_template(
2088 Stub_type type, const Insn_template* insns,
2090 : type_(type), insns_(insns), insn_count_(insn_count), alignment_(1),
2091 entry_in_thumb_mode_(false), relocs_()
2095 // Compute byte size and alignment of stub template.
2096 for (size_t i = 0; i < insn_count; i++)
2098 unsigned insn_alignment = insns[i].alignment();
2099 size_t insn_size = insns[i].size();
2100 gold_assert((offset & (insn_alignment - 1)) == 0);
2101 this->alignment_ = std::max(this->alignment_, insn_alignment);
2102 switch (insns[i].type())
2104 case Insn_template::THUMB16_TYPE:
2106 this->entry_in_thumb_mode_ = true;
2109 case Insn_template::THUMB32_TYPE:
2110 if (insns[i].r_type() != elfcpp::R_ARM_NONE)
2111 this->relocs_.push_back(Reloc(i, offset));
2113 this->entry_in_thumb_mode_ = true;
2116 case Insn_template::ARM_TYPE:
2117 // Handle cases where the target is encoded within the
2119 if (insns[i].r_type() == elfcpp::R_ARM_JUMP24)
2120 this->relocs_.push_back(Reloc(i, offset));
2123 case Insn_template::DATA_TYPE:
2124 // Entry point cannot be data.
2125 gold_assert(i != 0);
2126 this->relocs_.push_back(Reloc(i, offset));
2132 offset += insn_size;
2134 this->size_ = offset;
2137 // Reloc_stub::Key methods.
2139 // Dump a Key as a string for debugging.
2142 Reloc_stub::Key::name() const
2144 if (this->r_sym_ == invalid_index)
2146 // Global symbol key name
2147 // <stub-type>:<symbol name>:<addend>.
2148 const std::string sym_name = this->u_.symbol->name();
2149 // We need to print two hex number and two colons. So just add 100 bytes
2150 // to the symbol name size.
2151 size_t len = sym_name.size() + 100;
2152 char* buffer = new char[len];
2153 int c = snprintf(buffer, len, "%d:%s:%x", this->stub_type_,
2154 sym_name.c_str(), this->addend_);
2155 gold_assert(c > 0 && c < static_cast<int>(len));
2157 return std::string(buffer);
2161 // local symbol key name
2162 // <stub-type>:<object>:<r_sym>:<addend>.
2163 const size_t len = 200;
2165 int c = snprintf(buffer, len, "%d:%p:%u:%x", this->stub_type_,
2166 this->u_.relobj, this->r_sym_, this->addend_);
2167 gold_assert(c > 0 && c < static_cast<int>(len));
2168 return std::string(buffer);
2172 // Reloc_stub methods.
2174 // Determine the type of stub needed, if any, for a relocation of R_TYPE at
2175 // LOCATION to DESTINATION.
2176 // This code is based on the arm_type_of_stub function in
2177 // bfd/elf32-arm.c. We have changed the interface a liitle to keep the Stub
2181 Reloc_stub::stub_type_for_reloc(
2182 unsigned int r_type,
2183 Arm_address location,
2184 Arm_address destination,
2185 bool target_is_thumb)
2187 Stub_type stub_type = arm_stub_none;
2189 // This is a bit ugly but we want to avoid using a templated class for
2190 // big and little endianities.
2192 bool should_force_pic_veneer;
2195 if (parameters->target().is_big_endian())
2197 const Target_arm<true>& big_endian_target =
2198 Target_arm<true>::default_target();
2199 may_use_blx = big_endian_target.may_use_blx();
2200 should_force_pic_veneer = big_endian_target.should_force_pic_veneer();
2201 thumb2 = big_endian_target.using_thumb2();
2202 thumb_only = big_endian_target.using_thumb_only();
2206 const Target_arm<false>& little_endian_target =
2207 Target_arm<false>::default_target();
2208 may_use_blx = little_endian_target.may_use_blx();
2209 should_force_pic_veneer = little_endian_target.should_force_pic_veneer();
2210 thumb2 = little_endian_target.using_thumb2();
2211 thumb_only = little_endian_target.using_thumb_only();
2214 int64_t branch_offset = (int64_t)destination - location;
2216 if (r_type == elfcpp::R_ARM_THM_CALL || r_type == elfcpp::R_ARM_THM_JUMP24)
2218 // Handle cases where:
2219 // - this call goes too far (different Thumb/Thumb2 max
2221 // - it's a Thumb->Arm call and blx is not available, or it's a
2222 // Thumb->Arm branch (not bl). A stub is needed in this case.
2224 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
2225 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
2227 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
2228 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
2229 || ((!target_is_thumb)
2230 && (((r_type == elfcpp::R_ARM_THM_CALL) && !may_use_blx)
2231 || (r_type == elfcpp::R_ARM_THM_JUMP24))))
2233 if (target_is_thumb)
2238 stub_type = (parameters->options().shared() | should_force_pic_veneer)
2241 && (r_type == elfcpp::R_ARM_THM_CALL))
2242 // V5T and above. Stub starts with ARM code, so
2243 // we must be able to switch mode before
2244 // reaching it, which is only possible for 'bl'
2245 // (ie R_ARM_THM_CALL relocation).
2246 ? arm_stub_long_branch_any_thumb_pic
2247 // On V4T, use Thumb code only.
2248 : arm_stub_long_branch_v4t_thumb_thumb_pic)
2252 && (r_type == elfcpp::R_ARM_THM_CALL))
2253 ? arm_stub_long_branch_any_any // V5T and above.
2254 : arm_stub_long_branch_v4t_thumb_thumb); // V4T.
2258 stub_type = (parameters->options().shared() | should_force_pic_veneer)
2259 ? arm_stub_long_branch_thumb_only_pic // PIC stub.
2260 : arm_stub_long_branch_thumb_only; // non-PIC stub.
2267 // FIXME: We should check that the input section is from an
2268 // object that has interwork enabled.
2270 stub_type = (parameters->options().shared()
2271 || should_force_pic_veneer)
2274 && (r_type == elfcpp::R_ARM_THM_CALL))
2275 ? arm_stub_long_branch_any_arm_pic // V5T and above.
2276 : arm_stub_long_branch_v4t_thumb_arm_pic) // V4T.
2280 && (r_type == elfcpp::R_ARM_THM_CALL))
2281 ? arm_stub_long_branch_any_any // V5T and above.
2282 : arm_stub_long_branch_v4t_thumb_arm); // V4T.
2284 // Handle v4t short branches.
2285 if ((stub_type == arm_stub_long_branch_v4t_thumb_arm)
2286 && (branch_offset <= THM_MAX_FWD_BRANCH_OFFSET)
2287 && (branch_offset >= THM_MAX_BWD_BRANCH_OFFSET))
2288 stub_type = arm_stub_short_branch_v4t_thumb_arm;
2292 else if (r_type == elfcpp::R_ARM_CALL
2293 || r_type == elfcpp::R_ARM_JUMP24
2294 || r_type == elfcpp::R_ARM_PLT32)
2296 if (target_is_thumb)
2300 // FIXME: We should check that the input section is from an
2301 // object that has interwork enabled.
2303 // We have an extra 2-bytes reach because of
2304 // the mode change (bit 24 (H) of BLX encoding).
2305 if (branch_offset > (ARM_MAX_FWD_BRANCH_OFFSET + 2)
2306 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET)
2307 || ((r_type == elfcpp::R_ARM_CALL) && !may_use_blx)
2308 || (r_type == elfcpp::R_ARM_JUMP24)
2309 || (r_type == elfcpp::R_ARM_PLT32))
2311 stub_type = (parameters->options().shared()
2312 || should_force_pic_veneer)
2315 ? arm_stub_long_branch_any_thumb_pic// V5T and above.
2316 : arm_stub_long_branch_v4t_arm_thumb_pic) // V4T stub.
2320 ? arm_stub_long_branch_any_any // V5T and above.
2321 : arm_stub_long_branch_v4t_arm_thumb); // V4T.
2327 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
2328 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET))
2330 stub_type = (parameters->options().shared()
2331 || should_force_pic_veneer)
2332 ? arm_stub_long_branch_any_arm_pic // PIC stubs.
2333 : arm_stub_long_branch_any_any; /// non-PIC.
2341 // Template to implement do_write for a specific target endianity.
2343 template<bool big_endian>
2345 Reloc_stub::do_fixed_endian_write(unsigned char* view,
2346 section_size_type view_size)
2348 const Stub_template* stub_template = this->stub_template();
2349 const Insn_template* insns = stub_template->insns();
2351 // FIXME: We do not handle BE8 encoding yet.
2352 unsigned char* pov = view;
2353 for (size_t i = 0; i < stub_template->insn_count(); i++)
2355 switch (insns[i].type())
2357 case Insn_template::THUMB16_TYPE:
2358 // Non-zero reloc addends are only used in Cortex-A8 stubs.
2359 gold_assert(insns[i].reloc_addend() == 0);
2360 elfcpp::Swap<16, big_endian>::writeval(pov, insns[i].data() & 0xffff);
2362 case Insn_template::THUMB32_TYPE:
2364 uint32_t hi = (insns[i].data() >> 16) & 0xffff;
2365 uint32_t lo = insns[i].data() & 0xffff;
2366 elfcpp::Swap<16, big_endian>::writeval(pov, hi);
2367 elfcpp::Swap<16, big_endian>::writeval(pov + 2, lo);
2370 case Insn_template::ARM_TYPE:
2371 case Insn_template::DATA_TYPE:
2372 elfcpp::Swap<32, big_endian>::writeval(pov, insns[i].data());
2377 pov += insns[i].size();
2379 gold_assert(static_cast<section_size_type>(pov - view) == view_size);
2382 // Write a reloc stub to VIEW with endianity specified by BIG_ENDIAN.
2385 Reloc_stub::do_write(unsigned char* view, section_size_type view_size,
2389 this->do_fixed_endian_write<true>(view, view_size);
2391 this->do_fixed_endian_write<false>(view, view_size);
2394 // Stub_factory methods.
2396 Stub_factory::Stub_factory()
2398 // The instruction template sequences are declared as static
2399 // objects and initialized first time the constructor runs.
2401 // Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
2402 // to reach the stub if necessary.
2403 static const Insn_template elf32_arm_stub_long_branch_any_any[] =
2405 Insn_template::arm_insn(0xe51ff004), // ldr pc, [pc, #-4]
2406 Insn_template::data_word(0, elfcpp::R_ARM_ABS32, 0),
2407 // dcd R_ARM_ABS32(X)
2410 // V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
2412 static const Insn_template elf32_arm_stub_long_branch_v4t_arm_thumb[] =
2414 Insn_template::arm_insn(0xe59fc000), // ldr ip, [pc, #0]
2415 Insn_template::arm_insn(0xe12fff1c), // bx ip
2416 Insn_template::data_word(0, elfcpp::R_ARM_ABS32, 0),
2417 // dcd R_ARM_ABS32(X)
2420 // Thumb -> Thumb long branch stub. Used on M-profile architectures.
2421 static const Insn_template elf32_arm_stub_long_branch_thumb_only[] =
2423 Insn_template::thumb16_insn(0xb401), // push {r0}
2424 Insn_template::thumb16_insn(0x4802), // ldr r0, [pc, #8]
2425 Insn_template::thumb16_insn(0x4684), // mov ip, r0
2426 Insn_template::thumb16_insn(0xbc01), // pop {r0}
2427 Insn_template::thumb16_insn(0x4760), // bx ip
2428 Insn_template::thumb16_insn(0xbf00), // nop
2429 Insn_template::data_word(0, elfcpp::R_ARM_ABS32, 0),
2430 // dcd R_ARM_ABS32(X)
2433 // V4T Thumb -> Thumb long branch stub. Using the stack is not
2435 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_thumb[] =
2437 Insn_template::thumb16_insn(0x4778), // bx pc
2438 Insn_template::thumb16_insn(0x46c0), // nop
2439 Insn_template::arm_insn(0xe59fc000), // ldr ip, [pc, #0]
2440 Insn_template::arm_insn(0xe12fff1c), // bx ip
2441 Insn_template::data_word(0, elfcpp::R_ARM_ABS32, 0),
2442 // dcd R_ARM_ABS32(X)
2445 // V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
2447 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_arm[] =
2449 Insn_template::thumb16_insn(0x4778), // bx pc
2450 Insn_template::thumb16_insn(0x46c0), // nop
2451 Insn_template::arm_insn(0xe51ff004), // ldr pc, [pc, #-4]
2452 Insn_template::data_word(0, elfcpp::R_ARM_ABS32, 0),
2453 // dcd R_ARM_ABS32(X)
2456 // V4T Thumb -> ARM short branch stub. Shorter variant of the above
2457 // one, when the destination is close enough.
2458 static const Insn_template elf32_arm_stub_short_branch_v4t_thumb_arm[] =
2460 Insn_template::thumb16_insn(0x4778), // bx pc
2461 Insn_template::thumb16_insn(0x46c0), // nop
2462 Insn_template::arm_rel_insn(0xea000000, -8), // b (X-8)
2465 // ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
2466 // blx to reach the stub if necessary.
2467 static const Insn_template elf32_arm_stub_long_branch_any_arm_pic[] =
2469 Insn_template::arm_insn(0xe59fc000), // ldr r12, [pc]
2470 Insn_template::arm_insn(0xe08ff00c), // add pc, pc, ip
2471 Insn_template::data_word(0, elfcpp::R_ARM_REL32, -4),
2472 // dcd R_ARM_REL32(X-4)
2475 // ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
2476 // blx to reach the stub if necessary. We can not add into pc;
2477 // it is not guaranteed to mode switch (different in ARMv6 and
2479 static const Insn_template elf32_arm_stub_long_branch_any_thumb_pic[] =
2481 Insn_template::arm_insn(0xe59fc004), // ldr r12, [pc, #4]
2482 Insn_template::arm_insn(0xe08fc00c), // add ip, pc, ip
2483 Insn_template::arm_insn(0xe12fff1c), // bx ip
2484 Insn_template::data_word(0, elfcpp::R_ARM_REL32, 0),
2485 // dcd R_ARM_REL32(X)
2488 // V4T ARM -> ARM long branch stub, PIC.
2489 static const Insn_template elf32_arm_stub_long_branch_v4t_arm_thumb_pic[] =
2491 Insn_template::arm_insn(0xe59fc004), // ldr ip, [pc, #4]
2492 Insn_template::arm_insn(0xe08fc00c), // add ip, pc, ip
2493 Insn_template::arm_insn(0xe12fff1c), // bx ip
2494 Insn_template::data_word(0, elfcpp::R_ARM_REL32, 0),
2495 // dcd R_ARM_REL32(X)
2498 // V4T Thumb -> ARM long branch stub, PIC.
2499 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_arm_pic[] =
2501 Insn_template::thumb16_insn(0x4778), // bx pc
2502 Insn_template::thumb16_insn(0x46c0), // nop
2503 Insn_template::arm_insn(0xe59fc000), // ldr ip, [pc, #0]
2504 Insn_template::arm_insn(0xe08cf00f), // add pc, ip, pc
2505 Insn_template::data_word(0, elfcpp::R_ARM_REL32, -4),
2506 // dcd R_ARM_REL32(X)
2509 // Thumb -> Thumb long branch stub, PIC. Used on M-profile
2511 static const Insn_template elf32_arm_stub_long_branch_thumb_only_pic[] =
2513 Insn_template::thumb16_insn(0xb401), // push {r0}
2514 Insn_template::thumb16_insn(0x4802), // ldr r0, [pc, #8]
2515 Insn_template::thumb16_insn(0x46fc), // mov ip, pc
2516 Insn_template::thumb16_insn(0x4484), // add ip, r0
2517 Insn_template::thumb16_insn(0xbc01), // pop {r0}
2518 Insn_template::thumb16_insn(0x4760), // bx ip
2519 Insn_template::data_word(0, elfcpp::R_ARM_REL32, 4),
2520 // dcd R_ARM_REL32(X)
2523 // V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not
2525 static const Insn_template elf32_arm_stub_long_branch_v4t_thumb_thumb_pic[] =
2527 Insn_template::thumb16_insn(0x4778), // bx pc
2528 Insn_template::thumb16_insn(0x46c0), // nop
2529 Insn_template::arm_insn(0xe59fc004), // ldr ip, [pc, #4]
2530 Insn_template::arm_insn(0xe08fc00c), // add ip, pc, ip
2531 Insn_template::arm_insn(0xe12fff1c), // bx ip
2532 Insn_template::data_word(0, elfcpp::R_ARM_REL32, 0),
2533 // dcd R_ARM_REL32(X)
2536 // Cortex-A8 erratum-workaround stubs.
2538 // Stub used for conditional branches (which may be beyond +/-1MB away,
2539 // so we can't use a conditional branch to reach this stub).
2546 static const Insn_template elf32_arm_stub_a8_veneer_b_cond[] =
2548 Insn_template::thumb16_bcond_insn(0xd001), // b<cond>.n true
2549 Insn_template::thumb32_b_insn(0xf000b800, -4), // b.w after
2550 Insn_template::thumb32_b_insn(0xf000b800, -4) // true:
2554 // Stub used for b.w and bl.w instructions.
2556 static const Insn_template elf32_arm_stub_a8_veneer_b[] =
2558 Insn_template::thumb32_b_insn(0xf000b800, -4) // b.w dest
2561 static const Insn_template elf32_arm_stub_a8_veneer_bl[] =
2563 Insn_template::thumb32_b_insn(0xf000b800, -4) // b.w dest
2566 // Stub used for Thumb-2 blx.w instructions. We modified the original blx.w
2567 // instruction (which switches to ARM mode) to point to this stub. Jump to
2568 // the real destination using an ARM-mode branch.
2569 const Insn_template elf32_arm_stub_a8_veneer_blx[] =
2571 Insn_template::arm_rel_insn(0xea000000, -8) // b dest
2574 // Fill in the stub template look-up table. Stub templates are constructed
2575 // per instance of Stub_factory for fast look-up without locking
2576 // in a thread-enabled environment.
2578 this->stub_templates_[arm_stub_none] =
2579 new Stub_template(arm_stub_none, NULL, 0);
2581 #define DEF_STUB(x) \
2585 = sizeof(elf32_arm_stub_##x) / sizeof(elf32_arm_stub_##x[0]); \
2586 Stub_type type = arm_stub_##x; \
2587 this->stub_templates_[type] = \
2588 new Stub_template(type, elf32_arm_stub_##x, array_size); \
2596 // Stub_table methods.
2598 // Add a STUB with using KEY. Caller is reponsible for avoid adding
2599 // if already a STUB with the same key has been added.
2601 template<bool big_endian>
2603 Stub_table<big_endian>::add_reloc_stub(
2605 const Reloc_stub::Key& key)
2607 const Stub_template* stub_template = stub->stub_template();
2608 gold_assert(stub_template->type() == key.stub_type());
2609 this->reloc_stubs_[key] = stub;
2610 if (this->addralign_ < stub_template->alignment())
2611 this->addralign_ = stub_template->alignment();
2612 this->has_been_changed_ = true;
2615 template<bool big_endian>
2617 Stub_table<big_endian>::relocate_stubs(
2618 const Relocate_info<32, big_endian>* relinfo,
2619 Target_arm<big_endian>* arm_target,
2620 Output_section* output_section,
2621 unsigned char* view,
2622 Arm_address address,
2623 section_size_type view_size)
2625 // If we are passed a view bigger than the stub table's. we need to
2627 gold_assert(address == this->address()
2629 == static_cast<section_size_type>(this->data_size())));
2631 for (typename Reloc_stub_map::const_iterator p = this->reloc_stubs_.begin();
2632 p != this->reloc_stubs_.end();
2635 Reloc_stub* stub = p->second;
2636 const Stub_template* stub_template = stub->stub_template();
2637 if (stub_template->reloc_count() != 0)
2639 // Adjust view to cover the stub only.
2640 section_size_type offset = stub->offset();
2641 section_size_type stub_size = stub_template->size();
2642 gold_assert(offset + stub_size <= view_size);
2644 arm_target->relocate_stub(stub, relinfo, output_section,
2645 view + offset, address + offset,
2651 // Reset address and file offset.
2653 template<bool big_endian>
2655 Stub_table<big_endian>::do_reset_address_and_file_offset()
2658 uint64_t max_addralign = 1;
2659 for (typename Reloc_stub_map::const_iterator p = this->reloc_stubs_.begin();
2660 p != this->reloc_stubs_.end();
2663 Reloc_stub* stub = p->second;
2664 const Stub_template* stub_template = stub->stub_template();
2665 uint64_t stub_addralign = stub_template->alignment();
2666 max_addralign = std::max(max_addralign, stub_addralign);
2667 off = align_address(off, stub_addralign);
2668 stub->set_offset(off);
2669 stub->reset_destination_address();
2670 off += stub_template->size();
2673 this->addralign_ = max_addralign;
2674 this->set_current_data_size_for_child(off);
2677 // Write out the stubs to file.
2679 template<bool big_endian>
2681 Stub_table<big_endian>::do_write(Output_file* of)
2683 off_t offset = this->offset();
2684 const section_size_type oview_size =
2685 convert_to_section_size_type(this->data_size());
2686 unsigned char* const oview = of->get_output_view(offset, oview_size);
2688 for (typename Reloc_stub_map::const_iterator p = this->reloc_stubs_.begin();
2689 p != this->reloc_stubs_.end();
2692 Reloc_stub* stub = p->second;
2693 Arm_address address = this->address() + stub->offset();
2695 == align_address(address,
2696 stub->stub_template()->alignment()));
2697 stub->write(oview + stub->offset(), stub->stub_template()->size(),
2700 of->write_output_view(this->offset(), oview_size, oview);
2703 // Arm_input_section methods.
2705 // Initialize an Arm_input_section.
2707 template<bool big_endian>
2709 Arm_input_section<big_endian>::init()
2711 Relobj* relobj = this->relobj();
2712 unsigned int shndx = this->shndx();
2714 // Cache these to speed up size and alignment queries. It is too slow
2715 // to call section_addraglin and section_size every time.
2716 this->original_addralign_ = relobj->section_addralign(shndx);
2717 this->original_size_ = relobj->section_size(shndx);
2719 // We want to make this look like the original input section after
2720 // output sections are finalized.
2721 Output_section* os = relobj->output_section(shndx);
2722 off_t offset = relobj->output_section_offset(shndx);
2723 gold_assert(os != NULL && !relobj->is_output_section_offset_invalid(shndx));
2724 this->set_address(os->address() + offset);
2725 this->set_file_offset(os->offset() + offset);
2727 this->set_current_data_size(this->original_size_);
2728 this->finalize_data_size();
2731 template<bool big_endian>
2733 Arm_input_section<big_endian>::do_write(Output_file* of)
2735 // We have to write out the original section content.
2736 section_size_type section_size;
2737 const unsigned char* section_contents =
2738 this->relobj()->section_contents(this->shndx(), §ion_size, false);
2739 of->write(this->offset(), section_contents, section_size);
2741 // If this owns a stub table and it is not empty, write it.
2742 if (this->is_stub_table_owner() && !this->stub_table_->empty())
2743 this->stub_table_->write(of);
2746 // Finalize data size.
2748 template<bool big_endian>
2750 Arm_input_section<big_endian>::set_final_data_size()
2752 // If this owns a stub table, finalize its data size as well.
2753 if (this->is_stub_table_owner())
2755 uint64_t address = this->address();
2757 // The stub table comes after the original section contents.
2758 address += this->original_size_;
2759 address = align_address(address, this->stub_table_->addralign());
2760 off_t offset = this->offset() + (address - this->address());
2761 this->stub_table_->set_address_and_file_offset(address, offset);
2762 address += this->stub_table_->data_size();
2763 gold_assert(address == this->address() + this->current_data_size());
2766 this->set_data_size(this->current_data_size());
2769 // Reset address and file offset.
2771 template<bool big_endian>
2773 Arm_input_section<big_endian>::do_reset_address_and_file_offset()
2775 // Size of the original input section contents.
2776 off_t off = convert_types<off_t, uint64_t>(this->original_size_);
2778 // If this is a stub table owner, account for the stub table size.
2779 if (this->is_stub_table_owner())
2781 Stub_table<big_endian>* stub_table = this->stub_table_;
2783 // Reset the stub table's address and file offset. The
2784 // current data size for child will be updated after that.
2785 stub_table_->reset_address_and_file_offset();
2786 off = align_address(off, stub_table_->addralign());
2787 off += stub_table->current_data_size();
2790 this->set_current_data_size(off);
2793 // Arm_output_section methods.
2795 // Create a stub group for input sections from BEGIN to END. OWNER
2796 // points to the input section to be the owner a new stub table.
2798 template<bool big_endian>
2800 Arm_output_section<big_endian>::create_stub_group(
2801 Input_section_list::const_iterator begin,
2802 Input_section_list::const_iterator end,
2803 Input_section_list::const_iterator owner,
2804 Target_arm<big_endian>* target,
2805 std::vector<Output_relaxed_input_section*>* new_relaxed_sections)
2807 // Currently we convert ordinary input sections into relaxed sections only
2808 // at this point but we may want to support creating relaxed input section
2809 // very early. So we check here to see if owner is already a relaxed
2812 Arm_input_section<big_endian>* arm_input_section;
2813 if (owner->is_relaxed_input_section())
2816 Arm_input_section<big_endian>::as_arm_input_section(
2817 owner->relaxed_input_section());
2821 gold_assert(owner->is_input_section());
2822 // Create a new relaxed input section.
2824 target->new_arm_input_section(owner->relobj(), owner->shndx());
2825 new_relaxed_sections->push_back(arm_input_section);
2828 // Create a stub table.
2829 Stub_table<big_endian>* stub_table =
2830 target->new_stub_table(arm_input_section);
2832 arm_input_section->set_stub_table(stub_table);
2834 Input_section_list::const_iterator p = begin;
2835 Input_section_list::const_iterator prev_p;
2837 // Look for input sections or relaxed input sections in [begin ... end].
2840 if (p->is_input_section() || p->is_relaxed_input_section())
2842 // The stub table information for input sections live
2843 // in their objects.
2844 Arm_relobj<big_endian>* arm_relobj =
2845 Arm_relobj<big_endian>::as_arm_relobj(p->relobj());
2846 arm_relobj->set_stub_table(p->shndx(), stub_table);
2850 while (prev_p != end);
2853 // Group input sections for stub generation. GROUP_SIZE is roughly the limit
2854 // of stub groups. We grow a stub group by adding input section until the
2855 // size is just below GROUP_SIZE. The last input section will be converted
2856 // into a stub table. If STUB_ALWAYS_AFTER_BRANCH is false, we also add
2857 // input section after the stub table, effectively double the group size.
2859 // This is similar to the group_sections() function in elf32-arm.c but is
2860 // implemented differently.
2862 template<bool big_endian>
2864 Arm_output_section<big_endian>::group_sections(
2865 section_size_type group_size,
2866 bool stubs_always_after_branch,
2867 Target_arm<big_endian>* target)
2869 // We only care about sections containing code.
2870 if ((this->flags() & elfcpp::SHF_EXECINSTR) == 0)
2873 // States for grouping.
2876 // No group is being built.
2878 // A group is being built but the stub table is not found yet.
2879 // We keep group a stub group until the size is just under GROUP_SIZE.
2880 // The last input section in the group will be used as the stub table.
2881 FINDING_STUB_SECTION,
2882 // A group is being built and we have already found a stub table.
2883 // We enter this state to grow a stub group by adding input section
2884 // after the stub table. This effectively doubles the group size.
2888 // Any newly created relaxed sections are stored here.
2889 std::vector<Output_relaxed_input_section*> new_relaxed_sections;
2891 State state = NO_GROUP;
2892 section_size_type off = 0;
2893 section_size_type group_begin_offset = 0;
2894 section_size_type group_end_offset = 0;
2895 section_size_type stub_table_end_offset = 0;
2896 Input_section_list::const_iterator group_begin =
2897 this->input_sections().end();
2898 Input_section_list::const_iterator stub_table =
2899 this->input_sections().end();
2900 Input_section_list::const_iterator group_end = this->input_sections().end();
2901 for (Input_section_list::const_iterator p = this->input_sections().begin();
2902 p != this->input_sections().end();
2905 section_size_type section_begin_offset =
2906 align_address(off, p->addralign());
2907 section_size_type section_end_offset =
2908 section_begin_offset + p->data_size();
2910 // Check to see if we should group the previously seens sections.
2916 case FINDING_STUB_SECTION:
2917 // Adding this section makes the group larger than GROUP_SIZE.
2918 if (section_end_offset - group_begin_offset >= group_size)
2920 if (stubs_always_after_branch)
2922 gold_assert(group_end != this->input_sections().end());
2923 this->create_stub_group(group_begin, group_end, group_end,
2924 target, &new_relaxed_sections);
2929 // But wait, there's more! Input sections up to
2930 // stub_group_size bytes after the stub table can be
2931 // handled by it too.
2932 state = HAS_STUB_SECTION;
2933 stub_table = group_end;
2934 stub_table_end_offset = group_end_offset;
2939 case HAS_STUB_SECTION:
2940 // Adding this section makes the post stub-section group larger
2942 if (section_end_offset - stub_table_end_offset >= group_size)
2944 gold_assert(group_end != this->input_sections().end());
2945 this->create_stub_group(group_begin, group_end, stub_table,
2946 target, &new_relaxed_sections);
2955 // If we see an input section and currently there is no group, start
2956 // a new one. Skip any empty sections.
2957 if ((p->is_input_section() || p->is_relaxed_input_section())
2958 && (p->relobj()->section_size(p->shndx()) != 0))
2960 if (state == NO_GROUP)
2962 state = FINDING_STUB_SECTION;
2964 group_begin_offset = section_begin_offset;
2967 // Keep track of the last input section seen.
2969 group_end_offset = section_end_offset;
2972 off = section_end_offset;
2975 // Create a stub group for any ungrouped sections.
2976 if (state == FINDING_STUB_SECTION || state == HAS_STUB_SECTION)
2978 gold_assert(group_end != this->input_sections().end());
2979 this->create_stub_group(group_begin, group_end,
2980 (state == FINDING_STUB_SECTION
2983 target, &new_relaxed_sections);
2986 // Convert input section into relaxed input section in a batch.
2987 if (!new_relaxed_sections.empty())
2988 this->convert_input_sections_to_relaxed_sections(new_relaxed_sections);
2990 // Update the section offsets
2991 for (size_t i = 0; i < new_relaxed_sections.size(); ++i)
2993 Arm_relobj<big_endian>* arm_relobj =
2994 Arm_relobj<big_endian>::as_arm_relobj(
2995 new_relaxed_sections[i]->relobj());
2996 unsigned int shndx = new_relaxed_sections[i]->shndx();
2997 // Tell Arm_relobj that this input section is converted.
2998 arm_relobj->convert_input_section_to_relaxed_section(shndx);
3002 // Arm_relobj methods.
3004 // Scan relocations for stub generation.
3006 template<bool big_endian>
3008 Arm_relobj<big_endian>::scan_sections_for_stubs(
3009 Target_arm<big_endian>* arm_target,
3010 const Symbol_table* symtab,
3011 const Layout* layout)
3013 unsigned int shnum = this->shnum();
3014 const unsigned int shdr_size = elfcpp::Elf_sizes<32>::shdr_size;
3016 // Read the section headers.
3017 const unsigned char* pshdrs = this->get_view(this->elf_file()->shoff(),
3021 // To speed up processing, we set up hash tables for fast lookup of
3022 // input offsets to output addresses.
3023 this->initialize_input_to_output_maps();
3025 const Relobj::Output_sections& out_sections(this->output_sections());
3027 Relocate_info<32, big_endian> relinfo;
3028 relinfo.symtab = symtab;
3029 relinfo.layout = layout;
3030 relinfo.object = this;
3032 const unsigned char* p = pshdrs + shdr_size;
3033 for (unsigned int i = 1; i < shnum; ++i, p += shdr_size)
3035 typename elfcpp::Shdr<32, big_endian> shdr(p);
3037 unsigned int sh_type = shdr.get_sh_type();
3038 if (sh_type != elfcpp::SHT_REL && sh_type != elfcpp::SHT_RELA)
3041 off_t sh_size = shdr.get_sh_size();
3045 unsigned int index = this->adjust_shndx(shdr.get_sh_info());
3046 if (index >= this->shnum())
3048 // Ignore reloc section with bad info. This error will be
3049 // reported in the final link.
3053 Output_section* os = out_sections[index];
3056 // This relocation section is against a section which we
3060 Arm_address output_offset = this->get_output_section_offset(index);
3062 if (this->adjust_shndx(shdr.get_sh_link()) != this->symtab_shndx())
3064 // Ignore reloc section with unexpected symbol table. The
3065 // error will be reported in the final link.
3069 const unsigned char* prelocs = this->get_view(shdr.get_sh_offset(),
3070 sh_size, true, false);
3072 unsigned int reloc_size;
3073 if (sh_type == elfcpp::SHT_REL)
3074 reloc_size = elfcpp::Elf_sizes<32>::rel_size;
3076 reloc_size = elfcpp::Elf_sizes<32>::rela_size;
3078 if (reloc_size != shdr.get_sh_entsize())
3080 // Ignore reloc section with unexpected entsize. The error
3081 // will be reported in the final link.
3085 size_t reloc_count = sh_size / reloc_size;
3086 if (static_cast<off_t>(reloc_count * reloc_size) != sh_size)
3088 // Ignore reloc section with uneven size. The error will be
3089 // reported in the final link.
3093 gold_assert(output_offset != invalid_address
3094 || this->relocs_must_follow_section_writes());
3096 // Get the section contents. This does work for the case in which
3097 // we modify the contents of an input section. We need to pass the
3098 // output view under such circumstances.
3099 section_size_type input_view_size = 0;
3100 const unsigned char* input_view =
3101 this->section_contents(index, &input_view_size, false);
3103 relinfo.reloc_shndx = i;
3104 relinfo.data_shndx = index;
3105 arm_target->scan_section_for_stubs(&relinfo, sh_type, prelocs,
3107 output_offset == invalid_address,
3113 // After we've done the relocations, we release the hash tables,
3114 // since we no longer need them.
3115 this->free_input_to_output_maps();
3118 // Count the local symbols. The ARM backend needs to know if a symbol
3119 // is a THUMB function or not. For global symbols, it is easy because
3120 // the Symbol object keeps the ELF symbol type. For local symbol it is
3121 // harder because we cannot access this information. So we override the
3122 // do_count_local_symbol in parent and scan local symbols to mark
3123 // THUMB functions. This is not the most efficient way but I do not want to
3124 // slow down other ports by calling a per symbol targer hook inside
3125 // Sized_relobj<size, big_endian>::do_count_local_symbols.
3127 template<bool big_endian>
3129 Arm_relobj<big_endian>::do_count_local_symbols(
3130 Stringpool_template<char>* pool,
3131 Stringpool_template<char>* dynpool)
3133 // We need to fix-up the values of any local symbols whose type are
3136 // Ask parent to count the local symbols.
3137 Sized_relobj<32, big_endian>::do_count_local_symbols(pool, dynpool);
3138 const unsigned int loccount = this->local_symbol_count();
3142 // Intialize the thumb function bit-vector.
3143 std::vector<bool> empty_vector(loccount, false);
3144 this->local_symbol_is_thumb_function_.swap(empty_vector);
3146 // Read the symbol table section header.
3147 const unsigned int symtab_shndx = this->symtab_shndx();
3148 elfcpp::Shdr<32, big_endian>
3149 symtabshdr(this, this->elf_file()->section_header(symtab_shndx));
3150 gold_assert(symtabshdr.get_sh_type() == elfcpp::SHT_SYMTAB);
3152 // Read the local symbols.
3153 const int sym_size =elfcpp::Elf_sizes<32>::sym_size;
3154 gold_assert(loccount == symtabshdr.get_sh_info());
3155 off_t locsize = loccount * sym_size;
3156 const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
3157 locsize, true, true);
3159 // Loop over the local symbols and mark any local symbols pointing
3160 // to THUMB functions.
3162 // Skip the first dummy symbol.
3164 typename Sized_relobj<32, big_endian>::Local_values* plocal_values =
3165 this->local_values();
3166 for (unsigned int i = 1; i < loccount; ++i, psyms += sym_size)
3168 elfcpp::Sym<32, big_endian> sym(psyms);
3169 elfcpp::STT st_type = sym.get_st_type();
3170 Symbol_value<32>& lv((*plocal_values)[i]);
3171 Arm_address input_value = lv.input_value();
3173 if (st_type == elfcpp::STT_ARM_TFUNC
3174 || (st_type == elfcpp::STT_FUNC && ((input_value & 1) != 0)))
3176 // This is a THUMB function. Mark this and canonicalize the
3177 // symbol value by setting LSB.
3178 this->local_symbol_is_thumb_function_[i] = true;
3179 if ((input_value & 1) == 0)
3180 lv.set_input_value(input_value | 1);
3185 // Relocate sections.
3186 template<bool big_endian>
3188 Arm_relobj<big_endian>::do_relocate_sections(
3189 const General_options& options,
3190 const Symbol_table* symtab,
3191 const Layout* layout,
3192 const unsigned char* pshdrs,
3193 typename Sized_relobj<32, big_endian>::Views* pviews)
3195 // Call parent to relocate sections.
3196 Sized_relobj<32, big_endian>::do_relocate_sections(options, symtab, layout,
3199 // We do not generate stubs if doing a relocatable link.
3200 if (parameters->options().relocatable())
3203 // Relocate stub tables.
3204 unsigned int shnum = this->shnum();
3206 Target_arm<big_endian>* arm_target =
3207 Target_arm<big_endian>::default_target();
3209 Relocate_info<32, big_endian> relinfo;
3210 relinfo.options = &options;
3211 relinfo.symtab = symtab;
3212 relinfo.layout = layout;
3213 relinfo.object = this;
3215 for (unsigned int i = 1; i < shnum; ++i)
3217 Arm_input_section<big_endian>* arm_input_section =
3218 arm_target->find_arm_input_section(this, i);
3220 if (arm_input_section == NULL
3221 || !arm_input_section->is_stub_table_owner()
3222 || arm_input_section->stub_table()->empty())
3225 // We cannot discard a section if it owns a stub table.
3226 Output_section* os = this->output_section(i);
3227 gold_assert(os != NULL);
3229 relinfo.reloc_shndx = elfcpp::SHN_UNDEF;
3230 relinfo.reloc_shdr = NULL;
3231 relinfo.data_shndx = i;
3232 relinfo.data_shdr = pshdrs + i * elfcpp::Elf_sizes<32>::shdr_size;
3234 gold_assert((*pviews)[i].view != NULL);
3236 // We are passed the output section view. Adjust it to cover the
3238 Stub_table<big_endian>* stub_table = arm_input_section->stub_table();
3239 gold_assert((stub_table->address() >= (*pviews)[i].address)
3240 && ((stub_table->address() + stub_table->data_size())
3241 <= (*pviews)[i].address + (*pviews)[i].view_size));
3243 off_t offset = stub_table->address() - (*pviews)[i].address;
3244 unsigned char* view = (*pviews)[i].view + offset;
3245 Arm_address address = stub_table->address();
3246 section_size_type view_size = stub_table->data_size();
3248 stub_table->relocate_stubs(&relinfo, arm_target, os, view, address,
3253 // A class to handle the PLT data.
3255 template<bool big_endian>
3256 class Output_data_plt_arm : public Output_section_data
3259 typedef Output_data_reloc<elfcpp::SHT_REL, true, 32, big_endian>
3262 Output_data_plt_arm(Layout*, Output_data_space*);
3264 // Add an entry to the PLT.
3266 add_entry(Symbol* gsym);
3268 // Return the .rel.plt section data.
3269 const Reloc_section*
3271 { return this->rel_; }
3275 do_adjust_output_section(Output_section* os);
3277 // Write to a map file.
3279 do_print_to_mapfile(Mapfile* mapfile) const
3280 { mapfile->print_output_data(this, _("** PLT")); }
3283 // Template for the first PLT entry.
3284 static const uint32_t first_plt_entry[5];
3286 // Template for subsequent PLT entries.
3287 static const uint32_t plt_entry[3];
3289 // Set the final size.
3291 set_final_data_size()
3293 this->set_data_size(sizeof(first_plt_entry)
3294 + this->count_ * sizeof(plt_entry));
3297 // Write out the PLT data.
3299 do_write(Output_file*);
3301 // The reloc section.
3302 Reloc_section* rel_;
3303 // The .got.plt section.
3304 Output_data_space* got_plt_;
3305 // The number of PLT entries.
3306 unsigned int count_;
3309 // Create the PLT section. The ordinary .got section is an argument,
3310 // since we need to refer to the start. We also create our own .got
3311 // section just for PLT entries.
3313 template<bool big_endian>
3314 Output_data_plt_arm<big_endian>::Output_data_plt_arm(Layout* layout,
3315 Output_data_space* got_plt)
3316 : Output_section_data(4), got_plt_(got_plt), count_(0)
3318 this->rel_ = new Reloc_section(false);
3319 layout->add_output_section_data(".rel.plt", elfcpp::SHT_REL,
3320 elfcpp::SHF_ALLOC, this->rel_);
3323 template<bool big_endian>
3325 Output_data_plt_arm<big_endian>::do_adjust_output_section(Output_section* os)
3330 // Add an entry to the PLT.
3332 template<bool big_endian>
3334 Output_data_plt_arm<big_endian>::add_entry(Symbol* gsym)
3336 gold_assert(!gsym->has_plt_offset());
3338 // Note that when setting the PLT offset we skip the initial
3339 // reserved PLT entry.
3340 gsym->set_plt_offset((this->count_) * sizeof(plt_entry)
3341 + sizeof(first_plt_entry));
3345 section_offset_type got_offset = this->got_plt_->current_data_size();
3347 // Every PLT entry needs a GOT entry which points back to the PLT
3348 // entry (this will be changed by the dynamic linker, normally
3349 // lazily when the function is called).
3350 this->got_plt_->set_current_data_size(got_offset + 4);
3352 // Every PLT entry needs a reloc.
3353 gsym->set_needs_dynsym_entry();
3354 this->rel_->add_global(gsym, elfcpp::R_ARM_JUMP_SLOT, this->got_plt_,
3357 // Note that we don't need to save the symbol. The contents of the
3358 // PLT are independent of which symbols are used. The symbols only
3359 // appear in the relocations.
3363 // FIXME: This is not very flexible. Right now this has only been tested
3364 // on armv5te. If we are to support additional architecture features like
3365 // Thumb-2 or BE8, we need to make this more flexible like GNU ld.
3367 // The first entry in the PLT.
3368 template<bool big_endian>
3369 const uint32_t Output_data_plt_arm<big_endian>::first_plt_entry[5] =
3371 0xe52de004, // str lr, [sp, #-4]!
3372 0xe59fe004, // ldr lr, [pc, #4]
3373 0xe08fe00e, // add lr, pc, lr
3374 0xe5bef008, // ldr pc, [lr, #8]!
3375 0x00000000, // &GOT[0] - .
3378 // Subsequent entries in the PLT.
3380 template<bool big_endian>
3381 const uint32_t Output_data_plt_arm<big_endian>::plt_entry[3] =
3383 0xe28fc600, // add ip, pc, #0xNN00000
3384 0xe28cca00, // add ip, ip, #0xNN000
3385 0xe5bcf000, // ldr pc, [ip, #0xNNN]!
3388 // Write out the PLT. This uses the hand-coded instructions above,
3389 // and adjusts them as needed. This is all specified by the arm ELF
3390 // Processor Supplement.
3392 template<bool big_endian>
3394 Output_data_plt_arm<big_endian>::do_write(Output_file* of)
3396 const off_t offset = this->offset();
3397 const section_size_type oview_size =
3398 convert_to_section_size_type(this->data_size());
3399 unsigned char* const oview = of->get_output_view(offset, oview_size);
3401 const off_t got_file_offset = this->got_plt_->offset();
3402 const section_size_type got_size =
3403 convert_to_section_size_type(this->got_plt_->data_size());
3404 unsigned char* const got_view = of->get_output_view(got_file_offset,
3406 unsigned char* pov = oview;
3408 Arm_address plt_address = this->address();
3409 Arm_address got_address = this->got_plt_->address();
3411 // Write first PLT entry. All but the last word are constants.
3412 const size_t num_first_plt_words = (sizeof(first_plt_entry)
3413 / sizeof(plt_entry[0]));
3414 for (size_t i = 0; i < num_first_plt_words - 1; i++)
3415 elfcpp::Swap<32, big_endian>::writeval(pov + i * 4, first_plt_entry[i]);
3416 // Last word in first PLT entry is &GOT[0] - .
3417 elfcpp::Swap<32, big_endian>::writeval(pov + 16,
3418 got_address - (plt_address + 16));
3419 pov += sizeof(first_plt_entry);
3421 unsigned char* got_pov = got_view;
3423 memset(got_pov, 0, 12);
3426 const int rel_size = elfcpp::Elf_sizes<32>::rel_size;
3427 unsigned int plt_offset = sizeof(first_plt_entry);
3428 unsigned int plt_rel_offset = 0;
3429 unsigned int got_offset = 12;
3430 const unsigned int count = this->count_;
3431 for (unsigned int i = 0;
3434 pov += sizeof(plt_entry),
3436 plt_offset += sizeof(plt_entry),
3437 plt_rel_offset += rel_size,
3440 // Set and adjust the PLT entry itself.
3441 int32_t offset = ((got_address + got_offset)
3442 - (plt_address + plt_offset + 8));
3444 gold_assert(offset >= 0 && offset < 0x0fffffff);
3445 uint32_t plt_insn0 = plt_entry[0] | ((offset >> 20) & 0xff);
3446 elfcpp::Swap<32, big_endian>::writeval(pov, plt_insn0);
3447 uint32_t plt_insn1 = plt_entry[1] | ((offset >> 12) & 0xff);
3448 elfcpp::Swap<32, big_endian>::writeval(pov + 4, plt_insn1);
3449 uint32_t plt_insn2 = plt_entry[2] | (offset & 0xfff);
3450 elfcpp::Swap<32, big_endian>::writeval(pov + 8, plt_insn2);
3452 // Set the entry in the GOT.
3453 elfcpp::Swap<32, big_endian>::writeval(got_pov, plt_address);
3456 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
3457 gold_assert(static_cast<section_size_type>(got_pov - got_view) == got_size);
3459 of->write_output_view(offset, oview_size, oview);
3460 of->write_output_view(got_file_offset, got_size, got_view);
3463 // Create a PLT entry for a global symbol.
3465 template<bool big_endian>
3467 Target_arm<big_endian>::make_plt_entry(Symbol_table* symtab, Layout* layout,
3470 if (gsym->has_plt_offset())
3473 if (this->plt_ == NULL)
3475 // Create the GOT sections first.
3476 this->got_section(symtab, layout);
3478 this->plt_ = new Output_data_plt_arm<big_endian>(layout, this->got_plt_);
3479 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
3481 | elfcpp::SHF_EXECINSTR),
3484 this->plt_->add_entry(gsym);
3487 // Report an unsupported relocation against a local symbol.
3489 template<bool big_endian>
3491 Target_arm<big_endian>::Scan::unsupported_reloc_local(
3492 Sized_relobj<32, big_endian>* object,
3493 unsigned int r_type)
3495 gold_error(_("%s: unsupported reloc %u against local symbol"),
3496 object->name().c_str(), r_type);
3499 // We are about to emit a dynamic relocation of type R_TYPE. If the
3500 // dynamic linker does not support it, issue an error. The GNU linker
3501 // only issues a non-PIC error for an allocated read-only section.
3502 // Here we know the section is allocated, but we don't know that it is
3503 // read-only. But we check for all the relocation types which the
3504 // glibc dynamic linker supports, so it seems appropriate to issue an
3505 // error even if the section is not read-only.
3507 template<bool big_endian>
3509 Target_arm<big_endian>::Scan::check_non_pic(Relobj* object,
3510 unsigned int r_type)
3514 // These are the relocation types supported by glibc for ARM.
3515 case elfcpp::R_ARM_RELATIVE:
3516 case elfcpp::R_ARM_COPY:
3517 case elfcpp::R_ARM_GLOB_DAT:
3518 case elfcpp::R_ARM_JUMP_SLOT:
3519 case elfcpp::R_ARM_ABS32:
3520 case elfcpp::R_ARM_ABS32_NOI:
3521 case elfcpp::R_ARM_PC24:
3522 // FIXME: The following 3 types are not supported by Android's dynamic
3524 case elfcpp::R_ARM_TLS_DTPMOD32:
3525 case elfcpp::R_ARM_TLS_DTPOFF32:
3526 case elfcpp::R_ARM_TLS_TPOFF32:
3530 // This prevents us from issuing more than one error per reloc
3531 // section. But we can still wind up issuing more than one
3532 // error per object file.
3533 if (this->issued_non_pic_error_)
3535 object->error(_("requires unsupported dynamic reloc; "
3536 "recompile with -fPIC"));
3537 this->issued_non_pic_error_ = true;
3540 case elfcpp::R_ARM_NONE:
3545 // Scan a relocation for a local symbol.
3546 // FIXME: This only handles a subset of relocation types used by Android
3547 // on ARM v5te devices.
3549 template<bool big_endian>
3551 Target_arm<big_endian>::Scan::local(Symbol_table* symtab,
3554 Sized_relobj<32, big_endian>* object,
3555 unsigned int data_shndx,
3556 Output_section* output_section,
3557 const elfcpp::Rel<32, big_endian>& reloc,
3558 unsigned int r_type,
3559 const elfcpp::Sym<32, big_endian>&)
3561 r_type = get_real_reloc_type(r_type);
3564 case elfcpp::R_ARM_NONE:
3567 case elfcpp::R_ARM_ABS32:
3568 case elfcpp::R_ARM_ABS32_NOI:
3569 // If building a shared library (or a position-independent
3570 // executable), we need to create a dynamic relocation for
3571 // this location. The relocation applied at link time will
3572 // apply the link-time value, so we flag the location with
3573 // an R_ARM_RELATIVE relocation so the dynamic loader can
3574 // relocate it easily.
3575 if (parameters->options().output_is_position_independent())
3577 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
3578 unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
3579 // If we are to add more other reloc types than R_ARM_ABS32,
3580 // we need to add check_non_pic(object, r_type) here.
3581 rel_dyn->add_local_relative(object, r_sym, elfcpp::R_ARM_RELATIVE,
3582 output_section, data_shndx,
3583 reloc.get_r_offset());
3587 case elfcpp::R_ARM_REL32:
3588 case elfcpp::R_ARM_THM_CALL:
3589 case elfcpp::R_ARM_CALL:
3590 case elfcpp::R_ARM_PREL31:
3591 case elfcpp::R_ARM_JUMP24:
3592 case elfcpp::R_ARM_PLT32:
3593 case elfcpp::R_ARM_THM_ABS5:
3594 case elfcpp::R_ARM_ABS8:
3595 case elfcpp::R_ARM_ABS12:
3596 case elfcpp::R_ARM_ABS16:
3597 case elfcpp::R_ARM_BASE_ABS:
3598 case elfcpp::R_ARM_MOVW_ABS_NC:
3599 case elfcpp::R_ARM_MOVT_ABS:
3600 case elfcpp::R_ARM_THM_MOVW_ABS_NC:
3601 case elfcpp::R_ARM_THM_MOVT_ABS:
3602 case elfcpp::R_ARM_MOVW_PREL_NC:
3603 case elfcpp::R_ARM_MOVT_PREL:
3604 case elfcpp::R_ARM_THM_MOVW_PREL_NC:
3605 case elfcpp::R_ARM_THM_MOVT_PREL:
3608 case elfcpp::R_ARM_GOTOFF32:
3609 // We need a GOT section:
3610 target->got_section(symtab, layout);
3613 case elfcpp::R_ARM_BASE_PREL:
3614 // FIXME: What about this?
3617 case elfcpp::R_ARM_GOT_BREL:
3618 case elfcpp::R_ARM_GOT_PREL:
3620 // The symbol requires a GOT entry.
3621 Output_data_got<32, big_endian>* got =
3622 target->got_section(symtab, layout);
3623 unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
3624 if (got->add_local(object, r_sym, GOT_TYPE_STANDARD))
3626 // If we are generating a shared object, we need to add a
3627 // dynamic RELATIVE relocation for this symbol's GOT entry.
3628 if (parameters->options().output_is_position_independent())
3630 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
3631 unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
3632 rel_dyn->add_local_relative(
3633 object, r_sym, elfcpp::R_ARM_RELATIVE, got,
3634 object->local_got_offset(r_sym, GOT_TYPE_STANDARD));
3640 case elfcpp::R_ARM_TARGET1:
3641 // This should have been mapped to another type already.
3643 case elfcpp::R_ARM_COPY:
3644 case elfcpp::R_ARM_GLOB_DAT:
3645 case elfcpp::R_ARM_JUMP_SLOT:
3646 case elfcpp::R_ARM_RELATIVE:
3647 // These are relocations which should only be seen by the
3648 // dynamic linker, and should never be seen here.
3649 gold_error(_("%s: unexpected reloc %u in object file"),
3650 object->name().c_str(), r_type);
3654 unsupported_reloc_local(object, r_type);
3659 // Report an unsupported relocation against a global symbol.
3661 template<bool big_endian>
3663 Target_arm<big_endian>::Scan::unsupported_reloc_global(
3664 Sized_relobj<32, big_endian>* object,
3665 unsigned int r_type,
3668 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
3669 object->name().c_str(), r_type, gsym->demangled_name().c_str());
3672 // Scan a relocation for a global symbol.
3673 // FIXME: This only handles a subset of relocation types used by Android
3674 // on ARM v5te devices.
3676 template<bool big_endian>
3678 Target_arm<big_endian>::Scan::global(Symbol_table* symtab,
3681 Sized_relobj<32, big_endian>* object,
3682 unsigned int data_shndx,
3683 Output_section* output_section,
3684 const elfcpp::Rel<32, big_endian>& reloc,
3685 unsigned int r_type,
3688 r_type = get_real_reloc_type(r_type);
3691 case elfcpp::R_ARM_NONE:
3694 case elfcpp::R_ARM_ABS32:
3695 case elfcpp::R_ARM_ABS32_NOI:
3697 // Make a dynamic relocation if necessary.
3698 if (gsym->needs_dynamic_reloc(Symbol::ABSOLUTE_REF))
3700 if (target->may_need_copy_reloc(gsym))
3702 target->copy_reloc(symtab, layout, object,
3703 data_shndx, output_section, gsym, reloc);
3705 else if (gsym->can_use_relative_reloc(false))
3707 // If we are to add more other reloc types than R_ARM_ABS32,
3708 // we need to add check_non_pic(object, r_type) here.
3709 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
3710 rel_dyn->add_global_relative(gsym, elfcpp::R_ARM_RELATIVE,
3711 output_section, object,
3712 data_shndx, reloc.get_r_offset());
3716 // If we are to add more other reloc types than R_ARM_ABS32,
3717 // we need to add check_non_pic(object, r_type) here.
3718 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
3719 rel_dyn->add_global(gsym, r_type, output_section, object,
3720 data_shndx, reloc.get_r_offset());
3726 case elfcpp::R_ARM_MOVW_ABS_NC:
3727 case elfcpp::R_ARM_MOVT_ABS:
3728 case elfcpp::R_ARM_THM_MOVW_ABS_NC:
3729 case elfcpp::R_ARM_THM_MOVT_ABS:
3730 case elfcpp::R_ARM_MOVW_PREL_NC:
3731 case elfcpp::R_ARM_MOVT_PREL:
3732 case elfcpp::R_ARM_THM_MOVW_PREL_NC:
3733 case elfcpp::R_ARM_THM_MOVT_PREL:
3736 case elfcpp::R_ARM_THM_ABS5:
3737 case elfcpp::R_ARM_ABS8:
3738 case elfcpp::R_ARM_ABS12:
3739 case elfcpp::R_ARM_ABS16:
3740 case elfcpp::R_ARM_BASE_ABS:
3742 // No dynamic relocs of this kinds.
3743 // Report the error in case of PIC.
3744 int flags = Symbol::NON_PIC_REF;
3745 if (gsym->type() == elfcpp::STT_FUNC
3746 || gsym->type() == elfcpp::STT_ARM_TFUNC)
3747 flags |= Symbol::FUNCTION_CALL;
3748 if (gsym->needs_dynamic_reloc(flags))
3749 check_non_pic(object, r_type);
3753 case elfcpp::R_ARM_REL32:
3754 case elfcpp::R_ARM_PREL31:
3756 // Make a dynamic relocation if necessary.
3757 int flags = Symbol::NON_PIC_REF;
3758 if (gsym->needs_dynamic_reloc(flags))
3760 if (target->may_need_copy_reloc(gsym))
3762 target->copy_reloc(symtab, layout, object,
3763 data_shndx, output_section, gsym, reloc);
3767 check_non_pic(object, r_type);
3768 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
3769 rel_dyn->add_global(gsym, r_type, output_section, object,
3770 data_shndx, reloc.get_r_offset());
3776 case elfcpp::R_ARM_JUMP24:
3777 case elfcpp::R_ARM_THM_CALL:
3778 case elfcpp::R_ARM_CALL:
3780 if (Target_arm<big_endian>::Scan::symbol_needs_plt_entry(gsym))
3781 target->make_plt_entry(symtab, layout, gsym);
3782 // Make a dynamic relocation if necessary.
3783 int flags = Symbol::NON_PIC_REF;
3784 if (gsym->type() == elfcpp::STT_FUNC
3785 || gsym->type() == elfcpp::STT_ARM_TFUNC)
3786 flags |= Symbol::FUNCTION_CALL;
3787 if (gsym->needs_dynamic_reloc(flags))
3789 if (target->may_need_copy_reloc(gsym))
3791 target->copy_reloc(symtab, layout, object,
3792 data_shndx, output_section, gsym,
3797 check_non_pic(object, r_type);
3798 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
3799 rel_dyn->add_global(gsym, r_type, output_section, object,
3800 data_shndx, reloc.get_r_offset());
3806 case elfcpp::R_ARM_PLT32:
3807 // If the symbol is fully resolved, this is just a relative
3808 // local reloc. Otherwise we need a PLT entry.
3809 if (gsym->final_value_is_known())
3811 // If building a shared library, we can also skip the PLT entry
3812 // if the symbol is defined in the output file and is protected
3814 if (gsym->is_defined()
3815 && !gsym->is_from_dynobj()
3816 && !gsym->is_preemptible())
3818 target->make_plt_entry(symtab, layout, gsym);
3821 case elfcpp::R_ARM_GOTOFF32:
3822 // We need a GOT section.
3823 target->got_section(symtab, layout);
3826 case elfcpp::R_ARM_BASE_PREL:
3827 // FIXME: What about this?
3830 case elfcpp::R_ARM_GOT_BREL:
3831 case elfcpp::R_ARM_GOT_PREL:
3833 // The symbol requires a GOT entry.
3834 Output_data_got<32, big_endian>* got =
3835 target->got_section(symtab, layout);
3836 if (gsym->final_value_is_known())
3837 got->add_global(gsym, GOT_TYPE_STANDARD);
3840 // If this symbol is not fully resolved, we need to add a
3841 // GOT entry with a dynamic relocation.
3842 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
3843 if (gsym->is_from_dynobj()
3844 || gsym->is_undefined()
3845 || gsym->is_preemptible())
3846 got->add_global_with_rel(gsym, GOT_TYPE_STANDARD,
3847 rel_dyn, elfcpp::R_ARM_GLOB_DAT);
3850 if (got->add_global(gsym, GOT_TYPE_STANDARD))
3851 rel_dyn->add_global_relative(
3852 gsym, elfcpp::R_ARM_RELATIVE, got,
3853 gsym->got_offset(GOT_TYPE_STANDARD));
3859 case elfcpp::R_ARM_TARGET1:
3860 // This should have been mapped to another type already.
3862 case elfcpp::R_ARM_COPY:
3863 case elfcpp::R_ARM_GLOB_DAT:
3864 case elfcpp::R_ARM_JUMP_SLOT:
3865 case elfcpp::R_ARM_RELATIVE:
3866 // These are relocations which should only be seen by the
3867 // dynamic linker, and should never be seen here.
3868 gold_error(_("%s: unexpected reloc %u in object file"),
3869 object->name().c_str(), r_type);
3873 unsupported_reloc_global(object, r_type, gsym);
3878 // Process relocations for gc.
3880 template<bool big_endian>
3882 Target_arm<big_endian>::gc_process_relocs(Symbol_table* symtab,
3884 Sized_relobj<32, big_endian>* object,
3885 unsigned int data_shndx,
3887 const unsigned char* prelocs,
3889 Output_section* output_section,
3890 bool needs_special_offset_handling,
3891 size_t local_symbol_count,
3892 const unsigned char* plocal_symbols)
3894 typedef Target_arm<big_endian> Arm;
3895 typedef typename Target_arm<big_endian>::Scan Scan;
3897 gold::gc_process_relocs<32, big_endian, Arm, elfcpp::SHT_REL, Scan>(
3906 needs_special_offset_handling,
3911 // Scan relocations for a section.
3913 template<bool big_endian>
3915 Target_arm<big_endian>::scan_relocs(Symbol_table* symtab,
3917 Sized_relobj<32, big_endian>* object,
3918 unsigned int data_shndx,
3919 unsigned int sh_type,
3920 const unsigned char* prelocs,
3922 Output_section* output_section,
3923 bool needs_special_offset_handling,
3924 size_t local_symbol_count,
3925 const unsigned char* plocal_symbols)
3927 typedef typename Target_arm<big_endian>::Scan Scan;
3928 if (sh_type == elfcpp::SHT_RELA)
3930 gold_error(_("%s: unsupported RELA reloc section"),
3931 object->name().c_str());
3935 gold::scan_relocs<32, big_endian, Target_arm, elfcpp::SHT_REL, Scan>(
3944 needs_special_offset_handling,
3949 // Finalize the sections.
3951 template<bool big_endian>
3953 Target_arm<big_endian>::do_finalize_sections(Layout* layout)
3955 // Fill in some more dynamic tags.
3956 Output_data_dynamic* const odyn = layout->dynamic_data();
3959 if (this->got_plt_ != NULL)
3960 odyn->add_section_address(elfcpp::DT_PLTGOT, this->got_plt_);
3962 if (this->plt_ != NULL)
3964 const Output_data* od = this->plt_->rel_plt();
3965 odyn->add_section_size(elfcpp::DT_PLTRELSZ, od);
3966 odyn->add_section_address(elfcpp::DT_JMPREL, od);
3967 odyn->add_constant(elfcpp::DT_PLTREL, elfcpp::DT_REL);
3970 if (this->rel_dyn_ != NULL)
3972 const Output_data* od = this->rel_dyn_;
3973 odyn->add_section_address(elfcpp::DT_REL, od);
3974 odyn->add_section_size(elfcpp::DT_RELSZ, od);
3975 odyn->add_constant(elfcpp::DT_RELENT,
3976 elfcpp::Elf_sizes<32>::rel_size);
3979 if (!parameters->options().shared())
3981 // The value of the DT_DEBUG tag is filled in by the dynamic
3982 // linker at run time, and used by the debugger.
3983 odyn->add_constant(elfcpp::DT_DEBUG, 0);
3987 // Emit any relocs we saved in an attempt to avoid generating COPY
3989 if (this->copy_relocs_.any_saved_relocs())
3990 this->copy_relocs_.emit(this->rel_dyn_section(layout));
3992 // For the ARM target, we need to add a PT_ARM_EXIDX segment for
3993 // the .ARM.exidx section.
3994 if (!layout->script_options()->saw_phdrs_clause()
3995 && !parameters->options().relocatable())
3997 Output_section* exidx_section =
3998 layout->find_output_section(".ARM.exidx");
4000 if (exidx_section != NULL
4001 && exidx_section->type() == elfcpp::SHT_ARM_EXIDX)
4003 gold_assert(layout->find_output_segment(elfcpp::PT_ARM_EXIDX, 0, 0)
4005 Output_segment* exidx_segment =
4006 layout->make_output_segment(elfcpp::PT_ARM_EXIDX, elfcpp::PF_R);
4007 exidx_segment->add_output_section(exidx_section, elfcpp::PF_R);
4012 // Return whether a direct absolute static relocation needs to be applied.
4013 // In cases where Scan::local() or Scan::global() has created
4014 // a dynamic relocation other than R_ARM_RELATIVE, the addend
4015 // of the relocation is carried in the data, and we must not
4016 // apply the static relocation.
4018 template<bool big_endian>
4020 Target_arm<big_endian>::Relocate::should_apply_static_reloc(
4021 const Sized_symbol<32>* gsym,
4024 Output_section* output_section)
4026 // If the output section is not allocated, then we didn't call
4027 // scan_relocs, we didn't create a dynamic reloc, and we must apply
4029 if ((output_section->flags() & elfcpp::SHF_ALLOC) == 0)
4032 // For local symbols, we will have created a non-RELATIVE dynamic
4033 // relocation only if (a) the output is position independent,
4034 // (b) the relocation is absolute (not pc- or segment-relative), and
4035 // (c) the relocation is not 32 bits wide.
4037 return !(parameters->options().output_is_position_independent()
4038 && (ref_flags & Symbol::ABSOLUTE_REF)
4041 // For global symbols, we use the same helper routines used in the
4042 // scan pass. If we did not create a dynamic relocation, or if we
4043 // created a RELATIVE dynamic relocation, we should apply the static
4045 bool has_dyn = gsym->needs_dynamic_reloc(ref_flags);
4046 bool is_rel = (ref_flags & Symbol::ABSOLUTE_REF)
4047 && gsym->can_use_relative_reloc(ref_flags
4048 & Symbol::FUNCTION_CALL);
4049 return !has_dyn || is_rel;
4052 // Perform a relocation.
4054 template<bool big_endian>
4056 Target_arm<big_endian>::Relocate::relocate(
4057 const Relocate_info<32, big_endian>* relinfo,
4059 Output_section *output_section,
4061 const elfcpp::Rel<32, big_endian>& rel,
4062 unsigned int r_type,
4063 const Sized_symbol<32>* gsym,
4064 const Symbol_value<32>* psymval,
4065 unsigned char* view,
4066 Arm_address address,
4067 section_size_type /* view_size */ )
4069 typedef Arm_relocate_functions<big_endian> Arm_relocate_functions;
4071 r_type = get_real_reloc_type(r_type);
4073 // If this the symbol may be a Thumb function, set thumb bit to 1.
4074 bool has_thumb_bit = ((gsym != NULL)
4075 && (gsym->type() == elfcpp::STT_FUNC
4076 || gsym->type() == elfcpp::STT_ARM_TFUNC));
4078 // Pick the value to use for symbols defined in shared objects.
4079 Symbol_value<32> symval;
4081 && gsym->use_plt_offset(reloc_is_non_pic(r_type)))
4083 symval.set_output_value(target->plt_section()->address()
4084 + gsym->plt_offset());
4089 const Sized_relobj<32, big_endian>* object = relinfo->object;
4091 // Get the GOT offset if needed.
4092 // The GOT pointer points to the end of the GOT section.
4093 // We need to subtract the size of the GOT section to get
4094 // the actual offset to use in the relocation.
4095 bool have_got_offset = false;
4096 unsigned int got_offset = 0;
4099 case elfcpp::R_ARM_GOT_BREL:
4100 case elfcpp::R_ARM_GOT_PREL:
4103 gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
4104 got_offset = (gsym->got_offset(GOT_TYPE_STANDARD)
4105 - target->got_size());
4109 unsigned int r_sym = elfcpp::elf_r_sym<32>(rel.get_r_info());
4110 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
4111 got_offset = (object->local_got_offset(r_sym, GOT_TYPE_STANDARD)
4112 - target->got_size());
4114 have_got_offset = true;
4121 typename Arm_relocate_functions::Status reloc_status =
4122 Arm_relocate_functions::STATUS_OKAY;
4125 case elfcpp::R_ARM_NONE:
4128 case elfcpp::R_ARM_ABS8:
4129 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
4131 reloc_status = Arm_relocate_functions::abs8(view, object, psymval);
4134 case elfcpp::R_ARM_ABS12:
4135 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
4137 reloc_status = Arm_relocate_functions::abs12(view, object, psymval);
4140 case elfcpp::R_ARM_ABS16:
4141 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
4143 reloc_status = Arm_relocate_functions::abs16(view, object, psymval);
4146 case elfcpp::R_ARM_ABS32:
4147 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, true,
4149 reloc_status = Arm_relocate_functions::abs32(view, object, psymval,
4153 case elfcpp::R_ARM_ABS32_NOI:
4154 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, true,
4156 // No thumb bit for this relocation: (S + A)
4157 reloc_status = Arm_relocate_functions::abs32(view, object, psymval,
4161 case elfcpp::R_ARM_MOVW_ABS_NC:
4162 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, true,
4164 reloc_status = Arm_relocate_functions::movw_abs_nc(view, object,
4168 gold_error(_("relocation R_ARM_MOVW_ABS_NC cannot be used when making"
4169 "a shared object; recompile with -fPIC"));
4172 case elfcpp::R_ARM_MOVT_ABS:
4173 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, true,
4175 reloc_status = Arm_relocate_functions::movt_abs(view, object, psymval);
4177 gold_error(_("relocation R_ARM_MOVT_ABS cannot be used when making"
4178 "a shared object; recompile with -fPIC"));
4181 case elfcpp::R_ARM_THM_MOVW_ABS_NC:
4182 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, true,
4184 reloc_status = Arm_relocate_functions::thm_movw_abs_nc(view, object,
4188 gold_error(_("relocation R_ARM_THM_MOVW_ABS_NC cannot be used when"
4189 "making a shared object; recompile with -fPIC"));
4192 case elfcpp::R_ARM_THM_MOVT_ABS:
4193 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, true,
4195 reloc_status = Arm_relocate_functions::thm_movt_abs(view, object,
4198 gold_error(_("relocation R_ARM_THM_MOVT_ABS cannot be used when"
4199 "making a shared object; recompile with -fPIC"));
4202 case elfcpp::R_ARM_MOVW_PREL_NC:
4203 reloc_status = Arm_relocate_functions::movw_prel_nc(view, object,
4208 case elfcpp::R_ARM_MOVT_PREL:
4209 reloc_status = Arm_relocate_functions::movt_prel(view, object,
4213 case elfcpp::R_ARM_THM_MOVW_PREL_NC:
4214 reloc_status = Arm_relocate_functions::thm_movw_prel_nc(view, object,
4219 case elfcpp::R_ARM_THM_MOVT_PREL:
4220 reloc_status = Arm_relocate_functions::thm_movt_prel(view, object,
4224 case elfcpp::R_ARM_REL32:
4225 reloc_status = Arm_relocate_functions::rel32(view, object, psymval,
4226 address, has_thumb_bit);
4229 case elfcpp::R_ARM_THM_ABS5:
4230 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
4232 reloc_status = Arm_relocate_functions::thm_abs5(view, object, psymval);
4235 case elfcpp::R_ARM_THM_CALL:
4236 reloc_status = Arm_relocate_functions::thm_call(view, object, psymval,
4237 address, has_thumb_bit);
4240 case elfcpp::R_ARM_GOTOFF32:
4242 Arm_address got_origin;
4243 got_origin = target->got_plt_section()->address();
4244 reloc_status = Arm_relocate_functions::rel32(view, object, psymval,
4245 got_origin, has_thumb_bit);
4249 case elfcpp::R_ARM_BASE_PREL:
4252 // Get the addressing origin of the output segment defining the
4253 // symbol gsym (AAELF 4.6.1.2 Relocation types)
4254 gold_assert(gsym != NULL);
4255 if (gsym->source() == Symbol::IN_OUTPUT_SEGMENT)
4256 origin = gsym->output_segment()->vaddr();
4257 else if (gsym->source () == Symbol::IN_OUTPUT_DATA)
4258 origin = gsym->output_data()->address();
4261 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
4262 _("cannot find origin of R_ARM_BASE_PREL"));
4265 reloc_status = Arm_relocate_functions::base_prel(view, origin, address);
4269 case elfcpp::R_ARM_BASE_ABS:
4271 if (!should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, true,
4276 // Get the addressing origin of the output segment defining
4277 // the symbol gsym (AAELF 4.6.1.2 Relocation types).
4279 // R_ARM_BASE_ABS with the NULL symbol will give the
4280 // absolute address of the GOT origin (GOT_ORG) (see ARM IHI
4281 // 0044C (AAELF): 4.6.1.8 Proxy generating relocations).
4282 origin = target->got_plt_section()->address();
4283 else if (gsym->source() == Symbol::IN_OUTPUT_SEGMENT)
4284 origin = gsym->output_segment()->vaddr();
4285 else if (gsym->source () == Symbol::IN_OUTPUT_DATA)
4286 origin = gsym->output_data()->address();
4289 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
4290 _("cannot find origin of R_ARM_BASE_ABS"));
4294 reloc_status = Arm_relocate_functions::base_abs(view, origin);
4298 case elfcpp::R_ARM_GOT_BREL:
4299 gold_assert(have_got_offset);
4300 reloc_status = Arm_relocate_functions::got_brel(view, got_offset);
4303 case elfcpp::R_ARM_GOT_PREL:
4304 gold_assert(have_got_offset);
4305 // Get the address origin for GOT PLT, which is allocated right
4306 // after the GOT section, to calculate an absolute address of
4307 // the symbol GOT entry (got_origin + got_offset).
4308 Arm_address got_origin;
4309 got_origin = target->got_plt_section()->address();
4310 reloc_status = Arm_relocate_functions::got_prel(view,
4311 got_origin + got_offset,
4315 case elfcpp::R_ARM_PLT32:
4316 gold_assert(gsym == NULL
4317 || gsym->has_plt_offset()
4318 || gsym->final_value_is_known()
4319 || (gsym->is_defined()
4320 && !gsym->is_from_dynobj()
4321 && !gsym->is_preemptible()));
4322 reloc_status = Arm_relocate_functions::plt32(view, object, psymval,
4323 address, has_thumb_bit);
4326 case elfcpp::R_ARM_CALL:
4327 reloc_status = Arm_relocate_functions::call(view, object, psymval,
4328 address, has_thumb_bit);
4331 case elfcpp::R_ARM_JUMP24:
4332 reloc_status = Arm_relocate_functions::jump24(view, object, psymval,
4333 address, has_thumb_bit);
4336 case elfcpp::R_ARM_PREL31:
4337 reloc_status = Arm_relocate_functions::prel31(view, object, psymval,
4338 address, has_thumb_bit);
4341 case elfcpp::R_ARM_TARGET1:
4342 // This should have been mapped to another type already.
4344 case elfcpp::R_ARM_COPY:
4345 case elfcpp::R_ARM_GLOB_DAT:
4346 case elfcpp::R_ARM_JUMP_SLOT:
4347 case elfcpp::R_ARM_RELATIVE:
4348 // These are relocations which should only be seen by the
4349 // dynamic linker, and should never be seen here.
4350 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
4351 _("unexpected reloc %u in object file"),
4356 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
4357 _("unsupported reloc %u"),
4362 // Report any errors.
4363 switch (reloc_status)
4365 case Arm_relocate_functions::STATUS_OKAY:
4367 case Arm_relocate_functions::STATUS_OVERFLOW:
4368 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
4369 _("relocation overflow in relocation %u"),
4372 case Arm_relocate_functions::STATUS_BAD_RELOC:
4373 gold_error_at_location(
4377 _("unexpected opcode while processing relocation %u"),
4387 // Relocate section data.
4389 template<bool big_endian>
4391 Target_arm<big_endian>::relocate_section(
4392 const Relocate_info<32, big_endian>* relinfo,
4393 unsigned int sh_type,
4394 const unsigned char* prelocs,
4396 Output_section* output_section,
4397 bool needs_special_offset_handling,
4398 unsigned char* view,
4399 Arm_address address,
4400 section_size_type view_size,
4401 const Reloc_symbol_changes* reloc_symbol_changes)
4403 typedef typename Target_arm<big_endian>::Relocate Arm_relocate;
4404 gold_assert(sh_type == elfcpp::SHT_REL);
4406 gold::relocate_section<32, big_endian, Target_arm, elfcpp::SHT_REL,
4413 needs_special_offset_handling,
4417 reloc_symbol_changes);
4420 // Return the size of a relocation while scanning during a relocatable
4423 template<bool big_endian>
4425 Target_arm<big_endian>::Relocatable_size_for_reloc::get_size_for_reloc(
4426 unsigned int r_type,
4429 r_type = get_real_reloc_type(r_type);
4432 case elfcpp::R_ARM_NONE:
4435 case elfcpp::R_ARM_ABS8:
4438 case elfcpp::R_ARM_ABS16:
4439 case elfcpp::R_ARM_THM_ABS5:
4442 case elfcpp::R_ARM_ABS32:
4443 case elfcpp::R_ARM_ABS32_NOI:
4444 case elfcpp::R_ARM_ABS12:
4445 case elfcpp::R_ARM_BASE_ABS:
4446 case elfcpp::R_ARM_REL32:
4447 case elfcpp::R_ARM_THM_CALL:
4448 case elfcpp::R_ARM_GOTOFF32:
4449 case elfcpp::R_ARM_BASE_PREL:
4450 case elfcpp::R_ARM_GOT_BREL:
4451 case elfcpp::R_ARM_GOT_PREL:
4452 case elfcpp::R_ARM_PLT32:
4453 case elfcpp::R_ARM_CALL:
4454 case elfcpp::R_ARM_JUMP24:
4455 case elfcpp::R_ARM_PREL31:
4456 case elfcpp::R_ARM_MOVW_ABS_NC:
4457 case elfcpp::R_ARM_MOVT_ABS:
4458 case elfcpp::R_ARM_THM_MOVW_ABS_NC:
4459 case elfcpp::R_ARM_THM_MOVT_ABS:
4460 case elfcpp::R_ARM_MOVW_PREL_NC:
4461 case elfcpp::R_ARM_MOVT_PREL:
4462 case elfcpp::R_ARM_THM_MOVW_PREL_NC:
4463 case elfcpp::R_ARM_THM_MOVT_PREL:
4466 case elfcpp::R_ARM_TARGET1:
4467 // This should have been mapped to another type already.
4469 case elfcpp::R_ARM_COPY:
4470 case elfcpp::R_ARM_GLOB_DAT:
4471 case elfcpp::R_ARM_JUMP_SLOT:
4472 case elfcpp::R_ARM_RELATIVE:
4473 // These are relocations which should only be seen by the
4474 // dynamic linker, and should never be seen here.
4475 gold_error(_("%s: unexpected reloc %u in object file"),
4476 object->name().c_str(), r_type);
4480 object->error(_("unsupported reloc %u in object file"), r_type);
4485 // Scan the relocs during a relocatable link.
4487 template<bool big_endian>
4489 Target_arm<big_endian>::scan_relocatable_relocs(
4490 Symbol_table* symtab,
4492 Sized_relobj<32, big_endian>* object,
4493 unsigned int data_shndx,
4494 unsigned int sh_type,
4495 const unsigned char* prelocs,
4497 Output_section* output_section,
4498 bool needs_special_offset_handling,
4499 size_t local_symbol_count,
4500 const unsigned char* plocal_symbols,
4501 Relocatable_relocs* rr)
4503 gold_assert(sh_type == elfcpp::SHT_REL);
4505 typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_REL,
4506 Relocatable_size_for_reloc> Scan_relocatable_relocs;
4508 gold::scan_relocatable_relocs<32, big_endian, elfcpp::SHT_REL,
4509 Scan_relocatable_relocs>(
4517 needs_special_offset_handling,
4523 // Relocate a section during a relocatable link.
4525 template<bool big_endian>
4527 Target_arm<big_endian>::relocate_for_relocatable(
4528 const Relocate_info<32, big_endian>* relinfo,
4529 unsigned int sh_type,
4530 const unsigned char* prelocs,
4532 Output_section* output_section,
4533 off_t offset_in_output_section,
4534 const Relocatable_relocs* rr,
4535 unsigned char* view,
4536 Arm_address view_address,
4537 section_size_type view_size,
4538 unsigned char* reloc_view,
4539 section_size_type reloc_view_size)
4541 gold_assert(sh_type == elfcpp::SHT_REL);
4543 gold::relocate_for_relocatable<32, big_endian, elfcpp::SHT_REL>(
4548 offset_in_output_section,
4557 // Return the value to use for a dynamic symbol which requires special
4558 // treatment. This is how we support equality comparisons of function
4559 // pointers across shared library boundaries, as described in the
4560 // processor specific ABI supplement.
4562 template<bool big_endian>
4564 Target_arm<big_endian>::do_dynsym_value(const Symbol* gsym) const
4566 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
4567 return this->plt_section()->address() + gsym->plt_offset();
4570 // Map platform-specific relocs to real relocs
4572 template<bool big_endian>
4574 Target_arm<big_endian>::get_real_reloc_type (unsigned int r_type)
4578 case elfcpp::R_ARM_TARGET1:
4579 // This is either R_ARM_ABS32 or R_ARM_REL32;
4580 return elfcpp::R_ARM_ABS32;
4582 case elfcpp::R_ARM_TARGET2:
4583 // This can be any reloc type but ususally is R_ARM_GOT_PREL
4584 return elfcpp::R_ARM_GOT_PREL;
4591 // The selector for arm object files.
4593 template<bool big_endian>
4594 class Target_selector_arm : public Target_selector
4597 Target_selector_arm()
4598 : Target_selector(elfcpp::EM_ARM, 32, big_endian,
4599 (big_endian ? "elf32-bigarm" : "elf32-littlearm"))
4603 do_instantiate_target()
4604 { return new Target_arm<big_endian>(); }
4607 Target_selector_arm<false> target_selector_arm;
4608 Target_selector_arm<true> target_selector_armbe;
4610 } // End anonymous namespace.