1 // mips.cc -- mips target support for gold.
3 // Copyright (C) 2011-2014 Free Software Foundation, Inc.
4 // Written by Sasa Stankovic <sasa.stankovic@imgtec.com>
5 // and Aleksandar Simeonov <aleksandar.simeonov@rt-rk.com>.
6 // This file contains borrowed and adapted code from bfd/elfxx-mips.c.
8 // This file is part of gold.
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 3 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 // MA 02110-1301, USA.
33 #include "parameters.h"
40 #include "copy-relocs.h"
42 #include "target-reloc.h"
43 #include "target-select.h"
52 template<int size
, bool big_endian
>
53 class Mips_output_data_plt
;
55 template<int size
, bool big_endian
>
56 class Mips_output_data_got
;
58 template<int size
, bool big_endian
>
61 template<int size
, bool big_endian
>
62 class Mips_output_section_reginfo
;
64 template<int size
, bool big_endian
>
65 class Mips_output_data_la25_stub
;
67 template<int size
, bool big_endian
>
68 class Mips_output_data_mips_stubs
;
73 template<int size
, bool big_endian
>
76 template<int size
, bool big_endian
>
79 class Mips16_stub_section_base
;
81 template<int size
, bool big_endian
>
82 class Mips16_stub_section
;
84 // The ABI says that every symbol used by dynamic relocations must have
85 // a global GOT entry. Among other things, this provides the dynamic
86 // linker with a free, directly-indexed cache. The GOT can therefore
87 // contain symbols that are not referenced by GOT relocations themselves
88 // (in other words, it may have symbols that are not referenced by things
89 // like R_MIPS_GOT16 and R_MIPS_GOT_PAGE).
91 // GOT relocations are less likely to overflow if we put the associated
92 // GOT entries towards the beginning. We therefore divide the global
93 // GOT entries into two areas: "normal" and "reloc-only". Entries in
94 // the first area can be used for both dynamic relocations and GP-relative
95 // accesses, while those in the "reloc-only" area are for dynamic
98 // These GGA_* ("Global GOT Area") values are organised so that lower
99 // values are more general than higher values. Also, non-GGA_NONE
100 // values are ordered by the position of the area in the GOT.
109 // The types of GOT entries needed for this platform.
110 // These values are exposed to the ABI in an incremental link.
111 // Do not renumber existing values without changing the version
112 // number of the .gnu_incremental_inputs section.
115 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
116 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
117 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
119 // GOT entries for multi-GOT. We support up to 1024 GOTs in multi-GOT links.
120 GOT_TYPE_STANDARD_MULTIGOT
= 3,
121 GOT_TYPE_TLS_OFFSET_MULTIGOT
= GOT_TYPE_STANDARD_MULTIGOT
+ 1024,
122 GOT_TYPE_TLS_PAIR_MULTIGOT
= GOT_TYPE_TLS_OFFSET_MULTIGOT
+ 1024
125 // TLS type of GOT entry.
134 // Return TRUE if a relocation of type R_TYPE from OBJECT might
135 // require an la25 stub. See also local_pic_function, which determines
136 // whether the destination function ever requires a stub.
137 template<int size
, bool big_endian
>
139 relocation_needs_la25_stub(Mips_relobj
<size
, big_endian
>* object
,
140 unsigned int r_type
, bool target_is_16_bit_code
)
142 // We specifically ignore branches and jumps from EF_PIC objects,
143 // where the onus is on the compiler or programmer to perform any
144 // necessary initialization of $25. Sometimes such initialization
145 // is unnecessary; for example, -mno-shared functions do not use
146 // the incoming value of $25, and may therefore be called directly.
147 if (object
->is_pic())
152 case elfcpp::R_MIPS_26
:
153 case elfcpp::R_MIPS_PC16
:
154 case elfcpp::R_MICROMIPS_26_S1
:
155 case elfcpp::R_MICROMIPS_PC7_S1
:
156 case elfcpp::R_MICROMIPS_PC10_S1
:
157 case elfcpp::R_MICROMIPS_PC16_S1
:
158 case elfcpp::R_MICROMIPS_PC23_S2
:
161 case elfcpp::R_MIPS16_26
:
162 return !target_is_16_bit_code
;
169 // Return true if SYM is a locally-defined PIC function, in the sense
170 // that it or its fn_stub might need $25 to be valid on entry.
171 // Note that MIPS16 functions set up $gp using PC-relative instructions,
172 // so they themselves never need $25 to be valid. Only non-MIPS16
173 // entry points are of interest here.
174 template<int size
, bool big_endian
>
176 local_pic_function(Mips_symbol
<size
>* sym
)
178 bool def_regular
= (sym
->source() == Symbol::FROM_OBJECT
179 && !sym
->object()->is_dynamic()
180 && !sym
->is_undefined());
182 if (sym
->is_defined() && def_regular
)
184 Mips_relobj
<size
, big_endian
>* object
=
185 static_cast<Mips_relobj
<size
, big_endian
>*>(sym
->object());
187 if ((object
->is_pic() || sym
->is_pic())
188 && (!sym
->is_mips16()
189 || (sym
->has_mips16_fn_stub() && sym
->need_fn_stub())))
196 hi16_reloc(int r_type
)
198 return (r_type
== elfcpp::R_MIPS_HI16
199 || r_type
== elfcpp::R_MIPS16_HI16
200 || r_type
== elfcpp::R_MICROMIPS_HI16
);
204 lo16_reloc(int r_type
)
206 return (r_type
== elfcpp::R_MIPS_LO16
207 || r_type
== elfcpp::R_MIPS16_LO16
208 || r_type
== elfcpp::R_MICROMIPS_LO16
);
212 got16_reloc(unsigned int r_type
)
214 return (r_type
== elfcpp::R_MIPS_GOT16
215 || r_type
== elfcpp::R_MIPS16_GOT16
216 || r_type
== elfcpp::R_MICROMIPS_GOT16
);
220 call_lo16_reloc(unsigned int r_type
)
222 return (r_type
== elfcpp::R_MIPS_CALL_LO16
223 || r_type
== elfcpp::R_MICROMIPS_CALL_LO16
);
227 got_lo16_reloc(unsigned int r_type
)
229 return (r_type
== elfcpp::R_MIPS_GOT_LO16
230 || r_type
== elfcpp::R_MICROMIPS_GOT_LO16
);
234 got_disp_reloc(unsigned int r_type
)
236 return (r_type
== elfcpp::R_MIPS_GOT_DISP
237 || r_type
== elfcpp::R_MICROMIPS_GOT_DISP
);
241 got_page_reloc(unsigned int r_type
)
243 return (r_type
== elfcpp::R_MIPS_GOT_PAGE
244 || r_type
== elfcpp::R_MICROMIPS_GOT_PAGE
);
248 tls_gd_reloc(unsigned int r_type
)
250 return (r_type
== elfcpp::R_MIPS_TLS_GD
251 || r_type
== elfcpp::R_MIPS16_TLS_GD
252 || r_type
== elfcpp::R_MICROMIPS_TLS_GD
);
256 tls_gottprel_reloc(unsigned int r_type
)
258 return (r_type
== elfcpp::R_MIPS_TLS_GOTTPREL
259 || r_type
== elfcpp::R_MIPS16_TLS_GOTTPREL
260 || r_type
== elfcpp::R_MICROMIPS_TLS_GOTTPREL
);
264 tls_ldm_reloc(unsigned int r_type
)
266 return (r_type
== elfcpp::R_MIPS_TLS_LDM
267 || r_type
== elfcpp::R_MIPS16_TLS_LDM
268 || r_type
== elfcpp::R_MICROMIPS_TLS_LDM
);
272 mips16_call_reloc(unsigned int r_type
)
274 return (r_type
== elfcpp::R_MIPS16_26
275 || r_type
== elfcpp::R_MIPS16_CALL16
);
279 jal_reloc(unsigned int r_type
)
281 return (r_type
== elfcpp::R_MIPS_26
282 || r_type
== elfcpp::R_MIPS16_26
283 || r_type
== elfcpp::R_MICROMIPS_26_S1
);
287 micromips_branch_reloc(unsigned int r_type
)
289 return (r_type
== elfcpp::R_MICROMIPS_26_S1
290 || r_type
== elfcpp::R_MICROMIPS_PC16_S1
291 || r_type
== elfcpp::R_MICROMIPS_PC10_S1
292 || r_type
== elfcpp::R_MICROMIPS_PC7_S1
);
295 // Check if R_TYPE is a MIPS16 reloc.
297 mips16_reloc(unsigned int r_type
)
301 case elfcpp::R_MIPS16_26
:
302 case elfcpp::R_MIPS16_GPREL
:
303 case elfcpp::R_MIPS16_GOT16
:
304 case elfcpp::R_MIPS16_CALL16
:
305 case elfcpp::R_MIPS16_HI16
:
306 case elfcpp::R_MIPS16_LO16
:
307 case elfcpp::R_MIPS16_TLS_GD
:
308 case elfcpp::R_MIPS16_TLS_LDM
:
309 case elfcpp::R_MIPS16_TLS_DTPREL_HI16
:
310 case elfcpp::R_MIPS16_TLS_DTPREL_LO16
:
311 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
312 case elfcpp::R_MIPS16_TLS_TPREL_HI16
:
313 case elfcpp::R_MIPS16_TLS_TPREL_LO16
:
321 // Check if R_TYPE is a microMIPS reloc.
323 micromips_reloc(unsigned int r_type
)
327 case elfcpp::R_MICROMIPS_26_S1
:
328 case elfcpp::R_MICROMIPS_HI16
:
329 case elfcpp::R_MICROMIPS_LO16
:
330 case elfcpp::R_MICROMIPS_GPREL16
:
331 case elfcpp::R_MICROMIPS_LITERAL
:
332 case elfcpp::R_MICROMIPS_GOT16
:
333 case elfcpp::R_MICROMIPS_PC7_S1
:
334 case elfcpp::R_MICROMIPS_PC10_S1
:
335 case elfcpp::R_MICROMIPS_PC16_S1
:
336 case elfcpp::R_MICROMIPS_CALL16
:
337 case elfcpp::R_MICROMIPS_GOT_DISP
:
338 case elfcpp::R_MICROMIPS_GOT_PAGE
:
339 case elfcpp::R_MICROMIPS_GOT_OFST
:
340 case elfcpp::R_MICROMIPS_GOT_HI16
:
341 case elfcpp::R_MICROMIPS_GOT_LO16
:
342 case elfcpp::R_MICROMIPS_SUB
:
343 case elfcpp::R_MICROMIPS_HIGHER
:
344 case elfcpp::R_MICROMIPS_HIGHEST
:
345 case elfcpp::R_MICROMIPS_CALL_HI16
:
346 case elfcpp::R_MICROMIPS_CALL_LO16
:
347 case elfcpp::R_MICROMIPS_SCN_DISP
:
348 case elfcpp::R_MICROMIPS_JALR
:
349 case elfcpp::R_MICROMIPS_HI0_LO16
:
350 case elfcpp::R_MICROMIPS_TLS_GD
:
351 case elfcpp::R_MICROMIPS_TLS_LDM
:
352 case elfcpp::R_MICROMIPS_TLS_DTPREL_HI16
:
353 case elfcpp::R_MICROMIPS_TLS_DTPREL_LO16
:
354 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
355 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
356 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
357 case elfcpp::R_MICROMIPS_GPREL7_S2
:
358 case elfcpp::R_MICROMIPS_PC23_S2
:
367 is_matching_lo16_reloc(unsigned int high_reloc
, unsigned int lo16_reloc
)
371 case elfcpp::R_MIPS_HI16
:
372 case elfcpp::R_MIPS_GOT16
:
373 return lo16_reloc
== elfcpp::R_MIPS_LO16
;
374 case elfcpp::R_MIPS16_HI16
:
375 case elfcpp::R_MIPS16_GOT16
:
376 return lo16_reloc
== elfcpp::R_MIPS16_LO16
;
377 case elfcpp::R_MICROMIPS_HI16
:
378 case elfcpp::R_MICROMIPS_GOT16
:
379 return lo16_reloc
== elfcpp::R_MICROMIPS_LO16
;
385 // This class is used to hold information about one GOT entry.
386 // There are three types of entry:
388 // (1) a SYMBOL + OFFSET address, where SYMBOL is local to an input object
389 // (object != NULL, symndx >= 0, tls_type != GOT_TLS_LDM)
390 // (2) a SYMBOL address, where SYMBOL is not local to an input object
391 // (object != NULL, symndx == -1)
392 // (3) a TLS LDM slot
393 // (object != NULL, symndx == 0, tls_type == GOT_TLS_LDM)
395 template<int size
, bool big_endian
>
398 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
401 Mips_got_entry(Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
,
402 Mips_address addend
, unsigned char tls_type
,
404 : object_(object
), symndx_(symndx
), tls_type_(tls_type
), shndx_(shndx
)
405 { this->d
.addend
= addend
; }
407 Mips_got_entry(Mips_relobj
<size
, big_endian
>* object
, Mips_symbol
<size
>* sym
,
408 unsigned char tls_type
)
409 : object_(object
), symndx_(-1U), tls_type_(tls_type
), shndx_(-1U)
410 { this->d
.sym
= sym
; }
412 // Return whether this entry is for a local symbol.
414 is_for_local_symbol() const
415 { return this->symndx_
!= -1U; }
417 // Return whether this entry is for a global symbol.
419 is_for_global_symbol() const
420 { return this->symndx_
== -1U; }
422 // Return the hash of this entry.
426 if (this->tls_type_
== GOT_TLS_LDM
)
427 return this->symndx_
+ (1 << 18);
428 if (this->symndx_
!= -1U)
430 uintptr_t object_id
= reinterpret_cast<uintptr_t>(this->object());
431 return this->symndx_
+ object_id
+ this->d
.addend
;
435 uintptr_t sym_id
= reinterpret_cast<uintptr_t>(this->d
.sym
);
436 return this->symndx_
+ sym_id
;
440 // Return whether this entry is equal to OTHER.
442 equals(Mips_got_entry
<size
, big_endian
>* other
) const
444 if (this->symndx_
!= other
->symndx_
445 || this->tls_type_
!= other
->tls_type_
)
447 if (this->tls_type_
== GOT_TLS_LDM
)
449 if (this->symndx_
!= -1U)
450 return (this->object() == other
->object()
451 && this->d
.addend
== other
->d
.addend
);
453 return this->d
.sym
== other
->d
.sym
;
456 // Return input object that needs this GOT entry.
457 Mips_relobj
<size
, big_endian
>*
460 gold_assert(this->object_
!= NULL
);
461 return this->object_
;
464 // Return local symbol index for local GOT entries.
468 gold_assert(this->symndx_
!= -1U);
469 return this->symndx_
;
472 // Return the relocation addend for local GOT entries.
476 gold_assert(this->symndx_
!= -1U);
477 return this->d
.addend
;
480 // Return global symbol for global GOT entries.
484 gold_assert(this->symndx_
== -1U);
488 // Return whether this is a TLS GOT entry.
491 { return this->tls_type_
!= GOT_TLS_NONE
; }
493 // Return TLS type of this GOT entry.
496 { return this->tls_type_
; }
498 // Return section index of the local symbol for local GOT entries.
501 { return this->shndx_
; }
504 // The input object that needs the GOT entry.
505 Mips_relobj
<size
, big_endian
>* object_
;
506 // The index of the symbol if we have a local symbol; -1 otherwise.
507 unsigned int symndx_
;
511 // If symndx != -1, the addend of the relocation that should be added to the
514 // If symndx == -1, the global symbol corresponding to this GOT entry. The
515 // symbol's entry is in the local area if mips_sym->global_got_area is
516 // GGA_NONE, otherwise it is in the global area.
517 Mips_symbol
<size
>* sym
;
520 // The TLS type of this GOT entry. An LDM GOT entry will be a local
521 // symbol entry with r_symndx == 0.
522 unsigned char tls_type_
;
524 // For local GOT entries, section index of the local symbol.
528 // Hash for Mips_got_entry.
530 template<int size
, bool big_endian
>
531 class Mips_got_entry_hash
535 operator()(Mips_got_entry
<size
, big_endian
>* entry
) const
536 { return entry
->hash(); }
539 // Equality for Mips_got_entry.
541 template<int size
, bool big_endian
>
542 class Mips_got_entry_eq
546 operator()(Mips_got_entry
<size
, big_endian
>* e1
,
547 Mips_got_entry
<size
, big_endian
>* e2
) const
548 { return e1
->equals(e2
); }
551 // Got_page_range. This class describes a range of addends: [MIN_ADDEND,
552 // MAX_ADDEND]. The instances form a non-overlapping list that is sorted by
553 // increasing MIN_ADDEND.
555 struct Got_page_range
558 : next(NULL
), min_addend(0), max_addend(0)
561 Got_page_range
* next
;
565 // Return the maximum number of GOT page entries required.
568 { return (this->max_addend
- this->min_addend
+ 0x1ffff) >> 16; }
571 // Got_page_entry. This class describes the range of addends that are applied
572 // to page relocations against a given symbol.
574 struct Got_page_entry
577 : object(NULL
), symndx(-1U), ranges(NULL
), num_pages(0)
580 Got_page_entry(Object
* object_
, unsigned int symndx_
)
581 : object(object_
), symndx(symndx_
), ranges(NULL
), num_pages(0)
584 // The input object that needs the GOT page entry.
586 // The index of the symbol, as stored in the relocation r_info.
588 // The ranges for this page entry.
589 Got_page_range
* ranges
;
590 // The maximum number of page entries needed for RANGES.
591 unsigned int num_pages
;
594 // Hash for Got_page_entry.
596 struct Got_page_entry_hash
599 operator()(Got_page_entry
* entry
) const
600 { return reinterpret_cast<uintptr_t>(entry
->object
) + entry
->symndx
; }
603 // Equality for Got_page_entry.
605 struct Got_page_entry_eq
608 operator()(Got_page_entry
* entry1
, Got_page_entry
* entry2
) const
610 return entry1
->object
== entry2
->object
&& entry1
->symndx
== entry2
->symndx
;
614 // This class is used to hold .got information when linking.
616 template<int size
, bool big_endian
>
619 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
620 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
622 typedef Unordered_map
<unsigned int, unsigned int> Got_page_offsets
;
624 // Unordered set of GOT entries.
625 typedef Unordered_set
<Mips_got_entry
<size
, big_endian
>*,
626 Mips_got_entry_hash
<size
, big_endian
>,
627 Mips_got_entry_eq
<size
, big_endian
> > Got_entry_set
;
629 // Unordered set of GOT page entries.
630 typedef Unordered_set
<Got_page_entry
*,
631 Got_page_entry_hash
, Got_page_entry_eq
> Got_page_entry_set
;
635 : local_gotno_(0), page_gotno_(0), global_gotno_(0), reloc_only_gotno_(0),
636 tls_gotno_(0), tls_ldm_offset_(-1U), global_got_symbols_(),
637 got_entries_(), got_page_entries_(), got_page_offset_start_(0),
638 got_page_offset_next_(0), got_page_offsets_(), next_(NULL
), index_(-1U),
642 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
643 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
645 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
646 unsigned int symndx
, Mips_address addend
,
647 unsigned int r_type
, unsigned int shndx
);
649 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
650 // in OBJECT. FOR_CALL is true if the caller is only interested in
651 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
654 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
655 Mips_relobj
<size
, big_endian
>* object
,
656 unsigned int r_type
, bool dyn_reloc
, bool for_call
);
658 // Add ENTRY to master GOT and to OBJECT's GOT.
660 record_got_entry(Mips_got_entry
<size
, big_endian
>* entry
,
661 Mips_relobj
<size
, big_endian
>* object
);
663 // Record that OBJECT has a page relocation against symbol SYMNDX and
664 // that ADDEND is the addend for that relocation.
666 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
667 unsigned int symndx
, int addend
);
669 // Create all entries that should be in the local part of the GOT.
671 add_local_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
673 // Create GOT page entries.
675 add_page_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
677 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
679 add_global_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
680 unsigned int non_reloc_only_global_gotno
);
682 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
684 add_reloc_only_entries(Mips_output_data_got
<size
, big_endian
>* got
);
686 // Create TLS GOT entries.
688 add_tls_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
690 // Decide whether the symbol needs an entry in the global part of the primary
691 // GOT, setting global_got_area accordingly. Count the number of global
692 // symbols that are in the primary GOT only because they have dynamic
693 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
695 count_got_symbols(Symbol_table
* symtab
);
697 // Return the offset of GOT page entry for VALUE.
699 get_got_page_offset(Mips_address value
,
700 Mips_output_data_got
<size
, big_endian
>* got
);
702 // Count the number of GOT entries required.
706 // Count the number of GOT entries required by ENTRY. Accumulate the result.
708 count_got_entry(Mips_got_entry
<size
, big_endian
>* entry
);
710 // Add FROM's GOT entries.
712 add_got_entries(Mips_got_info
<size
, big_endian
>* from
);
714 // Add FROM's GOT page entries.
716 add_got_page_entries(Mips_got_info
<size
, big_endian
>* from
);
721 { return ((2 + this->local_gotno_
+ this->page_gotno_
+ this->global_gotno_
722 + this->tls_gotno_
) * size
/8);
725 // Return the number of local GOT entries.
728 { return this->local_gotno_
; }
730 // Return the maximum number of page GOT entries needed.
733 { return this->page_gotno_
; }
735 // Return the number of global GOT entries.
738 { return this->global_gotno_
; }
740 // Set the number of global GOT entries.
742 set_global_gotno(unsigned int global_gotno
)
743 { this->global_gotno_
= global_gotno
; }
745 // Return the number of GGA_RELOC_ONLY global GOT entries.
747 reloc_only_gotno() const
748 { return this->reloc_only_gotno_
; }
750 // Return the number of TLS GOT entries.
753 { return this->tls_gotno_
; }
755 // Return the GOT type for this GOT. Used for multi-GOT links only.
757 multigot_got_type(unsigned int got_type
) const
761 case GOT_TYPE_STANDARD
:
762 return GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
763 case GOT_TYPE_TLS_OFFSET
:
764 return GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
765 case GOT_TYPE_TLS_PAIR
:
766 return GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
772 // Remove lazy-binding stubs for global symbols in this GOT.
774 remove_lazy_stubs(Target_mips
<size
, big_endian
>* target
);
776 // Return offset of this GOT from the start of .got section.
779 { return this->offset_
; }
781 // Set offset of this GOT from the start of .got section.
783 set_offset(unsigned int offset
)
784 { this->offset_
= offset
; }
786 // Set index of this GOT in multi-GOT links.
788 set_index(unsigned int index
)
789 { this->index_
= index
; }
791 // Return next GOT in multi-GOT links.
792 Mips_got_info
<size
, big_endian
>*
794 { return this->next_
; }
796 // Set next GOT in multi-GOT links.
798 set_next(Mips_got_info
<size
, big_endian
>* next
)
799 { this->next_
= next
; }
801 // Return the offset of TLS LDM entry for this GOT.
803 tls_ldm_offset() const
804 { return this->tls_ldm_offset_
; }
806 // Set the offset of TLS LDM entry for this GOT.
808 set_tls_ldm_offset(unsigned int tls_ldm_offset
)
809 { this->tls_ldm_offset_
= tls_ldm_offset
; }
811 Unordered_set
<Mips_symbol
<size
>*>&
813 { return this->global_got_symbols_
; }
815 // Return the GOT_TLS_* type required by relocation type R_TYPE.
817 mips_elf_reloc_tls_type(unsigned int r_type
)
819 if (tls_gd_reloc(r_type
))
822 if (tls_ldm_reloc(r_type
))
825 if (tls_gottprel_reloc(r_type
))
831 // Return the number of GOT slots needed for GOT TLS type TYPE.
833 mips_tls_got_entries(unsigned int type
)
853 // The number of local GOT entries.
854 unsigned int local_gotno_
;
855 // The maximum number of page GOT entries needed.
856 unsigned int page_gotno_
;
857 // The number of global GOT entries.
858 unsigned int global_gotno_
;
859 // The number of global GOT entries that are in the GGA_RELOC_ONLY area.
860 unsigned int reloc_only_gotno_
;
861 // The number of TLS GOT entries.
862 unsigned int tls_gotno_
;
863 // The offset of TLS LDM entry for this GOT.
864 unsigned int tls_ldm_offset_
;
865 // All symbols that have global GOT entry.
866 Unordered_set
<Mips_symbol
<size
>*> global_got_symbols_
;
867 // A hash table holding GOT entries.
868 Got_entry_set got_entries_
;
869 // A hash table of GOT page entries.
870 Got_page_entry_set got_page_entries_
;
871 // The offset of first GOT page entry for this GOT.
872 unsigned int got_page_offset_start_
;
873 // The offset of next available GOT page entry for this GOT.
874 unsigned int got_page_offset_next_
;
875 // A hash table that maps GOT page entry value to the GOT offset where
876 // the entry is located.
877 Got_page_offsets got_page_offsets_
;
878 // In multi-GOT links, a pointer to the next GOT.
879 Mips_got_info
<size
, big_endian
>* next_
;
880 // Index of this GOT in multi-GOT links.
882 // The offset of this GOT in multi-GOT links.
883 unsigned int offset_
;
886 // This is a helper class used during relocation scan. It records GOT16 addend.
888 template<int size
, bool big_endian
>
891 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
893 got16_addend(const Sized_relobj_file
<size
, big_endian
>* _object
,
894 unsigned int _shndx
, unsigned int _r_type
, unsigned int _r_sym
,
895 Mips_address _addend
)
896 : object(_object
), shndx(_shndx
), r_type(_r_type
), r_sym(_r_sym
),
900 const Sized_relobj_file
<size
, big_endian
>* object
;
907 // Mips_symbol class. Holds additional symbol information needed for Mips.
910 class Mips_symbol
: public Sized_symbol
<size
>
914 : need_fn_stub_(false), has_nonpic_branches_(false), la25_stub_offset_(-1U),
915 has_static_relocs_(false), no_lazy_stub_(false), lazy_stub_offset_(0),
916 pointer_equality_needed_(false), global_got_area_(GGA_NONE
),
917 global_gotoffset_(-1U), got_only_for_calls_(true), has_lazy_stub_(false),
918 needs_mips_plt_(false), needs_comp_plt_(false), mips_plt_offset_(-1U),
919 comp_plt_offset_(-1U), mips16_fn_stub_(NULL
), mips16_call_stub_(NULL
),
920 mips16_call_fp_stub_(NULL
), applied_secondary_got_fixup_(false)
923 // Return whether this is a MIPS16 symbol.
927 // (st_other & STO_MIPS16) == STO_MIPS16
928 return ((this->nonvis() & (elfcpp::STO_MIPS16
>> 2))
929 == elfcpp::STO_MIPS16
>> 2);
932 // Return whether this is a microMIPS symbol.
936 // (st_other & STO_MIPS_ISA) == STO_MICROMIPS
937 return ((this->nonvis() & (elfcpp::STO_MIPS_ISA
>> 2))
938 == elfcpp::STO_MICROMIPS
>> 2);
941 // Return whether the symbol needs MIPS16 fn_stub.
944 { return this->need_fn_stub_
; }
946 // Set that the symbol needs MIPS16 fn_stub.
949 { this->need_fn_stub_
= true; }
951 // Return whether this symbol is referenced by branch relocations from
952 // any non-PIC input file.
954 has_nonpic_branches() const
955 { return this->has_nonpic_branches_
; }
957 // Set that this symbol is referenced by branch relocations from
958 // any non-PIC input file.
960 set_has_nonpic_branches()
961 { this->has_nonpic_branches_
= true; }
963 // Return the offset of the la25 stub for this symbol from the start of the
964 // la25 stub section.
966 la25_stub_offset() const
967 { return this->la25_stub_offset_
; }
969 // Set the offset of the la25 stub for this symbol from the start of the
970 // la25 stub section.
972 set_la25_stub_offset(unsigned int offset
)
973 { this->la25_stub_offset_
= offset
; }
975 // Return whether the symbol has la25 stub. This is true if this symbol is
976 // for a PIC function, and there are non-PIC branches and jumps to it.
978 has_la25_stub() const
979 { return this->la25_stub_offset_
!= -1U; }
981 // Return whether there is a relocation against this symbol that must be
982 // resolved by the static linker (that is, the relocation cannot possibly
985 has_static_relocs() const
986 { return this->has_static_relocs_
; }
988 // Set that there is a relocation against this symbol that must be resolved
989 // by the static linker (that is, the relocation cannot possibly be made
992 set_has_static_relocs()
993 { this->has_static_relocs_
= true; }
995 // Return whether we must not create a lazy-binding stub for this symbol.
998 { return this->no_lazy_stub_
; }
1000 // Set that we must not create a lazy-binding stub for this symbol.
1003 { this->no_lazy_stub_
= true; }
1005 // Return the offset of the lazy-binding stub for this symbol from the start
1006 // of .MIPS.stubs section.
1008 lazy_stub_offset() const
1009 { return this->lazy_stub_offset_
; }
1011 // Set the offset of the lazy-binding stub for this symbol from the start
1012 // of .MIPS.stubs section.
1014 set_lazy_stub_offset(unsigned int offset
)
1015 { this->lazy_stub_offset_
= offset
; }
1017 // Return whether there are any relocations for this symbol where
1018 // pointer equality matters.
1020 pointer_equality_needed() const
1021 { return this->pointer_equality_needed_
; }
1023 // Set that there are relocations for this symbol where pointer equality
1026 set_pointer_equality_needed()
1027 { this->pointer_equality_needed_
= true; }
1029 // Return global GOT area where this symbol in located.
1031 global_got_area() const
1032 { return this->global_got_area_
; }
1034 // Set global GOT area where this symbol in located.
1036 set_global_got_area(Global_got_area global_got_area
)
1037 { this->global_got_area_
= global_got_area
; }
1039 // Return the global GOT offset for this symbol. For multi-GOT links, this
1040 // returns the offset from the start of .got section to the first GOT entry
1041 // for the symbol. Note that in multi-GOT links the symbol can have entry
1042 // in more than one GOT.
1044 global_gotoffset() const
1045 { return this->global_gotoffset_
; }
1047 // Set the global GOT offset for this symbol. Note that in multi-GOT links
1048 // the symbol can have entry in more than one GOT. This method will set
1049 // the offset only if it is less than current offset.
1051 set_global_gotoffset(unsigned int offset
)
1053 if (this->global_gotoffset_
== -1U || offset
< this->global_gotoffset_
)
1054 this->global_gotoffset_
= offset
;
1057 // Return whether all GOT relocations for this symbol are for calls.
1059 got_only_for_calls() const
1060 { return this->got_only_for_calls_
; }
1062 // Set that there is a GOT relocation for this symbol that is not for call.
1064 set_got_not_only_for_calls()
1065 { this->got_only_for_calls_
= false; }
1067 // Return whether this is a PIC symbol.
1071 // (st_other & STO_MIPS_FLAGS) == STO_MIPS_PIC
1072 return ((this->nonvis() & (elfcpp::STO_MIPS_FLAGS
>> 2))
1073 == (elfcpp::STO_MIPS_PIC
>> 2));
1076 // Set the flag in st_other field that marks this symbol as PIC.
1080 if (this->is_mips16())
1081 // (st_other & ~(STO_MIPS16 | STO_MIPS_FLAGS)) | STO_MIPS_PIC
1082 this->set_nonvis((this->nonvis()
1083 & ~((elfcpp::STO_MIPS16
>> 2)
1084 | (elfcpp::STO_MIPS_FLAGS
>> 2)))
1085 | (elfcpp::STO_MIPS_PIC
>> 2));
1087 // (other & ~STO_MIPS_FLAGS) | STO_MIPS_PIC
1088 this->set_nonvis((this->nonvis() & ~(elfcpp::STO_MIPS_FLAGS
>> 2))
1089 | (elfcpp::STO_MIPS_PIC
>> 2));
1092 // Set the flag in st_other field that marks this symbol as PLT.
1096 if (this->is_mips16())
1097 // (st_other & (STO_MIPS16 | ~STO_MIPS_FLAGS)) | STO_MIPS_PLT
1098 this->set_nonvis((this->nonvis()
1099 & ((elfcpp::STO_MIPS16
>> 2)
1100 | ~(elfcpp::STO_MIPS_FLAGS
>> 2)))
1101 | (elfcpp::STO_MIPS_PLT
>> 2));
1104 // (st_other & ~STO_MIPS_FLAGS) | STO_MIPS_PLT
1105 this->set_nonvis((this->nonvis() & ~(elfcpp::STO_MIPS_FLAGS
>> 2))
1106 | (elfcpp::STO_MIPS_PLT
>> 2));
1109 // Downcast a base pointer to a Mips_symbol pointer.
1110 static Mips_symbol
<size
>*
1111 as_mips_sym(Symbol
* sym
)
1112 { return static_cast<Mips_symbol
<size
>*>(sym
); }
1114 // Downcast a base pointer to a Mips_symbol pointer.
1115 static const Mips_symbol
<size
>*
1116 as_mips_sym(const Symbol
* sym
)
1117 { return static_cast<const Mips_symbol
<size
>*>(sym
); }
1119 // Return whether the symbol has lazy-binding stub.
1121 has_lazy_stub() const
1122 { return this->has_lazy_stub_
; }
1124 // Set whether the symbol has lazy-binding stub.
1126 set_has_lazy_stub(bool has_lazy_stub
)
1127 { this->has_lazy_stub_
= has_lazy_stub
; }
1129 // Return whether the symbol needs a standard PLT entry.
1131 needs_mips_plt() const
1132 { return this->needs_mips_plt_
; }
1134 // Set whether the symbol needs a standard PLT entry.
1136 set_needs_mips_plt(bool needs_mips_plt
)
1137 { this->needs_mips_plt_
= needs_mips_plt
; }
1139 // Return whether the symbol needs a compressed (MIPS16 or microMIPS) PLT
1142 needs_comp_plt() const
1143 { return this->needs_comp_plt_
; }
1145 // Set whether the symbol needs a compressed (MIPS16 or microMIPS) PLT entry.
1147 set_needs_comp_plt(bool needs_comp_plt
)
1148 { this->needs_comp_plt_
= needs_comp_plt
; }
1150 // Return standard PLT entry offset, or -1 if none.
1152 mips_plt_offset() const
1153 { return this->mips_plt_offset_
; }
1155 // Set standard PLT entry offset.
1157 set_mips_plt_offset(unsigned int mips_plt_offset
)
1158 { this->mips_plt_offset_
= mips_plt_offset
; }
1160 // Return whether the symbol has standard PLT entry.
1162 has_mips_plt_offset() const
1163 { return this->mips_plt_offset_
!= -1U; }
1165 // Return compressed (MIPS16 or microMIPS) PLT entry offset, or -1 if none.
1167 comp_plt_offset() const
1168 { return this->comp_plt_offset_
; }
1170 // Set compressed (MIPS16 or microMIPS) PLT entry offset.
1172 set_comp_plt_offset(unsigned int comp_plt_offset
)
1173 { this->comp_plt_offset_
= comp_plt_offset
; }
1175 // Return whether the symbol has compressed (MIPS16 or microMIPS) PLT entry.
1177 has_comp_plt_offset() const
1178 { return this->comp_plt_offset_
!= -1U; }
1180 // Return MIPS16 fn stub for a symbol.
1181 template<bool big_endian
>
1182 Mips16_stub_section
<size
, big_endian
>*
1183 get_mips16_fn_stub() const
1185 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(mips16_fn_stub_
);
1188 // Set MIPS16 fn stub for a symbol.
1190 set_mips16_fn_stub(Mips16_stub_section_base
* stub
)
1191 { this->mips16_fn_stub_
= stub
; }
1193 // Return whether symbol has MIPS16 fn stub.
1195 has_mips16_fn_stub() const
1196 { return this->mips16_fn_stub_
!= NULL
; }
1198 // Return MIPS16 call stub for a symbol.
1199 template<bool big_endian
>
1200 Mips16_stub_section
<size
, big_endian
>*
1201 get_mips16_call_stub() const
1203 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(
1207 // Set MIPS16 call stub for a symbol.
1209 set_mips16_call_stub(Mips16_stub_section_base
* stub
)
1210 { this->mips16_call_stub_
= stub
; }
1212 // Return whether symbol has MIPS16 call stub.
1214 has_mips16_call_stub() const
1215 { return this->mips16_call_stub_
!= NULL
; }
1217 // Return MIPS16 call_fp stub for a symbol.
1218 template<bool big_endian
>
1219 Mips16_stub_section
<size
, big_endian
>*
1220 get_mips16_call_fp_stub() const
1222 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(
1223 mips16_call_fp_stub_
);
1226 // Set MIPS16 call_fp stub for a symbol.
1228 set_mips16_call_fp_stub(Mips16_stub_section_base
* stub
)
1229 { this->mips16_call_fp_stub_
= stub
; }
1231 // Return whether symbol has MIPS16 call_fp stub.
1233 has_mips16_call_fp_stub() const
1234 { return this->mips16_call_fp_stub_
!= NULL
; }
1237 get_applied_secondary_got_fixup() const
1238 { return applied_secondary_got_fixup_
; }
1241 set_applied_secondary_got_fixup()
1242 { this->applied_secondary_got_fixup_
= true; }
1245 // Whether the symbol needs MIPS16 fn_stub. This is true if this symbol
1246 // appears in any relocs other than a 16 bit call.
1249 // True if this symbol is referenced by branch relocations from
1250 // any non-PIC input file. This is used to determine whether an
1251 // la25 stub is required.
1252 bool has_nonpic_branches_
;
1254 // The offset of the la25 stub for this symbol from the start of the
1255 // la25 stub section.
1256 unsigned int la25_stub_offset_
;
1258 // True if there is a relocation against this symbol that must be
1259 // resolved by the static linker (that is, the relocation cannot
1260 // possibly be made dynamic).
1261 bool has_static_relocs_
;
1263 // Whether we must not create a lazy-binding stub for this symbol.
1264 // This is true if the symbol has relocations related to taking the
1265 // function's address.
1268 // The offset of the lazy-binding stub for this symbol from the start of
1269 // .MIPS.stubs section.
1270 unsigned int lazy_stub_offset_
;
1272 // True if there are any relocations for this symbol where pointer equality
1274 bool pointer_equality_needed_
;
1276 // Global GOT area where this symbol in located, or GGA_NONE if symbol is not
1277 // in the global part of the GOT.
1278 Global_got_area global_got_area_
;
1280 // The global GOT offset for this symbol. For multi-GOT links, this is offset
1281 // from the start of .got section to the first GOT entry for the symbol.
1282 // Note that in multi-GOT links the symbol can have entry in more than one GOT.
1283 unsigned int global_gotoffset_
;
1285 // Whether all GOT relocations for this symbol are for calls.
1286 bool got_only_for_calls_
;
1287 // Whether the symbol has lazy-binding stub.
1288 bool has_lazy_stub_
;
1289 // Whether the symbol needs a standard PLT entry.
1290 bool needs_mips_plt_
;
1291 // Whether the symbol needs a compressed (MIPS16 or microMIPS) PLT entry.
1292 bool needs_comp_plt_
;
1293 // Standard PLT entry offset, or -1 if none.
1294 unsigned int mips_plt_offset_
;
1295 // Compressed (MIPS16 or microMIPS) PLT entry offset, or -1 if none.
1296 unsigned int comp_plt_offset_
;
1297 // MIPS16 fn stub for a symbol.
1298 Mips16_stub_section_base
* mips16_fn_stub_
;
1299 // MIPS16 call stub for a symbol.
1300 Mips16_stub_section_base
* mips16_call_stub_
;
1301 // MIPS16 call_fp stub for a symbol.
1302 Mips16_stub_section_base
* mips16_call_fp_stub_
;
1304 bool applied_secondary_got_fixup_
;
1307 // Mips16_stub_section class.
1309 // The mips16 compiler uses a couple of special sections to handle
1310 // floating point arguments.
1312 // Section names that look like .mips16.fn.FNNAME contain stubs that
1313 // copy floating point arguments from the fp regs to the gp regs and
1314 // then jump to FNNAME. If any 32 bit function calls FNNAME, the
1315 // call should be redirected to the stub instead. If no 32 bit
1316 // function calls FNNAME, the stub should be discarded. We need to
1317 // consider any reference to the function, not just a call, because
1318 // if the address of the function is taken we will need the stub,
1319 // since the address might be passed to a 32 bit function.
1321 // Section names that look like .mips16.call.FNNAME contain stubs
1322 // that copy floating point arguments from the gp regs to the fp
1323 // regs and then jump to FNNAME. If FNNAME is a 32 bit function,
1324 // then any 16 bit function that calls FNNAME should be redirected
1325 // to the stub instead. If FNNAME is not a 32 bit function, the
1326 // stub should be discarded.
1328 // .mips16.call.fp.FNNAME sections are similar, but contain stubs
1329 // which call FNNAME and then copy the return value from the fp regs
1330 // to the gp regs. These stubs store the return address in $18 while
1331 // calling FNNAME; any function which might call one of these stubs
1332 // must arrange to save $18 around the call. (This case is not
1333 // needed for 32 bit functions that call 16 bit functions, because
1334 // 16 bit functions always return floating point values in both
1335 // $f0/$f1 and $2/$3.)
1337 // Note that in all cases FNNAME might be defined statically.
1338 // Therefore, FNNAME is not used literally. Instead, the relocation
1339 // information will indicate which symbol the section is for.
1341 // We record any stubs that we find in the symbol table.
1343 // TODO(sasa): All mips16 stub sections should be emitted in the .text section.
1345 class Mips16_stub_section_base
{ };
1347 template<int size
, bool big_endian
>
1348 class Mips16_stub_section
: public Mips16_stub_section_base
1350 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1353 Mips16_stub_section(Mips_relobj
<size
, big_endian
>* object
, unsigned int shndx
)
1354 : object_(object
), shndx_(shndx
), r_sym_(0), gsym_(NULL
),
1355 found_r_mips_none_(false)
1357 gold_assert(object
->is_mips16_fn_stub_section(shndx
)
1358 || object
->is_mips16_call_stub_section(shndx
)
1359 || object
->is_mips16_call_fp_stub_section(shndx
));
1362 // Return the object of this stub section.
1363 Mips_relobj
<size
, big_endian
>*
1365 { return this->object_
; }
1367 // Return the size of a section.
1369 section_size() const
1370 { return this->object_
->section_size(this->shndx_
); }
1372 // Return section index of this stub section.
1375 { return this->shndx_
; }
1377 // Return symbol index, if stub is for a local function.
1380 { return this->r_sym_
; }
1382 // Return symbol, if stub is for a global function.
1385 { return this->gsym_
; }
1387 // Return whether stub is for a local function.
1389 is_for_local_function() const
1390 { return this->gsym_
== NULL
; }
1392 // This method is called when a new relocation R_TYPE for local symbol R_SYM
1393 // is found in the stub section. Try to find stub target.
1395 new_local_reloc_found(unsigned int r_type
, unsigned int r_sym
)
1397 // To find target symbol for this stub, trust the first R_MIPS_NONE
1398 // relocation, if any. Otherwise trust the first relocation, whatever
1400 if (this->found_r_mips_none_
)
1402 if (r_type
== elfcpp::R_MIPS_NONE
)
1404 this->r_sym_
= r_sym
;
1406 this->found_r_mips_none_
= true;
1408 else if (!is_target_found())
1409 this->r_sym_
= r_sym
;
1412 // This method is called when a new relocation R_TYPE for global symbol GSYM
1413 // is found in the stub section. Try to find stub target.
1415 new_global_reloc_found(unsigned int r_type
, Mips_symbol
<size
>* gsym
)
1417 // To find target symbol for this stub, trust the first R_MIPS_NONE
1418 // relocation, if any. Otherwise trust the first relocation, whatever
1420 if (this->found_r_mips_none_
)
1422 if (r_type
== elfcpp::R_MIPS_NONE
)
1426 this->found_r_mips_none_
= true;
1428 else if (!is_target_found())
1432 // Return whether we found the stub target.
1434 is_target_found() const
1435 { return this->r_sym_
!= 0 || this->gsym_
!= NULL
; }
1437 // Return whether this is a fn stub.
1440 { return this->object_
->is_mips16_fn_stub_section(this->shndx_
); }
1442 // Return whether this is a call stub.
1444 is_call_stub() const
1445 { return this->object_
->is_mips16_call_stub_section(this->shndx_
); }
1447 // Return whether this is a call_fp stub.
1449 is_call_fp_stub() const
1450 { return this->object_
->is_mips16_call_fp_stub_section(this->shndx_
); }
1452 // Return the output address.
1454 output_address() const
1456 return (this->object_
->output_section(this->shndx_
)->address()
1457 + this->object_
->output_section_offset(this->shndx_
));
1461 // The object of this stub section.
1462 Mips_relobj
<size
, big_endian
>* object_
;
1463 // The section index of this stub section.
1464 unsigned int shndx_
;
1465 // The symbol index, if stub is for a local function.
1466 unsigned int r_sym_
;
1467 // The symbol, if stub is for a global function.
1468 Mips_symbol
<size
>* gsym_
;
1469 // True if we found R_MIPS_NONE relocation in this stub.
1470 bool found_r_mips_none_
;
1473 // Mips_relobj class.
1475 template<int size
, bool big_endian
>
1476 class Mips_relobj
: public Sized_relobj_file
<size
, big_endian
>
1478 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1479 typedef std::map
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>
1480 Mips16_stubs_int_map
;
1481 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1484 Mips_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
1485 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1486 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
1487 processor_specific_flags_(0), local_symbol_is_mips16_(),
1488 local_symbol_is_micromips_(), mips16_stub_sections_(),
1489 local_non_16bit_calls_(), local_16bit_calls_(), local_mips16_fn_stubs_(),
1490 local_mips16_call_stubs_(), gp_(0), got_info_(NULL
),
1491 section_is_mips16_fn_stub_(), section_is_mips16_call_stub_(),
1492 section_is_mips16_call_fp_stub_(), pdr_shndx_(-1U), gprmask_(0),
1493 cprmask1_(0), cprmask2_(0), cprmask3_(0), cprmask4_(0)
1495 this->is_pic_
= (ehdr
.get_e_flags() & elfcpp::EF_MIPS_PIC
) != 0;
1496 this->is_n32_
= elfcpp::abi_n32(ehdr
.get_e_flags());
1497 this->is_n64_
= elfcpp::abi_64(ehdr
.get_e_ident()[elfcpp::EI_CLASS
]);
1503 // Downcast a base pointer to a Mips_relobj pointer. This is
1504 // not type-safe but we only use Mips_relobj not the base class.
1505 static Mips_relobj
<size
, big_endian
>*
1506 as_mips_relobj(Relobj
* relobj
)
1507 { return static_cast<Mips_relobj
<size
, big_endian
>*>(relobj
); }
1509 // Downcast a base pointer to a Mips_relobj pointer. This is
1510 // not type-safe but we only use Mips_relobj not the base class.
1511 static const Mips_relobj
<size
, big_endian
>*
1512 as_mips_relobj(const Relobj
* relobj
)
1513 { return static_cast<const Mips_relobj
<size
, big_endian
>*>(relobj
); }
1515 // Processor-specific flags in ELF file header. This is valid only after
1518 processor_specific_flags() const
1519 { return this->processor_specific_flags_
; }
1521 // Whether a local symbol is MIPS16 symbol. R_SYM is the symbol table
1522 // index. This is only valid after do_count_local_symbol is called.
1524 local_symbol_is_mips16(unsigned int r_sym
) const
1526 gold_assert(r_sym
< this->local_symbol_is_mips16_
.size());
1527 return this->local_symbol_is_mips16_
[r_sym
];
1530 // Whether a local symbol is microMIPS symbol. R_SYM is the symbol table
1531 // index. This is only valid after do_count_local_symbol is called.
1533 local_symbol_is_micromips(unsigned int r_sym
) const
1535 gold_assert(r_sym
< this->local_symbol_is_micromips_
.size());
1536 return this->local_symbol_is_micromips_
[r_sym
];
1539 // Get or create MIPS16 stub section.
1540 Mips16_stub_section
<size
, big_endian
>*
1541 get_mips16_stub_section(unsigned int shndx
)
1543 typename
Mips16_stubs_int_map::const_iterator it
=
1544 this->mips16_stub_sections_
.find(shndx
);
1545 if (it
!= this->mips16_stub_sections_
.end())
1546 return (*it
).second
;
1548 Mips16_stub_section
<size
, big_endian
>* stub_section
=
1549 new Mips16_stub_section
<size
, big_endian
>(this, shndx
);
1550 this->mips16_stub_sections_
.insert(
1551 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1552 stub_section
->shndx(), stub_section
));
1553 return stub_section
;
1556 // Return MIPS16 fn stub section for local symbol R_SYM, or NULL if this
1557 // object doesn't have fn stub for R_SYM.
1558 Mips16_stub_section
<size
, big_endian
>*
1559 get_local_mips16_fn_stub(unsigned int r_sym
) const
1561 typename
Mips16_stubs_int_map::const_iterator it
=
1562 this->local_mips16_fn_stubs_
.find(r_sym
);
1563 if (it
!= this->local_mips16_fn_stubs_
.end())
1564 return (*it
).second
;
1568 // Record that this object has MIPS16 fn stub for local symbol. This method
1569 // is only called if we decided not to discard the stub.
1571 add_local_mips16_fn_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1573 gold_assert(stub
->is_for_local_function());
1574 unsigned int r_sym
= stub
->r_sym();
1575 this->local_mips16_fn_stubs_
.insert(
1576 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1580 // Return MIPS16 call stub section for local symbol R_SYM, or NULL if this
1581 // object doesn't have call stub for R_SYM.
1582 Mips16_stub_section
<size
, big_endian
>*
1583 get_local_mips16_call_stub(unsigned int r_sym
) const
1585 typename
Mips16_stubs_int_map::const_iterator it
=
1586 this->local_mips16_call_stubs_
.find(r_sym
);
1587 if (it
!= this->local_mips16_call_stubs_
.end())
1588 return (*it
).second
;
1592 // Record that this object has MIPS16 call stub for local symbol. This method
1593 // is only called if we decided not to discard the stub.
1595 add_local_mips16_call_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1597 gold_assert(stub
->is_for_local_function());
1598 unsigned int r_sym
= stub
->r_sym();
1599 this->local_mips16_call_stubs_
.insert(
1600 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1604 // Record that we found "non 16-bit" call relocation against local symbol
1605 // SYMNDX. This reloc would need to refer to a MIPS16 fn stub, if there
1608 add_local_non_16bit_call(unsigned int symndx
)
1609 { this->local_non_16bit_calls_
.insert(symndx
); }
1611 // Return true if there is any "non 16-bit" call relocation against local
1612 // symbol SYMNDX in this object.
1614 has_local_non_16bit_call_relocs(unsigned int symndx
)
1616 return (this->local_non_16bit_calls_
.find(symndx
)
1617 != this->local_non_16bit_calls_
.end());
1620 // Record that we found 16-bit call relocation R_MIPS16_26 against local
1621 // symbol SYMNDX. Local MIPS16 call or call_fp stubs will only be needed
1622 // if there is some R_MIPS16_26 relocation that refers to the stub symbol.
1624 add_local_16bit_call(unsigned int symndx
)
1625 { this->local_16bit_calls_
.insert(symndx
); }
1627 // Return true if there is any 16-bit call relocation R_MIPS16_26 against local
1628 // symbol SYMNDX in this object.
1630 has_local_16bit_call_relocs(unsigned int symndx
)
1632 return (this->local_16bit_calls_
.find(symndx
)
1633 != this->local_16bit_calls_
.end());
1636 // Get gp value that was used to create this object.
1639 { return this->gp_
; }
1641 // Return whether the object is a PIC object.
1644 { return this->is_pic_
; }
1646 // Return whether the object uses N32 ABI.
1649 { return this->is_n32_
; }
1651 // Return whether the object uses N64 ABI.
1654 { return this->is_n64_
; }
1656 // Return whether the object uses NewABI conventions.
1659 { return this->is_n32_
|| this->is_n64_
; }
1661 // Return Mips_got_info for this object.
1662 Mips_got_info
<size
, big_endian
>*
1663 get_got_info() const
1664 { return this->got_info_
; }
1666 // Return Mips_got_info for this object. Create new info if it doesn't exist.
1667 Mips_got_info
<size
, big_endian
>*
1668 get_or_create_got_info()
1670 if (!this->got_info_
)
1671 this->got_info_
= new Mips_got_info
<size
, big_endian
>();
1672 return this->got_info_
;
1675 // Set Mips_got_info for this object.
1677 set_got_info(Mips_got_info
<size
, big_endian
>* got_info
)
1678 { this->got_info_
= got_info
; }
1680 // Whether a section SHDNX is a MIPS16 stub section. This is only valid
1681 // after do_read_symbols is called.
1683 is_mips16_stub_section(unsigned int shndx
)
1685 return (is_mips16_fn_stub_section(shndx
)
1686 || is_mips16_call_stub_section(shndx
)
1687 || is_mips16_call_fp_stub_section(shndx
));
1690 // Return TRUE if relocations in section SHNDX can refer directly to a
1691 // MIPS16 function rather than to a hard-float stub. This is only valid
1692 // after do_read_symbols is called.
1694 section_allows_mips16_refs(unsigned int shndx
)
1696 return (this->is_mips16_stub_section(shndx
) || shndx
== this->pdr_shndx_
);
1699 // Whether a section SHDNX is a MIPS16 fn stub section. This is only valid
1700 // after do_read_symbols is called.
1702 is_mips16_fn_stub_section(unsigned int shndx
)
1704 gold_assert(shndx
< this->section_is_mips16_fn_stub_
.size());
1705 return this->section_is_mips16_fn_stub_
[shndx
];
1708 // Whether a section SHDNX is a MIPS16 call stub section. This is only valid
1709 // after do_read_symbols is called.
1711 is_mips16_call_stub_section(unsigned int shndx
)
1713 gold_assert(shndx
< this->section_is_mips16_call_stub_
.size());
1714 return this->section_is_mips16_call_stub_
[shndx
];
1717 // Whether a section SHDNX is a MIPS16 call_fp stub section. This is only
1718 // valid after do_read_symbols is called.
1720 is_mips16_call_fp_stub_section(unsigned int shndx
)
1722 gold_assert(shndx
< this->section_is_mips16_call_fp_stub_
.size());
1723 return this->section_is_mips16_call_fp_stub_
[shndx
];
1726 // Discard MIPS16 stub secions that are not needed.
1728 discard_mips16_stub_sections(Symbol_table
* symtab
);
1730 // Return gprmask from the .reginfo section of this object.
1733 { return this->gprmask_
; }
1735 // Return cprmask1 from the .reginfo section of this object.
1738 { return this->cprmask1_
; }
1740 // Return cprmask2 from the .reginfo section of this object.
1743 { return this->cprmask2_
; }
1745 // Return cprmask3 from the .reginfo section of this object.
1748 { return this->cprmask3_
; }
1750 // Return cprmask4 from the .reginfo section of this object.
1753 { return this->cprmask4_
; }
1756 // Count the local symbols.
1758 do_count_local_symbols(Stringpool_template
<char>*,
1759 Stringpool_template
<char>*);
1761 // Read the symbol information.
1763 do_read_symbols(Read_symbols_data
* sd
);
1766 // processor-specific flags in ELF file header.
1767 elfcpp::Elf_Word processor_specific_flags_
;
1769 // Bit vector to tell if a local symbol is a MIPS16 symbol or not.
1770 // This is only valid after do_count_local_symbol is called.
1771 std::vector
<bool> local_symbol_is_mips16_
;
1773 // Bit vector to tell if a local symbol is a microMIPS symbol or not.
1774 // This is only valid after do_count_local_symbol is called.
1775 std::vector
<bool> local_symbol_is_micromips_
;
1777 // Map from section index to the MIPS16 stub for that section. This contains
1778 // all stubs found in this object.
1779 Mips16_stubs_int_map mips16_stub_sections_
;
1781 // Local symbols that have "non 16-bit" call relocation. This relocation
1782 // would need to refer to a MIPS16 fn stub, if there is one.
1783 std::set
<unsigned int> local_non_16bit_calls_
;
1785 // Local symbols that have 16-bit call relocation R_MIPS16_26. Local MIPS16
1786 // call or call_fp stubs will only be needed if there is some R_MIPS16_26
1787 // relocation that refers to the stub symbol.
1788 std::set
<unsigned int> local_16bit_calls_
;
1790 // Map from local symbol index to the MIPS16 fn stub for that symbol.
1791 // This contains only the stubs that we decided not to discard.
1792 Mips16_stubs_int_map local_mips16_fn_stubs_
;
1794 // Map from local symbol index to the MIPS16 call stub for that symbol.
1795 // This contains only the stubs that we decided not to discard.
1796 Mips16_stubs_int_map local_mips16_call_stubs_
;
1798 // gp value that was used to create this object.
1800 // Whether the object is a PIC object.
1802 // Whether the object uses N32 ABI.
1804 // Whether the object uses N64 ABI.
1806 // The Mips_got_info for this object.
1807 Mips_got_info
<size
, big_endian
>* got_info_
;
1809 // Bit vector to tell if a section is a MIPS16 fn stub section or not.
1810 // This is only valid after do_read_symbols is called.
1811 std::vector
<bool> section_is_mips16_fn_stub_
;
1813 // Bit vector to tell if a section is a MIPS16 call stub section or not.
1814 // This is only valid after do_read_symbols is called.
1815 std::vector
<bool> section_is_mips16_call_stub_
;
1817 // Bit vector to tell if a section is a MIPS16 call_fp stub section or not.
1818 // This is only valid after do_read_symbols is called.
1819 std::vector
<bool> section_is_mips16_call_fp_stub_
;
1821 // .pdr section index.
1822 unsigned int pdr_shndx_
;
1824 // gprmask from the .reginfo section of this object.
1826 // cprmask1 from the .reginfo section of this object.
1828 // cprmask2 from the .reginfo section of this object.
1830 // cprmask3 from the .reginfo section of this object.
1832 // cprmask4 from the .reginfo section of this object.
1836 // Mips_output_data_got class.
1838 template<int size
, bool big_endian
>
1839 class Mips_output_data_got
: public Output_data_got
<size
, big_endian
>
1841 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1842 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
1844 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1847 Mips_output_data_got(Target_mips
<size
, big_endian
>* target
,
1848 Symbol_table
* symtab
, Layout
* layout
)
1849 : Output_data_got
<size
, big_endian
>(), target_(target
),
1850 symbol_table_(symtab
), layout_(layout
), static_relocs_(), got_view_(NULL
),
1851 first_global_got_dynsym_index_(-1U), primary_got_(NULL
),
1852 secondary_got_relocs_()
1854 this->master_got_info_
= new Mips_got_info
<size
, big_endian
>();
1855 this->set_addralign(16);
1858 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
1859 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
1861 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
1862 unsigned int symndx
, Mips_address addend
,
1863 unsigned int r_type
, unsigned int shndx
)
1865 this->master_got_info_
->record_local_got_symbol(object
, symndx
, addend
,
1869 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
1870 // in OBJECT. FOR_CALL is true if the caller is only interested in
1871 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
1874 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
1875 Mips_relobj
<size
, big_endian
>* object
,
1876 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
1878 this->master_got_info_
->record_global_got_symbol(mips_sym
, object
, r_type
,
1879 dyn_reloc
, for_call
);
1882 // Record that OBJECT has a page relocation against symbol SYMNDX and
1883 // that ADDEND is the addend for that relocation.
1885 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
1886 unsigned int symndx
, int addend
)
1887 { this->master_got_info_
->record_got_page_entry(object
, symndx
, addend
); }
1889 // Add a static entry for the GOT entry at OFFSET. GSYM is a global
1890 // symbol and R_TYPE is the code of a dynamic relocation that needs to be
1891 // applied in a static link.
1893 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
1894 Mips_symbol
<size
>* gsym
)
1895 { this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, gsym
)); }
1897 // Add a static reloc for the GOT entry at OFFSET. RELOBJ is an object
1898 // defining a local symbol with INDEX. R_TYPE is the code of a dynamic
1899 // relocation that needs to be applied in a static link.
1901 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
1902 Sized_relobj_file
<size
, big_endian
>* relobj
,
1905 this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, relobj
,
1909 // Record that global symbol GSYM has R_TYPE dynamic relocation in the
1910 // secondary GOT at OFFSET.
1912 add_secondary_got_reloc(unsigned int got_offset
, unsigned int r_type
,
1913 Mips_symbol
<size
>* gsym
)
1915 this->secondary_got_relocs_
.push_back(Static_reloc(got_offset
,
1919 // Update GOT entry at OFFSET with VALUE.
1921 update_got_entry(unsigned int offset
, Mips_address value
)
1923 elfcpp::Swap
<size
, big_endian
>::writeval(this->got_view_
+ offset
, value
);
1926 // Return the number of entries in local part of the GOT. This includes
1927 // local entries, page entries and 2 reserved entries.
1929 get_local_gotno() const
1931 if (!this->multi_got())
1933 return (2 + this->master_got_info_
->local_gotno()
1934 + this->master_got_info_
->page_gotno());
1937 return 2 + this->primary_got_
->local_gotno() + this->primary_got_
->page_gotno();
1940 // Return dynamic symbol table index of the first symbol with global GOT
1943 first_global_got_dynsym_index() const
1944 { return this->first_global_got_dynsym_index_
; }
1946 // Set dynamic symbol table index of the first symbol with global GOT entry.
1948 set_first_global_got_dynsym_index(unsigned int index
)
1949 { this->first_global_got_dynsym_index_
= index
; }
1951 // Lay out the GOT. Add local, global and TLS entries. If GOT is
1952 // larger than 64K, create multi-GOT.
1954 lay_out_got(Layout
* layout
, Symbol_table
* symtab
,
1955 const Input_objects
* input_objects
);
1957 // Create multi-GOT. For every GOT, add local, global and TLS entries.
1959 lay_out_multi_got(Layout
* layout
, const Input_objects
* input_objects
);
1961 // Attempt to merge GOTs of different input objects.
1963 merge_gots(const Input_objects
* input_objects
);
1965 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
1966 // this would lead to overflow, true if they were merged successfully.
1968 merge_got_with(Mips_got_info
<size
, big_endian
>* from
,
1969 Mips_relobj
<size
, big_endian
>* object
,
1970 Mips_got_info
<size
, big_endian
>* to
);
1972 // Return the offset of GOT page entry for VALUE. For multi-GOT links,
1973 // use OBJECT's GOT.
1975 get_got_page_offset(Mips_address value
,
1976 const Mips_relobj
<size
, big_endian
>* object
)
1978 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
1979 ? this->master_got_info_
1980 : object
->get_got_info());
1981 gold_assert(g
!= NULL
);
1982 return g
->get_got_page_offset(value
, this);
1985 // Return the GOT offset of type GOT_TYPE of the global symbol
1986 // GSYM. For multi-GOT links, use OBJECT's GOT.
1987 unsigned int got_offset(const Symbol
* gsym
, unsigned int got_type
,
1988 Mips_relobj
<size
, big_endian
>* object
) const
1990 if (!this->multi_got())
1991 return gsym
->got_offset(got_type
);
1994 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
1995 gold_assert(g
!= NULL
);
1996 return gsym
->got_offset(g
->multigot_got_type(got_type
));
2000 // Return the GOT offset of type GOT_TYPE of the local symbol
2003 got_offset(unsigned int symndx
, unsigned int got_type
,
2004 Sized_relobj_file
<size
, big_endian
>* object
) const
2005 { return object
->local_got_offset(symndx
, got_type
); }
2007 // Return the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2009 tls_ldm_offset(Mips_relobj
<size
, big_endian
>* object
) const
2011 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2012 ? this->master_got_info_
2013 : object
->get_got_info());
2014 gold_assert(g
!= NULL
);
2015 return g
->tls_ldm_offset();
2018 // Set the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2020 set_tls_ldm_offset(unsigned int tls_ldm_offset
,
2021 Mips_relobj
<size
, big_endian
>* object
)
2023 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2024 ? this->master_got_info_
2025 : object
->get_got_info());
2026 gold_assert(g
!= NULL
);
2027 g
->set_tls_ldm_offset(tls_ldm_offset
);
2030 // Return true for multi-GOT links.
2033 { return this->primary_got_
!= NULL
; }
2035 // Return the offset of OBJECT's GOT from the start of .got section.
2037 get_got_offset(const Mips_relobj
<size
, big_endian
>* object
)
2039 if (!this->multi_got())
2043 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
2044 return g
!= NULL
? g
->offset() : 0;
2048 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
2050 add_reloc_only_entries()
2051 { this->master_got_info_
->add_reloc_only_entries(this); }
2053 // Return offset of the primary GOT's entry for global symbol.
2055 get_primary_got_offset(const Mips_symbol
<size
>* sym
) const
2057 gold_assert(sym
->global_got_area() != GGA_NONE
);
2058 return (this->get_local_gotno() + sym
->dynsym_index()
2059 - this->first_global_got_dynsym_index()) * size
/8;
2062 // For the entry at offset GOT_OFFSET, return its offset from the gp.
2063 // Input argument GOT_OFFSET is always global offset from the start of
2064 // .got section, for both single and multi-GOT links.
2065 // For single GOT links, this returns GOT_OFFSET - 0x7FF0. For multi-GOT
2066 // links, the return value is object_got_offset - 0x7FF0, where
2067 // object_got_offset is offset in the OBJECT's GOT.
2069 gp_offset(unsigned int got_offset
,
2070 const Mips_relobj
<size
, big_endian
>* object
) const
2072 return (this->address() + got_offset
2073 - this->target_
->adjusted_gp_value(object
));
2077 // Write out the GOT table.
2079 do_write(Output_file
*);
2083 // This class represent dynamic relocations that need to be applied by
2084 // gold because we are using TLS relocations in a static link.
2088 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2089 Mips_symbol
<size
>* gsym
)
2090 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(true)
2091 { this->u_
.global
.symbol
= gsym
; }
2093 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2094 Sized_relobj_file
<size
, big_endian
>* relobj
, unsigned int index
)
2095 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(false)
2097 this->u_
.local
.relobj
= relobj
;
2098 this->u_
.local
.index
= index
;
2101 // Return the GOT offset.
2104 { return this->got_offset_
; }
2109 { return this->r_type_
; }
2111 // Whether the symbol is global or not.
2113 symbol_is_global() const
2114 { return this->symbol_is_global_
; }
2116 // For a relocation against a global symbol, the global symbol.
2120 gold_assert(this->symbol_is_global_
);
2121 return this->u_
.global
.symbol
;
2124 // For a relocation against a local symbol, the defining object.
2125 Sized_relobj_file
<size
, big_endian
>*
2128 gold_assert(!this->symbol_is_global_
);
2129 return this->u_
.local
.relobj
;
2132 // For a relocation against a local symbol, the local symbol index.
2136 gold_assert(!this->symbol_is_global_
);
2137 return this->u_
.local
.index
;
2141 // GOT offset of the entry to which this relocation is applied.
2142 unsigned int got_offset_
;
2143 // Type of relocation.
2144 unsigned int r_type_
;
2145 // Whether this relocation is against a global symbol.
2146 bool symbol_is_global_
;
2147 // A global or local symbol.
2152 // For a global symbol, the symbol itself.
2153 Mips_symbol
<size
>* symbol
;
2157 // For a local symbol, the object defining object.
2158 Sized_relobj_file
<size
, big_endian
>* relobj
;
2159 // For a local symbol, the symbol index.
2166 Target_mips
<size
, big_endian
>* target_
;
2167 // The symbol table.
2168 Symbol_table
* symbol_table_
;
2171 // Static relocs to be applied to the GOT.
2172 std::vector
<Static_reloc
> static_relocs_
;
2173 // .got section view.
2174 unsigned char* got_view_
;
2175 // The dynamic symbol table index of the first symbol with global GOT entry.
2176 unsigned int first_global_got_dynsym_index_
;
2177 // The master GOT information.
2178 Mips_got_info
<size
, big_endian
>* master_got_info_
;
2179 // The primary GOT information.
2180 Mips_got_info
<size
, big_endian
>* primary_got_
;
2181 // Secondary GOT fixups.
2182 std::vector
<Static_reloc
> secondary_got_relocs_
;
2185 // A class to handle LA25 stubs - non-PIC interface to a PIC function. There are
2186 // two ways of creating these interfaces. The first is to add:
2188 // lui $25,%hi(func)
2190 // addiu $25,$25,%lo(func)
2192 // to a separate trampoline section. The second is to add:
2194 // lui $25,%hi(func)
2195 // addiu $25,$25,%lo(func)
2197 // immediately before a PIC function "func", but only if a function is at the
2198 // beginning of the section, and the section is not too heavily aligned (i.e we
2199 // would need to add no more than 2 nops before the stub.)
2201 // We only create stubs of the first type.
2203 template<int size
, bool big_endian
>
2204 class Mips_output_data_la25_stub
: public Output_section_data
2206 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2209 Mips_output_data_la25_stub()
2210 : Output_section_data(size
== 32 ? 4 : 8), symbols_()
2213 // Create LA25 stub for a symbol.
2215 create_la25_stub(Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
2216 Mips_symbol
<size
>* gsym
);
2218 // Return output address of a stub.
2220 stub_address(const Mips_symbol
<size
>* sym
) const
2222 gold_assert(sym
->has_la25_stub());
2223 return this->address() + sym
->la25_stub_offset();
2228 do_adjust_output_section(Output_section
* os
)
2229 { os
->set_entsize(0); }
2232 // Template for standard LA25 stub.
2233 static const uint32_t la25_stub_entry
[];
2234 // Template for microMIPS LA25 stub.
2235 static const uint32_t la25_stub_micromips_entry
[];
2237 // Set the final size.
2239 set_final_data_size()
2240 { this->set_data_size(this->symbols_
.size() * 16); }
2242 // Create a symbol for SYM stub's value and size, to help make the
2243 // disassembly easier to read.
2245 create_stub_symbol(Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
2246 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
);
2248 // Write out the LA25 stub section.
2250 do_write(Output_file
*);
2252 // Symbols that have LA25 stubs.
2253 Unordered_set
<Mips_symbol
<size
>*> symbols_
;
2256 // A class to handle the PLT data.
2258 template<int size
, bool big_endian
>
2259 class Mips_output_data_plt
: public Output_section_data
2261 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2262 typedef Output_data_reloc
<elfcpp::SHT_REL
, true,
2263 size
, big_endian
> Reloc_section
;
2266 // Create the PLT section. The ordinary .got section is an argument,
2267 // since we need to refer to the start.
2268 Mips_output_data_plt(Layout
* layout
, Output_data_space
* got_plt
,
2269 Target_mips
<size
, big_endian
>* target
)
2270 : Output_section_data(size
== 32 ? 4 : 8), got_plt_(got_plt
), symbols_(),
2271 plt_mips_offset_(0), plt_comp_offset_(0), plt_header_size_(0),
2274 this->rel_
= new Reloc_section(false);
2275 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
2276 elfcpp::SHF_ALLOC
, this->rel_
,
2277 ORDER_DYNAMIC_PLT_RELOCS
, false);
2280 // Add an entry to the PLT for a symbol referenced by r_type relocation.
2282 add_entry(Mips_symbol
<size
>* gsym
, unsigned int r_type
);
2284 // Return the .rel.plt section data.
2285 const Reloc_section
*
2287 { return this->rel_
; }
2289 // Return the number of PLT entries.
2292 { return this->symbols_
.size(); }
2294 // Return the offset of the first non-reserved PLT entry.
2296 first_plt_entry_offset() const
2297 { return sizeof(plt0_entry_o32
); }
2299 // Return the size of a PLT entry.
2301 plt_entry_size() const
2302 { return sizeof(plt_entry
); }
2304 // Set final PLT offsets. For each symbol, determine whether standard or
2305 // compressed (MIPS16 or microMIPS) PLT entry is used.
2309 // Return the offset of the first standard PLT entry.
2311 first_mips_plt_offset() const
2312 { return this->plt_header_size_
; }
2314 // Return the offset of the first compressed PLT entry.
2316 first_comp_plt_offset() const
2317 { return this->plt_header_size_
+ this->plt_mips_offset_
; }
2319 // Return whether there are any standard PLT entries.
2321 has_standard_entries() const
2322 { return this->plt_mips_offset_
> 0; }
2324 // Return the output address of standard PLT entry.
2326 mips_entry_address(const Mips_symbol
<size
>* sym
) const
2328 gold_assert (sym
->has_mips_plt_offset());
2329 return (this->address() + this->first_mips_plt_offset()
2330 + sym
->mips_plt_offset());
2333 // Return the output address of compressed (MIPS16 or microMIPS) PLT entry.
2335 comp_entry_address(const Mips_symbol
<size
>* sym
) const
2337 gold_assert (sym
->has_comp_plt_offset());
2338 return (this->address() + this->first_comp_plt_offset()
2339 + sym
->comp_plt_offset());
2344 do_adjust_output_section(Output_section
* os
)
2345 { os
->set_entsize(0); }
2347 // Write to a map file.
2349 do_print_to_mapfile(Mapfile
* mapfile
) const
2350 { mapfile
->print_output_data(this, _(".plt")); }
2353 // Template for the first PLT entry.
2354 static const uint32_t plt0_entry_o32
[];
2355 static const uint32_t plt0_entry_n32
[];
2356 static const uint32_t plt0_entry_n64
[];
2357 static const uint32_t plt0_entry_micromips_o32
[];
2358 static const uint32_t plt0_entry_micromips32_o32
[];
2360 // Template for subsequent PLT entries.
2361 static const uint32_t plt_entry
[];
2362 static const uint32_t plt_entry_mips16_o32
[];
2363 static const uint32_t plt_entry_micromips_o32
[];
2364 static const uint32_t plt_entry_micromips32_o32
[];
2366 // Set the final size.
2368 set_final_data_size()
2370 this->set_data_size(this->plt_header_size_
+ this->plt_mips_offset_
2371 + this->plt_comp_offset_
);
2374 // Write out the PLT data.
2376 do_write(Output_file
*);
2378 // Return whether the plt header contains microMIPS code. For the sake of
2379 // cache alignment always use a standard header whenever any standard entries
2380 // are present even if microMIPS entries are present as well. This also lets
2381 // the microMIPS header rely on the value of $v0 only set by microMIPS
2382 // entries, for a small size reduction.
2384 is_plt_header_compressed() const
2386 gold_assert(this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0);
2387 return this->target_
->is_output_micromips() && this->plt_mips_offset_
== 0;
2390 // Return the size of the PLT header.
2392 get_plt_header_size() const
2394 if (this->target_
->is_output_n64())
2395 return 4 * sizeof(plt0_entry_n64
) / sizeof(plt0_entry_n64
[0]);
2396 else if (this->target_
->is_output_n32())
2397 return 4 * sizeof(plt0_entry_n32
) / sizeof(plt0_entry_n32
[0]);
2398 else if (!this->is_plt_header_compressed())
2399 return 4 * sizeof(plt0_entry_o32
) / sizeof(plt0_entry_o32
[0]);
2400 else if (this->target_
->use_32bit_micromips_instructions())
2401 return (2 * sizeof(plt0_entry_micromips32_o32
)
2402 / sizeof(plt0_entry_micromips32_o32
[0]));
2404 return (2 * sizeof(plt0_entry_micromips_o32
)
2405 / sizeof(plt0_entry_micromips_o32
[0]));
2408 // Return the PLT header entry.
2410 get_plt_header_entry() const
2412 if (this->target_
->is_output_n64())
2413 return plt0_entry_n64
;
2414 else if (this->target_
->is_output_n32())
2415 return plt0_entry_n32
;
2416 else if (!this->is_plt_header_compressed())
2417 return plt0_entry_o32
;
2418 else if (this->target_
->use_32bit_micromips_instructions())
2419 return plt0_entry_micromips32_o32
;
2421 return plt0_entry_micromips_o32
;
2424 // Return the size of the standard PLT entry.
2426 standard_plt_entry_size() const
2427 { return 4 * sizeof(plt_entry
) / sizeof(plt_entry
[0]); }
2429 // Return the size of the compressed PLT entry.
2431 compressed_plt_entry_size() const
2433 gold_assert(!this->target_
->is_output_newabi());
2435 if (!this->target_
->is_output_micromips())
2436 return (2 * sizeof(plt_entry_mips16_o32
)
2437 / sizeof(plt_entry_mips16_o32
[0]));
2438 else if (this->target_
->use_32bit_micromips_instructions())
2439 return (2 * sizeof(plt_entry_micromips32_o32
)
2440 / sizeof(plt_entry_micromips32_o32
[0]));
2442 return (2 * sizeof(plt_entry_micromips_o32
)
2443 / sizeof(plt_entry_micromips_o32
[0]));
2446 // The reloc section.
2447 Reloc_section
* rel_
;
2448 // The .got.plt section.
2449 Output_data_space
* got_plt_
;
2450 // Symbols that have PLT entry.
2451 std::vector
<Mips_symbol
<size
>*> symbols_
;
2452 // The offset of the next standard PLT entry to create.
2453 unsigned int plt_mips_offset_
;
2454 // The offset of the next compressed PLT entry to create.
2455 unsigned int plt_comp_offset_
;
2456 // The size of the PLT header in bytes.
2457 unsigned int plt_header_size_
;
2459 Target_mips
<size
, big_endian
>* target_
;
2462 // A class to handle the .MIPS.stubs data.
2464 template<int size
, bool big_endian
>
2465 class Mips_output_data_mips_stubs
: public Output_section_data
2467 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2470 Mips_output_data_mips_stubs(Target_mips
<size
, big_endian
>* target
)
2471 : Output_section_data(size
== 32 ? 4 : 8), symbols_(), dynsym_count_(-1U),
2472 stub_offsets_are_set_(false), target_(target
)
2475 // Create entry for a symbol.
2477 make_entry(Mips_symbol
<size
>*);
2479 // Remove entry for a symbol.
2481 remove_entry(Mips_symbol
<size
>* gsym
);
2483 // Set stub offsets for symbols. This method expects that the number of
2484 // entries in dynamic symbol table is set.
2486 set_lazy_stub_offsets();
2489 set_needs_dynsym_value();
2491 // Set the number of entries in dynamic symbol table.
2493 set_dynsym_count(unsigned int dynsym_count
)
2494 { this->dynsym_count_
= dynsym_count
; }
2496 // Return maximum size of the stub, ie. the stub size if the dynamic symbol
2497 // count is greater than 0x10000. If the dynamic symbol count is less than
2498 // 0x10000, the stub will be 4 bytes smaller.
2499 // There's no disadvantage from using microMIPS code here, so for the sake of
2500 // pure-microMIPS binaries we prefer it whenever there's any microMIPS code in
2501 // output produced at all. This has a benefit of stubs being shorter by
2502 // 4 bytes each too, unless in the insn32 mode.
2504 stub_max_size() const
2506 if (!this->target_
->is_output_micromips()
2507 || this->target_
->use_32bit_micromips_instructions())
2513 // Return the size of the stub. This method expects that the final dynsym
2518 gold_assert(this->dynsym_count_
!= -1U);
2519 if (this->dynsym_count_
> 0x10000)
2520 return this->stub_max_size();
2522 return this->stub_max_size() - 4;
2525 // Return output address of a stub.
2527 stub_address(const Mips_symbol
<size
>* sym
) const
2529 gold_assert(sym
->has_lazy_stub());
2530 return this->address() + sym
->lazy_stub_offset();
2535 do_adjust_output_section(Output_section
* os
)
2536 { os
->set_entsize(0); }
2538 // Write to a map file.
2540 do_print_to_mapfile(Mapfile
* mapfile
) const
2541 { mapfile
->print_output_data(this, _(".MIPS.stubs")); }
2544 static const uint32_t lazy_stub_normal_1
[];
2545 static const uint32_t lazy_stub_normal_1_n64
[];
2546 static const uint32_t lazy_stub_normal_2
[];
2547 static const uint32_t lazy_stub_normal_2_n64
[];
2548 static const uint32_t lazy_stub_big
[];
2549 static const uint32_t lazy_stub_big_n64
[];
2551 static const uint32_t lazy_stub_micromips_normal_1
[];
2552 static const uint32_t lazy_stub_micromips_normal_1_n64
[];
2553 static const uint32_t lazy_stub_micromips_normal_2
[];
2554 static const uint32_t lazy_stub_micromips_normal_2_n64
[];
2555 static const uint32_t lazy_stub_micromips_big
[];
2556 static const uint32_t lazy_stub_micromips_big_n64
[];
2558 static const uint32_t lazy_stub_micromips32_normal_1
[];
2559 static const uint32_t lazy_stub_micromips32_normal_1_n64
[];
2560 static const uint32_t lazy_stub_micromips32_normal_2
[];
2561 static const uint32_t lazy_stub_micromips32_normal_2_n64
[];
2562 static const uint32_t lazy_stub_micromips32_big
[];
2563 static const uint32_t lazy_stub_micromips32_big_n64
[];
2565 // Set the final size.
2567 set_final_data_size()
2568 { this->set_data_size(this->symbols_
.size() * this->stub_max_size()); }
2570 // Write out the .MIPS.stubs data.
2572 do_write(Output_file
*);
2574 // .MIPS.stubs symbols
2575 Unordered_set
<Mips_symbol
<size
>*> symbols_
;
2576 // Number of entries in dynamic symbol table.
2577 unsigned int dynsym_count_
;
2578 // Whether the stub offsets are set.
2579 bool stub_offsets_are_set_
;
2581 Target_mips
<size
, big_endian
>* target_
;
2584 // This class handles Mips .reginfo output section.
2586 template<int size
, bool big_endian
>
2587 class Mips_output_section_reginfo
: public Output_section
2589 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
2592 Mips_output_section_reginfo(const char* name
, elfcpp::Elf_Word type
,
2593 elfcpp::Elf_Xword flags
,
2594 Target_mips
<size
, big_endian
>* target
)
2595 : Output_section(name
, type
, flags
), target_(target
), gprmask_(0),
2596 cprmask1_(0), cprmask2_(0), cprmask3_(0), cprmask4_(0)
2599 // Downcast a base pointer to a Mips_output_section_reginfo pointer.
2600 static Mips_output_section_reginfo
<size
, big_endian
>*
2601 as_mips_output_section_reginfo(Output_section
* os
)
2602 { return static_cast<Mips_output_section_reginfo
<size
, big_endian
>*>(os
); }
2604 // Set masks of the output .reginfo section.
2606 set_masks(Valtype gprmask
, Valtype cprmask1
, Valtype cprmask2
,
2607 Valtype cprmask3
, Valtype cprmask4
)
2609 this->gprmask_
= gprmask
;
2610 this->cprmask1_
= cprmask1
;
2611 this->cprmask2_
= cprmask2
;
2612 this->cprmask3_
= cprmask3
;
2613 this->cprmask4_
= cprmask4
;
2617 // Set the final data size.
2619 set_final_data_size()
2620 { this->set_data_size(24); }
2622 // Write out reginfo section.
2624 do_write(Output_file
* of
);
2627 Target_mips
<size
, big_endian
>* target_
;
2629 // gprmask of the output .reginfo section.
2631 // cprmask1 of the output .reginfo section.
2633 // cprmask2 of the output .reginfo section.
2635 // cprmask3 of the output .reginfo section.
2637 // cprmask4 of the output .reginfo section.
2641 // The MIPS target has relocation types which default handling of relocatable
2642 // relocation cannot process. So we have to extend the default code.
2644 template<bool big_endian
, int sh_type
, typename Classify_reloc
>
2645 class Mips_scan_relocatable_relocs
:
2646 public Default_scan_relocatable_relocs
<sh_type
, Classify_reloc
>
2649 // Return the strategy to use for a local symbol which is a section
2650 // symbol, given the relocation type.
2651 inline Relocatable_relocs::Reloc_strategy
2652 local_section_strategy(unsigned int r_type
, Relobj
* object
)
2654 if (sh_type
== elfcpp::SHT_RELA
)
2655 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
2660 case elfcpp::R_MIPS_26
:
2661 return Relocatable_relocs::RELOC_SPECIAL
;
2664 return Default_scan_relocatable_relocs
<sh_type
, Classify_reloc
>::
2665 local_section_strategy(r_type
, object
);
2671 // Mips_copy_relocs class. The only difference from the base class is the
2672 // method emit_mips, which should be called instead of Copy_reloc_entry::emit.
2673 // Mips cannot convert all relocation types to dynamic relocs. If a reloc
2674 // cannot be made dynamic, a COPY reloc is emitted.
2676 template<int sh_type
, int size
, bool big_endian
>
2677 class Mips_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
2681 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_MIPS_COPY
)
2684 // Emit any saved relocations which turn out to be needed. This is
2685 // called after all the relocs have been scanned.
2687 emit_mips(Output_data_reloc
<sh_type
, true, size
, big_endian
>*,
2688 Symbol_table
*, Layout
*, Target_mips
<size
, big_endian
>*);
2691 typedef typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
2694 // Emit this reloc if appropriate. This is called after we have
2695 // scanned all the relocations, so we know whether we emitted a
2696 // COPY relocation for SYM_.
2698 emit_entry(Copy_reloc_entry
& entry
,
2699 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
2700 Symbol_table
* symtab
, Layout
* layout
,
2701 Target_mips
<size
, big_endian
>* target
);
2705 // Return true if the symbol SYM should be considered to resolve local
2706 // to the current module, and false otherwise. The logic is taken from
2707 // GNU ld's method _bfd_elf_symbol_refs_local_p.
2709 symbol_refs_local(const Symbol
* sym
, bool has_dynsym_entry
,
2710 bool local_protected
)
2712 // If it's a local sym, of course we resolve locally.
2716 // STV_HIDDEN or STV_INTERNAL ones must be local.
2717 if (sym
->visibility() == elfcpp::STV_HIDDEN
2718 || sym
->visibility() == elfcpp::STV_INTERNAL
)
2721 // If we don't have a definition in a regular file, then we can't
2722 // resolve locally. The sym is either undefined or dynamic.
2723 if (sym
->source() != Symbol::FROM_OBJECT
|| sym
->object()->is_dynamic()
2724 || sym
->is_undefined())
2727 // Forced local symbols resolve locally.
2728 if (sym
->is_forced_local())
2731 // As do non-dynamic symbols.
2732 if (!has_dynsym_entry
)
2735 // At this point, we know the symbol is defined and dynamic. In an
2736 // executable it must resolve locally, likewise when building symbolic
2737 // shared libraries.
2738 if (parameters
->options().output_is_executable()
2739 || parameters
->options().Bsymbolic())
2742 // Now deal with defined dynamic symbols in shared libraries. Ones
2743 // with default visibility might not resolve locally.
2744 if (sym
->visibility() == elfcpp::STV_DEFAULT
)
2747 // STV_PROTECTED non-function symbols are local.
2748 if (sym
->type() != elfcpp::STT_FUNC
)
2751 // Function pointer equality tests may require that STV_PROTECTED
2752 // symbols be treated as dynamic symbols. If the address of a
2753 // function not defined in an executable is set to that function's
2754 // plt entry in the executable, then the address of the function in
2755 // a shared library must also be the plt entry in the executable.
2756 return local_protected
;
2759 // Return TRUE if references to this symbol always reference the symbol in this
2762 symbol_references_local(const Symbol
* sym
, bool has_dynsym_entry
)
2764 return symbol_refs_local(sym
, has_dynsym_entry
, false);
2767 // Return TRUE if calls to this symbol always call the version in this object.
2769 symbol_calls_local(const Symbol
* sym
, bool has_dynsym_entry
)
2771 return symbol_refs_local(sym
, has_dynsym_entry
, true);
2774 // Compare GOT offsets of two symbols.
2776 template<int size
, bool big_endian
>
2778 got_offset_compare(Symbol
* sym1
, Symbol
* sym2
)
2780 Mips_symbol
<size
>* mips_sym1
= Mips_symbol
<size
>::as_mips_sym(sym1
);
2781 Mips_symbol
<size
>* mips_sym2
= Mips_symbol
<size
>::as_mips_sym(sym2
);
2782 unsigned int area1
= mips_sym1
->global_got_area();
2783 unsigned int area2
= mips_sym2
->global_got_area();
2784 gold_assert(area1
!= GGA_NONE
&& area1
!= GGA_NONE
);
2786 // GGA_NORMAL entries always come before GGA_RELOC_ONLY.
2788 return area1
< area2
;
2790 return mips_sym1
->global_gotoffset() < mips_sym2
->global_gotoffset();
2793 // This method divides dynamic symbols into symbols that have GOT entry, and
2794 // symbols that don't have GOT entry. It also sorts symbols with the GOT entry.
2795 // Mips ABI requires that symbols with the GOT entry must be at the end of
2796 // dynamic symbol table, and the order in dynamic symbol table must match the
2799 template<int size
, bool big_endian
>
2801 reorder_dyn_symbols(std::vector
<Symbol
*>* dyn_symbols
,
2802 std::vector
<Symbol
*>* non_got_symbols
,
2803 std::vector
<Symbol
*>* got_symbols
)
2805 for (std::vector
<Symbol
*>::iterator p
= dyn_symbols
->begin();
2806 p
!= dyn_symbols
->end();
2809 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(*p
);
2810 if (mips_sym
->global_got_area() == GGA_NORMAL
2811 || mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
2812 got_symbols
->push_back(mips_sym
);
2814 non_got_symbols
->push_back(mips_sym
);
2817 std::sort(got_symbols
->begin(), got_symbols
->end(),
2818 got_offset_compare
<size
, big_endian
>);
2821 // Functor class for processing the global symbol table.
2823 template<int size
, bool big_endian
>
2824 class Symbol_visitor_check_symbols
2827 Symbol_visitor_check_symbols(Target_mips
<size
, big_endian
>* target
,
2828 Layout
* layout
, Symbol_table
* symtab
)
2829 : target_(target
), layout_(layout
), symtab_(symtab
)
2833 operator()(Sized_symbol
<size
>* sym
)
2835 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
2836 if (local_pic_function
<size
, big_endian
>(mips_sym
))
2838 // SYM is a function that might need $25 to be valid on entry.
2839 // If we're creating a non-PIC relocatable object, mark SYM as
2840 // being PIC. If we're creating a non-relocatable object with
2841 // non-PIC branches and jumps to SYM, make sure that SYM has an la25
2843 if (parameters
->options().relocatable())
2845 if (!parameters
->options().output_is_position_independent())
2846 mips_sym
->set_pic();
2848 else if (mips_sym
->has_nonpic_branches())
2850 this->target_
->la25_stub_section(layout_
)
2851 ->create_la25_stub(this->symtab_
, this->target_
, mips_sym
);
2857 Target_mips
<size
, big_endian
>* target_
;
2859 Symbol_table
* symtab_
;
2862 template<int size
, bool big_endian
>
2863 class Target_mips
: public Sized_target
<size
, big_endian
>
2865 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2866 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
2868 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
>
2870 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
2871 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
2874 Target_mips(const Target::Target_info
* info
= &mips_info
)
2875 : Sized_target
<size
, big_endian
>(info
), got_(NULL
), gp_(NULL
), plt_(NULL
),
2876 got_plt_(NULL
), rel_dyn_(NULL
), copy_relocs_(),
2877 dyn_relocs_(), la25_stub_(NULL
), mips_mach_extensions_(),
2878 mips_stubs_(NULL
), ei_class_(0), mach_(0), layout_(NULL
),
2879 got16_addends_(), entry_symbol_is_compressed_(false), insn32_(false)
2881 this->add_machine_extensions();
2884 // The offset of $gp from the beginning of the .got section.
2885 static const unsigned int MIPS_GP_OFFSET
= 0x7ff0;
2887 // The maximum size of the GOT for it to be addressable using 16-bit
2888 // offsets from $gp.
2889 static const unsigned int MIPS_GOT_MAX_SIZE
= MIPS_GP_OFFSET
+ 0x7fff;
2891 // Make a new symbol table entry for the Mips target.
2894 { return new Mips_symbol
<size
>(); }
2896 // Process the relocations to determine unreferenced sections for
2897 // garbage collection.
2899 gc_process_relocs(Symbol_table
* symtab
,
2901 Sized_relobj_file
<size
, big_endian
>* object
,
2902 unsigned int data_shndx
,
2903 unsigned int sh_type
,
2904 const unsigned char* prelocs
,
2906 Output_section
* output_section
,
2907 bool needs_special_offset_handling
,
2908 size_t local_symbol_count
,
2909 const unsigned char* plocal_symbols
);
2911 // Scan the relocations to look for symbol adjustments.
2913 scan_relocs(Symbol_table
* symtab
,
2915 Sized_relobj_file
<size
, big_endian
>* object
,
2916 unsigned int data_shndx
,
2917 unsigned int sh_type
,
2918 const unsigned char* prelocs
,
2920 Output_section
* output_section
,
2921 bool needs_special_offset_handling
,
2922 size_t local_symbol_count
,
2923 const unsigned char* plocal_symbols
);
2925 // Finalize the sections.
2927 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
2929 // Relocate a section.
2931 relocate_section(const Relocate_info
<size
, big_endian
>*,
2932 unsigned int sh_type
,
2933 const unsigned char* prelocs
,
2935 Output_section
* output_section
,
2936 bool needs_special_offset_handling
,
2937 unsigned char* view
,
2938 Mips_address view_address
,
2939 section_size_type view_size
,
2940 const Reloc_symbol_changes
*);
2942 // Scan the relocs during a relocatable link.
2944 scan_relocatable_relocs(Symbol_table
* symtab
,
2946 Sized_relobj_file
<size
, big_endian
>* object
,
2947 unsigned int data_shndx
,
2948 unsigned int sh_type
,
2949 const unsigned char* prelocs
,
2951 Output_section
* output_section
,
2952 bool needs_special_offset_handling
,
2953 size_t local_symbol_count
,
2954 const unsigned char* plocal_symbols
,
2955 Relocatable_relocs
*);
2957 // Emit relocations for a section.
2959 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
2960 unsigned int sh_type
,
2961 const unsigned char* prelocs
,
2963 Output_section
* output_section
,
2964 typename
elfcpp::Elf_types
<size
>::Elf_Off
2965 offset_in_output_section
,
2966 const Relocatable_relocs
*,
2967 unsigned char* view
,
2968 Mips_address view_address
,
2969 section_size_type view_size
,
2970 unsigned char* reloc_view
,
2971 section_size_type reloc_view_size
);
2973 // Perform target-specific processing in a relocatable link. This is
2974 // only used if we use the relocation strategy RELOC_SPECIAL.
2976 relocate_special_relocatable(const Relocate_info
<size
, big_endian
>* relinfo
,
2977 unsigned int sh_type
,
2978 const unsigned char* preloc_in
,
2980 Output_section
* output_section
,
2981 typename
elfcpp::Elf_types
<size
>::Elf_Off
2982 offset_in_output_section
,
2983 unsigned char* view
,
2984 Mips_address view_address
,
2985 section_size_type view_size
,
2986 unsigned char* preloc_out
);
2988 // Return whether SYM is defined by the ABI.
2990 do_is_defined_by_abi(const Symbol
* sym
) const
2992 return ((strcmp(sym
->name(), "__gnu_local_gp") == 0)
2993 || (strcmp(sym
->name(), "_gp_disp") == 0)
2994 || (strcmp(sym
->name(), "___tls_get_addr") == 0));
2997 // Return the number of entries in the GOT.
2999 got_entry_count() const
3001 if (!this->has_got_section())
3003 return this->got_size() / (size
/8);
3006 // Return the number of entries in the PLT.
3008 plt_entry_count() const
3010 if (this->plt_
== NULL
)
3012 return this->plt_
->entry_count();
3015 // Return the offset of the first non-reserved PLT entry.
3017 first_plt_entry_offset() const
3018 { return this->plt_
->first_plt_entry_offset(); }
3020 // Return the size of each PLT entry.
3022 plt_entry_size() const
3023 { return this->plt_
->plt_entry_size(); }
3025 // Get the GOT section, creating it if necessary.
3026 Mips_output_data_got
<size
, big_endian
>*
3027 got_section(Symbol_table
*, Layout
*);
3029 // Get the GOT section.
3030 Mips_output_data_got
<size
, big_endian
>*
3033 gold_assert(this->got_
!= NULL
);
3037 // Get the .MIPS.stubs section, creating it if necessary.
3038 Mips_output_data_mips_stubs
<size
, big_endian
>*
3039 mips_stubs_section(Layout
* layout
);
3041 // Get the .MIPS.stubs section.
3042 Mips_output_data_mips_stubs
<size
, big_endian
>*
3043 mips_stubs_section() const
3045 gold_assert(this->mips_stubs_
!= NULL
);
3046 return this->mips_stubs_
;
3049 // Get the LA25 stub section, creating it if necessary.
3050 Mips_output_data_la25_stub
<size
, big_endian
>*
3051 la25_stub_section(Layout
*);
3053 // Get the LA25 stub section.
3054 Mips_output_data_la25_stub
<size
, big_endian
>*
3057 gold_assert(this->la25_stub_
!= NULL
);
3058 return this->la25_stub_
;
3061 // Get gp value. It has the value of .got + 0x7FF0.
3065 if (this->gp_
!= NULL
)
3066 return this->gp_
->value();
3070 // Get gp value. It has the value of .got + 0x7FF0. Adjust it for
3071 // multi-GOT links so that OBJECT's GOT + 0x7FF0 is returned.
3073 adjusted_gp_value(const Mips_relobj
<size
, big_endian
>* object
)
3075 if (this->gp_
== NULL
)
3078 bool multi_got
= false;
3079 if (this->has_got_section())
3080 multi_got
= this->got_section()->multi_got();
3082 return this->gp_
->value();
3084 return this->gp_
->value() + this->got_section()->get_got_offset(object
);
3087 // Get the dynamic reloc section, creating it if necessary.
3089 rel_dyn_section(Layout
*);
3092 do_has_custom_set_dynsym_indexes() const
3095 // Don't emit input .reginfo sections to output .reginfo.
3097 do_should_include_section(elfcpp::Elf_Word sh_type
) const
3098 { return sh_type
!= elfcpp::SHT_MIPS_REGINFO
; }
3100 // Set the dynamic symbol indexes. INDEX is the index of the first
3101 // global dynamic symbol. Pointers to the symbols are stored into the
3102 // vector SYMS. The names are added to DYNPOOL. This returns an
3103 // updated dynamic symbol index.
3105 do_set_dynsym_indexes(std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
3106 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
3107 Versions
* versions
, Symbol_table
* symtab
) const;
3109 // Remove .MIPS.stubs entry for a symbol.
3111 remove_lazy_stub_entry(Mips_symbol
<size
>* sym
)
3113 if (this->mips_stubs_
!= NULL
)
3114 this->mips_stubs_
->remove_entry(sym
);
3117 // The value to write into got[1] for SVR4 targets, to identify it is
3118 // a GNU object. The dynamic linker can then use got[1] to store the
3121 mips_elf_gnu_got1_mask()
3123 if (this->is_output_n64())
3124 return (uint64_t)1 << 63;
3129 // Whether the output has microMIPS code. This is valid only after
3130 // merge_processor_specific_flags() is called.
3132 is_output_micromips() const
3134 gold_assert(this->are_processor_specific_flags_set());
3135 return elfcpp::is_micromips(this->processor_specific_flags());
3138 // Whether the output uses N32 ABI. This is valid only after
3139 // merge_processor_specific_flags() is called.
3141 is_output_n32() const
3143 gold_assert(this->are_processor_specific_flags_set());
3144 return elfcpp::abi_n32(this->processor_specific_flags());
3147 // Whether the output uses N64 ABI. This is valid only after
3148 // merge_processor_specific_flags() is called.
3150 is_output_n64() const
3152 gold_assert(this->are_processor_specific_flags_set());
3153 return elfcpp::abi_64(this->ei_class_
);
3156 // Whether the output uses NEWABI. This is valid only after
3157 // merge_processor_specific_flags() is called.
3159 is_output_newabi() const
3160 { return this->is_output_n32() || this->is_output_n64(); }
3162 // Whether we can only use 32-bit microMIPS instructions.
3164 use_32bit_micromips_instructions() const
3165 { return this->insn32_
; }
3168 // Return the value to use for a dynamic symbol which requires special
3169 // treatment. This is how we support equality comparisons of function
3170 // pointers across shared library boundaries, as described in the
3171 // processor specific ABI supplement.
3173 do_dynsym_value(const Symbol
* gsym
) const;
3175 // Make an ELF object.
3177 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
3178 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
);
3181 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
3182 const elfcpp::Ehdr
<size
, !big_endian
>&)
3183 { gold_unreachable(); }
3185 // Make an output section.
3187 do_make_output_section(const char* name
, elfcpp::Elf_Word type
,
3188 elfcpp::Elf_Xword flags
)
3190 if (type
== elfcpp::SHT_MIPS_REGINFO
)
3191 return new Mips_output_section_reginfo
<size
, big_endian
>(name
, type
,
3194 return new Output_section(name
, type
, flags
);
3197 // Adjust ELF file header.
3199 do_adjust_elf_header(unsigned char* view
, int len
);
3201 // Get the custom dynamic tag value.
3203 do_dynamic_tag_custom_value(elfcpp::DT
) const;
3205 // Adjust the value written to the dynamic symbol table.
3207 do_adjust_dyn_symbol(const Symbol
* sym
, unsigned char* view
) const
3209 elfcpp::Sym
<size
, big_endian
> isym(view
);
3210 elfcpp::Sym_write
<size
, big_endian
> osym(view
);
3211 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
3213 // Keep dynamic compressed symbols odd. This allows the dynamic linker
3214 // to treat compressed symbols like any other.
3215 Mips_address value
= isym
.get_st_value();
3216 if (mips_sym
->is_mips16() && value
!= 0)
3218 if (!mips_sym
->has_mips16_fn_stub())
3222 // If we have a MIPS16 function with a stub, the dynamic symbol
3223 // must refer to the stub, since only the stub uses the standard
3224 // calling conventions. Stub contains MIPS32 code, so don't add +1
3227 // There is a code which does this in the method
3228 // Target_mips::do_dynsym_value, but that code will only be
3229 // executed if the symbol is from dynobj.
3230 // TODO(sasa): GNU ld also changes the value in non-dynamic symbol
3233 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
3234 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
3235 value
= fn_stub
->output_address();
3236 osym
.put_st_size(fn_stub
->section_size());
3239 osym
.put_st_value(value
);
3240 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(),
3241 mips_sym
->nonvis() - (elfcpp::STO_MIPS16
>> 2)));
3243 else if ((mips_sym
->is_micromips()
3244 // Stubs are always microMIPS if there is any microMIPS code in
3246 || (this->is_output_micromips() && mips_sym
->has_lazy_stub()))
3249 osym
.put_st_value(value
| 1);
3250 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(),
3251 mips_sym
->nonvis() - (elfcpp::STO_MICROMIPS
>> 2)));
3256 // The class which scans relocations.
3264 get_reference_flags(unsigned int r_type
);
3267 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3268 Sized_relobj_file
<size
, big_endian
>* object
,
3269 unsigned int data_shndx
,
3270 Output_section
* output_section
,
3271 const elfcpp::Rel
<size
, big_endian
>& reloc
, unsigned int r_type
,
3272 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3276 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3277 Sized_relobj_file
<size
, big_endian
>* object
,
3278 unsigned int data_shndx
,
3279 Output_section
* output_section
,
3280 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
3281 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3285 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3286 Sized_relobj_file
<size
, big_endian
>* object
,
3287 unsigned int data_shndx
,
3288 Output_section
* output_section
,
3289 const elfcpp::Rela
<size
, big_endian
>* rela
,
3290 const elfcpp::Rel
<size
, big_endian
>* rel
,
3291 unsigned int rel_type
,
3292 unsigned int r_type
,
3293 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3297 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3298 Sized_relobj_file
<size
, big_endian
>* object
,
3299 unsigned int data_shndx
,
3300 Output_section
* output_section
,
3301 const elfcpp::Rel
<size
, big_endian
>& reloc
, unsigned int r_type
,
3305 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3306 Sized_relobj_file
<size
, big_endian
>* object
,
3307 unsigned int data_shndx
,
3308 Output_section
* output_section
,
3309 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
3313 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3314 Sized_relobj_file
<size
, big_endian
>* object
,
3315 unsigned int data_shndx
,
3316 Output_section
* output_section
,
3317 const elfcpp::Rela
<size
, big_endian
>* rela
,
3318 const elfcpp::Rel
<size
, big_endian
>* rel
,
3319 unsigned int rel_type
,
3320 unsigned int r_type
,
3324 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
*,
3326 Sized_relobj_file
<size
, big_endian
>*,
3329 const elfcpp::Rel
<size
, big_endian
>&,
3331 const elfcpp::Sym
<size
, big_endian
>&)
3335 global_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3337 Sized_relobj_file
<size
, big_endian
>*,
3340 const elfcpp::Rel
<size
, big_endian
>&,
3341 unsigned int, Symbol
*)
3345 local_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3347 Sized_relobj_file
<size
, big_endian
>*,
3350 const elfcpp::Rela
<size
, big_endian
>&,
3352 const elfcpp::Sym
<size
, big_endian
>&)
3356 global_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3358 Sized_relobj_file
<size
, big_endian
>*,
3361 const elfcpp::Rela
<size
, big_endian
>&,
3362 unsigned int, Symbol
*)
3366 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
3367 unsigned int r_type
);
3370 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
3371 unsigned int r_type
, Symbol
*);
3374 // The class which implements relocation.
3384 // Return whether the R_MIPS_32 relocation needs to be applied.
3386 should_apply_r_mips_32_reloc(const Mips_symbol
<size
>* gsym
,
3387 unsigned int r_type
,
3388 Output_section
* output_section
,
3389 Target_mips
* target
);
3391 // Do a relocation. Return false if the caller should not issue
3392 // any warnings about this relocation.
3394 relocate(const Relocate_info
<size
, big_endian
>*, Target_mips
*,
3395 Output_section
*, size_t relnum
,
3396 const elfcpp::Rela
<size
, big_endian
>*,
3397 const elfcpp::Rel
<size
, big_endian
>*,
3399 unsigned int, const Sized_symbol
<size
>*,
3400 const Symbol_value
<size
>*,
3406 relocate(const Relocate_info
<size
, big_endian
>*, Target_mips
*,
3407 Output_section
*, size_t relnum
,
3408 const elfcpp::Rel
<size
, big_endian
>&,
3409 unsigned int, const Sized_symbol
<size
>*,
3410 const Symbol_value
<size
>*,
3416 relocate(const Relocate_info
<size
, big_endian
>*, Target_mips
*,
3417 Output_section
*, size_t relnum
,
3418 const elfcpp::Rela
<size
, big_endian
>&,
3419 unsigned int, const Sized_symbol
<size
>*,
3420 const Symbol_value
<size
>*,
3426 // A class which returns the size required for a relocation type,
3427 // used while scanning relocs during a relocatable link.
3428 class Relocatable_size_for_reloc
3432 get_size_for_reloc(unsigned int, Relobj
*);
3435 // This POD class holds the dynamic relocations that should be emitted instead
3436 // of R_MIPS_32, R_MIPS_REL32 and R_MIPS_64 relocations. We will emit these
3437 // relocations if it turns out that the symbol does not have static
3442 Dyn_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
3443 Mips_relobj
<size
, big_endian
>* relobj
, unsigned int shndx
,
3444 Output_section
* output_section
, Mips_address r_offset
)
3445 : sym_(sym
), r_type_(r_type
), relobj_(relobj
),
3446 shndx_(shndx
), output_section_(output_section
),
3450 // Emit this reloc if appropriate. This is called after we have
3451 // scanned all the relocations, so we know whether the symbol has
3452 // static relocations.
3454 emit(Reloc_section
* rel_dyn
, Mips_output_data_got
<size
, big_endian
>* got
,
3455 Symbol_table
* symtab
)
3457 if (!this->sym_
->has_static_relocs())
3459 got
->record_global_got_symbol(this->sym_
, this->relobj_
,
3460 this->r_type_
, true, false);
3461 if (!symbol_references_local(this->sym_
,
3462 this->sym_
->should_add_dynsym_entry(symtab
)))
3463 rel_dyn
->add_global(this->sym_
, this->r_type_
,
3464 this->output_section_
, this->relobj_
,
3465 this->shndx_
, this->r_offset_
);
3467 rel_dyn
->add_symbolless_global_addend(this->sym_
, this->r_type_
,
3468 this->output_section_
, this->relobj_
,
3469 this->shndx_
, this->r_offset_
);
3474 Mips_symbol
<size
>* sym_
;
3475 unsigned int r_type_
;
3476 Mips_relobj
<size
, big_endian
>* relobj_
;
3477 unsigned int shndx_
;
3478 Output_section
* output_section_
;
3479 Mips_address r_offset_
;
3482 // Adjust TLS relocation type based on the options and whether this
3483 // is a local symbol.
3484 static tls::Tls_optimization
3485 optimize_tls_reloc(bool is_final
, int r_type
);
3487 // Return whether there is a GOT section.
3489 has_got_section() const
3490 { return this->got_
!= NULL
; }
3492 // Check whether the given ELF header flags describe a 32-bit binary.
3494 mips_32bit_flags(elfcpp::Elf_Word
);
3497 mach_mips3000
= 3000,
3498 mach_mips3900
= 3900,
3499 mach_mips4000
= 4000,
3500 mach_mips4010
= 4010,
3501 mach_mips4100
= 4100,
3502 mach_mips4111
= 4111,
3503 mach_mips4120
= 4120,
3504 mach_mips4300
= 4300,
3505 mach_mips4400
= 4400,
3506 mach_mips4600
= 4600,
3507 mach_mips4650
= 4650,
3508 mach_mips5000
= 5000,
3509 mach_mips5400
= 5400,
3510 mach_mips5500
= 5500,
3511 mach_mips6000
= 6000,
3512 mach_mips7000
= 7000,
3513 mach_mips8000
= 8000,
3514 mach_mips9000
= 9000,
3515 mach_mips10000
= 10000,
3516 mach_mips12000
= 12000,
3517 mach_mips14000
= 14000,
3518 mach_mips16000
= 16000,
3521 mach_mips_loongson_2e
= 3001,
3522 mach_mips_loongson_2f
= 3002,
3523 mach_mips_loongson_3a
= 3003,
3524 mach_mips_sb1
= 12310201, // octal 'SB', 01
3525 mach_mips_octeon
= 6501,
3526 mach_mips_octeonp
= 6601,
3527 mach_mips_octeon2
= 6502,
3528 mach_mips_xlr
= 887682, // decimal 'XLR'
3529 mach_mipsisa32
= 32,
3530 mach_mipsisa32r2
= 33,
3531 mach_mipsisa64
= 64,
3532 mach_mipsisa64r2
= 65,
3533 mach_mips_micromips
= 96
3536 // Return the MACH for a MIPS e_flags value.
3538 elf_mips_mach(elfcpp::Elf_Word
);
3540 // Check whether machine EXTENSION is an extension of machine BASE.
3542 mips_mach_extends(unsigned int, unsigned int);
3544 // Merge processor specific flags.
3546 merge_processor_specific_flags(const std::string
&, elfcpp::Elf_Word
,
3547 unsigned char, bool);
3549 // True if we are linking for CPUs that are faster if JAL is converted to BAL.
3554 // True if we are linking for CPUs that are faster if JALR is converted to
3555 // BAL. This should be safe for all architectures. We enable this predicate
3561 // True if we are linking for CPUs that are faster if JR is converted to B.
3562 // This should be safe for all architectures. We enable this predicate for
3568 // Return the size of the GOT section.
3572 gold_assert(this->got_
!= NULL
);
3573 return this->got_
->data_size();
3576 // Create a PLT entry for a global symbol referenced by r_type relocation.
3578 make_plt_entry(Symbol_table
*, Layout
*, Mips_symbol
<size
>*,
3579 unsigned int r_type
);
3581 // Get the PLT section.
3582 Mips_output_data_plt
<size
, big_endian
>*
3585 gold_assert(this->plt_
!= NULL
);
3589 // Get the GOT PLT section.
3590 const Mips_output_data_plt
<size
, big_endian
>*
3591 got_plt_section() const
3593 gold_assert(this->got_plt_
!= NULL
);
3594 return this->got_plt_
;
3597 // Copy a relocation against a global symbol.
3599 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
3600 Sized_relobj_file
<size
, big_endian
>* object
,
3601 unsigned int shndx
, Output_section
* output_section
,
3602 Symbol
* sym
, const elfcpp::Rel
<size
, big_endian
>& reloc
)
3604 this->copy_relocs_
.copy_reloc(symtab
, layout
,
3605 symtab
->get_sized_symbol
<size
>(sym
),
3606 object
, shndx
, output_section
,
3607 reloc
, this->rel_dyn_section(layout
));
3611 dynamic_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
3612 Mips_relobj
<size
, big_endian
>* relobj
,
3613 unsigned int shndx
, Output_section
* output_section
,
3614 Mips_address r_offset
)
3616 this->dyn_relocs_
.push_back(Dyn_reloc(sym
, r_type
, relobj
, shndx
,
3617 output_section
, r_offset
));
3620 // Calculate value of _gp symbol.
3622 set_gp(Layout
*, Symbol_table
*);
3625 elf_mips_abi_name(elfcpp::Elf_Word e_flags
, unsigned char ei_class
);
3627 elf_mips_mach_name(elfcpp::Elf_Word e_flags
);
3629 // Adds entries that describe how machines relate to one another. The entries
3630 // are ordered topologically with MIPS I extensions listed last. First
3631 // element is extension, second element is base.
3633 add_machine_extensions()
3635 // MIPS64r2 extensions.
3636 this->add_extension(mach_mips_octeon2
, mach_mips_octeonp
);
3637 this->add_extension(mach_mips_octeonp
, mach_mips_octeon
);
3638 this->add_extension(mach_mips_octeon
, mach_mipsisa64r2
);
3640 // MIPS64 extensions.
3641 this->add_extension(mach_mipsisa64r2
, mach_mipsisa64
);
3642 this->add_extension(mach_mips_sb1
, mach_mipsisa64
);
3643 this->add_extension(mach_mips_xlr
, mach_mipsisa64
);
3644 this->add_extension(mach_mips_loongson_3a
, mach_mipsisa64
);
3646 // MIPS V extensions.
3647 this->add_extension(mach_mipsisa64
, mach_mips5
);
3649 // R10000 extensions.
3650 this->add_extension(mach_mips12000
, mach_mips10000
);
3651 this->add_extension(mach_mips14000
, mach_mips10000
);
3652 this->add_extension(mach_mips16000
, mach_mips10000
);
3654 // R5000 extensions. Note: the vr5500 ISA is an extension of the core
3655 // vr5400 ISA, but doesn't include the multimedia stuff. It seems
3656 // better to allow vr5400 and vr5500 code to be merged anyway, since
3657 // many libraries will just use the core ISA. Perhaps we could add
3658 // some sort of ASE flag if this ever proves a problem.
3659 this->add_extension(mach_mips5500
, mach_mips5400
);
3660 this->add_extension(mach_mips5400
, mach_mips5000
);
3662 // MIPS IV extensions.
3663 this->add_extension(mach_mips5
, mach_mips8000
);
3664 this->add_extension(mach_mips10000
, mach_mips8000
);
3665 this->add_extension(mach_mips5000
, mach_mips8000
);
3666 this->add_extension(mach_mips7000
, mach_mips8000
);
3667 this->add_extension(mach_mips9000
, mach_mips8000
);
3669 // VR4100 extensions.
3670 this->add_extension(mach_mips4120
, mach_mips4100
);
3671 this->add_extension(mach_mips4111
, mach_mips4100
);
3673 // MIPS III extensions.
3674 this->add_extension(mach_mips_loongson_2e
, mach_mips4000
);
3675 this->add_extension(mach_mips_loongson_2f
, mach_mips4000
);
3676 this->add_extension(mach_mips8000
, mach_mips4000
);
3677 this->add_extension(mach_mips4650
, mach_mips4000
);
3678 this->add_extension(mach_mips4600
, mach_mips4000
);
3679 this->add_extension(mach_mips4400
, mach_mips4000
);
3680 this->add_extension(mach_mips4300
, mach_mips4000
);
3681 this->add_extension(mach_mips4100
, mach_mips4000
);
3682 this->add_extension(mach_mips4010
, mach_mips4000
);
3684 // MIPS32 extensions.
3685 this->add_extension(mach_mipsisa32r2
, mach_mipsisa32
);
3687 // MIPS II extensions.
3688 this->add_extension(mach_mips4000
, mach_mips6000
);
3689 this->add_extension(mach_mipsisa32
, mach_mips6000
);
3691 // MIPS I extensions.
3692 this->add_extension(mach_mips6000
, mach_mips3000
);
3693 this->add_extension(mach_mips3900
, mach_mips3000
);
3696 // Add value to MIPS extenstions.
3698 add_extension(unsigned int base
, unsigned int extension
)
3700 std::pair
<unsigned int, unsigned int> ext(base
, extension
);
3701 this->mips_mach_extensions_
.push_back(ext
);
3704 // Return the number of entries in the .dynsym section.
3705 unsigned int get_dt_mips_symtabno() const
3707 return ((unsigned int)(this->layout_
->dynsym_section()->data_size()
3708 / elfcpp::Elf_sizes
<size
>::sym_size
));
3709 // TODO(sasa): Entry size is MIPS_ELF_SYM_SIZE.
3712 // Information about this specific target which we pass to the
3713 // general Target structure.
3714 static Target::Target_info mips_info
;
3716 Mips_output_data_got
<size
, big_endian
>* got_
;
3717 // gp symbol. It has the value of .got + 0x7FF0.
3718 Sized_symbol
<size
>* gp_
;
3720 Mips_output_data_plt
<size
, big_endian
>* plt_
;
3721 // The GOT PLT section.
3722 Output_data_space
* got_plt_
;
3723 // The dynamic reloc section.
3724 Reloc_section
* rel_dyn_
;
3725 // Relocs saved to avoid a COPY reloc.
3726 Mips_copy_relocs
<elfcpp::SHT_REL
, size
, big_endian
> copy_relocs_
;
3728 // A list of dyn relocs to be saved.
3729 std::vector
<Dyn_reloc
> dyn_relocs_
;
3731 // The LA25 stub section.
3732 Mips_output_data_la25_stub
<size
, big_endian
>* la25_stub_
;
3733 // Architecture extensions.
3734 std::vector
<std::pair
<unsigned int, unsigned int> > mips_mach_extensions_
;
3736 Mips_output_data_mips_stubs
<size
, big_endian
>* mips_stubs_
;
3738 unsigned char ei_class_
;
3742 typename
std::list
<got16_addend
<size
, big_endian
> > got16_addends_
;
3744 // Whether the entry symbol is mips16 or micromips.
3745 bool entry_symbol_is_compressed_
;
3747 // Whether we can use only 32-bit microMIPS instructions.
3748 // TODO(sasa): This should be a linker option.
3753 // Helper structure for R_MIPS*_HI16/LO16 and R_MIPS*_GOT16/LO16 relocations.
3754 // It records high part of the relocation pair.
3756 template<int size
, bool big_endian
>
3759 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
3761 reloc_high(unsigned char* _view
, const Mips_relobj
<size
, big_endian
>* _object
,
3762 const Symbol_value
<size
>* _psymval
, Mips_address _addend
,
3763 unsigned int _r_type
, bool _extract_addend
,
3764 Mips_address _address
= 0, bool _gp_disp
= false)
3765 : view(_view
), object(_object
), psymval(_psymval
), addend(_addend
),
3766 r_type(_r_type
), extract_addend(_extract_addend
), address(_address
),
3770 unsigned char* view
;
3771 const Mips_relobj
<size
, big_endian
>* object
;
3772 const Symbol_value
<size
>* psymval
;
3773 Mips_address addend
;
3774 unsigned int r_type
;
3775 bool extract_addend
;
3776 Mips_address address
;
3780 template<int size
, bool big_endian
>
3781 class Mips_relocate_functions
: public Relocate_functions
<size
, big_endian
>
3783 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
3784 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype16
;
3785 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
3790 STATUS_OKAY
, // No error during relocation.
3791 STATUS_OVERFLOW
, // Relocation overflow.
3792 STATUS_BAD_RELOC
// Relocation cannot be applied.
3796 typedef Relocate_functions
<size
, big_endian
> Base
;
3797 typedef Mips_relocate_functions
<size
, big_endian
> This
;
3799 static typename
std::list
<reloc_high
<size
, big_endian
> > hi16_relocs
;
3800 static typename
std::list
<reloc_high
<size
, big_endian
> > got16_relocs
;
3802 // R_MIPS16_26 is used for the mips16 jal and jalx instructions.
3803 // Most mips16 instructions are 16 bits, but these instructions
3806 // The format of these instructions is:
3808 // +--------------+--------------------------------+
3809 // | JALX | X| Imm 20:16 | Imm 25:21 |
3810 // +--------------+--------------------------------+
3811 // | Immediate 15:0 |
3812 // +-----------------------------------------------+
3814 // JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
3815 // Note that the immediate value in the first word is swapped.
3817 // When producing a relocatable object file, R_MIPS16_26 is
3818 // handled mostly like R_MIPS_26. In particular, the addend is
3819 // stored as a straight 26-bit value in a 32-bit instruction.
3820 // (gas makes life simpler for itself by never adjusting a
3821 // R_MIPS16_26 reloc to be against a section, so the addend is
3822 // always zero). However, the 32 bit instruction is stored as 2
3823 // 16-bit values, rather than a single 32-bit value. In a
3824 // big-endian file, the result is the same; in a little-endian
3825 // file, the two 16-bit halves of the 32 bit value are swapped.
3826 // This is so that a disassembler can recognize the jal
3829 // When doing a final link, R_MIPS16_26 is treated as a 32 bit
3830 // instruction stored as two 16-bit values. The addend A is the
3831 // contents of the targ26 field. The calculation is the same as
3832 // R_MIPS_26. When storing the calculated value, reorder the
3833 // immediate value as shown above, and don't forget to store the
3834 // value as two 16-bit values.
3836 // To put it in MIPS ABI terms, the relocation field is T-targ26-16,
3840 // +--------+----------------------+
3844 // +--------+----------------------+
3847 // +----------+------+-------------+
3849 // | sub1 | | sub2 |
3850 // |0 9|10 15|16 31|
3851 // +----------+--------------------+
3852 // where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
3853 // ((sub1 << 16) | sub2)).
3855 // When producing a relocatable object file, the calculation is
3856 // (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
3857 // When producing a fully linked file, the calculation is
3858 // let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
3859 // ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
3861 // The table below lists the other MIPS16 instruction relocations.
3862 // Each one is calculated in the same way as the non-MIPS16 relocation
3863 // given on the right, but using the extended MIPS16 layout of 16-bit
3864 // immediate fields:
3866 // R_MIPS16_GPREL R_MIPS_GPREL16
3867 // R_MIPS16_GOT16 R_MIPS_GOT16
3868 // R_MIPS16_CALL16 R_MIPS_CALL16
3869 // R_MIPS16_HI16 R_MIPS_HI16
3870 // R_MIPS16_LO16 R_MIPS_LO16
3872 // A typical instruction will have a format like this:
3874 // +--------------+--------------------------------+
3875 // | EXTEND | Imm 10:5 | Imm 15:11 |
3876 // +--------------+--------------------------------+
3877 // | Major | rx | ry | Imm 4:0 |
3878 // +--------------+--------------------------------+
3880 // EXTEND is the five bit value 11110. Major is the instruction
3883 // All we need to do here is shuffle the bits appropriately.
3884 // As above, the two 16-bit halves must be swapped on a
3885 // little-endian system.
3887 // Similar to MIPS16, the two 16-bit halves in microMIPS must be swapped
3888 // on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1
3889 // and R_MICROMIPS_PC10_S1 relocs that apply to 16-bit instructions.
3892 should_shuffle_micromips_reloc(unsigned int r_type
)
3894 return (micromips_reloc(r_type
)
3895 && r_type
!= elfcpp::R_MICROMIPS_PC7_S1
3896 && r_type
!= elfcpp::R_MICROMIPS_PC10_S1
);
3900 mips_reloc_unshuffle(unsigned char* view
, unsigned int r_type
,
3903 if (!mips16_reloc(r_type
)
3904 && !should_shuffle_micromips_reloc(r_type
))
3907 // Pick up the first and second halfwords of the instruction.
3908 Valtype16 first
= elfcpp::Swap
<16, big_endian
>::readval(view
);
3909 Valtype16 second
= elfcpp::Swap
<16, big_endian
>::readval(view
+ 2);
3912 if (micromips_reloc(r_type
)
3913 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
3914 val
= first
<< 16 | second
;
3915 else if (r_type
!= elfcpp::R_MIPS16_26
)
3916 val
= (((first
& 0xf800) << 16) | ((second
& 0xffe0) << 11)
3917 | ((first
& 0x1f) << 11) | (first
& 0x7e0) | (second
& 0x1f));
3919 val
= (((first
& 0xfc00) << 16) | ((first
& 0x3e0) << 11)
3920 | ((first
& 0x1f) << 21) | second
);
3922 elfcpp::Swap
<32, big_endian
>::writeval(view
, val
);
3926 mips_reloc_shuffle(unsigned char* view
, unsigned int r_type
, bool jal_shuffle
)
3928 if (!mips16_reloc(r_type
)
3929 && !should_shuffle_micromips_reloc(r_type
))
3932 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
3933 Valtype16 first
, second
;
3935 if (micromips_reloc(r_type
)
3936 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
3938 second
= val
& 0xffff;
3941 else if (r_type
!= elfcpp::R_MIPS16_26
)
3943 second
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
3944 first
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
3948 second
= val
& 0xffff;
3949 first
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
3950 | ((val
>> 21) & 0x1f);
3953 elfcpp::Swap
<16, big_endian
>::writeval(view
+ 2, second
);
3954 elfcpp::Swap
<16, big_endian
>::writeval(view
, first
);
3958 // R_MIPS_16: S + sign-extend(A)
3959 static inline typename
This::Status
3960 rel16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
3961 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
3962 bool extract_addend
, unsigned int r_type
)
3964 mips_reloc_unshuffle(view
, r_type
, false);
3965 Valtype16
* wv
= reinterpret_cast<Valtype16
*>(view
);
3966 Valtype16 val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
3968 Valtype32 addend
= (extract_addend
? Bits
<16>::sign_extend32(val
)
3969 : Bits
<16>::sign_extend32(addend_a
));
3971 Valtype32 x
= psymval
->value(object
, addend
);
3972 val
= Bits
<16>::bit_select32(val
, x
, 0xffffU
);
3973 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
3974 mips_reloc_shuffle(view
, r_type
, false);
3975 return (Bits
<16>::has_overflow32(x
)
3976 ? This::STATUS_OVERFLOW
3977 : This::STATUS_OKAY
);
3981 static inline typename
This::Status
3982 rel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
3983 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
3984 bool extract_addend
, unsigned int r_type
)
3986 mips_reloc_unshuffle(view
, r_type
, false);
3987 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
3988 Valtype32 addend
= (extract_addend
3989 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
3990 : Bits
<32>::sign_extend32(addend_a
));
3991 Valtype32 x
= psymval
->value(object
, addend
);
3992 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
3993 mips_reloc_shuffle(view
, r_type
, false);
3994 return This::STATUS_OKAY
;
3997 // R_MIPS_JALR, R_MICROMIPS_JALR
3998 static inline typename
This::Status
3999 reljalr(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4000 const Symbol_value
<size
>* psymval
, Mips_address address
,
4001 Mips_address addend_a
, bool extract_addend
, bool cross_mode_jump
,
4002 unsigned int r_type
, bool jalr_to_bal
, bool jr_to_b
)
4004 mips_reloc_unshuffle(view
, r_type
, false);
4005 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4006 Valtype32 addend
= extract_addend
? 0 : addend_a
;
4007 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4009 // Try converting J(AL)R to B(AL), if the target is in range.
4010 if (!parameters
->options().relocatable()
4011 && r_type
== elfcpp::R_MIPS_JALR
4013 && ((jalr_to_bal
&& val
== 0x0320f809) // jalr t9
4014 || (jr_to_b
&& val
== 0x03200008))) // jr t9
4016 int offset
= psymval
->value(object
, addend
) - (address
+ 4);
4017 if (!Bits
<18>::has_overflow32(offset
))
4019 if (val
== 0x03200008) // jr t9
4020 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4022 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4026 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4027 mips_reloc_shuffle(view
, r_type
, false);
4028 return This::STATUS_OKAY
;
4031 // R_MIPS_PC32: S + A - P
4032 static inline typename
This::Status
4033 relpc32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4034 const Symbol_value
<size
>* psymval
, Mips_address address
,
4035 Mips_address addend_a
, bool extract_addend
, unsigned int r_type
)
4037 mips_reloc_unshuffle(view
, r_type
, false);
4038 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4039 Valtype32 addend
= (extract_addend
4040 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
4041 : Bits
<32>::sign_extend32(addend_a
));
4042 Valtype32 x
= psymval
->value(object
, addend
) - address
;
4043 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4044 mips_reloc_shuffle(view
, r_type
, false);
4045 return This::STATUS_OKAY
;
4048 // R_MIPS_26, R_MIPS16_26, R_MICROMIPS_26_S1
4049 static inline typename
This::Status
4050 rel26(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4051 const Symbol_value
<size
>* psymval
, Mips_address address
,
4052 bool local
, Mips_address addend_a
, bool extract_addend
,
4053 const Symbol
* gsym
, bool cross_mode_jump
, unsigned int r_type
,
4056 mips_reloc_unshuffle(view
, r_type
, false);
4057 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4058 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4063 if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4064 addend
= (val
& 0x03ffffff) << 1;
4066 addend
= (val
& 0x03ffffff) << 2;
4071 // Make sure the target of JALX is word-aligned. Bit 0 must be
4072 // the correct ISA mode selector and bit 1 must be 0.
4074 && (psymval
->value(object
, 0) & 3) != (r_type
== elfcpp::R_MIPS_26
))
4076 gold_warning(_("JALX to a non-word-aligned address"));
4077 mips_reloc_shuffle(view
, r_type
, !parameters
->options().relocatable());
4078 return This::STATUS_BAD_RELOC
;
4081 // Shift is 2, unusually, for microMIPS JALX.
4082 unsigned int shift
=
4083 (!cross_mode_jump
&& r_type
== elfcpp::R_MICROMIPS_26_S1
) ? 1 : 2;
4087 x
= addend
| ((address
+ 4) & (0xfc000000 << shift
));
4091 x
= Bits
<27>::sign_extend32(addend
);
4093 x
= Bits
<28>::sign_extend32(addend
);
4095 x
= psymval
->value(object
, x
) >> shift
;
4097 if (!local
&& !gsym
->is_weak_undefined())
4099 if ((x
>> 26) != ((address
+ 4) >> (26 + shift
)))
4101 gold_error(_("relocation truncated to fit: %u against '%s'"),
4102 r_type
, gsym
->name());
4103 return This::STATUS_OVERFLOW
;
4107 val
= Bits
<32>::bit_select32(val
, x
, 0x03ffffff);
4109 // If required, turn JAL into JALX.
4110 if (cross_mode_jump
)
4113 Valtype32 opcode
= val
>> 26;
4114 Valtype32 jalx_opcode
;
4116 // Check to see if the opcode is already JAL or JALX.
4117 if (r_type
== elfcpp::R_MIPS16_26
)
4119 ok
= (opcode
== 0x6) || (opcode
== 0x7);
4122 else if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4124 ok
= (opcode
== 0x3d) || (opcode
== 0x3c);
4129 ok
= (opcode
== 0x3) || (opcode
== 0x1d);
4133 // If the opcode is not JAL or JALX, there's a problem. We cannot
4134 // convert J or JALS to JALX.
4137 gold_error(_("Unsupported jump between ISA modes; consider "
4138 "recompiling with interlinking enabled."));
4139 return This::STATUS_BAD_RELOC
;
4142 // Make this the JALX opcode.
4143 val
= (val
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
4146 // Try converting JAL to BAL, if the target is in range.
4147 if (!parameters
->options().relocatable()
4150 && r_type
== elfcpp::R_MIPS_26
4151 && (val
>> 26) == 0x3))) // jal addr
4153 Valtype32 dest
= (x
<< 2) | (((address
+ 4) >> 28) << 28);
4154 int offset
= dest
- (address
+ 4);
4155 if (!Bits
<18>::has_overflow32(offset
))
4157 if (val
== 0x03200008) // jr t9
4158 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4160 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4164 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4165 mips_reloc_shuffle(view
, r_type
, !parameters
->options().relocatable());
4166 return This::STATUS_OKAY
;
4170 static inline typename
This::Status
4171 relpc16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4172 const Symbol_value
<size
>* psymval
, Mips_address address
,
4173 Mips_address addend_a
, bool extract_addend
, unsigned int r_type
)
4175 mips_reloc_unshuffle(view
, r_type
, false);
4176 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4177 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4179 Valtype32 addend
= extract_addend
? (val
& 0xffff) << 2 : addend_a
;
4180 addend
= Bits
<18>::sign_extend32(addend
);
4182 Valtype32 x
= psymval
->value(object
, addend
) - address
;
4183 val
= Bits
<16>::bit_select32(val
, x
>> 2, 0xffff);
4184 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4185 mips_reloc_shuffle(view
, r_type
, false);
4186 return (Bits
<18>::has_overflow32(x
)
4187 ? This::STATUS_OVERFLOW
4188 : This::STATUS_OKAY
);
4191 // R_MICROMIPS_PC7_S1
4192 static inline typename
This::Status
4193 relmicromips_pc7_s1(unsigned char* view
,
4194 const Mips_relobj
<size
, big_endian
>* object
,
4195 const Symbol_value
<size
>* psymval
, Mips_address address
,
4196 Mips_address addend_a
, bool extract_addend
,
4197 unsigned int r_type
)
4199 mips_reloc_unshuffle(view
, r_type
, false);
4200 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4201 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4203 Valtype32 addend
= extract_addend
? (val
& 0x7f) << 1 : addend_a
;
4204 addend
= Bits
<8>::sign_extend32(addend
);
4206 Valtype32 x
= psymval
->value(object
, addend
) - address
;
4207 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x7f);
4208 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4209 mips_reloc_shuffle(view
, r_type
, false);
4210 return (Bits
<8>::has_overflow32(x
)
4211 ? This::STATUS_OVERFLOW
4212 : This::STATUS_OKAY
);
4215 // R_MICROMIPS_PC10_S1
4216 static inline typename
This::Status
4217 relmicromips_pc10_s1(unsigned char* view
,
4218 const Mips_relobj
<size
, big_endian
>* object
,
4219 const Symbol_value
<size
>* psymval
, Mips_address address
,
4220 Mips_address addend_a
, bool extract_addend
,
4221 unsigned int r_type
)
4223 mips_reloc_unshuffle(view
, r_type
, false);
4224 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4225 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4227 Valtype32 addend
= extract_addend
? (val
& 0x3ff) << 1 : addend_a
;
4228 addend
= Bits
<11>::sign_extend32(addend
);
4230 Valtype32 x
= psymval
->value(object
, addend
) - address
;
4231 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x3ff);
4232 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4233 mips_reloc_shuffle(view
, r_type
, false);
4234 return (Bits
<11>::has_overflow32(x
)
4235 ? This::STATUS_OVERFLOW
4236 : This::STATUS_OKAY
);
4239 // R_MICROMIPS_PC16_S1
4240 static inline typename
This::Status
4241 relmicromips_pc16_s1(unsigned char* view
,
4242 const Mips_relobj
<size
, big_endian
>* object
,
4243 const Symbol_value
<size
>* psymval
, Mips_address address
,
4244 Mips_address addend_a
, bool extract_addend
,
4245 unsigned int r_type
)
4247 mips_reloc_unshuffle(view
, r_type
, false);
4248 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4249 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4251 Valtype32 addend
= extract_addend
? (val
& 0xffff) << 1 : addend_a
;
4252 addend
= Bits
<17>::sign_extend32(addend
);
4254 Valtype32 x
= psymval
->value(object
, addend
) - address
;
4255 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0xffff);
4256 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4257 mips_reloc_shuffle(view
, r_type
, false);
4258 return (Bits
<17>::has_overflow32(x
)
4259 ? This::STATUS_OVERFLOW
4260 : This::STATUS_OKAY
);
4263 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
4264 static inline typename
This::Status
4265 relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4266 const Symbol_value
<size
>* psymval
, Mips_address addend
,
4267 Mips_address address
, bool gp_disp
, unsigned int r_type
,
4268 bool extract_addend
)
4270 // Record the relocation. It will be resolved when we find lo16 part.
4271 hi16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
4272 addend
, r_type
, extract_addend
, address
, gp_disp
));
4273 return This::STATUS_OKAY
;
4276 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
4277 static inline typename
This::Status
4278 do_relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4279 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
4280 Mips_address address
, bool is_gp_disp
, unsigned int r_type
,
4281 bool extract_addend
, Valtype32 addend_lo
,
4282 Target_mips
<size
, big_endian
>* target
)
4284 mips_reloc_unshuffle(view
, r_type
, false);
4285 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4286 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4288 Valtype32 addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
4293 value
= psymval
->value(object
, addend
);
4296 // For MIPS16 ABI code we generate this sequence
4297 // 0: li $v0,%hi(_gp_disp)
4298 // 4: addiupc $v1,%lo(_gp_disp)
4302 // So the offsets of hi and lo relocs are the same, but the
4303 // base $pc is that used by the ADDIUPC instruction at $t9 + 4.
4304 // ADDIUPC clears the low two bits of the instruction address,
4305 // so the base is ($t9 + 4) & ~3.
4307 if (r_type
== elfcpp::R_MIPS16_HI16
)
4308 gp_disp
= (target
->adjusted_gp_value(object
)
4309 - ((address
+ 4) & ~0x3));
4310 // The microMIPS .cpload sequence uses the same assembly
4311 // instructions as the traditional psABI version, but the
4312 // incoming $t9 has the low bit set.
4313 else if (r_type
== elfcpp::R_MICROMIPS_HI16
)
4314 gp_disp
= target
->adjusted_gp_value(object
) - address
- 1;
4316 gp_disp
= target
->adjusted_gp_value(object
) - address
;
4317 value
= gp_disp
+ addend
;
4319 Valtype32 x
= ((value
+ 0x8000) >> 16) & 0xffff;
4320 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4321 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4322 mips_reloc_shuffle(view
, r_type
, false);
4323 return (is_gp_disp
&& Bits
<16>::has_overflow32(x
)
4324 ? This::STATUS_OVERFLOW
4325 : This::STATUS_OKAY
);
4328 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4329 static inline typename
This::Status
4330 relgot16_local(unsigned char* view
,
4331 const Mips_relobj
<size
, big_endian
>* object
,
4332 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4333 bool extract_addend
, unsigned int r_type
)
4335 // Record the relocation. It will be resolved when we find lo16 part.
4336 got16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
4337 addend_a
, r_type
, extract_addend
));
4338 return This::STATUS_OKAY
;
4341 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4342 static inline typename
This::Status
4343 do_relgot16_local(unsigned char* view
,
4344 const Mips_relobj
<size
, big_endian
>* object
,
4345 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
4346 unsigned int r_type
, bool extract_addend
,
4347 Valtype32 addend_lo
, Target_mips
<size
, big_endian
>* target
)
4349 mips_reloc_unshuffle(view
, r_type
, false);
4350 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4351 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4353 Valtype32 addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
4356 // Find GOT page entry.
4357 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000) >> 16)
4360 unsigned int got_offset
=
4361 target
->got_section()->get_got_page_offset(value
, object
);
4363 // Resolve the relocation.
4364 Valtype32 x
= target
->got_section()->gp_offset(got_offset
, object
);
4365 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4366 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4367 mips_reloc_shuffle(view
, r_type
, false);
4368 return (Bits
<16>::has_overflow32(x
)
4369 ? This::STATUS_OVERFLOW
4370 : This::STATUS_OKAY
);
4373 // R_MIPS_LO16, R_MIPS16_LO16, R_MICROMIPS_LO16, R_MICROMIPS_HI0_LO16
4374 static inline typename
This::Status
4375 rello16(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4376 const Mips_relobj
<size
, big_endian
>* object
,
4377 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4378 bool extract_addend
, Mips_address address
, bool is_gp_disp
,
4379 unsigned int r_type
)
4381 mips_reloc_unshuffle(view
, r_type
, false);
4382 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4383 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4385 Valtype32 addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
4388 // Resolve pending R_MIPS_HI16 relocations.
4389 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it
=
4390 hi16_relocs
.begin();
4391 while (it
!= hi16_relocs
.end())
4393 reloc_high
<size
, big_endian
> hi16
= *it
;
4394 if (hi16
.psymval
->value(hi16
.object
, 0) == psymval
->value(object
, 0))
4396 if (do_relhi16(hi16
.view
, hi16
.object
, hi16
.psymval
, hi16
.addend
,
4397 hi16
.address
, hi16
.gp_disp
, hi16
.r_type
,
4398 hi16
.extract_addend
, addend
, target
)
4399 == This::STATUS_OVERFLOW
)
4400 return This::STATUS_OVERFLOW
;
4401 it
= hi16_relocs
.erase(it
);
4407 // Resolve pending local R_MIPS_GOT16 relocations.
4408 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it2
=
4409 got16_relocs
.begin();
4410 while (it2
!= got16_relocs
.end())
4412 reloc_high
<size
, big_endian
> got16
= *it2
;
4413 if (got16
.psymval
->value(got16
.object
, 0) == psymval
->value(object
, 0))
4415 if (do_relgot16_local(got16
.view
, got16
.object
, got16
.psymval
,
4416 got16
.addend
, got16
.r_type
,
4417 got16
.extract_addend
, addend
,
4418 target
) == This::STATUS_OVERFLOW
)
4419 return This::STATUS_OVERFLOW
;
4420 it2
= got16_relocs
.erase(it2
);
4426 // Resolve R_MIPS_LO16 relocation.
4429 x
= psymval
->value(object
, addend
);
4432 // See the comment for R_MIPS16_HI16 above for the reason
4433 // for this conditional.
4435 if (r_type
== elfcpp::R_MIPS16_LO16
)
4436 gp_disp
= target
->adjusted_gp_value(object
) - (address
& ~0x3);
4437 else if (r_type
== elfcpp::R_MICROMIPS_LO16
4438 || r_type
== elfcpp::R_MICROMIPS_HI0_LO16
)
4439 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 3;
4441 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 4;
4442 // The MIPS ABI requires checking the R_MIPS_LO16 relocation
4443 // for overflow. Relocations against _gp_disp are normally
4444 // generated from the .cpload pseudo-op. It generates code
4445 // that normally looks like this:
4447 // lui $gp,%hi(_gp_disp)
4448 // addiu $gp,$gp,%lo(_gp_disp)
4451 // Here $t9 holds the address of the function being called,
4452 // as required by the MIPS ELF ABI. The R_MIPS_LO16
4453 // relocation can easily overflow in this situation, but the
4454 // R_MIPS_HI16 relocation will handle the overflow.
4455 // Therefore, we consider this a bug in the MIPS ABI, and do
4456 // not check for overflow here.
4457 x
= gp_disp
+ addend
;
4459 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4460 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4461 mips_reloc_shuffle(view
, r_type
, false);
4462 return This::STATUS_OKAY
;
4465 // R_MIPS_CALL16, R_MIPS16_CALL16, R_MICROMIPS_CALL16
4466 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4467 // R_MIPS_TLS_GD, R_MIPS16_TLS_GD, R_MICROMIPS_TLS_GD
4468 // R_MIPS_TLS_GOTTPREL, R_MIPS16_TLS_GOTTPREL, R_MICROMIPS_TLS_GOTTPREL
4469 // R_MIPS_TLS_LDM, R_MIPS16_TLS_LDM, R_MICROMIPS_TLS_LDM
4470 // R_MIPS_GOT_DISP, R_MICROMIPS_GOT_DISP
4471 static inline typename
This::Status
4472 relgot(unsigned char* view
, int gp_offset
, unsigned int r_type
)
4474 mips_reloc_unshuffle(view
, r_type
, false);
4475 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4476 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4477 Valtype32 x
= gp_offset
;
4478 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4479 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4480 mips_reloc_shuffle(view
, r_type
, false);
4481 return (Bits
<16>::has_overflow32(x
)
4482 ? This::STATUS_OVERFLOW
4483 : This::STATUS_OKAY
);
4486 // R_MIPS_GOT_PAGE, R_MICROMIPS_GOT_PAGE
4487 static inline typename
This::Status
4488 relgotpage(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4489 const Mips_relobj
<size
, big_endian
>* object
,
4490 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4491 bool extract_addend
, unsigned int r_type
)
4493 mips_reloc_unshuffle(view
, r_type
, false);
4494 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4495 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4496 Valtype32 addend
= extract_addend
? val
& 0xffff : addend_a
;
4498 // Find a GOT page entry that points to within 32KB of symbol + addend.
4499 Mips_address value
= (psymval
->value(object
, addend
) + 0x8000) & ~0xffff;
4500 unsigned int got_offset
=
4501 target
->got_section()->get_got_page_offset(value
, object
);
4503 Valtype32 x
= target
->got_section()->gp_offset(got_offset
, object
);
4504 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4505 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4506 mips_reloc_shuffle(view
, r_type
, false);
4507 return (Bits
<16>::has_overflow32(x
)
4508 ? This::STATUS_OVERFLOW
4509 : This::STATUS_OKAY
);
4512 // R_MIPS_GOT_OFST, R_MICROMIPS_GOT_OFST
4513 static inline typename
This::Status
4514 relgotofst(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4515 const Mips_relobj
<size
, big_endian
>* object
,
4516 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4517 bool extract_addend
, bool local
, unsigned int r_type
)
4519 mips_reloc_unshuffle(view
, r_type
, false);
4520 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4521 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4522 Valtype32 addend
= extract_addend
? val
& 0xffff : addend_a
;
4524 // For a local symbol, find a GOT page entry that points to within 32KB of
4525 // symbol + addend. Relocation value is the offset of the GOT page entry's
4526 // value from symbol + addend.
4527 // For a global symbol, relocation value is addend.
4531 // Find GOT page entry.
4532 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000)
4534 target
->got_section()->get_got_page_offset(value
, object
);
4536 x
= psymval
->value(object
, addend
) - value
;
4540 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4541 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4542 mips_reloc_shuffle(view
, r_type
, false);
4543 return (Bits
<16>::has_overflow32(x
)
4544 ? This::STATUS_OVERFLOW
4545 : This::STATUS_OKAY
);
4548 // R_MIPS_GOT_HI16, R_MIPS_CALL_HI16,
4549 // R_MICROMIPS_GOT_HI16, R_MICROMIPS_CALL_HI16
4550 static inline typename
This::Status
4551 relgot_hi16(unsigned char* view
, int gp_offset
, unsigned int r_type
)
4553 mips_reloc_unshuffle(view
, r_type
, false);
4554 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4555 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4556 Valtype32 x
= gp_offset
;
4557 x
= ((x
+ 0x8000) >> 16) & 0xffff;
4558 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4559 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4560 mips_reloc_shuffle(view
, r_type
, false);
4561 return This::STATUS_OKAY
;
4564 // R_MIPS_GOT_LO16, R_MIPS_CALL_LO16,
4565 // R_MICROMIPS_GOT_LO16, R_MICROMIPS_CALL_LO16
4566 static inline typename
This::Status
4567 relgot_lo16(unsigned char* view
, int gp_offset
, unsigned int r_type
)
4569 mips_reloc_unshuffle(view
, r_type
, false);
4570 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4571 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4572 Valtype32 x
= gp_offset
;
4573 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4574 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4575 mips_reloc_shuffle(view
, r_type
, false);
4576 return This::STATUS_OKAY
;
4579 // R_MIPS_GPREL16, R_MIPS16_GPREL, R_MIPS_LITERAL, R_MICROMIPS_LITERAL
4580 // R_MICROMIPS_GPREL7_S2, R_MICROMIPS_GPREL16
4581 static inline typename
This::Status
4582 relgprel(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4583 const Symbol_value
<size
>* psymval
, Mips_address gp
,
4584 Mips_address addend_a
, bool extract_addend
, bool local
,
4585 unsigned int r_type
)
4587 mips_reloc_unshuffle(view
, r_type
, false);
4588 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4589 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4594 if (r_type
== elfcpp::R_MICROMIPS_GPREL7_S2
)
4595 addend
= (val
& 0x7f) << 2;
4597 addend
= val
& 0xffff;
4598 // Only sign-extend the addend if it was extracted from the
4599 // instruction. If the addend was separate, leave it alone,
4600 // otherwise we may lose significant bits.
4601 addend
= Bits
<16>::sign_extend32(addend
);
4606 Valtype32 x
= psymval
->value(object
, addend
) - gp
;
4608 // If the symbol was local, any earlier relocatable links will
4609 // have adjusted its addend with the gp offset, so compensate
4610 // for that now. Don't do it for symbols forced local in this
4611 // link, though, since they won't have had the gp offset applied
4614 x
+= object
->gp_value();
4616 if (r_type
== elfcpp::R_MICROMIPS_GPREL7_S2
)
4617 val
= Bits
<32>::bit_select32(val
, x
, 0x7f);
4619 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4620 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4621 mips_reloc_shuffle(view
, r_type
, false);
4622 if (Bits
<16>::has_overflow32(x
))
4624 gold_error(_("small-data section exceeds 64KB; lower small-data size "
4625 "limit (see option -G)"));
4626 return This::STATUS_OVERFLOW
;
4628 return This::STATUS_OKAY
;
4632 static inline typename
This::Status
4633 relgprel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4634 const Symbol_value
<size
>* psymval
, Mips_address gp
,
4635 Mips_address addend_a
, bool extract_addend
, unsigned int r_type
)
4637 mips_reloc_unshuffle(view
, r_type
, false);
4638 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4639 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4640 Valtype32 addend
= extract_addend
? val
: addend_a
;
4642 // R_MIPS_GPREL32 relocations are defined for local symbols only.
4643 Valtype32 x
= psymval
->value(object
, addend
) + object
->gp_value() - gp
;
4644 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4645 mips_reloc_shuffle(view
, r_type
, false);
4646 return This::STATUS_OKAY
;
4649 // R_MIPS_TLS_TPREL_HI16, R_MIPS16_TLS_TPREL_HI16, R_MICROMIPS_TLS_TPREL_HI16
4650 // R_MIPS_TLS_DTPREL_HI16, R_MIPS16_TLS_DTPREL_HI16,
4651 // R_MICROMIPS_TLS_DTPREL_HI16
4652 static inline typename
This::Status
4653 tlsrelhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4654 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
4655 Mips_address addend_a
, bool extract_addend
, unsigned int r_type
)
4657 mips_reloc_unshuffle(view
, r_type
, false);
4658 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4659 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4660 Valtype32 addend
= extract_addend
? val
& 0xffff : addend_a
;
4662 // tls symbol values are relative to tls_segment()->vaddr()
4663 Valtype32 x
= ((psymval
->value(object
, addend
) - tp_offset
) + 0x8000) >> 16;
4664 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4665 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4666 mips_reloc_shuffle(view
, r_type
, false);
4667 return This::STATUS_OKAY
;
4670 // R_MIPS_TLS_TPREL_LO16, R_MIPS16_TLS_TPREL_LO16, R_MICROMIPS_TLS_TPREL_LO16,
4671 // R_MIPS_TLS_DTPREL_LO16, R_MIPS16_TLS_DTPREL_LO16,
4672 // R_MICROMIPS_TLS_DTPREL_LO16,
4673 static inline typename
This::Status
4674 tlsrello16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4675 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
4676 Mips_address addend_a
, bool extract_addend
, unsigned int r_type
)
4678 mips_reloc_unshuffle(view
, r_type
, false);
4679 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4680 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4681 Valtype32 addend
= extract_addend
? val
& 0xffff : addend_a
;
4683 // tls symbol values are relative to tls_segment()->vaddr()
4684 Valtype32 x
= psymval
->value(object
, addend
) - tp_offset
;
4685 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4686 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4687 mips_reloc_shuffle(view
, r_type
, false);
4688 return This::STATUS_OKAY
;
4691 // R_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL64,
4692 // R_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL64
4693 static inline typename
This::Status
4694 tlsrel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4695 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
4696 Mips_address addend_a
, bool extract_addend
, unsigned int r_type
)
4698 mips_reloc_unshuffle(view
, r_type
, false);
4699 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4700 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4701 Valtype32 addend
= extract_addend
? val
: addend_a
;
4703 // tls symbol values are relative to tls_segment()->vaddr()
4704 Valtype32 x
= psymval
->value(object
, addend
) - tp_offset
;
4705 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4706 mips_reloc_shuffle(view
, r_type
, false);
4707 return This::STATUS_OKAY
;
4710 // R_MIPS_SUB, R_MICROMIPS_SUB
4711 static inline typename
This::Status
4712 relsub(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4713 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4714 bool extract_addend
, unsigned int r_type
)
4716 mips_reloc_unshuffle(view
, r_type
, false);
4717 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4718 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4719 Valtype32 addend
= extract_addend
? val
: addend_a
;
4721 Valtype32 x
= psymval
->value(object
, -addend
);
4722 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4723 mips_reloc_shuffle(view
, r_type
, false);
4724 return This::STATUS_OKAY
;
4728 template<int size
, bool big_endian
>
4729 typename
std::list
<reloc_high
<size
, big_endian
> >
4730 Mips_relocate_functions
<size
, big_endian
>::hi16_relocs
;
4732 template<int size
, bool big_endian
>
4733 typename
std::list
<reloc_high
<size
, big_endian
> >
4734 Mips_relocate_functions
<size
, big_endian
>::got16_relocs
;
4736 // Mips_got_info methods.
4738 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
4739 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
4741 template<int size
, bool big_endian
>
4743 Mips_got_info
<size
, big_endian
>::record_local_got_symbol(
4744 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
,
4745 Mips_address addend
, unsigned int r_type
, unsigned int shndx
)
4747 Mips_got_entry
<size
, big_endian
>* entry
=
4748 new Mips_got_entry
<size
, big_endian
>(object
, symndx
, addend
,
4749 mips_elf_reloc_tls_type(r_type
),
4751 this->record_got_entry(entry
, object
);
4754 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
4755 // in OBJECT. FOR_CALL is true if the caller is only interested in
4756 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
4759 template<int size
, bool big_endian
>
4761 Mips_got_info
<size
, big_endian
>::record_global_got_symbol(
4762 Mips_symbol
<size
>* mips_sym
, Mips_relobj
<size
, big_endian
>* object
,
4763 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
4766 mips_sym
->set_got_not_only_for_calls();
4768 // A global symbol in the GOT must also be in the dynamic symbol table.
4769 if (!mips_sym
->needs_dynsym_entry())
4771 switch (mips_sym
->visibility())
4773 case elfcpp::STV_INTERNAL
:
4774 case elfcpp::STV_HIDDEN
:
4775 mips_sym
->set_is_forced_local();
4778 mips_sym
->set_needs_dynsym_entry();
4783 unsigned char tls_type
= mips_elf_reloc_tls_type(r_type
);
4784 if (tls_type
== GOT_TLS_NONE
)
4785 this->global_got_symbols_
.insert(mips_sym
);
4789 if (mips_sym
->global_got_area() == GGA_NONE
)
4790 mips_sym
->set_global_got_area(GGA_RELOC_ONLY
);
4794 Mips_got_entry
<size
, big_endian
>* entry
=
4795 new Mips_got_entry
<size
, big_endian
>(object
, mips_sym
, tls_type
);
4797 this->record_got_entry(entry
, object
);
4800 // Add ENTRY to master GOT and to OBJECT's GOT.
4802 template<int size
, bool big_endian
>
4804 Mips_got_info
<size
, big_endian
>::record_got_entry(
4805 Mips_got_entry
<size
, big_endian
>* entry
,
4806 Mips_relobj
<size
, big_endian
>* object
)
4808 if (this->got_entries_
.find(entry
) == this->got_entries_
.end())
4809 this->got_entries_
.insert(entry
);
4811 // Create the GOT entry for the OBJECT's GOT.
4812 Mips_got_info
<size
, big_endian
>* g
= object
->get_or_create_got_info();
4813 Mips_got_entry
<size
, big_endian
>* entry2
=
4814 new Mips_got_entry
<size
, big_endian
>(*entry
);
4816 if (g
->got_entries_
.find(entry2
) == g
->got_entries_
.end())
4817 g
->got_entries_
.insert(entry2
);
4820 // Record that OBJECT has a page relocation against symbol SYMNDX and
4821 // that ADDEND is the addend for that relocation.
4822 // This function creates an upper bound on the number of GOT slots
4823 // required; no attempt is made to combine references to non-overridable
4824 // global symbols across multiple input files.
4826 template<int size
, bool big_endian
>
4828 Mips_got_info
<size
, big_endian
>::record_got_page_entry(
4829 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
, int addend
)
4831 struct Got_page_range
**range_ptr
, *range
;
4832 int old_pages
, new_pages
;
4834 // Find the Got_page_entry for this symbol.
4835 Got_page_entry
* entry
= new Got_page_entry(object
, symndx
);
4836 typename
Got_page_entry_set::iterator it
=
4837 this->got_page_entries_
.find(entry
);
4838 if (it
!= this->got_page_entries_
.end())
4841 this->got_page_entries_
.insert(entry
);
4843 // Add the same entry to the OBJECT's GOT.
4844 Got_page_entry
* entry2
= NULL
;
4845 Mips_got_info
<size
, big_endian
>* g2
= object
->get_or_create_got_info();
4846 if (g2
->got_page_entries_
.find(entry
) == g2
->got_page_entries_
.end())
4848 entry2
= new Got_page_entry(*entry
);
4849 g2
->got_page_entries_
.insert(entry2
);
4852 // Skip over ranges whose maximum extent cannot share a page entry
4854 range_ptr
= &entry
->ranges
;
4855 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
4856 range_ptr
= &(*range_ptr
)->next
;
4858 // If we scanned to the end of the list, or found a range whose
4859 // minimum extent cannot share a page entry with ADDEND, create
4860 // a new singleton range.
4862 if (!range
|| addend
< range
->min_addend
- 0xffff)
4864 range
= new Got_page_range();
4865 range
->next
= *range_ptr
;
4866 range
->min_addend
= addend
;
4867 range
->max_addend
= addend
;
4872 ++entry2
->num_pages
;
4873 ++this->page_gotno_
;
4878 // Remember how many pages the old range contributed.
4879 old_pages
= range
->get_max_pages();
4881 // Update the ranges.
4882 if (addend
< range
->min_addend
)
4883 range
->min_addend
= addend
;
4884 else if (addend
> range
->max_addend
)
4886 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
4888 old_pages
+= range
->next
->get_max_pages();
4889 range
->max_addend
= range
->next
->max_addend
;
4890 range
->next
= range
->next
->next
;
4893 range
->max_addend
= addend
;
4896 // Record any change in the total estimate.
4897 new_pages
= range
->get_max_pages();
4898 if (old_pages
!= new_pages
)
4900 entry
->num_pages
+= new_pages
- old_pages
;
4902 entry2
->num_pages
+= new_pages
- old_pages
;
4903 this->page_gotno_
+= new_pages
- old_pages
;
4904 g2
->page_gotno_
+= new_pages
- old_pages
;
4908 // Create all entries that should be in the local part of the GOT.
4910 template<int size
, bool big_endian
>
4912 Mips_got_info
<size
, big_endian
>::add_local_entries(
4913 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
4915 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
4916 // First two GOT entries are reserved. The first entry will be filled at
4917 // runtime. The second entry will be used by some runtime loaders.
4918 got
->add_constant(0);
4919 got
->add_constant(target
->mips_elf_gnu_got1_mask());
4921 for (typename
Got_entry_set::iterator
4922 p
= this->got_entries_
.begin();
4923 p
!= this->got_entries_
.end();
4926 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
4927 if (entry
->is_for_local_symbol() && !entry
->is_tls_entry())
4929 got
->add_local(entry
->object(), entry
->symndx(),
4931 unsigned int got_offset
= entry
->object()->local_got_offset(
4932 entry
->symndx(), GOT_TYPE_STANDARD
);
4933 if (got
->multi_got() && this->index_
> 0
4934 && parameters
->options().output_is_position_independent())
4935 target
->rel_dyn_section(layout
)->add_local(entry
->object(),
4936 entry
->symndx(), elfcpp::R_MIPS_REL32
, got
, got_offset
);
4940 this->add_page_entries(target
, layout
);
4942 // Add global entries that should be in the local area.
4943 for (typename
Got_entry_set::iterator
4944 p
= this->got_entries_
.begin();
4945 p
!= this->got_entries_
.end();
4948 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
4949 if (!entry
->is_for_global_symbol())
4952 Mips_symbol
<size
>* mips_sym
= entry
->sym();
4953 if (mips_sym
->global_got_area() == GGA_NONE
&& !entry
->is_tls_entry())
4955 unsigned int got_type
;
4956 if (!got
->multi_got())
4957 got_type
= GOT_TYPE_STANDARD
;
4959 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
4960 if (got
->add_global(mips_sym
, got_type
))
4962 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
4963 if (got
->multi_got() && this->index_
> 0
4964 && parameters
->options().output_is_position_independent())
4965 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
4966 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
4967 mips_sym
->got_offset(got_type
));
4973 // Create GOT page entries.
4975 template<int size
, bool big_endian
>
4977 Mips_got_info
<size
, big_endian
>::add_page_entries(
4978 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
4980 if (this->page_gotno_
== 0)
4983 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
4984 this->got_page_offset_start_
= got
->add_constant(0);
4985 if (got
->multi_got() && this->index_
> 0
4986 && parameters
->options().output_is_position_independent())
4987 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
4988 this->got_page_offset_start_
);
4989 int num_entries
= this->page_gotno_
;
4990 unsigned int prev_offset
= this->got_page_offset_start_
;
4991 while (--num_entries
> 0)
4993 unsigned int next_offset
= got
->add_constant(0);
4994 if (got
->multi_got() && this->index_
> 0
4995 && parameters
->options().output_is_position_independent())
4996 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
4998 gold_assert(next_offset
== prev_offset
+ size
/8);
4999 prev_offset
= next_offset
;
5001 this->got_page_offset_next_
= this->got_page_offset_start_
;
5004 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
5006 template<int size
, bool big_endian
>
5008 Mips_got_info
<size
, big_endian
>::add_global_entries(
5009 Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
5010 unsigned int non_reloc_only_global_gotno
)
5012 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5013 // Add GGA_NORMAL entries.
5014 unsigned int count
= 0;
5015 for (typename
Got_entry_set::iterator
5016 p
= this->got_entries_
.begin();
5017 p
!= this->got_entries_
.end();
5020 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5021 if (!entry
->is_for_global_symbol())
5024 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5025 if (mips_sym
->global_got_area() != GGA_NORMAL
)
5028 unsigned int got_type
;
5029 if (!got
->multi_got())
5030 got_type
= GOT_TYPE_STANDARD
;
5032 // In multi-GOT links, global symbol can be in both primary and
5033 // secondary GOT(s). By creating custom GOT type
5034 // (GOT_TYPE_STANDARD_MULTIGOT + got_index) we ensure that symbol
5035 // is added to secondary GOT(s).
5036 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
5037 if (!got
->add_global(mips_sym
, got_type
))
5040 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5041 if (got
->multi_got() && this->index_
== 0)
5043 if (got
->multi_got() && this->index_
> 0)
5045 if (parameters
->options().output_is_position_independent()
5046 || (!parameters
->doing_static_link()
5047 && mips_sym
->is_from_dynobj() && !mips_sym
->is_undefined()))
5049 target
->rel_dyn_section(layout
)->add_global(
5050 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
5051 mips_sym
->got_offset(got_type
));
5052 got
->add_secondary_got_reloc(mips_sym
->got_offset(got_type
),
5053 elfcpp::R_MIPS_REL32
, mips_sym
);
5058 if (!got
->multi_got() || this->index_
== 0)
5060 if (got
->multi_got())
5062 // We need to allocate space in the primary GOT for GGA_NORMAL entries
5063 // of secondary GOTs, to ensure that GOT offsets of GGA_RELOC_ONLY
5064 // entries correspond to dynamic symbol indexes.
5065 while (count
< non_reloc_only_global_gotno
)
5067 got
->add_constant(0);
5072 // Add GGA_RELOC_ONLY entries.
5073 got
->add_reloc_only_entries();
5077 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
5079 template<int size
, bool big_endian
>
5081 Mips_got_info
<size
, big_endian
>::add_reloc_only_entries(
5082 Mips_output_data_got
<size
, big_endian
>* got
)
5084 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
5085 p
= this->global_got_symbols_
.begin();
5086 p
!= this->global_got_symbols_
.end();
5089 Mips_symbol
<size
>* mips_sym
= *p
;
5090 if (mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
5092 unsigned int got_type
;
5093 if (!got
->multi_got())
5094 got_type
= GOT_TYPE_STANDARD
;
5096 got_type
= GOT_TYPE_STANDARD_MULTIGOT
;
5097 if (got
->add_global(mips_sym
, got_type
))
5098 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5103 // Create TLS GOT entries.
5105 template<int size
, bool big_endian
>
5107 Mips_got_info
<size
, big_endian
>::add_tls_entries(
5108 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5110 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5111 // Add local tls entries.
5112 for (typename
Got_entry_set::iterator
5113 p
= this->got_entries_
.begin();
5114 p
!= this->got_entries_
.end();
5117 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5118 if (!entry
->is_tls_entry() || !entry
->is_for_local_symbol())
5121 if (entry
->tls_type() == GOT_TLS_GD
)
5123 unsigned int got_type
= GOT_TYPE_TLS_PAIR
;
5124 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5125 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5126 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
5127 : elfcpp::R_MIPS_TLS_DTPREL64
);
5129 if (!parameters
->doing_static_link())
5131 got
->add_local_pair_with_rel(entry
->object(), entry
->symndx(),
5132 entry
->shndx(), got_type
,
5133 target
->rel_dyn_section(layout
),
5135 unsigned int got_offset
=
5136 entry
->object()->local_got_offset(entry
->symndx(), got_type
);
5137 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
5138 entry
->object(), entry
->symndx());
5142 // We are doing a static link. Mark it as belong to module 1,
5144 unsigned int got_offset
= got
->add_constant(1);
5145 entry
->object()->set_local_got_offset(entry
->symndx(), got_type
,
5147 got
->add_constant(0);
5148 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
5149 entry
->object(), entry
->symndx());
5152 else if (entry
->tls_type() == GOT_TLS_IE
)
5154 unsigned int got_type
= GOT_TYPE_TLS_OFFSET
;
5155 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
5156 : elfcpp::R_MIPS_TLS_TPREL64
);
5157 if (!parameters
->doing_static_link())
5158 got
->add_local_with_rel(entry
->object(), entry
->symndx(), got_type
,
5159 target
->rel_dyn_section(layout
), r_type
);
5162 got
->add_local(entry
->object(), entry
->symndx(), got_type
);
5163 unsigned int got_offset
=
5164 entry
->object()->local_got_offset(entry
->symndx(), got_type
);
5165 got
->add_static_reloc(got_offset
, r_type
, entry
->object(),
5169 else if (entry
->tls_type() == GOT_TLS_LDM
)
5171 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5172 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5173 unsigned int got_offset
;
5174 if (!parameters
->doing_static_link())
5176 got_offset
= got
->add_constant(0);
5177 target
->rel_dyn_section(layout
)->add_local(
5178 entry
->object(), 0, r_type
, got
, got_offset
);
5181 // We are doing a static link. Just mark it as belong to module 1,
5183 got_offset
= got
->add_constant(1);
5185 got
->add_constant(0);
5186 got
->set_tls_ldm_offset(got_offset
, entry
->object());
5192 // Add global tls entries.
5193 for (typename
Got_entry_set::iterator
5194 p
= this->got_entries_
.begin();
5195 p
!= this->got_entries_
.end();
5198 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5199 if (!entry
->is_tls_entry() || !entry
->is_for_global_symbol())
5202 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5203 if (entry
->tls_type() == GOT_TLS_GD
)
5205 unsigned int got_type
;
5206 if (!got
->multi_got())
5207 got_type
= GOT_TYPE_TLS_PAIR
;
5209 got_type
= GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
5210 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5211 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5212 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
5213 : elfcpp::R_MIPS_TLS_DTPREL64
);
5214 if (!parameters
->doing_static_link())
5215 got
->add_global_pair_with_rel(mips_sym
, got_type
,
5216 target
->rel_dyn_section(layout
), r_type1
, r_type2
);
5219 // Add a GOT pair for for R_MIPS_TLS_GD. The creates a pair of
5220 // GOT entries. The first one is initialized to be 1, which is the
5221 // module index for the main executable and the second one 0. A
5222 // reloc of the type R_MIPS_TLS_DTPREL32/64 will be created for
5223 // the second GOT entry and will be applied by gold.
5224 unsigned int got_offset
= got
->add_constant(1);
5225 mips_sym
->set_got_offset(got_type
, got_offset
);
5226 got
->add_constant(0);
5227 got
->add_static_reloc(got_offset
+ size
/8, r_type2
, mips_sym
);
5230 else if (entry
->tls_type() == GOT_TLS_IE
)
5232 unsigned int got_type
;
5233 if (!got
->multi_got())
5234 got_type
= GOT_TYPE_TLS_OFFSET
;
5236 got_type
= GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
5237 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
5238 : elfcpp::R_MIPS_TLS_TPREL64
);
5239 if (!parameters
->doing_static_link())
5240 got
->add_global_with_rel(mips_sym
, got_type
,
5241 target
->rel_dyn_section(layout
), r_type
);
5244 got
->add_global(mips_sym
, got_type
);
5245 unsigned int got_offset
= mips_sym
->got_offset(got_type
);
5246 got
->add_static_reloc(got_offset
, r_type
, mips_sym
);
5254 // Decide whether the symbol needs an entry in the global part of the primary
5255 // GOT, setting global_got_area accordingly. Count the number of global
5256 // symbols that are in the primary GOT only because they have dynamic
5257 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
5259 template<int size
, bool big_endian
>
5261 Mips_got_info
<size
, big_endian
>::count_got_symbols(Symbol_table
* symtab
)
5263 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
5264 p
= this->global_got_symbols_
.begin();
5265 p
!= this->global_got_symbols_
.end();
5268 Mips_symbol
<size
>* sym
= *p
;
5269 // Make a final decision about whether the symbol belongs in the
5270 // local or global GOT. Symbols that bind locally can (and in the
5271 // case of forced-local symbols, must) live in the local GOT.
5272 // Those that are aren't in the dynamic symbol table must also
5273 // live in the local GOT.
5275 if (!sym
->should_add_dynsym_entry(symtab
)
5276 || (sym
->got_only_for_calls()
5277 ? symbol_calls_local(sym
, sym
->should_add_dynsym_entry(symtab
))
5278 : symbol_references_local(sym
,
5279 sym
->should_add_dynsym_entry(symtab
))))
5280 // The symbol belongs in the local GOT. We no longer need this
5281 // entry if it was only used for relocations; those relocations
5282 // will be against the null or section symbol instead.
5283 sym
->set_global_got_area(GGA_NONE
);
5284 else if (sym
->global_got_area() == GGA_RELOC_ONLY
)
5286 ++this->reloc_only_gotno_
;
5287 ++this->global_gotno_
;
5292 // Return the offset of GOT page entry for VALUE. Initialize the entry with
5293 // VALUE if it is not initialized.
5295 template<int size
, bool big_endian
>
5297 Mips_got_info
<size
, big_endian
>::get_got_page_offset(Mips_address value
,
5298 Mips_output_data_got
<size
, big_endian
>* got
)
5300 typename
Got_page_offsets::iterator it
= this->got_page_offsets_
.find(value
);
5301 if (it
!= this->got_page_offsets_
.end())
5304 gold_assert(this->got_page_offset_next_
< this->got_page_offset_start_
5305 + (size
/8) * this->page_gotno_
);
5307 unsigned int got_offset
= this->got_page_offset_next_
;
5308 this->got_page_offsets_
[value
] = got_offset
;
5309 this->got_page_offset_next_
+= size
/8;
5310 got
->update_got_entry(got_offset
, value
);
5314 // Remove lazy-binding stubs for global symbols in this GOT.
5316 template<int size
, bool big_endian
>
5318 Mips_got_info
<size
, big_endian
>::remove_lazy_stubs(
5319 Target_mips
<size
, big_endian
>* target
)
5321 for (typename
Got_entry_set::iterator
5322 p
= this->got_entries_
.begin();
5323 p
!= this->got_entries_
.end();
5326 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5327 if (entry
->is_for_global_symbol())
5328 target
->remove_lazy_stub_entry(entry
->sym());
5332 // Count the number of GOT entries required.
5334 template<int size
, bool big_endian
>
5336 Mips_got_info
<size
, big_endian
>::count_got_entries()
5338 for (typename
Got_entry_set::iterator
5339 p
= this->got_entries_
.begin();
5340 p
!= this->got_entries_
.end();
5343 this->count_got_entry(*p
);
5347 // Count the number of GOT entries required by ENTRY. Accumulate the result.
5349 template<int size
, bool big_endian
>
5351 Mips_got_info
<size
, big_endian
>::count_got_entry(
5352 Mips_got_entry
<size
, big_endian
>* entry
)
5354 if (entry
->is_tls_entry())
5355 this->tls_gotno_
+= mips_tls_got_entries(entry
->tls_type());
5356 else if (entry
->is_for_local_symbol()
5357 || entry
->sym()->global_got_area() == GGA_NONE
)
5358 ++this->local_gotno_
;
5360 ++this->global_gotno_
;
5363 // Add FROM's GOT entries.
5365 template<int size
, bool big_endian
>
5367 Mips_got_info
<size
, big_endian
>::add_got_entries(
5368 Mips_got_info
<size
, big_endian
>* from
)
5370 for (typename
Got_entry_set::iterator
5371 p
= from
->got_entries_
.begin();
5372 p
!= from
->got_entries_
.end();
5375 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5376 if (this->got_entries_
.find(entry
) == this->got_entries_
.end())
5378 Mips_got_entry
<size
, big_endian
>* entry2
=
5379 new Mips_got_entry
<size
, big_endian
>(*entry
);
5380 this->got_entries_
.insert(entry2
);
5381 this->count_got_entry(entry
);
5386 // Add FROM's GOT page entries.
5388 template<int size
, bool big_endian
>
5390 Mips_got_info
<size
, big_endian
>::add_got_page_entries(
5391 Mips_got_info
<size
, big_endian
>* from
)
5393 for (typename
Got_page_entry_set::iterator
5394 p
= from
->got_page_entries_
.begin();
5395 p
!= from
->got_page_entries_
.end();
5398 Got_page_entry
* entry
= *p
;
5399 if (this->got_page_entries_
.find(entry
) == this->got_page_entries_
.end())
5401 Got_page_entry
* entry2
= new Got_page_entry(*entry
);
5402 this->got_page_entries_
.insert(entry2
);
5403 this->page_gotno_
+= entry
->num_pages
;
5408 // Mips_output_data_got methods.
5410 // Lay out the GOT. Add local, global and TLS entries. If GOT is
5411 // larger than 64K, create multi-GOT.
5413 template<int size
, bool big_endian
>
5415 Mips_output_data_got
<size
, big_endian
>::lay_out_got(Layout
* layout
,
5416 Symbol_table
* symtab
, const Input_objects
* input_objects
)
5418 // Decide which symbols need to go in the global part of the GOT and
5419 // count the number of reloc-only GOT symbols.
5420 this->master_got_info_
->count_got_symbols(symtab
);
5422 // Count the number of GOT entries.
5423 this->master_got_info_
->count_got_entries();
5425 unsigned int got_size
= this->master_got_info_
->got_size();
5426 if (got_size
> Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
)
5427 this->lay_out_multi_got(layout
, input_objects
);
5430 // Record that all objects use single GOT.
5431 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
5432 p
!= input_objects
->relobj_end();
5435 Mips_relobj
<size
, big_endian
>* object
=
5436 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
5437 if (object
->get_got_info() != NULL
)
5438 object
->set_got_info(this->master_got_info_
);
5441 this->master_got_info_
->add_local_entries(this->target_
, layout
);
5442 this->master_got_info_
->add_global_entries(this->target_
, layout
,
5444 this->master_got_info_
->add_tls_entries(this->target_
, layout
);
5448 // Create multi-GOT. For every GOT, add local, global and TLS entries.
5450 template<int size
, bool big_endian
>
5452 Mips_output_data_got
<size
, big_endian
>::lay_out_multi_got(Layout
* layout
,
5453 const Input_objects
* input_objects
)
5455 // Try to merge the GOTs of input objects together, as long as they
5456 // don't seem to exceed the maximum GOT size, choosing one of them
5457 // to be the primary GOT.
5458 this->merge_gots(input_objects
);
5460 // Every symbol that is referenced in a dynamic relocation must be
5461 // present in the primary GOT.
5462 this->primary_got_
->set_global_gotno(this->master_got_info_
->global_gotno());
5466 unsigned int offset
= 0;
5467 Mips_got_info
<size
, big_endian
>* g
= this->primary_got_
;
5471 g
->set_offset(offset
);
5473 g
->add_local_entries(this->target_
, layout
);
5475 g
->add_global_entries(this->target_
, layout
,
5476 (this->master_got_info_
->global_gotno()
5477 - this->master_got_info_
->reloc_only_gotno()));
5479 g
->add_global_entries(this->target_
, layout
, /*not used*/-1U);
5480 g
->add_tls_entries(this->target_
, layout
);
5482 // Forbid global symbols in every non-primary GOT from having
5483 // lazy-binding stubs.
5485 g
->remove_lazy_stubs(this->target_
);
5488 offset
+= g
->got_size();
5494 // Attempt to merge GOTs of different input objects. Try to use as much as
5495 // possible of the primary GOT, since it doesn't require explicit dynamic
5496 // relocations, but don't use objects that would reference global symbols
5497 // out of the addressable range. Failing the primary GOT, attempt to merge
5498 // with the current GOT, or finish the current GOT and then make make the new
5501 template<int size
, bool big_endian
>
5503 Mips_output_data_got
<size
, big_endian
>::merge_gots(
5504 const Input_objects
* input_objects
)
5506 gold_assert(this->primary_got_
== NULL
);
5507 Mips_got_info
<size
, big_endian
>* current
= NULL
;
5509 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
5510 p
!= input_objects
->relobj_end();
5513 Mips_relobj
<size
, big_endian
>* object
=
5514 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
5516 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
5520 g
->count_got_entries();
5522 // Work out the number of page, local and TLS entries.
5523 unsigned int estimate
= this->master_got_info_
->page_gotno();
5524 if (estimate
> g
->page_gotno())
5525 estimate
= g
->page_gotno();
5526 estimate
+= g
->local_gotno() + g
->tls_gotno();
5528 // We place TLS GOT entries after both locals and globals. The globals
5529 // for the primary GOT may overflow the normal GOT size limit, so be
5530 // sure not to merge a GOT which requires TLS with the primary GOT in that
5531 // case. This doesn't affect non-primary GOTs.
5532 estimate
+= (g
->tls_gotno() > 0 ? this->master_got_info_
->global_gotno()
5533 : g
->global_gotno());
5535 unsigned int max_count
=
5536 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
5537 if (estimate
<= max_count
)
5539 // If we don't have a primary GOT, use it as
5540 // a starting point for the primary GOT.
5541 if (!this->primary_got_
)
5543 this->primary_got_
= g
;
5547 // Try merging with the primary GOT.
5548 if (this->merge_got_with(g
, object
, this->primary_got_
))
5552 // If we can merge with the last-created GOT, do it.
5553 if (current
&& this->merge_got_with(g
, object
, current
))
5556 // Well, we couldn't merge, so create a new GOT. Don't check if it
5557 // fits; if it turns out that it doesn't, we'll get relocation
5558 // overflows anyway.
5559 g
->set_next(current
);
5563 // If we do not find any suitable primary GOT, create an empty one.
5564 if (this->primary_got_
== NULL
)
5565 this->primary_got_
= new Mips_got_info
<size
, big_endian
>();
5567 // Link primary GOT with secondary GOTs.
5568 this->primary_got_
->set_next(current
);
5571 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
5572 // this would lead to overflow, true if they were merged successfully.
5574 template<int size
, bool big_endian
>
5576 Mips_output_data_got
<size
, big_endian
>::merge_got_with(
5577 Mips_got_info
<size
, big_endian
>* from
,
5578 Mips_relobj
<size
, big_endian
>* object
,
5579 Mips_got_info
<size
, big_endian
>* to
)
5581 // Work out how many page entries we would need for the combined GOT.
5582 unsigned int estimate
= this->master_got_info_
->page_gotno();
5583 if (estimate
>= from
->page_gotno() + to
->page_gotno())
5584 estimate
= from
->page_gotno() + to
->page_gotno();
5586 // Conservatively estimate how many local and TLS entries would be needed.
5587 estimate
+= from
->local_gotno() + to
->local_gotno();
5588 estimate
+= from
->tls_gotno() + to
->tls_gotno();
5590 // If we're merging with the primary got, any TLS relocations will
5591 // come after the full set of global entries. Otherwise estimate those
5592 // conservatively as well.
5593 if (to
== this->primary_got_
&& (from
->tls_gotno() + to
->tls_gotno()) > 0)
5594 estimate
+= this->master_got_info_
->global_gotno();
5596 estimate
+= from
->global_gotno() + to
->global_gotno();
5598 // Bail out if the combined GOT might be too big.
5599 unsigned int max_count
=
5600 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
5601 if (estimate
> max_count
)
5604 // Transfer the object's GOT information from FROM to TO.
5605 to
->add_got_entries(from
);
5606 to
->add_got_page_entries(from
);
5608 // Record that OBJECT should use output GOT TO.
5609 object
->set_got_info(to
);
5614 // Write out the GOT.
5616 template<int size
, bool big_endian
>
5618 Mips_output_data_got
<size
, big_endian
>::do_write(Output_file
* of
)
5620 // Call parent to write out GOT.
5621 Output_data_got
<size
, big_endian
>::do_write(of
);
5623 const off_t offset
= this->offset();
5624 const section_size_type oview_size
=
5625 convert_to_section_size_type(this->data_size());
5626 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
5628 // Needed for fixing values of .got section.
5629 this->got_view_
= oview
;
5631 // Write lazy stub addresses.
5632 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
5633 p
= this->master_got_info_
->global_got_symbols().begin();
5634 p
!= this->master_got_info_
->global_got_symbols().end();
5637 Mips_symbol
<size
>* mips_sym
= *p
;
5638 if (mips_sym
->has_lazy_stub())
5640 Valtype
* wv
= reinterpret_cast<Valtype
*>(
5641 oview
+ this->get_primary_got_offset(mips_sym
));
5643 this->target_
->mips_stubs_section()->stub_address(mips_sym
);
5644 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
5648 // Add +1 to GGA_NONE nonzero MIPS16 and microMIPS entries.
5649 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
5650 p
= this->master_got_info_
->global_got_symbols().begin();
5651 p
!= this->master_got_info_
->global_got_symbols().end();
5654 Mips_symbol
<size
>* mips_sym
= *p
;
5655 if (!this->multi_got()
5656 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
5657 && mips_sym
->global_got_area() == GGA_NONE
5658 && mips_sym
->has_got_offset(GOT_TYPE_STANDARD
))
5660 Valtype
* wv
= reinterpret_cast<Valtype
*>(
5661 oview
+ mips_sym
->got_offset(GOT_TYPE_STANDARD
));
5662 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv
);
5666 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
5671 if (!this->secondary_got_relocs_
.empty())
5673 // Fixup for the secondary GOT R_MIPS_REL32 relocs. For global
5674 // secondary GOT entries with non-zero initial value copy the value
5675 // to the corresponding primary GOT entry, and set the secondary GOT
5677 // TODO(sasa): This is workaround. It needs to be investigated further.
5679 for (size_t i
= 0; i
< this->secondary_got_relocs_
.size(); ++i
)
5681 Static_reloc
& reloc(this->secondary_got_relocs_
[i
]);
5682 if (reloc
.symbol_is_global())
5684 Mips_symbol
<size
>* gsym
= reloc
.symbol();
5685 gold_assert(gsym
!= NULL
);
5687 unsigned got_offset
= reloc
.got_offset();
5688 gold_assert(got_offset
< oview_size
);
5690 // Find primary GOT entry.
5691 Valtype
* wv_prim
= reinterpret_cast<Valtype
*>(
5692 oview
+ this->get_primary_got_offset(gsym
));
5694 // Find secondary GOT entry.
5695 Valtype
* wv_sec
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
5697 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv_sec
);
5700 elfcpp::Swap
<size
, big_endian
>::writeval(wv_prim
, value
);
5701 elfcpp::Swap
<size
, big_endian
>::writeval(wv_sec
, 0);
5702 gsym
->set_applied_secondary_got_fixup();
5707 of
->write_output_view(offset
, oview_size
, oview
);
5710 // We are done if there is no fix up.
5711 if (this->static_relocs_
.empty())
5714 Output_segment
* tls_segment
= this->layout_
->tls_segment();
5715 gold_assert(tls_segment
!= NULL
);
5717 for (size_t i
= 0; i
< this->static_relocs_
.size(); ++i
)
5719 Static_reloc
& reloc(this->static_relocs_
[i
]);
5722 if (!reloc
.symbol_is_global())
5724 Sized_relobj_file
<size
, big_endian
>* object
= reloc
.relobj();
5725 const Symbol_value
<size
>* psymval
=
5726 object
->local_symbol(reloc
.index());
5728 // We are doing static linking. Issue an error and skip this
5729 // relocation if the symbol is undefined or in a discarded_section.
5731 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
5732 if ((shndx
== elfcpp::SHN_UNDEF
)
5734 && shndx
!= elfcpp::SHN_UNDEF
5735 && !object
->is_section_included(shndx
)
5736 && !this->symbol_table_
->is_section_folded(object
, shndx
)))
5738 gold_error(_("undefined or discarded local symbol %u from "
5739 " object %s in GOT"),
5740 reloc
.index(), reloc
.relobj()->name().c_str());
5744 value
= psymval
->value(object
, 0);
5748 const Mips_symbol
<size
>* gsym
= reloc
.symbol();
5749 gold_assert(gsym
!= NULL
);
5751 // We are doing static linking. Issue an error and skip this
5752 // relocation if the symbol is undefined or in a discarded_section
5753 // unless it is a weakly_undefined symbol.
5754 if ((gsym
->is_defined_in_discarded_section() || gsym
->is_undefined())
5755 && !gsym
->is_weak_undefined())
5757 gold_error(_("undefined or discarded symbol %s in GOT"),
5762 if (!gsym
->is_weak_undefined())
5763 value
= gsym
->value();
5768 unsigned got_offset
= reloc
.got_offset();
5769 gold_assert(got_offset
< oview_size
);
5771 Valtype
* wv
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
5774 switch (reloc
.r_type())
5776 case elfcpp::R_MIPS_TLS_DTPMOD32
:
5777 case elfcpp::R_MIPS_TLS_DTPMOD64
:
5780 case elfcpp::R_MIPS_TLS_DTPREL32
:
5781 case elfcpp::R_MIPS_TLS_DTPREL64
:
5782 x
= value
- elfcpp::DTP_OFFSET
;
5784 case elfcpp::R_MIPS_TLS_TPREL32
:
5785 case elfcpp::R_MIPS_TLS_TPREL64
:
5786 x
= value
- elfcpp::TP_OFFSET
;
5793 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, x
);
5796 of
->write_output_view(offset
, oview_size
, oview
);
5799 // Mips_relobj methods.
5801 // Count the local symbols. The Mips backend needs to know if a symbol
5802 // is a MIPS16 or microMIPS function or not. For global symbols, it is easy
5803 // because the Symbol object keeps the ELF symbol type and st_other field.
5804 // For local symbol it is harder because we cannot access this information.
5805 // So we override the do_count_local_symbol in parent and scan local symbols to
5806 // mark MIPS16 and microMIPS functions. This is not the most efficient way but
5807 // I do not want to slow down other ports by calling a per symbol target hook
5808 // inside Sized_relobj_file<size, big_endian>::do_count_local_symbols.
5810 template<int size
, bool big_endian
>
5812 Mips_relobj
<size
, big_endian
>::do_count_local_symbols(
5813 Stringpool_template
<char>* pool
,
5814 Stringpool_template
<char>* dynpool
)
5816 // Ask parent to count the local symbols.
5817 Sized_relobj_file
<size
, big_endian
>::do_count_local_symbols(pool
, dynpool
);
5818 const unsigned int loccount
= this->local_symbol_count();
5822 // Initialize the mips16 and micromips function bit-vector.
5823 this->local_symbol_is_mips16_
.resize(loccount
, false);
5824 this->local_symbol_is_micromips_
.resize(loccount
, false);
5826 // Read the symbol table section header.
5827 const unsigned int symtab_shndx
= this->symtab_shndx();
5828 elfcpp::Shdr
<size
, big_endian
>
5829 symtabshdr(this, this->elf_file()->section_header(symtab_shndx
));
5830 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
5832 // Read the local symbols.
5833 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
5834 gold_assert(loccount
== symtabshdr
.get_sh_info());
5835 off_t locsize
= loccount
* sym_size
;
5836 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
5837 locsize
, true, true);
5839 // Loop over the local symbols and mark any MIPS16 or microMIPS local symbols.
5841 // Skip the first dummy symbol.
5843 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
5845 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
5846 unsigned char st_other
= sym
.get_st_other();
5847 this->local_symbol_is_mips16_
[i
] = elfcpp::elf_st_is_mips16(st_other
);
5848 this->local_symbol_is_micromips_
[i
] =
5849 elfcpp::elf_st_is_micromips(st_other
);
5853 // Read the symbol information.
5855 template<int size
, bool big_endian
>
5857 Mips_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
5859 // Call parent class to read symbol information.
5860 this->base_read_symbols(sd
);
5862 // Read processor-specific flags in ELF file header.
5863 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
5864 elfcpp::Elf_sizes
<size
>::ehdr_size
,
5866 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
5867 this->processor_specific_flags_
= ehdr
.get_e_flags();
5869 // Get the section names.
5870 const unsigned char* pnamesu
= sd
->section_names
->data();
5871 const char* pnames
= reinterpret_cast<const char*>(pnamesu
);
5873 // Initialize the mips16 stub section bit-vectors.
5874 this->section_is_mips16_fn_stub_
.resize(this->shnum(), false);
5875 this->section_is_mips16_call_stub_
.resize(this->shnum(), false);
5876 this->section_is_mips16_call_fp_stub_
.resize(this->shnum(), false);
5878 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
5879 const unsigned char* pshdrs
= sd
->section_headers
->data();
5880 const unsigned char* ps
= pshdrs
+ shdr_size
;
5881 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
5883 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
5885 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_REGINFO
)
5887 // Read the gp value that was used to create this object. We need the
5888 // gp value while processing relocs. The .reginfo section is not used
5889 // in the 64-bit MIPS ELF ABI.
5890 section_offset_type section_offset
= shdr
.get_sh_offset();
5891 section_size_type section_size
=
5892 convert_to_section_size_type(shdr
.get_sh_size());
5893 const unsigned char* view
=
5894 this->get_view(section_offset
, section_size
, true, false);
5896 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 20);
5898 // Read the rest of .reginfo.
5899 this->gprmask_
= elfcpp::Swap
<size
, big_endian
>::readval(view
);
5900 this->cprmask1_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 4);
5901 this->cprmask2_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 8);
5902 this->cprmask3_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 12);
5903 this->cprmask4_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 16);
5906 const char* name
= pnames
+ shdr
.get_sh_name();
5907 this->section_is_mips16_fn_stub_
[i
] = is_prefix_of(".mips16.fn", name
);
5908 this->section_is_mips16_call_stub_
[i
] =
5909 is_prefix_of(".mips16.call.", name
);
5910 this->section_is_mips16_call_fp_stub_
[i
] =
5911 is_prefix_of(".mips16.call.fp.", name
);
5913 if (strcmp(name
, ".pdr") == 0)
5915 gold_assert(this->pdr_shndx_
== -1U);
5916 this->pdr_shndx_
= i
;
5921 // Discard MIPS16 stub secions that are not needed.
5923 template<int size
, bool big_endian
>
5925 Mips_relobj
<size
, big_endian
>::discard_mips16_stub_sections(Symbol_table
* symtab
)
5927 for (typename
Mips16_stubs_int_map::const_iterator
5928 it
= this->mips16_stub_sections_
.begin();
5929 it
!= this->mips16_stub_sections_
.end(); ++it
)
5931 Mips16_stub_section
<size
, big_endian
>* stub_section
= it
->second
;
5932 if (!stub_section
->is_target_found())
5934 gold_error(_("no relocation found in mips16 stub section '%s'"),
5935 stub_section
->object()
5936 ->section_name(stub_section
->shndx()).c_str());
5939 bool discard
= false;
5940 if (stub_section
->is_for_local_function())
5942 if (stub_section
->is_fn_stub())
5944 // This stub is for a local symbol. This stub will only
5945 // be needed if there is some relocation in this object,
5946 // other than a 16 bit function call, which refers to this
5948 if (!this->has_local_non_16bit_call_relocs(stub_section
->r_sym()))
5951 this->add_local_mips16_fn_stub(stub_section
);
5955 // This stub is for a local symbol. This stub will only
5956 // be needed if there is some relocation (R_MIPS16_26) in
5957 // this object that refers to this symbol.
5958 gold_assert(stub_section
->is_call_stub()
5959 || stub_section
->is_call_fp_stub());
5960 if (!this->has_local_16bit_call_relocs(stub_section
->r_sym()))
5963 this->add_local_mips16_call_stub(stub_section
);
5968 Mips_symbol
<size
>* gsym
= stub_section
->gsym();
5969 if (stub_section
->is_fn_stub())
5971 if (gsym
->has_mips16_fn_stub())
5972 // We already have a stub for this function.
5976 gsym
->set_mips16_fn_stub(stub_section
);
5977 if (gsym
->should_add_dynsym_entry(symtab
))
5979 // If we have a MIPS16 function with a stub, the
5980 // dynamic symbol must refer to the stub, since only
5981 // the stub uses the standard calling conventions.
5982 gsym
->set_need_fn_stub();
5983 if (gsym
->is_from_dynobj())
5984 gsym
->set_needs_dynsym_value();
5987 if (!gsym
->need_fn_stub())
5990 else if (stub_section
->is_call_stub())
5992 if (gsym
->is_mips16())
5993 // We don't need the call_stub; this is a 16 bit
5994 // function, so calls from other 16 bit functions are
5997 else if (gsym
->has_mips16_call_stub())
5998 // We already have a stub for this function.
6001 gsym
->set_mips16_call_stub(stub_section
);
6005 gold_assert(stub_section
->is_call_fp_stub());
6006 if (gsym
->is_mips16())
6007 // We don't need the call_stub; this is a 16 bit
6008 // function, so calls from other 16 bit functions are
6011 else if (gsym
->has_mips16_call_fp_stub())
6012 // We already have a stub for this function.
6015 gsym
->set_mips16_call_fp_stub(stub_section
);
6019 this->set_output_section(stub_section
->shndx(), NULL
);
6023 // Mips_output_data_la25_stub methods.
6025 // Template for standard LA25 stub.
6026 template<int size
, bool big_endian
>
6028 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_entry
[] =
6030 0x3c190000, // lui $25,%hi(func)
6031 0x08000000, // j func
6032 0x27390000, // add $25,$25,%lo(func)
6036 // Template for microMIPS LA25 stub.
6037 template<int size
, bool big_endian
>
6039 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_micromips_entry
[] =
6041 0x41b9, 0x0000, // lui t9,%hi(func)
6042 0xd400, 0x0000, // j func
6043 0x3339, 0x0000, // addiu t9,t9,%lo(func)
6044 0x0000, 0x0000 // nop
6047 // Create la25 stub for a symbol.
6049 template<int size
, bool big_endian
>
6051 Mips_output_data_la25_stub
<size
, big_endian
>::create_la25_stub(
6052 Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
6053 Mips_symbol
<size
>* gsym
)
6055 if (!gsym
->has_la25_stub())
6057 gsym
->set_la25_stub_offset(this->symbols_
.size() * 16);
6058 this->symbols_
.insert(gsym
);
6059 this->create_stub_symbol(gsym
, symtab
, target
, 16);
6063 // Create a symbol for SYM stub's value and size, to help make the disassembly
6066 template<int size
, bool big_endian
>
6068 Mips_output_data_la25_stub
<size
, big_endian
>::create_stub_symbol(
6069 Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
6070 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
)
6072 std::string
name(".pic.");
6073 name
+= sym
->name();
6075 unsigned int offset
= sym
->la25_stub_offset();
6076 if (sym
->is_micromips())
6079 // Make it a local function.
6080 Symbol
* new_sym
= symtab
->define_in_output_data(name
.c_str(), NULL
,
6081 Symbol_table::PREDEFINED
,
6082 target
->la25_stub_section(),
6083 offset
, symsize
, elfcpp::STT_FUNC
,
6085 elfcpp::STV_DEFAULT
, 0,
6087 new_sym
->set_is_forced_local();
6090 // Write out la25 stubs. This uses the hand-coded instructions above,
6091 // and adjusts them as needed.
6093 template<int size
, bool big_endian
>
6095 Mips_output_data_la25_stub
<size
, big_endian
>::do_write(Output_file
* of
)
6097 const off_t offset
= this->offset();
6098 const section_size_type oview_size
=
6099 convert_to_section_size_type(this->data_size());
6100 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6102 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
6103 p
= this->symbols_
.begin();
6104 p
!= this->symbols_
.end();
6107 Mips_symbol
<size
>* sym
= *p
;
6108 unsigned char* pov
= oview
+ sym
->la25_stub_offset();
6110 Mips_address target
= sym
->value();
6111 if (!sym
->is_micromips())
6113 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
6114 la25_stub_entry
[0] | (((target
+ 0x8000) >> 16) & 0xffff));
6115 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
6116 la25_stub_entry
[1] | ((target
>> 2) & 0x3ffffff));
6117 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
6118 la25_stub_entry
[2] | (target
& 0xffff));
6119 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12, la25_stub_entry
[3]);
6124 // First stub instruction. Paste high 16-bits of the target.
6125 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
6126 la25_stub_micromips_entry
[0]);
6127 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
6128 ((target
+ 0x8000) >> 16) & 0xffff);
6129 // Second stub instruction. Paste low 26-bits of the target, shifted
6131 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
6132 la25_stub_micromips_entry
[2] | ((target
>> 17) & 0x3ff));
6133 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
6134 la25_stub_micromips_entry
[3] | ((target
>> 1) & 0xffff));
6135 // Third stub instruction. Paste low 16-bits of the target.
6136 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8,
6137 la25_stub_micromips_entry
[4]);
6138 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, target
& 0xffff);
6139 // Fourth stub instruction.
6140 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 12,
6141 la25_stub_micromips_entry
[6]);
6142 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 14,
6143 la25_stub_micromips_entry
[7]);
6147 of
->write_output_view(offset
, oview_size
, oview
);
6150 // Mips_output_data_plt methods.
6152 // The format of the first PLT entry in an O32 executable.
6153 template<int size
, bool big_endian
>
6154 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_o32
[] =
6156 0x3c1c0000, // lui $28, %hi(&GOTPLT[0])
6157 0x8f990000, // lw $25, %lo(&GOTPLT[0])($28)
6158 0x279c0000, // addiu $28, $28, %lo(&GOTPLT[0])
6159 0x031cc023, // subu $24, $24, $28
6160 0x03e07821, // move $15, $31 # 32-bit move (addu)
6161 0x0018c082, // srl $24, $24, 2
6162 0x0320f809, // jalr $25
6163 0x2718fffe // subu $24, $24, 2
6166 // The format of the first PLT entry in an N32 executable. Different
6167 // because gp ($28) is not available; we use t2 ($14) instead.
6168 template<int size
, bool big_endian
>
6169 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n32
[] =
6171 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
6172 0x8dd90000, // lw $25, %lo(&GOTPLT[0])($14)
6173 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
6174 0x030ec023, // subu $24, $24, $14
6175 0x03e07821, // move $15, $31 # 32-bit move (addu)
6176 0x0018c082, // srl $24, $24, 2
6177 0x0320f809, // jalr $25
6178 0x2718fffe // subu $24, $24, 2
6181 // The format of the first PLT entry in an N64 executable. Different
6182 // from N32 because of the increased size of GOT entries.
6183 template<int size
, bool big_endian
>
6184 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n64
[] =
6186 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
6187 0xddd90000, // ld $25, %lo(&GOTPLT[0])($14)
6188 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
6189 0x030ec023, // subu $24, $24, $14
6190 0x03e07821, // move $15, $31 # 64-bit move (daddu)
6191 0x0018c0c2, // srl $24, $24, 3
6192 0x0320f809, // jalr $25
6193 0x2718fffe // subu $24, $24, 2
6196 // The format of the microMIPS first PLT entry in an O32 executable.
6197 // We rely on v0 ($2) rather than t8 ($24) to contain the address
6198 // of the GOTPLT entry handled, so this stub may only be used when
6199 // all the subsequent PLT entries are microMIPS code too.
6201 // The trailing NOP is for alignment and correct disassembly only.
6202 template<int size
, bool big_endian
>
6203 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6204 plt0_entry_micromips_o32
[] =
6206 0x7980, 0x0000, // addiupc $3, (&GOTPLT[0]) - .
6207 0xff23, 0x0000, // lw $25, 0($3)
6208 0x0535, // subu $2, $2, $3
6209 0x2525, // srl $2, $2, 2
6210 0x3302, 0xfffe, // subu $24, $2, 2
6211 0x0dff, // move $15, $31
6212 0x45f9, // jalrs $25
6213 0x0f83, // move $28, $3
6217 // The format of the microMIPS first PLT entry in an O32 executable
6218 // in the insn32 mode.
6219 template<int size
, bool big_endian
>
6220 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6221 plt0_entry_micromips32_o32
[] =
6223 0x41bc, 0x0000, // lui $28, %hi(&GOTPLT[0])
6224 0xff3c, 0x0000, // lw $25, %lo(&GOTPLT[0])($28)
6225 0x339c, 0x0000, // addiu $28, $28, %lo(&GOTPLT[0])
6226 0x0398, 0xc1d0, // subu $24, $24, $28
6227 0x001f, 0x7950, // move $15, $31
6228 0x0318, 0x1040, // srl $24, $24, 2
6229 0x03f9, 0x0f3c, // jalr $25
6230 0x3318, 0xfffe // subu $24, $24, 2
6233 // The format of subsequent standard entries in the PLT.
6234 template<int size
, bool big_endian
>
6235 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry
[] =
6237 0x3c0f0000, // lui $15, %hi(.got.plt entry)
6238 0x8df90000, // l[wd] $25, %lo(.got.plt entry)($15)
6239 0x03200008, // jr $25
6240 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
6243 // The format of subsequent MIPS16 o32 PLT entries. We use v1 ($3) as a
6244 // temporary because t8 ($24) and t9 ($25) are not directly addressable.
6245 // Note that this differs from the GNU ld which uses both v0 ($2) and v1 ($3).
6246 // We cannot use v0 because MIPS16 call stubs from the CS toolchain expect
6247 // target function address in register v0.
6248 template<int size
, bool big_endian
>
6249 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry_mips16_o32
[] =
6251 0xb303, // lw $3, 12($pc)
6252 0x651b, // move $24, $3
6253 0x9b60, // lw $3, 0($3)
6255 0x653b, // move $25, $3
6257 0x0000, 0x0000 // .word (.got.plt entry)
6260 // The format of subsequent microMIPS o32 PLT entries. We use v0 ($2)
6261 // as a temporary because t8 ($24) is not addressable with ADDIUPC.
6262 template<int size
, bool big_endian
>
6263 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6264 plt_entry_micromips_o32
[] =
6266 0x7900, 0x0000, // addiupc $2, (.got.plt entry) - .
6267 0xff22, 0x0000, // lw $25, 0($2)
6269 0x0f02 // move $24, $2
6272 // The format of subsequent microMIPS o32 PLT entries in the insn32 mode.
6273 template<int size
, bool big_endian
>
6274 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6275 plt_entry_micromips32_o32
[] =
6277 0x41af, 0x0000, // lui $15, %hi(.got.plt entry)
6278 0xff2f, 0x0000, // lw $25, %lo(.got.plt entry)($15)
6279 0x0019, 0x0f3c, // jr $25
6280 0x330f, 0x0000 // addiu $24, $15, %lo(.got.plt entry)
6283 // Add an entry to the PLT for a symbol referenced by r_type relocation.
6285 template<int size
, bool big_endian
>
6287 Mips_output_data_plt
<size
, big_endian
>::add_entry(Mips_symbol
<size
>* gsym
,
6288 unsigned int r_type
)
6290 gold_assert(!gsym
->has_plt_offset());
6292 // Final PLT offset for a symbol will be set in method set_plt_offsets().
6293 gsym
->set_plt_offset(this->entry_count() * sizeof(plt_entry
)
6294 + sizeof(plt0_entry_o32
));
6295 this->symbols_
.push_back(gsym
);
6297 // Record whether the relocation requires a standard MIPS
6298 // or a compressed code entry.
6299 if (jal_reloc(r_type
))
6301 if (r_type
== elfcpp::R_MIPS_26
)
6302 gsym
->set_needs_mips_plt(true);
6304 gsym
->set_needs_comp_plt(true);
6307 section_offset_type got_offset
= this->got_plt_
->current_data_size();
6309 // Every PLT entry needs a GOT entry which points back to the PLT
6310 // entry (this will be changed by the dynamic linker, normally
6311 // lazily when the function is called).
6312 this->got_plt_
->set_current_data_size(got_offset
+ size
/8);
6314 gsym
->set_needs_dynsym_entry();
6315 this->rel_
->add_global(gsym
, elfcpp::R_MIPS_JUMP_SLOT
, this->got_plt_
,
6319 // Set final PLT offsets. For each symbol, determine whether standard or
6320 // compressed (MIPS16 or microMIPS) PLT entry is used.
6322 template<int size
, bool big_endian
>
6324 Mips_output_data_plt
<size
, big_endian
>::set_plt_offsets()
6326 // The sizes of individual PLT entries.
6327 unsigned int plt_mips_entry_size
= this->standard_plt_entry_size();
6328 unsigned int plt_comp_entry_size
= (!this->target_
->is_output_newabi()
6329 ? this->compressed_plt_entry_size() : 0);
6331 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
6332 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
6334 Mips_symbol
<size
>* mips_sym
= *p
;
6336 // There are no defined MIPS16 or microMIPS PLT entries for n32 or n64,
6337 // so always use a standard entry there.
6339 // If the symbol has a MIPS16 call stub and gets a PLT entry, then
6340 // all MIPS16 calls will go via that stub, and there is no benefit
6341 // to having a MIPS16 entry. And in the case of call_stub a
6342 // standard entry actually has to be used as the stub ends with a J
6344 if (this->target_
->is_output_newabi()
6345 || mips_sym
->has_mips16_call_stub()
6346 || mips_sym
->has_mips16_call_fp_stub())
6348 mips_sym
->set_needs_mips_plt(true);
6349 mips_sym
->set_needs_comp_plt(false);
6352 // Otherwise, if there are no direct calls to the function, we
6353 // have a free choice of whether to use standard or compressed
6354 // entries. Prefer microMIPS entries if the object is known to
6355 // contain microMIPS code, so that it becomes possible to create
6356 // pure microMIPS binaries. Prefer standard entries otherwise,
6357 // because MIPS16 ones are no smaller and are usually slower.
6358 if (!mips_sym
->needs_mips_plt() && !mips_sym
->needs_comp_plt())
6360 if (this->target_
->is_output_micromips())
6361 mips_sym
->set_needs_comp_plt(true);
6363 mips_sym
->set_needs_mips_plt(true);
6366 if (mips_sym
->needs_mips_plt())
6368 mips_sym
->set_mips_plt_offset(this->plt_mips_offset_
);
6369 this->plt_mips_offset_
+= plt_mips_entry_size
;
6371 if (mips_sym
->needs_comp_plt())
6373 mips_sym
->set_comp_plt_offset(this->plt_comp_offset_
);
6374 this->plt_comp_offset_
+= plt_comp_entry_size
;
6378 // Figure out the size of the PLT header if we know that we are using it.
6379 if (this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0)
6380 this->plt_header_size_
= this->get_plt_header_size();
6383 // Write out the PLT. This uses the hand-coded instructions above,
6384 // and adjusts them as needed.
6386 template<int size
, bool big_endian
>
6388 Mips_output_data_plt
<size
, big_endian
>::do_write(Output_file
* of
)
6390 const off_t offset
= this->offset();
6391 const section_size_type oview_size
=
6392 convert_to_section_size_type(this->data_size());
6393 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6395 const off_t gotplt_file_offset
= this->got_plt_
->offset();
6396 const section_size_type gotplt_size
=
6397 convert_to_section_size_type(this->got_plt_
->data_size());
6398 unsigned char* const gotplt_view
= of
->get_output_view(gotplt_file_offset
,
6400 unsigned char* pov
= oview
;
6402 Mips_address plt_address
= this->address();
6404 // Calculate the address of .got.plt.
6405 Mips_address gotplt_addr
= this->got_plt_
->address();
6406 Mips_address gotplt_addr_high
= ((gotplt_addr
+ 0x8000) >> 16) & 0xffff;
6407 Mips_address gotplt_addr_low
= gotplt_addr
& 0xffff;
6409 // The PLT sequence is not safe for N64 if .got.plt's address can
6410 // not be loaded in two instructions.
6411 gold_assert((gotplt_addr
& ~(Mips_address
) 0x7fffffff) == 0
6412 || ~(gotplt_addr
| 0x7fffffff) == 0);
6414 // Write the PLT header.
6415 const uint32_t* plt0_entry
= this->get_plt_header_entry();
6416 if (plt0_entry
== plt0_entry_micromips_o32
)
6418 // Write microMIPS PLT header.
6419 gold_assert(gotplt_addr
% 4 == 0);
6421 Mips_address gotpc_offset
= gotplt_addr
- ((plt_address
| 3) ^ 3);
6423 // ADDIUPC has a span of +/-16MB, check we're in range.
6424 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
6426 gold_error(_(".got.plt offset of %ld from .plt beyond the range of "
6427 "ADDIUPC"), (long)gotpc_offset
);
6431 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
6432 plt0_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
6433 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
6434 (gotpc_offset
>> 2) & 0xffff);
6436 for (unsigned int i
= 2;
6437 i
< (sizeof(plt0_entry_micromips_o32
)
6438 / sizeof(plt0_entry_micromips_o32
[0]));
6441 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
6445 else if (plt0_entry
== plt0_entry_micromips32_o32
)
6447 // Write microMIPS PLT header in insn32 mode.
6448 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[0]);
6449 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, gotplt_addr_high
);
6450 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, plt0_entry
[2]);
6451 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, gotplt_addr_low
);
6452 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8, plt0_entry
[4]);
6453 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, gotplt_addr_low
);
6455 for (unsigned int i
= 6;
6456 i
< (sizeof(plt0_entry_micromips32_o32
)
6457 / sizeof(plt0_entry_micromips32_o32
[0]));
6460 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
6466 // Write standard PLT header.
6467 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
6468 plt0_entry
[0] | gotplt_addr_high
);
6469 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
6470 plt0_entry
[1] | gotplt_addr_low
);
6471 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
6472 plt0_entry
[2] | gotplt_addr_low
);
6474 for (int i
= 3; i
< 8; i
++)
6476 elfcpp::Swap
<32, big_endian
>::writeval(pov
, plt0_entry
[i
]);
6482 unsigned char* gotplt_pov
= gotplt_view
;
6483 unsigned int got_entry_size
= size
/8; // TODO(sasa): MIPS_ELF_GOT_SIZE
6485 // The first two entries in .got.plt are reserved.
6486 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
, 0);
6487 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
+ got_entry_size
, 0);
6489 unsigned int gotplt_offset
= 2 * got_entry_size
;
6490 gotplt_pov
+= 2 * got_entry_size
;
6492 // Calculate the address of the PLT header.
6493 Mips_address header_address
= (plt_address
6494 + (this->is_plt_header_compressed() ? 1 : 0));
6496 // Initialize compressed PLT area view.
6497 unsigned char* pov2
= pov
+ this->plt_mips_offset_
;
6499 // Write the PLT entries.
6500 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
6501 p
= this->symbols_
.begin();
6502 p
!= this->symbols_
.end();
6503 ++p
, gotplt_pov
+= got_entry_size
, gotplt_offset
+= got_entry_size
)
6505 Mips_symbol
<size
>* mips_sym
= *p
;
6507 // Calculate the address of the .got.plt entry.
6508 uint32_t gotplt_entry_addr
= (gotplt_addr
+ gotplt_offset
);
6509 uint32_t gotplt_entry_addr_hi
= (((gotplt_entry_addr
+ 0x8000) >> 16)
6511 uint32_t gotplt_entry_addr_lo
= gotplt_entry_addr
& 0xffff;
6513 // Initially point the .got.plt entry at the PLT header.
6514 if (this->target_
->is_output_n64())
6515 elfcpp::Swap
<64, big_endian
>::writeval(gotplt_pov
, header_address
);
6517 elfcpp::Swap
<32, big_endian
>::writeval(gotplt_pov
, header_address
);
6519 // Now handle the PLT itself. First the standard entry.
6520 if (mips_sym
->has_mips_plt_offset())
6522 // Pick the load opcode (LW or LD).
6523 uint64_t load
= this->target_
->is_output_n64() ? 0xdc000000
6526 // Fill in the PLT entry itself.
6527 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
6528 plt_entry
[0] | gotplt_entry_addr_hi
);
6529 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
6530 plt_entry
[1] | gotplt_entry_addr_lo
| load
);
6531 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8, plt_entry
[2]);
6532 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12,
6533 plt_entry
[3] | gotplt_entry_addr_lo
);
6537 // Now the compressed entry. They come after any standard ones.
6538 if (mips_sym
->has_comp_plt_offset())
6540 if (!this->target_
->is_output_micromips())
6542 // Write MIPS16 PLT entry.
6543 const uint32_t* plt_entry
= plt_entry_mips16_o32
;
6545 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
6546 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2, plt_entry
[1]);
6547 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
6548 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
6549 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
6550 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
6551 elfcpp::Swap
<32, big_endian
>::writeval(pov2
+ 12,
6555 else if (this->target_
->use_32bit_micromips_instructions())
6557 // Write microMIPS PLT entry in insn32 mode.
6558 const uint32_t* plt_entry
= plt_entry_micromips32_o32
;
6560 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
6561 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2,
6562 gotplt_entry_addr_hi
);
6563 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
6564 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6,
6565 gotplt_entry_addr_lo
);
6566 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
6567 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
6568 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 12, plt_entry
[6]);
6569 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 14,
6570 gotplt_entry_addr_lo
);
6575 // Write microMIPS PLT entry.
6576 const uint32_t* plt_entry
= plt_entry_micromips_o32
;
6578 gold_assert(gotplt_entry_addr
% 4 == 0);
6580 Mips_address loc_address
= plt_address
+ pov2
- oview
;
6581 int gotpc_offset
= gotplt_entry_addr
- ((loc_address
| 3) ^ 3);
6583 // ADDIUPC has a span of +/-16MB, check we're in range.
6584 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
6586 gold_error(_(".got.plt offset of %ld from .plt beyond the "
6587 "range of ADDIUPC"), (long)gotpc_offset
);
6591 elfcpp::Swap
<16, big_endian
>::writeval(pov2
,
6592 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
6593 elfcpp::Swap
<16, big_endian
>::writeval(
6594 pov2
+ 2, (gotpc_offset
>> 2) & 0xffff);
6595 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
6596 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
6597 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
6598 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
6604 // Check the number of bytes written for standard entries.
6605 gold_assert(static_cast<section_size_type
>(
6606 pov
- oview
- this->plt_header_size_
) == this->plt_mips_offset_
);
6607 // Check the number of bytes written for compressed entries.
6608 gold_assert((static_cast<section_size_type
>(pov2
- pov
)
6609 == this->plt_comp_offset_
));
6610 // Check the total number of bytes written.
6611 gold_assert(static_cast<section_size_type
>(pov2
- oview
) == oview_size
);
6613 gold_assert(static_cast<section_size_type
>(gotplt_pov
- gotplt_view
)
6616 of
->write_output_view(offset
, oview_size
, oview
);
6617 of
->write_output_view(gotplt_file_offset
, gotplt_size
, gotplt_view
);
6620 // Mips_output_data_mips_stubs methods.
6622 // The format of the lazy binding stub when dynamic symbol count is less than
6623 // 64K, dynamic symbol index is less than 32K, and ABI is not N64.
6624 template<int size
, bool big_endian
>
6626 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1
[4] =
6628 0x8f998010, // lw t9,0x8010(gp)
6629 0x03e07821, // addu t7,ra,zero
6630 0x0320f809, // jalr t9,ra
6631 0x24180000 // addiu t8,zero,DYN_INDEX sign extended
6634 // The format of the lazy binding stub when dynamic symbol count is less than
6635 // 64K, dynamic symbol index is less than 32K, and ABI is N64.
6636 template<int size
, bool big_endian
>
6638 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1_n64
[4] =
6640 0xdf998010, // ld t9,0x8010(gp)
6641 0x03e0782d, // daddu t7,ra,zero
6642 0x0320f809, // jalr t9,ra
6643 0x64180000 // daddiu t8,zero,DYN_INDEX sign extended
6646 // The format of the lazy binding stub when dynamic symbol count is less than
6647 // 64K, dynamic symbol index is between 32K and 64K, and ABI is not N64.
6648 template<int size
, bool big_endian
>
6650 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2
[4] =
6652 0x8f998010, // lw t9,0x8010(gp)
6653 0x03e07821, // addu t7,ra,zero
6654 0x0320f809, // jalr t9,ra
6655 0x34180000 // ori t8,zero,DYN_INDEX unsigned
6658 // The format of the lazy binding stub when dynamic symbol count is less than
6659 // 64K, dynamic symbol index is between 32K and 64K, and ABI is N64.
6660 template<int size
, bool big_endian
>
6662 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2_n64
[4] =
6664 0xdf998010, // ld t9,0x8010(gp)
6665 0x03e0782d, // daddu t7,ra,zero
6666 0x0320f809, // jalr t9,ra
6667 0x34180000 // ori t8,zero,DYN_INDEX unsigned
6670 // The format of the lazy binding stub when dynamic symbol count is greater than
6671 // 64K, and ABI is not N64.
6672 template<int size
, bool big_endian
>
6673 const uint32_t Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big
[5] =
6675 0x8f998010, // lw t9,0x8010(gp)
6676 0x03e07821, // addu t7,ra,zero
6677 0x3c180000, // lui t8,DYN_INDEX
6678 0x0320f809, // jalr t9,ra
6679 0x37180000 // ori t8,t8,DYN_INDEX
6682 // The format of the lazy binding stub when dynamic symbol count is greater than
6683 // 64K, and ABI is N64.
6684 template<int size
, bool big_endian
>
6686 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big_n64
[5] =
6688 0xdf998010, // ld t9,0x8010(gp)
6689 0x03e0782d, // daddu t7,ra,zero
6690 0x3c180000, // lui t8,DYN_INDEX
6691 0x0320f809, // jalr t9,ra
6692 0x37180000 // ori t8,t8,DYN_INDEX
6697 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6698 // less than 64K, dynamic symbol index is less than 32K, and ABI is not N64.
6699 template<int size
, bool big_endian
>
6701 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_1
[] =
6703 0xff3c, 0x8010, // lw t9,0x8010(gp)
6704 0x0dff, // move t7,ra
6706 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
6709 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6710 // less than 64K, dynamic symbol index is less than 32K, and ABI is N64.
6711 template<int size
, bool big_endian
>
6713 Mips_output_data_mips_stubs
<size
, big_endian
>::
6714 lazy_stub_micromips_normal_1_n64
[] =
6716 0xdf3c, 0x8010, // ld t9,0x8010(gp)
6717 0x0dff, // move t7,ra
6719 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
6722 // The format of the microMIPS lazy binding stub when dynamic symbol
6723 // count is less than 64K, dynamic symbol index is between 32K and 64K,
6724 // and ABI is not N64.
6725 template<int size
, bool big_endian
>
6727 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_2
[] =
6729 0xff3c, 0x8010, // lw t9,0x8010(gp)
6730 0x0dff, // move t7,ra
6732 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
6735 // The format of the microMIPS lazy binding stub when dynamic symbol
6736 // count is less than 64K, dynamic symbol index is between 32K and 64K,
6738 template<int size
, bool big_endian
>
6740 Mips_output_data_mips_stubs
<size
, big_endian
>::
6741 lazy_stub_micromips_normal_2_n64
[] =
6743 0xdf3c, 0x8010, // ld t9,0x8010(gp)
6744 0x0dff, // move t7,ra
6746 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
6749 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6750 // greater than 64K, and ABI is not N64.
6751 template<int size
, bool big_endian
>
6753 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big
[] =
6755 0xff3c, 0x8010, // lw t9,0x8010(gp)
6756 0x0dff, // move t7,ra
6757 0x41b8, 0x0000, // lui t8,DYN_INDEX
6759 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
6762 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6763 // greater than 64K, and ABI is N64.
6764 template<int size
, bool big_endian
>
6766 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big_n64
[] =
6768 0xdf3c, 0x8010, // ld t9,0x8010(gp)
6769 0x0dff, // move t7,ra
6770 0x41b8, 0x0000, // lui t8,DYN_INDEX
6772 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
6775 // 32-bit microMIPS stubs.
6777 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6778 // less than 64K, dynamic symbol index is less than 32K, ABI is not N64, and we
6779 // can use only 32-bit instructions.
6780 template<int size
, bool big_endian
>
6782 Mips_output_data_mips_stubs
<size
, big_endian
>::
6783 lazy_stub_micromips32_normal_1
[] =
6785 0xff3c, 0x8010, // lw t9,0x8010(gp)
6786 0x001f, 0x7950, // addu t7,ra,zero
6787 0x03f9, 0x0f3c, // jalr ra,t9
6788 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
6791 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6792 // less than 64K, dynamic symbol index is less than 32K, ABI is N64, and we can
6793 // use only 32-bit instructions.
6794 template<int size
, bool big_endian
>
6796 Mips_output_data_mips_stubs
<size
, big_endian
>::
6797 lazy_stub_micromips32_normal_1_n64
[] =
6799 0xdf3c, 0x8010, // ld t9,0x8010(gp)
6800 0x581f, 0x7950, // daddu t7,ra,zero
6801 0x03f9, 0x0f3c, // jalr ra,t9
6802 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
6805 // The format of the microMIPS lazy binding stub when dynamic symbol
6806 // count is less than 64K, dynamic symbol index is between 32K and 64K,
6807 // ABI is not N64, and we can use only 32-bit instructions.
6808 template<int size
, bool big_endian
>
6810 Mips_output_data_mips_stubs
<size
, big_endian
>::
6811 lazy_stub_micromips32_normal_2
[] =
6813 0xff3c, 0x8010, // lw t9,0x8010(gp)
6814 0x001f, 0x7950, // addu t7,ra,zero
6815 0x03f9, 0x0f3c, // jalr ra,t9
6816 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
6819 // The format of the microMIPS lazy binding stub when dynamic symbol
6820 // count is less than 64K, dynamic symbol index is between 32K and 64K,
6821 // ABI is N64, and we can use only 32-bit instructions.
6822 template<int size
, bool big_endian
>
6824 Mips_output_data_mips_stubs
<size
, big_endian
>::
6825 lazy_stub_micromips32_normal_2_n64
[] =
6827 0xdf3c, 0x8010, // ld t9,0x8010(gp)
6828 0x581f, 0x7950, // daddu t7,ra,zero
6829 0x03f9, 0x0f3c, // jalr ra,t9
6830 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
6833 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6834 // greater than 64K, ABI is not N64, and we can use only 32-bit instructions.
6835 template<int size
, bool big_endian
>
6837 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big
[] =
6839 0xff3c, 0x8010, // lw t9,0x8010(gp)
6840 0x001f, 0x7950, // addu t7,ra,zero
6841 0x41b8, 0x0000, // lui t8,DYN_INDEX
6842 0x03f9, 0x0f3c, // jalr ra,t9
6843 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
6846 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6847 // greater than 64K, ABI is N64, and we can use only 32-bit instructions.
6848 template<int size
, bool big_endian
>
6850 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big_n64
[] =
6852 0xdf3c, 0x8010, // ld t9,0x8010(gp)
6853 0x581f, 0x7950, // daddu t7,ra,zero
6854 0x41b8, 0x0000, // lui t8,DYN_INDEX
6855 0x03f9, 0x0f3c, // jalr ra,t9
6856 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
6859 // Create entry for a symbol.
6861 template<int size
, bool big_endian
>
6863 Mips_output_data_mips_stubs
<size
, big_endian
>::make_entry(
6864 Mips_symbol
<size
>* gsym
)
6866 if (!gsym
->has_lazy_stub() && !gsym
->has_plt_offset())
6868 this->symbols_
.insert(gsym
);
6869 gsym
->set_has_lazy_stub(true);
6873 // Remove entry for a symbol.
6875 template<int size
, bool big_endian
>
6877 Mips_output_data_mips_stubs
<size
, big_endian
>::remove_entry(
6878 Mips_symbol
<size
>* gsym
)
6880 if (gsym
->has_lazy_stub())
6882 this->symbols_
.erase(gsym
);
6883 gsym
->set_has_lazy_stub(false);
6887 // Set stub offsets for symbols. This method expects that the number of
6888 // entries in dynamic symbol table is set.
6890 template<int size
, bool big_endian
>
6892 Mips_output_data_mips_stubs
<size
, big_endian
>::set_lazy_stub_offsets()
6894 gold_assert(this->dynsym_count_
!= -1U);
6896 if (this->stub_offsets_are_set_
)
6899 unsigned int stub_size
= this->stub_size();
6900 unsigned int offset
= 0;
6901 for (typename Unordered_set
<Mips_symbol
<size
>*>::const_iterator
6902 p
= this->symbols_
.begin();
6903 p
!= this->symbols_
.end();
6904 ++p
, offset
+= stub_size
)
6906 Mips_symbol
<size
>* mips_sym
= *p
;
6907 mips_sym
->set_lazy_stub_offset(offset
);
6909 this->stub_offsets_are_set_
= true;
6912 template<int size
, bool big_endian
>
6914 Mips_output_data_mips_stubs
<size
, big_endian
>::set_needs_dynsym_value()
6916 for (typename Unordered_set
<Mips_symbol
<size
>*>::const_iterator
6917 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
6919 Mips_symbol
<size
>* sym
= *p
;
6920 if (sym
->is_from_dynobj())
6921 sym
->set_needs_dynsym_value();
6925 // Write out the .MIPS.stubs. This uses the hand-coded instructions and
6926 // adjusts them as needed.
6928 template<int size
, bool big_endian
>
6930 Mips_output_data_mips_stubs
<size
, big_endian
>::do_write(Output_file
* of
)
6932 const off_t offset
= this->offset();
6933 const section_size_type oview_size
=
6934 convert_to_section_size_type(this->data_size());
6935 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6937 bool big_stub
= this->dynsym_count_
> 0x10000;
6939 unsigned char* pov
= oview
;
6940 for (typename Unordered_set
<Mips_symbol
<size
>*>::const_iterator
6941 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
6943 Mips_symbol
<size
>* sym
= *p
;
6944 const uint32_t* lazy_stub
;
6945 bool n64
= this->target_
->is_output_n64();
6947 if (!this->target_
->is_output_micromips())
6949 // Write standard (non-microMIPS) stub.
6952 if (sym
->dynsym_index() & ~0x7fff)
6953 // Dynsym index is between 32K and 64K.
6954 lazy_stub
= n64
? lazy_stub_normal_2_n64
: lazy_stub_normal_2
;
6956 // Dynsym index is less than 32K.
6957 lazy_stub
= n64
? lazy_stub_normal_1_n64
: lazy_stub_normal_1
;
6960 lazy_stub
= n64
? lazy_stub_big_n64
: lazy_stub_big
;
6963 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
6964 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 1]);
6970 // LUI instruction of the big stub. Paste high 16 bits of the
6972 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
6973 lazy_stub
[i
] | ((sym
->dynsym_index() >> 16) & 0x7fff));
6977 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
6978 // Last stub instruction. Paste low 16 bits of the dynsym index.
6979 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
6980 lazy_stub
[i
+ 1] | (sym
->dynsym_index() & 0xffff));
6983 else if (this->target_
->use_32bit_micromips_instructions())
6985 // Write microMIPS stub in insn32 mode.
6988 if (sym
->dynsym_index() & ~0x7fff)
6989 // Dynsym index is between 32K and 64K.
6990 lazy_stub
= n64
? lazy_stub_micromips32_normal_2_n64
6991 : lazy_stub_micromips32_normal_2
;
6993 // Dynsym index is less than 32K.
6994 lazy_stub
= n64
? lazy_stub_micromips32_normal_1_n64
6995 : lazy_stub_micromips32_normal_1
;
6998 lazy_stub
= n64
? lazy_stub_micromips32_big_n64
6999 : lazy_stub_micromips32_big
;
7002 // First stub instruction. We emit 32-bit microMIPS instructions by
7003 // emitting two 16-bit parts because on microMIPS the 16-bit part of
7004 // the instruction where the opcode is must always come first, for
7005 // both little and big endian.
7006 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7007 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7008 // Second stub instruction.
7009 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7010 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, lazy_stub
[i
+ 3]);
7015 // LUI instruction of the big stub. Paste high 16 bits of the
7017 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7018 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7019 (sym
->dynsym_index() >> 16) & 0x7fff);
7023 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7024 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7025 // Last stub instruction. Paste low 16 bits of the dynsym index.
7026 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7027 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
7028 sym
->dynsym_index() & 0xffff);
7033 // Write microMIPS stub.
7036 if (sym
->dynsym_index() & ~0x7fff)
7037 // Dynsym index is between 32K and 64K.
7038 lazy_stub
= n64
? lazy_stub_micromips_normal_2_n64
7039 : lazy_stub_micromips_normal_2
;
7041 // Dynsym index is less than 32K.
7042 lazy_stub
= n64
? lazy_stub_micromips_normal_1_n64
7043 : lazy_stub_micromips_normal_1
;
7046 lazy_stub
= n64
? lazy_stub_micromips_big_n64
7047 : lazy_stub_micromips_big
;
7050 // First stub instruction. We emit 32-bit microMIPS instructions by
7051 // emitting two 16-bit parts because on microMIPS the 16-bit part of
7052 // the instruction where the opcode is must always come first, for
7053 // both little and big endian.
7054 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7055 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7056 // Second stub instruction.
7057 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7062 // LUI instruction of the big stub. Paste high 16 bits of the
7064 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7065 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7066 (sym
->dynsym_index() >> 16) & 0x7fff);
7070 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7071 // Last stub instruction. Paste low 16 bits of the dynsym index.
7072 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7073 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
7074 sym
->dynsym_index() & 0xffff);
7079 // We always allocate 20 bytes for every stub, because final dynsym count is
7080 // not known in method do_finalize_sections. There are 4 unused bytes per
7081 // stub if final dynsym count is less than 0x10000.
7082 unsigned int used
= pov
- oview
;
7083 unsigned int unused
= big_stub
? 0 : this->symbols_
.size() * 4;
7084 gold_assert(static_cast<section_size_type
>(used
+ unused
) == oview_size
);
7086 // Fill the unused space with zeroes.
7087 // TODO(sasa): Can we strip unused bytes during the relaxation?
7089 memset(pov
, 0, unused
);
7091 of
->write_output_view(offset
, oview_size
, oview
);
7094 // Mips_output_section_reginfo methods.
7096 template<int size
, bool big_endian
>
7098 Mips_output_section_reginfo
<size
, big_endian
>::do_write(Output_file
* of
)
7100 off_t offset
= this->offset();
7101 off_t data_size
= this->data_size();
7103 unsigned char* view
= of
->get_output_view(offset
, data_size
);
7104 elfcpp::Swap
<size
, big_endian
>::writeval(view
, this->gprmask_
);
7105 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 4, this->cprmask1_
);
7106 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 8, this->cprmask2_
);
7107 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 12, this->cprmask3_
);
7108 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 16, this->cprmask4_
);
7109 // Write the gp value.
7110 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 20,
7111 this->target_
->gp_value());
7113 of
->write_output_view(offset
, data_size
, view
);
7116 // Mips_copy_relocs methods.
7118 // Emit any saved relocs.
7120 template<int sh_type
, int size
, bool big_endian
>
7122 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_mips(
7123 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
7124 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
7126 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
7127 Copy_reloc_entries::iterator p
= this->entries_
.begin();
7128 p
!= this->entries_
.end();
7130 emit_entry(*p
, reloc_section
, symtab
, layout
, target
);
7132 // We no longer need the saved information.
7133 this->entries_
.clear();
7136 // Emit the reloc if appropriate.
7138 template<int sh_type
, int size
, bool big_endian
>
7140 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_entry(
7141 Copy_reloc_entry
& entry
,
7142 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
7143 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
7145 // If the symbol is no longer defined in a dynamic object, then we
7146 // emitted a COPY relocation, and we do not want to emit this
7147 // dynamic relocation.
7148 if (!entry
.sym_
->is_from_dynobj())
7151 bool can_make_dynamic
= (entry
.reloc_type_
== elfcpp::R_MIPS_32
7152 || entry
.reloc_type_
== elfcpp::R_MIPS_REL32
7153 || entry
.reloc_type_
== elfcpp::R_MIPS_64
);
7155 Mips_symbol
<size
>* sym
= Mips_symbol
<size
>::as_mips_sym(entry
.sym_
);
7156 if (can_make_dynamic
&& !sym
->has_static_relocs())
7158 Mips_relobj
<size
, big_endian
>* object
=
7159 Mips_relobj
<size
, big_endian
>::as_mips_relobj(entry
.relobj_
);
7160 target
->got_section(symtab
, layout
)->record_global_got_symbol(
7161 sym
, object
, entry
.reloc_type_
, true, false);
7162 if (!symbol_references_local(sym
, sym
->should_add_dynsym_entry(symtab
)))
7163 target
->rel_dyn_section(layout
)->add_global(sym
, elfcpp::R_MIPS_REL32
,
7164 entry
.output_section_
, entry
.relobj_
, entry
.shndx_
, entry
.address_
);
7166 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
7167 sym
, elfcpp::R_MIPS_REL32
, entry
.output_section_
, entry
.relobj_
,
7168 entry
.shndx_
, entry
.address_
);
7171 this->make_copy_reloc(symtab
, layout
,
7172 static_cast<Sized_symbol
<size
>*>(entry
.sym_
),
7176 // Target_mips methods.
7178 // Return the value to use for a dynamic symbol which requires special
7179 // treatment. This is how we support equality comparisons of function
7180 // pointers across shared library boundaries, as described in the
7181 // processor specific ABI supplement.
7183 template<int size
, bool big_endian
>
7185 Target_mips
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
7188 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
7190 if (!mips_sym
->has_lazy_stub())
7192 if (mips_sym
->has_plt_offset())
7194 // We distinguish between PLT entries and lazy-binding stubs by
7195 // giving the former an st_other value of STO_MIPS_PLT. Set the
7196 // value to the stub address if there are any relocations in the
7197 // binary where pointer equality matters.
7198 if (mips_sym
->pointer_equality_needed())
7200 // Prefer a standard MIPS PLT entry.
7201 if (mips_sym
->has_mips_plt_offset())
7202 value
= this->plt_section()->mips_entry_address(mips_sym
);
7204 value
= this->plt_section()->comp_entry_address(mips_sym
) + 1;
7212 // First, set stub offsets for symbols. This method expects that the
7213 // number of entries in dynamic symbol table is set.
7214 this->mips_stubs_section()->set_lazy_stub_offsets();
7216 // The run-time linker uses the st_value field of the symbol
7217 // to reset the global offset table entry for this external
7218 // to its stub address when unlinking a shared object.
7219 value
= this->mips_stubs_section()->stub_address(mips_sym
);
7222 if (mips_sym
->has_mips16_fn_stub())
7224 // If we have a MIPS16 function with a stub, the dynamic symbol must
7225 // refer to the stub, since only the stub uses the standard calling
7227 value
= mips_sym
->template
7228 get_mips16_fn_stub
<big_endian
>()->output_address();
7234 // Get the dynamic reloc section, creating it if necessary. It's always
7235 // .rel.dyn, even for MIPS64.
7237 template<int size
, bool big_endian
>
7238 typename Target_mips
<size
, big_endian
>::Reloc_section
*
7239 Target_mips
<size
, big_endian
>::rel_dyn_section(Layout
* layout
)
7241 if (this->rel_dyn_
== NULL
)
7243 gold_assert(layout
!= NULL
);
7244 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
7245 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
7246 elfcpp::SHF_ALLOC
, this->rel_dyn_
,
7247 ORDER_DYNAMIC_RELOCS
, false);
7249 // First entry in .rel.dyn has to be null.
7250 // This is hack - we define dummy output data and set its address to 0,
7251 // and define absolute R_MIPS_NONE relocation with offset 0 against it.
7252 // This ensures that the entry is null.
7253 Output_data
* od
= new Output_data_zero_fill(0, 0);
7255 this->rel_dyn_
->add_absolute(elfcpp::R_MIPS_NONE
, od
, 0);
7257 return this->rel_dyn_
;
7260 // Get the GOT section, creating it if necessary.
7262 template<int size
, bool big_endian
>
7263 Mips_output_data_got
<size
, big_endian
>*
7264 Target_mips
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
7267 if (this->got_
== NULL
)
7269 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
7271 this->got_
= new Mips_output_data_got
<size
, big_endian
>(this, symtab
,
7273 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
7274 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
|
7275 elfcpp::SHF_MIPS_GPREL
),
7276 this->got_
, ORDER_DATA
, false);
7278 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
7279 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
7280 Symbol_table::PREDEFINED
,
7282 0, 0, elfcpp::STT_OBJECT
,
7284 elfcpp::STV_DEFAULT
, 0,
7291 // Calculate value of _gp symbol.
7293 template<int size
, bool big_endian
>
7295 Target_mips
<size
, big_endian
>::set_gp(Layout
* layout
, Symbol_table
* symtab
)
7297 if (this->gp_
!= NULL
)
7300 Output_data
* section
= layout
->find_output_section(".got");
7301 if (section
== NULL
)
7303 // If there is no .got section, gp should be based on .sdata.
7304 // TODO(sasa): This is probably not needed. This was needed for older
7305 // MIPS architectures which accessed both GOT and .sdata section using
7306 // gp-relative addressing. Modern Mips Linux ELF architectures don't
7307 // access .sdata using gp-relative addressing.
7308 for (Layout::Section_list::const_iterator
7309 p
= layout
->section_list().begin();
7310 p
!= layout
->section_list().end();
7313 if (strcmp((*p
)->name(), ".sdata") == 0)
7321 Sized_symbol
<size
>* gp
=
7322 static_cast<Sized_symbol
<size
>*>(symtab
->lookup("_gp"));
7325 if (gp
->source() != Symbol::IS_CONSTANT
&& section
!= NULL
)
7326 gp
->init_output_data(gp
->name(), NULL
, section
, MIPS_GP_OFFSET
, 0,
7329 elfcpp::STV_DEFAULT
, 0,
7333 else if (section
!= NULL
)
7335 gp
= static_cast<Sized_symbol
<size
>*>(symtab
->define_in_output_data(
7336 "_gp", NULL
, Symbol_table::PREDEFINED
,
7337 section
, MIPS_GP_OFFSET
, 0,
7340 elfcpp::STV_DEFAULT
,
7346 // Set the dynamic symbol indexes. INDEX is the index of the first
7347 // global dynamic symbol. Pointers to the symbols are stored into the
7348 // vector SYMS. The names are added to DYNPOOL. This returns an
7349 // updated dynamic symbol index.
7351 template<int size
, bool big_endian
>
7353 Target_mips
<size
, big_endian
>::do_set_dynsym_indexes(
7354 std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
7355 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
7356 Versions
* versions
, Symbol_table
* symtab
) const
7358 std::vector
<Symbol
*> non_got_symbols
;
7359 std::vector
<Symbol
*> got_symbols
;
7361 reorder_dyn_symbols
<size
, big_endian
>(dyn_symbols
, &non_got_symbols
,
7364 for (std::vector
<Symbol
*>::iterator p
= non_got_symbols
.begin();
7365 p
!= non_got_symbols
.end();
7370 // Note that SYM may already have a dynamic symbol index, since
7371 // some symbols appear more than once in the symbol table, with
7372 // and without a version.
7374 if (!sym
->has_dynsym_index())
7376 sym
->set_dynsym_index(index
);
7378 syms
->push_back(sym
);
7379 dynpool
->add(sym
->name(), false, NULL
);
7381 // Record any version information.
7382 if (sym
->version() != NULL
)
7383 versions
->record_version(symtab
, dynpool
, sym
);
7385 // If the symbol is defined in a dynamic object and is
7386 // referenced in a regular object, then mark the dynamic
7387 // object as needed. This is used to implement --as-needed.
7388 if (sym
->is_from_dynobj() && sym
->in_reg())
7389 sym
->object()->set_is_needed();
7393 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
7394 p
!= got_symbols
.end();
7398 if (!sym
->has_dynsym_index())
7400 // Record any version information.
7401 if (sym
->version() != NULL
)
7402 versions
->record_version(symtab
, dynpool
, sym
);
7406 index
= versions
->finalize(symtab
, index
, syms
);
7408 int got_sym_count
= 0;
7409 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
7410 p
!= got_symbols
.end();
7415 if (!sym
->has_dynsym_index())
7418 sym
->set_dynsym_index(index
);
7420 syms
->push_back(sym
);
7421 dynpool
->add(sym
->name(), false, NULL
);
7423 // If the symbol is defined in a dynamic object and is
7424 // referenced in a regular object, then mark the dynamic
7425 // object as needed. This is used to implement --as-needed.
7426 if (sym
->is_from_dynobj() && sym
->in_reg())
7427 sym
->object()->set_is_needed();
7431 // Set index of the first symbol that has .got entry.
7432 this->got_
->set_first_global_got_dynsym_index(
7433 got_sym_count
> 0 ? index
- got_sym_count
: -1U);
7435 if (this->mips_stubs_
!= NULL
)
7436 this->mips_stubs_
->set_dynsym_count(index
);
7441 // Create a PLT entry for a global symbol referenced by r_type relocation.
7443 template<int size
, bool big_endian
>
7445 Target_mips
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7447 Mips_symbol
<size
>* gsym
,
7448 unsigned int r_type
)
7450 if (gsym
->has_lazy_stub() || gsym
->has_plt_offset())
7453 if (this->plt_
== NULL
)
7455 // Create the GOT section first.
7456 this->got_section(symtab
, layout
);
7458 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
7459 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
7460 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
7461 this->got_plt_
, ORDER_DATA
, false);
7463 // The first two entries are reserved.
7464 this->got_plt_
->set_current_data_size(2 * size
/8);
7466 this->plt_
= new Mips_output_data_plt
<size
, big_endian
>(layout
,
7469 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
7471 | elfcpp::SHF_EXECINSTR
),
7472 this->plt_
, ORDER_PLT
, false);
7475 this->plt_
->add_entry(gsym
, r_type
);
7479 // Get the .MIPS.stubs section, creating it if necessary.
7481 template<int size
, bool big_endian
>
7482 Mips_output_data_mips_stubs
<size
, big_endian
>*
7483 Target_mips
<size
, big_endian
>::mips_stubs_section(Layout
* layout
)
7485 if (this->mips_stubs_
== NULL
)
7488 new Mips_output_data_mips_stubs
<size
, big_endian
>(this);
7489 layout
->add_output_section_data(".MIPS.stubs", elfcpp::SHT_PROGBITS
,
7491 | elfcpp::SHF_EXECINSTR
),
7492 this->mips_stubs_
, ORDER_PLT
, false);
7494 return this->mips_stubs_
;
7497 // Get the LA25 stub section, creating it if necessary.
7499 template<int size
, bool big_endian
>
7500 Mips_output_data_la25_stub
<size
, big_endian
>*
7501 Target_mips
<size
, big_endian
>::la25_stub_section(Layout
* layout
)
7503 if (this->la25_stub_
== NULL
)
7505 this->la25_stub_
= new Mips_output_data_la25_stub
<size
, big_endian
>();
7506 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7508 | elfcpp::SHF_EXECINSTR
),
7509 this->la25_stub_
, ORDER_TEXT
, false);
7511 return this->la25_stub_
;
7514 // Process the relocations to determine unreferenced sections for
7515 // garbage collection.
7517 template<int size
, bool big_endian
>
7519 Target_mips
<size
, big_endian
>::gc_process_relocs(
7520 Symbol_table
* symtab
,
7522 Sized_relobj_file
<size
, big_endian
>* object
,
7523 unsigned int data_shndx
,
7525 const unsigned char* prelocs
,
7527 Output_section
* output_section
,
7528 bool needs_special_offset_handling
,
7529 size_t local_symbol_count
,
7530 const unsigned char* plocal_symbols
)
7532 typedef Target_mips
<size
, big_endian
> Mips
;
7533 typedef typename Target_mips
<size
, big_endian
>::Scan Scan
;
7535 gold::gc_process_relocs
<size
, big_endian
, Mips
, elfcpp::SHT_REL
, Scan
,
7536 typename
Target_mips::Relocatable_size_for_reloc
>(
7545 needs_special_offset_handling
,
7550 // Scan relocations for a section.
7552 template<int size
, bool big_endian
>
7554 Target_mips
<size
, big_endian
>::scan_relocs(
7555 Symbol_table
* symtab
,
7557 Sized_relobj_file
<size
, big_endian
>* object
,
7558 unsigned int data_shndx
,
7559 unsigned int sh_type
,
7560 const unsigned char* prelocs
,
7562 Output_section
* output_section
,
7563 bool needs_special_offset_handling
,
7564 size_t local_symbol_count
,
7565 const unsigned char* plocal_symbols
)
7567 typedef Target_mips
<size
, big_endian
> Mips
;
7568 typedef typename Target_mips
<size
, big_endian
>::Scan Scan
;
7570 if (sh_type
== elfcpp::SHT_REL
)
7571 gold::scan_relocs
<size
, big_endian
, Mips
, elfcpp::SHT_REL
, Scan
>(
7580 needs_special_offset_handling
,
7583 else if (sh_type
== elfcpp::SHT_RELA
)
7584 gold::scan_relocs
<size
, big_endian
, Mips
, elfcpp::SHT_RELA
, Scan
>(
7593 needs_special_offset_handling
,
7598 template<int size
, bool big_endian
>
7600 Target_mips
<size
, big_endian
>::mips_32bit_flags(elfcpp::Elf_Word flags
)
7602 return ((flags
& elfcpp::EF_MIPS_32BITMODE
) != 0
7603 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_O32
7604 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_EABI32
7605 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_1
7606 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_2
7607 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32
7608 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32R2
);
7611 // Return the MACH for a MIPS e_flags value.
7612 template<int size
, bool big_endian
>
7614 Target_mips
<size
, big_endian
>::elf_mips_mach(elfcpp::Elf_Word flags
)
7616 switch (flags
& elfcpp::EF_MIPS_MACH
)
7618 case elfcpp::E_MIPS_MACH_3900
:
7619 return mach_mips3900
;
7621 case elfcpp::E_MIPS_MACH_4010
:
7622 return mach_mips4010
;
7624 case elfcpp::E_MIPS_MACH_4100
:
7625 return mach_mips4100
;
7627 case elfcpp::E_MIPS_MACH_4111
:
7628 return mach_mips4111
;
7630 case elfcpp::E_MIPS_MACH_4120
:
7631 return mach_mips4120
;
7633 case elfcpp::E_MIPS_MACH_4650
:
7634 return mach_mips4650
;
7636 case elfcpp::E_MIPS_MACH_5400
:
7637 return mach_mips5400
;
7639 case elfcpp::E_MIPS_MACH_5500
:
7640 return mach_mips5500
;
7642 case elfcpp::E_MIPS_MACH_9000
:
7643 return mach_mips9000
;
7645 case elfcpp::E_MIPS_MACH_SB1
:
7646 return mach_mips_sb1
;
7648 case elfcpp::E_MIPS_MACH_LS2E
:
7649 return mach_mips_loongson_2e
;
7651 case elfcpp::E_MIPS_MACH_LS2F
:
7652 return mach_mips_loongson_2f
;
7654 case elfcpp::E_MIPS_MACH_LS3A
:
7655 return mach_mips_loongson_3a
;
7657 case elfcpp::E_MIPS_MACH_OCTEON2
:
7658 return mach_mips_octeon2
;
7660 case elfcpp::E_MIPS_MACH_OCTEON
:
7661 return mach_mips_octeon
;
7663 case elfcpp::E_MIPS_MACH_XLR
:
7664 return mach_mips_xlr
;
7667 switch (flags
& elfcpp::EF_MIPS_ARCH
)
7670 case elfcpp::E_MIPS_ARCH_1
:
7671 return mach_mips3000
;
7673 case elfcpp::E_MIPS_ARCH_2
:
7674 return mach_mips6000
;
7676 case elfcpp::E_MIPS_ARCH_3
:
7677 return mach_mips4000
;
7679 case elfcpp::E_MIPS_ARCH_4
:
7680 return mach_mips8000
;
7682 case elfcpp::E_MIPS_ARCH_5
:
7685 case elfcpp::E_MIPS_ARCH_32
:
7686 return mach_mipsisa32
;
7688 case elfcpp::E_MIPS_ARCH_64
:
7689 return mach_mipsisa64
;
7691 case elfcpp::E_MIPS_ARCH_32R2
:
7692 return mach_mipsisa32r2
;
7694 case elfcpp::E_MIPS_ARCH_64R2
:
7695 return mach_mipsisa64r2
;
7702 // Check whether machine EXTENSION is an extension of machine BASE.
7703 template<int size
, bool big_endian
>
7705 Target_mips
<size
, big_endian
>::mips_mach_extends(unsigned int base
,
7706 unsigned int extension
)
7708 if (extension
== base
)
7711 if ((base
== mach_mipsisa32
)
7712 && this->mips_mach_extends(mach_mipsisa64
, extension
))
7715 if ((base
== mach_mipsisa32r2
)
7716 && this->mips_mach_extends(mach_mipsisa64r2
, extension
))
7719 for (unsigned int i
= 0; i
< this->mips_mach_extensions_
.size(); ++i
)
7720 if (extension
== this->mips_mach_extensions_
[i
].first
)
7722 extension
= this->mips_mach_extensions_
[i
].second
;
7723 if (extension
== base
)
7730 template<int size
, bool big_endian
>
7732 Target_mips
<size
, big_endian
>::merge_processor_specific_flags(
7733 const std::string
& name
, elfcpp::Elf_Word in_flags
,
7734 unsigned char in_ei_class
, bool dyn_obj
)
7736 // If flags are not set yet, just copy them.
7737 if (!this->are_processor_specific_flags_set())
7739 this->set_processor_specific_flags(in_flags
);
7740 this->ei_class_
= in_ei_class
;
7741 this->mach_
= this->elf_mips_mach(in_flags
);
7745 elfcpp::Elf_Word new_flags
= in_flags
;
7746 elfcpp::Elf_Word old_flags
= this->processor_specific_flags();
7747 elfcpp::Elf_Word merged_flags
= this->processor_specific_flags();
7748 merged_flags
|= new_flags
& elfcpp::EF_MIPS_NOREORDER
;
7750 // Check flag compatibility.
7751 new_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
7752 old_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
7754 // Some IRIX 6 BSD-compatibility objects have this bit set. It
7755 // doesn't seem to matter.
7756 new_flags
&= ~elfcpp::EF_MIPS_XGOT
;
7757 old_flags
&= ~elfcpp::EF_MIPS_XGOT
;
7759 // MIPSpro generates ucode info in n64 objects. Again, we should
7760 // just be able to ignore this.
7761 new_flags
&= ~elfcpp::EF_MIPS_UCODE
;
7762 old_flags
&= ~elfcpp::EF_MIPS_UCODE
;
7764 // DSOs should only be linked with CPIC code.
7766 new_flags
|= elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
;
7768 if (new_flags
== old_flags
)
7770 this->set_processor_specific_flags(merged_flags
);
7774 if (((new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0)
7775 != ((old_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0))
7776 gold_warning(_("%s: linking abicalls files with non-abicalls files"),
7779 if (new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
))
7780 merged_flags
|= elfcpp::EF_MIPS_CPIC
;
7781 if (!(new_flags
& elfcpp::EF_MIPS_PIC
))
7782 merged_flags
&= ~elfcpp::EF_MIPS_PIC
;
7784 new_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
7785 old_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
7787 // Compare the ISAs.
7788 if (mips_32bit_flags(old_flags
) != mips_32bit_flags(new_flags
))
7789 gold_error(_("%s: linking 32-bit code with 64-bit code"), name
.c_str());
7790 else if (!this->mips_mach_extends(this->elf_mips_mach(in_flags
), this->mach_
))
7792 // Output ISA isn't the same as, or an extension of, input ISA.
7793 if (this->mips_mach_extends(this->mach_
, this->elf_mips_mach(in_flags
)))
7795 // Copy the architecture info from input object to output. Also copy
7796 // the 32-bit flag (if set) so that we continue to recognise
7797 // output as a 32-bit binary.
7798 this->mach_
= this->elf_mips_mach(in_flags
);
7799 merged_flags
&= ~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
);
7800 merged_flags
|= (new_flags
& (elfcpp::EF_MIPS_ARCH
7801 | elfcpp::EF_MIPS_MACH
| elfcpp::EF_MIPS_32BITMODE
));
7803 // Copy across the ABI flags if output doesn't use them
7804 // and if that was what caused us to treat input object as 32-bit.
7805 if ((old_flags
& elfcpp::EF_MIPS_ABI
) == 0
7806 && this->mips_32bit_flags(new_flags
)
7807 && !this->mips_32bit_flags(new_flags
& ~elfcpp::EF_MIPS_ABI
))
7808 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ABI
;
7811 // The ISAs aren't compatible.
7812 gold_error(_("%s: linking %s module with previous %s modules"),
7813 name
.c_str(), this->elf_mips_mach_name(in_flags
),
7814 this->elf_mips_mach_name(merged_flags
));
7817 new_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
7818 | elfcpp::EF_MIPS_32BITMODE
));
7819 old_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
7820 | elfcpp::EF_MIPS_32BITMODE
));
7822 // Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it does set
7823 // EI_CLASS differently from any 32-bit ABI.
7824 if ((new_flags
& elfcpp::EF_MIPS_ABI
) != (old_flags
& elfcpp::EF_MIPS_ABI
)
7825 || (in_ei_class
!= this->ei_class_
))
7827 // Only error if both are set (to different values).
7828 if (((new_flags
& elfcpp::EF_MIPS_ABI
)
7829 && (old_flags
& elfcpp::EF_MIPS_ABI
))
7830 || (in_ei_class
!= this->ei_class_
))
7831 gold_error(_("%s: ABI mismatch: linking %s module with "
7832 "previous %s modules"), name
.c_str(),
7833 this->elf_mips_abi_name(in_flags
, in_ei_class
),
7834 this->elf_mips_abi_name(merged_flags
, this->ei_class_
));
7836 new_flags
&= ~elfcpp::EF_MIPS_ABI
;
7837 old_flags
&= ~elfcpp::EF_MIPS_ABI
;
7840 // Compare ASEs. Forbid linking MIPS16 and microMIPS ASE modules together
7841 // and allow arbitrary mixing of the remaining ASEs (retain the union).
7842 if ((new_flags
& elfcpp::EF_MIPS_ARCH_ASE
)
7843 != (old_flags
& elfcpp::EF_MIPS_ARCH_ASE
))
7845 int old_micro
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
7846 int new_micro
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
7847 int old_m16
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
7848 int new_m16
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
7849 int micro_mis
= old_m16
&& new_micro
;
7850 int m16_mis
= old_micro
&& new_m16
;
7852 if (m16_mis
|| micro_mis
)
7853 gold_error(_("%s: ASE mismatch: linking %s module with "
7854 "previous %s modules"), name
.c_str(),
7855 m16_mis
? "MIPS16" : "microMIPS",
7856 m16_mis
? "microMIPS" : "MIPS16");
7858 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ARCH_ASE
;
7860 new_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
7861 old_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
7864 // Warn about any other mismatches.
7865 if (new_flags
!= old_flags
)
7866 gold_error(_("%s: uses different e_flags (0x%x) fields than previous "
7867 "modules (0x%x)"), name
.c_str(), new_flags
, old_flags
);
7869 this->set_processor_specific_flags(merged_flags
);
7872 // Adjust ELF file header.
7874 template<int size
, bool big_endian
>
7876 Target_mips
<size
, big_endian
>::do_adjust_elf_header(
7877 unsigned char* view
,
7880 gold_assert(len
== elfcpp::Elf_sizes
<size
>::ehdr_size
);
7882 elfcpp::Ehdr
<size
, big_endian
> ehdr(view
);
7883 unsigned char e_ident
[elfcpp::EI_NIDENT
];
7884 memcpy(e_ident
, ehdr
.get_e_ident(), elfcpp::EI_NIDENT
);
7886 e_ident
[elfcpp::EI_CLASS
] = this->ei_class_
;
7888 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
7889 oehdr
.put_e_ident(e_ident
);
7890 if (this->entry_symbol_is_compressed_
)
7891 oehdr
.put_e_entry(ehdr
.get_e_entry() + 1);
7894 // do_make_elf_object to override the same function in the base class.
7895 // We need to use a target-specific sub-class of
7896 // Sized_relobj_file<size, big_endian> to store Mips specific information.
7897 // Hence we need to have our own ELF object creation.
7899 template<int size
, bool big_endian
>
7901 Target_mips
<size
, big_endian
>::do_make_elf_object(
7902 const std::string
& name
,
7903 Input_file
* input_file
,
7904 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
7906 int et
= ehdr
.get_e_type();
7907 // ET_EXEC files are valid input for --just-symbols/-R,
7908 // and we treat them as relocatable objects.
7909 if (et
== elfcpp::ET_REL
7910 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
7912 Mips_relobj
<size
, big_endian
>* obj
=
7913 new Mips_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
7917 else if (et
== elfcpp::ET_DYN
)
7919 // TODO(sasa): Should we create Mips_dynobj?
7920 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
7924 gold_error(_("%s: unsupported ELF file type %d"),
7930 // Finalize the sections.
7932 template <int size
, bool big_endian
>
7934 Target_mips
<size
, big_endian
>::do_finalize_sections(Layout
* layout
,
7935 const Input_objects
* input_objects
,
7936 Symbol_table
* symtab
)
7938 // Add +1 to MIPS16 and microMIPS init_ and _fini symbols so that DT_INIT and
7939 // DT_FINI have correct values.
7940 Mips_symbol
<size
>* init
= static_cast<Mips_symbol
<size
>*>(
7941 symtab
->lookup(parameters
->options().init()));
7942 if (init
!= NULL
&& (init
->is_mips16() || init
->is_micromips()))
7943 init
->set_value(init
->value() | 1);
7944 Mips_symbol
<size
>* fini
= static_cast<Mips_symbol
<size
>*>(
7945 symtab
->lookup(parameters
->options().fini()));
7946 if (fini
!= NULL
&& (fini
->is_mips16() || fini
->is_micromips()))
7947 fini
->set_value(fini
->value() | 1);
7949 // Check whether the entry symbol is mips16 or micromips. This is needed to
7950 // adjust entry address in ELF header.
7951 Mips_symbol
<size
>* entry
=
7952 static_cast<Mips_symbol
<size
>*>(symtab
->lookup(this->entry_symbol_name()));
7953 this->entry_symbol_is_compressed_
= (entry
!= NULL
&& (entry
->is_mips16()
7954 || entry
->is_micromips()));
7956 if (!parameters
->doing_static_link()
7957 && (strcmp(parameters
->options().hash_style(), "gnu") == 0
7958 || strcmp(parameters
->options().hash_style(), "both") == 0))
7960 // .gnu.hash and the MIPS ABI require .dynsym to be sorted in different
7961 // ways. .gnu.hash needs symbols to be grouped by hash code whereas the
7962 // MIPS ABI requires a mapping between the GOT and the symbol table.
7963 gold_error(".gnu.hash is incompatible with the MIPS ABI");
7966 // Check whether the final section that was scanned has HI16 or GOT16
7967 // relocations without the corresponding LO16 part.
7968 if (this->got16_addends_
.size() > 0)
7969 gold_error("Can't find matching LO16 reloc");
7972 this->set_gp(layout
, symtab
);
7974 // Check for any mips16 stub sections that we can discard.
7975 if (!parameters
->options().relocatable())
7977 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
7978 p
!= input_objects
->relobj_end();
7981 Mips_relobj
<size
, big_endian
>* object
=
7982 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
7983 object
->discard_mips16_stub_sections(symtab
);
7987 // Merge processor-specific flags.
7988 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
7989 p
!= input_objects
->relobj_end();
7992 Mips_relobj
<size
, big_endian
>* relobj
=
7993 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
7995 Input_file::Format format
= relobj
->input_file()->format();
7996 if (format
== Input_file::FORMAT_ELF
)
7998 // Read processor-specific flags in ELF file header.
7999 const unsigned char* pehdr
= relobj
->get_view(
8000 elfcpp::file_header_offset
,
8001 elfcpp::Elf_sizes
<size
>::ehdr_size
,
8004 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
8005 elfcpp::Elf_Word in_flags
= ehdr
.get_e_flags();
8006 unsigned char ei_class
= ehdr
.get_e_ident()[elfcpp::EI_CLASS
];
8008 this->merge_processor_specific_flags(relobj
->name(), in_flags
,
8013 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
8014 p
!= input_objects
->dynobj_end();
8017 Sized_dynobj
<size
, big_endian
>* dynobj
=
8018 static_cast<Sized_dynobj
<size
, big_endian
>*>(*p
);
8020 // Read processor-specific flags.
8021 const unsigned char* pehdr
= dynobj
->get_view(elfcpp::file_header_offset
,
8022 elfcpp::Elf_sizes
<size
>::ehdr_size
,
8025 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
8026 elfcpp::Elf_Word in_flags
= ehdr
.get_e_flags();
8027 unsigned char ei_class
= ehdr
.get_e_ident()[elfcpp::EI_CLASS
];
8029 this->merge_processor_specific_flags(dynobj
->name(), in_flags
, ei_class
,
8033 // Merge .reginfo contents of input objects.
8034 Valtype gprmask
= 0;
8035 Valtype cprmask1
= 0;
8036 Valtype cprmask2
= 0;
8037 Valtype cprmask3
= 0;
8038 Valtype cprmask4
= 0;
8039 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8040 p
!= input_objects
->relobj_end();
8043 Mips_relobj
<size
, big_endian
>* relobj
=
8044 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
8046 gprmask
|= relobj
->gprmask();
8047 cprmask1
|= relobj
->cprmask1();
8048 cprmask2
|= relobj
->cprmask2();
8049 cprmask3
|= relobj
->cprmask3();
8050 cprmask4
|= relobj
->cprmask4();
8053 if (this->plt_
!= NULL
)
8055 // Set final PLT offsets for symbols.
8056 this->plt_section()->set_plt_offsets();
8058 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
8059 // Set STO_MICROMIPS flag if the output has microMIPS code, but only if
8060 // there are no standard PLT entries present.
8061 unsigned char nonvis
= 0;
8062 if (this->is_output_micromips()
8063 && !this->plt_section()->has_standard_entries())
8064 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
8065 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
8066 Symbol_table::PREDEFINED
,
8068 0, 0, elfcpp::STT_FUNC
,
8070 elfcpp::STV_DEFAULT
, nonvis
,
8074 if (this->mips_stubs_
!= NULL
)
8076 // Define _MIPS_STUBS_ at the start of the .MIPS.stubs section.
8077 unsigned char nonvis
= 0;
8078 if (this->is_output_micromips())
8079 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
8080 symtab
->define_in_output_data("_MIPS_STUBS_", NULL
,
8081 Symbol_table::PREDEFINED
,
8083 0, 0, elfcpp::STT_FUNC
,
8085 elfcpp::STV_DEFAULT
, nonvis
,
8089 if (!parameters
->options().relocatable() && !parameters
->doing_static_link())
8090 // In case there is no .got section, create one.
8091 this->got_section(symtab
, layout
);
8093 // Emit any relocs we saved in an attempt to avoid generating COPY
8095 if (this->copy_relocs_
.any_saved_relocs())
8096 this->copy_relocs_
.emit_mips(this->rel_dyn_section(layout
), symtab
, layout
,
8099 // Emit dynamic relocs.
8100 for (typename
std::vector
<Dyn_reloc
>::iterator p
= this->dyn_relocs_
.begin();
8101 p
!= this->dyn_relocs_
.end();
8103 p
->emit(this->rel_dyn_section(layout
), this->got_section(), symtab
);
8105 if (this->has_got_section())
8106 this->got_section()->lay_out_got(layout
, symtab
, input_objects
);
8108 if (this->mips_stubs_
!= NULL
)
8109 this->mips_stubs_
->set_needs_dynsym_value();
8111 // Check for functions that might need $25 to be valid on entry.
8112 // TODO(sasa): Can we do this without iterating over all symbols?
8113 typedef Symbol_visitor_check_symbols
<size
, big_endian
> Symbol_visitor
;
8114 symtab
->for_all_symbols
<size
, Symbol_visitor
>(Symbol_visitor(this, layout
,
8117 // Add NULL segment.
8118 if (!parameters
->options().relocatable())
8119 layout
->make_output_segment(elfcpp::PT_NULL
, 0);
8121 for (Layout::Section_list::const_iterator p
= layout
->section_list().begin();
8122 p
!= layout
->section_list().end();
8125 if ((*p
)->type() == elfcpp::SHT_MIPS_REGINFO
)
8127 Mips_output_section_reginfo
<size
, big_endian
>* reginfo
=
8128 Mips_output_section_reginfo
<size
, big_endian
>::
8129 as_mips_output_section_reginfo(*p
);
8131 reginfo
->set_masks(gprmask
, cprmask1
, cprmask2
, cprmask3
, cprmask4
);
8133 if (!parameters
->options().relocatable())
8135 Output_segment
* reginfo_segment
=
8136 layout
->make_output_segment(elfcpp::PT_MIPS_REGINFO
,
8138 reginfo_segment
->add_output_section_to_nonload(reginfo
,
8144 // Fill in some more dynamic tags.
8145 // TODO(sasa): Add more dynamic tags.
8146 const Reloc_section
* rel_plt
= (this->plt_
== NULL
8147 ? NULL
: this->plt_
->rel_plt());
8148 layout
->add_target_dynamic_tags(true, this->got_
, rel_plt
,
8149 this->rel_dyn_
, true, false);
8151 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
8153 && !parameters
->options().relocatable()
8154 && !parameters
->doing_static_link())
8157 // This element holds a 32-bit version id for the Runtime
8158 // Linker Interface. This will start at integer value 1.
8160 odyn
->add_constant(elfcpp::DT_MIPS_RLD_VERSION
, d_val
);
8163 d_val
= elfcpp::RHF_NOTPOT
;
8164 odyn
->add_constant(elfcpp::DT_MIPS_FLAGS
, d_val
);
8166 // Save layout for using when emiting custom dynamic tags.
8167 this->layout_
= layout
;
8169 // This member holds the base address of the segment.
8170 odyn
->add_custom(elfcpp::DT_MIPS_BASE_ADDRESS
);
8172 // This member holds the number of entries in the .dynsym section.
8173 odyn
->add_custom(elfcpp::DT_MIPS_SYMTABNO
);
8175 // This member holds the index of the first dynamic symbol
8176 // table entry that corresponds to an entry in the global offset table.
8177 odyn
->add_custom(elfcpp::DT_MIPS_GOTSYM
);
8179 // This member holds the number of local GOT entries.
8180 odyn
->add_constant(elfcpp::DT_MIPS_LOCAL_GOTNO
,
8181 this->got_
->get_local_gotno());
8183 if (this->plt_
!= NULL
)
8184 // DT_MIPS_PLTGOT dynamic tag
8185 odyn
->add_section_address(elfcpp::DT_MIPS_PLTGOT
, this->got_plt_
);
8189 // Get the custom dynamic tag value.
8190 template<int size
, bool big_endian
>
8192 Target_mips
<size
, big_endian
>::do_dynamic_tag_custom_value(elfcpp::DT tag
) const
8196 case elfcpp::DT_MIPS_BASE_ADDRESS
:
8198 // The base address of the segment.
8199 // At this point, the segment list has been sorted into final order,
8200 // so just return vaddr of the first readable PT_LOAD segment.
8201 Output_segment
* seg
=
8202 this->layout_
->find_output_segment(elfcpp::PT_LOAD
, elfcpp::PF_R
, 0);
8203 gold_assert(seg
!= NULL
);
8204 return seg
->vaddr();
8207 case elfcpp::DT_MIPS_SYMTABNO
:
8208 // The number of entries in the .dynsym section.
8209 return this->get_dt_mips_symtabno();
8211 case elfcpp::DT_MIPS_GOTSYM
:
8213 // The index of the first dynamic symbol table entry that corresponds
8214 // to an entry in the GOT.
8215 if (this->got_
->first_global_got_dynsym_index() != -1U)
8216 return this->got_
->first_global_got_dynsym_index();
8218 // In case if we don't have global GOT symbols we default to setting
8219 // DT_MIPS_GOTSYM to the same value as DT_MIPS_SYMTABNO.
8220 return this->get_dt_mips_symtabno();
8224 gold_error(_("Unknown dynamic tag 0x%x"), (unsigned int)tag
);
8227 return (unsigned int)-1;
8230 // Relocate section data.
8232 template<int size
, bool big_endian
>
8234 Target_mips
<size
, big_endian
>::relocate_section(
8235 const Relocate_info
<size
, big_endian
>* relinfo
,
8236 unsigned int sh_type
,
8237 const unsigned char* prelocs
,
8239 Output_section
* output_section
,
8240 bool needs_special_offset_handling
,
8241 unsigned char* view
,
8242 Mips_address address
,
8243 section_size_type view_size
,
8244 const Reloc_symbol_changes
* reloc_symbol_changes
)
8246 typedef Target_mips
<size
, big_endian
> Mips
;
8247 typedef typename Target_mips
<size
, big_endian
>::Relocate Mips_relocate
;
8249 if (sh_type
== elfcpp::SHT_REL
)
8250 gold::relocate_section
<size
, big_endian
, Mips
, elfcpp::SHT_REL
,
8251 Mips_relocate
, gold::Default_comdat_behavior
>(
8257 needs_special_offset_handling
,
8261 reloc_symbol_changes
);
8262 else if (sh_type
== elfcpp::SHT_RELA
)
8263 gold::relocate_section
<size
, big_endian
, Mips
, elfcpp::SHT_RELA
,
8264 Mips_relocate
, gold::Default_comdat_behavior
>(
8270 needs_special_offset_handling
,
8274 reloc_symbol_changes
);
8277 // Return the size of a relocation while scanning during a relocatable
8280 template<int size
, bool big_endian
>
8282 Target_mips
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
8283 unsigned int r_type
,
8288 case elfcpp::R_MIPS_NONE
:
8289 case elfcpp::R_MIPS_TLS_DTPMOD64
:
8290 case elfcpp::R_MIPS_TLS_DTPREL64
:
8291 case elfcpp::R_MIPS_TLS_TPREL64
:
8294 case elfcpp::R_MIPS_32
:
8295 case elfcpp::R_MIPS_TLS_DTPMOD32
:
8296 case elfcpp::R_MIPS_TLS_DTPREL32
:
8297 case elfcpp::R_MIPS_TLS_TPREL32
:
8298 case elfcpp::R_MIPS_REL32
:
8299 case elfcpp::R_MIPS_PC32
:
8300 case elfcpp::R_MIPS_GPREL32
:
8301 case elfcpp::R_MIPS_JALR
:
8304 case elfcpp::R_MIPS_16
:
8305 case elfcpp::R_MIPS_HI16
:
8306 case elfcpp::R_MIPS_LO16
:
8307 case elfcpp::R_MIPS_GPREL16
:
8308 case elfcpp::R_MIPS16_HI16
:
8309 case elfcpp::R_MIPS16_LO16
:
8310 case elfcpp::R_MIPS_PC16
:
8311 case elfcpp::R_MIPS_GOT16
:
8312 case elfcpp::R_MIPS16_GOT16
:
8313 case elfcpp::R_MIPS_CALL16
:
8314 case elfcpp::R_MIPS16_CALL16
:
8315 case elfcpp::R_MIPS_GOT_HI16
:
8316 case elfcpp::R_MIPS_CALL_HI16
:
8317 case elfcpp::R_MIPS_GOT_LO16
:
8318 case elfcpp::R_MIPS_CALL_LO16
:
8319 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
8320 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
8321 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
8322 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
8323 case elfcpp::R_MIPS16_GPREL
:
8324 case elfcpp::R_MIPS_GOT_DISP
:
8325 case elfcpp::R_MIPS_LITERAL
:
8326 case elfcpp::R_MIPS_GOT_PAGE
:
8327 case elfcpp::R_MIPS_GOT_OFST
:
8328 case elfcpp::R_MIPS_TLS_GD
:
8329 case elfcpp::R_MIPS_TLS_LDM
:
8330 case elfcpp::R_MIPS_TLS_GOTTPREL
:
8333 // These relocations are not byte sized
8334 case elfcpp::R_MIPS_26
:
8335 case elfcpp::R_MIPS16_26
:
8338 case elfcpp::R_MIPS_COPY
:
8339 case elfcpp::R_MIPS_JUMP_SLOT
:
8340 object
->error(_("unexpected reloc %u in object file"), r_type
);
8344 object
->error(_("unsupported reloc %u in object file"), r_type
);
8349 // Scan the relocs during a relocatable link.
8351 template<int size
, bool big_endian
>
8353 Target_mips
<size
, big_endian
>::scan_relocatable_relocs(
8354 Symbol_table
* symtab
,
8356 Sized_relobj_file
<size
, big_endian
>* object
,
8357 unsigned int data_shndx
,
8358 unsigned int sh_type
,
8359 const unsigned char* prelocs
,
8361 Output_section
* output_section
,
8362 bool needs_special_offset_handling
,
8363 size_t local_symbol_count
,
8364 const unsigned char* plocal_symbols
,
8365 Relocatable_relocs
* rr
)
8367 gold_assert(sh_type
== elfcpp::SHT_REL
);
8369 typedef Mips_scan_relocatable_relocs
<big_endian
, elfcpp::SHT_REL
,
8370 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
8372 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_REL
,
8373 Scan_relocatable_relocs
>(
8381 needs_special_offset_handling
,
8387 // Emit relocations for a section.
8389 template<int size
, bool big_endian
>
8391 Target_mips
<size
, big_endian
>::relocate_relocs(
8392 const Relocate_info
<size
, big_endian
>* relinfo
,
8393 unsigned int sh_type
,
8394 const unsigned char* prelocs
,
8396 Output_section
* output_section
,
8397 typename
elfcpp::Elf_types
<size
>::Elf_Off
8398 offset_in_output_section
,
8399 const Relocatable_relocs
* rr
,
8400 unsigned char* view
,
8401 Mips_address view_address
,
8402 section_size_type view_size
,
8403 unsigned char* reloc_view
,
8404 section_size_type reloc_view_size
)
8406 gold_assert(sh_type
== elfcpp::SHT_REL
);
8408 gold::relocate_relocs
<size
, big_endian
, elfcpp::SHT_REL
>(
8413 offset_in_output_section
,
8422 // Perform target-specific processing in a relocatable link. This is
8423 // only used if we use the relocation strategy RELOC_SPECIAL.
8425 template<int size
, bool big_endian
>
8427 Target_mips
<size
, big_endian
>::relocate_special_relocatable(
8428 const Relocate_info
<size
, big_endian
>* relinfo
,
8429 unsigned int sh_type
,
8430 const unsigned char* preloc_in
,
8432 Output_section
* output_section
,
8433 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
8434 unsigned char* view
,
8435 Mips_address view_address
,
8437 unsigned char* preloc_out
)
8439 // We can only handle REL type relocation sections.
8440 gold_assert(sh_type
== elfcpp::SHT_REL
);
8442 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
8444 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc_write
8447 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
8449 const Mips_address invalid_address
= static_cast<Mips_address
>(0) - 1;
8451 Mips_relobj
<size
, big_endian
>* object
=
8452 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
8453 const unsigned int local_count
= object
->local_symbol_count();
8455 Reltype
reloc(preloc_in
);
8456 Reltype_write
reloc_write(preloc_out
);
8458 elfcpp::Elf_types
<32>::Elf_WXword r_info
= reloc
.get_r_info();
8459 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
8460 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
8462 // Get the new symbol index.
8463 // We only use RELOC_SPECIAL strategy in local relocations.
8464 gold_assert(r_sym
< local_count
);
8466 // We are adjusting a section symbol. We need to find
8467 // the symbol table index of the section symbol for
8468 // the output section corresponding to input section
8469 // in which this symbol is defined.
8471 unsigned int shndx
= object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
8472 gold_assert(is_ordinary
);
8473 Output_section
* os
= object
->output_section(shndx
);
8474 gold_assert(os
!= NULL
);
8475 gold_assert(os
->needs_symtab_index());
8476 unsigned int new_symndx
= os
->symtab_index();
8478 // Get the new offset--the location in the output section where
8479 // this relocation should be applied.
8481 Mips_address offset
= reloc
.get_r_offset();
8482 Mips_address new_offset
;
8483 if (offset_in_output_section
!= invalid_address
)
8484 new_offset
= offset
+ offset_in_output_section
;
8487 section_offset_type sot_offset
=
8488 convert_types
<section_offset_type
, Mips_address
>(offset
);
8489 section_offset_type new_sot_offset
=
8490 output_section
->output_offset(object
, relinfo
->data_shndx
,
8492 gold_assert(new_sot_offset
!= -1);
8493 new_offset
= new_sot_offset
;
8496 // In an object file, r_offset is an offset within the section.
8497 // In an executable or dynamic object, generated by
8498 // --emit-relocs, r_offset is an absolute address.
8499 if (!parameters
->options().relocatable())
8501 new_offset
+= view_address
;
8502 if (offset_in_output_section
!= invalid_address
)
8503 new_offset
-= offset_in_output_section
;
8506 reloc_write
.put_r_offset(new_offset
);
8507 reloc_write
.put_r_info(elfcpp::elf_r_info
<32>(new_symndx
, r_type
));
8509 // Handle the reloc addend.
8510 // The relocation uses a section symbol in the input file.
8511 // We are adjusting it to use a section symbol in the output
8512 // file. The input section symbol refers to some address in
8513 // the input section. We need the relocation in the output
8514 // file to refer to that same address. This adjustment to
8515 // the addend is the same calculation we use for a simple
8516 // absolute relocation for the input section symbol.
8518 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
8520 unsigned char* paddend
= view
+ offset
;
8521 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
8524 case elfcpp::R_MIPS_26
:
8525 reloc_status
= Reloc_funcs::rel26(paddend
, object
, psymval
,
8526 offset_in_output_section
, true, 0, sh_type
== elfcpp::SHT_REL
, NULL
,
8527 false /*TODO(sasa): cross mode jump*/, r_type
, this->jal_to_bal());
8534 // Report any errors.
8535 switch (reloc_status
)
8537 case Reloc_funcs::STATUS_OKAY
:
8539 case Reloc_funcs::STATUS_OVERFLOW
:
8540 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
8541 _("relocation overflow"));
8543 case Reloc_funcs::STATUS_BAD_RELOC
:
8544 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
8545 _("unexpected opcode while processing relocation"));
8552 // Optimize the TLS relocation type based on what we know about the
8553 // symbol. IS_FINAL is true if the final address of this symbol is
8554 // known at link time.
8556 template<int size
, bool big_endian
>
8557 tls::Tls_optimization
8558 Target_mips
<size
, big_endian
>::optimize_tls_reloc(bool, int)
8560 // FIXME: Currently we do not do any TLS optimization.
8561 return tls::TLSOPT_NONE
;
8564 // Scan a relocation for a local symbol.
8566 template<int size
, bool big_endian
>
8568 Target_mips
<size
, big_endian
>::Scan::local(
8569 Symbol_table
* symtab
,
8571 Target_mips
<size
, big_endian
>* target
,
8572 Sized_relobj_file
<size
, big_endian
>* object
,
8573 unsigned int data_shndx
,
8574 Output_section
* output_section
,
8575 const elfcpp::Rela
<size
, big_endian
>* rela
,
8576 const elfcpp::Rel
<size
, big_endian
>* rel
,
8577 unsigned int rel_type
,
8578 unsigned int r_type
,
8579 const elfcpp::Sym
<size
, big_endian
>& lsym
,
8585 Mips_address r_offset
;
8586 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
;
8587 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
8589 if (rel_type
== elfcpp::SHT_RELA
)
8591 r_offset
= rela
->get_r_offset();
8592 r_info
= rela
->get_r_info();
8593 r_addend
= rela
->get_r_addend();
8597 r_offset
= rel
->get_r_offset();
8598 r_info
= rel
->get_r_info();
8602 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
8603 Mips_relobj
<size
, big_endian
>* mips_obj
=
8604 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
8606 if (mips_obj
->is_mips16_stub_section(data_shndx
))
8608 mips_obj
->get_mips16_stub_section(data_shndx
)
8609 ->new_local_reloc_found(r_type
, r_sym
);
8612 if (r_type
== elfcpp::R_MIPS_NONE
)
8613 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
8617 if (!mips16_call_reloc(r_type
)
8618 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
8619 // This reloc would need to refer to a MIPS16 hard-float stub, if
8620 // there is one. We ignore MIPS16 stub sections and .pdr section when
8621 // looking for relocs that would need to refer to MIPS16 stubs.
8622 mips_obj
->add_local_non_16bit_call(r_sym
);
8624 if (r_type
== elfcpp::R_MIPS16_26
8625 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
8626 mips_obj
->add_local_16bit_call(r_sym
);
8630 case elfcpp::R_MIPS_GOT16
:
8631 case elfcpp::R_MIPS_CALL16
:
8632 case elfcpp::R_MIPS_CALL_HI16
:
8633 case elfcpp::R_MIPS_CALL_LO16
:
8634 case elfcpp::R_MIPS_GOT_HI16
:
8635 case elfcpp::R_MIPS_GOT_LO16
:
8636 case elfcpp::R_MIPS_GOT_PAGE
:
8637 case elfcpp::R_MIPS_GOT_OFST
:
8638 case elfcpp::R_MIPS_GOT_DISP
:
8639 case elfcpp::R_MIPS_TLS_GOTTPREL
:
8640 case elfcpp::R_MIPS_TLS_GD
:
8641 case elfcpp::R_MIPS_TLS_LDM
:
8642 case elfcpp::R_MIPS16_GOT16
:
8643 case elfcpp::R_MIPS16_CALL16
:
8644 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
8645 case elfcpp::R_MIPS16_TLS_GD
:
8646 case elfcpp::R_MIPS16_TLS_LDM
:
8647 case elfcpp::R_MICROMIPS_GOT16
:
8648 case elfcpp::R_MICROMIPS_CALL16
:
8649 case elfcpp::R_MICROMIPS_CALL_HI16
:
8650 case elfcpp::R_MICROMIPS_CALL_LO16
:
8651 case elfcpp::R_MICROMIPS_GOT_HI16
:
8652 case elfcpp::R_MICROMIPS_GOT_LO16
:
8653 case elfcpp::R_MICROMIPS_GOT_PAGE
:
8654 case elfcpp::R_MICROMIPS_GOT_OFST
:
8655 case elfcpp::R_MICROMIPS_GOT_DISP
:
8656 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
8657 case elfcpp::R_MICROMIPS_TLS_GD
:
8658 case elfcpp::R_MICROMIPS_TLS_LDM
:
8659 // We need a GOT section.
8660 target
->got_section(symtab
, layout
);
8667 if (call_lo16_reloc(r_type
)
8668 || got_lo16_reloc(r_type
)
8669 || got_disp_reloc(r_type
))
8671 // We may need a local GOT entry for this relocation. We
8672 // don't count R_MIPS_GOT_PAGE because we can estimate the
8673 // maximum number of pages needed by looking at the size of
8674 // the segment. Similar comments apply to R_MIPS*_GOT16 and
8675 // R_MIPS*_CALL16. We don't count R_MIPS_GOT_HI16, or
8676 // R_MIPS_CALL_HI16 because these are always followed by an
8677 // R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
8678 Mips_output_data_got
<size
, big_endian
>* got
=
8679 target
->got_section(symtab
, layout
);
8680 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
8681 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
, -1U);
8686 case elfcpp::R_MIPS_CALL16
:
8687 case elfcpp::R_MIPS16_CALL16
:
8688 case elfcpp::R_MICROMIPS_CALL16
:
8689 gold_error(_("CALL16 reloc at 0x%lx not against global symbol "),
8690 (unsigned long)r_offset
);
8693 case elfcpp::R_MIPS_GOT_PAGE
:
8694 case elfcpp::R_MICROMIPS_GOT_PAGE
:
8695 case elfcpp::R_MIPS16_GOT16
:
8696 case elfcpp::R_MIPS_GOT16
:
8697 case elfcpp::R_MIPS_GOT_HI16
:
8698 case elfcpp::R_MIPS_GOT_LO16
:
8699 case elfcpp::R_MICROMIPS_GOT16
:
8700 case elfcpp::R_MICROMIPS_GOT_HI16
:
8701 case elfcpp::R_MICROMIPS_GOT_LO16
:
8703 // This relocation needs a page entry in the GOT.
8704 // Get the section contents.
8705 section_size_type view_size
= 0;
8706 const unsigned char* view
= object
->section_contents(data_shndx
,
8710 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
8711 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
8714 if (rel_type
== elfcpp::SHT_REL
&& got16_reloc(r_type
))
8715 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
8716 object
, data_shndx
, r_type
, r_sym
, addend
));
8718 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
, addend
);
8722 case elfcpp::R_MIPS_HI16
:
8723 case elfcpp::R_MIPS16_HI16
:
8724 case elfcpp::R_MICROMIPS_HI16
:
8725 // Record the reloc so that we can check whether the corresponding LO16
8727 if (rel_type
== elfcpp::SHT_REL
)
8728 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
8729 object
, data_shndx
, r_type
, r_sym
, 0));
8732 case elfcpp::R_MIPS_LO16
:
8733 case elfcpp::R_MIPS16_LO16
:
8734 case elfcpp::R_MICROMIPS_LO16
:
8736 if (rel_type
!= elfcpp::SHT_REL
)
8739 // Find corresponding GOT16/HI16 relocation.
8741 // According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
8742 // be immediately following. However, for the IRIX6 ABI, the next
8743 // relocation may be a composed relocation consisting of several
8744 // relocations for the same address. In that case, the R_MIPS_LO16
8745 // relocation may occur as one of these. We permit a similar
8746 // extension in general, as that is useful for GCC.
8748 // In some cases GCC dead code elimination removes the LO16 but
8749 // keeps the corresponding HI16. This is strictly speaking a
8750 // violation of the ABI but not immediately harmful.
8752 typename
std::list
<got16_addend
<size
, big_endian
> >::iterator it
=
8753 target
->got16_addends_
.begin();
8754 while (it
!= target
->got16_addends_
.end())
8756 got16_addend
<size
, big_endian
> _got16_addend
= *it
;
8758 // TODO(sasa): Split got16_addends_ list into two lists - one for
8759 // GOT16 relocs and the other for HI16 relocs.
8761 // Report an error if we find HI16 or GOT16 reloc from the
8762 // previous section without the matching LO16 part.
8763 if (_got16_addend
.object
!= object
8764 || _got16_addend
.shndx
!= data_shndx
)
8766 gold_error("Can't find matching LO16 reloc");
8770 if (_got16_addend
.r_sym
!= r_sym
8771 || !is_matching_lo16_reloc(_got16_addend
.r_type
, r_type
))
8777 // We found a matching HI16 or GOT16 reloc for this LO16 reloc.
8778 // For GOT16, we need to calculate combined addend and record GOT page
8780 if (got16_reloc(_got16_addend
.r_type
))
8783 section_size_type view_size
= 0;
8784 const unsigned char* view
= object
->section_contents(data_shndx
,
8789 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
8790 int32_t addend
= Bits
<16>::sign_extend32(val
& 0xffff);
8792 addend
= (_got16_addend
.addend
<< 16) + addend
;
8793 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
,
8797 it
= target
->got16_addends_
.erase(it
);
8805 case elfcpp::R_MIPS_32
:
8806 case elfcpp::R_MIPS_REL32
:
8807 case elfcpp::R_MIPS_64
:
8809 if (parameters
->options().output_is_position_independent())
8811 // If building a shared library (or a position-independent
8812 // executable), we need to create a dynamic relocation for
8814 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
8815 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(r_info
);
8816 rel_dyn
->add_symbolless_local_addend(object
, r_sym
,
8817 elfcpp::R_MIPS_REL32
,
8818 output_section
, data_shndx
,
8824 case elfcpp::R_MIPS_TLS_GOTTPREL
:
8825 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
8826 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
8827 case elfcpp::R_MIPS_TLS_LDM
:
8828 case elfcpp::R_MIPS16_TLS_LDM
:
8829 case elfcpp::R_MICROMIPS_TLS_LDM
:
8830 case elfcpp::R_MIPS_TLS_GD
:
8831 case elfcpp::R_MIPS16_TLS_GD
:
8832 case elfcpp::R_MICROMIPS_TLS_GD
:
8834 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
8835 bool output_is_shared
= parameters
->options().shared();
8836 const tls::Tls_optimization optimized_type
8837 = Target_mips
<size
, big_endian
>::optimize_tls_reloc(
8838 !output_is_shared
, r_type
);
8841 case elfcpp::R_MIPS_TLS_GD
:
8842 case elfcpp::R_MIPS16_TLS_GD
:
8843 case elfcpp::R_MICROMIPS_TLS_GD
:
8844 if (optimized_type
== tls::TLSOPT_NONE
)
8846 // Create a pair of GOT entries for the module index and
8847 // dtv-relative offset.
8848 Mips_output_data_got
<size
, big_endian
>* got
=
8849 target
->got_section(symtab
, layout
);
8850 unsigned int shndx
= lsym
.get_st_shndx();
8852 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8855 object
->error(_("local symbol %u has bad shndx %u"),
8859 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
8864 // FIXME: TLS optimization not supported yet.
8869 case elfcpp::R_MIPS_TLS_LDM
:
8870 case elfcpp::R_MIPS16_TLS_LDM
:
8871 case elfcpp::R_MICROMIPS_TLS_LDM
:
8872 if (optimized_type
== tls::TLSOPT_NONE
)
8874 // We always record LDM symbols as local with index 0.
8875 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
8881 // FIXME: TLS optimization not supported yet.
8885 case elfcpp::R_MIPS_TLS_GOTTPREL
:
8886 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
8887 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
8888 layout
->set_has_static_tls();
8889 if (optimized_type
== tls::TLSOPT_NONE
)
8891 // Create a GOT entry for the tp-relative offset.
8892 Mips_output_data_got
<size
, big_endian
>* got
=
8893 target
->got_section(symtab
, layout
);
8894 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
8899 // FIXME: TLS optimization not supported yet.
8914 // Refuse some position-dependent relocations when creating a
8915 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
8916 // not PIC, but we can create dynamic relocations and the result
8917 // will be fine. Also do not refuse R_MIPS_LO16, which can be
8918 // combined with R_MIPS_GOT16.
8919 if (parameters
->options().shared())
8923 case elfcpp::R_MIPS16_HI16
:
8924 case elfcpp::R_MIPS_HI16
:
8925 case elfcpp::R_MICROMIPS_HI16
:
8926 // Don't refuse a high part relocation if it's against
8927 // no symbol (e.g. part of a compound relocation).
8933 case elfcpp::R_MIPS16_26
:
8934 case elfcpp::R_MIPS_26
:
8935 case elfcpp::R_MICROMIPS_26_S1
:
8936 gold_error(_("%s: relocation %u against `%s' can not be used when "
8937 "making a shared object; recompile with -fPIC"),
8938 object
->name().c_str(), r_type
, "a local symbol");
8945 template<int size
, bool big_endian
>
8947 Target_mips
<size
, big_endian
>::Scan::local(
8948 Symbol_table
* symtab
,
8950 Target_mips
<size
, big_endian
>* target
,
8951 Sized_relobj_file
<size
, big_endian
>* object
,
8952 unsigned int data_shndx
,
8953 Output_section
* output_section
,
8954 const elfcpp::Rel
<size
, big_endian
>& reloc
,
8955 unsigned int r_type
,
8956 const elfcpp::Sym
<size
, big_endian
>& lsym
,
8969 (const elfcpp::Rela
<size
, big_endian
>*) NULL
,
8973 lsym
, is_discarded
);
8977 template<int size
, bool big_endian
>
8979 Target_mips
<size
, big_endian
>::Scan::local(
8980 Symbol_table
* symtab
,
8982 Target_mips
<size
, big_endian
>* target
,
8983 Sized_relobj_file
<size
, big_endian
>* object
,
8984 unsigned int data_shndx
,
8985 Output_section
* output_section
,
8986 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8987 unsigned int r_type
,
8988 const elfcpp::Sym
<size
, big_endian
>& lsym
,
9002 (const elfcpp::Rel
<size
, big_endian
>*) NULL
,
9005 lsym
, is_discarded
);
9008 // Scan a relocation for a global symbol.
9010 template<int size
, bool big_endian
>
9012 Target_mips
<size
, big_endian
>::Scan::global(
9013 Symbol_table
* symtab
,
9015 Target_mips
<size
, big_endian
>* target
,
9016 Sized_relobj_file
<size
, big_endian
>* object
,
9017 unsigned int data_shndx
,
9018 Output_section
* output_section
,
9019 const elfcpp::Rela
<size
, big_endian
>* rela
,
9020 const elfcpp::Rel
<size
, big_endian
>* rel
,
9021 unsigned int rel_type
,
9022 unsigned int r_type
,
9025 Mips_address r_offset
;
9026 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
;
9027 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
9029 if (rel_type
== elfcpp::SHT_RELA
)
9031 r_offset
= rela
->get_r_offset();
9032 r_info
= rela
->get_r_info();
9033 r_addend
= rela
->get_r_addend();
9037 r_offset
= rel
->get_r_offset();
9038 r_info
= rel
->get_r_info();
9042 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
9043 Mips_relobj
<size
, big_endian
>* mips_obj
=
9044 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
9045 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
9047 if (mips_obj
->is_mips16_stub_section(data_shndx
))
9049 mips_obj
->get_mips16_stub_section(data_shndx
)
9050 ->new_global_reloc_found(r_type
, mips_sym
);
9053 if (r_type
== elfcpp::R_MIPS_NONE
)
9054 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
9058 if (!mips16_call_reloc(r_type
)
9059 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
9060 // This reloc would need to refer to a MIPS16 hard-float stub, if
9061 // there is one. We ignore MIPS16 stub sections and .pdr section when
9062 // looking for relocs that would need to refer to MIPS16 stubs.
9063 mips_sym
->set_need_fn_stub();
9065 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
9066 // section. We check here to avoid creating a dynamic reloc against
9067 // _GLOBAL_OFFSET_TABLE_.
9068 if (!target
->has_got_section()
9069 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9070 target
->got_section(symtab
, layout
);
9072 // We need PLT entries if there are static-only relocations against
9073 // an externally-defined function. This can technically occur for
9074 // shared libraries if there are branches to the symbol, although it
9075 // is unlikely that this will be used in practice due to the short
9076 // ranges involved. It can occur for any relative or absolute relocation
9077 // in executables; in that case, the PLT entry becomes the function's
9078 // canonical address.
9079 bool static_reloc
= false;
9081 // Set CAN_MAKE_DYNAMIC to true if we can convert this
9082 // relocation into a dynamic one.
9083 bool can_make_dynamic
= false;
9086 case elfcpp::R_MIPS_GOT16
:
9087 case elfcpp::R_MIPS_CALL16
:
9088 case elfcpp::R_MIPS_CALL_HI16
:
9089 case elfcpp::R_MIPS_CALL_LO16
:
9090 case elfcpp::R_MIPS_GOT_HI16
:
9091 case elfcpp::R_MIPS_GOT_LO16
:
9092 case elfcpp::R_MIPS_GOT_PAGE
:
9093 case elfcpp::R_MIPS_GOT_OFST
:
9094 case elfcpp::R_MIPS_GOT_DISP
:
9095 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9096 case elfcpp::R_MIPS_TLS_GD
:
9097 case elfcpp::R_MIPS_TLS_LDM
:
9098 case elfcpp::R_MIPS16_GOT16
:
9099 case elfcpp::R_MIPS16_CALL16
:
9100 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9101 case elfcpp::R_MIPS16_TLS_GD
:
9102 case elfcpp::R_MIPS16_TLS_LDM
:
9103 case elfcpp::R_MICROMIPS_GOT16
:
9104 case elfcpp::R_MICROMIPS_CALL16
:
9105 case elfcpp::R_MICROMIPS_CALL_HI16
:
9106 case elfcpp::R_MICROMIPS_CALL_LO16
:
9107 case elfcpp::R_MICROMIPS_GOT_HI16
:
9108 case elfcpp::R_MICROMIPS_GOT_LO16
:
9109 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9110 case elfcpp::R_MICROMIPS_GOT_OFST
:
9111 case elfcpp::R_MICROMIPS_GOT_DISP
:
9112 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9113 case elfcpp::R_MICROMIPS_TLS_GD
:
9114 case elfcpp::R_MICROMIPS_TLS_LDM
:
9115 // We need a GOT section.
9116 target
->got_section(symtab
, layout
);
9119 // This is just a hint; it can safely be ignored. Don't set
9120 // has_static_relocs for the corresponding symbol.
9121 case elfcpp::R_MIPS_JALR
:
9122 case elfcpp::R_MICROMIPS_JALR
:
9125 case elfcpp::R_MIPS_GPREL16
:
9126 case elfcpp::R_MIPS_GPREL32
:
9127 case elfcpp::R_MIPS16_GPREL
:
9128 case elfcpp::R_MICROMIPS_GPREL16
:
9130 // GP-relative relocations always resolve to a definition in a
9131 // regular input file, ignoring the one-definition rule. This is
9132 // important for the GP setup sequence in NewABI code, which
9133 // always resolves to a local function even if other relocations
9134 // against the symbol wouldn't.
9135 //constrain_symbol_p = FALSE;
9138 case elfcpp::R_MIPS_32
:
9139 case elfcpp::R_MIPS_REL32
:
9140 case elfcpp::R_MIPS_64
:
9141 if (parameters
->options().shared()
9142 || strcmp(gsym
->name(), "__gnu_local_gp") != 0)
9144 if (r_type
!= elfcpp::R_MIPS_REL32
)
9146 static_reloc
= true;
9147 mips_sym
->set_pointer_equality_needed();
9149 can_make_dynamic
= true;
9155 // Most static relocations require pointer equality, except
9157 mips_sym
->set_pointer_equality_needed();
9161 case elfcpp::R_MIPS_26
:
9162 case elfcpp::R_MIPS_PC16
:
9163 case elfcpp::R_MIPS16_26
:
9164 case elfcpp::R_MICROMIPS_26_S1
:
9165 case elfcpp::R_MICROMIPS_PC7_S1
:
9166 case elfcpp::R_MICROMIPS_PC10_S1
:
9167 case elfcpp::R_MICROMIPS_PC16_S1
:
9168 case elfcpp::R_MICROMIPS_PC23_S2
:
9169 static_reloc
= true;
9170 mips_sym
->set_has_static_relocs();
9174 // If there are call relocations against an externally-defined symbol,
9175 // see whether we can create a MIPS lazy-binding stub for it. We can
9176 // only do this if all references to the function are through call
9177 // relocations, and in that case, the traditional lazy-binding stubs
9178 // are much more efficient than PLT entries.
9181 case elfcpp::R_MIPS16_CALL16
:
9182 case elfcpp::R_MIPS_CALL16
:
9183 case elfcpp::R_MIPS_CALL_HI16
:
9184 case elfcpp::R_MIPS_CALL_LO16
:
9185 case elfcpp::R_MIPS_JALR
:
9186 case elfcpp::R_MICROMIPS_CALL16
:
9187 case elfcpp::R_MICROMIPS_CALL_HI16
:
9188 case elfcpp::R_MICROMIPS_CALL_LO16
:
9189 case elfcpp::R_MICROMIPS_JALR
:
9190 if (!mips_sym
->no_lazy_stub())
9192 if ((mips_sym
->needs_plt_entry() && mips_sym
->is_from_dynobj())
9193 // Calls from shared objects to undefined symbols of type
9194 // STT_NOTYPE need lazy-binding stub.
9195 || (mips_sym
->is_undefined() && parameters
->options().shared()))
9196 target
->mips_stubs_section(layout
)->make_entry(mips_sym
);
9201 // We must not create a stub for a symbol that has relocations
9202 // related to taking the function's address.
9203 mips_sym
->set_no_lazy_stub();
9204 target
->remove_lazy_stub_entry(mips_sym
);
9209 if (relocation_needs_la25_stub
<size
, big_endian
>(mips_obj
, r_type
,
9210 mips_sym
->is_mips16()))
9211 mips_sym
->set_has_nonpic_branches();
9213 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
9214 // and has a special meaning.
9215 bool gp_disp_against_hi16
= (!mips_obj
->is_newabi()
9216 && strcmp(gsym
->name(), "_gp_disp") == 0
9217 && (hi16_reloc(r_type
) || lo16_reloc(r_type
)));
9218 if (static_reloc
&& gsym
->needs_plt_entry())
9220 target
->make_plt_entry(symtab
, layout
, mips_sym
, r_type
);
9222 // Since this is not a PC-relative relocation, we may be
9223 // taking the address of a function. In that case we need to
9224 // set the entry in the dynamic symbol table to the address of
9226 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
9228 gsym
->set_needs_dynsym_value();
9229 // We distinguish between PLT entries and lazy-binding stubs by
9230 // giving the former an st_other value of STO_MIPS_PLT. Set the
9231 // flag if there are any relocations in the binary where pointer
9232 // equality matters.
9233 if (mips_sym
->pointer_equality_needed())
9234 mips_sym
->set_mips_plt();
9237 if ((static_reloc
|| can_make_dynamic
) && !gp_disp_against_hi16
)
9239 // Absolute addressing relocations.
9240 // Make a dynamic relocation if necessary.
9241 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
9243 if (gsym
->may_need_copy_reloc())
9245 target
->copy_reloc(symtab
, layout
, object
,
9246 data_shndx
, output_section
, gsym
, *rel
);
9248 else if (can_make_dynamic
)
9250 // Create .rel.dyn section.
9251 target
->rel_dyn_section(layout
);
9252 target
->dynamic_reloc(mips_sym
, elfcpp::R_MIPS_REL32
, mips_obj
,
9253 data_shndx
, output_section
, r_offset
);
9256 gold_error(_("non-dynamic relocations refer to dynamic symbol %s"),
9261 bool for_call
= false;
9264 case elfcpp::R_MIPS_CALL16
:
9265 case elfcpp::R_MIPS16_CALL16
:
9266 case elfcpp::R_MICROMIPS_CALL16
:
9267 case elfcpp::R_MIPS_CALL_HI16
:
9268 case elfcpp::R_MIPS_CALL_LO16
:
9269 case elfcpp::R_MICROMIPS_CALL_HI16
:
9270 case elfcpp::R_MICROMIPS_CALL_LO16
:
9274 case elfcpp::R_MIPS16_GOT16
:
9275 case elfcpp::R_MIPS_GOT16
:
9276 case elfcpp::R_MIPS_GOT_HI16
:
9277 case elfcpp::R_MIPS_GOT_LO16
:
9278 case elfcpp::R_MICROMIPS_GOT16
:
9279 case elfcpp::R_MICROMIPS_GOT_HI16
:
9280 case elfcpp::R_MICROMIPS_GOT_LO16
:
9281 case elfcpp::R_MIPS_GOT_DISP
:
9282 case elfcpp::R_MICROMIPS_GOT_DISP
:
9284 // The symbol requires a GOT entry.
9285 Mips_output_data_got
<size
, big_endian
>* got
=
9286 target
->got_section(symtab
, layout
);
9287 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
9289 mips_sym
->set_global_got_area(GGA_NORMAL
);
9293 case elfcpp::R_MIPS_GOT_PAGE
:
9294 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9296 // This relocation needs a page entry in the GOT.
9297 // Get the section contents.
9298 section_size_type view_size
= 0;
9299 const unsigned char* view
=
9300 object
->section_contents(data_shndx
, &view_size
, false);
9303 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
9304 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
9306 Mips_output_data_got
<size
, big_endian
>* got
=
9307 target
->got_section(symtab
, layout
);
9308 got
->record_got_page_entry(mips_obj
, r_sym
, addend
);
9310 // If this is a global, overridable symbol, GOT_PAGE will
9311 // decay to GOT_DISP, so we'll need a GOT entry for it.
9312 bool def_regular
= (mips_sym
->source() == Symbol::FROM_OBJECT
9313 && !mips_sym
->object()->is_dynamic()
9314 && !mips_sym
->is_undefined());
9316 || (parameters
->options().output_is_position_independent()
9317 && !parameters
->options().Bsymbolic()
9318 && !mips_sym
->is_forced_local()))
9320 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
9322 mips_sym
->set_global_got_area(GGA_NORMAL
);
9327 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9328 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9329 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9330 case elfcpp::R_MIPS_TLS_LDM
:
9331 case elfcpp::R_MIPS16_TLS_LDM
:
9332 case elfcpp::R_MICROMIPS_TLS_LDM
:
9333 case elfcpp::R_MIPS_TLS_GD
:
9334 case elfcpp::R_MIPS16_TLS_GD
:
9335 case elfcpp::R_MICROMIPS_TLS_GD
:
9337 const bool is_final
= gsym
->final_value_is_known();
9338 const tls::Tls_optimization optimized_type
=
9339 Target_mips
<size
, big_endian
>::optimize_tls_reloc(is_final
, r_type
);
9343 case elfcpp::R_MIPS_TLS_GD
:
9344 case elfcpp::R_MIPS16_TLS_GD
:
9345 case elfcpp::R_MICROMIPS_TLS_GD
:
9346 if (optimized_type
== tls::TLSOPT_NONE
)
9348 // Create a pair of GOT entries for the module index and
9349 // dtv-relative offset.
9350 Mips_output_data_got
<size
, big_endian
>* got
=
9351 target
->got_section(symtab
, layout
);
9352 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
9357 // FIXME: TLS optimization not supported yet.
9362 case elfcpp::R_MIPS_TLS_LDM
:
9363 case elfcpp::R_MIPS16_TLS_LDM
:
9364 case elfcpp::R_MICROMIPS_TLS_LDM
:
9365 if (optimized_type
== tls::TLSOPT_NONE
)
9367 // We always record LDM symbols as local with index 0.
9368 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
9374 // FIXME: TLS optimization not supported yet.
9378 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9379 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9380 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9381 layout
->set_has_static_tls();
9382 if (optimized_type
== tls::TLSOPT_NONE
)
9384 // Create a GOT entry for the tp-relative offset.
9385 Mips_output_data_got
<size
, big_endian
>* got
=
9386 target
->got_section(symtab
, layout
);
9387 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
9392 // FIXME: TLS optimization not supported yet.
9402 case elfcpp::R_MIPS_COPY
:
9403 case elfcpp::R_MIPS_JUMP_SLOT
:
9404 // These are relocations which should only be seen by the
9405 // dynamic linker, and should never be seen here.
9406 gold_error(_("%s: unexpected reloc %u in object file"),
9407 object
->name().c_str(), r_type
);
9414 // Refuse some position-dependent relocations when creating a
9415 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
9416 // not PIC, but we can create dynamic relocations and the result
9417 // will be fine. Also do not refuse R_MIPS_LO16, which can be
9418 // combined with R_MIPS_GOT16.
9419 if (parameters
->options().shared())
9423 case elfcpp::R_MIPS16_HI16
:
9424 case elfcpp::R_MIPS_HI16
:
9425 case elfcpp::R_MICROMIPS_HI16
:
9426 // Don't refuse a high part relocation if it's against
9427 // no symbol (e.g. part of a compound relocation).
9431 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
9432 // and has a special meaning.
9433 if (!mips_obj
->is_newabi() && strcmp(gsym
->name(), "_gp_disp") == 0)
9438 case elfcpp::R_MIPS16_26
:
9439 case elfcpp::R_MIPS_26
:
9440 case elfcpp::R_MICROMIPS_26_S1
:
9441 gold_error(_("%s: relocation %u against `%s' can not be used when "
9442 "making a shared object; recompile with -fPIC"),
9443 object
->name().c_str(), r_type
, gsym
->name());
9450 template<int size
, bool big_endian
>
9452 Target_mips
<size
, big_endian
>::Scan::global(
9453 Symbol_table
* symtab
,
9455 Target_mips
<size
, big_endian
>* target
,
9456 Sized_relobj_file
<size
, big_endian
>* object
,
9457 unsigned int data_shndx
,
9458 Output_section
* output_section
,
9459 const elfcpp::Rela
<size
, big_endian
>& reloc
,
9460 unsigned int r_type
,
9471 (const elfcpp::Rel
<size
, big_endian
>*) NULL
,
9477 template<int size
, bool big_endian
>
9479 Target_mips
<size
, big_endian
>::Scan::global(
9480 Symbol_table
* symtab
,
9482 Target_mips
<size
, big_endian
>* target
,
9483 Sized_relobj_file
<size
, big_endian
>* object
,
9484 unsigned int data_shndx
,
9485 Output_section
* output_section
,
9486 const elfcpp::Rel
<size
, big_endian
>& reloc
,
9487 unsigned int r_type
,
9497 (const elfcpp::Rela
<size
, big_endian
>*) NULL
,
9504 // Return whether a R_MIPS_32 relocation needs to be applied.
9506 template<int size
, bool big_endian
>
9508 Target_mips
<size
, big_endian
>::Relocate::should_apply_r_mips_32_reloc(
9509 const Mips_symbol
<size
>* gsym
,
9510 unsigned int r_type
,
9511 Output_section
* output_section
,
9512 Target_mips
* target
)
9514 // If the output section is not allocated, then we didn't call
9515 // scan_relocs, we didn't create a dynamic reloc, and we must apply
9517 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
9524 // For global symbols, we use the same helper routines used in the
9526 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
))
9527 && !gsym
->may_need_copy_reloc())
9529 // We have generated dynamic reloc (R_MIPS_REL32).
9531 bool multi_got
= false;
9532 if (target
->has_got_section())
9533 multi_got
= target
->got_section()->multi_got();
9534 bool has_got_offset
;
9536 has_got_offset
= gsym
->has_got_offset(GOT_TYPE_STANDARD
);
9538 has_got_offset
= gsym
->global_gotoffset() != -1U;
9539 if (!has_got_offset
)
9542 // Apply the relocation only if the symbol is in the local got.
9543 // Do not apply the relocation if the symbol is in the global
9545 return symbol_references_local(gsym
, gsym
->has_dynsym_index());
9548 // We have not generated dynamic reloc.
9553 // Perform a relocation.
9555 template<int size
, bool big_endian
>
9557 Target_mips
<size
, big_endian
>::Relocate::relocate(
9558 const Relocate_info
<size
, big_endian
>* relinfo
,
9559 Target_mips
* target
,
9560 Output_section
* output_section
,
9562 const elfcpp::Rela
<size
, big_endian
>* rela
,
9563 const elfcpp::Rel
<size
, big_endian
>* rel
,
9564 unsigned int rel_type
,
9565 unsigned int r_type
,
9566 const Sized_symbol
<size
>* gsym
,
9567 const Symbol_value
<size
>* psymval
,
9568 unsigned char* view
,
9569 Mips_address address
,
9572 Mips_address r_offset
;
9573 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
;
9574 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
9576 if (rel_type
== elfcpp::SHT_RELA
)
9578 r_offset
= rela
->get_r_offset();
9579 r_info
= rela
->get_r_info();
9580 r_addend
= rela
->get_r_addend();
9584 r_offset
= rel
->get_r_offset();
9585 r_info
= rel
->get_r_info();
9589 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
9590 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
9592 Mips_relobj
<size
, big_endian
>* object
=
9593 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
9595 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
9596 bool target_is_16_bit_code
= false;
9597 bool target_is_micromips_code
= false;
9598 bool cross_mode_jump
;
9600 Symbol_value
<size
> symval
;
9602 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
9604 bool changed_symbol_value
= false;
9607 target_is_16_bit_code
= object
->local_symbol_is_mips16(r_sym
);
9608 target_is_micromips_code
= object
->local_symbol_is_micromips(r_sym
);
9609 if (target_is_16_bit_code
|| target_is_micromips_code
)
9611 // MIPS16/microMIPS text labels should be treated as odd.
9612 symval
.set_output_value(psymval
->value(object
, 1));
9614 changed_symbol_value
= true;
9619 target_is_16_bit_code
= mips_sym
->is_mips16();
9620 target_is_micromips_code
= mips_sym
->is_micromips();
9622 // If this is a mips16/microMIPS text symbol, add 1 to the value to make
9623 // it odd. This will cause something like .word SYM to come up with
9624 // the right value when it is loaded into the PC.
9626 if ((mips_sym
->is_mips16() || mips_sym
->is_micromips())
9627 && psymval
->value(object
, 0) != 0)
9629 symval
.set_output_value(psymval
->value(object
, 0) | 1);
9631 changed_symbol_value
= true;
9634 // Pick the value to use for symbols defined in shared objects.
9635 if (mips_sym
->use_plt_offset(Scan::get_reference_flags(r_type
))
9636 || mips_sym
->has_lazy_stub())
9639 if (!mips_sym
->has_lazy_stub())
9641 // Prefer a standard MIPS PLT entry.
9642 if (mips_sym
->has_mips_plt_offset())
9644 value
= target
->plt_section()->mips_entry_address(mips_sym
);
9645 target_is_micromips_code
= false;
9646 target_is_16_bit_code
= false;
9650 value
= (target
->plt_section()->comp_entry_address(mips_sym
)
9652 if (target
->is_output_micromips())
9653 target_is_micromips_code
= true;
9655 target_is_16_bit_code
= true;
9659 value
= target
->mips_stubs_section()->stub_address(mips_sym
);
9661 symval
.set_output_value(value
);
9666 // TRUE if the symbol referred to by this relocation is "_gp_disp".
9667 // Note that such a symbol must always be a global symbol.
9668 bool gp_disp
= (gsym
!= NULL
&& (strcmp(gsym
->name(), "_gp_disp") == 0)
9669 && !object
->is_newabi());
9671 // TRUE if the symbol referred to by this relocation is "__gnu_local_gp".
9672 // Note that such a symbol must always be a global symbol.
9673 bool gnu_local_gp
= gsym
&& (strcmp(gsym
->name(), "__gnu_local_gp") == 0);
9678 if (!hi16_reloc(r_type
) && !lo16_reloc(r_type
))
9679 gold_error_at_location(relinfo
, relnum
, r_offset
,
9680 _("relocations against _gp_disp are permitted only"
9681 " with R_MIPS_HI16 and R_MIPS_LO16 relocations."));
9683 else if (gnu_local_gp
)
9685 // __gnu_local_gp is _gp symbol.
9686 symval
.set_output_value(target
->adjusted_gp_value(object
));
9690 // If this is a reference to a 16-bit function with a stub, we need
9691 // to redirect the relocation to the stub unless:
9693 // (a) the relocation is for a MIPS16 JAL;
9695 // (b) the relocation is for a MIPS16 PIC call, and there are no
9696 // non-MIPS16 uses of the GOT slot; or
9698 // (c) the section allows direct references to MIPS16 functions.
9699 if (r_type
!= elfcpp::R_MIPS16_26
9700 && !parameters
->options().relocatable()
9701 && ((mips_sym
!= NULL
9702 && mips_sym
->has_mips16_fn_stub()
9703 && (r_type
!= elfcpp::R_MIPS16_CALL16
|| mips_sym
->need_fn_stub()))
9704 || (mips_sym
== NULL
9705 && object
->get_local_mips16_fn_stub(r_sym
) != NULL
))
9706 && !object
->section_allows_mips16_refs(relinfo
->data_shndx
))
9708 // This is a 32- or 64-bit call to a 16-bit function. We should
9709 // have already noticed that we were going to need the
9712 if (mips_sym
== NULL
)
9713 value
= object
->get_local_mips16_fn_stub(r_sym
)->output_address();
9716 gold_assert(mips_sym
->need_fn_stub());
9717 if (mips_sym
->has_la25_stub())
9718 value
= target
->la25_stub_section()->stub_address(mips_sym
);
9721 value
= mips_sym
->template
9722 get_mips16_fn_stub
<big_endian
>()->output_address();
9725 symval
.set_output_value(value
);
9727 changed_symbol_value
= true;
9729 // The target is 16-bit, but the stub isn't.
9730 target_is_16_bit_code
= false;
9732 // If this is a MIPS16 call with a stub, that is made through the PLT or
9733 // to a standard MIPS function, we need to redirect the call to the stub.
9734 // Note that we specifically exclude R_MIPS16_CALL16 from this behavior;
9735 // indirect calls should use an indirect stub instead.
9736 else if (r_type
== elfcpp::R_MIPS16_26
&& !parameters
->options().relocatable()
9737 && ((mips_sym
!= NULL
9738 && (mips_sym
->has_mips16_call_stub()
9739 || mips_sym
->has_mips16_call_fp_stub()))
9740 || (mips_sym
== NULL
9741 && object
->get_local_mips16_call_stub(r_sym
) != NULL
))
9742 && ((mips_sym
!= NULL
&& mips_sym
->has_plt_offset())
9743 || !target_is_16_bit_code
))
9745 Mips16_stub_section
<size
, big_endian
>* call_stub
;
9746 if (mips_sym
== NULL
)
9747 call_stub
= object
->get_local_mips16_call_stub(r_sym
);
9750 // If both call_stub and call_fp_stub are defined, we can figure
9751 // out which one to use by checking which one appears in the input
9753 if (mips_sym
->has_mips16_call_stub()
9754 && mips_sym
->has_mips16_call_fp_stub())
9757 for (unsigned int i
= 1; i
< object
->shnum(); ++i
)
9759 if (object
->is_mips16_call_fp_stub_section(i
))
9761 call_stub
= mips_sym
->template
9762 get_mips16_call_fp_stub
<big_endian
>();
9767 if (call_stub
== NULL
)
9769 mips_sym
->template get_mips16_call_stub
<big_endian
>();
9771 else if (mips_sym
->has_mips16_call_stub())
9772 call_stub
= mips_sym
->template get_mips16_call_stub
<big_endian
>();
9774 call_stub
= mips_sym
->template get_mips16_call_fp_stub
<big_endian
>();
9777 symval
.set_output_value(call_stub
->output_address());
9779 changed_symbol_value
= true;
9781 // If this is a direct call to a PIC function, redirect to the
9783 else if (mips_sym
!= NULL
9784 && mips_sym
->has_la25_stub()
9785 && relocation_needs_la25_stub
<size
, big_endian
>(
9786 object
, r_type
, target_is_16_bit_code
))
9788 Mips_address value
= target
->la25_stub_section()->stub_address(mips_sym
);
9789 if (mips_sym
->is_micromips())
9791 symval
.set_output_value(value
);
9794 // For direct MIPS16 and microMIPS calls make sure the compressed PLT
9795 // entry is used if a standard PLT entry has also been made.
9796 else if ((r_type
== elfcpp::R_MIPS16_26
9797 || r_type
== elfcpp::R_MICROMIPS_26_S1
)
9798 && !parameters
->options().relocatable()
9800 && mips_sym
->has_plt_offset()
9801 && mips_sym
->has_comp_plt_offset()
9802 && mips_sym
->has_mips_plt_offset())
9804 Mips_address value
= (target
->plt_section()->comp_entry_address(mips_sym
)
9806 symval
.set_output_value(value
);
9809 target_is_16_bit_code
= !target
->is_output_micromips();
9810 target_is_micromips_code
= target
->is_output_micromips();
9813 // Make sure MIPS16 and microMIPS are not used together.
9814 if ((r_type
== elfcpp::R_MIPS16_26
&& target_is_micromips_code
)
9815 || (micromips_branch_reloc(r_type
) && target_is_16_bit_code
))
9817 gold_error(_("MIPS16 and microMIPS functions cannot call each other"));
9820 // Calls from 16-bit code to 32-bit code and vice versa require the
9821 // mode change. However, we can ignore calls to undefined weak symbols,
9822 // which should never be executed at runtime. This exception is important
9823 // because the assembly writer may have "known" that any definition of the
9824 // symbol would be 16-bit code, and that direct jumps were therefore
9827 (!parameters
->options().relocatable()
9828 && !(gsym
!= NULL
&& gsym
->is_weak_undefined())
9829 && ((r_type
== elfcpp::R_MIPS16_26
&& !target_is_16_bit_code
)
9830 || (r_type
== elfcpp::R_MICROMIPS_26_S1
&& !target_is_micromips_code
)
9831 || ((r_type
== elfcpp::R_MIPS_26
|| r_type
== elfcpp::R_MIPS_JALR
)
9832 && (target_is_16_bit_code
|| target_is_micromips_code
))));
9834 bool local
= (mips_sym
== NULL
9835 || (mips_sym
->got_only_for_calls()
9836 ? symbol_calls_local(mips_sym
, mips_sym
->has_dynsym_index())
9837 : symbol_references_local(mips_sym
,
9838 mips_sym
->has_dynsym_index())));
9840 // Global R_MIPS_GOT_PAGE/R_MICROMIPS_GOT_PAGE relocations are equivalent
9841 // to R_MIPS_GOT_DISP/R_MICROMIPS_GOT_DISP. The addend is applied by the
9842 // corresponding R_MIPS_GOT_OFST/R_MICROMIPS_GOT_OFST.
9843 if (got_page_reloc(r_type
) && !local
)
9844 r_type
= (micromips_reloc(r_type
) ? elfcpp::R_MICROMIPS_GOT_DISP
9845 : elfcpp::R_MIPS_GOT_DISP
);
9847 unsigned int got_offset
= 0;
9850 bool update_got_entry
= false;
9851 bool extract_addend
= rel_type
== elfcpp::SHT_REL
;
9854 case elfcpp::R_MIPS_NONE
:
9856 case elfcpp::R_MIPS_16
:
9857 reloc_status
= Reloc_funcs::rel16(view
, object
, psymval
, r_addend
,
9858 extract_addend
, r_type
);
9861 case elfcpp::R_MIPS_32
:
9862 if (should_apply_r_mips_32_reloc(mips_sym
, r_type
, output_section
,
9864 reloc_status
= Reloc_funcs::rel32(view
, object
, psymval
, r_addend
,
9865 extract_addend
, r_type
);
9866 if (mips_sym
!= NULL
9867 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
9868 && mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
9870 // If mips_sym->has_mips16_fn_stub() is false, symbol value is
9871 // already updated by adding +1.
9872 if (mips_sym
->has_mips16_fn_stub())
9874 gold_assert(mips_sym
->need_fn_stub());
9875 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
9876 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
9878 symval
.set_output_value(fn_stub
->output_address());
9881 got_offset
= mips_sym
->global_gotoffset();
9882 update_got_entry
= true;
9886 case elfcpp::R_MIPS_REL32
:
9889 case elfcpp::R_MIPS_PC32
:
9890 reloc_status
= Reloc_funcs::relpc32(view
, object
, psymval
, address
,
9891 r_addend
, extract_addend
, r_type
);
9894 case elfcpp::R_MIPS16_26
:
9895 // The calculation for R_MIPS16_26 is just the same as for an
9896 // R_MIPS_26. It's only the storage of the relocated field into
9897 // the output file that's different. So, we just fall through to the
9898 // R_MIPS_26 case here.
9899 case elfcpp::R_MIPS_26
:
9900 case elfcpp::R_MICROMIPS_26_S1
:
9901 reloc_status
= Reloc_funcs::rel26(view
, object
, psymval
, address
,
9902 gsym
== NULL
, r_addend
, extract_addend
, gsym
, cross_mode_jump
, r_type
,
9903 target
->jal_to_bal());
9906 case elfcpp::R_MIPS_HI16
:
9907 case elfcpp::R_MIPS16_HI16
:
9908 case elfcpp::R_MICROMIPS_HI16
:
9909 reloc_status
= Reloc_funcs::relhi16(view
, object
, psymval
, r_addend
,
9910 address
, gp_disp
, r_type
,
9914 case elfcpp::R_MIPS_LO16
:
9915 case elfcpp::R_MIPS16_LO16
:
9916 case elfcpp::R_MICROMIPS_LO16
:
9917 case elfcpp::R_MICROMIPS_HI0_LO16
:
9918 reloc_status
= Reloc_funcs::rello16(target
, view
, object
, psymval
,
9919 r_addend
, extract_addend
, address
,
9923 case elfcpp::R_MIPS_LITERAL
:
9924 case elfcpp::R_MICROMIPS_LITERAL
:
9925 // Because we don't merge literal sections, we can handle this
9926 // just like R_MIPS_GPREL16. In the long run, we should merge
9927 // shared literals, and then we will need to additional work
9932 case elfcpp::R_MIPS_GPREL16
:
9933 case elfcpp::R_MIPS16_GPREL
:
9934 case elfcpp::R_MICROMIPS_GPREL7_S2
:
9935 case elfcpp::R_MICROMIPS_GPREL16
:
9936 reloc_status
= Reloc_funcs::relgprel(view
, object
, psymval
,
9937 target
->adjusted_gp_value(object
),
9938 r_addend
, extract_addend
,
9939 gsym
== NULL
, r_type
);
9942 case elfcpp::R_MIPS_PC16
:
9943 reloc_status
= Reloc_funcs::relpc16(view
, object
, psymval
, address
,
9944 r_addend
, extract_addend
, r_type
);
9946 case elfcpp::R_MICROMIPS_PC7_S1
:
9947 reloc_status
= Reloc_funcs::relmicromips_pc7_s1(view
, object
, psymval
,
9949 extract_addend
, r_type
);
9951 case elfcpp::R_MICROMIPS_PC10_S1
:
9952 reloc_status
= Reloc_funcs::relmicromips_pc10_s1(view
, object
, psymval
,
9954 extract_addend
, r_type
);
9956 case elfcpp::R_MICROMIPS_PC16_S1
:
9957 reloc_status
= Reloc_funcs::relmicromips_pc16_s1(view
, object
, psymval
,
9959 extract_addend
, r_type
);
9961 case elfcpp::R_MIPS_GPREL32
:
9962 reloc_status
= Reloc_funcs::relgprel32(view
, object
, psymval
,
9963 target
->adjusted_gp_value(object
),
9964 r_addend
, extract_addend
, r_type
);
9966 case elfcpp::R_MIPS_GOT_HI16
:
9967 case elfcpp::R_MIPS_CALL_HI16
:
9968 case elfcpp::R_MICROMIPS_GOT_HI16
:
9969 case elfcpp::R_MICROMIPS_CALL_HI16
:
9971 got_offset
= target
->got_section()->got_offset(gsym
, GOT_TYPE_STANDARD
,
9974 got_offset
= target
->got_section()->got_offset(r_sym
, GOT_TYPE_STANDARD
,
9976 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
9977 reloc_status
= Reloc_funcs::relgot_hi16(view
, gp_offset
, r_type
);
9978 update_got_entry
= changed_symbol_value
;
9981 case elfcpp::R_MIPS_GOT_LO16
:
9982 case elfcpp::R_MIPS_CALL_LO16
:
9983 case elfcpp::R_MICROMIPS_GOT_LO16
:
9984 case elfcpp::R_MICROMIPS_CALL_LO16
:
9986 got_offset
= target
->got_section()->got_offset(gsym
, GOT_TYPE_STANDARD
,
9989 got_offset
= target
->got_section()->got_offset(r_sym
, GOT_TYPE_STANDARD
,
9991 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
9992 reloc_status
= Reloc_funcs::relgot_lo16(view
, gp_offset
, r_type
);
9993 update_got_entry
= changed_symbol_value
;
9996 case elfcpp::R_MIPS_GOT_DISP
:
9997 case elfcpp::R_MICROMIPS_GOT_DISP
:
9999 got_offset
= target
->got_section()->got_offset(gsym
, GOT_TYPE_STANDARD
,
10002 got_offset
= target
->got_section()->got_offset(r_sym
, GOT_TYPE_STANDARD
,
10004 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10005 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, r_type
);
10008 case elfcpp::R_MIPS_CALL16
:
10009 case elfcpp::R_MIPS16_CALL16
:
10010 case elfcpp::R_MICROMIPS_CALL16
:
10011 gold_assert(gsym
!= NULL
);
10012 got_offset
= target
->got_section()->got_offset(gsym
, GOT_TYPE_STANDARD
,
10014 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10015 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, r_type
);
10016 // TODO(sasa): We should also initialize update_got_entry in other places
10017 // where relgot is called.
10018 update_got_entry
= changed_symbol_value
;
10021 case elfcpp::R_MIPS_GOT16
:
10022 case elfcpp::R_MIPS16_GOT16
:
10023 case elfcpp::R_MICROMIPS_GOT16
:
10026 got_offset
= target
->got_section()->got_offset(gsym
,
10029 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10030 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, r_type
);
10033 reloc_status
= Reloc_funcs::relgot16_local(view
, object
, psymval
,
10034 r_addend
, extract_addend
,
10036 update_got_entry
= changed_symbol_value
;
10039 case elfcpp::R_MIPS_TLS_GD
:
10040 case elfcpp::R_MIPS16_TLS_GD
:
10041 case elfcpp::R_MICROMIPS_TLS_GD
:
10043 got_offset
= target
->got_section()->got_offset(gsym
, GOT_TYPE_TLS_PAIR
,
10046 got_offset
= target
->got_section()->got_offset(r_sym
, GOT_TYPE_TLS_PAIR
,
10048 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10049 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, r_type
);
10052 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10053 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10054 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10056 got_offset
= target
->got_section()->got_offset(gsym
,
10057 GOT_TYPE_TLS_OFFSET
,
10060 got_offset
= target
->got_section()->got_offset(r_sym
,
10061 GOT_TYPE_TLS_OFFSET
,
10063 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10064 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, r_type
);
10067 case elfcpp::R_MIPS_TLS_LDM
:
10068 case elfcpp::R_MIPS16_TLS_LDM
:
10069 case elfcpp::R_MICROMIPS_TLS_LDM
:
10070 // Relocate the field with the offset of the GOT entry for
10071 // the module index.
10072 got_offset
= target
->got_section()->tls_ldm_offset(object
);
10073 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10074 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, r_type
);
10077 case elfcpp::R_MIPS_GOT_PAGE
:
10078 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10079 reloc_status
= Reloc_funcs::relgotpage(target
, view
, object
, psymval
,
10080 r_addend
, extract_addend
, r_type
);
10083 case elfcpp::R_MIPS_GOT_OFST
:
10084 case elfcpp::R_MICROMIPS_GOT_OFST
:
10085 reloc_status
= Reloc_funcs::relgotofst(target
, view
, object
, psymval
,
10086 r_addend
, extract_addend
, local
,
10090 case elfcpp::R_MIPS_JALR
:
10091 case elfcpp::R_MICROMIPS_JALR
:
10092 // This relocation is only a hint. In some cases, we optimize
10093 // it into a bal instruction. But we don't try to optimize
10094 // when the symbol does not resolve locally.
10095 if (gsym
== NULL
|| symbol_calls_local(gsym
, gsym
->has_dynsym_index()))
10096 reloc_status
= Reloc_funcs::reljalr(view
, object
, psymval
, address
,
10097 r_addend
, extract_addend
,
10098 cross_mode_jump
, r_type
,
10099 target
->jalr_to_bal(),
10100 target
->jr_to_b());
10103 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
10104 case elfcpp::R_MIPS16_TLS_DTPREL_HI16
:
10105 case elfcpp::R_MICROMIPS_TLS_DTPREL_HI16
:
10106 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
10107 elfcpp::DTP_OFFSET
, r_addend
,
10108 extract_addend
, r_type
);
10110 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
10111 case elfcpp::R_MIPS16_TLS_DTPREL_LO16
:
10112 case elfcpp::R_MICROMIPS_TLS_DTPREL_LO16
:
10113 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
10114 elfcpp::DTP_OFFSET
, r_addend
,
10115 extract_addend
, r_type
);
10117 case elfcpp::R_MIPS_TLS_DTPREL32
:
10118 case elfcpp::R_MIPS_TLS_DTPREL64
:
10119 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
10120 elfcpp::DTP_OFFSET
, r_addend
,
10121 extract_addend
, r_type
);
10123 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
10124 case elfcpp::R_MIPS16_TLS_TPREL_HI16
:
10125 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
10126 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
10127 elfcpp::TP_OFFSET
, r_addend
,
10128 extract_addend
, r_type
);
10130 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
10131 case elfcpp::R_MIPS16_TLS_TPREL_LO16
:
10132 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
10133 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
10134 elfcpp::TP_OFFSET
, r_addend
,
10135 extract_addend
, r_type
);
10137 case elfcpp::R_MIPS_TLS_TPREL32
:
10138 case elfcpp::R_MIPS_TLS_TPREL64
:
10139 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
10140 elfcpp::TP_OFFSET
, r_addend
,
10141 extract_addend
, r_type
);
10143 case elfcpp::R_MIPS_SUB
:
10144 case elfcpp::R_MICROMIPS_SUB
:
10145 reloc_status
= Reloc_funcs::relsub(view
, object
, psymval
, r_addend
,
10146 extract_addend
, r_type
);
10149 gold_error_at_location(relinfo
, relnum
, r_offset
,
10150 _("unsupported reloc %u"), r_type
);
10154 if (update_got_entry
)
10156 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
10157 if (mips_sym
!= NULL
&& mips_sym
->get_applied_secondary_got_fixup())
10158 got
->update_got_entry(got
->get_primary_got_offset(mips_sym
),
10159 psymval
->value(object
, 0));
10161 got
->update_got_entry(got_offset
, psymval
->value(object
, 0));
10164 // Report any errors.
10165 switch (reloc_status
)
10167 case Reloc_funcs::STATUS_OKAY
:
10169 case Reloc_funcs::STATUS_OVERFLOW
:
10170 gold_error_at_location(relinfo
, relnum
, r_offset
,
10171 _("relocation overflow"));
10173 case Reloc_funcs::STATUS_BAD_RELOC
:
10174 gold_error_at_location(relinfo
, relnum
, r_offset
,
10175 _("unexpected opcode while processing relocation"));
10178 gold_unreachable();
10184 template<int size
, bool big_endian
>
10186 Target_mips
<size
, big_endian
>::Relocate::relocate(
10187 const Relocate_info
<size
, big_endian
>* relinfo
,
10188 Target_mips
* target
,
10189 Output_section
* output_section
,
10191 const elfcpp::Rela
<size
, big_endian
>& reloc
,
10192 unsigned int r_type
,
10193 const Sized_symbol
<size
>* gsym
,
10194 const Symbol_value
<size
>* psymval
,
10195 unsigned char* view
,
10196 Mips_address address
,
10197 section_size_type view_size
)
10205 (const elfcpp::Rel
<size
, big_endian
>*) NULL
,
10215 template<int size
, bool big_endian
>
10217 Target_mips
<size
, big_endian
>::Relocate::relocate(
10218 const Relocate_info
<size
, big_endian
>* relinfo
,
10219 Target_mips
* target
,
10220 Output_section
* output_section
,
10222 const elfcpp::Rel
<size
, big_endian
>& reloc
,
10223 unsigned int r_type
,
10224 const Sized_symbol
<size
>* gsym
,
10225 const Symbol_value
<size
>* psymval
,
10226 unsigned char* view
,
10227 Mips_address address
,
10228 section_size_type view_size
)
10235 (const elfcpp::Rela
<size
, big_endian
>*) NULL
,
10246 // Get the Reference_flags for a particular relocation.
10248 template<int size
, bool big_endian
>
10250 Target_mips
<size
, big_endian
>::Scan::get_reference_flags(
10251 unsigned int r_type
)
10255 case elfcpp::R_MIPS_NONE
:
10256 // No symbol reference.
10259 case elfcpp::R_MIPS_16
:
10260 case elfcpp::R_MIPS_32
:
10261 case elfcpp::R_MIPS_64
:
10262 case elfcpp::R_MIPS_HI16
:
10263 case elfcpp::R_MIPS_LO16
:
10264 case elfcpp::R_MIPS16_HI16
:
10265 case elfcpp::R_MIPS16_LO16
:
10266 case elfcpp::R_MICROMIPS_HI16
:
10267 case elfcpp::R_MICROMIPS_LO16
:
10268 return Symbol::ABSOLUTE_REF
;
10270 case elfcpp::R_MIPS_26
:
10271 case elfcpp::R_MIPS16_26
:
10272 case elfcpp::R_MICROMIPS_26_S1
:
10273 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
10275 case elfcpp::R_MIPS_GPREL32
:
10276 case elfcpp::R_MIPS_GPREL16
:
10277 case elfcpp::R_MIPS_REL32
:
10278 case elfcpp::R_MIPS16_GPREL
:
10279 return Symbol::RELATIVE_REF
;
10281 case elfcpp::R_MIPS_PC16
:
10282 case elfcpp::R_MIPS_PC32
:
10283 case elfcpp::R_MIPS_JALR
:
10284 case elfcpp::R_MICROMIPS_JALR
:
10285 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
10287 case elfcpp::R_MIPS_GOT16
:
10288 case elfcpp::R_MIPS_CALL16
:
10289 case elfcpp::R_MIPS_GOT_DISP
:
10290 case elfcpp::R_MIPS_GOT_HI16
:
10291 case elfcpp::R_MIPS_GOT_LO16
:
10292 case elfcpp::R_MIPS_CALL_HI16
:
10293 case elfcpp::R_MIPS_CALL_LO16
:
10294 case elfcpp::R_MIPS_LITERAL
:
10295 case elfcpp::R_MIPS_GOT_PAGE
:
10296 case elfcpp::R_MIPS_GOT_OFST
:
10297 case elfcpp::R_MIPS16_GOT16
:
10298 case elfcpp::R_MIPS16_CALL16
:
10299 case elfcpp::R_MICROMIPS_GOT16
:
10300 case elfcpp::R_MICROMIPS_CALL16
:
10301 case elfcpp::R_MICROMIPS_GOT_HI16
:
10302 case elfcpp::R_MICROMIPS_GOT_LO16
:
10303 case elfcpp::R_MICROMIPS_CALL_HI16
:
10304 case elfcpp::R_MICROMIPS_CALL_LO16
:
10305 // Absolute in GOT.
10306 return Symbol::RELATIVE_REF
;
10308 case elfcpp::R_MIPS_TLS_DTPMOD32
:
10309 case elfcpp::R_MIPS_TLS_DTPREL32
:
10310 case elfcpp::R_MIPS_TLS_DTPMOD64
:
10311 case elfcpp::R_MIPS_TLS_DTPREL64
:
10312 case elfcpp::R_MIPS_TLS_GD
:
10313 case elfcpp::R_MIPS_TLS_LDM
:
10314 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
10315 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
10316 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10317 case elfcpp::R_MIPS_TLS_TPREL32
:
10318 case elfcpp::R_MIPS_TLS_TPREL64
:
10319 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
10320 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
10321 case elfcpp::R_MIPS16_TLS_GD
:
10322 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10323 case elfcpp::R_MICROMIPS_TLS_GD
:
10324 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10325 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
10326 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
10327 return Symbol::TLS_REF
;
10329 case elfcpp::R_MIPS_COPY
:
10330 case elfcpp::R_MIPS_JUMP_SLOT
:
10332 gold_unreachable();
10333 // Not expected. We will give an error later.
10338 // Report an unsupported relocation against a local symbol.
10340 template<int size
, bool big_endian
>
10342 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_local(
10343 Sized_relobj_file
<size
, big_endian
>* object
,
10344 unsigned int r_type
)
10346 gold_error(_("%s: unsupported reloc %u against local symbol"),
10347 object
->name().c_str(), r_type
);
10350 // Report an unsupported relocation against a global symbol.
10352 template<int size
, bool big_endian
>
10354 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_global(
10355 Sized_relobj_file
<size
, big_endian
>* object
,
10356 unsigned int r_type
,
10359 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
10360 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
10363 // Return printable name for ABI.
10364 template<int size
, bool big_endian
>
10366 Target_mips
<size
, big_endian
>::elf_mips_abi_name(elfcpp::Elf_Word e_flags
,
10367 unsigned char ei_class
)
10369 switch (e_flags
& elfcpp::EF_MIPS_ABI
)
10372 if ((e_flags
& elfcpp::EF_MIPS_ABI2
) != 0)
10374 else if (elfcpp::abi_64(ei_class
))
10378 case elfcpp::E_MIPS_ABI_O32
:
10380 case elfcpp::E_MIPS_ABI_O64
:
10382 case elfcpp::E_MIPS_ABI_EABI32
:
10384 case elfcpp::E_MIPS_ABI_EABI64
:
10387 return "unknown abi";
10391 template<int size
, bool big_endian
>
10393 Target_mips
<size
, big_endian
>::elf_mips_mach_name(elfcpp::Elf_Word e_flags
)
10395 switch (e_flags
& elfcpp::EF_MIPS_MACH
)
10397 case elfcpp::E_MIPS_MACH_3900
:
10398 return "mips:3900";
10399 case elfcpp::E_MIPS_MACH_4010
:
10400 return "mips:4010";
10401 case elfcpp::E_MIPS_MACH_4100
:
10402 return "mips:4100";
10403 case elfcpp::E_MIPS_MACH_4111
:
10404 return "mips:4111";
10405 case elfcpp::E_MIPS_MACH_4120
:
10406 return "mips:4120";
10407 case elfcpp::E_MIPS_MACH_4650
:
10408 return "mips:4650";
10409 case elfcpp::E_MIPS_MACH_5400
:
10410 return "mips:5400";
10411 case elfcpp::E_MIPS_MACH_5500
:
10412 return "mips:5500";
10413 case elfcpp::E_MIPS_MACH_SB1
:
10415 case elfcpp::E_MIPS_MACH_9000
:
10416 return "mips:9000";
10417 case elfcpp::E_MIPS_MACH_LS2E
:
10418 return "mips:loongson-2e";
10419 case elfcpp::E_MIPS_MACH_LS2F
:
10420 return "mips:loongson-2f";
10421 case elfcpp::E_MIPS_MACH_LS3A
:
10422 return "mips:loongson-3a";
10423 case elfcpp::E_MIPS_MACH_OCTEON
:
10424 return "mips:octeon";
10425 case elfcpp::E_MIPS_MACH_OCTEON2
:
10426 return "mips:octeon2";
10427 case elfcpp::E_MIPS_MACH_XLR
:
10430 switch (e_flags
& elfcpp::EF_MIPS_ARCH
)
10433 case elfcpp::E_MIPS_ARCH_1
:
10434 return "mips:3000";
10436 case elfcpp::E_MIPS_ARCH_2
:
10437 return "mips:6000";
10439 case elfcpp::E_MIPS_ARCH_3
:
10440 return "mips:4000";
10442 case elfcpp::E_MIPS_ARCH_4
:
10443 return "mips:8000";
10445 case elfcpp::E_MIPS_ARCH_5
:
10446 return "mips:mips5";
10448 case elfcpp::E_MIPS_ARCH_32
:
10449 return "mips:isa32";
10451 case elfcpp::E_MIPS_ARCH_64
:
10452 return "mips:isa64";
10454 case elfcpp::E_MIPS_ARCH_32R2
:
10455 return "mips:isa32r2";
10457 case elfcpp::E_MIPS_ARCH_64R2
:
10458 return "mips:isa64r2";
10461 return "unknown CPU";
10464 template<int size
, bool big_endian
>
10465 Target::Target_info Target_mips
<size
, big_endian
>::mips_info
=
10468 big_endian
, // is_big_endian
10469 elfcpp::EM_MIPS
, // machine_code
10470 true, // has_make_symbol
10471 false, // has_resolve
10472 false, // has_code_fill
10473 true, // is_default_stack_executable
10474 false, // can_icf_inline_merge_sections
10476 "/lib/ld.so.1", // dynamic_linker
10477 0x400000, // default_text_segment_address
10478 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
10479 4 * 1024, // common_pagesize (overridable by -z common-page-size)
10480 false, // isolate_execinstr
10481 0, // rosegment_gap
10482 elfcpp::SHN_UNDEF
, // small_common_shndx
10483 elfcpp::SHN_UNDEF
, // large_common_shndx
10484 0, // small_common_section_flags
10485 0, // large_common_section_flags
10486 NULL
, // attributes_section
10487 NULL
, // attributes_vendor
10488 "__start" // entry_symbol_name
10491 // The selector for mips object files.
10493 template<int size
, bool big_endian
>
10494 class Target_selector_mips
: public Target_selector
10497 Target_selector_mips()
10498 : Target_selector(elfcpp::EM_MIPS
, size
, big_endian
,
10500 (big_endian
? "elf64-tradbigmips" : "elf64-tradlittlemips") :
10501 (big_endian
? "elf32-tradbigmips" : "elf32-tradlittlemips")),
10503 (big_endian
? "elf64-tradbigmips" : "elf64-tradlittlemips") :
10504 (big_endian
? "elf32-tradbigmips" : "elf32-tradlittlemips")))
10507 Target
* do_instantiate_target()
10508 { return new Target_mips
<size
, big_endian
>(); }
10511 Target_selector_mips
<32, true> target_selector_mips32be
;
10512 Target_selector_mips
<32, false> target_selector_mips32
;
10513 Target_selector_mips
<64, true> target_selector_mips64be
;
10514 Target_selector_mips
<64, false> target_selector_mips64
;
10517 } // End anonymous namespace.