]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gold/arm.cc
*** empty log message ***
[thirdparty/binutils-gdb.git] / gold / arm.cc
CommitLineData
4a657b0d
DK
1// arm.cc -- arm target support for gold.
2
3// Copyright 2009 Free Software Foundation, Inc.
4// Written by Doug Kwan <dougkwan@google.com> based on the i386 code
5// by Ian Lance Taylor <iant@google.com>.
6
7// This file is part of gold.
8
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.
13
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.
18
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.
23
24#include "gold.h"
25
26#include <cstring>
27#include <limits>
28#include <cstdio>
29#include <string>
30
31#include "elfcpp.h"
32#include "parameters.h"
33#include "reloc.h"
34#include "arm.h"
35#include "object.h"
36#include "symtab.h"
37#include "layout.h"
38#include "output.h"
39#include "copy-relocs.h"
40#include "target.h"
41#include "target-reloc.h"
42#include "target-select.h"
43#include "tls.h"
44#include "defstd.h"
45
46namespace
47{
48
49using namespace gold;
50
94cdfcff
DK
51template<bool big_endian>
52class Output_data_plt_arm;
53
4a657b0d
DK
54// The arm target class.
55//
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
58// are supported.
59//
60// R_ARM_NONE
61// R_ARM_ABS32
62// R_ARM_REL32
63// R_ARM_THM_CALL
64// R_ARM_COPY
65// R_ARM_GLOB_DAT
66// R_ARM_BASE_PREL
67// R_ARM_JUMP_SLOT
68// R_ARM_RELATIVE
69// R_ARM_GOTOFF32
70// R_ARM_GOT_BREL
71// R_ARM_PLT32
72// R_ARM_CALL
73// R_ARM_JUMP24
74// R_ARM_TARGET1
75// R_ARM_PREL31
76//
4a657b0d 77// TODOs:
11af873f
DK
78// - Generate various branch stubs.
79// - Support interworking.
80// - Define section symbols __exidx_start and __exidx_stop.
4a657b0d 81// - Support more relocation types as needed.
94cdfcff
DK
82// - Make PLTs more flexible for different architecture features like
83// Thumb-2 and BE8.
11af873f 84// There are probably a lot more.
4a657b0d 85
c121c671
DK
86// Utilities for manipulating integers of up to 32-bits
87
88namespace utils
89{
90 // Sign extend an n-bit unsigned integer stored in an uint32_t into
91 // an int32_t. NO_BITS must be between 1 to 32.
92 template<int no_bits>
93 static inline int32_t
94 sign_extend(uint32_t bits)
95 {
96d49306 96 gold_assert(no_bits >= 0 && no_bits <= 32);
c121c671
DK
97 if (no_bits == 32)
98 return static_cast<int32_t>(bits);
99 uint32_t mask = (~((uint32_t) 0)) >> (32 - no_bits);
100 bits &= mask;
101 uint32_t top_bit = 1U << (no_bits - 1);
102 int32_t as_signed = static_cast<int32_t>(bits);
103 return (bits & top_bit) ? as_signed + (-top_bit * 2) : as_signed;
104 }
105
106 // Detects overflow of an NO_BITS integer stored in a uint32_t.
107 template<int no_bits>
108 static inline bool
109 has_overflow(uint32_t bits)
110 {
96d49306 111 gold_assert(no_bits >= 0 && no_bits <= 32);
c121c671
DK
112 if (no_bits == 32)
113 return false;
114 int32_t max = (1 << (no_bits - 1)) - 1;
115 int32_t min = -(1 << (no_bits - 1));
116 int32_t as_signed = static_cast<int32_t>(bits);
117 return as_signed > max || as_signed < min;
118 }
119
5e445df6
ILT
120 // Detects overflow of an NO_BITS integer stored in a uint32_t when it
121 // fits in the given number of bits as either a signed or unsigned value.
122 // For example, has_signed_unsigned_overflow<8> would check
123 // -128 <= bits <= 255
124 template<int no_bits>
125 static inline bool
126 has_signed_unsigned_overflow(uint32_t bits)
127 {
128 gold_assert(no_bits >= 2 && no_bits <= 32);
129 if (no_bits == 32)
130 return false;
131 int32_t max = static_cast<int32_t>((1U << no_bits) - 1);
132 int32_t min = -(1 << (no_bits - 1));
133 int32_t as_signed = static_cast<int32_t>(bits);
134 return as_signed > max || as_signed < min;
135 }
136
c121c671
DK
137 // Select bits from A and B using bits in MASK. For each n in [0..31],
138 // the n-th bit in the result is chosen from the n-th bits of A and B.
139 // A zero selects A and a one selects B.
140 static inline uint32_t
141 bit_select(uint32_t a, uint32_t b, uint32_t mask)
142 { return (a & ~mask) | (b & mask); }
143};
144
4a657b0d
DK
145template<bool big_endian>
146class Target_arm : public Sized_target<32, big_endian>
147{
148 public:
149 typedef Output_data_reloc<elfcpp::SHT_REL, true, 32, big_endian>
150 Reloc_section;
151
152 Target_arm()
94cdfcff
DK
153 : Sized_target<32, big_endian>(&arm_info),
154 got_(NULL), plt_(NULL), got_plt_(NULL), rel_dyn_(NULL),
155 copy_relocs_(elfcpp::R_ARM_COPY), dynbss_(NULL)
4a657b0d
DK
156 { }
157
158 // Process the relocations to determine unreferenced sections for
159 // garbage collection.
160 void
161 gc_process_relocs(const General_options& options,
162 Symbol_table* symtab,
163 Layout* layout,
164 Sized_relobj<32, big_endian>* object,
165 unsigned int data_shndx,
166 unsigned int sh_type,
167 const unsigned char* prelocs,
168 size_t reloc_count,
169 Output_section* output_section,
170 bool needs_special_offset_handling,
171 size_t local_symbol_count,
172 const unsigned char* plocal_symbols);
173
174 // Scan the relocations to look for symbol adjustments.
175 void
176 scan_relocs(const General_options& options,
177 Symbol_table* symtab,
178 Layout* layout,
179 Sized_relobj<32, big_endian>* object,
180 unsigned int data_shndx,
181 unsigned int sh_type,
182 const unsigned char* prelocs,
183 size_t reloc_count,
184 Output_section* output_section,
185 bool needs_special_offset_handling,
186 size_t local_symbol_count,
187 const unsigned char* plocal_symbols);
188
189 // Finalize the sections.
190 void
191 do_finalize_sections(Layout*);
192
94cdfcff 193 // Return the value to use for a dynamic symbol which requires special
4a657b0d
DK
194 // treatment.
195 uint64_t
196 do_dynsym_value(const Symbol*) const;
197
198 // Relocate a section.
199 void
200 relocate_section(const Relocate_info<32, big_endian>*,
201 unsigned int sh_type,
202 const unsigned char* prelocs,
203 size_t reloc_count,
204 Output_section* output_section,
205 bool needs_special_offset_handling,
206 unsigned char* view,
207 elfcpp::Elf_types<32>::Elf_Addr view_address,
208 section_size_type view_size);
209
210 // Scan the relocs during a relocatable link.
211 void
212 scan_relocatable_relocs(const General_options& options,
213 Symbol_table* symtab,
214 Layout* layout,
215 Sized_relobj<32, big_endian>* object,
216 unsigned int data_shndx,
217 unsigned int sh_type,
218 const unsigned char* prelocs,
219 size_t reloc_count,
220 Output_section* output_section,
221 bool needs_special_offset_handling,
222 size_t local_symbol_count,
223 const unsigned char* plocal_symbols,
224 Relocatable_relocs*);
225
226 // Relocate a section during a relocatable link.
227 void
228 relocate_for_relocatable(const Relocate_info<32, big_endian>*,
229 unsigned int sh_type,
230 const unsigned char* prelocs,
231 size_t reloc_count,
232 Output_section* output_section,
233 off_t offset_in_output_section,
234 const Relocatable_relocs*,
235 unsigned char* view,
236 elfcpp::Elf_types<32>::Elf_Addr view_address,
237 section_size_type view_size,
238 unsigned char* reloc_view,
239 section_size_type reloc_view_size);
240
241 // Return whether SYM is defined by the ABI.
242 bool
243 do_is_defined_by_abi(Symbol* sym) const
244 { return strcmp(sym->name(), "__tls_get_addr") == 0; }
245
94cdfcff
DK
246 // Return the size of the GOT section.
247 section_size_type
248 got_size()
249 {
250 gold_assert(this->got_ != NULL);
251 return this->got_->data_size();
252 }
253
4a657b0d
DK
254 // Map platform-specific reloc types
255 static unsigned int
256 get_real_reloc_type (unsigned int r_type);
257
258 private:
259 // The class which scans relocations.
260 class Scan
261 {
262 public:
263 Scan()
bec53400 264 : issued_non_pic_error_(false)
4a657b0d
DK
265 { }
266
267 inline void
268 local(const General_options& options, Symbol_table* symtab,
269 Layout* layout, Target_arm* target,
270 Sized_relobj<32, big_endian>* object,
271 unsigned int data_shndx,
272 Output_section* output_section,
273 const elfcpp::Rel<32, big_endian>& reloc, unsigned int r_type,
274 const elfcpp::Sym<32, big_endian>& lsym);
275
276 inline void
277 global(const General_options& options, Symbol_table* symtab,
278 Layout* layout, Target_arm* target,
279 Sized_relobj<32, big_endian>* object,
280 unsigned int data_shndx,
281 Output_section* output_section,
282 const elfcpp::Rel<32, big_endian>& reloc, unsigned int r_type,
283 Symbol* gsym);
284
285 private:
286 static void
287 unsupported_reloc_local(Sized_relobj<32, big_endian>*,
288 unsigned int r_type);
289
290 static void
291 unsupported_reloc_global(Sized_relobj<32, big_endian>*,
292 unsigned int r_type, Symbol*);
bec53400
DK
293
294 void
295 check_non_pic(Relobj*, unsigned int r_type);
296
297 // Almost identical to Symbol::needs_plt_entry except that it also
298 // handles STT_ARM_TFUNC.
299 static bool
300 symbol_needs_plt_entry(const Symbol* sym)
301 {
302 // An undefined symbol from an executable does not need a PLT entry.
303 if (sym->is_undefined() && !parameters->options().shared())
304 return false;
305
306 return (!parameters->doing_static_link()
307 && (sym->type() == elfcpp::STT_FUNC
308 || sym->type() == elfcpp::STT_ARM_TFUNC)
309 && (sym->is_from_dynobj()
310 || sym->is_undefined()
311 || sym->is_preemptible()));
312 }
313
314 // Whether we have issued an error about a non-PIC compilation.
315 bool issued_non_pic_error_;
4a657b0d
DK
316 };
317
318 // The class which implements relocation.
319 class Relocate
320 {
321 public:
322 Relocate()
323 { }
324
325 ~Relocate()
326 { }
327
bec53400
DK
328 // Return whether the static relocation needs to be applied.
329 inline bool
330 should_apply_static_reloc(const Sized_symbol<32>* gsym,
331 int ref_flags,
332 bool is_32bit,
333 Output_section* output_section);
334
4a657b0d
DK
335 // Do a relocation. Return false if the caller should not issue
336 // any warnings about this relocation.
337 inline bool
338 relocate(const Relocate_info<32, big_endian>*, Target_arm*,
339 Output_section*, size_t relnum,
340 const elfcpp::Rel<32, big_endian>&,
341 unsigned int r_type, const Sized_symbol<32>*,
342 const Symbol_value<32>*,
343 unsigned char*, elfcpp::Elf_types<32>::Elf_Addr,
344 section_size_type);
c121c671
DK
345
346 // Return whether we want to pass flag NON_PIC_REF for this
347 // reloc.
348 static inline bool
349 reloc_is_non_pic (unsigned int r_type)
350 {
351 switch (r_type)
352 {
353 case elfcpp::R_ARM_REL32:
354 case elfcpp::R_ARM_THM_CALL:
355 case elfcpp::R_ARM_CALL:
356 case elfcpp::R_ARM_JUMP24:
357 case elfcpp::R_ARM_PREL31:
358 return true;
359 default:
360 return false;
361 }
362 }
4a657b0d
DK
363 };
364
365 // A class which returns the size required for a relocation type,
366 // used while scanning relocs during a relocatable link.
367 class Relocatable_size_for_reloc
368 {
369 public:
370 unsigned int
371 get_size_for_reloc(unsigned int, Relobj*);
372 };
373
94cdfcff
DK
374 // Get the GOT section, creating it if necessary.
375 Output_data_got<32, big_endian>*
376 got_section(Symbol_table*, Layout*);
377
378 // Get the GOT PLT section.
379 Output_data_space*
380 got_plt_section() const
381 {
382 gold_assert(this->got_plt_ != NULL);
383 return this->got_plt_;
384 }
385
386 // Create a PLT entry for a global symbol.
387 void
388 make_plt_entry(Symbol_table*, Layout*, Symbol*);
389
390 // Get the PLT section.
391 const Output_data_plt_arm<big_endian>*
392 plt_section() const
393 {
394 gold_assert(this->plt_ != NULL);
395 return this->plt_;
396 }
397
398 // Get the dynamic reloc section, creating it if necessary.
399 Reloc_section*
400 rel_dyn_section(Layout*);
401
402 // Return true if the symbol may need a COPY relocation.
403 // References from an executable object to non-function symbols
404 // defined in a dynamic object may need a COPY relocation.
405 bool
406 may_need_copy_reloc(Symbol* gsym)
407 {
408 return (!parameters->options().shared()
409 && gsym->is_from_dynobj()
bec53400
DK
410 && gsym->type() != elfcpp::STT_FUNC
411 && gsym->type() != elfcpp::STT_ARM_TFUNC);
94cdfcff
DK
412 }
413
414 // Add a potential copy relocation.
415 void
416 copy_reloc(Symbol_table* symtab, Layout* layout,
417 Sized_relobj<32, big_endian>* object,
418 unsigned int shndx, Output_section* output_section,
419 Symbol* sym, const elfcpp::Rel<32, big_endian>& reloc)
420 {
421 this->copy_relocs_.copy_reloc(symtab, layout,
422 symtab->get_sized_symbol<32>(sym),
423 object, shndx, output_section, reloc,
424 this->rel_dyn_section(layout));
425 }
426
4a657b0d
DK
427 // Information about this specific target which we pass to the
428 // general Target structure.
429 static const Target::Target_info arm_info;
94cdfcff
DK
430
431 // The types of GOT entries needed for this platform.
432 enum Got_type
433 {
434 GOT_TYPE_STANDARD = 0 // GOT entry for a regular symbol
435 };
436
437 // The GOT section.
438 Output_data_got<32, big_endian>* got_;
439 // The PLT section.
440 Output_data_plt_arm<big_endian>* plt_;
441 // The GOT PLT section.
442 Output_data_space* got_plt_;
443 // The dynamic reloc section.
444 Reloc_section* rel_dyn_;
445 // Relocs saved to avoid a COPY reloc.
446 Copy_relocs<elfcpp::SHT_REL, 32, big_endian> copy_relocs_;
447 // Space for variables copied with a COPY reloc.
448 Output_data_space* dynbss_;
4a657b0d
DK
449};
450
451template<bool big_endian>
452const Target::Target_info Target_arm<big_endian>::arm_info =
453{
454 32, // size
455 big_endian, // is_big_endian
456 elfcpp::EM_ARM, // machine_code
457 false, // has_make_symbol
458 false, // has_resolve
459 false, // has_code_fill
460 true, // is_default_stack_executable
461 '\0', // wrap_char
462 "/usr/lib/libc.so.1", // dynamic_linker
463 0x8000, // default_text_segment_address
464 0x1000, // abi_pagesize (overridable by -z max-page-size)
8a5e3e08
ILT
465 0x1000, // common_pagesize (overridable by -z common-page-size)
466 elfcpp::SHN_UNDEF, // small_common_shndx
467 elfcpp::SHN_UNDEF, // large_common_shndx
468 0, // small_common_section_flags
469 0 // large_common_section_flags
4a657b0d
DK
470};
471
c121c671
DK
472// Arm relocate functions class
473//
474
475template<bool big_endian>
476class Arm_relocate_functions : public Relocate_functions<32, big_endian>
477{
478 public:
479 typedef enum
480 {
481 STATUS_OKAY, // No error during relocation.
482 STATUS_OVERFLOW, // Relocation oveflow.
483 STATUS_BAD_RELOC // Relocation cannot be applied.
484 } Status;
485
486 private:
487 typedef Relocate_functions<32, big_endian> Base;
488 typedef Arm_relocate_functions<big_endian> This;
489
490 // Get an symbol value of *PSYMVAL with an ADDEND. This is a wrapper
491 // to Symbol_value::value(). If HAS_THUMB_BIT is true, that LSB is used
492 // to distinguish ARM and THUMB functions and it is treated specially.
493 static inline Symbol_value<32>::Value
494 arm_symbol_value (const Sized_relobj<32, big_endian> *object,
495 const Symbol_value<32>* psymval,
496 Symbol_value<32>::Value addend,
497 bool has_thumb_bit)
498 {
499 typedef Symbol_value<32>::Value Valtype;
500
501 if (has_thumb_bit)
502 {
503 Valtype raw = psymval->value(object, 0);
504 Valtype thumb_bit = raw & 1;
505 return ((raw & ~((Valtype) 1)) + addend) | thumb_bit;
506 }
507 else
508 return psymval->value(object, addend);
509 }
510
511 // FIXME: This probably only works for Android on ARM v5te. We should
512 // following GNU ld for the general case.
513 template<unsigned r_type>
514 static inline typename This::Status
515 arm_branch_common(unsigned char *view,
516 const Sized_relobj<32, big_endian>* object,
517 const Symbol_value<32>* psymval,
518 elfcpp::Elf_types<32>::Elf_Addr address,
519 bool has_thumb_bit)
520 {
521 typedef typename elfcpp::Swap<32, big_endian>::Valtype Valtype;
522 Valtype* wv = reinterpret_cast<Valtype*>(view);
523 Valtype val = elfcpp::Swap<32, big_endian>::readval(wv);
524
525 bool insn_is_b = (((val >> 28) & 0xf) <= 0xe)
526 && ((val & 0x0f000000UL) == 0x0a000000UL);
527 bool insn_is_uncond_bl = (val & 0xff000000UL) == 0xeb000000UL;
528 bool insn_is_cond_bl = (((val >> 28) & 0xf) < 0xe)
529 && ((val & 0x0f000000UL) == 0x0b000000UL);
530 bool insn_is_blx = (val & 0xfe000000UL) == 0xfa000000UL;
531 bool insn_is_any_branch = (val & 0x0e000000UL) == 0x0a000000UL;
532
533 if (r_type == elfcpp::R_ARM_CALL)
534 {
535 if (!insn_is_uncond_bl && !insn_is_blx)
536 return This::STATUS_BAD_RELOC;
537 }
538 else if (r_type == elfcpp::R_ARM_JUMP24)
539 {
540 if (!insn_is_b && !insn_is_cond_bl)
541 return This::STATUS_BAD_RELOC;
542 }
543 else if (r_type == elfcpp::R_ARM_PLT32)
544 {
545 if (!insn_is_any_branch)
546 return This::STATUS_BAD_RELOC;
547 }
548 else
549 gold_unreachable();
550
551 Valtype addend = utils::sign_extend<26>(val << 2);
552 Valtype x = (This::arm_symbol_value(object, psymval, addend, has_thumb_bit)
553 - address);
554
555 // If target has thumb bit set, we need to either turn the BL
556 // into a BLX (for ARMv5 or above) or generate a stub.
557 if (x & 1)
558 {
559 // Turn BL to BLX.
560 if (insn_is_uncond_bl)
561 val = (val & 0xffffff) | 0xfa000000 | ((x & 2) << 23);
562 else
563 return This::STATUS_BAD_RELOC;
564 }
565 else
566 gold_assert(!insn_is_blx);
567
568 val = utils::bit_select(val, (x >> 2), 0xffffffUL);
569 elfcpp::Swap<32, big_endian>::writeval(wv, val);
570 return (utils::has_overflow<26>(x)
571 ? This::STATUS_OVERFLOW : This::STATUS_OKAY);
572 }
573
574 public:
5e445df6
ILT
575
576 // R_ARM_ABS8: S + A
577 static inline typename This::Status
578 abs8(unsigned char *view,
579 const Sized_relobj<32, big_endian>* object,
580 const Symbol_value<32>* psymval, bool has_thumb_bit)
581 {
582 typedef typename elfcpp::Swap<8, big_endian>::Valtype Valtype;
583 typedef typename elfcpp::Swap<32, big_endian>::Valtype Reltype;
584 Valtype* wv = reinterpret_cast<Valtype*>(view);
585 Valtype val = elfcpp::Swap<8, big_endian>::readval(wv);
586 Reltype addend = utils::sign_extend<8>(val);
587 Reltype x = This::arm_symbol_value(object, psymval, addend, has_thumb_bit);
588 val = utils::bit_select(val, x, 0xffU);
589 elfcpp::Swap<8, big_endian>::writeval(wv, val);
590 return (utils::has_signed_unsigned_overflow<8>(x)
591 ? This::STATUS_OVERFLOW
592 : This::STATUS_OKAY);
593 }
594
c121c671
DK
595 // R_ARM_ABS32: (S + A) | T
596 static inline typename This::Status
597 abs32(unsigned char *view,
598 const Sized_relobj<32, big_endian>* object,
599 const Symbol_value<32>* psymval,
600 bool has_thumb_bit)
601 {
602 typedef typename elfcpp::Swap<32, big_endian>::Valtype Valtype;
603 Valtype* wv = reinterpret_cast<Valtype*>(view);
604 Valtype addend = elfcpp::Swap<32, big_endian>::readval(wv);
605 Valtype x = This::arm_symbol_value(object, psymval, addend, has_thumb_bit);
606 elfcpp::Swap<32, big_endian>::writeval(wv, x);
607 return This::STATUS_OKAY;
608 }
609
610 // R_ARM_REL32: (S + A) | T - P
611 static inline typename This::Status
612 rel32(unsigned char *view,
613 const Sized_relobj<32, big_endian>* object,
614 const Symbol_value<32>* psymval,
615 elfcpp::Elf_types<32>::Elf_Addr address,
616 bool has_thumb_bit)
617 {
618 typedef typename elfcpp::Swap<32, big_endian>::Valtype Valtype;
619 Valtype* wv = reinterpret_cast<Valtype*>(view);
620 Valtype addend = elfcpp::Swap<32, big_endian>::readval(wv);
621 Valtype x = (This::arm_symbol_value(object, psymval, addend, has_thumb_bit)
622 - address);
623 elfcpp::Swap<32, big_endian>::writeval(wv, x);
624 return This::STATUS_OKAY;
625 }
626
627 // R_ARM_THM_CALL: (S + A) | T - P
628 static inline typename This::Status
629 thm_call(unsigned char *view,
630 const Sized_relobj<32, big_endian>* object,
631 const Symbol_value<32>* psymval,
632 elfcpp::Elf_types<32>::Elf_Addr address,
633 bool has_thumb_bit)
634 {
635 // A thumb call consists of two instructions.
636 typedef typename elfcpp::Swap<16, big_endian>::Valtype Valtype;
637 typedef typename elfcpp::Swap<32, big_endian>::Valtype Reltype;
638 Valtype* wv = reinterpret_cast<Valtype*>(view);
639 Valtype hi = elfcpp::Swap<16, big_endian>::readval(wv);
640 Valtype lo = elfcpp::Swap<16, big_endian>::readval(wv + 1);
641 // Must be a BL instruction. lo == 11111xxxxxxxxxxx.
642 gold_assert((lo & 0xf800) == 0xf800);
643 Reltype addend = utils::sign_extend<23>(((hi & 0x7ff) << 12)
644 | ((lo & 0x7ff) << 1));
645 Reltype x = (This::arm_symbol_value(object, psymval, addend, has_thumb_bit)
646 - address);
647
648 // If target has no thumb bit set, we need to either turn the BL
649 // into a BLX (for ARMv5 or above) or generate a stub.
650 if ((x & 1) == 0)
651 {
652 // This only works for ARMv5 and above with interworking enabled.
653 lo &= 0xefff;
654 }
655 hi = utils::bit_select(hi, (x >> 12), 0x7ffU);
656 lo = utils::bit_select(lo, (x >> 1), 0x7ffU);
657 elfcpp::Swap<16, big_endian>::writeval(wv, hi);
658 elfcpp::Swap<16, big_endian>::writeval(wv + 1, lo);
659 return (utils::has_overflow<23>(x)
660 ? This::STATUS_OVERFLOW
661 : This::STATUS_OKAY);
662 }
663
664 // R_ARM_BASE_PREL: B(S) + A - P
665 static inline typename This::Status
666 base_prel(unsigned char* view,
667 elfcpp::Elf_types<32>::Elf_Addr origin,
668 elfcpp::Elf_types<32>::Elf_Addr address)
669 {
670 Base::rel32(view, origin - address);
671 return STATUS_OKAY;
672 }
673
674 // R_ARM_GOT_BREL: GOT(S) + A - GOT_ORG
675 static inline typename This::Status
676 got_brel(unsigned char* view,
677 typename elfcpp::Swap<32, big_endian>::Valtype got_offset)
678 {
679 Base::rel32(view, got_offset);
680 return This::STATUS_OKAY;
681 }
682
683 // R_ARM_PLT32: (S + A) | T - P
684 static inline typename This::Status
685 plt32(unsigned char *view,
686 const Sized_relobj<32, big_endian>* object,
687 const Symbol_value<32>* psymval,
688 elfcpp::Elf_types<32>::Elf_Addr address,
689 bool has_thumb_bit)
690 {
691 return arm_branch_common<elfcpp::R_ARM_PLT32>(view, object, psymval,
692 address, has_thumb_bit);
693 }
694
695 // R_ARM_CALL: (S + A) | T - P
696 static inline typename This::Status
697 call(unsigned char *view,
698 const Sized_relobj<32, big_endian>* object,
699 const Symbol_value<32>* psymval,
700 elfcpp::Elf_types<32>::Elf_Addr address,
701 bool has_thumb_bit)
702 {
703 return arm_branch_common<elfcpp::R_ARM_CALL>(view, object, psymval,
704 address, has_thumb_bit);
705 }
706
707 // R_ARM_JUMP24: (S + A) | T - P
708 static inline typename This::Status
709 jump24(unsigned char *view,
710 const Sized_relobj<32, big_endian>* object,
711 const Symbol_value<32>* psymval,
712 elfcpp::Elf_types<32>::Elf_Addr address,
713 bool has_thumb_bit)
714 {
715 return arm_branch_common<elfcpp::R_ARM_JUMP24>(view, object, psymval,
716 address, has_thumb_bit);
717 }
718
719 // R_ARM_PREL: (S + A) | T - P
720 static inline typename This::Status
721 prel31(unsigned char *view,
722 const Sized_relobj<32, big_endian>* object,
723 const Symbol_value<32>* psymval,
724 elfcpp::Elf_types<32>::Elf_Addr address,
725 bool has_thumb_bit)
726 {
727 typedef typename elfcpp::Swap<32, big_endian>::Valtype Valtype;
728 Valtype* wv = reinterpret_cast<Valtype*>(view);
729 Valtype val = elfcpp::Swap<32, big_endian>::readval(wv);
730 Valtype addend = utils::sign_extend<31>(val);
731 Valtype x = (This::arm_symbol_value(object, psymval, addend, has_thumb_bit)
732 - address);
733 val = utils::bit_select(val, x, 0x7fffffffU);
734 elfcpp::Swap<32, big_endian>::writeval(wv, val);
735 return (utils::has_overflow<31>(x) ?
736 This::STATUS_OVERFLOW : This::STATUS_OKAY);
737 }
738};
739
94cdfcff
DK
740// Get the GOT section, creating it if necessary.
741
742template<bool big_endian>
743Output_data_got<32, big_endian>*
744Target_arm<big_endian>::got_section(Symbol_table* symtab, Layout* layout)
745{
746 if (this->got_ == NULL)
747 {
748 gold_assert(symtab != NULL && layout != NULL);
749
750 this->got_ = new Output_data_got<32, big_endian>();
751
752 Output_section* os;
753 os = layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
754 (elfcpp::SHF_ALLOC
755 | elfcpp::SHF_WRITE),
756 this->got_);
757 os->set_is_relro();
758
759 // The old GNU linker creates a .got.plt section. We just
760 // create another set of data in the .got section. Note that we
761 // always create a PLT if we create a GOT, although the PLT
762 // might be empty.
763 this->got_plt_ = new Output_data_space(4, "** GOT PLT");
764 os = layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
765 (elfcpp::SHF_ALLOC
766 | elfcpp::SHF_WRITE),
767 this->got_plt_);
768 os->set_is_relro();
769
770 // The first three entries are reserved.
771 this->got_plt_->set_current_data_size(3 * 4);
772
773 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
774 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
775 this->got_plt_,
776 0, 0, elfcpp::STT_OBJECT,
777 elfcpp::STB_LOCAL,
778 elfcpp::STV_HIDDEN, 0,
779 false, false);
780 }
781 return this->got_;
782}
783
784// Get the dynamic reloc section, creating it if necessary.
785
786template<bool big_endian>
787typename Target_arm<big_endian>::Reloc_section*
788Target_arm<big_endian>::rel_dyn_section(Layout* layout)
789{
790 if (this->rel_dyn_ == NULL)
791 {
792 gold_assert(layout != NULL);
793 this->rel_dyn_ = new Reloc_section(parameters->options().combreloc());
794 layout->add_output_section_data(".rel.dyn", elfcpp::SHT_REL,
795 elfcpp::SHF_ALLOC, this->rel_dyn_);
796 }
797 return this->rel_dyn_;
798}
799
800// A class to handle the PLT data.
801
802template<bool big_endian>
803class Output_data_plt_arm : public Output_section_data
804{
805 public:
806 typedef Output_data_reloc<elfcpp::SHT_REL, true, 32, big_endian>
807 Reloc_section;
808
809 Output_data_plt_arm(Layout*, Output_data_space*);
810
811 // Add an entry to the PLT.
812 void
813 add_entry(Symbol* gsym);
814
815 // Return the .rel.plt section data.
816 const Reloc_section*
817 rel_plt() const
818 { return this->rel_; }
819
820 protected:
821 void
822 do_adjust_output_section(Output_section* os);
823
824 // Write to a map file.
825 void
826 do_print_to_mapfile(Mapfile* mapfile) const
827 { mapfile->print_output_data(this, _("** PLT")); }
828
829 private:
830 // Template for the first PLT entry.
831 static const uint32_t first_plt_entry[5];
832
833 // Template for subsequent PLT entries.
834 static const uint32_t plt_entry[3];
835
836 // Set the final size.
837 void
838 set_final_data_size()
839 {
840 this->set_data_size(sizeof(first_plt_entry)
841 + this->count_ * sizeof(plt_entry));
842 }
843
844 // Write out the PLT data.
845 void
846 do_write(Output_file*);
847
848 // The reloc section.
849 Reloc_section* rel_;
850 // The .got.plt section.
851 Output_data_space* got_plt_;
852 // The number of PLT entries.
853 unsigned int count_;
854};
855
856// Create the PLT section. The ordinary .got section is an argument,
857// since we need to refer to the start. We also create our own .got
858// section just for PLT entries.
859
860template<bool big_endian>
861Output_data_plt_arm<big_endian>::Output_data_plt_arm(Layout* layout,
862 Output_data_space* got_plt)
863 : Output_section_data(4), got_plt_(got_plt), count_(0)
864{
865 this->rel_ = new Reloc_section(false);
866 layout->add_output_section_data(".rel.plt", elfcpp::SHT_REL,
867 elfcpp::SHF_ALLOC, this->rel_);
868}
869
870template<bool big_endian>
871void
872Output_data_plt_arm<big_endian>::do_adjust_output_section(Output_section* os)
873{
874 os->set_entsize(0);
875}
876
877// Add an entry to the PLT.
878
879template<bool big_endian>
880void
881Output_data_plt_arm<big_endian>::add_entry(Symbol* gsym)
882{
883 gold_assert(!gsym->has_plt_offset());
884
885 // Note that when setting the PLT offset we skip the initial
886 // reserved PLT entry.
887 gsym->set_plt_offset((this->count_) * sizeof(plt_entry)
888 + sizeof(first_plt_entry));
889
890 ++this->count_;
891
892 section_offset_type got_offset = this->got_plt_->current_data_size();
893
894 // Every PLT entry needs a GOT entry which points back to the PLT
895 // entry (this will be changed by the dynamic linker, normally
896 // lazily when the function is called).
897 this->got_plt_->set_current_data_size(got_offset + 4);
898
899 // Every PLT entry needs a reloc.
900 gsym->set_needs_dynsym_entry();
901 this->rel_->add_global(gsym, elfcpp::R_ARM_JUMP_SLOT, this->got_plt_,
902 got_offset);
903
904 // Note that we don't need to save the symbol. The contents of the
905 // PLT are independent of which symbols are used. The symbols only
906 // appear in the relocations.
907}
908
909// ARM PLTs.
910// FIXME: This is not very flexible. Right now this has only been tested
911// on armv5te. If we are to support additional architecture features like
912// Thumb-2 or BE8, we need to make this more flexible like GNU ld.
913
914// The first entry in the PLT.
915template<bool big_endian>
916const uint32_t Output_data_plt_arm<big_endian>::first_plt_entry[5] =
917{
918 0xe52de004, // str lr, [sp, #-4]!
919 0xe59fe004, // ldr lr, [pc, #4]
920 0xe08fe00e, // add lr, pc, lr
921 0xe5bef008, // ldr pc, [lr, #8]!
922 0x00000000, // &GOT[0] - .
923};
924
925// Subsequent entries in the PLT.
926
927template<bool big_endian>
928const uint32_t Output_data_plt_arm<big_endian>::plt_entry[3] =
929{
930 0xe28fc600, // add ip, pc, #0xNN00000
931 0xe28cca00, // add ip, ip, #0xNN000
932 0xe5bcf000, // ldr pc, [ip, #0xNNN]!
933};
934
935// Write out the PLT. This uses the hand-coded instructions above,
936// and adjusts them as needed. This is all specified by the arm ELF
937// Processor Supplement.
938
939template<bool big_endian>
940void
941Output_data_plt_arm<big_endian>::do_write(Output_file* of)
942{
943 const off_t offset = this->offset();
944 const section_size_type oview_size =
945 convert_to_section_size_type(this->data_size());
946 unsigned char* const oview = of->get_output_view(offset, oview_size);
947
948 const off_t got_file_offset = this->got_plt_->offset();
949 const section_size_type got_size =
950 convert_to_section_size_type(this->got_plt_->data_size());
951 unsigned char* const got_view = of->get_output_view(got_file_offset,
952 got_size);
953 unsigned char* pov = oview;
954
955 elfcpp::Elf_types<32>::Elf_Addr plt_address = this->address();
956 elfcpp::Elf_types<32>::Elf_Addr got_address = this->got_plt_->address();
957
958 // Write first PLT entry. All but the last word are constants.
959 const size_t num_first_plt_words = (sizeof(first_plt_entry)
960 / sizeof(plt_entry[0]));
961 for (size_t i = 0; i < num_first_plt_words - 1; i++)
962 elfcpp::Swap<32, big_endian>::writeval(pov + i * 4, first_plt_entry[i]);
963 // Last word in first PLT entry is &GOT[0] - .
964 elfcpp::Swap<32, big_endian>::writeval(pov + 16,
965 got_address - (plt_address + 16));
966 pov += sizeof(first_plt_entry);
967
968 unsigned char* got_pov = got_view;
969
970 memset(got_pov, 0, 12);
971 got_pov += 12;
972
973 const int rel_size = elfcpp::Elf_sizes<32>::rel_size;
974 unsigned int plt_offset = sizeof(first_plt_entry);
975 unsigned int plt_rel_offset = 0;
976 unsigned int got_offset = 12;
977 const unsigned int count = this->count_;
978 for (unsigned int i = 0;
979 i < count;
980 ++i,
981 pov += sizeof(plt_entry),
982 got_pov += 4,
983 plt_offset += sizeof(plt_entry),
984 plt_rel_offset += rel_size,
985 got_offset += 4)
986 {
987 // Set and adjust the PLT entry itself.
988 int32_t offset = ((got_address + got_offset)
989 - (plt_address + plt_offset + 8));
990
991 gold_assert(offset >= 0 && offset < 0x0fffffff);
992 uint32_t plt_insn0 = plt_entry[0] | ((offset >> 20) & 0xff);
993 elfcpp::Swap<32, big_endian>::writeval(pov, plt_insn0);
994 uint32_t plt_insn1 = plt_entry[1] | ((offset >> 12) & 0xff);
995 elfcpp::Swap<32, big_endian>::writeval(pov + 4, plt_insn1);
996 uint32_t plt_insn2 = plt_entry[2] | (offset & 0xfff);
997 elfcpp::Swap<32, big_endian>::writeval(pov + 8, plt_insn2);
998
999 // Set the entry in the GOT.
1000 elfcpp::Swap<32, big_endian>::writeval(got_pov, plt_address);
1001 }
1002
1003 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
1004 gold_assert(static_cast<section_size_type>(got_pov - got_view) == got_size);
1005
1006 of->write_output_view(offset, oview_size, oview);
1007 of->write_output_view(got_file_offset, got_size, got_view);
1008}
1009
1010// Create a PLT entry for a global symbol.
1011
1012template<bool big_endian>
1013void
1014Target_arm<big_endian>::make_plt_entry(Symbol_table* symtab, Layout* layout,
1015 Symbol* gsym)
1016{
1017 if (gsym->has_plt_offset())
1018 return;
1019
1020 if (this->plt_ == NULL)
1021 {
1022 // Create the GOT sections first.
1023 this->got_section(symtab, layout);
1024
1025 this->plt_ = new Output_data_plt_arm<big_endian>(layout, this->got_plt_);
1026 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
1027 (elfcpp::SHF_ALLOC
1028 | elfcpp::SHF_EXECINSTR),
1029 this->plt_);
1030 }
1031 this->plt_->add_entry(gsym);
1032}
1033
4a657b0d
DK
1034// Report an unsupported relocation against a local symbol.
1035
1036template<bool big_endian>
1037void
1038Target_arm<big_endian>::Scan::unsupported_reloc_local(
1039 Sized_relobj<32, big_endian>* object,
1040 unsigned int r_type)
1041{
1042 gold_error(_("%s: unsupported reloc %u against local symbol"),
1043 object->name().c_str(), r_type);
1044}
1045
bec53400
DK
1046// We are about to emit a dynamic relocation of type R_TYPE. If the
1047// dynamic linker does not support it, issue an error. The GNU linker
1048// only issues a non-PIC error for an allocated read-only section.
1049// Here we know the section is allocated, but we don't know that it is
1050// read-only. But we check for all the relocation types which the
1051// glibc dynamic linker supports, so it seems appropriate to issue an
1052// error even if the section is not read-only.
1053
1054template<bool big_endian>
1055void
1056Target_arm<big_endian>::Scan::check_non_pic(Relobj* object,
1057 unsigned int r_type)
1058{
1059 switch (r_type)
1060 {
1061 // These are the relocation types supported by glibc for ARM.
1062 case elfcpp::R_ARM_RELATIVE:
1063 case elfcpp::R_ARM_COPY:
1064 case elfcpp::R_ARM_GLOB_DAT:
1065 case elfcpp::R_ARM_JUMP_SLOT:
1066 case elfcpp::R_ARM_ABS32:
1067 case elfcpp::R_ARM_PC24:
1068 // FIXME: The following 3 types are not supported by Android's dynamic
1069 // linker.
1070 case elfcpp::R_ARM_TLS_DTPMOD32:
1071 case elfcpp::R_ARM_TLS_DTPOFF32:
1072 case elfcpp::R_ARM_TLS_TPOFF32:
1073 return;
1074
1075 default:
1076 // This prevents us from issuing more than one error per reloc
1077 // section. But we can still wind up issuing more than one
1078 // error per object file.
1079 if (this->issued_non_pic_error_)
1080 return;
1081 object->error(_("requires unsupported dynamic reloc; "
1082 "recompile with -fPIC"));
1083 this->issued_non_pic_error_ = true;
1084 return;
1085
1086 case elfcpp::R_ARM_NONE:
1087 gold_unreachable();
1088 }
1089}
1090
4a657b0d 1091// Scan a relocation for a local symbol.
bec53400
DK
1092// FIXME: This only handles a subset of relocation types used by Android
1093// on ARM v5te devices.
4a657b0d
DK
1094
1095template<bool big_endian>
1096inline void
1097Target_arm<big_endian>::Scan::local(const General_options&,
bec53400
DK
1098 Symbol_table* symtab,
1099 Layout* layout,
1100 Target_arm* target,
4a657b0d 1101 Sized_relobj<32, big_endian>* object,
bec53400
DK
1102 unsigned int data_shndx,
1103 Output_section* output_section,
1104 const elfcpp::Rel<32, big_endian>& reloc,
4a657b0d
DK
1105 unsigned int r_type,
1106 const elfcpp::Sym<32, big_endian>&)
1107{
1108 r_type = get_real_reloc_type(r_type);
1109 switch (r_type)
1110 {
1111 case elfcpp::R_ARM_NONE:
1112 break;
1113
5e445df6
ILT
1114 case elfcpp::R_ARM_ABS8:
1115 if (parameters->options().output_is_position_independent())
1116 {
1117 // FIXME: Create a dynamic relocation for this location.
1118 gold_error(_("%s: gold bug: need dynamic ABS8 reloc"),
1119 object->name().c_str());
1120 }
1121 break;
1122
bec53400
DK
1123 case elfcpp::R_ARM_ABS32:
1124 // If building a shared library (or a position-independent
1125 // executable), we need to create a dynamic relocation for
1126 // this location. The relocation applied at link time will
1127 // apply the link-time value, so we flag the location with
1128 // an R_ARM_RELATIVE relocation so the dynamic loader can
1129 // relocate it easily.
1130 if (parameters->options().output_is_position_independent())
1131 {
1132 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
1133 unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
1134 // If we are to add more other reloc types than R_ARM_ABS32,
1135 // we need to add check_non_pic(object, r_type) here.
1136 rel_dyn->add_local_relative(object, r_sym, elfcpp::R_ARM_RELATIVE,
1137 output_section, data_shndx,
1138 reloc.get_r_offset());
1139 }
1140 break;
1141
1142 case elfcpp::R_ARM_REL32:
1143 case elfcpp::R_ARM_THM_CALL:
1144 case elfcpp::R_ARM_CALL:
1145 case elfcpp::R_ARM_PREL31:
1146 case elfcpp::R_ARM_JUMP24:
1147 case elfcpp::R_ARM_PLT32:
1148 break;
1149
1150 case elfcpp::R_ARM_GOTOFF32:
1151 // We need a GOT section:
1152 target->got_section(symtab, layout);
1153 break;
1154
1155 case elfcpp::R_ARM_BASE_PREL:
1156 // FIXME: What about this?
1157 break;
1158
1159 case elfcpp::R_ARM_GOT_BREL:
1160 {
1161 // The symbol requires a GOT entry.
1162 Output_data_got<32, big_endian>* got =
1163 target->got_section(symtab, layout);
1164 unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
1165 if (got->add_local(object, r_sym, GOT_TYPE_STANDARD))
1166 {
1167 // If we are generating a shared object, we need to add a
1168 // dynamic RELATIVE relocation for this symbol's GOT entry.
1169 if (parameters->options().output_is_position_independent())
1170 {
1171 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
1172 unsigned int r_sym = elfcpp::elf_r_sym<32>(reloc.get_r_info());
1173 rel_dyn->add_local_relative(
1174 object, r_sym, elfcpp::R_ARM_RELATIVE, got,
1175 object->local_got_offset(r_sym, GOT_TYPE_STANDARD));
1176 }
1177 }
1178 }
1179 break;
1180
1181 case elfcpp::R_ARM_TARGET1:
1182 // This should have been mapped to another type already.
1183 // Fall through.
1184 case elfcpp::R_ARM_COPY:
1185 case elfcpp::R_ARM_GLOB_DAT:
1186 case elfcpp::R_ARM_JUMP_SLOT:
1187 case elfcpp::R_ARM_RELATIVE:
1188 // These are relocations which should only be seen by the
1189 // dynamic linker, and should never be seen here.
1190 gold_error(_("%s: unexpected reloc %u in object file"),
1191 object->name().c_str(), r_type);
1192 break;
1193
4a657b0d
DK
1194 default:
1195 unsupported_reloc_local(object, r_type);
1196 break;
1197 }
1198}
1199
1200// Report an unsupported relocation against a global symbol.
1201
1202template<bool big_endian>
1203void
1204Target_arm<big_endian>::Scan::unsupported_reloc_global(
1205 Sized_relobj<32, big_endian>* object,
1206 unsigned int r_type,
1207 Symbol* gsym)
1208{
1209 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1210 object->name().c_str(), r_type, gsym->demangled_name().c_str());
1211}
1212
1213// Scan a relocation for a global symbol.
bec53400
DK
1214// FIXME: This only handles a subset of relocation types used by Android
1215// on ARM v5te devices.
4a657b0d
DK
1216
1217template<bool big_endian>
1218inline void
1219Target_arm<big_endian>::Scan::global(const General_options&,
bec53400
DK
1220 Symbol_table* symtab,
1221 Layout* layout,
1222 Target_arm* target,
4a657b0d 1223 Sized_relobj<32, big_endian>* object,
bec53400
DK
1224 unsigned int data_shndx,
1225 Output_section* output_section,
1226 const elfcpp::Rel<32, big_endian>& reloc,
4a657b0d
DK
1227 unsigned int r_type,
1228 Symbol* gsym)
1229{
1230 r_type = get_real_reloc_type(r_type);
1231 switch (r_type)
1232 {
1233 case elfcpp::R_ARM_NONE:
1234 break;
1235
5e445df6
ILT
1236 case elfcpp::R_ARM_ABS8:
1237 // Make a dynamic relocation if necessary.
1238 if (gsym->needs_dynamic_reloc(Symbol::ABSOLUTE_REF))
1239 {
1240 // FIXME: Create a dynamic relocation for this location.
1241 gold_error(_("%s: gold bug: need dynamic ABS8 reloc for %s"),
1242 object->name().c_str(), gsym->demangled_name().c_str());
1243 }
1244 break;
1245
bec53400
DK
1246 case elfcpp::R_ARM_ABS32:
1247 {
1248 // Make a dynamic relocation if necessary.
1249 if (gsym->needs_dynamic_reloc(Symbol::ABSOLUTE_REF))
1250 {
1251 if (target->may_need_copy_reloc(gsym))
1252 {
1253 target->copy_reloc(symtab, layout, object,
1254 data_shndx, output_section, gsym, reloc);
1255 }
1256 else if (gsym->can_use_relative_reloc(false))
1257 {
1258 // If we are to add more other reloc types than R_ARM_ABS32,
1259 // we need to add check_non_pic(object, r_type) here.
1260 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
1261 rel_dyn->add_global_relative(gsym, elfcpp::R_ARM_RELATIVE,
1262 output_section, object,
1263 data_shndx, reloc.get_r_offset());
1264 }
1265 else
1266 {
1267 // If we are to add more other reloc types than R_ARM_ABS32,
1268 // we need to add check_non_pic(object, r_type) here.
1269 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
1270 rel_dyn->add_global(gsym, r_type, output_section, object,
1271 data_shndx, reloc.get_r_offset());
1272 }
1273 }
1274 }
1275 break;
1276
1277 case elfcpp::R_ARM_REL32:
1278 case elfcpp::R_ARM_PREL31:
1279 {
1280 // Make a dynamic relocation if necessary.
1281 int flags = Symbol::NON_PIC_REF;
1282 if (gsym->needs_dynamic_reloc(flags))
1283 {
1284 if (target->may_need_copy_reloc(gsym))
1285 {
1286 target->copy_reloc(symtab, layout, object,
1287 data_shndx, output_section, gsym, reloc);
1288 }
1289 else
1290 {
1291 check_non_pic(object, r_type);
1292 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
1293 rel_dyn->add_global(gsym, r_type, output_section, object,
1294 data_shndx, reloc.get_r_offset());
1295 }
1296 }
1297 }
1298 break;
1299
1300 case elfcpp::R_ARM_JUMP24:
1301 case elfcpp::R_ARM_THM_CALL:
1302 case elfcpp::R_ARM_CALL:
1303 {
1304 if (Target_arm<big_endian>::Scan::symbol_needs_plt_entry(gsym))
1305 target->make_plt_entry(symtab, layout, gsym);
1306 // Make a dynamic relocation if necessary.
1307 int flags = Symbol::NON_PIC_REF;
1308 if (gsym->type() == elfcpp::STT_FUNC
07800fab 1309 || gsym->type() == elfcpp::STT_ARM_TFUNC)
bec53400
DK
1310 flags |= Symbol::FUNCTION_CALL;
1311 if (gsym->needs_dynamic_reloc(flags))
1312 {
1313 if (target->may_need_copy_reloc(gsym))
1314 {
1315 target->copy_reloc(symtab, layout, object,
1316 data_shndx, output_section, gsym,
1317 reloc);
1318 }
1319 else
1320 {
1321 check_non_pic(object, r_type);
1322 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
1323 rel_dyn->add_global(gsym, r_type, output_section, object,
1324 data_shndx, reloc.get_r_offset());
1325 }
1326 }
1327 }
1328 break;
1329
1330 case elfcpp::R_ARM_PLT32:
1331 // If the symbol is fully resolved, this is just a relative
1332 // local reloc. Otherwise we need a PLT entry.
1333 if (gsym->final_value_is_known())
1334 break;
1335 // If building a shared library, we can also skip the PLT entry
1336 // if the symbol is defined in the output file and is protected
1337 // or hidden.
1338 if (gsym->is_defined()
1339 && !gsym->is_from_dynobj()
1340 && !gsym->is_preemptible())
1341 break;
1342 target->make_plt_entry(symtab, layout, gsym);
1343 break;
1344
1345 case elfcpp::R_ARM_GOTOFF32:
1346 // We need a GOT section.
1347 target->got_section(symtab, layout);
1348 break;
1349
1350 case elfcpp::R_ARM_BASE_PREL:
1351 // FIXME: What about this?
1352 break;
1353
1354 case elfcpp::R_ARM_GOT_BREL:
1355 {
1356 // The symbol requires a GOT entry.
1357 Output_data_got<32, big_endian>* got =
1358 target->got_section(symtab, layout);
1359 if (gsym->final_value_is_known())
1360 got->add_global(gsym, GOT_TYPE_STANDARD);
1361 else
1362 {
1363 // If this symbol is not fully resolved, we need to add a
1364 // GOT entry with a dynamic relocation.
1365 Reloc_section* rel_dyn = target->rel_dyn_section(layout);
1366 if (gsym->is_from_dynobj()
1367 || gsym->is_undefined()
1368 || gsym->is_preemptible())
1369 got->add_global_with_rel(gsym, GOT_TYPE_STANDARD,
1370 rel_dyn, elfcpp::R_ARM_GLOB_DAT);
1371 else
1372 {
1373 if (got->add_global(gsym, GOT_TYPE_STANDARD))
1374 rel_dyn->add_global_relative(
1375 gsym, elfcpp::R_ARM_RELATIVE, got,
1376 gsym->got_offset(GOT_TYPE_STANDARD));
1377 }
1378 }
1379 }
1380 break;
1381
1382 case elfcpp::R_ARM_TARGET1:
1383 // This should have been mapped to another type already.
1384 // Fall through.
1385 case elfcpp::R_ARM_COPY:
1386 case elfcpp::R_ARM_GLOB_DAT:
1387 case elfcpp::R_ARM_JUMP_SLOT:
1388 case elfcpp::R_ARM_RELATIVE:
1389 // These are relocations which should only be seen by the
1390 // dynamic linker, and should never be seen here.
1391 gold_error(_("%s: unexpected reloc %u in object file"),
1392 object->name().c_str(), r_type);
1393 break;
1394
4a657b0d
DK
1395 default:
1396 unsupported_reloc_global(object, r_type, gsym);
1397 break;
1398 }
1399}
1400
1401// Process relocations for gc.
1402
1403template<bool big_endian>
1404void
1405Target_arm<big_endian>::gc_process_relocs(const General_options& options,
1406 Symbol_table* symtab,
1407 Layout* layout,
1408 Sized_relobj<32, big_endian>* object,
1409 unsigned int data_shndx,
1410 unsigned int,
1411 const unsigned char* prelocs,
1412 size_t reloc_count,
1413 Output_section* output_section,
1414 bool needs_special_offset_handling,
1415 size_t local_symbol_count,
1416 const unsigned char* plocal_symbols)
1417{
1418 typedef Target_arm<big_endian> Arm;
1419 typedef typename Target_arm<big_endian>::Scan Scan;
1420
1421 gold::gc_process_relocs<32, big_endian, Arm, elfcpp::SHT_REL, Scan>(
1422 options,
1423 symtab,
1424 layout,
1425 this,
1426 object,
1427 data_shndx,
1428 prelocs,
1429 reloc_count,
1430 output_section,
1431 needs_special_offset_handling,
1432 local_symbol_count,
1433 plocal_symbols);
1434}
1435
1436// Scan relocations for a section.
1437
1438template<bool big_endian>
1439void
1440Target_arm<big_endian>::scan_relocs(const General_options& options,
1441 Symbol_table* symtab,
1442 Layout* layout,
1443 Sized_relobj<32, big_endian>* object,
1444 unsigned int data_shndx,
1445 unsigned int sh_type,
1446 const unsigned char* prelocs,
1447 size_t reloc_count,
1448 Output_section* output_section,
1449 bool needs_special_offset_handling,
1450 size_t local_symbol_count,
1451 const unsigned char* plocal_symbols)
1452{
1453 typedef typename Target_arm<big_endian>::Scan Scan;
1454 if (sh_type == elfcpp::SHT_RELA)
1455 {
1456 gold_error(_("%s: unsupported RELA reloc section"),
1457 object->name().c_str());
1458 return;
1459 }
1460
1461 gold::scan_relocs<32, big_endian, Target_arm, elfcpp::SHT_REL, Scan>(
1462 options,
1463 symtab,
1464 layout,
1465 this,
1466 object,
1467 data_shndx,
1468 prelocs,
1469 reloc_count,
1470 output_section,
1471 needs_special_offset_handling,
1472 local_symbol_count,
1473 plocal_symbols);
1474}
1475
1476// Finalize the sections.
1477
1478template<bool big_endian>
1479void
94cdfcff 1480Target_arm<big_endian>::do_finalize_sections(Layout* layout)
4a657b0d 1481{
94cdfcff
DK
1482 // Fill in some more dynamic tags.
1483 Output_data_dynamic* const odyn = layout->dynamic_data();
1484 if (odyn != NULL)
1485 {
1486 if (this->got_plt_ != NULL)
1487 odyn->add_section_address(elfcpp::DT_PLTGOT, this->got_plt_);
1488
1489 if (this->plt_ != NULL)
1490 {
1491 const Output_data* od = this->plt_->rel_plt();
1492 odyn->add_section_size(elfcpp::DT_PLTRELSZ, od);
1493 odyn->add_section_address(elfcpp::DT_JMPREL, od);
1494 odyn->add_constant(elfcpp::DT_PLTREL, elfcpp::DT_REL);
1495 }
1496
1497 if (this->rel_dyn_ != NULL)
1498 {
1499 const Output_data* od = this->rel_dyn_;
1500 odyn->add_section_address(elfcpp::DT_REL, od);
1501 odyn->add_section_size(elfcpp::DT_RELSZ, od);
1502 odyn->add_constant(elfcpp::DT_RELENT,
1503 elfcpp::Elf_sizes<32>::rel_size);
1504 }
1505
1506 if (!parameters->options().shared())
1507 {
1508 // The value of the DT_DEBUG tag is filled in by the dynamic
1509 // linker at run time, and used by the debugger.
1510 odyn->add_constant(elfcpp::DT_DEBUG, 0);
1511 }
1512 }
1513
1514 // Emit any relocs we saved in an attempt to avoid generating COPY
1515 // relocs.
1516 if (this->copy_relocs_.any_saved_relocs())
1517 this->copy_relocs_.emit(this->rel_dyn_section(layout));
11af873f
DK
1518
1519 // For the ARM target, we need to add a PT_ARM_EXIDX segment for
1520 // the .ARM.exidx section.
1521 if (!layout->script_options()->saw_phdrs_clause()
1522 && !parameters->options().relocatable())
1523 {
1524 Output_section* exidx_section =
1525 layout->find_output_section(".ARM.exidx");
1526
1527 if (exidx_section != NULL
1528 && exidx_section->type() == elfcpp::SHT_ARM_EXIDX)
1529 {
1530 gold_assert(layout->find_output_segment(elfcpp::PT_ARM_EXIDX, 0, 0)
1531 == NULL);
1532 Output_segment* exidx_segment =
1533 layout->make_output_segment(elfcpp::PT_ARM_EXIDX, elfcpp::PF_R);
1534 exidx_segment->add_output_section(exidx_section, elfcpp::PF_R);
1535 }
1536 }
4a657b0d
DK
1537}
1538
bec53400
DK
1539// Return whether a direct absolute static relocation needs to be applied.
1540// In cases where Scan::local() or Scan::global() has created
1541// a dynamic relocation other than R_ARM_RELATIVE, the addend
1542// of the relocation is carried in the data, and we must not
1543// apply the static relocation.
1544
1545template<bool big_endian>
1546inline bool
1547Target_arm<big_endian>::Relocate::should_apply_static_reloc(
1548 const Sized_symbol<32>* gsym,
1549 int ref_flags,
1550 bool is_32bit,
1551 Output_section* output_section)
1552{
1553 // If the output section is not allocated, then we didn't call
1554 // scan_relocs, we didn't create a dynamic reloc, and we must apply
1555 // the reloc here.
1556 if ((output_section->flags() & elfcpp::SHF_ALLOC) == 0)
1557 return true;
1558
1559 // For local symbols, we will have created a non-RELATIVE dynamic
1560 // relocation only if (a) the output is position independent,
1561 // (b) the relocation is absolute (not pc- or segment-relative), and
1562 // (c) the relocation is not 32 bits wide.
1563 if (gsym == NULL)
1564 return !(parameters->options().output_is_position_independent()
1565 && (ref_flags & Symbol::ABSOLUTE_REF)
1566 && !is_32bit);
1567
1568 // For global symbols, we use the same helper routines used in the
1569 // scan pass. If we did not create a dynamic relocation, or if we
1570 // created a RELATIVE dynamic relocation, we should apply the static
1571 // relocation.
1572 bool has_dyn = gsym->needs_dynamic_reloc(ref_flags);
1573 bool is_rel = (ref_flags & Symbol::ABSOLUTE_REF)
1574 && gsym->can_use_relative_reloc(ref_flags
1575 & Symbol::FUNCTION_CALL);
1576 return !has_dyn || is_rel;
1577}
1578
4a657b0d
DK
1579// Perform a relocation.
1580
1581template<bool big_endian>
1582inline bool
1583Target_arm<big_endian>::Relocate::relocate(
c121c671
DK
1584 const Relocate_info<32, big_endian>* relinfo,
1585 Target_arm* target,
1586 Output_section *output_section,
1587 size_t relnum,
1588 const elfcpp::Rel<32, big_endian>& rel,
4a657b0d 1589 unsigned int r_type,
c121c671
DK
1590 const Sized_symbol<32>* gsym,
1591 const Symbol_value<32>* psymval,
1592 unsigned char* view,
1593 elfcpp::Elf_types<32>::Elf_Addr address,
4a657b0d
DK
1594 section_size_type /* view_size */ )
1595{
c121c671
DK
1596 typedef Arm_relocate_functions<big_endian> Arm_relocate_functions;
1597
1598 r_type = get_real_reloc_type(r_type);
1599
1600 // If this the symbol may be a Thumb function, set thumb bit to 1.
1601 bool has_thumb_bit = ((gsym != NULL)
1602 && (gsym->type() == elfcpp::STT_FUNC
1603 || gsym->type() == elfcpp::STT_ARM_TFUNC));
1604
1605 // Pick the value to use for symbols defined in shared objects.
1606 Symbol_value<32> symval;
1607 if (gsym != NULL
1608 && gsym->use_plt_offset(reloc_is_non_pic(r_type)))
1609 {
1610 symval.set_output_value(target->plt_section()->address()
1611 + gsym->plt_offset());
1612 psymval = &symval;
1613 has_thumb_bit = 0;
1614 }
1615
1616 const Sized_relobj<32, big_endian>* object = relinfo->object;
1617
1618 // Get the GOT offset if needed.
1619 // The GOT pointer points to the end of the GOT section.
1620 // We need to subtract the size of the GOT section to get
1621 // the actual offset to use in the relocation.
1622 bool have_got_offset = false;
1623 unsigned int got_offset = 0;
1624 switch (r_type)
1625 {
1626 case elfcpp::R_ARM_GOT_BREL:
1627 if (gsym != NULL)
1628 {
1629 gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
1630 got_offset = (gsym->got_offset(GOT_TYPE_STANDARD)
1631 - target->got_size());
1632 }
1633 else
1634 {
1635 unsigned int r_sym = elfcpp::elf_r_sym<32>(rel.get_r_info());
1636 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
1637 got_offset = (object->local_got_offset(r_sym, GOT_TYPE_STANDARD)
1638 - target->got_size());
1639 }
1640 have_got_offset = true;
1641 break;
1642
1643 default:
1644 break;
1645 }
1646
1647 typename Arm_relocate_functions::Status reloc_status =
1648 Arm_relocate_functions::STATUS_OKAY;
4a657b0d
DK
1649 switch (r_type)
1650 {
1651 case elfcpp::R_ARM_NONE:
1652 break;
1653
5e445df6
ILT
1654 case elfcpp::R_ARM_ABS8:
1655 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
1656 output_section))
1657 reloc_status = Arm_relocate_functions::abs8(view, object, psymval,
1658 has_thumb_bit);
1659 break;
1660
c121c671
DK
1661 case elfcpp::R_ARM_ABS32:
1662 if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, true,
1663 output_section))
1664 reloc_status = Arm_relocate_functions::abs32(view, object, psymval,
1665 has_thumb_bit);
1666 break;
1667
1668 case elfcpp::R_ARM_REL32:
1669 reloc_status = Arm_relocate_functions::rel32(view, object, psymval,
1670 address, has_thumb_bit);
1671 break;
1672
1673 case elfcpp::R_ARM_THM_CALL:
1674 reloc_status = Arm_relocate_functions::thm_call(view, object, psymval,
1675 address, has_thumb_bit);
1676 break;
1677
1678 case elfcpp::R_ARM_GOTOFF32:
1679 {
1680 elfcpp::Elf_types<32>::Elf_Addr got_origin;
1681 got_origin = target->got_plt_section()->address();
1682 reloc_status = Arm_relocate_functions::rel32(view, object, psymval,
1683 got_origin, has_thumb_bit);
1684 }
1685 break;
1686
1687 case elfcpp::R_ARM_BASE_PREL:
1688 {
1689 uint32_t origin;
1690 // Get the addressing origin of the output segment defining the
1691 // symbol gsym (AAELF 4.6.1.2 Relocation types)
1692 gold_assert(gsym != NULL);
1693 if (gsym->source() == Symbol::IN_OUTPUT_SEGMENT)
1694 origin = gsym->output_segment()->vaddr();
1695 else if (gsym->source () == Symbol::IN_OUTPUT_DATA)
1696 origin = gsym->output_data()->address();
1697 else
1698 {
1699 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
1700 _("cannot find origin of R_ARM_BASE_PREL"));
1701 return true;
1702 }
1703 reloc_status = Arm_relocate_functions::base_prel(view, origin, address);
1704 }
1705 break;
1706
1707 case elfcpp::R_ARM_GOT_BREL:
1708 gold_assert(have_got_offset);
1709 reloc_status = Arm_relocate_functions::got_brel(view, got_offset);
1710 break;
1711
1712 case elfcpp::R_ARM_PLT32:
1713 gold_assert(gsym == NULL
1714 || gsym->has_plt_offset()
1715 || gsym->final_value_is_known()
1716 || (gsym->is_defined()
1717 && !gsym->is_from_dynobj()
1718 && !gsym->is_preemptible()));
1719 reloc_status = Arm_relocate_functions::plt32(view, object, psymval,
1720 address, has_thumb_bit);
1721 break;
1722
1723 case elfcpp::R_ARM_CALL:
1724 reloc_status = Arm_relocate_functions::call(view, object, psymval,
1725 address, has_thumb_bit);
1726 break;
1727
1728 case elfcpp::R_ARM_JUMP24:
1729 reloc_status = Arm_relocate_functions::jump24(view, object, psymval,
1730 address, has_thumb_bit);
1731 break;
1732
1733 case elfcpp::R_ARM_PREL31:
1734 reloc_status = Arm_relocate_functions::prel31(view, object, psymval,
1735 address, has_thumb_bit);
1736 break;
1737
1738 case elfcpp::R_ARM_TARGET1:
1739 // This should have been mapped to another type already.
1740 // Fall through.
1741 case elfcpp::R_ARM_COPY:
1742 case elfcpp::R_ARM_GLOB_DAT:
1743 case elfcpp::R_ARM_JUMP_SLOT:
1744 case elfcpp::R_ARM_RELATIVE:
1745 // These are relocations which should only be seen by the
1746 // dynamic linker, and should never be seen here.
1747 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
1748 _("unexpected reloc %u in object file"),
1749 r_type);
1750 break;
1751
1752 default:
1753 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
1754 _("unsupported reloc %u"),
1755 r_type);
1756 break;
1757 }
1758
1759 // Report any errors.
1760 switch (reloc_status)
1761 {
1762 case Arm_relocate_functions::STATUS_OKAY:
1763 break;
1764 case Arm_relocate_functions::STATUS_OVERFLOW:
1765 gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
1766 _("relocation overflow in relocation %u"),
1767 r_type);
1768 break;
1769 case Arm_relocate_functions::STATUS_BAD_RELOC:
1770 gold_error_at_location(
1771 relinfo,
1772 relnum,
1773 rel.get_r_offset(),
1774 _("unexpected opcode while processing relocation %u"),
1775 r_type);
1776 break;
4a657b0d
DK
1777 default:
1778 gold_unreachable();
1779 }
1780
1781 return true;
1782}
1783
1784// Relocate section data.
1785
1786template<bool big_endian>
1787void
1788Target_arm<big_endian>::relocate_section(
1789 const Relocate_info<32, big_endian>* relinfo,
1790 unsigned int sh_type,
1791 const unsigned char* prelocs,
1792 size_t reloc_count,
1793 Output_section* output_section,
1794 bool needs_special_offset_handling,
1795 unsigned char* view,
1796 elfcpp::Elf_types<32>::Elf_Addr address,
1797 section_size_type view_size)
1798{
1799 typedef typename Target_arm<big_endian>::Relocate Arm_relocate;
1800 gold_assert(sh_type == elfcpp::SHT_REL);
1801
1802 gold::relocate_section<32, big_endian, Target_arm, elfcpp::SHT_REL,
1803 Arm_relocate>(
1804 relinfo,
1805 this,
1806 prelocs,
1807 reloc_count,
1808 output_section,
1809 needs_special_offset_handling,
1810 view,
1811 address,
1812 view_size);
1813}
1814
1815// Return the size of a relocation while scanning during a relocatable
1816// link.
1817
1818template<bool big_endian>
1819unsigned int
1820Target_arm<big_endian>::Relocatable_size_for_reloc::get_size_for_reloc(
1821 unsigned int r_type,
1822 Relobj* object)
1823{
1824 r_type = get_real_reloc_type(r_type);
1825 switch (r_type)
1826 {
1827 case elfcpp::R_ARM_NONE:
1828 return 0;
1829
5e445df6
ILT
1830 case elfcpp::R_ARM_ABS8:
1831 return 1;
1832
4a657b0d
DK
1833 case elfcpp::R_ARM_ABS32:
1834 case elfcpp::R_ARM_REL32:
1835 case elfcpp::R_ARM_THM_CALL:
1836 case elfcpp::R_ARM_GOTOFF32:
1837 case elfcpp::R_ARM_BASE_PREL:
1838 case elfcpp::R_ARM_GOT_BREL:
1839 case elfcpp::R_ARM_PLT32:
1840 case elfcpp::R_ARM_CALL:
1841 case elfcpp::R_ARM_JUMP24:
1842 case elfcpp::R_ARM_PREL31:
1843 return 4;
1844
1845 case elfcpp::R_ARM_TARGET1:
1846 // This should have been mapped to another type already.
1847 // Fall through.
1848 case elfcpp::R_ARM_COPY:
1849 case elfcpp::R_ARM_GLOB_DAT:
1850 case elfcpp::R_ARM_JUMP_SLOT:
1851 case elfcpp::R_ARM_RELATIVE:
1852 // These are relocations which should only be seen by the
1853 // dynamic linker, and should never be seen here.
1854 gold_error(_("%s: unexpected reloc %u in object file"),
1855 object->name().c_str(), r_type);
1856 return 0;
1857
1858 default:
1859 object->error(_("unsupported reloc %u in object file"), r_type);
1860 return 0;
1861 }
1862}
1863
1864// Scan the relocs during a relocatable link.
1865
1866template<bool big_endian>
1867void
1868Target_arm<big_endian>::scan_relocatable_relocs(
1869 const General_options& options,
1870 Symbol_table* symtab,
1871 Layout* layout,
1872 Sized_relobj<32, big_endian>* object,
1873 unsigned int data_shndx,
1874 unsigned int sh_type,
1875 const unsigned char* prelocs,
1876 size_t reloc_count,
1877 Output_section* output_section,
1878 bool needs_special_offset_handling,
1879 size_t local_symbol_count,
1880 const unsigned char* plocal_symbols,
1881 Relocatable_relocs* rr)
1882{
1883 gold_assert(sh_type == elfcpp::SHT_REL);
1884
1885 typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_REL,
1886 Relocatable_size_for_reloc> Scan_relocatable_relocs;
1887
1888 gold::scan_relocatable_relocs<32, big_endian, elfcpp::SHT_REL,
1889 Scan_relocatable_relocs>(
1890 options,
1891 symtab,
1892 layout,
1893 object,
1894 data_shndx,
1895 prelocs,
1896 reloc_count,
1897 output_section,
1898 needs_special_offset_handling,
1899 local_symbol_count,
1900 plocal_symbols,
1901 rr);
1902}
1903
1904// Relocate a section during a relocatable link.
1905
1906template<bool big_endian>
1907void
1908Target_arm<big_endian>::relocate_for_relocatable(
1909 const Relocate_info<32, big_endian>* relinfo,
1910 unsigned int sh_type,
1911 const unsigned char* prelocs,
1912 size_t reloc_count,
1913 Output_section* output_section,
1914 off_t offset_in_output_section,
1915 const Relocatable_relocs* rr,
1916 unsigned char* view,
1917 elfcpp::Elf_types<32>::Elf_Addr view_address,
1918 section_size_type view_size,
1919 unsigned char* reloc_view,
1920 section_size_type reloc_view_size)
1921{
1922 gold_assert(sh_type == elfcpp::SHT_REL);
1923
1924 gold::relocate_for_relocatable<32, big_endian, elfcpp::SHT_REL>(
1925 relinfo,
1926 prelocs,
1927 reloc_count,
1928 output_section,
1929 offset_in_output_section,
1930 rr,
1931 view,
1932 view_address,
1933 view_size,
1934 reloc_view,
1935 reloc_view_size);
1936}
1937
94cdfcff
DK
1938// Return the value to use for a dynamic symbol which requires special
1939// treatment. This is how we support equality comparisons of function
1940// pointers across shared library boundaries, as described in the
1941// processor specific ABI supplement.
1942
4a657b0d
DK
1943template<bool big_endian>
1944uint64_t
94cdfcff 1945Target_arm<big_endian>::do_dynsym_value(const Symbol* gsym) const
4a657b0d 1946{
94cdfcff
DK
1947 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
1948 return this->plt_section()->address() + gsym->plt_offset();
4a657b0d
DK
1949}
1950
1951// Map platform-specific relocs to real relocs
1952//
1953template<bool big_endian>
1954unsigned int
1955Target_arm<big_endian>::get_real_reloc_type (unsigned int r_type)
1956{
1957 switch (r_type)
1958 {
1959 case elfcpp::R_ARM_TARGET1:
1960 // This is either R_ARM_ABS32 or R_ARM_REL32;
1961 return elfcpp::R_ARM_ABS32;
1962
1963 case elfcpp::R_ARM_TARGET2:
1964 // This can be any reloc type but ususally is R_ARM_GOT_PREL
1965 return elfcpp::R_ARM_GOT_PREL;
1966
1967 default:
1968 return r_type;
1969 }
1970}
1971
1972// The selector for arm object files.
1973
1974template<bool big_endian>
1975class Target_selector_arm : public Target_selector
1976{
1977 public:
1978 Target_selector_arm()
1979 : Target_selector(elfcpp::EM_ARM, 32, big_endian,
1980 (big_endian ? "elf32-bigarm" : "elf32-littlearm"))
1981 { }
1982
1983 Target*
1984 do_instantiate_target()
1985 { return new Target_arm<big_endian>(); }
1986};
1987
1988Target_selector_arm<false> target_selector_arm;
1989Target_selector_arm<true> target_selector_armbe;
1990
1991} // End anonymous namespace.