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 // - Generate various branch stubs.
85 // - Support interworking.
86 // - Define section symbols __exidx_start and __exidx_stop.
87 // - Support more relocation types as needed.
88 // - Make PLTs more flexible for different architecture features like
90 // There are probably a lot more.
92 // Utilities for manipulating integers of up to 32-bits
96 // Sign extend an n-bit unsigned integer stored in an uint32_t into
97 // an int32_t. NO_BITS must be between 1 to 32.
100 sign_extend(uint32_t bits
)
102 gold_assert(no_bits
>= 0 && no_bits
<= 32);
104 return static_cast<int32_t>(bits
);
105 uint32_t mask
= (~((uint32_t) 0)) >> (32 - no_bits
);
107 uint32_t top_bit
= 1U << (no_bits
- 1);
108 int32_t as_signed
= static_cast<int32_t>(bits
);
109 return (bits
& top_bit
) ? as_signed
+ (-top_bit
* 2) : as_signed
;
112 // Detects overflow of an NO_BITS integer stored in a uint32_t.
113 template<int no_bits
>
115 has_overflow(uint32_t bits
)
117 gold_assert(no_bits
>= 0 && no_bits
<= 32);
120 int32_t max
= (1 << (no_bits
- 1)) - 1;
121 int32_t min
= -(1 << (no_bits
- 1));
122 int32_t as_signed
= static_cast<int32_t>(bits
);
123 return as_signed
> max
|| as_signed
< min
;
126 // Detects overflow of an NO_BITS integer stored in a uint32_t when it
127 // fits in the given number of bits as either a signed or unsigned value.
128 // For example, has_signed_unsigned_overflow<8> would check
129 // -128 <= bits <= 255
130 template<int no_bits
>
132 has_signed_unsigned_overflow(uint32_t bits
)
134 gold_assert(no_bits
>= 2 && no_bits
<= 32);
137 int32_t max
= static_cast<int32_t>((1U << no_bits
) - 1);
138 int32_t min
= -(1 << (no_bits
- 1));
139 int32_t as_signed
= static_cast<int32_t>(bits
);
140 return as_signed
> max
|| as_signed
< min
;
143 // Select bits from A and B using bits in MASK. For each n in [0..31],
144 // the n-th bit in the result is chosen from the n-th bits of A and B.
145 // A zero selects A and a one selects B.
146 static inline uint32_t
147 bit_select(uint32_t a
, uint32_t b
, uint32_t mask
)
148 { return (a
& ~mask
) | (b
& mask
); }
151 template<bool big_endian
>
152 class Target_arm
: public Sized_target
<32, big_endian
>
155 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, big_endian
>
159 : Sized_target
<32, big_endian
>(&arm_info
),
160 got_(NULL
), plt_(NULL
), got_plt_(NULL
), rel_dyn_(NULL
),
161 copy_relocs_(elfcpp::R_ARM_COPY
), dynbss_(NULL
)
164 // Process the relocations to determine unreferenced sections for
165 // garbage collection.
167 gc_process_relocs(const General_options
& options
,
168 Symbol_table
* symtab
,
170 Sized_relobj
<32, big_endian
>* object
,
171 unsigned int data_shndx
,
172 unsigned int sh_type
,
173 const unsigned char* prelocs
,
175 Output_section
* output_section
,
176 bool needs_special_offset_handling
,
177 size_t local_symbol_count
,
178 const unsigned char* plocal_symbols
);
180 // Scan the relocations to look for symbol adjustments.
182 scan_relocs(const General_options
& options
,
183 Symbol_table
* symtab
,
185 Sized_relobj
<32, big_endian
>* object
,
186 unsigned int data_shndx
,
187 unsigned int sh_type
,
188 const unsigned char* prelocs
,
190 Output_section
* output_section
,
191 bool needs_special_offset_handling
,
192 size_t local_symbol_count
,
193 const unsigned char* plocal_symbols
);
195 // Finalize the sections.
197 do_finalize_sections(Layout
*);
199 // Return the value to use for a dynamic symbol which requires special
202 do_dynsym_value(const Symbol
*) const;
204 // Relocate a section.
206 relocate_section(const Relocate_info
<32, big_endian
>*,
207 unsigned int sh_type
,
208 const unsigned char* prelocs
,
210 Output_section
* output_section
,
211 bool needs_special_offset_handling
,
213 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
214 section_size_type view_size
,
215 const Reloc_symbol_changes
*);
217 // Scan the relocs during a relocatable link.
219 scan_relocatable_relocs(const General_options
& options
,
220 Symbol_table
* symtab
,
222 Sized_relobj
<32, big_endian
>* object
,
223 unsigned int data_shndx
,
224 unsigned int sh_type
,
225 const unsigned char* prelocs
,
227 Output_section
* output_section
,
228 bool needs_special_offset_handling
,
229 size_t local_symbol_count
,
230 const unsigned char* plocal_symbols
,
231 Relocatable_relocs
*);
233 // Relocate a section during a relocatable link.
235 relocate_for_relocatable(const Relocate_info
<32, big_endian
>*,
236 unsigned int sh_type
,
237 const unsigned char* prelocs
,
239 Output_section
* output_section
,
240 off_t offset_in_output_section
,
241 const Relocatable_relocs
*,
243 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
244 section_size_type view_size
,
245 unsigned char* reloc_view
,
246 section_size_type reloc_view_size
);
248 // Return whether SYM is defined by the ABI.
250 do_is_defined_by_abi(Symbol
* sym
) const
251 { return strcmp(sym
->name(), "__tls_get_addr") == 0; }
253 // Return the size of the GOT section.
257 gold_assert(this->got_
!= NULL
);
258 return this->got_
->data_size();
261 // Map platform-specific reloc types
263 get_real_reloc_type (unsigned int r_type
);
266 // The class which scans relocations.
271 : issued_non_pic_error_(false)
275 local(const General_options
& options
, Symbol_table
* symtab
,
276 Layout
* layout
, Target_arm
* target
,
277 Sized_relobj
<32, big_endian
>* object
,
278 unsigned int data_shndx
,
279 Output_section
* output_section
,
280 const elfcpp::Rel
<32, big_endian
>& reloc
, unsigned int r_type
,
281 const elfcpp::Sym
<32, big_endian
>& lsym
);
284 global(const General_options
& options
, Symbol_table
* symtab
,
285 Layout
* layout
, Target_arm
* target
,
286 Sized_relobj
<32, big_endian
>* object
,
287 unsigned int data_shndx
,
288 Output_section
* output_section
,
289 const elfcpp::Rel
<32, big_endian
>& reloc
, unsigned int r_type
,
294 unsupported_reloc_local(Sized_relobj
<32, big_endian
>*,
295 unsigned int r_type
);
298 unsupported_reloc_global(Sized_relobj
<32, big_endian
>*,
299 unsigned int r_type
, Symbol
*);
302 check_non_pic(Relobj
*, unsigned int r_type
);
304 // Almost identical to Symbol::needs_plt_entry except that it also
305 // handles STT_ARM_TFUNC.
307 symbol_needs_plt_entry(const Symbol
* sym
)
309 // An undefined symbol from an executable does not need a PLT entry.
310 if (sym
->is_undefined() && !parameters
->options().shared())
313 return (!parameters
->doing_static_link()
314 && (sym
->type() == elfcpp::STT_FUNC
315 || sym
->type() == elfcpp::STT_ARM_TFUNC
)
316 && (sym
->is_from_dynobj()
317 || sym
->is_undefined()
318 || sym
->is_preemptible()));
321 // Whether we have issued an error about a non-PIC compilation.
322 bool issued_non_pic_error_
;
325 // The class which implements relocation.
335 // Return whether the static relocation needs to be applied.
337 should_apply_static_reloc(const Sized_symbol
<32>* gsym
,
340 Output_section
* output_section
);
342 // Do a relocation. Return false if the caller should not issue
343 // any warnings about this relocation.
345 relocate(const Relocate_info
<32, big_endian
>*, Target_arm
*,
346 Output_section
*, size_t relnum
,
347 const elfcpp::Rel
<32, big_endian
>&,
348 unsigned int r_type
, const Sized_symbol
<32>*,
349 const Symbol_value
<32>*,
350 unsigned char*, elfcpp::Elf_types
<32>::Elf_Addr
,
353 // Return whether we want to pass flag NON_PIC_REF for this
356 reloc_is_non_pic (unsigned int r_type
)
360 case elfcpp::R_ARM_REL32
:
361 case elfcpp::R_ARM_THM_CALL
:
362 case elfcpp::R_ARM_CALL
:
363 case elfcpp::R_ARM_JUMP24
:
364 case elfcpp::R_ARM_PREL31
:
372 // A class which returns the size required for a relocation type,
373 // used while scanning relocs during a relocatable link.
374 class Relocatable_size_for_reloc
378 get_size_for_reloc(unsigned int, Relobj
*);
381 // Get the GOT section, creating it if necessary.
382 Output_data_got
<32, big_endian
>*
383 got_section(Symbol_table
*, Layout
*);
385 // Get the GOT PLT section.
387 got_plt_section() const
389 gold_assert(this->got_plt_
!= NULL
);
390 return this->got_plt_
;
393 // Create a PLT entry for a global symbol.
395 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
397 // Get the PLT section.
398 const Output_data_plt_arm
<big_endian
>*
401 gold_assert(this->plt_
!= NULL
);
405 // Get the dynamic reloc section, creating it if necessary.
407 rel_dyn_section(Layout
*);
409 // Return true if the symbol may need a COPY relocation.
410 // References from an executable object to non-function symbols
411 // defined in a dynamic object may need a COPY relocation.
413 may_need_copy_reloc(Symbol
* gsym
)
415 return (gsym
->type() != elfcpp::STT_ARM_TFUNC
416 && gsym
->may_need_copy_reloc());
419 // Add a potential copy relocation.
421 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
422 Sized_relobj
<32, big_endian
>* object
,
423 unsigned int shndx
, Output_section
* output_section
,
424 Symbol
* sym
, const elfcpp::Rel
<32, big_endian
>& reloc
)
426 this->copy_relocs_
.copy_reloc(symtab
, layout
,
427 symtab
->get_sized_symbol
<32>(sym
),
428 object
, shndx
, output_section
, reloc
,
429 this->rel_dyn_section(layout
));
432 // Information about this specific target which we pass to the
433 // general Target structure.
434 static const Target::Target_info arm_info
;
436 // The types of GOT entries needed for this platform.
439 GOT_TYPE_STANDARD
= 0 // GOT entry for a regular symbol
443 Output_data_got
<32, big_endian
>* got_
;
445 Output_data_plt_arm
<big_endian
>* plt_
;
446 // The GOT PLT section.
447 Output_data_space
* got_plt_
;
448 // The dynamic reloc section.
449 Reloc_section
* rel_dyn_
;
450 // Relocs saved to avoid a COPY reloc.
451 Copy_relocs
<elfcpp::SHT_REL
, 32, big_endian
> copy_relocs_
;
452 // Space for variables copied with a COPY reloc.
453 Output_data_space
* dynbss_
;
456 template<bool big_endian
>
457 const Target::Target_info Target_arm
<big_endian
>::arm_info
=
460 big_endian
, // is_big_endian
461 elfcpp::EM_ARM
, // machine_code
462 false, // has_make_symbol
463 false, // has_resolve
464 false, // has_code_fill
465 true, // is_default_stack_executable
467 "/usr/lib/libc.so.1", // dynamic_linker
468 0x8000, // default_text_segment_address
469 0x1000, // abi_pagesize (overridable by -z max-page-size)
470 0x1000, // common_pagesize (overridable by -z common-page-size)
471 elfcpp::SHN_UNDEF
, // small_common_shndx
472 elfcpp::SHN_UNDEF
, // large_common_shndx
473 0, // small_common_section_flags
474 0 // large_common_section_flags
477 // Arm relocate functions class
480 template<bool big_endian
>
481 class Arm_relocate_functions
: public Relocate_functions
<32, big_endian
>
486 STATUS_OKAY
, // No error during relocation.
487 STATUS_OVERFLOW
, // Relocation oveflow.
488 STATUS_BAD_RELOC
// Relocation cannot be applied.
492 typedef Relocate_functions
<32, big_endian
> Base
;
493 typedef Arm_relocate_functions
<big_endian
> This
;
495 // Get an symbol value of *PSYMVAL with an ADDEND. This is a wrapper
496 // to Symbol_value::value(). If HAS_THUMB_BIT is true, that LSB is used
497 // to distinguish ARM and THUMB functions and it is treated specially.
498 static inline Symbol_value
<32>::Value
499 arm_symbol_value (const Sized_relobj
<32, big_endian
> *object
,
500 const Symbol_value
<32>* psymval
,
501 Symbol_value
<32>::Value addend
,
504 typedef Symbol_value
<32>::Value Valtype
;
508 Valtype raw
= psymval
->value(object
, 0);
509 Valtype thumb_bit
= raw
& 1;
510 return ((raw
& ~((Valtype
) 1)) + addend
) | thumb_bit
;
513 return psymval
->value(object
, addend
);
516 // Encoding of imm16 argument for movt and movw ARM instructions
519 // imm16 := imm4 | imm12
521 // 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
522 // +-------+---------------+-------+-------+-----------------------+
523 // | | |imm4 | |imm12 |
524 // +-------+---------------+-------+-------+-----------------------+
526 // Extract the relocation addend from VAL based on the ARM
527 // instruction encoding described above.
528 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
529 extract_arm_movw_movt_addend(
530 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
)
532 // According to the Elf ABI for ARM Architecture the immediate
533 // field is sign-extended to form the addend.
534 return utils::sign_extend
<16>(((val
>> 4) & 0xf000) | (val
& 0xfff));
537 // Insert X into VAL based on the ARM instruction encoding described
539 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
540 insert_val_arm_movw_movt(
541 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
,
542 typename
elfcpp::Swap
<32, big_endian
>::Valtype x
)
546 val
|= (x
& 0xf000) << 4;
550 // Encoding of imm16 argument for movt and movw Thumb2 instructions
553 // imm16 := imm4 | i | imm3 | imm8
555 // 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
556 // +---------+-+-----------+-------++-+-----+-------+---------------+
557 // | |i| |imm4 || |imm3 | |imm8 |
558 // +---------+-+-----------+-------++-+-----+-------+---------------+
560 // Extract the relocation addend from VAL based on the Thumb2
561 // instruction encoding described above.
562 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
563 extract_thumb_movw_movt_addend(
564 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
)
566 // According to the Elf ABI for ARM Architecture the immediate
567 // field is sign-extended to form the addend.
568 return utils::sign_extend
<16>(((val
>> 4) & 0xf000)
569 | ((val
>> 15) & 0x0800)
570 | ((val
>> 4) & 0x0700)
574 // Insert X into VAL based on the Thumb2 instruction encoding
576 static inline typename
elfcpp::Swap
<32, big_endian
>::Valtype
577 insert_val_thumb_movw_movt(
578 typename
elfcpp::Swap
<32, big_endian
>::Valtype val
,
579 typename
elfcpp::Swap
<32, big_endian
>::Valtype x
)
582 val
|= (x
& 0xf000) << 4;
583 val
|= (x
& 0x0800) << 15;
584 val
|= (x
& 0x0700) << 4;
589 // FIXME: This probably only works for Android on ARM v5te. We should
590 // following GNU ld for the general case.
591 template<unsigned r_type
>
592 static inline typename
This::Status
593 arm_branch_common(unsigned char *view
,
594 const Sized_relobj
<32, big_endian
>* object
,
595 const Symbol_value
<32>* psymval
,
596 elfcpp::Elf_types
<32>::Elf_Addr address
,
599 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
600 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
601 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
603 bool insn_is_b
= (((val
>> 28) & 0xf) <= 0xe)
604 && ((val
& 0x0f000000UL
) == 0x0a000000UL
);
605 bool insn_is_uncond_bl
= (val
& 0xff000000UL
) == 0xeb000000UL
;
606 bool insn_is_cond_bl
= (((val
>> 28) & 0xf) < 0xe)
607 && ((val
& 0x0f000000UL
) == 0x0b000000UL
);
608 bool insn_is_blx
= (val
& 0xfe000000UL
) == 0xfa000000UL
;
609 bool insn_is_any_branch
= (val
& 0x0e000000UL
) == 0x0a000000UL
;
611 if (r_type
== elfcpp::R_ARM_CALL
)
613 if (!insn_is_uncond_bl
&& !insn_is_blx
)
614 return This::STATUS_BAD_RELOC
;
616 else if (r_type
== elfcpp::R_ARM_JUMP24
)
618 if (!insn_is_b
&& !insn_is_cond_bl
)
619 return This::STATUS_BAD_RELOC
;
621 else if (r_type
== elfcpp::R_ARM_PLT32
)
623 if (!insn_is_any_branch
)
624 return This::STATUS_BAD_RELOC
;
629 Valtype addend
= utils::sign_extend
<26>(val
<< 2);
630 Valtype x
= (This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
)
633 // If target has thumb bit set, we need to either turn the BL
634 // into a BLX (for ARMv5 or above) or generate a stub.
638 if (insn_is_uncond_bl
)
639 val
= (val
& 0xffffff) | 0xfa000000 | ((x
& 2) << 23);
641 return This::STATUS_BAD_RELOC
;
644 gold_assert(!insn_is_blx
);
646 val
= utils::bit_select(val
, (x
>> 2), 0xffffffUL
);
647 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
648 return (utils::has_overflow
<26>(x
)
649 ? This::STATUS_OVERFLOW
: This::STATUS_OKAY
);
655 static inline typename
This::Status
656 abs8(unsigned char *view
,
657 const Sized_relobj
<32, big_endian
>* object
,
658 const Symbol_value
<32>* psymval
, bool has_thumb_bit
)
660 typedef typename
elfcpp::Swap
<8, big_endian
>::Valtype Valtype
;
661 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
662 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
663 Valtype val
= elfcpp::Swap
<8, big_endian
>::readval(wv
);
664 Reltype addend
= utils::sign_extend
<8>(val
);
665 Reltype x
= This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
);
666 val
= utils::bit_select(val
, x
, 0xffU
);
667 elfcpp::Swap
<8, big_endian
>::writeval(wv
, val
);
668 return (utils::has_signed_unsigned_overflow
<8>(x
)
669 ? This::STATUS_OVERFLOW
670 : This::STATUS_OKAY
);
673 // R_ARM_ABS32: (S + A) | T
674 static inline typename
This::Status
675 abs32(unsigned char *view
,
676 const Sized_relobj
<32, big_endian
>* object
,
677 const Symbol_value
<32>* psymval
,
680 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
681 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
682 Valtype addend
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
683 Valtype x
= This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
);
684 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
685 return This::STATUS_OKAY
;
688 // R_ARM_REL32: (S + A) | T - P
689 static inline typename
This::Status
690 rel32(unsigned char *view
,
691 const Sized_relobj
<32, big_endian
>* object
,
692 const Symbol_value
<32>* psymval
,
693 elfcpp::Elf_types
<32>::Elf_Addr address
,
696 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
697 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
698 Valtype addend
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
699 Valtype x
= (This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
)
701 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
702 return This::STATUS_OKAY
;
705 // R_ARM_THM_CALL: (S + A) | T - P
706 static inline typename
This::Status
707 thm_call(unsigned char *view
,
708 const Sized_relobj
<32, big_endian
>* object
,
709 const Symbol_value
<32>* psymval
,
710 elfcpp::Elf_types
<32>::Elf_Addr address
,
713 // A thumb call consists of two instructions.
714 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
715 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
716 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
717 Valtype hi
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
718 Valtype lo
= elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1);
719 // Must be a BL instruction. lo == 11111xxxxxxxxxxx.
720 gold_assert((lo
& 0xf800) == 0xf800);
721 Reltype addend
= utils::sign_extend
<23>(((hi
& 0x7ff) << 12)
722 | ((lo
& 0x7ff) << 1));
723 Reltype x
= (This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
)
726 // If target has no thumb bit set, we need to either turn the BL
727 // into a BLX (for ARMv5 or above) or generate a stub.
730 // This only works for ARMv5 and above with interworking enabled.
733 hi
= utils::bit_select(hi
, (x
>> 12), 0x7ffU
);
734 lo
= utils::bit_select(lo
, (x
>> 1), 0x7ffU
);
735 elfcpp::Swap
<16, big_endian
>::writeval(wv
, hi
);
736 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, lo
);
737 return (utils::has_overflow
<23>(x
)
738 ? This::STATUS_OVERFLOW
739 : This::STATUS_OKAY
);
742 // R_ARM_BASE_PREL: B(S) + A - P
743 static inline typename
This::Status
744 base_prel(unsigned char* view
,
745 elfcpp::Elf_types
<32>::Elf_Addr origin
,
746 elfcpp::Elf_types
<32>::Elf_Addr address
)
748 Base::rel32(view
, origin
- address
);
752 // R_ARM_GOT_BREL: GOT(S) + A - GOT_ORG
753 static inline typename
This::Status
754 got_brel(unsigned char* view
,
755 typename
elfcpp::Swap
<32, big_endian
>::Valtype got_offset
)
757 Base::rel32(view
, got_offset
);
758 return This::STATUS_OKAY
;
761 // R_ARM_GOT_PREL: GOT(S) + A – P
762 static inline typename
This::Status
763 got_prel(unsigned char* view
,
764 typename
elfcpp::Swap
<32, big_endian
>::Valtype got_offset
,
765 elfcpp::Elf_types
<32>::Elf_Addr address
)
767 Base::rel32(view
, got_offset
- address
);
768 return This::STATUS_OKAY
;
771 // R_ARM_PLT32: (S + A) | T - P
772 static inline typename
This::Status
773 plt32(unsigned char *view
,
774 const Sized_relobj
<32, big_endian
>* object
,
775 const Symbol_value
<32>* psymval
,
776 elfcpp::Elf_types
<32>::Elf_Addr address
,
779 return arm_branch_common
<elfcpp::R_ARM_PLT32
>(view
, object
, psymval
,
780 address
, has_thumb_bit
);
783 // R_ARM_CALL: (S + A) | T - P
784 static inline typename
This::Status
785 call(unsigned char *view
,
786 const Sized_relobj
<32, big_endian
>* object
,
787 const Symbol_value
<32>* psymval
,
788 elfcpp::Elf_types
<32>::Elf_Addr address
,
791 return arm_branch_common
<elfcpp::R_ARM_CALL
>(view
, object
, psymval
,
792 address
, has_thumb_bit
);
795 // R_ARM_JUMP24: (S + A) | T - P
796 static inline typename
This::Status
797 jump24(unsigned char *view
,
798 const Sized_relobj
<32, big_endian
>* object
,
799 const Symbol_value
<32>* psymval
,
800 elfcpp::Elf_types
<32>::Elf_Addr address
,
803 return arm_branch_common
<elfcpp::R_ARM_JUMP24
>(view
, object
, psymval
,
804 address
, has_thumb_bit
);
807 // R_ARM_PREL: (S + A) | T - P
808 static inline typename
This::Status
809 prel31(unsigned char *view
,
810 const Sized_relobj
<32, big_endian
>* object
,
811 const Symbol_value
<32>* psymval
,
812 elfcpp::Elf_types
<32>::Elf_Addr address
,
815 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
816 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
817 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
818 Valtype addend
= utils::sign_extend
<31>(val
);
819 Valtype x
= (This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
)
821 val
= utils::bit_select(val
, x
, 0x7fffffffU
);
822 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
823 return (utils::has_overflow
<31>(x
) ?
824 This::STATUS_OVERFLOW
: This::STATUS_OKAY
);
827 // R_ARM_MOVW_ABS_NC: (S + A) | T
828 static inline typename
This::Status
829 movw_abs_nc(unsigned char *view
,
830 const Sized_relobj
<32, big_endian
>* object
,
831 const Symbol_value
<32>* psymval
,
834 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
835 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
836 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
837 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
838 Valtype x
= This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
);
839 val
= This::insert_val_arm_movw_movt(val
, x
);
840 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
841 return This::STATUS_OKAY
;
844 // R_ARM_MOVT_ABS: S + A
845 static inline typename
This::Status
846 movt_abs(unsigned char *view
,
847 const Sized_relobj
<32, big_endian
>* object
,
848 const Symbol_value
<32>* psymval
)
850 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
851 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
852 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
853 Valtype addend
= This::extract_arm_movw_movt_addend(val
);
854 Valtype x
= This::arm_symbol_value(object
, psymval
, addend
, 0) >> 16;
855 val
= This::insert_val_arm_movw_movt(val
, x
);
856 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
857 return This::STATUS_OKAY
;
860 // R_ARM_THM_MOVW_ABS_NC: S + A | T
861 static inline typename
This::Status
862 thm_movw_abs_nc(unsigned char *view
,
863 const Sized_relobj
<32, big_endian
>* object
,
864 const Symbol_value
<32>* psymval
,
867 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
868 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
869 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
870 Reltype val
= ((elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
871 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1));
872 Reltype addend
= extract_thumb_movw_movt_addend(val
);
873 Reltype x
= This::arm_symbol_value(object
, psymval
, addend
, has_thumb_bit
);
874 val
= This::insert_val_thumb_movw_movt(val
, x
);
875 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
876 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
877 return This::STATUS_OKAY
;
880 // R_ARM_THM_MOVT_ABS: S + A
881 static inline typename
This::Status
882 thm_movt_abs(unsigned char *view
,
883 const Sized_relobj
<32, big_endian
>* object
,
884 const Symbol_value
<32>* psymval
)
886 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype
;
887 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Reltype
;
888 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
889 Reltype val
= ((elfcpp::Swap
<16, big_endian
>::readval(wv
) << 16)
890 | elfcpp::Swap
<16, big_endian
>::readval(wv
+ 1));
891 Reltype addend
= This::extract_thumb_movw_movt_addend(val
);
892 Reltype x
= This::arm_symbol_value(object
, psymval
, addend
, 0) >> 16;
893 val
= This::insert_val_thumb_movw_movt(val
, x
);
894 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
>> 16);
895 elfcpp::Swap
<16, big_endian
>::writeval(wv
+ 1, val
& 0xffff);
896 return This::STATUS_OKAY
;
901 // Get the GOT section, creating it if necessary.
903 template<bool big_endian
>
904 Output_data_got
<32, big_endian
>*
905 Target_arm
<big_endian
>::got_section(Symbol_table
* symtab
, Layout
* layout
)
907 if (this->got_
== NULL
)
909 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
911 this->got_
= new Output_data_got
<32, big_endian
>();
914 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
916 | elfcpp::SHF_WRITE
),
920 // The old GNU linker creates a .got.plt section. We just
921 // create another set of data in the .got section. Note that we
922 // always create a PLT if we create a GOT, although the PLT
924 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
925 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
927 | elfcpp::SHF_WRITE
),
931 // The first three entries are reserved.
932 this->got_plt_
->set_current_data_size(3 * 4);
934 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
935 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
937 0, 0, elfcpp::STT_OBJECT
,
939 elfcpp::STV_HIDDEN
, 0,
945 // Get the dynamic reloc section, creating it if necessary.
947 template<bool big_endian
>
948 typename Target_arm
<big_endian
>::Reloc_section
*
949 Target_arm
<big_endian
>::rel_dyn_section(Layout
* layout
)
951 if (this->rel_dyn_
== NULL
)
953 gold_assert(layout
!= NULL
);
954 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
955 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
956 elfcpp::SHF_ALLOC
, this->rel_dyn_
);
958 return this->rel_dyn_
;
961 // A class to handle the PLT data.
963 template<bool big_endian
>
964 class Output_data_plt_arm
: public Output_section_data
967 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, 32, big_endian
>
970 Output_data_plt_arm(Layout
*, Output_data_space
*);
972 // Add an entry to the PLT.
974 add_entry(Symbol
* gsym
);
976 // Return the .rel.plt section data.
979 { return this->rel_
; }
983 do_adjust_output_section(Output_section
* os
);
985 // Write to a map file.
987 do_print_to_mapfile(Mapfile
* mapfile
) const
988 { mapfile
->print_output_data(this, _("** PLT")); }
991 // Template for the first PLT entry.
992 static const uint32_t first_plt_entry
[5];
994 // Template for subsequent PLT entries.
995 static const uint32_t plt_entry
[3];
997 // Set the final size.
999 set_final_data_size()
1001 this->set_data_size(sizeof(first_plt_entry
)
1002 + this->count_
* sizeof(plt_entry
));
1005 // Write out the PLT data.
1007 do_write(Output_file
*);
1009 // The reloc section.
1010 Reloc_section
* rel_
;
1011 // The .got.plt section.
1012 Output_data_space
* got_plt_
;
1013 // The number of PLT entries.
1014 unsigned int count_
;
1017 // Create the PLT section. The ordinary .got section is an argument,
1018 // since we need to refer to the start. We also create our own .got
1019 // section just for PLT entries.
1021 template<bool big_endian
>
1022 Output_data_plt_arm
<big_endian
>::Output_data_plt_arm(Layout
* layout
,
1023 Output_data_space
* got_plt
)
1024 : Output_section_data(4), got_plt_(got_plt
), count_(0)
1026 this->rel_
= new Reloc_section(false);
1027 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
1028 elfcpp::SHF_ALLOC
, this->rel_
);
1031 template<bool big_endian
>
1033 Output_data_plt_arm
<big_endian
>::do_adjust_output_section(Output_section
* os
)
1038 // Add an entry to the PLT.
1040 template<bool big_endian
>
1042 Output_data_plt_arm
<big_endian
>::add_entry(Symbol
* gsym
)
1044 gold_assert(!gsym
->has_plt_offset());
1046 // Note that when setting the PLT offset we skip the initial
1047 // reserved PLT entry.
1048 gsym
->set_plt_offset((this->count_
) * sizeof(plt_entry
)
1049 + sizeof(first_plt_entry
));
1053 section_offset_type got_offset
= this->got_plt_
->current_data_size();
1055 // Every PLT entry needs a GOT entry which points back to the PLT
1056 // entry (this will be changed by the dynamic linker, normally
1057 // lazily when the function is called).
1058 this->got_plt_
->set_current_data_size(got_offset
+ 4);
1060 // Every PLT entry needs a reloc.
1061 gsym
->set_needs_dynsym_entry();
1062 this->rel_
->add_global(gsym
, elfcpp::R_ARM_JUMP_SLOT
, this->got_plt_
,
1065 // Note that we don't need to save the symbol. The contents of the
1066 // PLT are independent of which symbols are used. The symbols only
1067 // appear in the relocations.
1071 // FIXME: This is not very flexible. Right now this has only been tested
1072 // on armv5te. If we are to support additional architecture features like
1073 // Thumb-2 or BE8, we need to make this more flexible like GNU ld.
1075 // The first entry in the PLT.
1076 template<bool big_endian
>
1077 const uint32_t Output_data_plt_arm
<big_endian
>::first_plt_entry
[5] =
1079 0xe52de004, // str lr, [sp, #-4]!
1080 0xe59fe004, // ldr lr, [pc, #4]
1081 0xe08fe00e, // add lr, pc, lr
1082 0xe5bef008, // ldr pc, [lr, #8]!
1083 0x00000000, // &GOT[0] - .
1086 // Subsequent entries in the PLT.
1088 template<bool big_endian
>
1089 const uint32_t Output_data_plt_arm
<big_endian
>::plt_entry
[3] =
1091 0xe28fc600, // add ip, pc, #0xNN00000
1092 0xe28cca00, // add ip, ip, #0xNN000
1093 0xe5bcf000, // ldr pc, [ip, #0xNNN]!
1096 // Write out the PLT. This uses the hand-coded instructions above,
1097 // and adjusts them as needed. This is all specified by the arm ELF
1098 // Processor Supplement.
1100 template<bool big_endian
>
1102 Output_data_plt_arm
<big_endian
>::do_write(Output_file
* of
)
1104 const off_t offset
= this->offset();
1105 const section_size_type oview_size
=
1106 convert_to_section_size_type(this->data_size());
1107 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1109 const off_t got_file_offset
= this->got_plt_
->offset();
1110 const section_size_type got_size
=
1111 convert_to_section_size_type(this->got_plt_
->data_size());
1112 unsigned char* const got_view
= of
->get_output_view(got_file_offset
,
1114 unsigned char* pov
= oview
;
1116 elfcpp::Elf_types
<32>::Elf_Addr plt_address
= this->address();
1117 elfcpp::Elf_types
<32>::Elf_Addr got_address
= this->got_plt_
->address();
1119 // Write first PLT entry. All but the last word are constants.
1120 const size_t num_first_plt_words
= (sizeof(first_plt_entry
)
1121 / sizeof(plt_entry
[0]));
1122 for (size_t i
= 0; i
< num_first_plt_words
- 1; i
++)
1123 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ i
* 4, first_plt_entry
[i
]);
1124 // Last word in first PLT entry is &GOT[0] - .
1125 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 16,
1126 got_address
- (plt_address
+ 16));
1127 pov
+= sizeof(first_plt_entry
);
1129 unsigned char* got_pov
= got_view
;
1131 memset(got_pov
, 0, 12);
1134 const int rel_size
= elfcpp::Elf_sizes
<32>::rel_size
;
1135 unsigned int plt_offset
= sizeof(first_plt_entry
);
1136 unsigned int plt_rel_offset
= 0;
1137 unsigned int got_offset
= 12;
1138 const unsigned int count
= this->count_
;
1139 for (unsigned int i
= 0;
1142 pov
+= sizeof(plt_entry
),
1144 plt_offset
+= sizeof(plt_entry
),
1145 plt_rel_offset
+= rel_size
,
1148 // Set and adjust the PLT entry itself.
1149 int32_t offset
= ((got_address
+ got_offset
)
1150 - (plt_address
+ plt_offset
+ 8));
1152 gold_assert(offset
>= 0 && offset
< 0x0fffffff);
1153 uint32_t plt_insn0
= plt_entry
[0] | ((offset
>> 20) & 0xff);
1154 elfcpp::Swap
<32, big_endian
>::writeval(pov
, plt_insn0
);
1155 uint32_t plt_insn1
= plt_entry
[1] | ((offset
>> 12) & 0xff);
1156 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, plt_insn1
);
1157 uint32_t plt_insn2
= plt_entry
[2] | (offset
& 0xfff);
1158 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8, plt_insn2
);
1160 // Set the entry in the GOT.
1161 elfcpp::Swap
<32, big_endian
>::writeval(got_pov
, plt_address
);
1164 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1165 gold_assert(static_cast<section_size_type
>(got_pov
- got_view
) == got_size
);
1167 of
->write_output_view(offset
, oview_size
, oview
);
1168 of
->write_output_view(got_file_offset
, got_size
, got_view
);
1171 // Create a PLT entry for a global symbol.
1173 template<bool big_endian
>
1175 Target_arm
<big_endian
>::make_plt_entry(Symbol_table
* symtab
, Layout
* layout
,
1178 if (gsym
->has_plt_offset())
1181 if (this->plt_
== NULL
)
1183 // Create the GOT sections first.
1184 this->got_section(symtab
, layout
);
1186 this->plt_
= new Output_data_plt_arm
<big_endian
>(layout
, this->got_plt_
);
1187 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1189 | elfcpp::SHF_EXECINSTR
),
1192 this->plt_
->add_entry(gsym
);
1195 // Report an unsupported relocation against a local symbol.
1197 template<bool big_endian
>
1199 Target_arm
<big_endian
>::Scan::unsupported_reloc_local(
1200 Sized_relobj
<32, big_endian
>* object
,
1201 unsigned int r_type
)
1203 gold_error(_("%s: unsupported reloc %u against local symbol"),
1204 object
->name().c_str(), r_type
);
1207 // We are about to emit a dynamic relocation of type R_TYPE. If the
1208 // dynamic linker does not support it, issue an error. The GNU linker
1209 // only issues a non-PIC error for an allocated read-only section.
1210 // Here we know the section is allocated, but we don't know that it is
1211 // read-only. But we check for all the relocation types which the
1212 // glibc dynamic linker supports, so it seems appropriate to issue an
1213 // error even if the section is not read-only.
1215 template<bool big_endian
>
1217 Target_arm
<big_endian
>::Scan::check_non_pic(Relobj
* object
,
1218 unsigned int r_type
)
1222 // These are the relocation types supported by glibc for ARM.
1223 case elfcpp::R_ARM_RELATIVE
:
1224 case elfcpp::R_ARM_COPY
:
1225 case elfcpp::R_ARM_GLOB_DAT
:
1226 case elfcpp::R_ARM_JUMP_SLOT
:
1227 case elfcpp::R_ARM_ABS32
:
1228 case elfcpp::R_ARM_PC24
:
1229 // FIXME: The following 3 types are not supported by Android's dynamic
1231 case elfcpp::R_ARM_TLS_DTPMOD32
:
1232 case elfcpp::R_ARM_TLS_DTPOFF32
:
1233 case elfcpp::R_ARM_TLS_TPOFF32
:
1237 // This prevents us from issuing more than one error per reloc
1238 // section. But we can still wind up issuing more than one
1239 // error per object file.
1240 if (this->issued_non_pic_error_
)
1242 object
->error(_("requires unsupported dynamic reloc; "
1243 "recompile with -fPIC"));
1244 this->issued_non_pic_error_
= true;
1247 case elfcpp::R_ARM_NONE
:
1252 // Scan a relocation for a local symbol.
1253 // FIXME: This only handles a subset of relocation types used by Android
1254 // on ARM v5te devices.
1256 template<bool big_endian
>
1258 Target_arm
<big_endian
>::Scan::local(const General_options
&,
1259 Symbol_table
* symtab
,
1262 Sized_relobj
<32, big_endian
>* object
,
1263 unsigned int data_shndx
,
1264 Output_section
* output_section
,
1265 const elfcpp::Rel
<32, big_endian
>& reloc
,
1266 unsigned int r_type
,
1267 const elfcpp::Sym
<32, big_endian
>&)
1269 r_type
= get_real_reloc_type(r_type
);
1272 case elfcpp::R_ARM_NONE
:
1275 case elfcpp::R_ARM_ABS8
:
1276 if (parameters
->options().output_is_position_independent())
1278 // FIXME: Create a dynamic relocation for this location.
1279 gold_error(_("%s: gold bug: need dynamic ABS8 reloc"),
1280 object
->name().c_str());
1284 case elfcpp::R_ARM_ABS32
:
1285 // If building a shared library (or a position-independent
1286 // executable), we need to create a dynamic relocation for
1287 // this location. The relocation applied at link time will
1288 // apply the link-time value, so we flag the location with
1289 // an R_ARM_RELATIVE relocation so the dynamic loader can
1290 // relocate it easily.
1291 if (parameters
->options().output_is_position_independent())
1293 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1294 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1295 // If we are to add more other reloc types than R_ARM_ABS32,
1296 // we need to add check_non_pic(object, r_type) here.
1297 rel_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_ARM_RELATIVE
,
1298 output_section
, data_shndx
,
1299 reloc
.get_r_offset());
1303 case elfcpp::R_ARM_REL32
:
1304 case elfcpp::R_ARM_THM_CALL
:
1305 case elfcpp::R_ARM_CALL
:
1306 case elfcpp::R_ARM_PREL31
:
1307 case elfcpp::R_ARM_JUMP24
:
1308 case elfcpp::R_ARM_PLT32
:
1309 case elfcpp::R_ARM_MOVW_ABS_NC
:
1310 case elfcpp::R_ARM_MOVT_ABS
:
1311 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
1312 case elfcpp::R_ARM_THM_MOVT_ABS
:
1315 case elfcpp::R_ARM_GOTOFF32
:
1316 // We need a GOT section:
1317 target
->got_section(symtab
, layout
);
1320 case elfcpp::R_ARM_BASE_PREL
:
1321 // FIXME: What about this?
1324 case elfcpp::R_ARM_GOT_BREL
:
1325 case elfcpp::R_ARM_GOT_PREL
:
1327 // The symbol requires a GOT entry.
1328 Output_data_got
<32, big_endian
>* got
=
1329 target
->got_section(symtab
, layout
);
1330 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1331 if (got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
))
1333 // If we are generating a shared object, we need to add a
1334 // dynamic RELATIVE relocation for this symbol's GOT entry.
1335 if (parameters
->options().output_is_position_independent())
1337 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1338 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(reloc
.get_r_info());
1339 rel_dyn
->add_local_relative(
1340 object
, r_sym
, elfcpp::R_ARM_RELATIVE
, got
,
1341 object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
));
1347 case elfcpp::R_ARM_TARGET1
:
1348 // This should have been mapped to another type already.
1350 case elfcpp::R_ARM_COPY
:
1351 case elfcpp::R_ARM_GLOB_DAT
:
1352 case elfcpp::R_ARM_JUMP_SLOT
:
1353 case elfcpp::R_ARM_RELATIVE
:
1354 // These are relocations which should only be seen by the
1355 // dynamic linker, and should never be seen here.
1356 gold_error(_("%s: unexpected reloc %u in object file"),
1357 object
->name().c_str(), r_type
);
1361 unsupported_reloc_local(object
, r_type
);
1366 // Report an unsupported relocation against a global symbol.
1368 template<bool big_endian
>
1370 Target_arm
<big_endian
>::Scan::unsupported_reloc_global(
1371 Sized_relobj
<32, big_endian
>* object
,
1372 unsigned int r_type
,
1375 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1376 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
1379 // Scan a relocation for a global symbol.
1380 // FIXME: This only handles a subset of relocation types used by Android
1381 // on ARM v5te devices.
1383 template<bool big_endian
>
1385 Target_arm
<big_endian
>::Scan::global(const General_options
&,
1386 Symbol_table
* symtab
,
1389 Sized_relobj
<32, big_endian
>* object
,
1390 unsigned int data_shndx
,
1391 Output_section
* output_section
,
1392 const elfcpp::Rel
<32, big_endian
>& reloc
,
1393 unsigned int r_type
,
1396 r_type
= get_real_reloc_type(r_type
);
1399 case elfcpp::R_ARM_NONE
:
1402 case elfcpp::R_ARM_ABS8
:
1403 // Make a dynamic relocation if necessary.
1404 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
1406 // FIXME: Create a dynamic relocation for this location.
1407 gold_error(_("%s: gold bug: need dynamic ABS8 reloc for %s"),
1408 object
->name().c_str(), gsym
->demangled_name().c_str());
1412 case elfcpp::R_ARM_ABS32
:
1414 // Make a dynamic relocation if necessary.
1415 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
1417 if (target
->may_need_copy_reloc(gsym
))
1419 target
->copy_reloc(symtab
, layout
, object
,
1420 data_shndx
, output_section
, gsym
, reloc
);
1422 else if (gsym
->can_use_relative_reloc(false))
1424 // If we are to add more other reloc types than R_ARM_ABS32,
1425 // we need to add check_non_pic(object, r_type) here.
1426 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1427 rel_dyn
->add_global_relative(gsym
, elfcpp::R_ARM_RELATIVE
,
1428 output_section
, object
,
1429 data_shndx
, reloc
.get_r_offset());
1433 // If we are to add more other reloc types than R_ARM_ABS32,
1434 // we need to add check_non_pic(object, r_type) here.
1435 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1436 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
1437 data_shndx
, reloc
.get_r_offset());
1443 case elfcpp::R_ARM_MOVW_ABS_NC
:
1444 case elfcpp::R_ARM_MOVT_ABS
:
1445 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
1446 case elfcpp::R_ARM_THM_MOVT_ABS
:
1449 case elfcpp::R_ARM_REL32
:
1450 case elfcpp::R_ARM_PREL31
:
1452 // Make a dynamic relocation if necessary.
1453 int flags
= Symbol::NON_PIC_REF
;
1454 if (gsym
->needs_dynamic_reloc(flags
))
1456 if (target
->may_need_copy_reloc(gsym
))
1458 target
->copy_reloc(symtab
, layout
, object
,
1459 data_shndx
, output_section
, gsym
, reloc
);
1463 check_non_pic(object
, r_type
);
1464 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1465 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
1466 data_shndx
, reloc
.get_r_offset());
1472 case elfcpp::R_ARM_JUMP24
:
1473 case elfcpp::R_ARM_THM_CALL
:
1474 case elfcpp::R_ARM_CALL
:
1476 if (Target_arm
<big_endian
>::Scan::symbol_needs_plt_entry(gsym
))
1477 target
->make_plt_entry(symtab
, layout
, gsym
);
1478 // Make a dynamic relocation if necessary.
1479 int flags
= Symbol::NON_PIC_REF
;
1480 if (gsym
->type() == elfcpp::STT_FUNC
1481 || gsym
->type() == elfcpp::STT_ARM_TFUNC
)
1482 flags
|= Symbol::FUNCTION_CALL
;
1483 if (gsym
->needs_dynamic_reloc(flags
))
1485 if (target
->may_need_copy_reloc(gsym
))
1487 target
->copy_reloc(symtab
, layout
, object
,
1488 data_shndx
, output_section
, gsym
,
1493 check_non_pic(object
, r_type
);
1494 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1495 rel_dyn
->add_global(gsym
, r_type
, output_section
, object
,
1496 data_shndx
, reloc
.get_r_offset());
1502 case elfcpp::R_ARM_PLT32
:
1503 // If the symbol is fully resolved, this is just a relative
1504 // local reloc. Otherwise we need a PLT entry.
1505 if (gsym
->final_value_is_known())
1507 // If building a shared library, we can also skip the PLT entry
1508 // if the symbol is defined in the output file and is protected
1510 if (gsym
->is_defined()
1511 && !gsym
->is_from_dynobj()
1512 && !gsym
->is_preemptible())
1514 target
->make_plt_entry(symtab
, layout
, gsym
);
1517 case elfcpp::R_ARM_GOTOFF32
:
1518 // We need a GOT section.
1519 target
->got_section(symtab
, layout
);
1522 case elfcpp::R_ARM_BASE_PREL
:
1523 // FIXME: What about this?
1526 case elfcpp::R_ARM_GOT_BREL
:
1527 case elfcpp::R_ARM_GOT_PREL
:
1529 // The symbol requires a GOT entry.
1530 Output_data_got
<32, big_endian
>* got
=
1531 target
->got_section(symtab
, layout
);
1532 if (gsym
->final_value_is_known())
1533 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
1536 // If this symbol is not fully resolved, we need to add a
1537 // GOT entry with a dynamic relocation.
1538 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
1539 if (gsym
->is_from_dynobj()
1540 || gsym
->is_undefined()
1541 || gsym
->is_preemptible())
1542 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
,
1543 rel_dyn
, elfcpp::R_ARM_GLOB_DAT
);
1546 if (got
->add_global(gsym
, GOT_TYPE_STANDARD
))
1547 rel_dyn
->add_global_relative(
1548 gsym
, elfcpp::R_ARM_RELATIVE
, got
,
1549 gsym
->got_offset(GOT_TYPE_STANDARD
));
1555 case elfcpp::R_ARM_TARGET1
:
1556 // This should have been mapped to another type already.
1558 case elfcpp::R_ARM_COPY
:
1559 case elfcpp::R_ARM_GLOB_DAT
:
1560 case elfcpp::R_ARM_JUMP_SLOT
:
1561 case elfcpp::R_ARM_RELATIVE
:
1562 // These are relocations which should only be seen by the
1563 // dynamic linker, and should never be seen here.
1564 gold_error(_("%s: unexpected reloc %u in object file"),
1565 object
->name().c_str(), r_type
);
1569 unsupported_reloc_global(object
, r_type
, gsym
);
1574 // Process relocations for gc.
1576 template<bool big_endian
>
1578 Target_arm
<big_endian
>::gc_process_relocs(const General_options
& options
,
1579 Symbol_table
* symtab
,
1581 Sized_relobj
<32, big_endian
>* object
,
1582 unsigned int data_shndx
,
1584 const unsigned char* prelocs
,
1586 Output_section
* output_section
,
1587 bool needs_special_offset_handling
,
1588 size_t local_symbol_count
,
1589 const unsigned char* plocal_symbols
)
1591 typedef Target_arm
<big_endian
> Arm
;
1592 typedef typename Target_arm
<big_endian
>::Scan Scan
;
1594 gold::gc_process_relocs
<32, big_endian
, Arm
, elfcpp::SHT_REL
, Scan
>(
1604 needs_special_offset_handling
,
1609 // Scan relocations for a section.
1611 template<bool big_endian
>
1613 Target_arm
<big_endian
>::scan_relocs(const General_options
& options
,
1614 Symbol_table
* symtab
,
1616 Sized_relobj
<32, big_endian
>* object
,
1617 unsigned int data_shndx
,
1618 unsigned int sh_type
,
1619 const unsigned char* prelocs
,
1621 Output_section
* output_section
,
1622 bool needs_special_offset_handling
,
1623 size_t local_symbol_count
,
1624 const unsigned char* plocal_symbols
)
1626 typedef typename Target_arm
<big_endian
>::Scan Scan
;
1627 if (sh_type
== elfcpp::SHT_RELA
)
1629 gold_error(_("%s: unsupported RELA reloc section"),
1630 object
->name().c_str());
1634 gold::scan_relocs
<32, big_endian
, Target_arm
, elfcpp::SHT_REL
, Scan
>(
1644 needs_special_offset_handling
,
1649 // Finalize the sections.
1651 template<bool big_endian
>
1653 Target_arm
<big_endian
>::do_finalize_sections(Layout
* layout
)
1655 // Fill in some more dynamic tags.
1656 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
1659 if (this->got_plt_
!= NULL
)
1660 odyn
->add_section_address(elfcpp::DT_PLTGOT
, this->got_plt_
);
1662 if (this->plt_
!= NULL
)
1664 const Output_data
* od
= this->plt_
->rel_plt();
1665 odyn
->add_section_size(elfcpp::DT_PLTRELSZ
, od
);
1666 odyn
->add_section_address(elfcpp::DT_JMPREL
, od
);
1667 odyn
->add_constant(elfcpp::DT_PLTREL
, elfcpp::DT_REL
);
1670 if (this->rel_dyn_
!= NULL
)
1672 const Output_data
* od
= this->rel_dyn_
;
1673 odyn
->add_section_address(elfcpp::DT_REL
, od
);
1674 odyn
->add_section_size(elfcpp::DT_RELSZ
, od
);
1675 odyn
->add_constant(elfcpp::DT_RELENT
,
1676 elfcpp::Elf_sizes
<32>::rel_size
);
1679 if (!parameters
->options().shared())
1681 // The value of the DT_DEBUG tag is filled in by the dynamic
1682 // linker at run time, and used by the debugger.
1683 odyn
->add_constant(elfcpp::DT_DEBUG
, 0);
1687 // Emit any relocs we saved in an attempt to avoid generating COPY
1689 if (this->copy_relocs_
.any_saved_relocs())
1690 this->copy_relocs_
.emit(this->rel_dyn_section(layout
));
1692 // For the ARM target, we need to add a PT_ARM_EXIDX segment for
1693 // the .ARM.exidx section.
1694 if (!layout
->script_options()->saw_phdrs_clause()
1695 && !parameters
->options().relocatable())
1697 Output_section
* exidx_section
=
1698 layout
->find_output_section(".ARM.exidx");
1700 if (exidx_section
!= NULL
1701 && exidx_section
->type() == elfcpp::SHT_ARM_EXIDX
)
1703 gold_assert(layout
->find_output_segment(elfcpp::PT_ARM_EXIDX
, 0, 0)
1705 Output_segment
* exidx_segment
=
1706 layout
->make_output_segment(elfcpp::PT_ARM_EXIDX
, elfcpp::PF_R
);
1707 exidx_segment
->add_output_section(exidx_section
, elfcpp::PF_R
);
1712 // Return whether a direct absolute static relocation needs to be applied.
1713 // In cases where Scan::local() or Scan::global() has created
1714 // a dynamic relocation other than R_ARM_RELATIVE, the addend
1715 // of the relocation is carried in the data, and we must not
1716 // apply the static relocation.
1718 template<bool big_endian
>
1720 Target_arm
<big_endian
>::Relocate::should_apply_static_reloc(
1721 const Sized_symbol
<32>* gsym
,
1724 Output_section
* output_section
)
1726 // If the output section is not allocated, then we didn't call
1727 // scan_relocs, we didn't create a dynamic reloc, and we must apply
1729 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
1732 // For local symbols, we will have created a non-RELATIVE dynamic
1733 // relocation only if (a) the output is position independent,
1734 // (b) the relocation is absolute (not pc- or segment-relative), and
1735 // (c) the relocation is not 32 bits wide.
1737 return !(parameters
->options().output_is_position_independent()
1738 && (ref_flags
& Symbol::ABSOLUTE_REF
)
1741 // For global symbols, we use the same helper routines used in the
1742 // scan pass. If we did not create a dynamic relocation, or if we
1743 // created a RELATIVE dynamic relocation, we should apply the static
1745 bool has_dyn
= gsym
->needs_dynamic_reloc(ref_flags
);
1746 bool is_rel
= (ref_flags
& Symbol::ABSOLUTE_REF
)
1747 && gsym
->can_use_relative_reloc(ref_flags
1748 & Symbol::FUNCTION_CALL
);
1749 return !has_dyn
|| is_rel
;
1752 // Perform a relocation.
1754 template<bool big_endian
>
1756 Target_arm
<big_endian
>::Relocate::relocate(
1757 const Relocate_info
<32, big_endian
>* relinfo
,
1759 Output_section
*output_section
,
1761 const elfcpp::Rel
<32, big_endian
>& rel
,
1762 unsigned int r_type
,
1763 const Sized_symbol
<32>* gsym
,
1764 const Symbol_value
<32>* psymval
,
1765 unsigned char* view
,
1766 elfcpp::Elf_types
<32>::Elf_Addr address
,
1767 section_size_type
/* view_size */ )
1769 typedef Arm_relocate_functions
<big_endian
> Arm_relocate_functions
;
1771 r_type
= get_real_reloc_type(r_type
);
1773 // If this the symbol may be a Thumb function, set thumb bit to 1.
1774 bool has_thumb_bit
= ((gsym
!= NULL
)
1775 && (gsym
->type() == elfcpp::STT_FUNC
1776 || gsym
->type() == elfcpp::STT_ARM_TFUNC
));
1778 // Pick the value to use for symbols defined in shared objects.
1779 Symbol_value
<32> symval
;
1781 && gsym
->use_plt_offset(reloc_is_non_pic(r_type
)))
1783 symval
.set_output_value(target
->plt_section()->address()
1784 + gsym
->plt_offset());
1789 const Sized_relobj
<32, big_endian
>* object
= relinfo
->object
;
1791 // Get the GOT offset if needed.
1792 // The GOT pointer points to the end of the GOT section.
1793 // We need to subtract the size of the GOT section to get
1794 // the actual offset to use in the relocation.
1795 bool have_got_offset
= false;
1796 unsigned int got_offset
= 0;
1799 case elfcpp::R_ARM_GOT_BREL
:
1800 case elfcpp::R_ARM_GOT_PREL
:
1803 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
1804 got_offset
= (gsym
->got_offset(GOT_TYPE_STANDARD
)
1805 - target
->got_size());
1809 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(rel
.get_r_info());
1810 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
1811 got_offset
= (object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
)
1812 - target
->got_size());
1814 have_got_offset
= true;
1821 typename
Arm_relocate_functions::Status reloc_status
=
1822 Arm_relocate_functions::STATUS_OKAY
;
1825 case elfcpp::R_ARM_NONE
:
1828 case elfcpp::R_ARM_ABS8
:
1829 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, false,
1831 reloc_status
= Arm_relocate_functions::abs8(view
, object
, psymval
,
1835 case elfcpp::R_ARM_ABS32
:
1836 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
1838 reloc_status
= Arm_relocate_functions::abs32(view
, object
, psymval
,
1842 case elfcpp::R_ARM_MOVW_ABS_NC
:
1843 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
1845 reloc_status
= Arm_relocate_functions::movw_abs_nc(view
, object
,
1849 gold_error(_("relocation R_ARM_MOVW_ABS_NC cannot be used when making"
1850 "a shared object; recompile with -fPIC"));
1853 case elfcpp::R_ARM_MOVT_ABS
:
1854 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
1856 reloc_status
= Arm_relocate_functions::movt_abs(view
, object
, psymval
);
1858 gold_error(_("relocation R_ARM_MOVT_ABS cannot be used when making"
1859 "a shared object; recompile with -fPIC"));
1862 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
1863 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
1865 reloc_status
= Arm_relocate_functions::thm_movw_abs_nc(view
, object
,
1869 gold_error(_("relocation R_ARM_THM_MOVW_ABS_NC cannot be used when"
1870 "making a shared object; recompile with -fPIC"));
1873 case elfcpp::R_ARM_THM_MOVT_ABS
:
1874 if (should_apply_static_reloc(gsym
, Symbol::ABSOLUTE_REF
, true,
1876 reloc_status
= Arm_relocate_functions::thm_movt_abs(view
, object
,
1879 gold_error(_("relocation R_ARM_THM_MOVT_ABS cannot be used when"
1880 "making a shared object; recompile with -fPIC"));
1883 case elfcpp::R_ARM_REL32
:
1884 reloc_status
= Arm_relocate_functions::rel32(view
, object
, psymval
,
1885 address
, has_thumb_bit
);
1888 case elfcpp::R_ARM_THM_CALL
:
1889 reloc_status
= Arm_relocate_functions::thm_call(view
, object
, psymval
,
1890 address
, has_thumb_bit
);
1893 case elfcpp::R_ARM_GOTOFF32
:
1895 elfcpp::Elf_types
<32>::Elf_Addr got_origin
;
1896 got_origin
= target
->got_plt_section()->address();
1897 reloc_status
= Arm_relocate_functions::rel32(view
, object
, psymval
,
1898 got_origin
, has_thumb_bit
);
1902 case elfcpp::R_ARM_BASE_PREL
:
1905 // Get the addressing origin of the output segment defining the
1906 // symbol gsym (AAELF 4.6.1.2 Relocation types)
1907 gold_assert(gsym
!= NULL
);
1908 if (gsym
->source() == Symbol::IN_OUTPUT_SEGMENT
)
1909 origin
= gsym
->output_segment()->vaddr();
1910 else if (gsym
->source () == Symbol::IN_OUTPUT_DATA
)
1911 origin
= gsym
->output_data()->address();
1914 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1915 _("cannot find origin of R_ARM_BASE_PREL"));
1918 reloc_status
= Arm_relocate_functions::base_prel(view
, origin
, address
);
1922 case elfcpp::R_ARM_GOT_BREL
:
1923 gold_assert(have_got_offset
);
1924 reloc_status
= Arm_relocate_functions::got_brel(view
, got_offset
);
1927 case elfcpp::R_ARM_GOT_PREL
:
1928 gold_assert(have_got_offset
);
1929 // Get the address origin for GOT PLT, which is allocated right
1930 // after the GOT section, to calculate an absolute address of
1931 // the symbol GOT entry (got_origin + got_offset).
1932 elfcpp::Elf_types
<32>::Elf_Addr got_origin
;
1933 got_origin
= target
->got_plt_section()->address();
1934 reloc_status
= Arm_relocate_functions::got_prel(view
,
1935 got_origin
+ got_offset
,
1939 case elfcpp::R_ARM_PLT32
:
1940 gold_assert(gsym
== NULL
1941 || gsym
->has_plt_offset()
1942 || gsym
->final_value_is_known()
1943 || (gsym
->is_defined()
1944 && !gsym
->is_from_dynobj()
1945 && !gsym
->is_preemptible()));
1946 reloc_status
= Arm_relocate_functions::plt32(view
, object
, psymval
,
1947 address
, has_thumb_bit
);
1950 case elfcpp::R_ARM_CALL
:
1951 reloc_status
= Arm_relocate_functions::call(view
, object
, psymval
,
1952 address
, has_thumb_bit
);
1955 case elfcpp::R_ARM_JUMP24
:
1956 reloc_status
= Arm_relocate_functions::jump24(view
, object
, psymval
,
1957 address
, has_thumb_bit
);
1960 case elfcpp::R_ARM_PREL31
:
1961 reloc_status
= Arm_relocate_functions::prel31(view
, object
, psymval
,
1962 address
, has_thumb_bit
);
1965 case elfcpp::R_ARM_TARGET1
:
1966 // This should have been mapped to another type already.
1968 case elfcpp::R_ARM_COPY
:
1969 case elfcpp::R_ARM_GLOB_DAT
:
1970 case elfcpp::R_ARM_JUMP_SLOT
:
1971 case elfcpp::R_ARM_RELATIVE
:
1972 // These are relocations which should only be seen by the
1973 // dynamic linker, and should never be seen here.
1974 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1975 _("unexpected reloc %u in object file"),
1980 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1981 _("unsupported reloc %u"),
1986 // Report any errors.
1987 switch (reloc_status
)
1989 case Arm_relocate_functions::STATUS_OKAY
:
1991 case Arm_relocate_functions::STATUS_OVERFLOW
:
1992 gold_error_at_location(relinfo
, relnum
, rel
.get_r_offset(),
1993 _("relocation overflow in relocation %u"),
1996 case Arm_relocate_functions::STATUS_BAD_RELOC
:
1997 gold_error_at_location(
2001 _("unexpected opcode while processing relocation %u"),
2011 // Relocate section data.
2013 template<bool big_endian
>
2015 Target_arm
<big_endian
>::relocate_section(
2016 const Relocate_info
<32, big_endian
>* relinfo
,
2017 unsigned int sh_type
,
2018 const unsigned char* prelocs
,
2020 Output_section
* output_section
,
2021 bool needs_special_offset_handling
,
2022 unsigned char* view
,
2023 elfcpp::Elf_types
<32>::Elf_Addr address
,
2024 section_size_type view_size
,
2025 const Reloc_symbol_changes
* reloc_symbol_changes
)
2027 typedef typename Target_arm
<big_endian
>::Relocate Arm_relocate
;
2028 gold_assert(sh_type
== elfcpp::SHT_REL
);
2030 gold::relocate_section
<32, big_endian
, Target_arm
, elfcpp::SHT_REL
,
2037 needs_special_offset_handling
,
2041 reloc_symbol_changes
);
2044 // Return the size of a relocation while scanning during a relocatable
2047 template<bool big_endian
>
2049 Target_arm
<big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
2050 unsigned int r_type
,
2053 r_type
= get_real_reloc_type(r_type
);
2056 case elfcpp::R_ARM_NONE
:
2059 case elfcpp::R_ARM_ABS8
:
2062 case elfcpp::R_ARM_ABS32
:
2063 case elfcpp::R_ARM_REL32
:
2064 case elfcpp::R_ARM_THM_CALL
:
2065 case elfcpp::R_ARM_GOTOFF32
:
2066 case elfcpp::R_ARM_BASE_PREL
:
2067 case elfcpp::R_ARM_GOT_BREL
:
2068 case elfcpp::R_ARM_GOT_PREL
:
2069 case elfcpp::R_ARM_PLT32
:
2070 case elfcpp::R_ARM_CALL
:
2071 case elfcpp::R_ARM_JUMP24
:
2072 case elfcpp::R_ARM_PREL31
:
2073 case elfcpp::R_ARM_MOVW_ABS_NC
:
2074 case elfcpp::R_ARM_MOVT_ABS
:
2075 case elfcpp::R_ARM_THM_MOVW_ABS_NC
:
2076 case elfcpp::R_ARM_THM_MOVT_ABS
:
2079 case elfcpp::R_ARM_TARGET1
:
2080 // This should have been mapped to another type already.
2082 case elfcpp::R_ARM_COPY
:
2083 case elfcpp::R_ARM_GLOB_DAT
:
2084 case elfcpp::R_ARM_JUMP_SLOT
:
2085 case elfcpp::R_ARM_RELATIVE
:
2086 // These are relocations which should only be seen by the
2087 // dynamic linker, and should never be seen here.
2088 gold_error(_("%s: unexpected reloc %u in object file"),
2089 object
->name().c_str(), r_type
);
2093 object
->error(_("unsupported reloc %u in object file"), r_type
);
2098 // Scan the relocs during a relocatable link.
2100 template<bool big_endian
>
2102 Target_arm
<big_endian
>::scan_relocatable_relocs(
2103 const General_options
& options
,
2104 Symbol_table
* symtab
,
2106 Sized_relobj
<32, big_endian
>* object
,
2107 unsigned int data_shndx
,
2108 unsigned int sh_type
,
2109 const unsigned char* prelocs
,
2111 Output_section
* output_section
,
2112 bool needs_special_offset_handling
,
2113 size_t local_symbol_count
,
2114 const unsigned char* plocal_symbols
,
2115 Relocatable_relocs
* rr
)
2117 gold_assert(sh_type
== elfcpp::SHT_REL
);
2119 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_REL
,
2120 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
2122 gold::scan_relocatable_relocs
<32, big_endian
, elfcpp::SHT_REL
,
2123 Scan_relocatable_relocs
>(
2132 needs_special_offset_handling
,
2138 // Relocate a section during a relocatable link.
2140 template<bool big_endian
>
2142 Target_arm
<big_endian
>::relocate_for_relocatable(
2143 const Relocate_info
<32, big_endian
>* relinfo
,
2144 unsigned int sh_type
,
2145 const unsigned char* prelocs
,
2147 Output_section
* output_section
,
2148 off_t offset_in_output_section
,
2149 const Relocatable_relocs
* rr
,
2150 unsigned char* view
,
2151 elfcpp::Elf_types
<32>::Elf_Addr view_address
,
2152 section_size_type view_size
,
2153 unsigned char* reloc_view
,
2154 section_size_type reloc_view_size
)
2156 gold_assert(sh_type
== elfcpp::SHT_REL
);
2158 gold::relocate_for_relocatable
<32, big_endian
, elfcpp::SHT_REL
>(
2163 offset_in_output_section
,
2172 // Return the value to use for a dynamic symbol which requires special
2173 // treatment. This is how we support equality comparisons of function
2174 // pointers across shared library boundaries, as described in the
2175 // processor specific ABI supplement.
2177 template<bool big_endian
>
2179 Target_arm
<big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
2181 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
2182 return this->plt_section()->address() + gsym
->plt_offset();
2185 // Map platform-specific relocs to real relocs
2187 template<bool big_endian
>
2189 Target_arm
<big_endian
>::get_real_reloc_type (unsigned int r_type
)
2193 case elfcpp::R_ARM_TARGET1
:
2194 // This is either R_ARM_ABS32 or R_ARM_REL32;
2195 return elfcpp::R_ARM_ABS32
;
2197 case elfcpp::R_ARM_TARGET2
:
2198 // This can be any reloc type but ususally is R_ARM_GOT_PREL
2199 return elfcpp::R_ARM_GOT_PREL
;
2206 // The selector for arm object files.
2208 template<bool big_endian
>
2209 class Target_selector_arm
: public Target_selector
2212 Target_selector_arm()
2213 : Target_selector(elfcpp::EM_ARM
, 32, big_endian
,
2214 (big_endian
? "elf32-bigarm" : "elf32-littlearm"))
2218 do_instantiate_target()
2219 { return new Target_arm
<big_endian
>(); }
2222 Target_selector_arm
<false> target_selector_arm
;
2223 Target_selector_arm
<true> target_selector_armbe
;
2225 } // End anonymous namespace.