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