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>.
7 // This file is part of gold.
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 // MA 02110-1301, USA.
32 #include "parameters.h"
39 #include "copy-relocs.h"
41 #include "target-reloc.h"
42 #include "target-select.h"
51 template<bool big_endian
>
52 class Output_data_plt_arm
;
54 // The arm target class.
56 // This is a very simple port of gold for ARM-EABI. It is intended for
57 // supporting Android only for the time being. Only these relocation types
80 // R_ARM_THM_MOVW_ABS_NC
84 // R_ARM_THM_MOVW_PREL_NC
85 // R_ARM_THM_MOVT_PREL
88 // - Generate various branch stubs.
89 // - Support interworking.
90 // - Define section symbols __exidx_start and __exidx_stop.
91 // - Support more relocation types as needed.
92 // - Make PLTs more flexible for different architecture features like
94 // There are probably a lot more.
96 // Utilities for manipulating integers of up to 32-bits
100 // Sign extend an n-bit unsigned integer stored in an uint32_t into
101 // an int32_t. NO_BITS must be between 1 to 32.
102 template<int no_bits
>
103 static inline int32_t
104 sign_extend(uint32_t bits
)
106 gold_assert(no_bits
>= 0 && no_bits
<= 32);
108 return static_cast<int32_t>(bits
);
109 uint32_t mask
= (~((uint32_t) 0)) >> (32 - no_bits
);
111 uint32_t top_bit
= 1U << (no_bits
- 1);
112 int32_t as_signed
= static_cast<int32_t>(bits
);
113 return (bits
& top_bit
) ? as_signed
+ (-top_bit
* 2) : as_signed
;
116 // Detects overflow of an NO_BITS integer stored in a uint32_t.
117 template<int no_bits
>
119 has_overflow(uint32_t bits
)
121 gold_assert(no_bits
>= 0 && no_bits
<= 32);
124 int32_t max
= (1 << (no_bits
- 1)) - 1;
125 int32_t min
= -(1 << (no_bits
- 1));
126 int32_t as_signed
= static_cast<int32_t>(bits
);
127 return as_signed
> max
|| as_signed
< min
;
130 // Detects overflow of an NO_BITS integer stored in a uint32_t when it
131 // fits in the given number of bits as either a signed or unsigned value.
132 // For example, has_signed_unsigned_overflow<8> would check
133 // -128 <= bits <= 255
134 template<int no_bits
>
136 has_signed_unsigned_overflow(uint32_t bits
)
138 gold_assert(no_bits
>= 2 && no_bits
<= 32);
141 int32_t max
= static_cast<int32_t>((1U << no_bits
) - 1);
142 int32_t min
= -(1 << (no_bits
- 1));
143 int32_t as_signed
= static_cast<int32_t>(bits
);
144 return as_signed
> max
|| as_signed
< min
;
147 // Select bits from A and B using bits in MASK. For each n in [0..31],
148 // the n-th bit in the result is chosen from the n-th bits of A and B.
149 // A zero selects A and a one selects B.
150 static inline uint32_t
151 bit_select(uint32_t a
, uint32_t b
, uint32_t mask
)
152 { return (a
& ~mask
) | (b
& mask
); }
155 template<bool big_endian
>
156 class Target_arm
: public Sized_target
<32, big_endian
>
159 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, big_endian
>
163 : Sized_target
<32, big_endian
>(&arm_info
),
164 got_(NULL
), plt_(NULL
), got_plt_(NULL
), rel_dyn_(NULL
),
165 copy_relocs_(elfcpp::R_ARM_COPY
), dynbss_(NULL
)
168 // Process the relocations to determine unreferenced sections for
169 // garbage collection.
171 gc_process_relocs(const General_options
& options
,
172 Symbol_table
* symtab
,
174 Sized_relobj
<32, big_endian
>* object
,
175 unsigned int data_shndx
,
176 unsigned int sh_type
,
177 const unsigned char* prelocs
,
179 Output_section
* output_section
,
180 bool needs_special_offset_handling
,
181 size_t local_symbol_count
,
182 const unsigned char* plocal_symbols
);
184 // Scan the relocations to look for symbol adjustments.
186 scan_relocs(const General_options
& options
,
187 Symbol_table
* symtab
,
189 Sized_relobj
<32, big_endian
>* object
,
190 unsigned int data_shndx
,
191 unsigned int sh_type
,
192 const unsigned char* prelocs
,
194 Output_section
* output_section
,
195 bool needs_special_offset_handling
,
196 size_t local_symbol_count
,
197 const unsigned char* plocal_symbols
);
199 // Finalize the sections.
201 do_finalize_sections(Layout
*);
203 // Return the value to use for a dynamic symbol which requires special
206 do_dynsym_value(const Symbol
*) const;
208 // Relocate a section.
210 relocate_section(const Relocate_info
<32, big_endian
>*,
211 unsigned int sh_type
,
212 const unsigned char* prelocs
,
214 Output_section
* output_section
,
215 bool needs_special_offset_handling
,
217 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
218 section_size_type view_size
,
219 const Reloc_symbol_changes
*);
221 // Scan the relocs during a relocatable link.
223 scan_relocatable_relocs(const General_options
& options
,
224 Symbol_table
* symtab
,
226 Sized_relobj
<32, big_endian
>* object
,
227 unsigned int data_shndx
,
228 unsigned int sh_type
,
229 const unsigned char* prelocs
,
231 Output_section
* output_section
,
232 bool needs_special_offset_handling
,
233 size_t local_symbol_count
,
234 const unsigned char* plocal_symbols
,
235 Relocatable_relocs
*);
237 // Relocate a section during a relocatable link.
239 relocate_for_relocatable(const Relocate_info
<32, big_endian
>*,
240 unsigned int sh_type
,
241 const unsigned char* prelocs
,
243 Output_section
* output_section
,
244 off_t offset_in_output_section
,
245 const Relocatable_relocs
*,
247 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
248 section_size_type view_size
,
249 unsigned char* reloc_view
,
250 section_size_type reloc_view_size
);
252 // Return whether SYM is defined by the ABI.
254 do_is_defined_by_abi(Symbol
* sym
) const
255 { return strcmp(sym
->name(), "__tls_get_addr") == 0; }
257 // Return the size of the GOT section.
261 gold_assert(this->got_
!= NULL
);
262 return this->got_
->data_size();
265 // Map platform-specific reloc types
267 get_real_reloc_type (unsigned int r_type
);
270 // The class which scans relocations.
275 : issued_non_pic_error_(false)
279 local(const General_options
& options
, Symbol_table
* symtab
,
280 Layout
* layout
, Target_arm
* target
,
281 Sized_relobj
<32, big_endian
>* object
,
282 unsigned int data_shndx
,
283 Output_section
* output_section
,
284 const elfcpp::Rel
<32, big_endian
>& reloc
, unsigned int r_type
,
285 const elfcpp::Sym
<32, big_endian
>& lsym
);
288 global(const General_options
& options
, Symbol_table
* symtab
,
289 Layout
* layout
, Target_arm
* target
,
290 Sized_relobj
<32, big_endian
>* object
,
291 unsigned int data_shndx
,
292 Output_section
* output_section
,
293 const elfcpp::Rel
<32, big_endian
>& reloc
, unsigned int r_type
,
298 unsupported_reloc_local(Sized_relobj
<32, big_endian
>*,
299 unsigned int r_type
);
302 unsupported_reloc_global(Sized_relobj
<32, big_endian
>*,
303 unsigned int r_type
, Symbol
*);
306 check_non_pic(Relobj
*, unsigned int r_type
);
308 // Almost identical to Symbol::needs_plt_entry except that it also
309 // handles STT_ARM_TFUNC.
311 symbol_needs_plt_entry(const Symbol
* sym
)
313 // An undefined symbol from an executable does not need a PLT entry.
314 if (sym
->is_undefined() && !parameters
->options().shared())
317 return (!parameters
->doing_static_link()
318 && (sym
->type() == elfcpp::STT_FUNC
319 || sym
->type() == elfcpp::STT_ARM_TFUNC
)
320 && (sym
->is_from_dynobj()
321 || sym
->is_undefined()
322 || sym
->is_preemptible()));
325 // Whether we have issued an error about a non-PIC compilation.
326 bool issued_non_pic_error_
;
329 // The class which implements relocation.
339 // Return whether the static relocation needs to be applied.
341 should_apply_static_reloc(const Sized_symbol
<32>* gsym
,
344 Output_section
* output_section
);
346 // Do a relocation. Return false if the caller should not issue
347 // any warnings about this relocation.
349 relocate(const Relocate_info
<32, big_endian
>*, Target_arm
*,
350 Output_section
*, size_t relnum
,
351 const elfcpp::Rel
<32, big_endian
>&,
352 unsigned int r_type
, const Sized_symbol
<32>*,
353 const Symbol_value
<32>*,
354 unsigned char*, elfcpp::Elf_types
<32>::Elf_Addr
,
357 // Return whether we want to pass flag NON_PIC_REF for this
360 reloc_is_non_pic (unsigned int r_type
)
364 case elfcpp::R_ARM_REL32
:
365 case elfcpp::R_ARM_THM_CALL
:
366 case elfcpp::R_ARM_CALL
:
367 case elfcpp::R_ARM_JUMP24
:
368 case elfcpp::R_ARM_PREL31
:
376 // A class which returns the size required for a relocation type,
377 // used while scanning relocs during a relocatable link.
378 class Relocatable_size_for_reloc
382 get_size_for_reloc(unsigned int, Relobj
*);
385 // Get the GOT section, creating it if necessary.
386 Output_data_got
<32, big_endian
>*
387 got_section(Symbol_table
*, Layout
*);
389 // Get the GOT PLT section.
391 got_plt_section() const
393 gold_assert(this->got_plt_
!= NULL
);
394 return this->got_plt_
;
397 // Create a PLT entry for a global symbol.
399 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
401 // Get the PLT section.
402 const Output_data_plt_arm
<big_endian
>*
405 gold_assert(this->plt_
!= NULL
);
409 // Get the dynamic reloc section, creating it if necessary.
411 rel_dyn_section(Layout
*);
413 // Return true if the symbol may need a COPY relocation.
414 // References from an executable object to non-function symbols
415 // defined in a dynamic object may need a COPY relocation.
417 may_need_copy_reloc(Symbol
* gsym
)
419 return (gsym
->type() != elfcpp::STT_ARM_TFUNC
420 && gsym
->may_need_copy_reloc());
423 // Add a potential copy relocation.
425 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
426 Sized_relobj
<32, big_endian
>* object
,
427 unsigned int shndx
, Output_section
* output_section
,
428 Symbol
* sym
, const elfcpp::Rel
<32, big_endian
>& reloc
)
430 this->copy_relocs_
.copy_reloc(symtab
, layout
,
431 symtab
->get_sized_symbol
<32>(sym
),
432 object
, shndx
, output_section
, reloc
,
433 this->rel_dyn_section(layout
));
436 // Information about this specific target which we pass to the
437 // general Target structure.
438 static const Target::Target_info arm_info
;
440 // The types of GOT entries needed for this platform.
443 GOT_TYPE_STANDARD
= 0 // GOT entry for a regular symbol
447 Output_data_got
<32, big_endian
>* got_
;
449 Output_data_plt_arm
<big_endian
>* plt_
;
450 // The GOT PLT section.
451 Output_data_space
* got_plt_
;
452 // The dynamic reloc section.
453 Reloc_section
* rel_dyn_
;
454 // Relocs saved to avoid a COPY reloc.
455 Copy_relocs
<elfcpp::SHT_REL
, 32, big_endian
> copy_relocs_
;
456 // Space for variables copied with a COPY reloc.
457 Output_data_space
* dynbss_
;
460 template<bool big_endian
>
461 const Target::Target_info Target_arm
<big_endian
>::arm_info
=
464 big_endian
, // is_big_endian
465 elfcpp::EM_ARM
, // machine_code
466 false, // has_make_symbol
467 false, // has_resolve
468 false, // has_code_fill
469 true, // is_default_stack_executable
471 "/usr/lib/libc.so.1", // dynamic_linker
472 0x8000, // default_text_segment_address
473 0x1000, // abi_pagesize (overridable by -z max-page-size)
474 0x1000, // common_pagesize (overridable by -z common-page-size)
475 elfcpp::SHN_UNDEF
, // small_common_shndx
476 elfcpp::SHN_UNDEF
, // large_common_shndx
477 0, // small_common_section_flags
478 0 // large_common_section_flags
481 // Arm relocate functions class
484 template<bool big_endian
>
485 class Arm_relocate_functions
: public Relocate_functions
<32, big_endian
>
490 STATUS_OKAY
, // No error during relocation.
491 STATUS_OVERFLOW
, // Relocation oveflow.
492 STATUS_BAD_RELOC
// Relocation cannot be applied.
496 typedef Relocate_functions
<32, big_endian
> Base
;
497 typedef Arm_relocate_functions
<big_endian
> This
;
499 // Get an symbol value of *PSYMVAL with an ADDEND. This is a wrapper
500 // to Symbol_value::value(). If HAS_THUMB_BIT is true, that LSB is used
501 // to distinguish ARM and THUMB functions and it is treated specially.
502 static inline Symbol_value
<32>::Value
503 arm_symbol_value (const Sized_relobj
<32, big_endian
> *object
,
504 const Symbol_value
<32>* psymval
,
505 Symbol_value
<32>::Value addend
,
508 typedef Symbol_value
<32>::Value Valtype
;
512 Valtype raw
= psymval
->value(object
, 0);
513 Valtype thumb_bit
= raw
& 1;
514 return ((raw
& ~((Valtype
) 1)) + addend
) | thumb_bit
;
517 return psymval
->value(object
, addend
);
520 // Encoding of imm16 argument for movt and movw ARM instructions
523 // imm16 := imm4 | imm12
525 // 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
526 // +-------+---------------+-------+-------+-----------------------+
527 // | | |imm4 | |imm12 |
528 // +-------+---------------+-------+-------+-----------------------+
530 // Extract the relocation addend from VAL based on the ARM
531 // instruction encoding described above.
532 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
533 extract_arm_movw_movt_addend(
534 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
)
536 // According to the Elf ABI for ARM Architecture the immediate
537 // field is sign-extended to form the addend.
538 return utils::sign_extend
<16>(((val
>> 4) & 0xf000) | (val
& 0xfff));
541 // Insert X into VAL based on the ARM instruction encoding described
543 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
544 insert_val_arm_movw_movt(
545 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
,
546 typename
elfcpp::Swap
<32, big_endian
>::Valtype x
)
550 val
|= (x
& 0xf000) << 4;
554 // Encoding of imm16 argument for movt and movw Thumb2 instructions
557 // imm16 := imm4 | i | imm3 | imm8
559 // 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
560 // +---------+-+-----------+-------++-+-----+-------+---------------+
561 // | |i| |imm4 || |imm3 | |imm8 |
562 // +---------+-+-----------+-------++-+-----+-------+---------------+
564 // Extract the relocation addend from VAL based on the Thumb2
565 // instruction encoding described above.
566 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
567 extract_thumb_movw_movt_addend(
568 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
)
570 // According to the Elf ABI for ARM Architecture the immediate
571 // field is sign-extended to form the addend.
572 return utils::sign_extend
<16>(((val
>> 4) & 0xf000)
573 | ((val
>> 15) & 0x0800)
574 | ((val
>> 4) & 0x0700)
578 // Insert X into VAL based on the Thumb2 instruction encoding
580 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
581 insert_val_thumb_movw_movt(
582 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
,
583 typename
elfcpp::Swap
<32, big_endian
>::Valtype x
)
586 val
|= (x
& 0xf000) << 4;
587 val
|= (x
& 0x0800) << 15;
588 val
|= (x
& 0x0700) << 4;
593 // FIXME: This probably only works for Android on ARM v5te. We should
594 // following GNU ld for the general case.
595 template<unsigned r_type
>
596 static inline typename
This::Status
597 arm_branch_common(unsigned char *view
,
598 const Sized_relobj
<32, big_endian
>* object
,
599 const Symbol_value
<32>* psymval
,
600 elfcpp::Elf_types
<32>::Elf_Addr address
,
603 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
604 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
605 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
607 bool insn_is_b
= (((val
>> 28) & 0xf) <= 0xe)
608 && ((val
& 0x0f000000UL
) == 0x0a000000UL
);
609 bool insn_is_uncond_bl
= (val
& 0xff000000UL
) == 0xeb000000UL
;
610 bool insn_is_cond_bl
= (((val
>> 28) & 0xf) < 0xe)
611 && ((val
& 0x0f000000UL
) == 0x0b000000UL
);
612 bool insn_is_blx
= (val
& 0xfe000000UL
) == 0xfa000000UL
;
613 bool insn_is_any_branch
= (val
& 0x0e000000UL
) == 0x0a000000UL
;
615 if (r_type
== elfcpp::R_ARM_CALL
)
617 if (!insn_is_uncond_bl
&& !insn_is_blx
)
618 return This::STATUS_BAD_RELOC
;
620 else if (r_type
== elfcpp::R_ARM_JUMP24
)
622 if (!insn_is_b
&& !insn_is_cond_bl
)
623 return This::STATUS_BAD_RELOC
;
625 else if (r_type
== elfcpp::R_ARM_PLT32
)
627 if (!insn_is_any_branch
)
628 return This::STATUS_BAD_RELOC
;
633 Valtype addend
= utils::sign_extend
<26>(val
<< 2);
634 Valtype x
= (This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
)
637 // If target has thumb bit set, we need to either turn the BL
638 // into a BLX (for ARMv5 or above) or generate a stub.
642 if (insn_is_uncond_bl
)
643 val
= (val
& 0xffffff) | 0xfa000000 | ((x
& 2) << 23);
645 return This::STATUS_BAD_RELOC
;
648 gold_assert(!insn_is_blx
);
650 val
= utils::bit_select(val
, (x
>> 2), 0xffffffUL
);
651 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
652 return (utils::has_overflow
<26>(x
)
653 ? This::STATUS_OVERFLOW
: This::STATUS_OKAY
);
659 static inline typename
This::Status
660 abs8(unsigned char *view
,
661 const Sized_relobj
<32, big_endian
>* object
,
662 const Symbol_value
<32>* psymval
, bool has_thumb_bit
)
664 typedef typename
elfcpp::Swap
<8, big_endian
>::Valtype Valtype
;
665 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
666 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
667 Valtype val
= elfcpp::Swap
<8, big_endian
>::readval(wv
);
668 Reltype addend
= utils::sign_extend
<8>(val
);
669 Reltype x
= This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
);
670 val
= utils::bit_select(val
, x
, 0xffU
);
671 elfcpp::Swap
<8, big_endian
>::writeval(wv
, val
);
672 return (utils::has_signed_unsigned_overflow
<8>(x
)
673 ? This::STATUS_OVERFLOW
674 : This::STATUS_OKAY
);
677 // R_ARM_ABS32: (S + A) | T
678 static inline typename
This::Status
679 abs32(unsigned char *view
,
680 const Sized_relobj
<32, big_endian
>* object
,
681 const Symbol_value
<32>* psymval
,
684 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
685 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
686 Valtype addend
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
687 Valtype x
= This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
);
688 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
689 return This::STATUS_OKAY
;
692 // R_ARM_REL32: (S + A) | T - P
693 static inline typename
This::Status
694 rel32(unsigned char *view
,
695 const Sized_relobj
<32, big_endian
>* object
,
696 const Symbol_value
<32>* psymval
,
697 elfcpp::Elf_types
<32>::Elf_Addr address
,
700 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
701 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
702 Valtype addend
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
703 Valtype x
= (This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
)
705 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
706 return This::STATUS_OKAY
;
709 // R_ARM_THM_CALL: (S + A) | T - P
710 static inline typename
This::Status
711 thm_call(unsigned char *view
,
712 const Sized_relobj
<32, big_endian
>* object
,
713 const Symbol_value
<32>* psymval
,
714 elfcpp::Elf_types
<32>::Elf_Addr address
,
717 // A thumb call consists of two instructions.
718 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
719 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
720 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
721 Valtype hi
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
722 Valtype lo
= elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
723 // Must be a BL instruction. lo == 11111xxxxxxxxxxx.
724 gold_assert((lo
& 0xf800) == 0xf800);
725 Reltype addend
= utils::sign_extend
<23>(((hi
& 0x7ff) << 12)
726 | ((lo
& 0x7ff) << 1));
727 Reltype x
= (This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
)
730 // If target has no thumb bit set, we need to either turn the BL
731 // into a BLX (for ARMv5 or above) or generate a stub.
734 // This only works for ARMv5 and above with interworking enabled.
737 hi
= utils::bit_select(hi
, (x
>> 12), 0x7ffU
);
738 lo
= utils::bit_select(lo
, (x
>> 1), 0x7ffU
);
739 elfcpp::Swap
<16, big_endian
>::writeval(wv
, hi
);
740 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, lo
);
741 return (utils::has_overflow
<23>(x
)
742 ? This::STATUS_OVERFLOW
743 : This::STATUS_OKAY
);
746 // R_ARM_BASE_PREL: B(S) + A - P
747 static inline typename
This::Status
748 base_prel(unsigned char* view
,
749 elfcpp::Elf_types
<32>::Elf_Addr origin
,
750 elfcpp::Elf_types
<32>::Elf_Addr address
)
752 Base::rel32(view
, origin
- address
);
756 // R_ARM_GOT_BREL: GOT(S) + A - GOT_ORG
757 static inline typename
This::Status
758 got_brel(unsigned char* view
,
759 typename
elfcpp::Swap
<32, big_endian
>::Valtype got_offset
)
761 Base::rel32(view
, got_offset
);
762 return This::STATUS_OKAY
;
765 // R_ARM_GOT_PREL: GOT(S) + A – P
766 static inline typename
This::Status
767 got_prel(unsigned char* view
,
768 typename
elfcpp::Swap
<32, big_endian
>::Valtype got_offset
,
769 elfcpp::Elf_types
<32>::Elf_Addr address
)
771 Base::rel32(view
, got_offset
- address
);
772 return This::STATUS_OKAY
;
775 // R_ARM_PLT32: (S + A) | T - P
776 static inline typename
This::Status
777 plt32(unsigned char *view
,
778 const Sized_relobj
<32, big_endian
>* object
,
779 const Symbol_value
<32>* psymval
,
780 elfcpp::Elf_types
<32>::Elf_Addr address
,
783 return arm_branch_common
<elfcpp::R_ARM_PLT32
>(view
, object
, psymval
,
784 address
, has_thumb_bit
);
787 // R_ARM_CALL: (S + A) | T - P
788 static inline typename
This::Status
789 call(unsigned char *view
,
790 const Sized_relobj
<32, big_endian
>* object
,
791 const Symbol_value
<32>* psymval
,
792 elfcpp::Elf_types
<32>::Elf_Addr address
,
795 return arm_branch_common
<elfcpp::R_ARM_CALL
>(view
, object
, psymval
,
796 address
, has_thumb_bit
);
799 // R_ARM_JUMP24: (S + A) | T - P
800 static inline typename
This::Status
801 jump24(unsigned char *view
,
802 const Sized_relobj
<32, big_endian
>* object
,
803 const Symbol_value
<32>* psymval
,
804 elfcpp::Elf_types
<32>::Elf_Addr address
,
807 return arm_branch_common
<elfcpp::R_ARM_JUMP24
>(view
, object
, psymval
,
808 address
, has_thumb_bit
);
811 // R_ARM_PREL: (S + A) | T - P
812 static inline typename
This::Status
813 prel31(unsigned char *view
,
814 const Sized_relobj
<32, big_endian
>* object
,
815 const Symbol_value
<32>* psymval
,
816 elfcpp::Elf_types
<32>::Elf_Addr address
,
819 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
820 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
821 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
822 Valtype addend
= utils::sign_extend
<31>(val
);
823 Valtype x
= (This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
)
825 val
= utils::bit_select(val
, x
, 0x7fffffffU
);
826 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
827 return (utils::has_overflow
<31>(x
) ?
828 This::STATUS_OVERFLOW
: This::STATUS_OKAY
);
831 // R_ARM_MOVW_ABS_NC: (S + A) | T
832 static inline typename
This::Status
833 movw_abs_nc(unsigned char *view
,
834 const Sized_relobj
<32, big_endian
>* object
,
835 const Symbol_value
<32>* psymval
,
838 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
839 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
840 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
841 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
842 Valtype x
= This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
);
843 val
= This::insert_val_arm_movw_movt(val
, x
);
844 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
845 return This::STATUS_OKAY
;
848 // R_ARM_MOVT_ABS: S + A
849 static inline typename
This::Status
850 movt_abs(unsigned char *view
,
851 const Sized_relobj
<32, big_endian
>* object
,
852 const Symbol_value
<32>* psymval
)
854 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
855 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
856 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
857 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
858 Valtype x
= This::arm_symbol_value(object
, psymval
, addend
, 0) >> 16;
859 val
= This::insert_val_arm_movw_movt(val
, x
);
860 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
861 return This::STATUS_OKAY
;
864 // R_ARM_THM_MOVW_ABS_NC: S + A | T
865 static inline typename
This::Status
866 thm_movw_abs_nc(unsigned char *view
,
867 const Sized_relobj
<32, big_endian
>* object
,
868 const Symbol_value
<32>* psymval
,
871 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
872 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
873 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
874 Reltype val
= ((elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
875 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1));
876 Reltype addend
= extract_thumb_movw_movt_addend(val
);
877 Reltype x
= This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
);
878 val
= This::insert_val_thumb_movw_movt(val
, x
);
879 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
880 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
881 return This::STATUS_OKAY
;
884 // R_ARM_THM_MOVT_ABS: S + A
885 static inline typename
This::Status
886 thm_movt_abs(unsigned char *view
,
887 const Sized_relobj
<32, big_endian
>* object
,
888 const Symbol_value
<32>* psymval
)
890 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
891 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
892 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
893 Reltype val
= ((elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
894 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1));
895 Reltype addend
= This::extract_thumb_movw_movt_addend(val
);
896 Reltype x
= This::arm_symbol_value(object
, psymval
, addend
, 0) >> 16;
897 val
= This::insert_val_thumb_movw_movt(val
, x
);
898 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
899 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
900 return This::STATUS_OKAY
;
903 // R_ARM_MOVW_PREL_NC: (S + A) | T - P
904 static inline typename
This::Status
905 movw_prel_nc(unsigned char *view
,
906 const Sized_relobj
<32, big_endian
>* object
,
907 const Symbol_value
<32>* psymval
,
908 elfcpp::Elf_types
<32>::Elf_Addr address
,
911 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
912 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
913 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
914 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
915 Valtype x
= (This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
)
917 val
= This::insert_val_arm_movw_movt(val
, x
);
918 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
919 return This::STATUS_OKAY
;
922 // R_ARM_MOVT_PREL: S + A - P
923 static inline typename
This::Status
924 movt_prel(unsigned char *view
,
925 const Sized_relobj
<32, big_endian
>* object
,
926 const Symbol_value
<32>* psymval
,
927 elfcpp::Elf_types
<32>::Elf_Addr address
)
929 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
930 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
931 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
932 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
933 Valtype x
= (This::arm_symbol_value(object
, psymval
, addend
, 0)
935 val
= This::insert_val_arm_movw_movt(val
, x
);
936 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
937 return This::STATUS_OKAY
;
940 // R_ARM_THM_MOVW_PREL_NC: (S + A) | T - P
941 static inline typename
This::Status
942 thm_movw_prel_nc(unsigned char *view
,
943 const Sized_relobj
<32, big_endian
>* object
,
944 const Symbol_value
<32>* psymval
,
945 elfcpp::Elf_types
<32>::Elf_Addr address
,
948 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
949 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
950 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
951 Reltype val
= (elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
952 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
953 Reltype addend
= This::extract_thumb_movw_movt_addend(val
);
954 Reltype x
= (This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
)
956 val
= This::insert_val_thumb_movw_movt(val
, x
);
957 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
958 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
959 return This::STATUS_OKAY
;
962 // R_ARM_THM_MOVT_PREL: S + A - P
963 static inline typename
This::Status
964 thm_movt_prel(unsigned char *view
,
965 const Sized_relobj
<32, big_endian
>* object
,
966 const Symbol_value
<32>* psymval
,
967 elfcpp::Elf_types
<32>::Elf_Addr address
)
969 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
970 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
971 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
972 Reltype val
= (elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
973 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
974 Reltype addend
= This::extract_thumb_movw_movt_addend(val
);
975 Reltype x
= (This::arm_symbol_value(object
, psymval
, addend
, 0)
977 val
= This::insert_val_thumb_movw_movt(val
, x
);
978 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
979 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
980 return This::STATUS_OKAY
;
984 // Get the GOT section, creating it if necessary.
986 template<bool big_endian
>
987 Output_data_got
<32, big_endian
>*
988 Target_arm
<big_endian
>::got_section(Symbol_table
* symtab
, Layout
* layout
)
990 if (this->got_
== NULL
)
992 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
994 this->got_
= new Output_data_got
<32, big_endian
>();
997 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
999 | elfcpp::SHF_WRITE
),
1003 // The old GNU linker creates a .got.plt section. We just
1004 // create another set of data in the .got section. Note that we
1005 // always create a PLT if we create a GOT, although the PLT
1007 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
1008 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1010 | elfcpp::SHF_WRITE
),
1014 // The first three entries are reserved.
1015 this->got_plt_
->set_current_data_size(3 * 4);
1017 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
1018 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1020 0, 0, elfcpp::STT_OBJECT
,
1022 elfcpp::STV_HIDDEN
, 0,
1028 // Get the dynamic reloc section, creating it if necessary.
1030 template<bool big_endian
>
1031 typename Target_arm
<big_endian
>::Reloc_section
*
1032 Target_arm
<big_endian
>::rel_dyn_section(Layout
* layout
)
1034 if (this->rel_dyn_
== NULL
)
1036 gold_assert(layout
!= NULL
);
1037 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
1038 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
1039 elfcpp::SHF_ALLOC
, this->rel_dyn_
);
1041 return this->rel_dyn_
;
1044 // A class to handle the PLT data.
1046 template<bool big_endian
>
1047 class Output_data_plt_arm
: public Output_section_data
1050 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, big_endian
>
1053 Output_data_plt_arm(Layout
*, Output_data_space
*);
1055 // Add an entry to the PLT.
1057 add_entry(Symbol
* gsym
);
1059 // Return the .rel.plt section data.
1060 const Reloc_section
*
1062 { return this->rel_
; }
1066 do_adjust_output_section(Output_section
* os
);
1068 // Write to a map file.
1070 do_print_to_mapfile(Mapfile
* mapfile
) const
1071 { mapfile
->print_output_data(this, _("** PLT")); }
1074 // Template for the first PLT entry.
1075 static const uint32_t first_plt_entry
[5];
1077 // Template for subsequent PLT entries.
1078 static const uint32_t plt_entry
[3];
1080 // Set the final size.
1082 set_final_data_size()
1084 this->set_data_size(sizeof(first_plt_entry
)
1085 + this->count_
* sizeof(plt_entry
));
1088 // Write out the PLT data.
1090 do_write(Output_file
*);
1092 // The reloc section.
1093 Reloc_section
* rel_
;
1094 // The .got.plt section.
1095 Output_data_space
* got_plt_
;
1096 // The number of PLT entries.
1097 unsigned int count_
;
1100 // Create the PLT section. The ordinary .got section is an argument,
1101 // since we need to refer to the start. We also create our own .got
1102 // section just for PLT entries.
1104 template<bool big_endian
>
1105 Output_data_plt_arm
<big_endian
>::Output_data_plt_arm(Layout
* layout
,
1106 Output_data_space
* got_plt
)
1107 : Output_section_data(4), got_plt_(got_plt
), count_(0)
1109 this->rel_
= new Reloc_section(false);
1110 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
1111 elfcpp::SHF_ALLOC
, this->rel_
);
1114 template<bool big_endian
>
1116 Output_data_plt_arm
<big_endian
>::do_adjust_output_section(Output_section
* os
)
1121 // Add an entry to the PLT.
1123 template<bool big_endian
>
1125 Output_data_plt_arm
<big_endian
>::add_entry(Symbol
* gsym
)
1127 gold_assert(!gsym
->has_plt_offset());
1129 // Note that when setting the PLT offset we skip the initial
1130 // reserved PLT entry.
1131 gsym
->set_plt_offset((this->count_
) * sizeof(plt_entry
)
1132 + sizeof(first_plt_entry
));
1136 section_offset_type got_offset
= this->got_plt_
->current_data_size();
1138 // Every PLT entry needs a GOT entry which points back to the PLT
1139 // entry (this will be changed by the dynamic linker, normally
1140 // lazily when the function is called).
1141 this->got_plt_
->set_current_data_size(got_offset
+ 4);
1143 // Every PLT entry needs a reloc.
1144 gsym
->set_needs_dynsym_entry();
1145 this->rel_
->add_global(gsym
, elfcpp::R_ARM_JUMP_SLOT
, this->got_plt_
,
1148 // Note that we don't need to save the symbol. The contents of the
1149 // PLT are independent of which symbols are used. The symbols only
1150 // appear in the relocations.
1154 // FIXME: This is not very flexible. Right now this has only been tested
1155 // on armv5te. If we are to support additional architecture features like
1156 // Thumb-2 or BE8, we need to make this more flexible like GNU ld.
1158 // The first entry in the PLT.
1159 template<bool big_endian
>
1160 const uint32_t Output_data_plt_arm
<big_endian
>::first_plt_entry
[5] =
1162 0xe52de004, // str lr, [sp, #-4]!
1163 0xe59fe004, // ldr lr, [pc, #4]
1164 0xe08fe00e, // add lr, pc, lr
1165 0xe5bef008, // ldr pc, [lr, #8]!
1166 0x00000000, // &GOT[0] - .
1169 // Subsequent entries in the PLT.
1171 template<bool big_endian
>
1172 const uint32_t Output_data_plt_arm
<big_endian
>::plt_entry
[3] =
1174 0xe28fc600, // add ip, pc, #0xNN00000
1175 0xe28cca00, // add ip, ip, #0xNN000
1176 0xe5bcf000, // ldr pc, [ip, #0xNNN]!
1179 // Write out the PLT. This uses the hand-coded instructions above,
1180 // and adjusts them as needed. This is all specified by the arm ELF
1181 // Processor Supplement.
1183 template<bool big_endian
>
1185 Output_data_plt_arm
<big_endian
>::do_write(Output_file
* of
)
1187 const off_t offset
= this->offset();
1188 const section_size_type oview_size
=
1189 convert_to_section_size_type(this->data_size());
1190 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1192 const off_t got_file_offset
= this->got_plt_
->offset();
1193 const section_size_type got_size
=
1194 convert_to_section_size_type(this->got_plt_
->data_size());
1195 unsigned char* const got_view
= of
->get_output_view(got_file_offset
,
1197 unsigned char* pov
= oview
;
1199 elfcpp::Elf_types
<32>::Elf_Addr plt_address
= this->address();
1200 elfcpp::Elf_types
<32>::Elf_Addr got_address
= this->got_plt_
->address();
1202 // Write first PLT entry. All but the last word are constants.
1203 const size_t num_first_plt_words
= (sizeof(first_plt_entry
)
1204 / sizeof(plt_entry
[0]));
1205 for (size_t i
= 0; i
< num_first_plt_words
- 1; i
++)
1206 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ i
* 4, first_plt_entry
[i
]);
1207 // Last word in first PLT entry is &GOT[0] - .
1208 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 16,
1209 got_address
- (plt_address
+ 16));
1210 pov
+= sizeof(first_plt_entry
);
1212 unsigned char* got_pov
= got_view
;
1214 memset(got_pov
, 0, 12);
1217 const int rel_size
= elfcpp::Elf_sizes
<32>::rel_size
;
1218 unsigned int plt_offset
= sizeof(first_plt_entry
);
1219 unsigned int plt_rel_offset
= 0;
1220 unsigned int got_offset
= 12;
1221 const unsigned int count
= this->count_
;
1222 for (unsigned int i
= 0;
1225 pov
+= sizeof(plt_entry
),
1227 plt_offset
+= sizeof(plt_entry
),
1228 plt_rel_offset
+= rel_size
,
1231 // Set and adjust the PLT entry itself.
1232 int32_t offset
= ((got_address
+ got_offset
)
1233 - (plt_address
+ plt_offset
+ 8));
1235 gold_assert(offset
>= 0 && offset
< 0x0fffffff);
1236 uint32_t plt_insn0
= plt_entry
[0] | ((offset
>> 20) & 0xff);
1237 elfcpp::Swap
<32, big_endian
>::writeval(pov
, plt_insn0
);
1238 uint32_t plt_insn1
= plt_entry
[1] | ((offset
>> 12) & 0xff);
1239 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, plt_insn1
);
1240 uint32_t plt_insn2
= plt_entry
[2] | (offset
& 0xfff);
1241 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8, plt_insn2
);
1243 // Set the entry in the GOT.
1244 elfcpp::Swap
<32, big_endian
>::writeval(got_pov
, plt_address
);
1247 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1248 gold_assert(static_cast<section_size_type
>(got_pov
- got_view
) == got_size
);
1250 of
->write_output_view(offset
, oview_size
, oview
);
1251 of
->write_output_view(got_file_offset
, got_size
, got_view
);
1254 // Create a PLT entry for a global symbol.
1256 template<bool big_endian
>
1258 Target_arm
<big_endian
>::make_plt_entry(Symbol_table
* symtab
, Layout
* layout
,
1261 if (gsym
->has_plt_offset())
1264 if (this->plt_
== NULL
)
1266 // Create the GOT sections first.
1267 this->got_section(symtab
, layout
);
1269 this->plt_
= new Output_data_plt_arm
<big_endian
>(layout
, this->got_plt_
);
1270 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1272 | elfcpp::SHF_EXECINSTR
),
1275 this->plt_
->add_entry(gsym
);
1278 // Report an unsupported relocation against a local symbol.
1280 template<bool big_endian
>
1282 Target_arm
<big_endian
>::Scan::unsupported_reloc_local(
1283 Sized_relobj
<32, big_endian
>* object
,
1284 unsigned int r_type
)
1286 gold_error(_("%s: unsupported reloc %u against local symbol"),
1287 object
->name().c_str(), r_type
);
1290 // We are about to emit a dynamic relocation of type R_TYPE. If the
1291 // dynamic linker does not support it, issue an error. The GNU linker
1292 // only issues a non-PIC error for an allocated read-only section.
1293 // Here we know the section is allocated, but we don't know that it is
1294 // read-only. But we check for all the relocation types which the
1295 // glibc dynamic linker supports, so it seems appropriate to issue an
1296 // error even if the section is not read-only.
1298 template<bool big_endian
>
1300 Target_arm
<big_endian
>::Scan::check_non_pic(Relobj
* object
,
1301 unsigned int r_type
)
1305 // These are the relocation types supported by glibc for ARM.
1306 case elfcpp::R_ARM_RELATIVE
:
1307 case elfcpp::R_ARM_COPY
:
1308 case elfcpp::R_ARM_GLOB_DAT
:
1309 case elfcpp::R_ARM_JUMP_SLOT
:
1310 case elfcpp::R_ARM_ABS32
:
1311 case elfcpp::R_ARM_PC24
:
1312 // FIXME: The following 3 types are not supported by Android's dynamic
1314 case elfcpp::R_ARM_TLS_DTPMOD32
:
1315 case elfcpp::R_ARM_TLS_DTPOFF32
:
1316 case elfcpp::R_ARM_TLS_TPOFF32
:
1320 // This prevents us from issuing more than one error per reloc
1321 // section. But we can still wind up issuing more than one
1322 // error per object file.
1323 if (this->issued_non_pic_error_
)
1325 object
->error(_("requires unsupported dynamic reloc; "
1326 "recompile with -fPIC"));
1327 this->issued_non_pic_error_
= true;
1330 case elfcpp::R_ARM_NONE
:
1335 // Scan a relocation for a local symbol.
1336 // FIXME: This only handles a subset of relocation types used by Android
1337 // on ARM v5te devices.
1339 template<bool big_endian
>
1341 Target_arm
<big_endian
>::Scan::local(const General_options
&,
1342 Symbol_table
* symtab
,
1345 Sized_relobj
<32, big_endian
>* object
,
1346 unsigned int data_shndx
,
1347 Output_section
* output_section
,
1348 const elfcpp::Rel
<32, big_endian
>& reloc
,
1349 unsigned int r_type
,
1350 const elfcpp::Sym
<32, big_endian
>&)
1352 r_type
= get_real_reloc_type(r_type
);
1355 case elfcpp::R_ARM_NONE
:
1358 case elfcpp::R_ARM_ABS8
:
1359 if (parameters
->options().output_is_position_independent())
1361 // FIXME: Create a dynamic relocation for this location.
1362 gold_error(_("%s: gold bug: need dynamic ABS8 reloc"),
1363 object
->name().c_str());
1367 case elfcpp::R_ARM_ABS32
:
1368 // If building a shared library (or a position-independent
1369 // executable), we need to create a dynamic relocation for
1370 // this location. The relocation applied at link time will
1371 // apply the link-time value, so we flag the location with
1372 // an R_ARM_RELATIVE relocation so the dynamic loader can
1373 // relocate it easily.
1374 if (parameters
->options().output_is_position_independent())
1376 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1377 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1378 // If we are to add more other reloc types than R_ARM_ABS32,
1379 // we need to add check_non_pic(object, r_type) here.
1380 rel_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_ARM_RELATIVE
,
1381 output_section
, data_shndx
,
1382 reloc
.get_r_offset());
1386 case elfcpp::R_ARM_REL32
:
1387 case elfcpp::R_ARM_THM_CALL
:
1388 case elfcpp::R_ARM_CALL
:
1389 case elfcpp::R_ARM_PREL31
:
1390 case elfcpp::R_ARM_JUMP24
:
1391 case elfcpp::R_ARM_PLT32
:
1392 case elfcpp::R_ARM_MOVW_ABS_NC
:
1393 case elfcpp::R_ARM_MOVT_ABS
:
1394 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
1395 case elfcpp::R_ARM_THM_MOVT_ABS
:
1396 case elfcpp::R_ARM_MOVW_PREL_NC
:
1397 case elfcpp::R_ARM_MOVT_PREL
:
1398 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
1399 case elfcpp::R_ARM_THM_MOVT_PREL
:
1402 case elfcpp::R_ARM_GOTOFF32
:
1403 // We need a GOT section:
1404 target
->got_section(symtab
, layout
);
1407 case elfcpp::R_ARM_BASE_PREL
:
1408 // FIXME: What about this?
1411 case elfcpp::R_ARM_GOT_BREL
:
1412 case elfcpp::R_ARM_GOT_PREL
:
1414 // The symbol requires a GOT entry.
1415 Output_data_got
<32, big_endian
>* got
=
1416 target
->got_section(symtab
, layout
);
1417 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1418 if (got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
))
1420 // If we are generating a shared object, we need to add a
1421 // dynamic RELATIVE relocation for this symbol's GOT entry.
1422 if (parameters
->options().output_is_position_independent())
1424 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1425 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1426 rel_dyn
->add_local_relative(
1427 object
, r_sym
, elfcpp::R_ARM_RELATIVE
, got
,
1428 object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
));
1434 case elfcpp::R_ARM_TARGET1
:
1435 // This should have been mapped to another type already.
1437 case elfcpp::R_ARM_COPY
:
1438 case elfcpp::R_ARM_GLOB_DAT
:
1439 case elfcpp::R_ARM_JUMP_SLOT
:
1440 case elfcpp::R_ARM_RELATIVE
:
1441 // These are relocations which should only be seen by the
1442 // dynamic linker, and should never be seen here.
1443 gold_error(_("%s: unexpected reloc %u in object file"),
1444 object
->name().c_str(), r_type
);
1448 unsupported_reloc_local(object
, r_type
);
1453 // Report an unsupported relocation against a global symbol.
1455 template<bool big_endian
>
1457 Target_arm
<big_endian
>::Scan::unsupported_reloc_global(
1458 Sized_relobj
<32, big_endian
>* object
,
1459 unsigned int r_type
,
1462 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1463 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
1466 // Scan a relocation for a global symbol.
1467 // FIXME: This only handles a subset of relocation types used by Android
1468 // on ARM v5te devices.
1470 template<bool big_endian
>
1472 Target_arm
<big_endian
>::Scan::global(const General_options
&,
1473 Symbol_table
* symtab
,
1476 Sized_relobj
<32, big_endian
>* object
,
1477 unsigned int data_shndx
,
1478 Output_section
* output_section
,
1479 const elfcpp::Rel
<32, big_endian
>& reloc
,
1480 unsigned int r_type
,
1483 r_type
= get_real_reloc_type(r_type
);
1486 case elfcpp::R_ARM_NONE
:
1489 case elfcpp::R_ARM_ABS8
:
1490 // Make a dynamic relocation if necessary.
1491 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
1493 // FIXME: Create a dynamic relocation for this location.
1494 gold_error(_("%s: gold bug: need dynamic ABS8 reloc for %s"),
1495 object
->name().c_str(), gsym
->demangled_name().c_str());
1499 case elfcpp::R_ARM_ABS32
:
1501 // Make a dynamic relocation if necessary.
1502 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
1504 if (target
->may_need_copy_reloc(gsym
))
1506 target
->copy_reloc(symtab
, layout
, object
,
1507 data_shndx
, output_section
, gsym
, reloc
);
1509 else if (gsym
->can_use_relative_reloc(false))
1511 // If we are to add more other reloc types than R_ARM_ABS32,
1512 // we need to add check_non_pic(object, r_type) here.
1513 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1514 rel_dyn
->add_global_relative(gsym
, elfcpp::R_ARM_RELATIVE
,
1515 output_section
, object
,
1516 data_shndx
, reloc
.get_r_offset());
1520 // If we are to add more other reloc types than R_ARM_ABS32,
1521 // we need to add check_non_pic(object, r_type) here.
1522 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1523 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
1524 data_shndx
, reloc
.get_r_offset());
1530 case elfcpp::R_ARM_MOVW_ABS_NC
:
1531 case elfcpp::R_ARM_MOVT_ABS
:
1532 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
1533 case elfcpp::R_ARM_THM_MOVT_ABS
:
1534 case elfcpp::R_ARM_MOVW_PREL_NC
:
1535 case elfcpp::R_ARM_MOVT_PREL
:
1536 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
1537 case elfcpp::R_ARM_THM_MOVT_PREL
:
1540 case elfcpp::R_ARM_REL32
:
1541 case elfcpp::R_ARM_PREL31
:
1543 // Make a dynamic relocation if necessary.
1544 int flags
= Symbol::NON_PIC_REF
;
1545 if (gsym
->needs_dynamic_reloc(flags
))
1547 if (target
->may_need_copy_reloc(gsym
))
1549 target
->copy_reloc(symtab
, layout
, object
,
1550 data_shndx
, output_section
, gsym
, reloc
);
1554 check_non_pic(object
, r_type
);
1555 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1556 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
1557 data_shndx
, reloc
.get_r_offset());
1563 case elfcpp::R_ARM_JUMP24
:
1564 case elfcpp::R_ARM_THM_CALL
:
1565 case elfcpp::R_ARM_CALL
:
1567 if (Target_arm
<big_endian
>::Scan::symbol_needs_plt_entry(gsym
))
1568 target
->make_plt_entry(symtab
, layout
, gsym
);
1569 // Make a dynamic relocation if necessary.
1570 int flags
= Symbol::NON_PIC_REF
;
1571 if (gsym
->type() == elfcpp::STT_FUNC
1572 || gsym
->type() == elfcpp::STT_ARM_TFUNC
)
1573 flags
|= Symbol::FUNCTION_CALL
;
1574 if (gsym
->needs_dynamic_reloc(flags
))
1576 if (target
->may_need_copy_reloc(gsym
))
1578 target
->copy_reloc(symtab
, layout
, object
,
1579 data_shndx
, output_section
, gsym
,
1584 check_non_pic(object
, r_type
);
1585 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1586 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
1587 data_shndx
, reloc
.get_r_offset());
1593 case elfcpp::R_ARM_PLT32
:
1594 // If the symbol is fully resolved, this is just a relative
1595 // local reloc. Otherwise we need a PLT entry.
1596 if (gsym
->final_value_is_known())
1598 // If building a shared library, we can also skip the PLT entry
1599 // if the symbol is defined in the output file and is protected
1601 if (gsym
->is_defined()
1602 && !gsym
->is_from_dynobj()
1603 && !gsym
->is_preemptible())
1605 target
->make_plt_entry(symtab
, layout
, gsym
);
1608 case elfcpp::R_ARM_GOTOFF32
:
1609 // We need a GOT section.
1610 target
->got_section(symtab
, layout
);
1613 case elfcpp::R_ARM_BASE_PREL
:
1614 // FIXME: What about this?
1617 case elfcpp::R_ARM_GOT_BREL
:
1618 case elfcpp::R_ARM_GOT_PREL
:
1620 // The symbol requires a GOT entry.
1621 Output_data_got
<32, big_endian
>* got
=
1622 target
->got_section(symtab
, layout
);
1623 if (gsym
->final_value_is_known())
1624 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
1627 // If this symbol is not fully resolved, we need to add a
1628 // GOT entry with a dynamic relocation.
1629 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1630 if (gsym
->is_from_dynobj()
1631 || gsym
->is_undefined()
1632 || gsym
->is_preemptible())
1633 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
,
1634 rel_dyn
, elfcpp::R_ARM_GLOB_DAT
);
1637 if (got
->add_global(gsym
, GOT_TYPE_STANDARD
))
1638 rel_dyn
->add_global_relative(
1639 gsym
, elfcpp::R_ARM_RELATIVE
, got
,
1640 gsym
->got_offset(GOT_TYPE_STANDARD
));
1646 case elfcpp::R_ARM_TARGET1
:
1647 // This should have been mapped to another type already.
1649 case elfcpp::R_ARM_COPY
:
1650 case elfcpp::R_ARM_GLOB_DAT
:
1651 case elfcpp::R_ARM_JUMP_SLOT
:
1652 case elfcpp::R_ARM_RELATIVE
:
1653 // These are relocations which should only be seen by the
1654 // dynamic linker, and should never be seen here.
1655 gold_error(_("%s: unexpected reloc %u in object file"),
1656 object
->name().c_str(), r_type
);
1660 unsupported_reloc_global(object
, r_type
, gsym
);
1665 // Process relocations for gc.
1667 template<bool big_endian
>
1669 Target_arm
<big_endian
>::gc_process_relocs(const General_options
& options
,
1670 Symbol_table
* symtab
,
1672 Sized_relobj
<32, big_endian
>* object
,
1673 unsigned int data_shndx
,
1675 const unsigned char* prelocs
,
1677 Output_section
* output_section
,
1678 bool needs_special_offset_handling
,
1679 size_t local_symbol_count
,
1680 const unsigned char* plocal_symbols
)
1682 typedef Target_arm
<big_endian
> Arm
;
1683 typedef typename Target_arm
<big_endian
>::Scan Scan
;
1685 gold::gc_process_relocs
<32, big_endian
, Arm
, elfcpp::SHT_REL
, Scan
>(
1695 needs_special_offset_handling
,
1700 // Scan relocations for a section.
1702 template<bool big_endian
>
1704 Target_arm
<big_endian
>::scan_relocs(const General_options
& options
,
1705 Symbol_table
* symtab
,
1707 Sized_relobj
<32, big_endian
>* object
,
1708 unsigned int data_shndx
,
1709 unsigned int sh_type
,
1710 const unsigned char* prelocs
,
1712 Output_section
* output_section
,
1713 bool needs_special_offset_handling
,
1714 size_t local_symbol_count
,
1715 const unsigned char* plocal_symbols
)
1717 typedef typename Target_arm
<big_endian
>::Scan Scan
;
1718 if (sh_type
== elfcpp::SHT_RELA
)
1720 gold_error(_("%s: unsupported RELA reloc section"),
1721 object
->name().c_str());
1725 gold::scan_relocs
<32, big_endian
, Target_arm
, elfcpp::SHT_REL
, Scan
>(
1735 needs_special_offset_handling
,
1740 // Finalize the sections.
1742 template<bool big_endian
>
1744 Target_arm
<big_endian
>::do_finalize_sections(Layout
* layout
)
1746 // Fill in some more dynamic tags.
1747 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
1750 if (this->got_plt_
!= NULL
)
1751 odyn
->add_section_address(elfcpp::DT_PLTGOT
, this->got_plt_
);
1753 if (this->plt_
!= NULL
)
1755 const Output_data
* od
= this->plt_
->rel_plt();
1756 odyn
->add_section_size(elfcpp::DT_PLTRELSZ
, od
);
1757 odyn
->add_section_address(elfcpp::DT_JMPREL
, od
);
1758 odyn
->add_constant(elfcpp::DT_PLTREL
, elfcpp::DT_REL
);
1761 if (this->rel_dyn_
!= NULL
)
1763 const Output_data
* od
= this->rel_dyn_
;
1764 odyn
->add_section_address(elfcpp::DT_REL
, od
);
1765 odyn
->add_section_size(elfcpp::DT_RELSZ
, od
);
1766 odyn
->add_constant(elfcpp::DT_RELENT
,
1767 elfcpp::Elf_sizes
<32>::rel_size
);
1770 if (!parameters
->options().shared())
1772 // The value of the DT_DEBUG tag is filled in by the dynamic
1773 // linker at run time, and used by the debugger.
1774 odyn
->add_constant(elfcpp::DT_DEBUG
, 0);
1778 // Emit any relocs we saved in an attempt to avoid generating COPY
1780 if (this->copy_relocs_
.any_saved_relocs())
1781 this->copy_relocs_
.emit(this->rel_dyn_section(layout
));
1783 // For the ARM target, we need to add a PT_ARM_EXIDX segment for
1784 // the .ARM.exidx section.
1785 if (!layout
->script_options()->saw_phdrs_clause()
1786 && !parameters
->options().relocatable())
1788 Output_section
* exidx_section
=
1789 layout
->find_output_section(".ARM.exidx");
1791 if (exidx_section
!= NULL
1792 && exidx_section
->type() == elfcpp::SHT_ARM_EXIDX
)
1794 gold_assert(layout
->find_output_segment(elfcpp::PT_ARM_EXIDX
, 0, 0)
1796 Output_segment
* exidx_segment
=
1797 layout
->make_output_segment(elfcpp::PT_ARM_EXIDX
, elfcpp::PF_R
);
1798 exidx_segment
->add_output_section(exidx_section
, elfcpp::PF_R
);
1803 // Return whether a direct absolute static relocation needs to be applied.
1804 // In cases where Scan::local() or Scan::global() has created
1805 // a dynamic relocation other than R_ARM_RELATIVE, the addend
1806 // of the relocation is carried in the data, and we must not
1807 // apply the static relocation.
1809 template<bool big_endian
>
1811 Target_arm
<big_endian
>::Relocate::should_apply_static_reloc(
1812 const Sized_symbol
<32>* gsym
,
1815 Output_section
* output_section
)
1817 // If the output section is not allocated, then we didn't call
1818 // scan_relocs, we didn't create a dynamic reloc, and we must apply
1820 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
1823 // For local symbols, we will have created a non-RELATIVE dynamic
1824 // relocation only if (a) the output is position independent,
1825 // (b) the relocation is absolute (not pc- or segment-relative), and
1826 // (c) the relocation is not 32 bits wide.
1828 return !(parameters
->options().output_is_position_independent()
1829 && (ref_flags
& Symbol::ABSOLUTE_REF
)
1832 // For global symbols, we use the same helper routines used in the
1833 // scan pass. If we did not create a dynamic relocation, or if we
1834 // created a RELATIVE dynamic relocation, we should apply the static
1836 bool has_dyn
= gsym
->needs_dynamic_reloc(ref_flags
);
1837 bool is_rel
= (ref_flags
& Symbol::ABSOLUTE_REF
)
1838 && gsym
->can_use_relative_reloc(ref_flags
1839 & Symbol::FUNCTION_CALL
);
1840 return !has_dyn
|| is_rel
;
1843 // Perform a relocation.
1845 template<bool big_endian
>
1847 Target_arm
<big_endian
>::Relocate::relocate(
1848 const Relocate_info
<32, big_endian
>* relinfo
,
1850 Output_section
*output_section
,
1852 const elfcpp::Rel
<32, big_endian
>& rel
,
1853 unsigned int r_type
,
1854 const Sized_symbol
<32>* gsym
,
1855 const Symbol_value
<32>* psymval
,
1856 unsigned char* view
,
1857 elfcpp::Elf_types
<32>::Elf_Addr address
,
1858 section_size_type
/* view_size */ )
1860 typedef Arm_relocate_functions
<big_endian
> Arm_relocate_functions
;
1862 r_type
= get_real_reloc_type(r_type
);
1864 // If this the symbol may be a Thumb function, set thumb bit to 1.
1865 bool has_thumb_bit
= ((gsym
!= NULL
)
1866 && (gsym
->type() == elfcpp::STT_FUNC
1867 || gsym
->type() == elfcpp::STT_ARM_TFUNC
));
1869 // Pick the value to use for symbols defined in shared objects.
1870 Symbol_value
<32> symval
;
1872 && gsym
->use_plt_offset(reloc_is_non_pic(r_type
)))
1874 symval
.set_output_value(target
->plt_section()->address()
1875 + gsym
->plt_offset());
1880 const Sized_relobj
<32, big_endian
>* object
= relinfo
->object
;
1882 // Get the GOT offset if needed.
1883 // The GOT pointer points to the end of the GOT section.
1884 // We need to subtract the size of the GOT section to get
1885 // the actual offset to use in the relocation.
1886 bool have_got_offset
= false;
1887 unsigned int got_offset
= 0;
1890 case elfcpp::R_ARM_GOT_BREL
:
1891 case elfcpp::R_ARM_GOT_PREL
:
1894 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
1895 got_offset
= (gsym
->got_offset(GOT_TYPE_STANDARD
)
1896 - target
->got_size());
1900 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
1901 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
1902 got_offset
= (object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
)
1903 - target
->got_size());
1905 have_got_offset
= true;
1912 typename
Arm_relocate_functions::Status reloc_status
=
1913 Arm_relocate_functions::STATUS_OKAY
;
1916 case elfcpp::R_ARM_NONE
:
1919 case elfcpp::R_ARM_ABS8
:
1920 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
1922 reloc_status
= Arm_relocate_functions::abs8(view
, object
, psymval
,
1926 case elfcpp::R_ARM_ABS32
:
1927 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
1929 reloc_status
= Arm_relocate_functions::abs32(view
, object
, psymval
,
1933 case elfcpp::R_ARM_MOVW_ABS_NC
:
1934 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
1936 reloc_status
= Arm_relocate_functions::movw_abs_nc(view
, object
,
1940 gold_error(_("relocation R_ARM_MOVW_ABS_NC cannot be used when making"
1941 "a shared object; recompile with -fPIC"));
1944 case elfcpp::R_ARM_MOVT_ABS
:
1945 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
1947 reloc_status
= Arm_relocate_functions::movt_abs(view
, object
, psymval
);
1949 gold_error(_("relocation R_ARM_MOVT_ABS cannot be used when making"
1950 "a shared object; recompile with -fPIC"));
1953 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
1954 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
1956 reloc_status
= Arm_relocate_functions::thm_movw_abs_nc(view
, object
,
1960 gold_error(_("relocation R_ARM_THM_MOVW_ABS_NC cannot be used when"
1961 "making a shared object; recompile with -fPIC"));
1964 case elfcpp::R_ARM_THM_MOVT_ABS
:
1965 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
1967 reloc_status
= Arm_relocate_functions::thm_movt_abs(view
, object
,
1970 gold_error(_("relocation R_ARM_THM_MOVT_ABS cannot be used when"
1971 "making a shared object; recompile with -fPIC"));
1974 case elfcpp::R_ARM_MOVW_PREL_NC
:
1975 reloc_status
= Arm_relocate_functions::movw_prel_nc(view
, object
,
1980 case elfcpp::R_ARM_MOVT_PREL
:
1981 reloc_status
= Arm_relocate_functions::movt_prel(view
, object
,
1985 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
1986 reloc_status
= Arm_relocate_functions::thm_movw_prel_nc(view
, object
,
1991 case elfcpp::R_ARM_THM_MOVT_PREL
:
1992 reloc_status
= Arm_relocate_functions::thm_movt_prel(view
, object
,
1996 case elfcpp::R_ARM_REL32
:
1997 reloc_status
= Arm_relocate_functions::rel32(view
, object
, psymval
,
1998 address
, has_thumb_bit
);
2001 case elfcpp::R_ARM_THM_CALL
:
2002 reloc_status
= Arm_relocate_functions::thm_call(view
, object
, psymval
,
2003 address
, has_thumb_bit
);
2006 case elfcpp::R_ARM_GOTOFF32
:
2008 elfcpp::Elf_types
<32>::Elf_Addr got_origin
;
2009 got_origin
= target
->got_plt_section()->address();
2010 reloc_status
= Arm_relocate_functions::rel32(view
, object
, psymval
,
2011 got_origin
, has_thumb_bit
);
2015 case elfcpp::R_ARM_BASE_PREL
:
2018 // Get the addressing origin of the output segment defining the
2019 // symbol gsym (AAELF 4.6.1.2 Relocation types)
2020 gold_assert(gsym
!= NULL
);
2021 if (gsym
->source() == Symbol::IN_OUTPUT_SEGMENT
)
2022 origin
= gsym
->output_segment()->vaddr();
2023 else if (gsym
->source () == Symbol::IN_OUTPUT_DATA
)
2024 origin
= gsym
->output_data()->address();
2027 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
2028 _("cannot find origin of R_ARM_BASE_PREL"));
2031 reloc_status
= Arm_relocate_functions::base_prel(view
, origin
, address
);
2035 case elfcpp::R_ARM_GOT_BREL
:
2036 gold_assert(have_got_offset
);
2037 reloc_status
= Arm_relocate_functions::got_brel(view
, got_offset
);
2040 case elfcpp::R_ARM_GOT_PREL
:
2041 gold_assert(have_got_offset
);
2042 // Get the address origin for GOT PLT, which is allocated right
2043 // after the GOT section, to calculate an absolute address of
2044 // the symbol GOT entry (got_origin + got_offset).
2045 elfcpp::Elf_types
<32>::Elf_Addr got_origin
;
2046 got_origin
= target
->got_plt_section()->address();
2047 reloc_status
= Arm_relocate_functions::got_prel(view
,
2048 got_origin
+ got_offset
,
2052 case elfcpp::R_ARM_PLT32
:
2053 gold_assert(gsym
== NULL
2054 || gsym
->has_plt_offset()
2055 || gsym
->final_value_is_known()
2056 || (gsym
->is_defined()
2057 && !gsym
->is_from_dynobj()
2058 && !gsym
->is_preemptible()));
2059 reloc_status
= Arm_relocate_functions::plt32(view
, object
, psymval
,
2060 address
, has_thumb_bit
);
2063 case elfcpp::R_ARM_CALL
:
2064 reloc_status
= Arm_relocate_functions::call(view
, object
, psymval
,
2065 address
, has_thumb_bit
);
2068 case elfcpp::R_ARM_JUMP24
:
2069 reloc_status
= Arm_relocate_functions::jump24(view
, object
, psymval
,
2070 address
, has_thumb_bit
);
2073 case elfcpp::R_ARM_PREL31
:
2074 reloc_status
= Arm_relocate_functions::prel31(view
, object
, psymval
,
2075 address
, has_thumb_bit
);
2078 case elfcpp::R_ARM_TARGET1
:
2079 // This should have been mapped to another type already.
2081 case elfcpp::R_ARM_COPY
:
2082 case elfcpp::R_ARM_GLOB_DAT
:
2083 case elfcpp::R_ARM_JUMP_SLOT
:
2084 case elfcpp::R_ARM_RELATIVE
:
2085 // These are relocations which should only be seen by the
2086 // dynamic linker, and should never be seen here.
2087 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
2088 _("unexpected reloc %u in object file"),
2093 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
2094 _("unsupported reloc %u"),
2099 // Report any errors.
2100 switch (reloc_status
)
2102 case Arm_relocate_functions::STATUS_OKAY
:
2104 case Arm_relocate_functions::STATUS_OVERFLOW
:
2105 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
2106 _("relocation overflow in relocation %u"),
2109 case Arm_relocate_functions::STATUS_BAD_RELOC
:
2110 gold_error_at_location(
2114 _("unexpected opcode while processing relocation %u"),
2124 // Relocate section data.
2126 template<bool big_endian
>
2128 Target_arm
<big_endian
>::relocate_section(
2129 const Relocate_info
<32, big_endian
>* relinfo
,
2130 unsigned int sh_type
,
2131 const unsigned char* prelocs
,
2133 Output_section
* output_section
,
2134 bool needs_special_offset_handling
,
2135 unsigned char* view
,
2136 elfcpp::Elf_types
<32>::Elf_Addr address
,
2137 section_size_type view_size
,
2138 const Reloc_symbol_changes
* reloc_symbol_changes
)
2140 typedef typename Target_arm
<big_endian
>::Relocate Arm_relocate
;
2141 gold_assert(sh_type
== elfcpp::SHT_REL
);
2143 gold::relocate_section
<32, big_endian
, Target_arm
, elfcpp::SHT_REL
,
2150 needs_special_offset_handling
,
2154 reloc_symbol_changes
);
2157 // Return the size of a relocation while scanning during a relocatable
2160 template<bool big_endian
>
2162 Target_arm
<big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
2163 unsigned int r_type
,
2166 r_type
= get_real_reloc_type(r_type
);
2169 case elfcpp::R_ARM_NONE
:
2172 case elfcpp::R_ARM_ABS8
:
2175 case elfcpp::R_ARM_ABS32
:
2176 case elfcpp::R_ARM_REL32
:
2177 case elfcpp::R_ARM_THM_CALL
:
2178 case elfcpp::R_ARM_GOTOFF32
:
2179 case elfcpp::R_ARM_BASE_PREL
:
2180 case elfcpp::R_ARM_GOT_BREL
:
2181 case elfcpp::R_ARM_GOT_PREL
:
2182 case elfcpp::R_ARM_PLT32
:
2183 case elfcpp::R_ARM_CALL
:
2184 case elfcpp::R_ARM_JUMP24
:
2185 case elfcpp::R_ARM_PREL31
:
2186 case elfcpp::R_ARM_MOVW_ABS_NC
:
2187 case elfcpp::R_ARM_MOVT_ABS
:
2188 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
2189 case elfcpp::R_ARM_THM_MOVT_ABS
:
2190 case elfcpp::R_ARM_MOVW_PREL_NC
:
2191 case elfcpp::R_ARM_MOVT_PREL
:
2192 case elfcpp::R_ARM_THM_MOVW_PREL_NC
:
2193 case elfcpp::R_ARM_THM_MOVT_PREL
:
2196 case elfcpp::R_ARM_TARGET1
:
2197 // This should have been mapped to another type already.
2199 case elfcpp::R_ARM_COPY
:
2200 case elfcpp::R_ARM_GLOB_DAT
:
2201 case elfcpp::R_ARM_JUMP_SLOT
:
2202 case elfcpp::R_ARM_RELATIVE
:
2203 // These are relocations which should only be seen by the
2204 // dynamic linker, and should never be seen here.
2205 gold_error(_("%s: unexpected reloc %u in object file"),
2206 object
->name().c_str(), r_type
);
2210 object
->error(_("unsupported reloc %u in object file"), r_type
);
2215 // Scan the relocs during a relocatable link.
2217 template<bool big_endian
>
2219 Target_arm
<big_endian
>::scan_relocatable_relocs(
2220 const General_options
& options
,
2221 Symbol_table
* symtab
,
2223 Sized_relobj
<32, big_endian
>* object
,
2224 unsigned int data_shndx
,
2225 unsigned int sh_type
,
2226 const unsigned char* prelocs
,
2228 Output_section
* output_section
,
2229 bool needs_special_offset_handling
,
2230 size_t local_symbol_count
,
2231 const unsigned char* plocal_symbols
,
2232 Relocatable_relocs
* rr
)
2234 gold_assert(sh_type
== elfcpp::SHT_REL
);
2236 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_REL
,
2237 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
2239 gold::scan_relocatable_relocs
<32, big_endian
, elfcpp::SHT_REL
,
2240 Scan_relocatable_relocs
>(
2249 needs_special_offset_handling
,
2255 // Relocate a section during a relocatable link.
2257 template<bool big_endian
>
2259 Target_arm
<big_endian
>::relocate_for_relocatable(
2260 const Relocate_info
<32, big_endian
>* relinfo
,
2261 unsigned int sh_type
,
2262 const unsigned char* prelocs
,
2264 Output_section
* output_section
,
2265 off_t offset_in_output_section
,
2266 const Relocatable_relocs
* rr
,
2267 unsigned char* view
,
2268 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
2269 section_size_type view_size
,
2270 unsigned char* reloc_view
,
2271 section_size_type reloc_view_size
)
2273 gold_assert(sh_type
== elfcpp::SHT_REL
);
2275 gold::relocate_for_relocatable
<32, big_endian
, elfcpp::SHT_REL
>(
2280 offset_in_output_section
,
2289 // Return the value to use for a dynamic symbol which requires special
2290 // treatment. This is how we support equality comparisons of function
2291 // pointers across shared library boundaries, as described in the
2292 // processor specific ABI supplement.
2294 template<bool big_endian
>
2296 Target_arm
<big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
2298 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
2299 return this->plt_section()->address() + gsym
->plt_offset();
2302 // Map platform-specific relocs to real relocs
2304 template<bool big_endian
>
2306 Target_arm
<big_endian
>::get_real_reloc_type (unsigned int r_type
)
2310 case elfcpp::R_ARM_TARGET1
:
2311 // This is either R_ARM_ABS32 or R_ARM_REL32;
2312 return elfcpp::R_ARM_ABS32
;
2314 case elfcpp::R_ARM_TARGET2
:
2315 // This can be any reloc type but ususally is R_ARM_GOT_PREL
2316 return elfcpp::R_ARM_GOT_PREL
;
2323 // The selector for arm object files.
2325 template<bool big_endian
>
2326 class Target_selector_arm
: public Target_selector
2329 Target_selector_arm()
2330 : Target_selector(elfcpp::EM_ARM
, 32, big_endian
,
2331 (big_endian
? "elf32-bigarm" : "elf32-littlearm"))
2335 do_instantiate_target()
2336 { return new Target_arm
<big_endian
>(); }
2339 Target_selector_arm
<false> target_selector_arm
;
2340 Target_selector_arm
<true> target_selector_armbe
;
2342 } // End anonymous namespace.