1 // mips.cc -- mips target support for gold.
3 // Copyright (C) 2011-2016 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"
53 template<int size
, bool big_endian
>
54 class Mips_output_data_plt
;
56 template<int size
, bool big_endian
>
57 class Mips_output_data_got
;
59 template<int size
, bool big_endian
>
62 template<int size
, bool big_endian
>
63 class Mips_output_section_reginfo
;
65 template<int size
, bool big_endian
>
66 class Mips_output_data_la25_stub
;
68 template<int size
, bool big_endian
>
69 class Mips_output_data_mips_stubs
;
74 template<int size
, bool big_endian
>
77 template<int size
, bool big_endian
>
80 class Mips16_stub_section_base
;
82 template<int size
, bool big_endian
>
83 class Mips16_stub_section
;
85 // The ABI says that every symbol used by dynamic relocations must have
86 // a global GOT entry. Among other things, this provides the dynamic
87 // linker with a free, directly-indexed cache. The GOT can therefore
88 // contain symbols that are not referenced by GOT relocations themselves
89 // (in other words, it may have symbols that are not referenced by things
90 // like R_MIPS_GOT16 and R_MIPS_GOT_PAGE).
92 // GOT relocations are less likely to overflow if we put the associated
93 // GOT entries towards the beginning. We therefore divide the global
94 // GOT entries into two areas: "normal" and "reloc-only". Entries in
95 // the first area can be used for both dynamic relocations and GP-relative
96 // accesses, while those in the "reloc-only" area are for dynamic
99 // These GGA_* ("Global GOT Area") values are organised so that lower
100 // values are more general than higher values. Also, non-GGA_NONE
101 // values are ordered by the position of the area in the GOT.
110 // The types of GOT entries needed for this platform.
111 // These values are exposed to the ABI in an incremental link.
112 // Do not renumber existing values without changing the version
113 // number of the .gnu_incremental_inputs section.
116 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
117 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
118 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
120 // GOT entries for multi-GOT. We support up to 1024 GOTs in multi-GOT links.
121 GOT_TYPE_STANDARD_MULTIGOT
= 3,
122 GOT_TYPE_TLS_OFFSET_MULTIGOT
= GOT_TYPE_STANDARD_MULTIGOT
+ 1024,
123 GOT_TYPE_TLS_PAIR_MULTIGOT
= GOT_TYPE_TLS_OFFSET_MULTIGOT
+ 1024
126 // TLS type of GOT entry.
135 // Return TRUE if a relocation of type R_TYPE from OBJECT might
136 // require an la25 stub. See also local_pic_function, which determines
137 // whether the destination function ever requires a stub.
138 template<int size
, bool big_endian
>
140 relocation_needs_la25_stub(Mips_relobj
<size
, big_endian
>* object
,
141 unsigned int r_type
, bool target_is_16_bit_code
)
143 // We specifically ignore branches and jumps from EF_PIC objects,
144 // where the onus is on the compiler or programmer to perform any
145 // necessary initialization of $25. Sometimes such initialization
146 // is unnecessary; for example, -mno-shared functions do not use
147 // the incoming value of $25, and may therefore be called directly.
148 if (object
->is_pic())
153 case elfcpp::R_MIPS_26
:
154 case elfcpp::R_MIPS_PC16
:
155 case elfcpp::R_MICROMIPS_26_S1
:
156 case elfcpp::R_MICROMIPS_PC7_S1
:
157 case elfcpp::R_MICROMIPS_PC10_S1
:
158 case elfcpp::R_MICROMIPS_PC16_S1
:
159 case elfcpp::R_MICROMIPS_PC23_S2
:
162 case elfcpp::R_MIPS16_26
:
163 return !target_is_16_bit_code
;
170 // Return true if SYM is a locally-defined PIC function, in the sense
171 // that it or its fn_stub might need $25 to be valid on entry.
172 // Note that MIPS16 functions set up $gp using PC-relative instructions,
173 // so they themselves never need $25 to be valid. Only non-MIPS16
174 // entry points are of interest here.
175 template<int size
, bool big_endian
>
177 local_pic_function(Mips_symbol
<size
>* sym
)
179 bool def_regular
= (sym
->source() == Symbol::FROM_OBJECT
180 && !sym
->object()->is_dynamic()
181 && !sym
->is_undefined());
183 if (sym
->is_defined() && def_regular
)
185 Mips_relobj
<size
, big_endian
>* object
=
186 static_cast<Mips_relobj
<size
, big_endian
>*>(sym
->object());
188 if ((object
->is_pic() || sym
->is_pic())
189 && (!sym
->is_mips16()
190 || (sym
->has_mips16_fn_stub() && sym
->need_fn_stub())))
197 hi16_reloc(int r_type
)
199 return (r_type
== elfcpp::R_MIPS_HI16
200 || r_type
== elfcpp::R_MIPS16_HI16
201 || r_type
== elfcpp::R_MICROMIPS_HI16
);
205 lo16_reloc(int r_type
)
207 return (r_type
== elfcpp::R_MIPS_LO16
208 || r_type
== elfcpp::R_MIPS16_LO16
209 || r_type
== elfcpp::R_MICROMIPS_LO16
);
213 got16_reloc(unsigned int r_type
)
215 return (r_type
== elfcpp::R_MIPS_GOT16
216 || r_type
== elfcpp::R_MIPS16_GOT16
217 || r_type
== elfcpp::R_MICROMIPS_GOT16
);
221 call_lo16_reloc(unsigned int r_type
)
223 return (r_type
== elfcpp::R_MIPS_CALL_LO16
224 || r_type
== elfcpp::R_MICROMIPS_CALL_LO16
);
228 got_lo16_reloc(unsigned int r_type
)
230 return (r_type
== elfcpp::R_MIPS_GOT_LO16
231 || r_type
== elfcpp::R_MICROMIPS_GOT_LO16
);
235 got_disp_reloc(unsigned int r_type
)
237 return (r_type
== elfcpp::R_MIPS_GOT_DISP
238 || r_type
== elfcpp::R_MICROMIPS_GOT_DISP
);
242 got_page_reloc(unsigned int r_type
)
244 return (r_type
== elfcpp::R_MIPS_GOT_PAGE
245 || r_type
== elfcpp::R_MICROMIPS_GOT_PAGE
);
249 tls_gd_reloc(unsigned int r_type
)
251 return (r_type
== elfcpp::R_MIPS_TLS_GD
252 || r_type
== elfcpp::R_MIPS16_TLS_GD
253 || r_type
== elfcpp::R_MICROMIPS_TLS_GD
);
257 tls_gottprel_reloc(unsigned int r_type
)
259 return (r_type
== elfcpp::R_MIPS_TLS_GOTTPREL
260 || r_type
== elfcpp::R_MIPS16_TLS_GOTTPREL
261 || r_type
== elfcpp::R_MICROMIPS_TLS_GOTTPREL
);
265 tls_ldm_reloc(unsigned int r_type
)
267 return (r_type
== elfcpp::R_MIPS_TLS_LDM
268 || r_type
== elfcpp::R_MIPS16_TLS_LDM
269 || r_type
== elfcpp::R_MICROMIPS_TLS_LDM
);
273 mips16_call_reloc(unsigned int r_type
)
275 return (r_type
== elfcpp::R_MIPS16_26
276 || r_type
== elfcpp::R_MIPS16_CALL16
);
280 jal_reloc(unsigned int r_type
)
282 return (r_type
== elfcpp::R_MIPS_26
283 || r_type
== elfcpp::R_MIPS16_26
284 || r_type
== elfcpp::R_MICROMIPS_26_S1
);
288 micromips_branch_reloc(unsigned int r_type
)
290 return (r_type
== elfcpp::R_MICROMIPS_26_S1
291 || r_type
== elfcpp::R_MICROMIPS_PC16_S1
292 || r_type
== elfcpp::R_MICROMIPS_PC10_S1
293 || r_type
== elfcpp::R_MICROMIPS_PC7_S1
);
296 // Check if R_TYPE is a MIPS16 reloc.
298 mips16_reloc(unsigned int r_type
)
302 case elfcpp::R_MIPS16_26
:
303 case elfcpp::R_MIPS16_GPREL
:
304 case elfcpp::R_MIPS16_GOT16
:
305 case elfcpp::R_MIPS16_CALL16
:
306 case elfcpp::R_MIPS16_HI16
:
307 case elfcpp::R_MIPS16_LO16
:
308 case elfcpp::R_MIPS16_TLS_GD
:
309 case elfcpp::R_MIPS16_TLS_LDM
:
310 case elfcpp::R_MIPS16_TLS_DTPREL_HI16
:
311 case elfcpp::R_MIPS16_TLS_DTPREL_LO16
:
312 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
313 case elfcpp::R_MIPS16_TLS_TPREL_HI16
:
314 case elfcpp::R_MIPS16_TLS_TPREL_LO16
:
322 // Check if R_TYPE is a microMIPS reloc.
324 micromips_reloc(unsigned int r_type
)
328 case elfcpp::R_MICROMIPS_26_S1
:
329 case elfcpp::R_MICROMIPS_HI16
:
330 case elfcpp::R_MICROMIPS_LO16
:
331 case elfcpp::R_MICROMIPS_GPREL16
:
332 case elfcpp::R_MICROMIPS_LITERAL
:
333 case elfcpp::R_MICROMIPS_GOT16
:
334 case elfcpp::R_MICROMIPS_PC7_S1
:
335 case elfcpp::R_MICROMIPS_PC10_S1
:
336 case elfcpp::R_MICROMIPS_PC16_S1
:
337 case elfcpp::R_MICROMIPS_CALL16
:
338 case elfcpp::R_MICROMIPS_GOT_DISP
:
339 case elfcpp::R_MICROMIPS_GOT_PAGE
:
340 case elfcpp::R_MICROMIPS_GOT_OFST
:
341 case elfcpp::R_MICROMIPS_GOT_HI16
:
342 case elfcpp::R_MICROMIPS_GOT_LO16
:
343 case elfcpp::R_MICROMIPS_SUB
:
344 case elfcpp::R_MICROMIPS_HIGHER
:
345 case elfcpp::R_MICROMIPS_HIGHEST
:
346 case elfcpp::R_MICROMIPS_CALL_HI16
:
347 case elfcpp::R_MICROMIPS_CALL_LO16
:
348 case elfcpp::R_MICROMIPS_SCN_DISP
:
349 case elfcpp::R_MICROMIPS_JALR
:
350 case elfcpp::R_MICROMIPS_HI0_LO16
:
351 case elfcpp::R_MICROMIPS_TLS_GD
:
352 case elfcpp::R_MICROMIPS_TLS_LDM
:
353 case elfcpp::R_MICROMIPS_TLS_DTPREL_HI16
:
354 case elfcpp::R_MICROMIPS_TLS_DTPREL_LO16
:
355 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
356 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
357 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
358 case elfcpp::R_MICROMIPS_GPREL7_S2
:
359 case elfcpp::R_MICROMIPS_PC23_S2
:
368 is_matching_lo16_reloc(unsigned int high_reloc
, unsigned int lo16_reloc
)
372 case elfcpp::R_MIPS_HI16
:
373 case elfcpp::R_MIPS_GOT16
:
374 return lo16_reloc
== elfcpp::R_MIPS_LO16
;
375 case elfcpp::R_MIPS16_HI16
:
376 case elfcpp::R_MIPS16_GOT16
:
377 return lo16_reloc
== elfcpp::R_MIPS16_LO16
;
378 case elfcpp::R_MICROMIPS_HI16
:
379 case elfcpp::R_MICROMIPS_GOT16
:
380 return lo16_reloc
== elfcpp::R_MICROMIPS_LO16
;
386 // This class is used to hold information about one GOT entry.
387 // There are three types of entry:
389 // (1) a SYMBOL + OFFSET address, where SYMBOL is local to an input object
390 // (object != NULL, symndx >= 0, tls_type != GOT_TLS_LDM)
391 // (2) a SYMBOL address, where SYMBOL is not local to an input object
392 // (object != NULL, symndx == -1)
393 // (3) a TLS LDM slot
394 // (object != NULL, symndx == 0, tls_type == GOT_TLS_LDM)
396 template<int size
, bool big_endian
>
399 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
402 Mips_got_entry(Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
,
403 Mips_address addend
, unsigned char tls_type
,
405 : object_(object
), symndx_(symndx
), tls_type_(tls_type
), shndx_(shndx
)
406 { this->d
.addend
= addend
; }
408 Mips_got_entry(Mips_relobj
<size
, big_endian
>* object
, Mips_symbol
<size
>* sym
,
409 unsigned char tls_type
)
410 : object_(object
), symndx_(-1U), tls_type_(tls_type
), shndx_(-1U)
411 { this->d
.sym
= sym
; }
413 // Return whether this entry is for a local symbol.
415 is_for_local_symbol() const
416 { return this->symndx_
!= -1U; }
418 // Return whether this entry is for a global symbol.
420 is_for_global_symbol() const
421 { return this->symndx_
== -1U; }
423 // Return the hash of this entry.
427 if (this->tls_type_
== GOT_TLS_LDM
)
428 return this->symndx_
+ (1 << 18);
429 if (this->symndx_
!= -1U)
431 uintptr_t object_id
= reinterpret_cast<uintptr_t>(this->object());
432 return this->symndx_
+ object_id
+ this->d
.addend
;
436 uintptr_t sym_id
= reinterpret_cast<uintptr_t>(this->d
.sym
);
437 return this->symndx_
+ sym_id
;
441 // Return whether this entry is equal to OTHER.
443 equals(Mips_got_entry
<size
, big_endian
>* other
) const
445 if (this->symndx_
!= other
->symndx_
446 || this->tls_type_
!= other
->tls_type_
)
448 if (this->tls_type_
== GOT_TLS_LDM
)
450 if (this->symndx_
!= -1U)
451 return (this->object() == other
->object()
452 && this->d
.addend
== other
->d
.addend
);
454 return this->d
.sym
== other
->d
.sym
;
457 // Return input object that needs this GOT entry.
458 Mips_relobj
<size
, big_endian
>*
461 gold_assert(this->object_
!= NULL
);
462 return this->object_
;
465 // Return local symbol index for local GOT entries.
469 gold_assert(this->symndx_
!= -1U);
470 return this->symndx_
;
473 // Return the relocation addend for local GOT entries.
477 gold_assert(this->symndx_
!= -1U);
478 return this->d
.addend
;
481 // Return global symbol for global GOT entries.
485 gold_assert(this->symndx_
== -1U);
489 // Return whether this is a TLS GOT entry.
492 { return this->tls_type_
!= GOT_TLS_NONE
; }
494 // Return TLS type of this GOT entry.
497 { return this->tls_type_
; }
499 // Return section index of the local symbol for local GOT entries.
502 { return this->shndx_
; }
505 // The input object that needs the GOT entry.
506 Mips_relobj
<size
, big_endian
>* object_
;
507 // The index of the symbol if we have a local symbol; -1 otherwise.
508 unsigned int symndx_
;
512 // If symndx != -1, the addend of the relocation that should be added to the
515 // If symndx == -1, the global symbol corresponding to this GOT entry. The
516 // symbol's entry is in the local area if mips_sym->global_got_area is
517 // GGA_NONE, otherwise it is in the global area.
518 Mips_symbol
<size
>* sym
;
521 // The TLS type of this GOT entry. An LDM GOT entry will be a local
522 // symbol entry with r_symndx == 0.
523 unsigned char tls_type_
;
525 // For local GOT entries, section index of the local symbol.
529 // Hash for Mips_got_entry.
531 template<int size
, bool big_endian
>
532 class Mips_got_entry_hash
536 operator()(Mips_got_entry
<size
, big_endian
>* entry
) const
537 { return entry
->hash(); }
540 // Equality for Mips_got_entry.
542 template<int size
, bool big_endian
>
543 class Mips_got_entry_eq
547 operator()(Mips_got_entry
<size
, big_endian
>* e1
,
548 Mips_got_entry
<size
, big_endian
>* e2
) const
549 { return e1
->equals(e2
); }
552 // Got_page_range. This class describes a range of addends: [MIN_ADDEND,
553 // MAX_ADDEND]. The instances form a non-overlapping list that is sorted by
554 // increasing MIN_ADDEND.
556 struct Got_page_range
559 : next(NULL
), min_addend(0), max_addend(0)
562 Got_page_range
* next
;
566 // Return the maximum number of GOT page entries required.
569 { return (this->max_addend
- this->min_addend
+ 0x1ffff) >> 16; }
572 // Got_page_entry. This class describes the range of addends that are applied
573 // to page relocations against a given symbol.
575 struct Got_page_entry
578 : object(NULL
), symndx(-1U), ranges(NULL
), num_pages(0)
581 Got_page_entry(Object
* object_
, unsigned int symndx_
)
582 : object(object_
), symndx(symndx_
), ranges(NULL
), num_pages(0)
585 // The input object that needs the GOT page entry.
587 // The index of the symbol, as stored in the relocation r_info.
589 // The ranges for this page entry.
590 Got_page_range
* ranges
;
591 // The maximum number of page entries needed for RANGES.
592 unsigned int num_pages
;
595 // Hash for Got_page_entry.
597 struct Got_page_entry_hash
600 operator()(Got_page_entry
* entry
) const
601 { return reinterpret_cast<uintptr_t>(entry
->object
) + entry
->symndx
; }
604 // Equality for Got_page_entry.
606 struct Got_page_entry_eq
609 operator()(Got_page_entry
* entry1
, Got_page_entry
* entry2
) const
611 return entry1
->object
== entry2
->object
&& entry1
->symndx
== entry2
->symndx
;
615 // This class is used to hold .got information when linking.
617 template<int size
, bool big_endian
>
620 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
621 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
623 typedef Unordered_map
<unsigned int, unsigned int> Got_page_offsets
;
625 // Unordered set of GOT entries.
626 typedef Unordered_set
<Mips_got_entry
<size
, big_endian
>*,
627 Mips_got_entry_hash
<size
, big_endian
>,
628 Mips_got_entry_eq
<size
, big_endian
> > Got_entry_set
;
630 // Unordered set of GOT page entries.
631 typedef Unordered_set
<Got_page_entry
*,
632 Got_page_entry_hash
, Got_page_entry_eq
> Got_page_entry_set
;
636 : local_gotno_(0), page_gotno_(0), global_gotno_(0), reloc_only_gotno_(0),
637 tls_gotno_(0), tls_ldm_offset_(-1U), global_got_symbols_(),
638 got_entries_(), got_page_entries_(), got_page_offset_start_(0),
639 got_page_offset_next_(0), got_page_offsets_(), next_(NULL
), index_(-1U),
643 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
644 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
646 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
647 unsigned int symndx
, Mips_address addend
,
648 unsigned int r_type
, unsigned int shndx
);
650 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
651 // in OBJECT. FOR_CALL is true if the caller is only interested in
652 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
655 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
656 Mips_relobj
<size
, big_endian
>* object
,
657 unsigned int r_type
, bool dyn_reloc
, bool for_call
);
659 // Add ENTRY to master GOT and to OBJECT's GOT.
661 record_got_entry(Mips_got_entry
<size
, big_endian
>* entry
,
662 Mips_relobj
<size
, big_endian
>* object
);
664 // Record that OBJECT has a page relocation against symbol SYMNDX and
665 // that ADDEND is the addend for that relocation.
667 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
668 unsigned int symndx
, int addend
);
670 // Create all entries that should be in the local part of the GOT.
672 add_local_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
674 // Create GOT page entries.
676 add_page_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
678 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
680 add_global_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
681 unsigned int non_reloc_only_global_gotno
);
683 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
685 add_reloc_only_entries(Mips_output_data_got
<size
, big_endian
>* got
);
687 // Create TLS GOT entries.
689 add_tls_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
691 // Decide whether the symbol needs an entry in the global part of the primary
692 // GOT, setting global_got_area accordingly. Count the number of global
693 // symbols that are in the primary GOT only because they have dynamic
694 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
696 count_got_symbols(Symbol_table
* symtab
);
698 // Return the offset of GOT page entry for VALUE.
700 get_got_page_offset(Mips_address value
,
701 Mips_output_data_got
<size
, big_endian
>* got
);
703 // Count the number of GOT entries required.
707 // Count the number of GOT entries required by ENTRY. Accumulate the result.
709 count_got_entry(Mips_got_entry
<size
, big_endian
>* entry
);
711 // Add FROM's GOT entries.
713 add_got_entries(Mips_got_info
<size
, big_endian
>* from
);
715 // Add FROM's GOT page entries.
717 add_got_page_entries(Mips_got_info
<size
, big_endian
>* from
);
722 { return ((2 + this->local_gotno_
+ this->page_gotno_
+ this->global_gotno_
723 + this->tls_gotno_
) * size
/8);
726 // Return the number of local GOT entries.
729 { return this->local_gotno_
; }
731 // Return the maximum number of page GOT entries needed.
734 { return this->page_gotno_
; }
736 // Return the number of global GOT entries.
739 { return this->global_gotno_
; }
741 // Set the number of global GOT entries.
743 set_global_gotno(unsigned int global_gotno
)
744 { this->global_gotno_
= global_gotno
; }
746 // Return the number of GGA_RELOC_ONLY global GOT entries.
748 reloc_only_gotno() const
749 { return this->reloc_only_gotno_
; }
751 // Return the number of TLS GOT entries.
754 { return this->tls_gotno_
; }
756 // Return the GOT type for this GOT. Used for multi-GOT links only.
758 multigot_got_type(unsigned int got_type
) const
762 case GOT_TYPE_STANDARD
:
763 return GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
764 case GOT_TYPE_TLS_OFFSET
:
765 return GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
766 case GOT_TYPE_TLS_PAIR
:
767 return GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
773 // Remove lazy-binding stubs for global symbols in this GOT.
775 remove_lazy_stubs(Target_mips
<size
, big_endian
>* target
);
777 // Return offset of this GOT from the start of .got section.
780 { return this->offset_
; }
782 // Set offset of this GOT from the start of .got section.
784 set_offset(unsigned int offset
)
785 { this->offset_
= offset
; }
787 // Set index of this GOT in multi-GOT links.
789 set_index(unsigned int index
)
790 { this->index_
= index
; }
792 // Return next GOT in multi-GOT links.
793 Mips_got_info
<size
, big_endian
>*
795 { return this->next_
; }
797 // Set next GOT in multi-GOT links.
799 set_next(Mips_got_info
<size
, big_endian
>* next
)
800 { this->next_
= next
; }
802 // Return the offset of TLS LDM entry for this GOT.
804 tls_ldm_offset() const
805 { return this->tls_ldm_offset_
; }
807 // Set the offset of TLS LDM entry for this GOT.
809 set_tls_ldm_offset(unsigned int tls_ldm_offset
)
810 { this->tls_ldm_offset_
= tls_ldm_offset
; }
812 Unordered_set
<Mips_symbol
<size
>*>&
814 { return this->global_got_symbols_
; }
816 // Return the GOT_TLS_* type required by relocation type R_TYPE.
818 mips_elf_reloc_tls_type(unsigned int r_type
)
820 if (tls_gd_reloc(r_type
))
823 if (tls_ldm_reloc(r_type
))
826 if (tls_gottprel_reloc(r_type
))
832 // Return the number of GOT slots needed for GOT TLS type TYPE.
834 mips_tls_got_entries(unsigned int type
)
854 // The number of local GOT entries.
855 unsigned int local_gotno_
;
856 // The maximum number of page GOT entries needed.
857 unsigned int page_gotno_
;
858 // The number of global GOT entries.
859 unsigned int global_gotno_
;
860 // The number of global GOT entries that are in the GGA_RELOC_ONLY area.
861 unsigned int reloc_only_gotno_
;
862 // The number of TLS GOT entries.
863 unsigned int tls_gotno_
;
864 // The offset of TLS LDM entry for this GOT.
865 unsigned int tls_ldm_offset_
;
866 // All symbols that have global GOT entry.
867 Unordered_set
<Mips_symbol
<size
>*> global_got_symbols_
;
868 // A hash table holding GOT entries.
869 Got_entry_set got_entries_
;
870 // A hash table of GOT page entries.
871 Got_page_entry_set got_page_entries_
;
872 // The offset of first GOT page entry for this GOT.
873 unsigned int got_page_offset_start_
;
874 // The offset of next available GOT page entry for this GOT.
875 unsigned int got_page_offset_next_
;
876 // A hash table that maps GOT page entry value to the GOT offset where
877 // the entry is located.
878 Got_page_offsets got_page_offsets_
;
879 // In multi-GOT links, a pointer to the next GOT.
880 Mips_got_info
<size
, big_endian
>* next_
;
881 // Index of this GOT in multi-GOT links.
883 // The offset of this GOT in multi-GOT links.
884 unsigned int offset_
;
887 // This is a helper class used during relocation scan. It records GOT16 addend.
889 template<int size
, bool big_endian
>
892 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
894 got16_addend(const Sized_relobj_file
<size
, big_endian
>* _object
,
895 unsigned int _shndx
, unsigned int _r_type
, unsigned int _r_sym
,
896 Mips_address _addend
)
897 : object(_object
), shndx(_shndx
), r_type(_r_type
), r_sym(_r_sym
),
901 const Sized_relobj_file
<size
, big_endian
>* object
;
908 // Mips_symbol class. Holds additional symbol information needed for Mips.
911 class Mips_symbol
: public Sized_symbol
<size
>
915 : need_fn_stub_(false), has_nonpic_branches_(false), la25_stub_offset_(-1U),
916 has_static_relocs_(false), no_lazy_stub_(false), lazy_stub_offset_(0),
917 pointer_equality_needed_(false), global_got_area_(GGA_NONE
),
918 global_gotoffset_(-1U), got_only_for_calls_(true), has_lazy_stub_(false),
919 needs_mips_plt_(false), needs_comp_plt_(false), mips_plt_offset_(-1U),
920 comp_plt_offset_(-1U), mips16_fn_stub_(NULL
), mips16_call_stub_(NULL
),
921 mips16_call_fp_stub_(NULL
), applied_secondary_got_fixup_(false)
924 // Return whether this is a MIPS16 symbol.
928 // (st_other & STO_MIPS16) == STO_MIPS16
929 return ((this->nonvis() & (elfcpp::STO_MIPS16
>> 2))
930 == elfcpp::STO_MIPS16
>> 2);
933 // Return whether this is a microMIPS symbol.
937 // (st_other & STO_MIPS_ISA) == STO_MICROMIPS
938 return ((this->nonvis() & (elfcpp::STO_MIPS_ISA
>> 2))
939 == elfcpp::STO_MICROMIPS
>> 2);
942 // Return whether the symbol needs MIPS16 fn_stub.
945 { return this->need_fn_stub_
; }
947 // Set that the symbol needs MIPS16 fn_stub.
950 { this->need_fn_stub_
= true; }
952 // Return whether this symbol is referenced by branch relocations from
953 // any non-PIC input file.
955 has_nonpic_branches() const
956 { return this->has_nonpic_branches_
; }
958 // Set that this symbol is referenced by branch relocations from
959 // any non-PIC input file.
961 set_has_nonpic_branches()
962 { this->has_nonpic_branches_
= true; }
964 // Return the offset of the la25 stub for this symbol from the start of the
965 // la25 stub section.
967 la25_stub_offset() const
968 { return this->la25_stub_offset_
; }
970 // Set the offset of the la25 stub for this symbol from the start of the
971 // la25 stub section.
973 set_la25_stub_offset(unsigned int offset
)
974 { this->la25_stub_offset_
= offset
; }
976 // Return whether the symbol has la25 stub. This is true if this symbol is
977 // for a PIC function, and there are non-PIC branches and jumps to it.
979 has_la25_stub() const
980 { return this->la25_stub_offset_
!= -1U; }
982 // Return whether there is a relocation against this symbol that must be
983 // resolved by the static linker (that is, the relocation cannot possibly
986 has_static_relocs() const
987 { return this->has_static_relocs_
; }
989 // Set that there is a relocation against this symbol that must be resolved
990 // by the static linker (that is, the relocation cannot possibly be made
993 set_has_static_relocs()
994 { this->has_static_relocs_
= true; }
996 // Return whether we must not create a lazy-binding stub for this symbol.
999 { return this->no_lazy_stub_
; }
1001 // Set that we must not create a lazy-binding stub for this symbol.
1004 { this->no_lazy_stub_
= true; }
1006 // Return the offset of the lazy-binding stub for this symbol from the start
1007 // of .MIPS.stubs section.
1009 lazy_stub_offset() const
1010 { return this->lazy_stub_offset_
; }
1012 // Set the offset of the lazy-binding stub for this symbol from the start
1013 // of .MIPS.stubs section.
1015 set_lazy_stub_offset(unsigned int offset
)
1016 { this->lazy_stub_offset_
= offset
; }
1018 // Return whether there are any relocations for this symbol where
1019 // pointer equality matters.
1021 pointer_equality_needed() const
1022 { return this->pointer_equality_needed_
; }
1024 // Set that there are relocations for this symbol where pointer equality
1027 set_pointer_equality_needed()
1028 { this->pointer_equality_needed_
= true; }
1030 // Return global GOT area where this symbol in located.
1032 global_got_area() const
1033 { return this->global_got_area_
; }
1035 // Set global GOT area where this symbol in located.
1037 set_global_got_area(Global_got_area global_got_area
)
1038 { this->global_got_area_
= global_got_area
; }
1040 // Return the global GOT offset for this symbol. For multi-GOT links, this
1041 // returns the offset from the start of .got section to the first GOT entry
1042 // for the symbol. Note that in multi-GOT links the symbol can have entry
1043 // in more than one GOT.
1045 global_gotoffset() const
1046 { return this->global_gotoffset_
; }
1048 // Set the global GOT offset for this symbol. Note that in multi-GOT links
1049 // the symbol can have entry in more than one GOT. This method will set
1050 // the offset only if it is less than current offset.
1052 set_global_gotoffset(unsigned int offset
)
1054 if (this->global_gotoffset_
== -1U || offset
< this->global_gotoffset_
)
1055 this->global_gotoffset_
= offset
;
1058 // Return whether all GOT relocations for this symbol are for calls.
1060 got_only_for_calls() const
1061 { return this->got_only_for_calls_
; }
1063 // Set that there is a GOT relocation for this symbol that is not for call.
1065 set_got_not_only_for_calls()
1066 { this->got_only_for_calls_
= false; }
1068 // Return whether this is a PIC symbol.
1072 // (st_other & STO_MIPS_FLAGS) == STO_MIPS_PIC
1073 return ((this->nonvis() & (elfcpp::STO_MIPS_FLAGS
>> 2))
1074 == (elfcpp::STO_MIPS_PIC
>> 2));
1077 // Set the flag in st_other field that marks this symbol as PIC.
1081 if (this->is_mips16())
1082 // (st_other & ~(STO_MIPS16 | STO_MIPS_FLAGS)) | STO_MIPS_PIC
1083 this->set_nonvis((this->nonvis()
1084 & ~((elfcpp::STO_MIPS16
>> 2)
1085 | (elfcpp::STO_MIPS_FLAGS
>> 2)))
1086 | (elfcpp::STO_MIPS_PIC
>> 2));
1088 // (other & ~STO_MIPS_FLAGS) | STO_MIPS_PIC
1089 this->set_nonvis((this->nonvis() & ~(elfcpp::STO_MIPS_FLAGS
>> 2))
1090 | (elfcpp::STO_MIPS_PIC
>> 2));
1093 // Set the flag in st_other field that marks this symbol as PLT.
1097 if (this->is_mips16())
1098 // (st_other & (STO_MIPS16 | ~STO_MIPS_FLAGS)) | STO_MIPS_PLT
1099 this->set_nonvis((this->nonvis()
1100 & ((elfcpp::STO_MIPS16
>> 2)
1101 | ~(elfcpp::STO_MIPS_FLAGS
>> 2)))
1102 | (elfcpp::STO_MIPS_PLT
>> 2));
1105 // (st_other & ~STO_MIPS_FLAGS) | STO_MIPS_PLT
1106 this->set_nonvis((this->nonvis() & ~(elfcpp::STO_MIPS_FLAGS
>> 2))
1107 | (elfcpp::STO_MIPS_PLT
>> 2));
1110 // Downcast a base pointer to a Mips_symbol pointer.
1111 static Mips_symbol
<size
>*
1112 as_mips_sym(Symbol
* sym
)
1113 { return static_cast<Mips_symbol
<size
>*>(sym
); }
1115 // Downcast a base pointer to a Mips_symbol pointer.
1116 static const Mips_symbol
<size
>*
1117 as_mips_sym(const Symbol
* sym
)
1118 { return static_cast<const Mips_symbol
<size
>*>(sym
); }
1120 // Return whether the symbol has lazy-binding stub.
1122 has_lazy_stub() const
1123 { return this->has_lazy_stub_
; }
1125 // Set whether the symbol has lazy-binding stub.
1127 set_has_lazy_stub(bool has_lazy_stub
)
1128 { this->has_lazy_stub_
= has_lazy_stub
; }
1130 // Return whether the symbol needs a standard PLT entry.
1132 needs_mips_plt() const
1133 { return this->needs_mips_plt_
; }
1135 // Set whether the symbol needs a standard PLT entry.
1137 set_needs_mips_plt(bool needs_mips_plt
)
1138 { this->needs_mips_plt_
= needs_mips_plt
; }
1140 // Return whether the symbol needs a compressed (MIPS16 or microMIPS) PLT
1143 needs_comp_plt() const
1144 { return this->needs_comp_plt_
; }
1146 // Set whether the symbol needs a compressed (MIPS16 or microMIPS) PLT entry.
1148 set_needs_comp_plt(bool needs_comp_plt
)
1149 { this->needs_comp_plt_
= needs_comp_plt
; }
1151 // Return standard PLT entry offset, or -1 if none.
1153 mips_plt_offset() const
1154 { return this->mips_plt_offset_
; }
1156 // Set standard PLT entry offset.
1158 set_mips_plt_offset(unsigned int mips_plt_offset
)
1159 { this->mips_plt_offset_
= mips_plt_offset
; }
1161 // Return whether the symbol has standard PLT entry.
1163 has_mips_plt_offset() const
1164 { return this->mips_plt_offset_
!= -1U; }
1166 // Return compressed (MIPS16 or microMIPS) PLT entry offset, or -1 if none.
1168 comp_plt_offset() const
1169 { return this->comp_plt_offset_
; }
1171 // Set compressed (MIPS16 or microMIPS) PLT entry offset.
1173 set_comp_plt_offset(unsigned int comp_plt_offset
)
1174 { this->comp_plt_offset_
= comp_plt_offset
; }
1176 // Return whether the symbol has compressed (MIPS16 or microMIPS) PLT entry.
1178 has_comp_plt_offset() const
1179 { return this->comp_plt_offset_
!= -1U; }
1181 // Return MIPS16 fn stub for a symbol.
1182 template<bool big_endian
>
1183 Mips16_stub_section
<size
, big_endian
>*
1184 get_mips16_fn_stub() const
1186 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(mips16_fn_stub_
);
1189 // Set MIPS16 fn stub for a symbol.
1191 set_mips16_fn_stub(Mips16_stub_section_base
* stub
)
1192 { this->mips16_fn_stub_
= stub
; }
1194 // Return whether symbol has MIPS16 fn stub.
1196 has_mips16_fn_stub() const
1197 { return this->mips16_fn_stub_
!= NULL
; }
1199 // Return MIPS16 call stub for a symbol.
1200 template<bool big_endian
>
1201 Mips16_stub_section
<size
, big_endian
>*
1202 get_mips16_call_stub() const
1204 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(
1208 // Set MIPS16 call stub for a symbol.
1210 set_mips16_call_stub(Mips16_stub_section_base
* stub
)
1211 { this->mips16_call_stub_
= stub
; }
1213 // Return whether symbol has MIPS16 call stub.
1215 has_mips16_call_stub() const
1216 { return this->mips16_call_stub_
!= NULL
; }
1218 // Return MIPS16 call_fp stub for a symbol.
1219 template<bool big_endian
>
1220 Mips16_stub_section
<size
, big_endian
>*
1221 get_mips16_call_fp_stub() const
1223 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(
1224 mips16_call_fp_stub_
);
1227 // Set MIPS16 call_fp stub for a symbol.
1229 set_mips16_call_fp_stub(Mips16_stub_section_base
* stub
)
1230 { this->mips16_call_fp_stub_
= stub
; }
1232 // Return whether symbol has MIPS16 call_fp stub.
1234 has_mips16_call_fp_stub() const
1235 { return this->mips16_call_fp_stub_
!= NULL
; }
1238 get_applied_secondary_got_fixup() const
1239 { return applied_secondary_got_fixup_
; }
1242 set_applied_secondary_got_fixup()
1243 { this->applied_secondary_got_fixup_
= true; }
1246 // Whether the symbol needs MIPS16 fn_stub. This is true if this symbol
1247 // appears in any relocs other than a 16 bit call.
1250 // True if this symbol is referenced by branch relocations from
1251 // any non-PIC input file. This is used to determine whether an
1252 // la25 stub is required.
1253 bool has_nonpic_branches_
;
1255 // The offset of the la25 stub for this symbol from the start of the
1256 // la25 stub section.
1257 unsigned int la25_stub_offset_
;
1259 // True if there is a relocation against this symbol that must be
1260 // resolved by the static linker (that is, the relocation cannot
1261 // possibly be made dynamic).
1262 bool has_static_relocs_
;
1264 // Whether we must not create a lazy-binding stub for this symbol.
1265 // This is true if the symbol has relocations related to taking the
1266 // function's address.
1269 // The offset of the lazy-binding stub for this symbol from the start of
1270 // .MIPS.stubs section.
1271 unsigned int lazy_stub_offset_
;
1273 // True if there are any relocations for this symbol where pointer equality
1275 bool pointer_equality_needed_
;
1277 // Global GOT area where this symbol in located, or GGA_NONE if symbol is not
1278 // in the global part of the GOT.
1279 Global_got_area global_got_area_
;
1281 // The global GOT offset for this symbol. For multi-GOT links, this is offset
1282 // from the start of .got section to the first GOT entry for the symbol.
1283 // Note that in multi-GOT links the symbol can have entry in more than one GOT.
1284 unsigned int global_gotoffset_
;
1286 // Whether all GOT relocations for this symbol are for calls.
1287 bool got_only_for_calls_
;
1288 // Whether the symbol has lazy-binding stub.
1289 bool has_lazy_stub_
;
1290 // Whether the symbol needs a standard PLT entry.
1291 bool needs_mips_plt_
;
1292 // Whether the symbol needs a compressed (MIPS16 or microMIPS) PLT entry.
1293 bool needs_comp_plt_
;
1294 // Standard PLT entry offset, or -1 if none.
1295 unsigned int mips_plt_offset_
;
1296 // Compressed (MIPS16 or microMIPS) PLT entry offset, or -1 if none.
1297 unsigned int comp_plt_offset_
;
1298 // MIPS16 fn stub for a symbol.
1299 Mips16_stub_section_base
* mips16_fn_stub_
;
1300 // MIPS16 call stub for a symbol.
1301 Mips16_stub_section_base
* mips16_call_stub_
;
1302 // MIPS16 call_fp stub for a symbol.
1303 Mips16_stub_section_base
* mips16_call_fp_stub_
;
1305 bool applied_secondary_got_fixup_
;
1308 // Mips16_stub_section class.
1310 // The mips16 compiler uses a couple of special sections to handle
1311 // floating point arguments.
1313 // Section names that look like .mips16.fn.FNNAME contain stubs that
1314 // copy floating point arguments from the fp regs to the gp regs and
1315 // then jump to FNNAME. If any 32 bit function calls FNNAME, the
1316 // call should be redirected to the stub instead. If no 32 bit
1317 // function calls FNNAME, the stub should be discarded. We need to
1318 // consider any reference to the function, not just a call, because
1319 // if the address of the function is taken we will need the stub,
1320 // since the address might be passed to a 32 bit function.
1322 // Section names that look like .mips16.call.FNNAME contain stubs
1323 // that copy floating point arguments from the gp regs to the fp
1324 // regs and then jump to FNNAME. If FNNAME is a 32 bit function,
1325 // then any 16 bit function that calls FNNAME should be redirected
1326 // to the stub instead. If FNNAME is not a 32 bit function, the
1327 // stub should be discarded.
1329 // .mips16.call.fp.FNNAME sections are similar, but contain stubs
1330 // which call FNNAME and then copy the return value from the fp regs
1331 // to the gp regs. These stubs store the return address in $18 while
1332 // calling FNNAME; any function which might call one of these stubs
1333 // must arrange to save $18 around the call. (This case is not
1334 // needed for 32 bit functions that call 16 bit functions, because
1335 // 16 bit functions always return floating point values in both
1336 // $f0/$f1 and $2/$3.)
1338 // Note that in all cases FNNAME might be defined statically.
1339 // Therefore, FNNAME is not used literally. Instead, the relocation
1340 // information will indicate which symbol the section is for.
1342 // We record any stubs that we find in the symbol table.
1344 // TODO(sasa): All mips16 stub sections should be emitted in the .text section.
1346 class Mips16_stub_section_base
{ };
1348 template<int size
, bool big_endian
>
1349 class Mips16_stub_section
: public Mips16_stub_section_base
1351 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1354 Mips16_stub_section(Mips_relobj
<size
, big_endian
>* object
, unsigned int shndx
)
1355 : object_(object
), shndx_(shndx
), r_sym_(0), gsym_(NULL
),
1356 found_r_mips_none_(false)
1358 gold_assert(object
->is_mips16_fn_stub_section(shndx
)
1359 || object
->is_mips16_call_stub_section(shndx
)
1360 || object
->is_mips16_call_fp_stub_section(shndx
));
1363 // Return the object of this stub section.
1364 Mips_relobj
<size
, big_endian
>*
1366 { return this->object_
; }
1368 // Return the size of a section.
1370 section_size() const
1371 { return this->object_
->section_size(this->shndx_
); }
1373 // Return section index of this stub section.
1376 { return this->shndx_
; }
1378 // Return symbol index, if stub is for a local function.
1381 { return this->r_sym_
; }
1383 // Return symbol, if stub is for a global function.
1386 { return this->gsym_
; }
1388 // Return whether stub is for a local function.
1390 is_for_local_function() const
1391 { return this->gsym_
== NULL
; }
1393 // This method is called when a new relocation R_TYPE for local symbol R_SYM
1394 // is found in the stub section. Try to find stub target.
1396 new_local_reloc_found(unsigned int r_type
, unsigned int r_sym
)
1398 // To find target symbol for this stub, trust the first R_MIPS_NONE
1399 // relocation, if any. Otherwise trust the first relocation, whatever
1401 if (this->found_r_mips_none_
)
1403 if (r_type
== elfcpp::R_MIPS_NONE
)
1405 this->r_sym_
= r_sym
;
1407 this->found_r_mips_none_
= true;
1409 else if (!is_target_found())
1410 this->r_sym_
= r_sym
;
1413 // This method is called when a new relocation R_TYPE for global symbol GSYM
1414 // is found in the stub section. Try to find stub target.
1416 new_global_reloc_found(unsigned int r_type
, Mips_symbol
<size
>* gsym
)
1418 // To find target symbol for this stub, trust the first R_MIPS_NONE
1419 // relocation, if any. Otherwise trust the first relocation, whatever
1421 if (this->found_r_mips_none_
)
1423 if (r_type
== elfcpp::R_MIPS_NONE
)
1427 this->found_r_mips_none_
= true;
1429 else if (!is_target_found())
1433 // Return whether we found the stub target.
1435 is_target_found() const
1436 { return this->r_sym_
!= 0 || this->gsym_
!= NULL
; }
1438 // Return whether this is a fn stub.
1441 { return this->object_
->is_mips16_fn_stub_section(this->shndx_
); }
1443 // Return whether this is a call stub.
1445 is_call_stub() const
1446 { return this->object_
->is_mips16_call_stub_section(this->shndx_
); }
1448 // Return whether this is a call_fp stub.
1450 is_call_fp_stub() const
1451 { return this->object_
->is_mips16_call_fp_stub_section(this->shndx_
); }
1453 // Return the output address.
1455 output_address() const
1457 return (this->object_
->output_section(this->shndx_
)->address()
1458 + this->object_
->output_section_offset(this->shndx_
));
1462 // The object of this stub section.
1463 Mips_relobj
<size
, big_endian
>* object_
;
1464 // The section index of this stub section.
1465 unsigned int shndx_
;
1466 // The symbol index, if stub is for a local function.
1467 unsigned int r_sym_
;
1468 // The symbol, if stub is for a global function.
1469 Mips_symbol
<size
>* gsym_
;
1470 // True if we found R_MIPS_NONE relocation in this stub.
1471 bool found_r_mips_none_
;
1474 // Mips_relobj class.
1476 template<int size
, bool big_endian
>
1477 class Mips_relobj
: public Sized_relobj_file
<size
, big_endian
>
1479 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1480 typedef std::map
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>
1481 Mips16_stubs_int_map
;
1482 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1485 Mips_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
1486 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1487 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
1488 processor_specific_flags_(0), local_symbol_is_mips16_(),
1489 local_symbol_is_micromips_(), mips16_stub_sections_(),
1490 local_non_16bit_calls_(), local_16bit_calls_(), local_mips16_fn_stubs_(),
1491 local_mips16_call_stubs_(), gp_(0), got_info_(NULL
),
1492 section_is_mips16_fn_stub_(), section_is_mips16_call_stub_(),
1493 section_is_mips16_call_fp_stub_(), pdr_shndx_(-1U), gprmask_(0),
1494 cprmask1_(0), cprmask2_(0), cprmask3_(0), cprmask4_(0)
1496 this->is_pic_
= (ehdr
.get_e_flags() & elfcpp::EF_MIPS_PIC
) != 0;
1497 this->is_n32_
= elfcpp::abi_n32(ehdr
.get_e_flags());
1498 this->is_n64_
= elfcpp::abi_64(ehdr
.get_e_ident()[elfcpp::EI_CLASS
]);
1504 // Downcast a base pointer to a Mips_relobj pointer. This is
1505 // not type-safe but we only use Mips_relobj not the base class.
1506 static Mips_relobj
<size
, big_endian
>*
1507 as_mips_relobj(Relobj
* relobj
)
1508 { return static_cast<Mips_relobj
<size
, big_endian
>*>(relobj
); }
1510 // Downcast a base pointer to a Mips_relobj pointer. This is
1511 // not type-safe but we only use Mips_relobj not the base class.
1512 static const Mips_relobj
<size
, big_endian
>*
1513 as_mips_relobj(const Relobj
* relobj
)
1514 { return static_cast<const Mips_relobj
<size
, big_endian
>*>(relobj
); }
1516 // Processor-specific flags in ELF file header. This is valid only after
1519 processor_specific_flags() const
1520 { return this->processor_specific_flags_
; }
1522 // Whether a local symbol is MIPS16 symbol. R_SYM is the symbol table
1523 // index. This is only valid after do_count_local_symbol is called.
1525 local_symbol_is_mips16(unsigned int r_sym
) const
1527 gold_assert(r_sym
< this->local_symbol_is_mips16_
.size());
1528 return this->local_symbol_is_mips16_
[r_sym
];
1531 // Whether a local symbol is microMIPS symbol. R_SYM is the symbol table
1532 // index. This is only valid after do_count_local_symbol is called.
1534 local_symbol_is_micromips(unsigned int r_sym
) const
1536 gold_assert(r_sym
< this->local_symbol_is_micromips_
.size());
1537 return this->local_symbol_is_micromips_
[r_sym
];
1540 // Get or create MIPS16 stub section.
1541 Mips16_stub_section
<size
, big_endian
>*
1542 get_mips16_stub_section(unsigned int shndx
)
1544 typename
Mips16_stubs_int_map::const_iterator it
=
1545 this->mips16_stub_sections_
.find(shndx
);
1546 if (it
!= this->mips16_stub_sections_
.end())
1547 return (*it
).second
;
1549 Mips16_stub_section
<size
, big_endian
>* stub_section
=
1550 new Mips16_stub_section
<size
, big_endian
>(this, shndx
);
1551 this->mips16_stub_sections_
.insert(
1552 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1553 stub_section
->shndx(), stub_section
));
1554 return stub_section
;
1557 // Return MIPS16 fn stub section for local symbol R_SYM, or NULL if this
1558 // object doesn't have fn stub for R_SYM.
1559 Mips16_stub_section
<size
, big_endian
>*
1560 get_local_mips16_fn_stub(unsigned int r_sym
) const
1562 typename
Mips16_stubs_int_map::const_iterator it
=
1563 this->local_mips16_fn_stubs_
.find(r_sym
);
1564 if (it
!= this->local_mips16_fn_stubs_
.end())
1565 return (*it
).second
;
1569 // Record that this object has MIPS16 fn stub for local symbol. This method
1570 // is only called if we decided not to discard the stub.
1572 add_local_mips16_fn_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1574 gold_assert(stub
->is_for_local_function());
1575 unsigned int r_sym
= stub
->r_sym();
1576 this->local_mips16_fn_stubs_
.insert(
1577 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1581 // Return MIPS16 call stub section for local symbol R_SYM, or NULL if this
1582 // object doesn't have call stub for R_SYM.
1583 Mips16_stub_section
<size
, big_endian
>*
1584 get_local_mips16_call_stub(unsigned int r_sym
) const
1586 typename
Mips16_stubs_int_map::const_iterator it
=
1587 this->local_mips16_call_stubs_
.find(r_sym
);
1588 if (it
!= this->local_mips16_call_stubs_
.end())
1589 return (*it
).second
;
1593 // Record that this object has MIPS16 call stub for local symbol. This method
1594 // is only called if we decided not to discard the stub.
1596 add_local_mips16_call_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1598 gold_assert(stub
->is_for_local_function());
1599 unsigned int r_sym
= stub
->r_sym();
1600 this->local_mips16_call_stubs_
.insert(
1601 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1605 // Record that we found "non 16-bit" call relocation against local symbol
1606 // SYMNDX. This reloc would need to refer to a MIPS16 fn stub, if there
1609 add_local_non_16bit_call(unsigned int symndx
)
1610 { this->local_non_16bit_calls_
.insert(symndx
); }
1612 // Return true if there is any "non 16-bit" call relocation against local
1613 // symbol SYMNDX in this object.
1615 has_local_non_16bit_call_relocs(unsigned int symndx
)
1617 return (this->local_non_16bit_calls_
.find(symndx
)
1618 != this->local_non_16bit_calls_
.end());
1621 // Record that we found 16-bit call relocation R_MIPS16_26 against local
1622 // symbol SYMNDX. Local MIPS16 call or call_fp stubs will only be needed
1623 // if there is some R_MIPS16_26 relocation that refers to the stub symbol.
1625 add_local_16bit_call(unsigned int symndx
)
1626 { this->local_16bit_calls_
.insert(symndx
); }
1628 // Return true if there is any 16-bit call relocation R_MIPS16_26 against local
1629 // symbol SYMNDX in this object.
1631 has_local_16bit_call_relocs(unsigned int symndx
)
1633 return (this->local_16bit_calls_
.find(symndx
)
1634 != this->local_16bit_calls_
.end());
1637 // Get gp value that was used to create this object.
1640 { return this->gp_
; }
1642 // Return whether the object is a PIC object.
1645 { return this->is_pic_
; }
1647 // Return whether the object uses N32 ABI.
1650 { return this->is_n32_
; }
1652 // Return whether the object uses N64 ABI.
1655 { return this->is_n64_
; }
1657 // Return whether the object uses NewABI conventions.
1660 { return this->is_n32_
|| this->is_n64_
; }
1662 // Return Mips_got_info for this object.
1663 Mips_got_info
<size
, big_endian
>*
1664 get_got_info() const
1665 { return this->got_info_
; }
1667 // Return Mips_got_info for this object. Create new info if it doesn't exist.
1668 Mips_got_info
<size
, big_endian
>*
1669 get_or_create_got_info()
1671 if (!this->got_info_
)
1672 this->got_info_
= new Mips_got_info
<size
, big_endian
>();
1673 return this->got_info_
;
1676 // Set Mips_got_info for this object.
1678 set_got_info(Mips_got_info
<size
, big_endian
>* got_info
)
1679 { this->got_info_
= got_info
; }
1681 // Whether a section SHDNX is a MIPS16 stub section. This is only valid
1682 // after do_read_symbols is called.
1684 is_mips16_stub_section(unsigned int shndx
)
1686 return (is_mips16_fn_stub_section(shndx
)
1687 || is_mips16_call_stub_section(shndx
)
1688 || is_mips16_call_fp_stub_section(shndx
));
1691 // Return TRUE if relocations in section SHNDX can refer directly to a
1692 // MIPS16 function rather than to a hard-float stub. This is only valid
1693 // after do_read_symbols is called.
1695 section_allows_mips16_refs(unsigned int shndx
)
1697 return (this->is_mips16_stub_section(shndx
) || shndx
== this->pdr_shndx_
);
1700 // Whether a section SHDNX is a MIPS16 fn stub section. This is only valid
1701 // after do_read_symbols is called.
1703 is_mips16_fn_stub_section(unsigned int shndx
)
1705 gold_assert(shndx
< this->section_is_mips16_fn_stub_
.size());
1706 return this->section_is_mips16_fn_stub_
[shndx
];
1709 // Whether a section SHDNX is a MIPS16 call stub section. This is only valid
1710 // after do_read_symbols is called.
1712 is_mips16_call_stub_section(unsigned int shndx
)
1714 gold_assert(shndx
< this->section_is_mips16_call_stub_
.size());
1715 return this->section_is_mips16_call_stub_
[shndx
];
1718 // Whether a section SHDNX is a MIPS16 call_fp stub section. This is only
1719 // valid after do_read_symbols is called.
1721 is_mips16_call_fp_stub_section(unsigned int shndx
)
1723 gold_assert(shndx
< this->section_is_mips16_call_fp_stub_
.size());
1724 return this->section_is_mips16_call_fp_stub_
[shndx
];
1727 // Discard MIPS16 stub secions that are not needed.
1729 discard_mips16_stub_sections(Symbol_table
* symtab
);
1731 // Return gprmask from the .reginfo section of this object.
1734 { return this->gprmask_
; }
1736 // Return cprmask1 from the .reginfo section of this object.
1739 { return this->cprmask1_
; }
1741 // Return cprmask2 from the .reginfo section of this object.
1744 { return this->cprmask2_
; }
1746 // Return cprmask3 from the .reginfo section of this object.
1749 { return this->cprmask3_
; }
1751 // Return cprmask4 from the .reginfo section of this object.
1754 { return this->cprmask4_
; }
1757 // Count the local symbols.
1759 do_count_local_symbols(Stringpool_template
<char>*,
1760 Stringpool_template
<char>*);
1762 // Read the symbol information.
1764 do_read_symbols(Read_symbols_data
* sd
);
1767 // processor-specific flags in ELF file header.
1768 elfcpp::Elf_Word processor_specific_flags_
;
1770 // Bit vector to tell if a local symbol is a MIPS16 symbol or not.
1771 // This is only valid after do_count_local_symbol is called.
1772 std::vector
<bool> local_symbol_is_mips16_
;
1774 // Bit vector to tell if a local symbol is a microMIPS symbol or not.
1775 // This is only valid after do_count_local_symbol is called.
1776 std::vector
<bool> local_symbol_is_micromips_
;
1778 // Map from section index to the MIPS16 stub for that section. This contains
1779 // all stubs found in this object.
1780 Mips16_stubs_int_map mips16_stub_sections_
;
1782 // Local symbols that have "non 16-bit" call relocation. This relocation
1783 // would need to refer to a MIPS16 fn stub, if there is one.
1784 std::set
<unsigned int> local_non_16bit_calls_
;
1786 // Local symbols that have 16-bit call relocation R_MIPS16_26. Local MIPS16
1787 // call or call_fp stubs will only be needed if there is some R_MIPS16_26
1788 // relocation that refers to the stub symbol.
1789 std::set
<unsigned int> local_16bit_calls_
;
1791 // Map from local symbol index to the MIPS16 fn stub for that symbol.
1792 // This contains only the stubs that we decided not to discard.
1793 Mips16_stubs_int_map local_mips16_fn_stubs_
;
1795 // Map from local symbol index to the MIPS16 call stub for that symbol.
1796 // This contains only the stubs that we decided not to discard.
1797 Mips16_stubs_int_map local_mips16_call_stubs_
;
1799 // gp value that was used to create this object.
1801 // Whether the object is a PIC object.
1803 // Whether the object uses N32 ABI.
1805 // Whether the object uses N64 ABI.
1807 // The Mips_got_info for this object.
1808 Mips_got_info
<size
, big_endian
>* got_info_
;
1810 // Bit vector to tell if a section is a MIPS16 fn stub section or not.
1811 // This is only valid after do_read_symbols is called.
1812 std::vector
<bool> section_is_mips16_fn_stub_
;
1814 // Bit vector to tell if a section is a MIPS16 call stub section or not.
1815 // This is only valid after do_read_symbols is called.
1816 std::vector
<bool> section_is_mips16_call_stub_
;
1818 // Bit vector to tell if a section is a MIPS16 call_fp stub section or not.
1819 // This is only valid after do_read_symbols is called.
1820 std::vector
<bool> section_is_mips16_call_fp_stub_
;
1822 // .pdr section index.
1823 unsigned int pdr_shndx_
;
1825 // gprmask from the .reginfo section of this object.
1827 // cprmask1 from the .reginfo section of this object.
1829 // cprmask2 from the .reginfo section of this object.
1831 // cprmask3 from the .reginfo section of this object.
1833 // cprmask4 from the .reginfo section of this object.
1837 // Mips_output_data_got class.
1839 template<int size
, bool big_endian
>
1840 class Mips_output_data_got
: public Output_data_got
<size
, big_endian
>
1842 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1843 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
1845 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1848 Mips_output_data_got(Target_mips
<size
, big_endian
>* target
,
1849 Symbol_table
* symtab
, Layout
* layout
)
1850 : Output_data_got
<size
, big_endian
>(), target_(target
),
1851 symbol_table_(symtab
), layout_(layout
), static_relocs_(), got_view_(NULL
),
1852 first_global_got_dynsym_index_(-1U), primary_got_(NULL
),
1853 secondary_got_relocs_()
1855 this->master_got_info_
= new Mips_got_info
<size
, big_endian
>();
1856 this->set_addralign(16);
1859 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
1860 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
1862 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
1863 unsigned int symndx
, Mips_address addend
,
1864 unsigned int r_type
, unsigned int shndx
)
1866 this->master_got_info_
->record_local_got_symbol(object
, symndx
, addend
,
1870 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
1871 // in OBJECT. FOR_CALL is true if the caller is only interested in
1872 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
1875 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
1876 Mips_relobj
<size
, big_endian
>* object
,
1877 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
1879 this->master_got_info_
->record_global_got_symbol(mips_sym
, object
, r_type
,
1880 dyn_reloc
, for_call
);
1883 // Record that OBJECT has a page relocation against symbol SYMNDX and
1884 // that ADDEND is the addend for that relocation.
1886 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
1887 unsigned int symndx
, int addend
)
1888 { this->master_got_info_
->record_got_page_entry(object
, symndx
, addend
); }
1890 // Add a static entry for the GOT entry at OFFSET. GSYM is a global
1891 // symbol and R_TYPE is the code of a dynamic relocation that needs to be
1892 // applied in a static link.
1894 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
1895 Mips_symbol
<size
>* gsym
)
1896 { this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, gsym
)); }
1898 // Add a static reloc for the GOT entry at OFFSET. RELOBJ is an object
1899 // defining a local symbol with INDEX. R_TYPE is the code of a dynamic
1900 // relocation that needs to be applied in a static link.
1902 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
1903 Sized_relobj_file
<size
, big_endian
>* relobj
,
1906 this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, relobj
,
1910 // Record that global symbol GSYM has R_TYPE dynamic relocation in the
1911 // secondary GOT at OFFSET.
1913 add_secondary_got_reloc(unsigned int got_offset
, unsigned int r_type
,
1914 Mips_symbol
<size
>* gsym
)
1916 this->secondary_got_relocs_
.push_back(Static_reloc(got_offset
,
1920 // Update GOT entry at OFFSET with VALUE.
1922 update_got_entry(unsigned int offset
, Mips_address value
)
1924 elfcpp::Swap
<size
, big_endian
>::writeval(this->got_view_
+ offset
, value
);
1927 // Return the number of entries in local part of the GOT. This includes
1928 // local entries, page entries and 2 reserved entries.
1930 get_local_gotno() const
1932 if (!this->multi_got())
1934 return (2 + this->master_got_info_
->local_gotno()
1935 + this->master_got_info_
->page_gotno());
1938 return 2 + this->primary_got_
->local_gotno() + this->primary_got_
->page_gotno();
1941 // Return dynamic symbol table index of the first symbol with global GOT
1944 first_global_got_dynsym_index() const
1945 { return this->first_global_got_dynsym_index_
; }
1947 // Set dynamic symbol table index of the first symbol with global GOT entry.
1949 set_first_global_got_dynsym_index(unsigned int index
)
1950 { this->first_global_got_dynsym_index_
= index
; }
1952 // Lay out the GOT. Add local, global and TLS entries. If GOT is
1953 // larger than 64K, create multi-GOT.
1955 lay_out_got(Layout
* layout
, Symbol_table
* symtab
,
1956 const Input_objects
* input_objects
);
1958 // Create multi-GOT. For every GOT, add local, global and TLS entries.
1960 lay_out_multi_got(Layout
* layout
, const Input_objects
* input_objects
);
1962 // Attempt to merge GOTs of different input objects.
1964 merge_gots(const Input_objects
* input_objects
);
1966 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
1967 // this would lead to overflow, true if they were merged successfully.
1969 merge_got_with(Mips_got_info
<size
, big_endian
>* from
,
1970 Mips_relobj
<size
, big_endian
>* object
,
1971 Mips_got_info
<size
, big_endian
>* to
);
1973 // Return the offset of GOT page entry for VALUE. For multi-GOT links,
1974 // use OBJECT's GOT.
1976 get_got_page_offset(Mips_address value
,
1977 const Mips_relobj
<size
, big_endian
>* object
)
1979 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
1980 ? this->master_got_info_
1981 : object
->get_got_info());
1982 gold_assert(g
!= NULL
);
1983 return g
->get_got_page_offset(value
, this);
1986 // Return the GOT offset of type GOT_TYPE of the global symbol
1987 // GSYM. For multi-GOT links, use OBJECT's GOT.
1988 unsigned int got_offset(const Symbol
* gsym
, unsigned int got_type
,
1989 Mips_relobj
<size
, big_endian
>* object
) const
1991 if (!this->multi_got())
1992 return gsym
->got_offset(got_type
);
1995 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
1996 gold_assert(g
!= NULL
);
1997 return gsym
->got_offset(g
->multigot_got_type(got_type
));
2001 // Return the GOT offset of type GOT_TYPE of the local symbol
2004 got_offset(unsigned int symndx
, unsigned int got_type
,
2005 Sized_relobj_file
<size
, big_endian
>* object
) const
2006 { return object
->local_got_offset(symndx
, got_type
); }
2008 // Return the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2010 tls_ldm_offset(Mips_relobj
<size
, big_endian
>* object
) const
2012 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2013 ? this->master_got_info_
2014 : object
->get_got_info());
2015 gold_assert(g
!= NULL
);
2016 return g
->tls_ldm_offset();
2019 // Set the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2021 set_tls_ldm_offset(unsigned int tls_ldm_offset
,
2022 Mips_relobj
<size
, big_endian
>* object
)
2024 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2025 ? this->master_got_info_
2026 : object
->get_got_info());
2027 gold_assert(g
!= NULL
);
2028 g
->set_tls_ldm_offset(tls_ldm_offset
);
2031 // Return true for multi-GOT links.
2034 { return this->primary_got_
!= NULL
; }
2036 // Return the offset of OBJECT's GOT from the start of .got section.
2038 get_got_offset(const Mips_relobj
<size
, big_endian
>* object
)
2040 if (!this->multi_got())
2044 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
2045 return g
!= NULL
? g
->offset() : 0;
2049 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
2051 add_reloc_only_entries()
2052 { this->master_got_info_
->add_reloc_only_entries(this); }
2054 // Return offset of the primary GOT's entry for global symbol.
2056 get_primary_got_offset(const Mips_symbol
<size
>* sym
) const
2058 gold_assert(sym
->global_got_area() != GGA_NONE
);
2059 return (this->get_local_gotno() + sym
->dynsym_index()
2060 - this->first_global_got_dynsym_index()) * size
/8;
2063 // For the entry at offset GOT_OFFSET, return its offset from the gp.
2064 // Input argument GOT_OFFSET is always global offset from the start of
2065 // .got section, for both single and multi-GOT links.
2066 // For single GOT links, this returns GOT_OFFSET - 0x7FF0. For multi-GOT
2067 // links, the return value is object_got_offset - 0x7FF0, where
2068 // object_got_offset is offset in the OBJECT's GOT.
2070 gp_offset(unsigned int got_offset
,
2071 const Mips_relobj
<size
, big_endian
>* object
) const
2073 return (this->address() + got_offset
2074 - this->target_
->adjusted_gp_value(object
));
2078 // Write out the GOT table.
2080 do_write(Output_file
*);
2084 // This class represent dynamic relocations that need to be applied by
2085 // gold because we are using TLS relocations in a static link.
2089 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2090 Mips_symbol
<size
>* gsym
)
2091 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(true)
2092 { this->u_
.global
.symbol
= gsym
; }
2094 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2095 Sized_relobj_file
<size
, big_endian
>* relobj
, unsigned int index
)
2096 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(false)
2098 this->u_
.local
.relobj
= relobj
;
2099 this->u_
.local
.index
= index
;
2102 // Return the GOT offset.
2105 { return this->got_offset_
; }
2110 { return this->r_type_
; }
2112 // Whether the symbol is global or not.
2114 symbol_is_global() const
2115 { return this->symbol_is_global_
; }
2117 // For a relocation against a global symbol, the global symbol.
2121 gold_assert(this->symbol_is_global_
);
2122 return this->u_
.global
.symbol
;
2125 // For a relocation against a local symbol, the defining object.
2126 Sized_relobj_file
<size
, big_endian
>*
2129 gold_assert(!this->symbol_is_global_
);
2130 return this->u_
.local
.relobj
;
2133 // For a relocation against a local symbol, the local symbol index.
2137 gold_assert(!this->symbol_is_global_
);
2138 return this->u_
.local
.index
;
2142 // GOT offset of the entry to which this relocation is applied.
2143 unsigned int got_offset_
;
2144 // Type of relocation.
2145 unsigned int r_type_
;
2146 // Whether this relocation is against a global symbol.
2147 bool symbol_is_global_
;
2148 // A global or local symbol.
2153 // For a global symbol, the symbol itself.
2154 Mips_symbol
<size
>* symbol
;
2158 // For a local symbol, the object defining object.
2159 Sized_relobj_file
<size
, big_endian
>* relobj
;
2160 // For a local symbol, the symbol index.
2167 Target_mips
<size
, big_endian
>* target_
;
2168 // The symbol table.
2169 Symbol_table
* symbol_table_
;
2172 // Static relocs to be applied to the GOT.
2173 std::vector
<Static_reloc
> static_relocs_
;
2174 // .got section view.
2175 unsigned char* got_view_
;
2176 // The dynamic symbol table index of the first symbol with global GOT entry.
2177 unsigned int first_global_got_dynsym_index_
;
2178 // The master GOT information.
2179 Mips_got_info
<size
, big_endian
>* master_got_info_
;
2180 // The primary GOT information.
2181 Mips_got_info
<size
, big_endian
>* primary_got_
;
2182 // Secondary GOT fixups.
2183 std::vector
<Static_reloc
> secondary_got_relocs_
;
2186 // A class to handle LA25 stubs - non-PIC interface to a PIC function. There are
2187 // two ways of creating these interfaces. The first is to add:
2189 // lui $25,%hi(func)
2191 // addiu $25,$25,%lo(func)
2193 // to a separate trampoline section. The second is to add:
2195 // lui $25,%hi(func)
2196 // addiu $25,$25,%lo(func)
2198 // immediately before a PIC function "func", but only if a function is at the
2199 // beginning of the section, and the section is not too heavily aligned (i.e we
2200 // would need to add no more than 2 nops before the stub.)
2202 // We only create stubs of the first type.
2204 template<int size
, bool big_endian
>
2205 class Mips_output_data_la25_stub
: public Output_section_data
2207 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2210 Mips_output_data_la25_stub()
2211 : Output_section_data(size
== 32 ? 4 : 8), symbols_()
2214 // Create LA25 stub for a symbol.
2216 create_la25_stub(Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
2217 Mips_symbol
<size
>* gsym
);
2219 // Return output address of a stub.
2221 stub_address(const Mips_symbol
<size
>* sym
) const
2223 gold_assert(sym
->has_la25_stub());
2224 return this->address() + sym
->la25_stub_offset();
2229 do_adjust_output_section(Output_section
* os
)
2230 { os
->set_entsize(0); }
2233 // Template for standard LA25 stub.
2234 static const uint32_t la25_stub_entry
[];
2235 // Template for microMIPS LA25 stub.
2236 static const uint32_t la25_stub_micromips_entry
[];
2238 // Set the final size.
2240 set_final_data_size()
2241 { this->set_data_size(this->symbols_
.size() * 16); }
2243 // Create a symbol for SYM stub's value and size, to help make the
2244 // disassembly easier to read.
2246 create_stub_symbol(Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
2247 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
);
2249 // Write out the LA25 stub section.
2251 do_write(Output_file
*);
2253 // Symbols that have LA25 stubs.
2254 Unordered_set
<Mips_symbol
<size
>*> symbols_
;
2257 // A class to handle the PLT data.
2259 template<int size
, bool big_endian
>
2260 class Mips_output_data_plt
: public Output_section_data
2262 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2263 typedef Output_data_reloc
<elfcpp::SHT_REL
, true,
2264 size
, big_endian
> Reloc_section
;
2267 // Create the PLT section. The ordinary .got section is an argument,
2268 // since we need to refer to the start.
2269 Mips_output_data_plt(Layout
* layout
, Output_data_space
* got_plt
,
2270 Target_mips
<size
, big_endian
>* target
)
2271 : Output_section_data(size
== 32 ? 4 : 8), got_plt_(got_plt
), symbols_(),
2272 plt_mips_offset_(0), plt_comp_offset_(0), plt_header_size_(0),
2275 this->rel_
= new Reloc_section(false);
2276 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
2277 elfcpp::SHF_ALLOC
, this->rel_
,
2278 ORDER_DYNAMIC_PLT_RELOCS
, false);
2281 // Add an entry to the PLT for a symbol referenced by r_type relocation.
2283 add_entry(Mips_symbol
<size
>* gsym
, unsigned int r_type
);
2285 // Return the .rel.plt section data.
2286 const Reloc_section
*
2288 { return this->rel_
; }
2290 // Return the number of PLT entries.
2293 { return this->symbols_
.size(); }
2295 // Return the offset of the first non-reserved PLT entry.
2297 first_plt_entry_offset() const
2298 { return sizeof(plt0_entry_o32
); }
2300 // Return the size of a PLT entry.
2302 plt_entry_size() const
2303 { return sizeof(plt_entry
); }
2305 // Set final PLT offsets. For each symbol, determine whether standard or
2306 // compressed (MIPS16 or microMIPS) PLT entry is used.
2310 // Return the offset of the first standard PLT entry.
2312 first_mips_plt_offset() const
2313 { return this->plt_header_size_
; }
2315 // Return the offset of the first compressed PLT entry.
2317 first_comp_plt_offset() const
2318 { return this->plt_header_size_
+ this->plt_mips_offset_
; }
2320 // Return whether there are any standard PLT entries.
2322 has_standard_entries() const
2323 { return this->plt_mips_offset_
> 0; }
2325 // Return the output address of standard PLT entry.
2327 mips_entry_address(const Mips_symbol
<size
>* sym
) const
2329 gold_assert (sym
->has_mips_plt_offset());
2330 return (this->address() + this->first_mips_plt_offset()
2331 + sym
->mips_plt_offset());
2334 // Return the output address of compressed (MIPS16 or microMIPS) PLT entry.
2336 comp_entry_address(const Mips_symbol
<size
>* sym
) const
2338 gold_assert (sym
->has_comp_plt_offset());
2339 return (this->address() + this->first_comp_plt_offset()
2340 + sym
->comp_plt_offset());
2345 do_adjust_output_section(Output_section
* os
)
2346 { os
->set_entsize(0); }
2348 // Write to a map file.
2350 do_print_to_mapfile(Mapfile
* mapfile
) const
2351 { mapfile
->print_output_data(this, _(".plt")); }
2354 // Template for the first PLT entry.
2355 static const uint32_t plt0_entry_o32
[];
2356 static const uint32_t plt0_entry_n32
[];
2357 static const uint32_t plt0_entry_n64
[];
2358 static const uint32_t plt0_entry_micromips_o32
[];
2359 static const uint32_t plt0_entry_micromips32_o32
[];
2361 // Template for subsequent PLT entries.
2362 static const uint32_t plt_entry
[];
2363 static const uint32_t plt_entry_mips16_o32
[];
2364 static const uint32_t plt_entry_micromips_o32
[];
2365 static const uint32_t plt_entry_micromips32_o32
[];
2367 // Set the final size.
2369 set_final_data_size()
2371 this->set_data_size(this->plt_header_size_
+ this->plt_mips_offset_
2372 + this->plt_comp_offset_
);
2375 // Write out the PLT data.
2377 do_write(Output_file
*);
2379 // Return whether the plt header contains microMIPS code. For the sake of
2380 // cache alignment always use a standard header whenever any standard entries
2381 // are present even if microMIPS entries are present as well. This also lets
2382 // the microMIPS header rely on the value of $v0 only set by microMIPS
2383 // entries, for a small size reduction.
2385 is_plt_header_compressed() const
2387 gold_assert(this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0);
2388 return this->target_
->is_output_micromips() && this->plt_mips_offset_
== 0;
2391 // Return the size of the PLT header.
2393 get_plt_header_size() const
2395 if (this->target_
->is_output_n64())
2396 return 4 * sizeof(plt0_entry_n64
) / sizeof(plt0_entry_n64
[0]);
2397 else if (this->target_
->is_output_n32())
2398 return 4 * sizeof(plt0_entry_n32
) / sizeof(plt0_entry_n32
[0]);
2399 else if (!this->is_plt_header_compressed())
2400 return 4 * sizeof(plt0_entry_o32
) / sizeof(plt0_entry_o32
[0]);
2401 else if (this->target_
->use_32bit_micromips_instructions())
2402 return (2 * sizeof(plt0_entry_micromips32_o32
)
2403 / sizeof(plt0_entry_micromips32_o32
[0]));
2405 return (2 * sizeof(plt0_entry_micromips_o32
)
2406 / sizeof(plt0_entry_micromips_o32
[0]));
2409 // Return the PLT header entry.
2411 get_plt_header_entry() const
2413 if (this->target_
->is_output_n64())
2414 return plt0_entry_n64
;
2415 else if (this->target_
->is_output_n32())
2416 return plt0_entry_n32
;
2417 else if (!this->is_plt_header_compressed())
2418 return plt0_entry_o32
;
2419 else if (this->target_
->use_32bit_micromips_instructions())
2420 return plt0_entry_micromips32_o32
;
2422 return plt0_entry_micromips_o32
;
2425 // Return the size of the standard PLT entry.
2427 standard_plt_entry_size() const
2428 { return 4 * sizeof(plt_entry
) / sizeof(plt_entry
[0]); }
2430 // Return the size of the compressed PLT entry.
2432 compressed_plt_entry_size() const
2434 gold_assert(!this->target_
->is_output_newabi());
2436 if (!this->target_
->is_output_micromips())
2437 return (2 * sizeof(plt_entry_mips16_o32
)
2438 / sizeof(plt_entry_mips16_o32
[0]));
2439 else if (this->target_
->use_32bit_micromips_instructions())
2440 return (2 * sizeof(plt_entry_micromips32_o32
)
2441 / sizeof(plt_entry_micromips32_o32
[0]));
2443 return (2 * sizeof(plt_entry_micromips_o32
)
2444 / sizeof(plt_entry_micromips_o32
[0]));
2447 // The reloc section.
2448 Reloc_section
* rel_
;
2449 // The .got.plt section.
2450 Output_data_space
* got_plt_
;
2451 // Symbols that have PLT entry.
2452 std::vector
<Mips_symbol
<size
>*> symbols_
;
2453 // The offset of the next standard PLT entry to create.
2454 unsigned int plt_mips_offset_
;
2455 // The offset of the next compressed PLT entry to create.
2456 unsigned int plt_comp_offset_
;
2457 // The size of the PLT header in bytes.
2458 unsigned int plt_header_size_
;
2460 Target_mips
<size
, big_endian
>* target_
;
2463 // A class to handle the .MIPS.stubs data.
2465 template<int size
, bool big_endian
>
2466 class Mips_output_data_mips_stubs
: public Output_section_data
2468 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2471 Mips_output_data_mips_stubs(Target_mips
<size
, big_endian
>* target
)
2472 : Output_section_data(size
== 32 ? 4 : 8), symbols_(), dynsym_count_(-1U),
2473 stub_offsets_are_set_(false), target_(target
)
2476 // Create entry for a symbol.
2478 make_entry(Mips_symbol
<size
>*);
2480 // Remove entry for a symbol.
2482 remove_entry(Mips_symbol
<size
>* gsym
);
2484 // Set stub offsets for symbols. This method expects that the number of
2485 // entries in dynamic symbol table is set.
2487 set_lazy_stub_offsets();
2490 set_needs_dynsym_value();
2492 // Set the number of entries in dynamic symbol table.
2494 set_dynsym_count(unsigned int dynsym_count
)
2495 { this->dynsym_count_
= dynsym_count
; }
2497 // Return maximum size of the stub, ie. the stub size if the dynamic symbol
2498 // count is greater than 0x10000. If the dynamic symbol count is less than
2499 // 0x10000, the stub will be 4 bytes smaller.
2500 // There's no disadvantage from using microMIPS code here, so for the sake of
2501 // pure-microMIPS binaries we prefer it whenever there's any microMIPS code in
2502 // output produced at all. This has a benefit of stubs being shorter by
2503 // 4 bytes each too, unless in the insn32 mode.
2505 stub_max_size() const
2507 if (!this->target_
->is_output_micromips()
2508 || this->target_
->use_32bit_micromips_instructions())
2514 // Return the size of the stub. This method expects that the final dynsym
2519 gold_assert(this->dynsym_count_
!= -1U);
2520 if (this->dynsym_count_
> 0x10000)
2521 return this->stub_max_size();
2523 return this->stub_max_size() - 4;
2526 // Return output address of a stub.
2528 stub_address(const Mips_symbol
<size
>* sym
) const
2530 gold_assert(sym
->has_lazy_stub());
2531 return this->address() + sym
->lazy_stub_offset();
2536 do_adjust_output_section(Output_section
* os
)
2537 { os
->set_entsize(0); }
2539 // Write to a map file.
2541 do_print_to_mapfile(Mapfile
* mapfile
) const
2542 { mapfile
->print_output_data(this, _(".MIPS.stubs")); }
2545 static const uint32_t lazy_stub_normal_1
[];
2546 static const uint32_t lazy_stub_normal_1_n64
[];
2547 static const uint32_t lazy_stub_normal_2
[];
2548 static const uint32_t lazy_stub_normal_2_n64
[];
2549 static const uint32_t lazy_stub_big
[];
2550 static const uint32_t lazy_stub_big_n64
[];
2552 static const uint32_t lazy_stub_micromips_normal_1
[];
2553 static const uint32_t lazy_stub_micromips_normal_1_n64
[];
2554 static const uint32_t lazy_stub_micromips_normal_2
[];
2555 static const uint32_t lazy_stub_micromips_normal_2_n64
[];
2556 static const uint32_t lazy_stub_micromips_big
[];
2557 static const uint32_t lazy_stub_micromips_big_n64
[];
2559 static const uint32_t lazy_stub_micromips32_normal_1
[];
2560 static const uint32_t lazy_stub_micromips32_normal_1_n64
[];
2561 static const uint32_t lazy_stub_micromips32_normal_2
[];
2562 static const uint32_t lazy_stub_micromips32_normal_2_n64
[];
2563 static const uint32_t lazy_stub_micromips32_big
[];
2564 static const uint32_t lazy_stub_micromips32_big_n64
[];
2566 // Set the final size.
2568 set_final_data_size()
2569 { this->set_data_size(this->symbols_
.size() * this->stub_max_size()); }
2571 // Write out the .MIPS.stubs data.
2573 do_write(Output_file
*);
2575 // .MIPS.stubs symbols
2576 Unordered_set
<Mips_symbol
<size
>*> symbols_
;
2577 // Number of entries in dynamic symbol table.
2578 unsigned int dynsym_count_
;
2579 // Whether the stub offsets are set.
2580 bool stub_offsets_are_set_
;
2582 Target_mips
<size
, big_endian
>* target_
;
2585 // This class handles Mips .reginfo output section.
2587 template<int size
, bool big_endian
>
2588 class Mips_output_section_reginfo
: public Output_section
2590 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
2593 Mips_output_section_reginfo(const char* name
, elfcpp::Elf_Word type
,
2594 elfcpp::Elf_Xword flags
,
2595 Target_mips
<size
, big_endian
>* target
)
2596 : Output_section(name
, type
, flags
), target_(target
), gprmask_(0),
2597 cprmask1_(0), cprmask2_(0), cprmask3_(0), cprmask4_(0)
2600 // Downcast a base pointer to a Mips_output_section_reginfo pointer.
2601 static Mips_output_section_reginfo
<size
, big_endian
>*
2602 as_mips_output_section_reginfo(Output_section
* os
)
2603 { return static_cast<Mips_output_section_reginfo
<size
, big_endian
>*>(os
); }
2605 // Set masks of the output .reginfo section.
2607 set_masks(Valtype gprmask
, Valtype cprmask1
, Valtype cprmask2
,
2608 Valtype cprmask3
, Valtype cprmask4
)
2610 this->gprmask_
= gprmask
;
2611 this->cprmask1_
= cprmask1
;
2612 this->cprmask2_
= cprmask2
;
2613 this->cprmask3_
= cprmask3
;
2614 this->cprmask4_
= cprmask4
;
2618 // Set the final data size.
2620 set_final_data_size()
2621 { this->set_data_size(24); }
2623 // Write out reginfo section.
2625 do_write(Output_file
* of
);
2628 Target_mips
<size
, big_endian
>* target_
;
2630 // gprmask of the output .reginfo section.
2632 // cprmask1 of the output .reginfo section.
2634 // cprmask2 of the output .reginfo section.
2636 // cprmask3 of the output .reginfo section.
2638 // cprmask4 of the output .reginfo section.
2642 // The MIPS target has relocation types which default handling of relocatable
2643 // relocation cannot process. So we have to extend the default code.
2645 template<bool big_endian
, int sh_type
, typename Classify_reloc
>
2646 class Mips_scan_relocatable_relocs
:
2647 public Default_scan_relocatable_relocs
<sh_type
, Classify_reloc
>
2650 // Return the strategy to use for a local symbol which is a section
2651 // symbol, given the relocation type.
2652 inline Relocatable_relocs::Reloc_strategy
2653 local_section_strategy(unsigned int r_type
, Relobj
* object
)
2655 if (sh_type
== elfcpp::SHT_RELA
)
2656 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
2661 case elfcpp::R_MIPS_26
:
2662 return Relocatable_relocs::RELOC_SPECIAL
;
2665 return Default_scan_relocatable_relocs
<sh_type
, Classify_reloc
>::
2666 local_section_strategy(r_type
, object
);
2672 // Mips_copy_relocs class. The only difference from the base class is the
2673 // method emit_mips, which should be called instead of Copy_reloc_entry::emit.
2674 // Mips cannot convert all relocation types to dynamic relocs. If a reloc
2675 // cannot be made dynamic, a COPY reloc is emitted.
2677 template<int sh_type
, int size
, bool big_endian
>
2678 class Mips_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
2682 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_MIPS_COPY
)
2685 // Emit any saved relocations which turn out to be needed. This is
2686 // called after all the relocs have been scanned.
2688 emit_mips(Output_data_reloc
<sh_type
, true, size
, big_endian
>*,
2689 Symbol_table
*, Layout
*, Target_mips
<size
, big_endian
>*);
2692 typedef typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
2695 // Emit this reloc if appropriate. This is called after we have
2696 // scanned all the relocations, so we know whether we emitted a
2697 // COPY relocation for SYM_.
2699 emit_entry(Copy_reloc_entry
& entry
,
2700 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
2701 Symbol_table
* symtab
, Layout
* layout
,
2702 Target_mips
<size
, big_endian
>* target
);
2706 // Return true if the symbol SYM should be considered to resolve local
2707 // to the current module, and false otherwise. The logic is taken from
2708 // GNU ld's method _bfd_elf_symbol_refs_local_p.
2710 symbol_refs_local(const Symbol
* sym
, bool has_dynsym_entry
,
2711 bool local_protected
)
2713 // If it's a local sym, of course we resolve locally.
2717 // STV_HIDDEN or STV_INTERNAL ones must be local.
2718 if (sym
->visibility() == elfcpp::STV_HIDDEN
2719 || sym
->visibility() == elfcpp::STV_INTERNAL
)
2722 // If we don't have a definition in a regular file, then we can't
2723 // resolve locally. The sym is either undefined or dynamic.
2724 if (sym
->source() != Symbol::FROM_OBJECT
|| sym
->object()->is_dynamic()
2725 || sym
->is_undefined())
2728 // Forced local symbols resolve locally.
2729 if (sym
->is_forced_local())
2732 // As do non-dynamic symbols.
2733 if (!has_dynsym_entry
)
2736 // At this point, we know the symbol is defined and dynamic. In an
2737 // executable it must resolve locally, likewise when building symbolic
2738 // shared libraries.
2739 if (parameters
->options().output_is_executable()
2740 || parameters
->options().Bsymbolic())
2743 // Now deal with defined dynamic symbols in shared libraries. Ones
2744 // with default visibility might not resolve locally.
2745 if (sym
->visibility() == elfcpp::STV_DEFAULT
)
2748 // STV_PROTECTED non-function symbols are local.
2749 if (sym
->type() != elfcpp::STT_FUNC
)
2752 // Function pointer equality tests may require that STV_PROTECTED
2753 // symbols be treated as dynamic symbols. If the address of a
2754 // function not defined in an executable is set to that function's
2755 // plt entry in the executable, then the address of the function in
2756 // a shared library must also be the plt entry in the executable.
2757 return local_protected
;
2760 // Return TRUE if references to this symbol always reference the symbol in this
2763 symbol_references_local(const Symbol
* sym
, bool has_dynsym_entry
)
2765 return symbol_refs_local(sym
, has_dynsym_entry
, false);
2768 // Return TRUE if calls to this symbol always call the version in this object.
2770 symbol_calls_local(const Symbol
* sym
, bool has_dynsym_entry
)
2772 return symbol_refs_local(sym
, has_dynsym_entry
, true);
2775 // Compare GOT offsets of two symbols.
2777 template<int size
, bool big_endian
>
2779 got_offset_compare(Symbol
* sym1
, Symbol
* sym2
)
2781 Mips_symbol
<size
>* mips_sym1
= Mips_symbol
<size
>::as_mips_sym(sym1
);
2782 Mips_symbol
<size
>* mips_sym2
= Mips_symbol
<size
>::as_mips_sym(sym2
);
2783 unsigned int area1
= mips_sym1
->global_got_area();
2784 unsigned int area2
= mips_sym2
->global_got_area();
2785 gold_assert(area1
!= GGA_NONE
&& area1
!= GGA_NONE
);
2787 // GGA_NORMAL entries always come before GGA_RELOC_ONLY.
2789 return area1
< area2
;
2791 return mips_sym1
->global_gotoffset() < mips_sym2
->global_gotoffset();
2794 // This method divides dynamic symbols into symbols that have GOT entry, and
2795 // symbols that don't have GOT entry. It also sorts symbols with the GOT entry.
2796 // Mips ABI requires that symbols with the GOT entry must be at the end of
2797 // dynamic symbol table, and the order in dynamic symbol table must match the
2800 template<int size
, bool big_endian
>
2802 reorder_dyn_symbols(std::vector
<Symbol
*>* dyn_symbols
,
2803 std::vector
<Symbol
*>* non_got_symbols
,
2804 std::vector
<Symbol
*>* got_symbols
)
2806 for (std::vector
<Symbol
*>::iterator p
= dyn_symbols
->begin();
2807 p
!= dyn_symbols
->end();
2810 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(*p
);
2811 if (mips_sym
->global_got_area() == GGA_NORMAL
2812 || mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
2813 got_symbols
->push_back(mips_sym
);
2815 non_got_symbols
->push_back(mips_sym
);
2818 std::sort(got_symbols
->begin(), got_symbols
->end(),
2819 got_offset_compare
<size
, big_endian
>);
2822 // Functor class for processing the global symbol table.
2824 template<int size
, bool big_endian
>
2825 class Symbol_visitor_check_symbols
2828 Symbol_visitor_check_symbols(Target_mips
<size
, big_endian
>* target
,
2829 Layout
* layout
, Symbol_table
* symtab
)
2830 : target_(target
), layout_(layout
), symtab_(symtab
)
2834 operator()(Sized_symbol
<size
>* sym
)
2836 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
2837 if (local_pic_function
<size
, big_endian
>(mips_sym
))
2839 // SYM is a function that might need $25 to be valid on entry.
2840 // If we're creating a non-PIC relocatable object, mark SYM as
2841 // being PIC. If we're creating a non-relocatable object with
2842 // non-PIC branches and jumps to SYM, make sure that SYM has an la25
2844 if (parameters
->options().relocatable())
2846 if (!parameters
->options().output_is_position_independent())
2847 mips_sym
->set_pic();
2849 else if (mips_sym
->has_nonpic_branches())
2851 this->target_
->la25_stub_section(layout_
)
2852 ->create_la25_stub(this->symtab_
, this->target_
, mips_sym
);
2858 Target_mips
<size
, big_endian
>* target_
;
2860 Symbol_table
* symtab_
;
2863 template<int size
, bool big_endian
>
2864 class Target_mips
: public Sized_target
<size
, big_endian
>
2866 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2867 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
2869 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
>
2871 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
2872 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
2875 Target_mips(const Target::Target_info
* info
= &mips_info
)
2876 : Sized_target
<size
, big_endian
>(info
), got_(NULL
), gp_(NULL
), plt_(NULL
),
2877 got_plt_(NULL
), rel_dyn_(NULL
), copy_relocs_(),
2878 dyn_relocs_(), la25_stub_(NULL
), mips_mach_extensions_(),
2879 mips_stubs_(NULL
), ei_class_(0), mach_(0), layout_(NULL
),
2880 got16_addends_(), entry_symbol_is_compressed_(false), insn32_(false)
2882 this->add_machine_extensions();
2885 // The offset of $gp from the beginning of the .got section.
2886 static const unsigned int MIPS_GP_OFFSET
= 0x7ff0;
2888 // The maximum size of the GOT for it to be addressable using 16-bit
2889 // offsets from $gp.
2890 static const unsigned int MIPS_GOT_MAX_SIZE
= MIPS_GP_OFFSET
+ 0x7fff;
2892 // Make a new symbol table entry for the Mips target.
2895 { return new Mips_symbol
<size
>(); }
2897 // Process the relocations to determine unreferenced sections for
2898 // garbage collection.
2900 gc_process_relocs(Symbol_table
* symtab
,
2902 Sized_relobj_file
<size
, big_endian
>* object
,
2903 unsigned int data_shndx
,
2904 unsigned int sh_type
,
2905 const unsigned char* prelocs
,
2907 Output_section
* output_section
,
2908 bool needs_special_offset_handling
,
2909 size_t local_symbol_count
,
2910 const unsigned char* plocal_symbols
);
2912 // Scan the relocations to look for symbol adjustments.
2914 scan_relocs(Symbol_table
* symtab
,
2916 Sized_relobj_file
<size
, big_endian
>* object
,
2917 unsigned int data_shndx
,
2918 unsigned int sh_type
,
2919 const unsigned char* prelocs
,
2921 Output_section
* output_section
,
2922 bool needs_special_offset_handling
,
2923 size_t local_symbol_count
,
2924 const unsigned char* plocal_symbols
);
2926 // Finalize the sections.
2928 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
2930 // Relocate a section.
2932 relocate_section(const Relocate_info
<size
, big_endian
>*,
2933 unsigned int sh_type
,
2934 const unsigned char* prelocs
,
2936 Output_section
* output_section
,
2937 bool needs_special_offset_handling
,
2938 unsigned char* view
,
2939 Mips_address view_address
,
2940 section_size_type view_size
,
2941 const Reloc_symbol_changes
*);
2943 // Scan the relocs during a relocatable link.
2945 scan_relocatable_relocs(Symbol_table
* symtab
,
2947 Sized_relobj_file
<size
, big_endian
>* object
,
2948 unsigned int data_shndx
,
2949 unsigned int sh_type
,
2950 const unsigned char* prelocs
,
2952 Output_section
* output_section
,
2953 bool needs_special_offset_handling
,
2954 size_t local_symbol_count
,
2955 const unsigned char* plocal_symbols
,
2956 Relocatable_relocs
*);
2958 // Emit relocations for a section.
2960 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
2961 unsigned int sh_type
,
2962 const unsigned char* prelocs
,
2964 Output_section
* output_section
,
2965 typename
elfcpp::Elf_types
<size
>::Elf_Off
2966 offset_in_output_section
,
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
>*, unsigned int,
3395 Target_mips
*, Output_section
*, size_t, const unsigned char*,
3396 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
3397 unsigned char*, Mips_address
, section_size_type
);
3400 // A class which returns the size required for a relocation type,
3401 // used while scanning relocs during a relocatable link.
3402 class Relocatable_size_for_reloc
3406 get_size_for_reloc(unsigned int, Relobj
*);
3409 // This POD class holds the dynamic relocations that should be emitted instead
3410 // of R_MIPS_32, R_MIPS_REL32 and R_MIPS_64 relocations. We will emit these
3411 // relocations if it turns out that the symbol does not have static
3416 Dyn_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
3417 Mips_relobj
<size
, big_endian
>* relobj
, unsigned int shndx
,
3418 Output_section
* output_section
, Mips_address r_offset
)
3419 : sym_(sym
), r_type_(r_type
), relobj_(relobj
),
3420 shndx_(shndx
), output_section_(output_section
),
3424 // Emit this reloc if appropriate. This is called after we have
3425 // scanned all the relocations, so we know whether the symbol has
3426 // static relocations.
3428 emit(Reloc_section
* rel_dyn
, Mips_output_data_got
<size
, big_endian
>* got
,
3429 Symbol_table
* symtab
)
3431 if (!this->sym_
->has_static_relocs())
3433 got
->record_global_got_symbol(this->sym_
, this->relobj_
,
3434 this->r_type_
, true, false);
3435 if (!symbol_references_local(this->sym_
,
3436 this->sym_
->should_add_dynsym_entry(symtab
)))
3437 rel_dyn
->add_global(this->sym_
, this->r_type_
,
3438 this->output_section_
, this->relobj_
,
3439 this->shndx_
, this->r_offset_
);
3441 rel_dyn
->add_symbolless_global_addend(this->sym_
, this->r_type_
,
3442 this->output_section_
, this->relobj_
,
3443 this->shndx_
, this->r_offset_
);
3448 Mips_symbol
<size
>* sym_
;
3449 unsigned int r_type_
;
3450 Mips_relobj
<size
, big_endian
>* relobj_
;
3451 unsigned int shndx_
;
3452 Output_section
* output_section_
;
3453 Mips_address r_offset_
;
3456 // Adjust TLS relocation type based on the options and whether this
3457 // is a local symbol.
3458 static tls::Tls_optimization
3459 optimize_tls_reloc(bool is_final
, int r_type
);
3461 // Return whether there is a GOT section.
3463 has_got_section() const
3464 { return this->got_
!= NULL
; }
3466 // Check whether the given ELF header flags describe a 32-bit binary.
3468 mips_32bit_flags(elfcpp::Elf_Word
);
3471 mach_mips3000
= 3000,
3472 mach_mips3900
= 3900,
3473 mach_mips4000
= 4000,
3474 mach_mips4010
= 4010,
3475 mach_mips4100
= 4100,
3476 mach_mips4111
= 4111,
3477 mach_mips4120
= 4120,
3478 mach_mips4300
= 4300,
3479 mach_mips4400
= 4400,
3480 mach_mips4600
= 4600,
3481 mach_mips4650
= 4650,
3482 mach_mips5000
= 5000,
3483 mach_mips5400
= 5400,
3484 mach_mips5500
= 5500,
3485 mach_mips6000
= 6000,
3486 mach_mips7000
= 7000,
3487 mach_mips8000
= 8000,
3488 mach_mips9000
= 9000,
3489 mach_mips10000
= 10000,
3490 mach_mips12000
= 12000,
3491 mach_mips14000
= 14000,
3492 mach_mips16000
= 16000,
3495 mach_mips_loongson_2e
= 3001,
3496 mach_mips_loongson_2f
= 3002,
3497 mach_mips_loongson_3a
= 3003,
3498 mach_mips_sb1
= 12310201, // octal 'SB', 01
3499 mach_mips_octeon
= 6501,
3500 mach_mips_octeonp
= 6601,
3501 mach_mips_octeon2
= 6502,
3502 mach_mips_xlr
= 887682, // decimal 'XLR'
3503 mach_mipsisa32
= 32,
3504 mach_mipsisa32r2
= 33,
3505 mach_mipsisa64
= 64,
3506 mach_mipsisa64r2
= 65,
3507 mach_mips_micromips
= 96
3510 // Return the MACH for a MIPS e_flags value.
3512 elf_mips_mach(elfcpp::Elf_Word
);
3514 // Check whether machine EXTENSION is an extension of machine BASE.
3516 mips_mach_extends(unsigned int, unsigned int);
3518 // Merge processor specific flags.
3520 merge_processor_specific_flags(const std::string
&, elfcpp::Elf_Word
,
3521 unsigned char, bool);
3523 // True if we are linking for CPUs that are faster if JAL is converted to BAL.
3528 // True if we are linking for CPUs that are faster if JALR is converted to
3529 // BAL. This should be safe for all architectures. We enable this predicate
3535 // True if we are linking for CPUs that are faster if JR is converted to B.
3536 // This should be safe for all architectures. We enable this predicate for
3542 // Return the size of the GOT section.
3546 gold_assert(this->got_
!= NULL
);
3547 return this->got_
->data_size();
3550 // Create a PLT entry for a global symbol referenced by r_type relocation.
3552 make_plt_entry(Symbol_table
*, Layout
*, Mips_symbol
<size
>*,
3553 unsigned int r_type
);
3555 // Get the PLT section.
3556 Mips_output_data_plt
<size
, big_endian
>*
3559 gold_assert(this->plt_
!= NULL
);
3563 // Get the GOT PLT section.
3564 const Mips_output_data_plt
<size
, big_endian
>*
3565 got_plt_section() const
3567 gold_assert(this->got_plt_
!= NULL
);
3568 return this->got_plt_
;
3571 // Copy a relocation against a global symbol.
3573 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
3574 Sized_relobj_file
<size
, big_endian
>* object
,
3575 unsigned int shndx
, Output_section
* output_section
,
3576 Symbol
* sym
, const elfcpp::Rel
<size
, big_endian
>& reloc
)
3578 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
3579 this->copy_relocs_
.copy_reloc(symtab
, layout
,
3580 symtab
->get_sized_symbol
<size
>(sym
),
3581 object
, shndx
, output_section
,
3582 r_type
, reloc
.get_r_offset(), 0,
3583 this->rel_dyn_section(layout
));
3587 dynamic_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
3588 Mips_relobj
<size
, big_endian
>* relobj
,
3589 unsigned int shndx
, Output_section
* output_section
,
3590 Mips_address r_offset
)
3592 this->dyn_relocs_
.push_back(Dyn_reloc(sym
, r_type
, relobj
, shndx
,
3593 output_section
, r_offset
));
3596 // Calculate value of _gp symbol.
3598 set_gp(Layout
*, Symbol_table
*);
3601 elf_mips_abi_name(elfcpp::Elf_Word e_flags
, unsigned char ei_class
);
3603 elf_mips_mach_name(elfcpp::Elf_Word e_flags
);
3605 // Adds entries that describe how machines relate to one another. The entries
3606 // are ordered topologically with MIPS I extensions listed last. First
3607 // element is extension, second element is base.
3609 add_machine_extensions()
3611 // MIPS64r2 extensions.
3612 this->add_extension(mach_mips_octeon2
, mach_mips_octeonp
);
3613 this->add_extension(mach_mips_octeonp
, mach_mips_octeon
);
3614 this->add_extension(mach_mips_octeon
, mach_mipsisa64r2
);
3616 // MIPS64 extensions.
3617 this->add_extension(mach_mipsisa64r2
, mach_mipsisa64
);
3618 this->add_extension(mach_mips_sb1
, mach_mipsisa64
);
3619 this->add_extension(mach_mips_xlr
, mach_mipsisa64
);
3620 this->add_extension(mach_mips_loongson_3a
, mach_mipsisa64
);
3622 // MIPS V extensions.
3623 this->add_extension(mach_mipsisa64
, mach_mips5
);
3625 // R10000 extensions.
3626 this->add_extension(mach_mips12000
, mach_mips10000
);
3627 this->add_extension(mach_mips14000
, mach_mips10000
);
3628 this->add_extension(mach_mips16000
, mach_mips10000
);
3630 // R5000 extensions. Note: the vr5500 ISA is an extension of the core
3631 // vr5400 ISA, but doesn't include the multimedia stuff. It seems
3632 // better to allow vr5400 and vr5500 code to be merged anyway, since
3633 // many libraries will just use the core ISA. Perhaps we could add
3634 // some sort of ASE flag if this ever proves a problem.
3635 this->add_extension(mach_mips5500
, mach_mips5400
);
3636 this->add_extension(mach_mips5400
, mach_mips5000
);
3638 // MIPS IV extensions.
3639 this->add_extension(mach_mips5
, mach_mips8000
);
3640 this->add_extension(mach_mips10000
, mach_mips8000
);
3641 this->add_extension(mach_mips5000
, mach_mips8000
);
3642 this->add_extension(mach_mips7000
, mach_mips8000
);
3643 this->add_extension(mach_mips9000
, mach_mips8000
);
3645 // VR4100 extensions.
3646 this->add_extension(mach_mips4120
, mach_mips4100
);
3647 this->add_extension(mach_mips4111
, mach_mips4100
);
3649 // MIPS III extensions.
3650 this->add_extension(mach_mips_loongson_2e
, mach_mips4000
);
3651 this->add_extension(mach_mips_loongson_2f
, mach_mips4000
);
3652 this->add_extension(mach_mips8000
, mach_mips4000
);
3653 this->add_extension(mach_mips4650
, mach_mips4000
);
3654 this->add_extension(mach_mips4600
, mach_mips4000
);
3655 this->add_extension(mach_mips4400
, mach_mips4000
);
3656 this->add_extension(mach_mips4300
, mach_mips4000
);
3657 this->add_extension(mach_mips4100
, mach_mips4000
);
3658 this->add_extension(mach_mips4010
, mach_mips4000
);
3660 // MIPS32 extensions.
3661 this->add_extension(mach_mipsisa32r2
, mach_mipsisa32
);
3663 // MIPS II extensions.
3664 this->add_extension(mach_mips4000
, mach_mips6000
);
3665 this->add_extension(mach_mipsisa32
, mach_mips6000
);
3667 // MIPS I extensions.
3668 this->add_extension(mach_mips6000
, mach_mips3000
);
3669 this->add_extension(mach_mips3900
, mach_mips3000
);
3672 // Add value to MIPS extenstions.
3674 add_extension(unsigned int base
, unsigned int extension
)
3676 std::pair
<unsigned int, unsigned int> ext(base
, extension
);
3677 this->mips_mach_extensions_
.push_back(ext
);
3680 // Return the number of entries in the .dynsym section.
3681 unsigned int get_dt_mips_symtabno() const
3683 return ((unsigned int)(this->layout_
->dynsym_section()->data_size()
3684 / elfcpp::Elf_sizes
<size
>::sym_size
));
3685 // TODO(sasa): Entry size is MIPS_ELF_SYM_SIZE.
3688 // Information about this specific target which we pass to the
3689 // general Target structure.
3690 static const Target::Target_info mips_info
;
3692 Mips_output_data_got
<size
, big_endian
>* got_
;
3693 // gp symbol. It has the value of .got + 0x7FF0.
3694 Sized_symbol
<size
>* gp_
;
3696 Mips_output_data_plt
<size
, big_endian
>* plt_
;
3697 // The GOT PLT section.
3698 Output_data_space
* got_plt_
;
3699 // The dynamic reloc section.
3700 Reloc_section
* rel_dyn_
;
3701 // Relocs saved to avoid a COPY reloc.
3702 Mips_copy_relocs
<elfcpp::SHT_REL
, size
, big_endian
> copy_relocs_
;
3704 // A list of dyn relocs to be saved.
3705 std::vector
<Dyn_reloc
> dyn_relocs_
;
3707 // The LA25 stub section.
3708 Mips_output_data_la25_stub
<size
, big_endian
>* la25_stub_
;
3709 // Architecture extensions.
3710 std::vector
<std::pair
<unsigned int, unsigned int> > mips_mach_extensions_
;
3712 Mips_output_data_mips_stubs
<size
, big_endian
>* mips_stubs_
;
3714 unsigned char ei_class_
;
3718 typename
std::list
<got16_addend
<size
, big_endian
> > got16_addends_
;
3720 // Whether the entry symbol is mips16 or micromips.
3721 bool entry_symbol_is_compressed_
;
3723 // Whether we can use only 32-bit microMIPS instructions.
3724 // TODO(sasa): This should be a linker option.
3729 // Helper structure for R_MIPS*_HI16/LO16 and R_MIPS*_GOT16/LO16 relocations.
3730 // It records high part of the relocation pair.
3732 template<int size
, bool big_endian
>
3735 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
3737 reloc_high(unsigned char* _view
, const Mips_relobj
<size
, big_endian
>* _object
,
3738 const Symbol_value
<size
>* _psymval
, Mips_address _addend
,
3739 unsigned int _r_type
, unsigned int _r_sym
, bool _extract_addend
,
3740 Mips_address _address
= 0, bool _gp_disp
= false)
3741 : view(_view
), object(_object
), psymval(_psymval
), addend(_addend
),
3742 r_type(_r_type
), r_sym(_r_sym
), extract_addend(_extract_addend
),
3743 address(_address
), gp_disp(_gp_disp
)
3746 unsigned char* view
;
3747 const Mips_relobj
<size
, big_endian
>* object
;
3748 const Symbol_value
<size
>* psymval
;
3749 Mips_address addend
;
3750 unsigned int r_type
;
3752 bool extract_addend
;
3753 Mips_address address
;
3757 template<int size
, bool big_endian
>
3758 class Mips_relocate_functions
: public Relocate_functions
<size
, big_endian
>
3760 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
3761 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype16
;
3762 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
3767 STATUS_OKAY
, // No error during relocation.
3768 STATUS_OVERFLOW
, // Relocation overflow.
3769 STATUS_BAD_RELOC
// Relocation cannot be applied.
3773 typedef Relocate_functions
<size
, big_endian
> Base
;
3774 typedef Mips_relocate_functions
<size
, big_endian
> This
;
3776 static typename
std::list
<reloc_high
<size
, big_endian
> > hi16_relocs
;
3777 static typename
std::list
<reloc_high
<size
, big_endian
> > got16_relocs
;
3779 // R_MIPS16_26 is used for the mips16 jal and jalx instructions.
3780 // Most mips16 instructions are 16 bits, but these instructions
3783 // The format of these instructions is:
3785 // +--------------+--------------------------------+
3786 // | JALX | X| Imm 20:16 | Imm 25:21 |
3787 // +--------------+--------------------------------+
3788 // | Immediate 15:0 |
3789 // +-----------------------------------------------+
3791 // JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
3792 // Note that the immediate value in the first word is swapped.
3794 // When producing a relocatable object file, R_MIPS16_26 is
3795 // handled mostly like R_MIPS_26. In particular, the addend is
3796 // stored as a straight 26-bit value in a 32-bit instruction.
3797 // (gas makes life simpler for itself by never adjusting a
3798 // R_MIPS16_26 reloc to be against a section, so the addend is
3799 // always zero). However, the 32 bit instruction is stored as 2
3800 // 16-bit values, rather than a single 32-bit value. In a
3801 // big-endian file, the result is the same; in a little-endian
3802 // file, the two 16-bit halves of the 32 bit value are swapped.
3803 // This is so that a disassembler can recognize the jal
3806 // When doing a final link, R_MIPS16_26 is treated as a 32 bit
3807 // instruction stored as two 16-bit values. The addend A is the
3808 // contents of the targ26 field. The calculation is the same as
3809 // R_MIPS_26. When storing the calculated value, reorder the
3810 // immediate value as shown above, and don't forget to store the
3811 // value as two 16-bit values.
3813 // To put it in MIPS ABI terms, the relocation field is T-targ26-16,
3817 // +--------+----------------------+
3821 // +--------+----------------------+
3824 // +----------+------+-------------+
3826 // | sub1 | | sub2 |
3827 // |0 9|10 15|16 31|
3828 // +----------+--------------------+
3829 // where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
3830 // ((sub1 << 16) | sub2)).
3832 // When producing a relocatable object file, the calculation is
3833 // (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
3834 // When producing a fully linked file, the calculation is
3835 // let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
3836 // ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
3838 // The table below lists the other MIPS16 instruction relocations.
3839 // Each one is calculated in the same way as the non-MIPS16 relocation
3840 // given on the right, but using the extended MIPS16 layout of 16-bit
3841 // immediate fields:
3843 // R_MIPS16_GPREL R_MIPS_GPREL16
3844 // R_MIPS16_GOT16 R_MIPS_GOT16
3845 // R_MIPS16_CALL16 R_MIPS_CALL16
3846 // R_MIPS16_HI16 R_MIPS_HI16
3847 // R_MIPS16_LO16 R_MIPS_LO16
3849 // A typical instruction will have a format like this:
3851 // +--------------+--------------------------------+
3852 // | EXTEND | Imm 10:5 | Imm 15:11 |
3853 // +--------------+--------------------------------+
3854 // | Major | rx | ry | Imm 4:0 |
3855 // +--------------+--------------------------------+
3857 // EXTEND is the five bit value 11110. Major is the instruction
3860 // All we need to do here is shuffle the bits appropriately.
3861 // As above, the two 16-bit halves must be swapped on a
3862 // little-endian system.
3864 // Similar to MIPS16, the two 16-bit halves in microMIPS must be swapped
3865 // on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1
3866 // and R_MICROMIPS_PC10_S1 relocs that apply to 16-bit instructions.
3869 should_shuffle_micromips_reloc(unsigned int r_type
)
3871 return (micromips_reloc(r_type
)
3872 && r_type
!= elfcpp::R_MICROMIPS_PC7_S1
3873 && r_type
!= elfcpp::R_MICROMIPS_PC10_S1
);
3877 mips_reloc_unshuffle(unsigned char* view
, unsigned int r_type
,
3880 if (!mips16_reloc(r_type
)
3881 && !should_shuffle_micromips_reloc(r_type
))
3884 // Pick up the first and second halfwords of the instruction.
3885 Valtype16 first
= elfcpp::Swap
<16, big_endian
>::readval(view
);
3886 Valtype16 second
= elfcpp::Swap
<16, big_endian
>::readval(view
+ 2);
3889 if (micromips_reloc(r_type
)
3890 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
3891 val
= first
<< 16 | second
;
3892 else if (r_type
!= elfcpp::R_MIPS16_26
)
3893 val
= (((first
& 0xf800) << 16) | ((second
& 0xffe0) << 11)
3894 | ((first
& 0x1f) << 11) | (first
& 0x7e0) | (second
& 0x1f));
3896 val
= (((first
& 0xfc00) << 16) | ((first
& 0x3e0) << 11)
3897 | ((first
& 0x1f) << 21) | second
);
3899 elfcpp::Swap
<32, big_endian
>::writeval(view
, val
);
3903 mips_reloc_shuffle(unsigned char* view
, unsigned int r_type
, bool jal_shuffle
)
3905 if (!mips16_reloc(r_type
)
3906 && !should_shuffle_micromips_reloc(r_type
))
3909 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
3910 Valtype16 first
, second
;
3912 if (micromips_reloc(r_type
)
3913 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
3915 second
= val
& 0xffff;
3918 else if (r_type
!= elfcpp::R_MIPS16_26
)
3920 second
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
3921 first
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
3925 second
= val
& 0xffff;
3926 first
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
3927 | ((val
>> 21) & 0x1f);
3930 elfcpp::Swap
<16, big_endian
>::writeval(view
+ 2, second
);
3931 elfcpp::Swap
<16, big_endian
>::writeval(view
, first
);
3935 // R_MIPS_16: S + sign-extend(A)
3936 static inline typename
This::Status
3937 rel16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
3938 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
3939 bool extract_addend
, unsigned int r_type
)
3941 mips_reloc_unshuffle(view
, r_type
, false);
3942 Valtype16
* wv
= reinterpret_cast<Valtype16
*>(view
);
3943 Valtype16 val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
3945 Valtype32 addend
= (extract_addend
? Bits
<16>::sign_extend32(val
)
3946 : Bits
<16>::sign_extend32(addend_a
));
3948 Valtype32 x
= psymval
->value(object
, addend
);
3949 val
= Bits
<16>::bit_select32(val
, x
, 0xffffU
);
3950 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
3951 mips_reloc_shuffle(view
, r_type
, false);
3952 return (Bits
<16>::has_overflow32(x
)
3953 ? This::STATUS_OVERFLOW
3954 : This::STATUS_OKAY
);
3958 static inline typename
This::Status
3959 rel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
3960 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
3961 bool extract_addend
, unsigned int r_type
)
3963 mips_reloc_unshuffle(view
, r_type
, false);
3964 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
3965 Valtype32 addend
= (extract_addend
3966 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
3967 : Bits
<32>::sign_extend32(addend_a
));
3968 Valtype32 x
= psymval
->value(object
, addend
);
3969 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
3970 mips_reloc_shuffle(view
, r_type
, false);
3971 return This::STATUS_OKAY
;
3974 // R_MIPS_JALR, R_MICROMIPS_JALR
3975 static inline typename
This::Status
3976 reljalr(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
3977 const Symbol_value
<size
>* psymval
, Mips_address address
,
3978 Mips_address addend_a
, bool extract_addend
, bool cross_mode_jump
,
3979 unsigned int r_type
, bool jalr_to_bal
, bool jr_to_b
)
3981 mips_reloc_unshuffle(view
, r_type
, false);
3982 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
3983 Valtype32 addend
= extract_addend
? 0 : addend_a
;
3984 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3986 // Try converting J(AL)R to B(AL), if the target is in range.
3987 if (!parameters
->options().relocatable()
3988 && r_type
== elfcpp::R_MIPS_JALR
3990 && ((jalr_to_bal
&& val
== 0x0320f809) // jalr t9
3991 || (jr_to_b
&& val
== 0x03200008))) // jr t9
3993 int offset
= psymval
->value(object
, addend
) - (address
+ 4);
3994 if (!Bits
<18>::has_overflow32(offset
))
3996 if (val
== 0x03200008) // jr t9
3997 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
3999 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4003 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4004 mips_reloc_shuffle(view
, r_type
, false);
4005 return This::STATUS_OKAY
;
4008 // R_MIPS_PC32: S + A - P
4009 static inline typename
This::Status
4010 relpc32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4011 const Symbol_value
<size
>* psymval
, Mips_address address
,
4012 Mips_address addend_a
, bool extract_addend
, unsigned int r_type
)
4014 mips_reloc_unshuffle(view
, r_type
, false);
4015 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4016 Valtype32 addend
= (extract_addend
4017 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
4018 : Bits
<32>::sign_extend32(addend_a
));
4019 Valtype32 x
= psymval
->value(object
, addend
) - address
;
4020 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4021 mips_reloc_shuffle(view
, r_type
, false);
4022 return This::STATUS_OKAY
;
4025 // R_MIPS_26, R_MIPS16_26, R_MICROMIPS_26_S1
4026 static inline typename
This::Status
4027 rel26(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4028 const Symbol_value
<size
>* psymval
, Mips_address address
,
4029 bool local
, Mips_address addend_a
, bool extract_addend
,
4030 const Symbol
* gsym
, bool cross_mode_jump
, unsigned int r_type
,
4033 mips_reloc_unshuffle(view
, r_type
, false);
4034 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4035 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4040 if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4041 addend
= (val
& 0x03ffffff) << 1;
4043 addend
= (val
& 0x03ffffff) << 2;
4048 // Make sure the target of JALX is word-aligned. Bit 0 must be
4049 // the correct ISA mode selector and bit 1 must be 0.
4051 && (psymval
->value(object
, 0) & 3) != (r_type
== elfcpp::R_MIPS_26
))
4053 gold_warning(_("JALX to a non-word-aligned address"));
4054 mips_reloc_shuffle(view
, r_type
, !parameters
->options().relocatable());
4055 return This::STATUS_BAD_RELOC
;
4058 // Shift is 2, unusually, for microMIPS JALX.
4059 unsigned int shift
=
4060 (!cross_mode_jump
&& r_type
== elfcpp::R_MICROMIPS_26_S1
) ? 1 : 2;
4064 x
= addend
| ((address
+ 4) & (0xfc000000 << shift
));
4068 x
= Bits
<27>::sign_extend32(addend
);
4070 x
= Bits
<28>::sign_extend32(addend
);
4072 x
= psymval
->value(object
, x
) >> shift
;
4074 if (!local
&& !gsym
->is_weak_undefined())
4076 if ((x
>> 26) != ((address
+ 4) >> (26 + shift
)))
4078 gold_error(_("relocation truncated to fit: %u against '%s'"),
4079 r_type
, gsym
->name());
4080 return This::STATUS_OVERFLOW
;
4084 val
= Bits
<32>::bit_select32(val
, x
, 0x03ffffff);
4086 // If required, turn JAL into JALX.
4087 if (cross_mode_jump
)
4090 Valtype32 opcode
= val
>> 26;
4091 Valtype32 jalx_opcode
;
4093 // Check to see if the opcode is already JAL or JALX.
4094 if (r_type
== elfcpp::R_MIPS16_26
)
4096 ok
= (opcode
== 0x6) || (opcode
== 0x7);
4099 else if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4101 ok
= (opcode
== 0x3d) || (opcode
== 0x3c);
4106 ok
= (opcode
== 0x3) || (opcode
== 0x1d);
4110 // If the opcode is not JAL or JALX, there's a problem. We cannot
4111 // convert J or JALS to JALX.
4114 gold_error(_("Unsupported jump between ISA modes; consider "
4115 "recompiling with interlinking enabled."));
4116 return This::STATUS_BAD_RELOC
;
4119 // Make this the JALX opcode.
4120 val
= (val
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
4123 // Try converting JAL to BAL, if the target is in range.
4124 if (!parameters
->options().relocatable()
4127 && r_type
== elfcpp::R_MIPS_26
4128 && (val
>> 26) == 0x3))) // jal addr
4130 Valtype32 dest
= (x
<< 2) | (((address
+ 4) >> 28) << 28);
4131 int offset
= dest
- (address
+ 4);
4132 if (!Bits
<18>::has_overflow32(offset
))
4134 if (val
== 0x03200008) // jr t9
4135 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4137 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4141 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4142 mips_reloc_shuffle(view
, r_type
, !parameters
->options().relocatable());
4143 return This::STATUS_OKAY
;
4147 static inline typename
This::Status
4148 relpc16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4149 const Symbol_value
<size
>* psymval
, Mips_address address
,
4150 Mips_address addend_a
, bool extract_addend
, unsigned int r_type
)
4152 mips_reloc_unshuffle(view
, r_type
, false);
4153 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4154 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4156 Valtype32 addend
= extract_addend
? (val
& 0xffff) << 2 : addend_a
;
4157 addend
= Bits
<18>::sign_extend32(addend
);
4159 Valtype32 x
= psymval
->value(object
, addend
) - address
;
4160 val
= Bits
<16>::bit_select32(val
, x
>> 2, 0xffff);
4161 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4162 mips_reloc_shuffle(view
, r_type
, false);
4163 return (Bits
<18>::has_overflow32(x
)
4164 ? This::STATUS_OVERFLOW
4165 : This::STATUS_OKAY
);
4168 // R_MICROMIPS_PC7_S1
4169 static inline typename
This::Status
4170 relmicromips_pc7_s1(unsigned char* view
,
4171 const Mips_relobj
<size
, big_endian
>* object
,
4172 const Symbol_value
<size
>* psymval
, Mips_address address
,
4173 Mips_address addend_a
, bool extract_addend
,
4174 unsigned int r_type
)
4176 mips_reloc_unshuffle(view
, r_type
, false);
4177 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4178 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4180 Valtype32 addend
= extract_addend
? (val
& 0x7f) << 1 : addend_a
;
4181 addend
= Bits
<8>::sign_extend32(addend
);
4183 Valtype32 x
= psymval
->value(object
, addend
) - address
;
4184 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x7f);
4185 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4186 mips_reloc_shuffle(view
, r_type
, false);
4187 return (Bits
<8>::has_overflow32(x
)
4188 ? This::STATUS_OVERFLOW
4189 : This::STATUS_OKAY
);
4192 // R_MICROMIPS_PC10_S1
4193 static inline typename
This::Status
4194 relmicromips_pc10_s1(unsigned char* view
,
4195 const Mips_relobj
<size
, big_endian
>* object
,
4196 const Symbol_value
<size
>* psymval
, Mips_address address
,
4197 Mips_address addend_a
, bool extract_addend
,
4198 unsigned int r_type
)
4200 mips_reloc_unshuffle(view
, r_type
, false);
4201 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4202 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4204 Valtype32 addend
= extract_addend
? (val
& 0x3ff) << 1 : addend_a
;
4205 addend
= Bits
<11>::sign_extend32(addend
);
4207 Valtype32 x
= psymval
->value(object
, addend
) - address
;
4208 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x3ff);
4209 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4210 mips_reloc_shuffle(view
, r_type
, false);
4211 return (Bits
<11>::has_overflow32(x
)
4212 ? This::STATUS_OVERFLOW
4213 : This::STATUS_OKAY
);
4216 // R_MICROMIPS_PC16_S1
4217 static inline typename
This::Status
4218 relmicromips_pc16_s1(unsigned char* view
,
4219 const Mips_relobj
<size
, big_endian
>* object
,
4220 const Symbol_value
<size
>* psymval
, Mips_address address
,
4221 Mips_address addend_a
, bool extract_addend
,
4222 unsigned int r_type
)
4224 mips_reloc_unshuffle(view
, r_type
, false);
4225 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4226 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4228 Valtype32 addend
= extract_addend
? (val
& 0xffff) << 1 : addend_a
;
4229 addend
= Bits
<17>::sign_extend32(addend
);
4231 Valtype32 x
= psymval
->value(object
, addend
) - address
;
4232 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0xffff);
4233 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4234 mips_reloc_shuffle(view
, r_type
, false);
4235 return (Bits
<17>::has_overflow32(x
)
4236 ? This::STATUS_OVERFLOW
4237 : This::STATUS_OKAY
);
4240 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
4241 static inline typename
This::Status
4242 relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4243 const Symbol_value
<size
>* psymval
, Mips_address addend
,
4244 Mips_address address
, bool gp_disp
, unsigned int r_type
,
4245 unsigned int r_sym
, bool extract_addend
)
4247 // Record the relocation. It will be resolved when we find lo16 part.
4248 hi16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
4249 addend
, r_type
, r_sym
, extract_addend
, address
,
4251 return This::STATUS_OKAY
;
4254 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
4255 static inline typename
This::Status
4256 do_relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4257 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
4258 Mips_address address
, bool is_gp_disp
, unsigned int r_type
,
4259 bool extract_addend
, Valtype32 addend_lo
,
4260 Target_mips
<size
, big_endian
>* target
)
4262 mips_reloc_unshuffle(view
, r_type
, false);
4263 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4264 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4266 Valtype32 addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
4271 value
= psymval
->value(object
, addend
);
4274 // For MIPS16 ABI code we generate this sequence
4275 // 0: li $v0,%hi(_gp_disp)
4276 // 4: addiupc $v1,%lo(_gp_disp)
4280 // So the offsets of hi and lo relocs are the same, but the
4281 // base $pc is that used by the ADDIUPC instruction at $t9 + 4.
4282 // ADDIUPC clears the low two bits of the instruction address,
4283 // so the base is ($t9 + 4) & ~3.
4285 if (r_type
== elfcpp::R_MIPS16_HI16
)
4286 gp_disp
= (target
->adjusted_gp_value(object
)
4287 - ((address
+ 4) & ~0x3));
4288 // The microMIPS .cpload sequence uses the same assembly
4289 // instructions as the traditional psABI version, but the
4290 // incoming $t9 has the low bit set.
4291 else if (r_type
== elfcpp::R_MICROMIPS_HI16
)
4292 gp_disp
= target
->adjusted_gp_value(object
) - address
- 1;
4294 gp_disp
= target
->adjusted_gp_value(object
) - address
;
4295 value
= gp_disp
+ addend
;
4297 Valtype32 x
= ((value
+ 0x8000) >> 16) & 0xffff;
4298 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4299 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4300 mips_reloc_shuffle(view
, r_type
, false);
4301 return (is_gp_disp
&& Bits
<16>::has_overflow32(x
)
4302 ? This::STATUS_OVERFLOW
4303 : This::STATUS_OKAY
);
4306 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4307 static inline typename
This::Status
4308 relgot16_local(unsigned char* view
,
4309 const Mips_relobj
<size
, big_endian
>* object
,
4310 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4311 bool extract_addend
, unsigned int r_type
, unsigned int r_sym
)
4313 // Record the relocation. It will be resolved when we find lo16 part.
4314 got16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
4315 addend_a
, r_type
, r_sym
, extract_addend
));
4316 return This::STATUS_OKAY
;
4319 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4320 static inline typename
This::Status
4321 do_relgot16_local(unsigned char* view
,
4322 const Mips_relobj
<size
, big_endian
>* object
,
4323 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
4324 unsigned int r_type
, bool extract_addend
,
4325 Valtype32 addend_lo
, Target_mips
<size
, big_endian
>* target
)
4327 mips_reloc_unshuffle(view
, r_type
, false);
4328 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4329 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4331 Valtype32 addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
4334 // Find GOT page entry.
4335 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000) >> 16)
4338 unsigned int got_offset
=
4339 target
->got_section()->get_got_page_offset(value
, object
);
4341 // Resolve the relocation.
4342 Valtype32 x
= target
->got_section()->gp_offset(got_offset
, object
);
4343 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4344 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4345 mips_reloc_shuffle(view
, r_type
, false);
4346 return (Bits
<16>::has_overflow32(x
)
4347 ? This::STATUS_OVERFLOW
4348 : This::STATUS_OKAY
);
4351 // R_MIPS_LO16, R_MIPS16_LO16, R_MICROMIPS_LO16, R_MICROMIPS_HI0_LO16
4352 static inline typename
This::Status
4353 rello16(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4354 const Mips_relobj
<size
, big_endian
>* object
,
4355 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4356 bool extract_addend
, Mips_address address
, bool is_gp_disp
,
4357 unsigned int r_type
, unsigned int r_sym
)
4359 mips_reloc_unshuffle(view
, r_type
, false);
4360 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4361 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4363 Valtype32 addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
4366 // Resolve pending R_MIPS_HI16 relocations.
4367 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it
=
4368 hi16_relocs
.begin();
4369 while (it
!= hi16_relocs
.end())
4371 reloc_high
<size
, big_endian
> hi16
= *it
;
4372 if (hi16
.r_sym
== r_sym
4373 && is_matching_lo16_reloc(hi16
.r_type
, r_type
))
4375 if (do_relhi16(hi16
.view
, hi16
.object
, hi16
.psymval
, hi16
.addend
,
4376 hi16
.address
, hi16
.gp_disp
, hi16
.r_type
,
4377 hi16
.extract_addend
, addend
, target
)
4378 == This::STATUS_OVERFLOW
)
4379 return This::STATUS_OVERFLOW
;
4380 it
= hi16_relocs
.erase(it
);
4386 // Resolve pending local R_MIPS_GOT16 relocations.
4387 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it2
=
4388 got16_relocs
.begin();
4389 while (it2
!= got16_relocs
.end())
4391 reloc_high
<size
, big_endian
> got16
= *it2
;
4392 if (got16
.r_sym
== r_sym
4393 && is_matching_lo16_reloc(got16
.r_type
, r_type
))
4395 if (do_relgot16_local(got16
.view
, got16
.object
, got16
.psymval
,
4396 got16
.addend
, got16
.r_type
,
4397 got16
.extract_addend
, addend
,
4398 target
) == This::STATUS_OVERFLOW
)
4399 return This::STATUS_OVERFLOW
;
4400 it2
= got16_relocs
.erase(it2
);
4406 // Resolve R_MIPS_LO16 relocation.
4409 x
= psymval
->value(object
, addend
);
4412 // See the comment for R_MIPS16_HI16 above for the reason
4413 // for this conditional.
4415 if (r_type
== elfcpp::R_MIPS16_LO16
)
4416 gp_disp
= target
->adjusted_gp_value(object
) - (address
& ~0x3);
4417 else if (r_type
== elfcpp::R_MICROMIPS_LO16
4418 || r_type
== elfcpp::R_MICROMIPS_HI0_LO16
)
4419 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 3;
4421 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 4;
4422 // The MIPS ABI requires checking the R_MIPS_LO16 relocation
4423 // for overflow. Relocations against _gp_disp are normally
4424 // generated from the .cpload pseudo-op. It generates code
4425 // that normally looks like this:
4427 // lui $gp,%hi(_gp_disp)
4428 // addiu $gp,$gp,%lo(_gp_disp)
4431 // Here $t9 holds the address of the function being called,
4432 // as required by the MIPS ELF ABI. The R_MIPS_LO16
4433 // relocation can easily overflow in this situation, but the
4434 // R_MIPS_HI16 relocation will handle the overflow.
4435 // Therefore, we consider this a bug in the MIPS ABI, and do
4436 // not check for overflow here.
4437 x
= gp_disp
+ addend
;
4439 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4440 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4441 mips_reloc_shuffle(view
, r_type
, false);
4442 return This::STATUS_OKAY
;
4445 // R_MIPS_CALL16, R_MIPS16_CALL16, R_MICROMIPS_CALL16
4446 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4447 // R_MIPS_TLS_GD, R_MIPS16_TLS_GD, R_MICROMIPS_TLS_GD
4448 // R_MIPS_TLS_GOTTPREL, R_MIPS16_TLS_GOTTPREL, R_MICROMIPS_TLS_GOTTPREL
4449 // R_MIPS_TLS_LDM, R_MIPS16_TLS_LDM, R_MICROMIPS_TLS_LDM
4450 // R_MIPS_GOT_DISP, R_MICROMIPS_GOT_DISP
4451 static inline typename
This::Status
4452 relgot(unsigned char* view
, int gp_offset
, unsigned int r_type
)
4454 mips_reloc_unshuffle(view
, r_type
, false);
4455 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4456 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4457 Valtype32 x
= gp_offset
;
4458 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4459 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4460 mips_reloc_shuffle(view
, r_type
, false);
4461 return (Bits
<16>::has_overflow32(x
)
4462 ? This::STATUS_OVERFLOW
4463 : This::STATUS_OKAY
);
4466 // R_MIPS_GOT_PAGE, R_MICROMIPS_GOT_PAGE
4467 static inline typename
This::Status
4468 relgotpage(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4469 const Mips_relobj
<size
, big_endian
>* object
,
4470 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4471 bool extract_addend
, unsigned int r_type
)
4473 mips_reloc_unshuffle(view
, r_type
, false);
4474 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4475 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4476 Valtype32 addend
= extract_addend
? val
& 0xffff : addend_a
;
4478 // Find a GOT page entry that points to within 32KB of symbol + addend.
4479 Mips_address value
= (psymval
->value(object
, addend
) + 0x8000) & ~0xffff;
4480 unsigned int got_offset
=
4481 target
->got_section()->get_got_page_offset(value
, object
);
4483 Valtype32 x
= target
->got_section()->gp_offset(got_offset
, object
);
4484 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4485 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4486 mips_reloc_shuffle(view
, r_type
, false);
4487 return (Bits
<16>::has_overflow32(x
)
4488 ? This::STATUS_OVERFLOW
4489 : This::STATUS_OKAY
);
4492 // R_MIPS_GOT_OFST, R_MICROMIPS_GOT_OFST
4493 static inline typename
This::Status
4494 relgotofst(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4495 const Mips_relobj
<size
, big_endian
>* object
,
4496 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4497 bool extract_addend
, bool local
, unsigned int r_type
)
4499 mips_reloc_unshuffle(view
, r_type
, false);
4500 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4501 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4502 Valtype32 addend
= extract_addend
? val
& 0xffff : addend_a
;
4504 // For a local symbol, find a GOT page entry that points to within 32KB of
4505 // symbol + addend. Relocation value is the offset of the GOT page entry's
4506 // value from symbol + addend.
4507 // For a global symbol, relocation value is addend.
4511 // Find GOT page entry.
4512 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000)
4514 target
->got_section()->get_got_page_offset(value
, object
);
4516 x
= psymval
->value(object
, addend
) - value
;
4520 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4521 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4522 mips_reloc_shuffle(view
, r_type
, false);
4523 return (Bits
<16>::has_overflow32(x
)
4524 ? This::STATUS_OVERFLOW
4525 : This::STATUS_OKAY
);
4528 // R_MIPS_GOT_HI16, R_MIPS_CALL_HI16,
4529 // R_MICROMIPS_GOT_HI16, R_MICROMIPS_CALL_HI16
4530 static inline typename
This::Status
4531 relgot_hi16(unsigned char* view
, int gp_offset
, unsigned int r_type
)
4533 mips_reloc_unshuffle(view
, r_type
, false);
4534 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4535 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4536 Valtype32 x
= gp_offset
;
4537 x
= ((x
+ 0x8000) >> 16) & 0xffff;
4538 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4539 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4540 mips_reloc_shuffle(view
, r_type
, false);
4541 return This::STATUS_OKAY
;
4544 // R_MIPS_GOT_LO16, R_MIPS_CALL_LO16,
4545 // R_MICROMIPS_GOT_LO16, R_MICROMIPS_CALL_LO16
4546 static inline typename
This::Status
4547 relgot_lo16(unsigned char* view
, int gp_offset
, unsigned int r_type
)
4549 mips_reloc_unshuffle(view
, r_type
, false);
4550 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4551 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4552 Valtype32 x
= gp_offset
;
4553 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4554 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4555 mips_reloc_shuffle(view
, r_type
, false);
4556 return This::STATUS_OKAY
;
4559 // R_MIPS_GPREL16, R_MIPS16_GPREL, R_MIPS_LITERAL, R_MICROMIPS_LITERAL
4560 // R_MICROMIPS_GPREL7_S2, R_MICROMIPS_GPREL16
4561 static inline typename
This::Status
4562 relgprel(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4563 const Symbol_value
<size
>* psymval
, Mips_address gp
,
4564 Mips_address addend_a
, bool extract_addend
, bool local
,
4565 unsigned int r_type
)
4567 mips_reloc_unshuffle(view
, r_type
, false);
4568 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4569 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4574 if (r_type
== elfcpp::R_MICROMIPS_GPREL7_S2
)
4575 addend
= (val
& 0x7f) << 2;
4577 addend
= val
& 0xffff;
4578 // Only sign-extend the addend if it was extracted from the
4579 // instruction. If the addend was separate, leave it alone,
4580 // otherwise we may lose significant bits.
4581 addend
= Bits
<16>::sign_extend32(addend
);
4586 Valtype32 x
= psymval
->value(object
, addend
) - gp
;
4588 // If the symbol was local, any earlier relocatable links will
4589 // have adjusted its addend with the gp offset, so compensate
4590 // for that now. Don't do it for symbols forced local in this
4591 // link, though, since they won't have had the gp offset applied
4594 x
+= object
->gp_value();
4596 if (r_type
== elfcpp::R_MICROMIPS_GPREL7_S2
)
4597 val
= Bits
<32>::bit_select32(val
, x
, 0x7f);
4599 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4600 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4601 mips_reloc_shuffle(view
, r_type
, false);
4602 if (Bits
<16>::has_overflow32(x
))
4604 gold_error(_("small-data section exceeds 64KB; lower small-data size "
4605 "limit (see option -G)"));
4606 return This::STATUS_OVERFLOW
;
4608 return This::STATUS_OKAY
;
4612 static inline typename
This::Status
4613 relgprel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4614 const Symbol_value
<size
>* psymval
, Mips_address gp
,
4615 Mips_address addend_a
, bool extract_addend
, unsigned int r_type
)
4617 mips_reloc_unshuffle(view
, r_type
, false);
4618 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4619 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4620 Valtype32 addend
= extract_addend
? val
: addend_a
;
4622 // R_MIPS_GPREL32 relocations are defined for local symbols only.
4623 Valtype32 x
= psymval
->value(object
, addend
) + object
->gp_value() - gp
;
4624 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4625 mips_reloc_shuffle(view
, r_type
, false);
4626 return This::STATUS_OKAY
;
4629 // R_MIPS_TLS_TPREL_HI16, R_MIPS16_TLS_TPREL_HI16, R_MICROMIPS_TLS_TPREL_HI16
4630 // R_MIPS_TLS_DTPREL_HI16, R_MIPS16_TLS_DTPREL_HI16,
4631 // R_MICROMIPS_TLS_DTPREL_HI16
4632 static inline typename
This::Status
4633 tlsrelhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4634 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
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
& 0xffff : addend_a
;
4642 // tls symbol values are relative to tls_segment()->vaddr()
4643 Valtype32 x
= ((psymval
->value(object
, addend
) - tp_offset
) + 0x8000) >> 16;
4644 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4645 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4646 mips_reloc_shuffle(view
, r_type
, false);
4647 return This::STATUS_OKAY
;
4650 // R_MIPS_TLS_TPREL_LO16, R_MIPS16_TLS_TPREL_LO16, R_MICROMIPS_TLS_TPREL_LO16,
4651 // R_MIPS_TLS_DTPREL_LO16, R_MIPS16_TLS_DTPREL_LO16,
4652 // R_MICROMIPS_TLS_DTPREL_LO16,
4653 static inline typename
This::Status
4654 tlsrello16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4655 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
4656 Mips_address addend_a
, bool extract_addend
, unsigned int r_type
)
4658 mips_reloc_unshuffle(view
, r_type
, false);
4659 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4660 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4661 Valtype32 addend
= extract_addend
? val
& 0xffff : addend_a
;
4663 // tls symbol values are relative to tls_segment()->vaddr()
4664 Valtype32 x
= psymval
->value(object
, addend
) - tp_offset
;
4665 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4666 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4667 mips_reloc_shuffle(view
, r_type
, false);
4668 return This::STATUS_OKAY
;
4671 // R_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL64,
4672 // R_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL64
4673 static inline typename
This::Status
4674 tlsrel32(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
: addend_a
;
4683 // tls symbol values are relative to tls_segment()->vaddr()
4684 Valtype32 x
= psymval
->value(object
, addend
) - tp_offset
;
4685 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4686 mips_reloc_shuffle(view
, r_type
, false);
4687 return This::STATUS_OKAY
;
4690 // R_MIPS_SUB, R_MICROMIPS_SUB
4691 static inline typename
This::Status
4692 relsub(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4693 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4694 bool extract_addend
, unsigned int r_type
)
4696 mips_reloc_unshuffle(view
, r_type
, false);
4697 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4698 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4699 Valtype32 addend
= extract_addend
? val
: addend_a
;
4701 Valtype32 x
= psymval
->value(object
, -addend
);
4702 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4703 mips_reloc_shuffle(view
, r_type
, false);
4704 return This::STATUS_OKAY
;
4708 template<int size
, bool big_endian
>
4709 typename
std::list
<reloc_high
<size
, big_endian
> >
4710 Mips_relocate_functions
<size
, big_endian
>::hi16_relocs
;
4712 template<int size
, bool big_endian
>
4713 typename
std::list
<reloc_high
<size
, big_endian
> >
4714 Mips_relocate_functions
<size
, big_endian
>::got16_relocs
;
4716 // Mips_got_info methods.
4718 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
4719 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
4721 template<int size
, bool big_endian
>
4723 Mips_got_info
<size
, big_endian
>::record_local_got_symbol(
4724 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
,
4725 Mips_address addend
, unsigned int r_type
, unsigned int shndx
)
4727 Mips_got_entry
<size
, big_endian
>* entry
=
4728 new Mips_got_entry
<size
, big_endian
>(object
, symndx
, addend
,
4729 mips_elf_reloc_tls_type(r_type
),
4731 this->record_got_entry(entry
, object
);
4734 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
4735 // in OBJECT. FOR_CALL is true if the caller is only interested in
4736 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
4739 template<int size
, bool big_endian
>
4741 Mips_got_info
<size
, big_endian
>::record_global_got_symbol(
4742 Mips_symbol
<size
>* mips_sym
, Mips_relobj
<size
, big_endian
>* object
,
4743 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
4746 mips_sym
->set_got_not_only_for_calls();
4748 // A global symbol in the GOT must also be in the dynamic symbol table.
4749 if (!mips_sym
->needs_dynsym_entry())
4751 switch (mips_sym
->visibility())
4753 case elfcpp::STV_INTERNAL
:
4754 case elfcpp::STV_HIDDEN
:
4755 mips_sym
->set_is_forced_local();
4758 mips_sym
->set_needs_dynsym_entry();
4763 unsigned char tls_type
= mips_elf_reloc_tls_type(r_type
);
4764 if (tls_type
== GOT_TLS_NONE
)
4765 this->global_got_symbols_
.insert(mips_sym
);
4769 if (mips_sym
->global_got_area() == GGA_NONE
)
4770 mips_sym
->set_global_got_area(GGA_RELOC_ONLY
);
4774 Mips_got_entry
<size
, big_endian
>* entry
=
4775 new Mips_got_entry
<size
, big_endian
>(object
, mips_sym
, tls_type
);
4777 this->record_got_entry(entry
, object
);
4780 // Add ENTRY to master GOT and to OBJECT's GOT.
4782 template<int size
, bool big_endian
>
4784 Mips_got_info
<size
, big_endian
>::record_got_entry(
4785 Mips_got_entry
<size
, big_endian
>* entry
,
4786 Mips_relobj
<size
, big_endian
>* object
)
4788 if (this->got_entries_
.find(entry
) == this->got_entries_
.end())
4789 this->got_entries_
.insert(entry
);
4791 // Create the GOT entry for the OBJECT's GOT.
4792 Mips_got_info
<size
, big_endian
>* g
= object
->get_or_create_got_info();
4793 Mips_got_entry
<size
, big_endian
>* entry2
=
4794 new Mips_got_entry
<size
, big_endian
>(*entry
);
4796 if (g
->got_entries_
.find(entry2
) == g
->got_entries_
.end())
4797 g
->got_entries_
.insert(entry2
);
4800 // Record that OBJECT has a page relocation against symbol SYMNDX and
4801 // that ADDEND is the addend for that relocation.
4802 // This function creates an upper bound on the number of GOT slots
4803 // required; no attempt is made to combine references to non-overridable
4804 // global symbols across multiple input files.
4806 template<int size
, bool big_endian
>
4808 Mips_got_info
<size
, big_endian
>::record_got_page_entry(
4809 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
, int addend
)
4811 struct Got_page_range
**range_ptr
, *range
;
4812 int old_pages
, new_pages
;
4814 // Find the Got_page_entry for this symbol.
4815 Got_page_entry
* entry
= new Got_page_entry(object
, symndx
);
4816 typename
Got_page_entry_set::iterator it
=
4817 this->got_page_entries_
.find(entry
);
4818 if (it
!= this->got_page_entries_
.end())
4821 this->got_page_entries_
.insert(entry
);
4823 // Add the same entry to the OBJECT's GOT.
4824 Got_page_entry
* entry2
= NULL
;
4825 Mips_got_info
<size
, big_endian
>* g2
= object
->get_or_create_got_info();
4826 if (g2
->got_page_entries_
.find(entry
) == g2
->got_page_entries_
.end())
4828 entry2
= new Got_page_entry(*entry
);
4829 g2
->got_page_entries_
.insert(entry2
);
4832 // Skip over ranges whose maximum extent cannot share a page entry
4834 range_ptr
= &entry
->ranges
;
4835 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
4836 range_ptr
= &(*range_ptr
)->next
;
4838 // If we scanned to the end of the list, or found a range whose
4839 // minimum extent cannot share a page entry with ADDEND, create
4840 // a new singleton range.
4842 if (!range
|| addend
< range
->min_addend
- 0xffff)
4844 range
= new Got_page_range();
4845 range
->next
= *range_ptr
;
4846 range
->min_addend
= addend
;
4847 range
->max_addend
= addend
;
4852 ++entry2
->num_pages
;
4853 ++this->page_gotno_
;
4858 // Remember how many pages the old range contributed.
4859 old_pages
= range
->get_max_pages();
4861 // Update the ranges.
4862 if (addend
< range
->min_addend
)
4863 range
->min_addend
= addend
;
4864 else if (addend
> range
->max_addend
)
4866 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
4868 old_pages
+= range
->next
->get_max_pages();
4869 range
->max_addend
= range
->next
->max_addend
;
4870 range
->next
= range
->next
->next
;
4873 range
->max_addend
= addend
;
4876 // Record any change in the total estimate.
4877 new_pages
= range
->get_max_pages();
4878 if (old_pages
!= new_pages
)
4880 entry
->num_pages
+= new_pages
- old_pages
;
4882 entry2
->num_pages
+= new_pages
- old_pages
;
4883 this->page_gotno_
+= new_pages
- old_pages
;
4884 g2
->page_gotno_
+= new_pages
- old_pages
;
4888 // Create all entries that should be in the local part of the GOT.
4890 template<int size
, bool big_endian
>
4892 Mips_got_info
<size
, big_endian
>::add_local_entries(
4893 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
4895 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
4896 // First two GOT entries are reserved. The first entry will be filled at
4897 // runtime. The second entry will be used by some runtime loaders.
4898 got
->add_constant(0);
4899 got
->add_constant(target
->mips_elf_gnu_got1_mask());
4901 for (typename
Got_entry_set::iterator
4902 p
= this->got_entries_
.begin();
4903 p
!= this->got_entries_
.end();
4906 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
4907 if (entry
->is_for_local_symbol() && !entry
->is_tls_entry())
4909 got
->add_local(entry
->object(), entry
->symndx(),
4911 unsigned int got_offset
= entry
->object()->local_got_offset(
4912 entry
->symndx(), GOT_TYPE_STANDARD
);
4913 if (got
->multi_got() && this->index_
> 0
4914 && parameters
->options().output_is_position_independent())
4915 target
->rel_dyn_section(layout
)->add_local(entry
->object(),
4916 entry
->symndx(), elfcpp::R_MIPS_REL32
, got
, got_offset
);
4920 this->add_page_entries(target
, layout
);
4922 // Add global entries that should be in the local area.
4923 for (typename
Got_entry_set::iterator
4924 p
= this->got_entries_
.begin();
4925 p
!= this->got_entries_
.end();
4928 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
4929 if (!entry
->is_for_global_symbol())
4932 Mips_symbol
<size
>* mips_sym
= entry
->sym();
4933 if (mips_sym
->global_got_area() == GGA_NONE
&& !entry
->is_tls_entry())
4935 unsigned int got_type
;
4936 if (!got
->multi_got())
4937 got_type
= GOT_TYPE_STANDARD
;
4939 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
4940 if (got
->add_global(mips_sym
, got_type
))
4942 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
4943 if (got
->multi_got() && this->index_
> 0
4944 && parameters
->options().output_is_position_independent())
4945 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
4946 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
4947 mips_sym
->got_offset(got_type
));
4953 // Create GOT page entries.
4955 template<int size
, bool big_endian
>
4957 Mips_got_info
<size
, big_endian
>::add_page_entries(
4958 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
4960 if (this->page_gotno_
== 0)
4963 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
4964 this->got_page_offset_start_
= got
->add_constant(0);
4965 if (got
->multi_got() && this->index_
> 0
4966 && parameters
->options().output_is_position_independent())
4967 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
4968 this->got_page_offset_start_
);
4969 int num_entries
= this->page_gotno_
;
4970 unsigned int prev_offset
= this->got_page_offset_start_
;
4971 while (--num_entries
> 0)
4973 unsigned int next_offset
= got
->add_constant(0);
4974 if (got
->multi_got() && this->index_
> 0
4975 && parameters
->options().output_is_position_independent())
4976 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
4978 gold_assert(next_offset
== prev_offset
+ size
/8);
4979 prev_offset
= next_offset
;
4981 this->got_page_offset_next_
= this->got_page_offset_start_
;
4984 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
4986 template<int size
, bool big_endian
>
4988 Mips_got_info
<size
, big_endian
>::add_global_entries(
4989 Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
4990 unsigned int non_reloc_only_global_gotno
)
4992 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
4993 // Add GGA_NORMAL entries.
4994 unsigned int count
= 0;
4995 for (typename
Got_entry_set::iterator
4996 p
= this->got_entries_
.begin();
4997 p
!= this->got_entries_
.end();
5000 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5001 if (!entry
->is_for_global_symbol())
5004 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5005 if (mips_sym
->global_got_area() != GGA_NORMAL
)
5008 unsigned int got_type
;
5009 if (!got
->multi_got())
5010 got_type
= GOT_TYPE_STANDARD
;
5012 // In multi-GOT links, global symbol can be in both primary and
5013 // secondary GOT(s). By creating custom GOT type
5014 // (GOT_TYPE_STANDARD_MULTIGOT + got_index) we ensure that symbol
5015 // is added to secondary GOT(s).
5016 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
5017 if (!got
->add_global(mips_sym
, got_type
))
5020 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5021 if (got
->multi_got() && this->index_
== 0)
5023 if (got
->multi_got() && this->index_
> 0)
5025 if (parameters
->options().output_is_position_independent()
5026 || (!parameters
->doing_static_link()
5027 && mips_sym
->is_from_dynobj() && !mips_sym
->is_undefined()))
5029 target
->rel_dyn_section(layout
)->add_global(
5030 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
5031 mips_sym
->got_offset(got_type
));
5032 got
->add_secondary_got_reloc(mips_sym
->got_offset(got_type
),
5033 elfcpp::R_MIPS_REL32
, mips_sym
);
5038 if (!got
->multi_got() || this->index_
== 0)
5040 if (got
->multi_got())
5042 // We need to allocate space in the primary GOT for GGA_NORMAL entries
5043 // of secondary GOTs, to ensure that GOT offsets of GGA_RELOC_ONLY
5044 // entries correspond to dynamic symbol indexes.
5045 while (count
< non_reloc_only_global_gotno
)
5047 got
->add_constant(0);
5052 // Add GGA_RELOC_ONLY entries.
5053 got
->add_reloc_only_entries();
5057 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
5059 template<int size
, bool big_endian
>
5061 Mips_got_info
<size
, big_endian
>::add_reloc_only_entries(
5062 Mips_output_data_got
<size
, big_endian
>* got
)
5064 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
5065 p
= this->global_got_symbols_
.begin();
5066 p
!= this->global_got_symbols_
.end();
5069 Mips_symbol
<size
>* mips_sym
= *p
;
5070 if (mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
5072 unsigned int got_type
;
5073 if (!got
->multi_got())
5074 got_type
= GOT_TYPE_STANDARD
;
5076 got_type
= GOT_TYPE_STANDARD_MULTIGOT
;
5077 if (got
->add_global(mips_sym
, got_type
))
5078 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5083 // Create TLS GOT entries.
5085 template<int size
, bool big_endian
>
5087 Mips_got_info
<size
, big_endian
>::add_tls_entries(
5088 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5090 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5091 // Add local tls entries.
5092 for (typename
Got_entry_set::iterator
5093 p
= this->got_entries_
.begin();
5094 p
!= this->got_entries_
.end();
5097 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5098 if (!entry
->is_tls_entry() || !entry
->is_for_local_symbol())
5101 if (entry
->tls_type() == GOT_TLS_GD
)
5103 unsigned int got_type
= GOT_TYPE_TLS_PAIR
;
5104 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5105 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5106 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
5107 : elfcpp::R_MIPS_TLS_DTPREL64
);
5109 if (!parameters
->doing_static_link())
5111 got
->add_local_pair_with_rel(entry
->object(), entry
->symndx(),
5112 entry
->shndx(), got_type
,
5113 target
->rel_dyn_section(layout
),
5115 unsigned int got_offset
=
5116 entry
->object()->local_got_offset(entry
->symndx(), got_type
);
5117 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
5118 entry
->object(), entry
->symndx());
5122 // We are doing a static link. Mark it as belong to module 1,
5124 unsigned int got_offset
= got
->add_constant(1);
5125 entry
->object()->set_local_got_offset(entry
->symndx(), got_type
,
5127 got
->add_constant(0);
5128 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
5129 entry
->object(), entry
->symndx());
5132 else if (entry
->tls_type() == GOT_TLS_IE
)
5134 unsigned int got_type
= GOT_TYPE_TLS_OFFSET
;
5135 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
5136 : elfcpp::R_MIPS_TLS_TPREL64
);
5137 if (!parameters
->doing_static_link())
5138 got
->add_local_with_rel(entry
->object(), entry
->symndx(), got_type
,
5139 target
->rel_dyn_section(layout
), r_type
);
5142 got
->add_local(entry
->object(), entry
->symndx(), got_type
);
5143 unsigned int got_offset
=
5144 entry
->object()->local_got_offset(entry
->symndx(), got_type
);
5145 got
->add_static_reloc(got_offset
, r_type
, entry
->object(),
5149 else if (entry
->tls_type() == GOT_TLS_LDM
)
5151 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5152 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5153 unsigned int got_offset
;
5154 if (!parameters
->doing_static_link())
5156 got_offset
= got
->add_constant(0);
5157 target
->rel_dyn_section(layout
)->add_local(
5158 entry
->object(), 0, r_type
, got
, got_offset
);
5161 // We are doing a static link. Just mark it as belong to module 1,
5163 got_offset
= got
->add_constant(1);
5165 got
->add_constant(0);
5166 got
->set_tls_ldm_offset(got_offset
, entry
->object());
5172 // Add global tls entries.
5173 for (typename
Got_entry_set::iterator
5174 p
= this->got_entries_
.begin();
5175 p
!= this->got_entries_
.end();
5178 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5179 if (!entry
->is_tls_entry() || !entry
->is_for_global_symbol())
5182 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5183 if (entry
->tls_type() == GOT_TLS_GD
)
5185 unsigned int got_type
;
5186 if (!got
->multi_got())
5187 got_type
= GOT_TYPE_TLS_PAIR
;
5189 got_type
= GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
5190 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5191 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5192 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
5193 : elfcpp::R_MIPS_TLS_DTPREL64
);
5194 if (!parameters
->doing_static_link())
5195 got
->add_global_pair_with_rel(mips_sym
, got_type
,
5196 target
->rel_dyn_section(layout
), r_type1
, r_type2
);
5199 // Add a GOT pair for for R_MIPS_TLS_GD. The creates a pair of
5200 // GOT entries. The first one is initialized to be 1, which is the
5201 // module index for the main executable and the second one 0. A
5202 // reloc of the type R_MIPS_TLS_DTPREL32/64 will be created for
5203 // the second GOT entry and will be applied by gold.
5204 unsigned int got_offset
= got
->add_constant(1);
5205 mips_sym
->set_got_offset(got_type
, got_offset
);
5206 got
->add_constant(0);
5207 got
->add_static_reloc(got_offset
+ size
/8, r_type2
, mips_sym
);
5210 else if (entry
->tls_type() == GOT_TLS_IE
)
5212 unsigned int got_type
;
5213 if (!got
->multi_got())
5214 got_type
= GOT_TYPE_TLS_OFFSET
;
5216 got_type
= GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
5217 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
5218 : elfcpp::R_MIPS_TLS_TPREL64
);
5219 if (!parameters
->doing_static_link())
5220 got
->add_global_with_rel(mips_sym
, got_type
,
5221 target
->rel_dyn_section(layout
), r_type
);
5224 got
->add_global(mips_sym
, got_type
);
5225 unsigned int got_offset
= mips_sym
->got_offset(got_type
);
5226 got
->add_static_reloc(got_offset
, r_type
, mips_sym
);
5234 // Decide whether the symbol needs an entry in the global part of the primary
5235 // GOT, setting global_got_area accordingly. Count the number of global
5236 // symbols that are in the primary GOT only because they have dynamic
5237 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
5239 template<int size
, bool big_endian
>
5241 Mips_got_info
<size
, big_endian
>::count_got_symbols(Symbol_table
* symtab
)
5243 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
5244 p
= this->global_got_symbols_
.begin();
5245 p
!= this->global_got_symbols_
.end();
5248 Mips_symbol
<size
>* sym
= *p
;
5249 // Make a final decision about whether the symbol belongs in the
5250 // local or global GOT. Symbols that bind locally can (and in the
5251 // case of forced-local symbols, must) live in the local GOT.
5252 // Those that are aren't in the dynamic symbol table must also
5253 // live in the local GOT.
5255 if (!sym
->should_add_dynsym_entry(symtab
)
5256 || (sym
->got_only_for_calls()
5257 ? symbol_calls_local(sym
, sym
->should_add_dynsym_entry(symtab
))
5258 : symbol_references_local(sym
,
5259 sym
->should_add_dynsym_entry(symtab
))))
5260 // The symbol belongs in the local GOT. We no longer need this
5261 // entry if it was only used for relocations; those relocations
5262 // will be against the null or section symbol instead.
5263 sym
->set_global_got_area(GGA_NONE
);
5264 else if (sym
->global_got_area() == GGA_RELOC_ONLY
)
5266 ++this->reloc_only_gotno_
;
5267 ++this->global_gotno_
;
5272 // Return the offset of GOT page entry for VALUE. Initialize the entry with
5273 // VALUE if it is not initialized.
5275 template<int size
, bool big_endian
>
5277 Mips_got_info
<size
, big_endian
>::get_got_page_offset(Mips_address value
,
5278 Mips_output_data_got
<size
, big_endian
>* got
)
5280 typename
Got_page_offsets::iterator it
= this->got_page_offsets_
.find(value
);
5281 if (it
!= this->got_page_offsets_
.end())
5284 gold_assert(this->got_page_offset_next_
< this->got_page_offset_start_
5285 + (size
/8) * this->page_gotno_
);
5287 unsigned int got_offset
= this->got_page_offset_next_
;
5288 this->got_page_offsets_
[value
] = got_offset
;
5289 this->got_page_offset_next_
+= size
/8;
5290 got
->update_got_entry(got_offset
, value
);
5294 // Remove lazy-binding stubs for global symbols in this GOT.
5296 template<int size
, bool big_endian
>
5298 Mips_got_info
<size
, big_endian
>::remove_lazy_stubs(
5299 Target_mips
<size
, big_endian
>* target
)
5301 for (typename
Got_entry_set::iterator
5302 p
= this->got_entries_
.begin();
5303 p
!= this->got_entries_
.end();
5306 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5307 if (entry
->is_for_global_symbol())
5308 target
->remove_lazy_stub_entry(entry
->sym());
5312 // Count the number of GOT entries required.
5314 template<int size
, bool big_endian
>
5316 Mips_got_info
<size
, big_endian
>::count_got_entries()
5318 for (typename
Got_entry_set::iterator
5319 p
= this->got_entries_
.begin();
5320 p
!= this->got_entries_
.end();
5323 this->count_got_entry(*p
);
5327 // Count the number of GOT entries required by ENTRY. Accumulate the result.
5329 template<int size
, bool big_endian
>
5331 Mips_got_info
<size
, big_endian
>::count_got_entry(
5332 Mips_got_entry
<size
, big_endian
>* entry
)
5334 if (entry
->is_tls_entry())
5335 this->tls_gotno_
+= mips_tls_got_entries(entry
->tls_type());
5336 else if (entry
->is_for_local_symbol()
5337 || entry
->sym()->global_got_area() == GGA_NONE
)
5338 ++this->local_gotno_
;
5340 ++this->global_gotno_
;
5343 // Add FROM's GOT entries.
5345 template<int size
, bool big_endian
>
5347 Mips_got_info
<size
, big_endian
>::add_got_entries(
5348 Mips_got_info
<size
, big_endian
>* from
)
5350 for (typename
Got_entry_set::iterator
5351 p
= from
->got_entries_
.begin();
5352 p
!= from
->got_entries_
.end();
5355 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5356 if (this->got_entries_
.find(entry
) == this->got_entries_
.end())
5358 Mips_got_entry
<size
, big_endian
>* entry2
=
5359 new Mips_got_entry
<size
, big_endian
>(*entry
);
5360 this->got_entries_
.insert(entry2
);
5361 this->count_got_entry(entry
);
5366 // Add FROM's GOT page entries.
5368 template<int size
, bool big_endian
>
5370 Mips_got_info
<size
, big_endian
>::add_got_page_entries(
5371 Mips_got_info
<size
, big_endian
>* from
)
5373 for (typename
Got_page_entry_set::iterator
5374 p
= from
->got_page_entries_
.begin();
5375 p
!= from
->got_page_entries_
.end();
5378 Got_page_entry
* entry
= *p
;
5379 if (this->got_page_entries_
.find(entry
) == this->got_page_entries_
.end())
5381 Got_page_entry
* entry2
= new Got_page_entry(*entry
);
5382 this->got_page_entries_
.insert(entry2
);
5383 this->page_gotno_
+= entry
->num_pages
;
5388 // Mips_output_data_got methods.
5390 // Lay out the GOT. Add local, global and TLS entries. If GOT is
5391 // larger than 64K, create multi-GOT.
5393 template<int size
, bool big_endian
>
5395 Mips_output_data_got
<size
, big_endian
>::lay_out_got(Layout
* layout
,
5396 Symbol_table
* symtab
, const Input_objects
* input_objects
)
5398 // Decide which symbols need to go in the global part of the GOT and
5399 // count the number of reloc-only GOT symbols.
5400 this->master_got_info_
->count_got_symbols(symtab
);
5402 // Count the number of GOT entries.
5403 this->master_got_info_
->count_got_entries();
5405 unsigned int got_size
= this->master_got_info_
->got_size();
5406 if (got_size
> Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
)
5407 this->lay_out_multi_got(layout
, input_objects
);
5410 // Record that all objects use single GOT.
5411 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
5412 p
!= input_objects
->relobj_end();
5415 Mips_relobj
<size
, big_endian
>* object
=
5416 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
5417 if (object
->get_got_info() != NULL
)
5418 object
->set_got_info(this->master_got_info_
);
5421 this->master_got_info_
->add_local_entries(this->target_
, layout
);
5422 this->master_got_info_
->add_global_entries(this->target_
, layout
,
5424 this->master_got_info_
->add_tls_entries(this->target_
, layout
);
5428 // Create multi-GOT. For every GOT, add local, global and TLS entries.
5430 template<int size
, bool big_endian
>
5432 Mips_output_data_got
<size
, big_endian
>::lay_out_multi_got(Layout
* layout
,
5433 const Input_objects
* input_objects
)
5435 // Try to merge the GOTs of input objects together, as long as they
5436 // don't seem to exceed the maximum GOT size, choosing one of them
5437 // to be the primary GOT.
5438 this->merge_gots(input_objects
);
5440 // Every symbol that is referenced in a dynamic relocation must be
5441 // present in the primary GOT.
5442 this->primary_got_
->set_global_gotno(this->master_got_info_
->global_gotno());
5446 unsigned int offset
= 0;
5447 Mips_got_info
<size
, big_endian
>* g
= this->primary_got_
;
5451 g
->set_offset(offset
);
5453 g
->add_local_entries(this->target_
, layout
);
5455 g
->add_global_entries(this->target_
, layout
,
5456 (this->master_got_info_
->global_gotno()
5457 - this->master_got_info_
->reloc_only_gotno()));
5459 g
->add_global_entries(this->target_
, layout
, /*not used*/-1U);
5460 g
->add_tls_entries(this->target_
, layout
);
5462 // Forbid global symbols in every non-primary GOT from having
5463 // lazy-binding stubs.
5465 g
->remove_lazy_stubs(this->target_
);
5468 offset
+= g
->got_size();
5474 // Attempt to merge GOTs of different input objects. Try to use as much as
5475 // possible of the primary GOT, since it doesn't require explicit dynamic
5476 // relocations, but don't use objects that would reference global symbols
5477 // out of the addressable range. Failing the primary GOT, attempt to merge
5478 // with the current GOT, or finish the current GOT and then make make the new
5481 template<int size
, bool big_endian
>
5483 Mips_output_data_got
<size
, big_endian
>::merge_gots(
5484 const Input_objects
* input_objects
)
5486 gold_assert(this->primary_got_
== NULL
);
5487 Mips_got_info
<size
, big_endian
>* current
= NULL
;
5489 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
5490 p
!= input_objects
->relobj_end();
5493 Mips_relobj
<size
, big_endian
>* object
=
5494 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
5496 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
5500 g
->count_got_entries();
5502 // Work out the number of page, local and TLS entries.
5503 unsigned int estimate
= this->master_got_info_
->page_gotno();
5504 if (estimate
> g
->page_gotno())
5505 estimate
= g
->page_gotno();
5506 estimate
+= g
->local_gotno() + g
->tls_gotno();
5508 // We place TLS GOT entries after both locals and globals. The globals
5509 // for the primary GOT may overflow the normal GOT size limit, so be
5510 // sure not to merge a GOT which requires TLS with the primary GOT in that
5511 // case. This doesn't affect non-primary GOTs.
5512 estimate
+= (g
->tls_gotno() > 0 ? this->master_got_info_
->global_gotno()
5513 : g
->global_gotno());
5515 unsigned int max_count
=
5516 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
5517 if (estimate
<= max_count
)
5519 // If we don't have a primary GOT, use it as
5520 // a starting point for the primary GOT.
5521 if (!this->primary_got_
)
5523 this->primary_got_
= g
;
5527 // Try merging with the primary GOT.
5528 if (this->merge_got_with(g
, object
, this->primary_got_
))
5532 // If we can merge with the last-created GOT, do it.
5533 if (current
&& this->merge_got_with(g
, object
, current
))
5536 // Well, we couldn't merge, so create a new GOT. Don't check if it
5537 // fits; if it turns out that it doesn't, we'll get relocation
5538 // overflows anyway.
5539 g
->set_next(current
);
5543 // If we do not find any suitable primary GOT, create an empty one.
5544 if (this->primary_got_
== NULL
)
5545 this->primary_got_
= new Mips_got_info
<size
, big_endian
>();
5547 // Link primary GOT with secondary GOTs.
5548 this->primary_got_
->set_next(current
);
5551 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
5552 // this would lead to overflow, true if they were merged successfully.
5554 template<int size
, bool big_endian
>
5556 Mips_output_data_got
<size
, big_endian
>::merge_got_with(
5557 Mips_got_info
<size
, big_endian
>* from
,
5558 Mips_relobj
<size
, big_endian
>* object
,
5559 Mips_got_info
<size
, big_endian
>* to
)
5561 // Work out how many page entries we would need for the combined GOT.
5562 unsigned int estimate
= this->master_got_info_
->page_gotno();
5563 if (estimate
>= from
->page_gotno() + to
->page_gotno())
5564 estimate
= from
->page_gotno() + to
->page_gotno();
5566 // Conservatively estimate how many local and TLS entries would be needed.
5567 estimate
+= from
->local_gotno() + to
->local_gotno();
5568 estimate
+= from
->tls_gotno() + to
->tls_gotno();
5570 // If we're merging with the primary got, any TLS relocations will
5571 // come after the full set of global entries. Otherwise estimate those
5572 // conservatively as well.
5573 if (to
== this->primary_got_
&& (from
->tls_gotno() + to
->tls_gotno()) > 0)
5574 estimate
+= this->master_got_info_
->global_gotno();
5576 estimate
+= from
->global_gotno() + to
->global_gotno();
5578 // Bail out if the combined GOT might be too big.
5579 unsigned int max_count
=
5580 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
5581 if (estimate
> max_count
)
5584 // Transfer the object's GOT information from FROM to TO.
5585 to
->add_got_entries(from
);
5586 to
->add_got_page_entries(from
);
5588 // Record that OBJECT should use output GOT TO.
5589 object
->set_got_info(to
);
5594 // Write out the GOT.
5596 template<int size
, bool big_endian
>
5598 Mips_output_data_got
<size
, big_endian
>::do_write(Output_file
* of
)
5600 // Call parent to write out GOT.
5601 Output_data_got
<size
, big_endian
>::do_write(of
);
5603 const off_t offset
= this->offset();
5604 const section_size_type oview_size
=
5605 convert_to_section_size_type(this->data_size());
5606 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
5608 // Needed for fixing values of .got section.
5609 this->got_view_
= oview
;
5611 // Write lazy stub addresses.
5612 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
5613 p
= this->master_got_info_
->global_got_symbols().begin();
5614 p
!= this->master_got_info_
->global_got_symbols().end();
5617 Mips_symbol
<size
>* mips_sym
= *p
;
5618 if (mips_sym
->has_lazy_stub())
5620 Valtype
* wv
= reinterpret_cast<Valtype
*>(
5621 oview
+ this->get_primary_got_offset(mips_sym
));
5623 this->target_
->mips_stubs_section()->stub_address(mips_sym
);
5624 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
5628 // Add +1 to GGA_NONE nonzero MIPS16 and microMIPS entries.
5629 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
5630 p
= this->master_got_info_
->global_got_symbols().begin();
5631 p
!= this->master_got_info_
->global_got_symbols().end();
5634 Mips_symbol
<size
>* mips_sym
= *p
;
5635 if (!this->multi_got()
5636 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
5637 && mips_sym
->global_got_area() == GGA_NONE
5638 && mips_sym
->has_got_offset(GOT_TYPE_STANDARD
))
5640 Valtype
* wv
= reinterpret_cast<Valtype
*>(
5641 oview
+ mips_sym
->got_offset(GOT_TYPE_STANDARD
));
5642 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv
);
5646 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
5651 if (!this->secondary_got_relocs_
.empty())
5653 // Fixup for the secondary GOT R_MIPS_REL32 relocs. For global
5654 // secondary GOT entries with non-zero initial value copy the value
5655 // to the corresponding primary GOT entry, and set the secondary GOT
5657 // TODO(sasa): This is workaround. It needs to be investigated further.
5659 for (size_t i
= 0; i
< this->secondary_got_relocs_
.size(); ++i
)
5661 Static_reloc
& reloc(this->secondary_got_relocs_
[i
]);
5662 if (reloc
.symbol_is_global())
5664 Mips_symbol
<size
>* gsym
= reloc
.symbol();
5665 gold_assert(gsym
!= NULL
);
5667 unsigned got_offset
= reloc
.got_offset();
5668 gold_assert(got_offset
< oview_size
);
5670 // Find primary GOT entry.
5671 Valtype
* wv_prim
= reinterpret_cast<Valtype
*>(
5672 oview
+ this->get_primary_got_offset(gsym
));
5674 // Find secondary GOT entry.
5675 Valtype
* wv_sec
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
5677 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv_sec
);
5680 elfcpp::Swap
<size
, big_endian
>::writeval(wv_prim
, value
);
5681 elfcpp::Swap
<size
, big_endian
>::writeval(wv_sec
, 0);
5682 gsym
->set_applied_secondary_got_fixup();
5687 of
->write_output_view(offset
, oview_size
, oview
);
5690 // We are done if there is no fix up.
5691 if (this->static_relocs_
.empty())
5694 Output_segment
* tls_segment
= this->layout_
->tls_segment();
5695 gold_assert(tls_segment
!= NULL
);
5697 for (size_t i
= 0; i
< this->static_relocs_
.size(); ++i
)
5699 Static_reloc
& reloc(this->static_relocs_
[i
]);
5702 if (!reloc
.symbol_is_global())
5704 Sized_relobj_file
<size
, big_endian
>* object
= reloc
.relobj();
5705 const Symbol_value
<size
>* psymval
=
5706 object
->local_symbol(reloc
.index());
5708 // We are doing static linking. Issue an error and skip this
5709 // relocation if the symbol is undefined or in a discarded_section.
5711 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
5712 if ((shndx
== elfcpp::SHN_UNDEF
)
5714 && shndx
!= elfcpp::SHN_UNDEF
5715 && !object
->is_section_included(shndx
)
5716 && !this->symbol_table_
->is_section_folded(object
, shndx
)))
5718 gold_error(_("undefined or discarded local symbol %u from "
5719 " object %s in GOT"),
5720 reloc
.index(), reloc
.relobj()->name().c_str());
5724 value
= psymval
->value(object
, 0);
5728 const Mips_symbol
<size
>* gsym
= reloc
.symbol();
5729 gold_assert(gsym
!= NULL
);
5731 // We are doing static linking. Issue an error and skip this
5732 // relocation if the symbol is undefined or in a discarded_section
5733 // unless it is a weakly_undefined symbol.
5734 if ((gsym
->is_defined_in_discarded_section() || gsym
->is_undefined())
5735 && !gsym
->is_weak_undefined())
5737 gold_error(_("undefined or discarded symbol %s in GOT"),
5742 if (!gsym
->is_weak_undefined())
5743 value
= gsym
->value();
5748 unsigned got_offset
= reloc
.got_offset();
5749 gold_assert(got_offset
< oview_size
);
5751 Valtype
* wv
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
5754 switch (reloc
.r_type())
5756 case elfcpp::R_MIPS_TLS_DTPMOD32
:
5757 case elfcpp::R_MIPS_TLS_DTPMOD64
:
5760 case elfcpp::R_MIPS_TLS_DTPREL32
:
5761 case elfcpp::R_MIPS_TLS_DTPREL64
:
5762 x
= value
- elfcpp::DTP_OFFSET
;
5764 case elfcpp::R_MIPS_TLS_TPREL32
:
5765 case elfcpp::R_MIPS_TLS_TPREL64
:
5766 x
= value
- elfcpp::TP_OFFSET
;
5773 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, x
);
5776 of
->write_output_view(offset
, oview_size
, oview
);
5779 // Mips_relobj methods.
5781 // Count the local symbols. The Mips backend needs to know if a symbol
5782 // is a MIPS16 or microMIPS function or not. For global symbols, it is easy
5783 // because the Symbol object keeps the ELF symbol type and st_other field.
5784 // For local symbol it is harder because we cannot access this information.
5785 // So we override the do_count_local_symbol in parent and scan local symbols to
5786 // mark MIPS16 and microMIPS functions. This is not the most efficient way but
5787 // I do not want to slow down other ports by calling a per symbol target hook
5788 // inside Sized_relobj_file<size, big_endian>::do_count_local_symbols.
5790 template<int size
, bool big_endian
>
5792 Mips_relobj
<size
, big_endian
>::do_count_local_symbols(
5793 Stringpool_template
<char>* pool
,
5794 Stringpool_template
<char>* dynpool
)
5796 // Ask parent to count the local symbols.
5797 Sized_relobj_file
<size
, big_endian
>::do_count_local_symbols(pool
, dynpool
);
5798 const unsigned int loccount
= this->local_symbol_count();
5802 // Initialize the mips16 and micromips function bit-vector.
5803 this->local_symbol_is_mips16_
.resize(loccount
, false);
5804 this->local_symbol_is_micromips_
.resize(loccount
, false);
5806 // Read the symbol table section header.
5807 const unsigned int symtab_shndx
= this->symtab_shndx();
5808 elfcpp::Shdr
<size
, big_endian
>
5809 symtabshdr(this, this->elf_file()->section_header(symtab_shndx
));
5810 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
5812 // Read the local symbols.
5813 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
5814 gold_assert(loccount
== symtabshdr
.get_sh_info());
5815 off_t locsize
= loccount
* sym_size
;
5816 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
5817 locsize
, true, true);
5819 // Loop over the local symbols and mark any MIPS16 or microMIPS local symbols.
5821 // Skip the first dummy symbol.
5823 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
5825 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
5826 unsigned char st_other
= sym
.get_st_other();
5827 this->local_symbol_is_mips16_
[i
] = elfcpp::elf_st_is_mips16(st_other
);
5828 this->local_symbol_is_micromips_
[i
] =
5829 elfcpp::elf_st_is_micromips(st_other
);
5833 // Read the symbol information.
5835 template<int size
, bool big_endian
>
5837 Mips_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
5839 // Call parent class to read symbol information.
5840 this->base_read_symbols(sd
);
5842 // Read processor-specific flags in ELF file header.
5843 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
5844 elfcpp::Elf_sizes
<size
>::ehdr_size
,
5846 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
5847 this->processor_specific_flags_
= ehdr
.get_e_flags();
5849 // Get the section names.
5850 const unsigned char* pnamesu
= sd
->section_names
->data();
5851 const char* pnames
= reinterpret_cast<const char*>(pnamesu
);
5853 // Initialize the mips16 stub section bit-vectors.
5854 this->section_is_mips16_fn_stub_
.resize(this->shnum(), false);
5855 this->section_is_mips16_call_stub_
.resize(this->shnum(), false);
5856 this->section_is_mips16_call_fp_stub_
.resize(this->shnum(), false);
5858 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
5859 const unsigned char* pshdrs
= sd
->section_headers
->data();
5860 const unsigned char* ps
= pshdrs
+ shdr_size
;
5861 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
5863 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
5865 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_REGINFO
)
5867 // Read the gp value that was used to create this object. We need the
5868 // gp value while processing relocs. The .reginfo section is not used
5869 // in the 64-bit MIPS ELF ABI.
5870 section_offset_type section_offset
= shdr
.get_sh_offset();
5871 section_size_type section_size
=
5872 convert_to_section_size_type(shdr
.get_sh_size());
5873 const unsigned char* view
=
5874 this->get_view(section_offset
, section_size
, true, false);
5876 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 20);
5878 // Read the rest of .reginfo.
5879 this->gprmask_
= elfcpp::Swap
<size
, big_endian
>::readval(view
);
5880 this->cprmask1_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 4);
5881 this->cprmask2_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 8);
5882 this->cprmask3_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 12);
5883 this->cprmask4_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 16);
5886 const char* name
= pnames
+ shdr
.get_sh_name();
5887 this->section_is_mips16_fn_stub_
[i
] = is_prefix_of(".mips16.fn", name
);
5888 this->section_is_mips16_call_stub_
[i
] =
5889 is_prefix_of(".mips16.call.", name
);
5890 this->section_is_mips16_call_fp_stub_
[i
] =
5891 is_prefix_of(".mips16.call.fp.", name
);
5893 if (strcmp(name
, ".pdr") == 0)
5895 gold_assert(this->pdr_shndx_
== -1U);
5896 this->pdr_shndx_
= i
;
5901 // Discard MIPS16 stub secions that are not needed.
5903 template<int size
, bool big_endian
>
5905 Mips_relobj
<size
, big_endian
>::discard_mips16_stub_sections(Symbol_table
* symtab
)
5907 for (typename
Mips16_stubs_int_map::const_iterator
5908 it
= this->mips16_stub_sections_
.begin();
5909 it
!= this->mips16_stub_sections_
.end(); ++it
)
5911 Mips16_stub_section
<size
, big_endian
>* stub_section
= it
->second
;
5912 if (!stub_section
->is_target_found())
5914 gold_error(_("no relocation found in mips16 stub section '%s'"),
5915 stub_section
->object()
5916 ->section_name(stub_section
->shndx()).c_str());
5919 bool discard
= false;
5920 if (stub_section
->is_for_local_function())
5922 if (stub_section
->is_fn_stub())
5924 // This stub is for a local symbol. This stub will only
5925 // be needed if there is some relocation in this object,
5926 // other than a 16 bit function call, which refers to this
5928 if (!this->has_local_non_16bit_call_relocs(stub_section
->r_sym()))
5931 this->add_local_mips16_fn_stub(stub_section
);
5935 // This stub is for a local symbol. This stub will only
5936 // be needed if there is some relocation (R_MIPS16_26) in
5937 // this object that refers to this symbol.
5938 gold_assert(stub_section
->is_call_stub()
5939 || stub_section
->is_call_fp_stub());
5940 if (!this->has_local_16bit_call_relocs(stub_section
->r_sym()))
5943 this->add_local_mips16_call_stub(stub_section
);
5948 Mips_symbol
<size
>* gsym
= stub_section
->gsym();
5949 if (stub_section
->is_fn_stub())
5951 if (gsym
->has_mips16_fn_stub())
5952 // We already have a stub for this function.
5956 gsym
->set_mips16_fn_stub(stub_section
);
5957 if (gsym
->should_add_dynsym_entry(symtab
))
5959 // If we have a MIPS16 function with a stub, the
5960 // dynamic symbol must refer to the stub, since only
5961 // the stub uses the standard calling conventions.
5962 gsym
->set_need_fn_stub();
5963 if (gsym
->is_from_dynobj())
5964 gsym
->set_needs_dynsym_value();
5967 if (!gsym
->need_fn_stub())
5970 else if (stub_section
->is_call_stub())
5972 if (gsym
->is_mips16())
5973 // We don't need the call_stub; this is a 16 bit
5974 // function, so calls from other 16 bit functions are
5977 else if (gsym
->has_mips16_call_stub())
5978 // We already have a stub for this function.
5981 gsym
->set_mips16_call_stub(stub_section
);
5985 gold_assert(stub_section
->is_call_fp_stub());
5986 if (gsym
->is_mips16())
5987 // We don't need the call_stub; this is a 16 bit
5988 // function, so calls from other 16 bit functions are
5991 else if (gsym
->has_mips16_call_fp_stub())
5992 // We already have a stub for this function.
5995 gsym
->set_mips16_call_fp_stub(stub_section
);
5999 this->set_output_section(stub_section
->shndx(), NULL
);
6003 // Mips_output_data_la25_stub methods.
6005 // Template for standard LA25 stub.
6006 template<int size
, bool big_endian
>
6008 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_entry
[] =
6010 0x3c190000, // lui $25,%hi(func)
6011 0x08000000, // j func
6012 0x27390000, // add $25,$25,%lo(func)
6016 // Template for microMIPS LA25 stub.
6017 template<int size
, bool big_endian
>
6019 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_micromips_entry
[] =
6021 0x41b9, 0x0000, // lui t9,%hi(func)
6022 0xd400, 0x0000, // j func
6023 0x3339, 0x0000, // addiu t9,t9,%lo(func)
6024 0x0000, 0x0000 // nop
6027 // Create la25 stub for a symbol.
6029 template<int size
, bool big_endian
>
6031 Mips_output_data_la25_stub
<size
, big_endian
>::create_la25_stub(
6032 Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
6033 Mips_symbol
<size
>* gsym
)
6035 if (!gsym
->has_la25_stub())
6037 gsym
->set_la25_stub_offset(this->symbols_
.size() * 16);
6038 this->symbols_
.insert(gsym
);
6039 this->create_stub_symbol(gsym
, symtab
, target
, 16);
6043 // Create a symbol for SYM stub's value and size, to help make the disassembly
6046 template<int size
, bool big_endian
>
6048 Mips_output_data_la25_stub
<size
, big_endian
>::create_stub_symbol(
6049 Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
6050 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
)
6052 std::string
name(".pic.");
6053 name
+= sym
->name();
6055 unsigned int offset
= sym
->la25_stub_offset();
6056 if (sym
->is_micromips())
6059 // Make it a local function.
6060 Symbol
* new_sym
= symtab
->define_in_output_data(name
.c_str(), NULL
,
6061 Symbol_table::PREDEFINED
,
6062 target
->la25_stub_section(),
6063 offset
, symsize
, elfcpp::STT_FUNC
,
6065 elfcpp::STV_DEFAULT
, 0,
6067 new_sym
->set_is_forced_local();
6070 // Write out la25 stubs. This uses the hand-coded instructions above,
6071 // and adjusts them as needed.
6073 template<int size
, bool big_endian
>
6075 Mips_output_data_la25_stub
<size
, big_endian
>::do_write(Output_file
* of
)
6077 const off_t offset
= this->offset();
6078 const section_size_type oview_size
=
6079 convert_to_section_size_type(this->data_size());
6080 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6082 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
6083 p
= this->symbols_
.begin();
6084 p
!= this->symbols_
.end();
6087 Mips_symbol
<size
>* sym
= *p
;
6088 unsigned char* pov
= oview
+ sym
->la25_stub_offset();
6090 Mips_address target
= sym
->value();
6091 if (!sym
->is_micromips())
6093 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
6094 la25_stub_entry
[0] | (((target
+ 0x8000) >> 16) & 0xffff));
6095 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
6096 la25_stub_entry
[1] | ((target
>> 2) & 0x3ffffff));
6097 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
6098 la25_stub_entry
[2] | (target
& 0xffff));
6099 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12, la25_stub_entry
[3]);
6104 // First stub instruction. Paste high 16-bits of the target.
6105 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
6106 la25_stub_micromips_entry
[0]);
6107 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
6108 ((target
+ 0x8000) >> 16) & 0xffff);
6109 // Second stub instruction. Paste low 26-bits of the target, shifted
6111 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
6112 la25_stub_micromips_entry
[2] | ((target
>> 17) & 0x3ff));
6113 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
6114 la25_stub_micromips_entry
[3] | ((target
>> 1) & 0xffff));
6115 // Third stub instruction. Paste low 16-bits of the target.
6116 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8,
6117 la25_stub_micromips_entry
[4]);
6118 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, target
& 0xffff);
6119 // Fourth stub instruction.
6120 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 12,
6121 la25_stub_micromips_entry
[6]);
6122 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 14,
6123 la25_stub_micromips_entry
[7]);
6127 of
->write_output_view(offset
, oview_size
, oview
);
6130 // Mips_output_data_plt methods.
6132 // The format of the first PLT entry in an O32 executable.
6133 template<int size
, bool big_endian
>
6134 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_o32
[] =
6136 0x3c1c0000, // lui $28, %hi(&GOTPLT[0])
6137 0x8f990000, // lw $25, %lo(&GOTPLT[0])($28)
6138 0x279c0000, // addiu $28, $28, %lo(&GOTPLT[0])
6139 0x031cc023, // subu $24, $24, $28
6140 0x03e07825, // or $15, $31, zero
6141 0x0018c082, // srl $24, $24, 2
6142 0x0320f809, // jalr $25
6143 0x2718fffe // subu $24, $24, 2
6146 // The format of the first PLT entry in an N32 executable. Different
6147 // because gp ($28) is not available; we use t2 ($14) instead.
6148 template<int size
, bool big_endian
>
6149 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n32
[] =
6151 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
6152 0x8dd90000, // lw $25, %lo(&GOTPLT[0])($14)
6153 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
6154 0x030ec023, // subu $24, $24, $14
6155 0x03e07825, // or $15, $31, zero
6156 0x0018c082, // srl $24, $24, 2
6157 0x0320f809, // jalr $25
6158 0x2718fffe // subu $24, $24, 2
6161 // The format of the first PLT entry in an N64 executable. Different
6162 // from N32 because of the increased size of GOT entries.
6163 template<int size
, bool big_endian
>
6164 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n64
[] =
6166 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
6167 0xddd90000, // ld $25, %lo(&GOTPLT[0])($14)
6168 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
6169 0x030ec023, // subu $24, $24, $14
6170 0x03e07825, // or $15, $31, zero
6171 0x0018c0c2, // srl $24, $24, 3
6172 0x0320f809, // jalr $25
6173 0x2718fffe // subu $24, $24, 2
6176 // The format of the microMIPS first PLT entry in an O32 executable.
6177 // We rely on v0 ($2) rather than t8 ($24) to contain the address
6178 // of the GOTPLT entry handled, so this stub may only be used when
6179 // all the subsequent PLT entries are microMIPS code too.
6181 // The trailing NOP is for alignment and correct disassembly only.
6182 template<int size
, bool big_endian
>
6183 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6184 plt0_entry_micromips_o32
[] =
6186 0x7980, 0x0000, // addiupc $3, (&GOTPLT[0]) - .
6187 0xff23, 0x0000, // lw $25, 0($3)
6188 0x0535, // subu $2, $2, $3
6189 0x2525, // srl $2, $2, 2
6190 0x3302, 0xfffe, // subu $24, $2, 2
6191 0x0dff, // move $15, $31
6192 0x45f9, // jalrs $25
6193 0x0f83, // move $28, $3
6197 // The format of the microMIPS first PLT entry in an O32 executable
6198 // in the insn32 mode.
6199 template<int size
, bool big_endian
>
6200 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6201 plt0_entry_micromips32_o32
[] =
6203 0x41bc, 0x0000, // lui $28, %hi(&GOTPLT[0])
6204 0xff3c, 0x0000, // lw $25, %lo(&GOTPLT[0])($28)
6205 0x339c, 0x0000, // addiu $28, $28, %lo(&GOTPLT[0])
6206 0x0398, 0xc1d0, // subu $24, $24, $28
6207 0x001f, 0x7a90, // or $15, $31, zero
6208 0x0318, 0x1040, // srl $24, $24, 2
6209 0x03f9, 0x0f3c, // jalr $25
6210 0x3318, 0xfffe // subu $24, $24, 2
6213 // The format of subsequent standard entries in the PLT.
6214 template<int size
, bool big_endian
>
6215 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry
[] =
6217 0x3c0f0000, // lui $15, %hi(.got.plt entry)
6218 0x8df90000, // l[wd] $25, %lo(.got.plt entry)($15)
6219 0x03200008, // jr $25
6220 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
6223 // The format of subsequent MIPS16 o32 PLT entries. We use v1 ($3) as a
6224 // temporary because t8 ($24) and t9 ($25) are not directly addressable.
6225 // Note that this differs from the GNU ld which uses both v0 ($2) and v1 ($3).
6226 // We cannot use v0 because MIPS16 call stubs from the CS toolchain expect
6227 // target function address in register v0.
6228 template<int size
, bool big_endian
>
6229 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry_mips16_o32
[] =
6231 0xb303, // lw $3, 12($pc)
6232 0x651b, // move $24, $3
6233 0x9b60, // lw $3, 0($3)
6235 0x653b, // move $25, $3
6237 0x0000, 0x0000 // .word (.got.plt entry)
6240 // The format of subsequent microMIPS o32 PLT entries. We use v0 ($2)
6241 // as a temporary because t8 ($24) is not addressable with ADDIUPC.
6242 template<int size
, bool big_endian
>
6243 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6244 plt_entry_micromips_o32
[] =
6246 0x7900, 0x0000, // addiupc $2, (.got.plt entry) - .
6247 0xff22, 0x0000, // lw $25, 0($2)
6249 0x0f02 // move $24, $2
6252 // The format of subsequent microMIPS o32 PLT entries in the insn32 mode.
6253 template<int size
, bool big_endian
>
6254 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6255 plt_entry_micromips32_o32
[] =
6257 0x41af, 0x0000, // lui $15, %hi(.got.plt entry)
6258 0xff2f, 0x0000, // lw $25, %lo(.got.plt entry)($15)
6259 0x0019, 0x0f3c, // jr $25
6260 0x330f, 0x0000 // addiu $24, $15, %lo(.got.plt entry)
6263 // Add an entry to the PLT for a symbol referenced by r_type relocation.
6265 template<int size
, bool big_endian
>
6267 Mips_output_data_plt
<size
, big_endian
>::add_entry(Mips_symbol
<size
>* gsym
,
6268 unsigned int r_type
)
6270 gold_assert(!gsym
->has_plt_offset());
6272 // Final PLT offset for a symbol will be set in method set_plt_offsets().
6273 gsym
->set_plt_offset(this->entry_count() * sizeof(plt_entry
)
6274 + sizeof(plt0_entry_o32
));
6275 this->symbols_
.push_back(gsym
);
6277 // Record whether the relocation requires a standard MIPS
6278 // or a compressed code entry.
6279 if (jal_reloc(r_type
))
6281 if (r_type
== elfcpp::R_MIPS_26
)
6282 gsym
->set_needs_mips_plt(true);
6284 gsym
->set_needs_comp_plt(true);
6287 section_offset_type got_offset
= this->got_plt_
->current_data_size();
6289 // Every PLT entry needs a GOT entry which points back to the PLT
6290 // entry (this will be changed by the dynamic linker, normally
6291 // lazily when the function is called).
6292 this->got_plt_
->set_current_data_size(got_offset
+ size
/8);
6294 gsym
->set_needs_dynsym_entry();
6295 this->rel_
->add_global(gsym
, elfcpp::R_MIPS_JUMP_SLOT
, this->got_plt_
,
6299 // Set final PLT offsets. For each symbol, determine whether standard or
6300 // compressed (MIPS16 or microMIPS) PLT entry is used.
6302 template<int size
, bool big_endian
>
6304 Mips_output_data_plt
<size
, big_endian
>::set_plt_offsets()
6306 // The sizes of individual PLT entries.
6307 unsigned int plt_mips_entry_size
= this->standard_plt_entry_size();
6308 unsigned int plt_comp_entry_size
= (!this->target_
->is_output_newabi()
6309 ? this->compressed_plt_entry_size() : 0);
6311 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
6312 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
6314 Mips_symbol
<size
>* mips_sym
= *p
;
6316 // There are no defined MIPS16 or microMIPS PLT entries for n32 or n64,
6317 // so always use a standard entry there.
6319 // If the symbol has a MIPS16 call stub and gets a PLT entry, then
6320 // all MIPS16 calls will go via that stub, and there is no benefit
6321 // to having a MIPS16 entry. And in the case of call_stub a
6322 // standard entry actually has to be used as the stub ends with a J
6324 if (this->target_
->is_output_newabi()
6325 || mips_sym
->has_mips16_call_stub()
6326 || mips_sym
->has_mips16_call_fp_stub())
6328 mips_sym
->set_needs_mips_plt(true);
6329 mips_sym
->set_needs_comp_plt(false);
6332 // Otherwise, if there are no direct calls to the function, we
6333 // have a free choice of whether to use standard or compressed
6334 // entries. Prefer microMIPS entries if the object is known to
6335 // contain microMIPS code, so that it becomes possible to create
6336 // pure microMIPS binaries. Prefer standard entries otherwise,
6337 // because MIPS16 ones are no smaller and are usually slower.
6338 if (!mips_sym
->needs_mips_plt() && !mips_sym
->needs_comp_plt())
6340 if (this->target_
->is_output_micromips())
6341 mips_sym
->set_needs_comp_plt(true);
6343 mips_sym
->set_needs_mips_plt(true);
6346 if (mips_sym
->needs_mips_plt())
6348 mips_sym
->set_mips_plt_offset(this->plt_mips_offset_
);
6349 this->plt_mips_offset_
+= plt_mips_entry_size
;
6351 if (mips_sym
->needs_comp_plt())
6353 mips_sym
->set_comp_plt_offset(this->plt_comp_offset_
);
6354 this->plt_comp_offset_
+= plt_comp_entry_size
;
6358 // Figure out the size of the PLT header if we know that we are using it.
6359 if (this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0)
6360 this->plt_header_size_
= this->get_plt_header_size();
6363 // Write out the PLT. This uses the hand-coded instructions above,
6364 // and adjusts them as needed.
6366 template<int size
, bool big_endian
>
6368 Mips_output_data_plt
<size
, big_endian
>::do_write(Output_file
* of
)
6370 const off_t offset
= this->offset();
6371 const section_size_type oview_size
=
6372 convert_to_section_size_type(this->data_size());
6373 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6375 const off_t gotplt_file_offset
= this->got_plt_
->offset();
6376 const section_size_type gotplt_size
=
6377 convert_to_section_size_type(this->got_plt_
->data_size());
6378 unsigned char* const gotplt_view
= of
->get_output_view(gotplt_file_offset
,
6380 unsigned char* pov
= oview
;
6382 Mips_address plt_address
= this->address();
6384 // Calculate the address of .got.plt.
6385 Mips_address gotplt_addr
= this->got_plt_
->address();
6386 Mips_address gotplt_addr_high
= ((gotplt_addr
+ 0x8000) >> 16) & 0xffff;
6387 Mips_address gotplt_addr_low
= gotplt_addr
& 0xffff;
6389 // The PLT sequence is not safe for N64 if .got.plt's address can
6390 // not be loaded in two instructions.
6391 gold_assert((gotplt_addr
& ~(Mips_address
) 0x7fffffff) == 0
6392 || ~(gotplt_addr
| 0x7fffffff) == 0);
6394 // Write the PLT header.
6395 const uint32_t* plt0_entry
= this->get_plt_header_entry();
6396 if (plt0_entry
== plt0_entry_micromips_o32
)
6398 // Write microMIPS PLT header.
6399 gold_assert(gotplt_addr
% 4 == 0);
6401 Mips_address gotpc_offset
= gotplt_addr
- ((plt_address
| 3) ^ 3);
6403 // ADDIUPC has a span of +/-16MB, check we're in range.
6404 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
6406 gold_error(_(".got.plt offset of %ld from .plt beyond the range of "
6407 "ADDIUPC"), (long)gotpc_offset
);
6411 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
6412 plt0_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
6413 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
6414 (gotpc_offset
>> 2) & 0xffff);
6416 for (unsigned int i
= 2;
6417 i
< (sizeof(plt0_entry_micromips_o32
)
6418 / sizeof(plt0_entry_micromips_o32
[0]));
6421 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
6425 else if (plt0_entry
== plt0_entry_micromips32_o32
)
6427 // Write microMIPS PLT header in insn32 mode.
6428 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[0]);
6429 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, gotplt_addr_high
);
6430 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, plt0_entry
[2]);
6431 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, gotplt_addr_low
);
6432 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8, plt0_entry
[4]);
6433 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, gotplt_addr_low
);
6435 for (unsigned int i
= 6;
6436 i
< (sizeof(plt0_entry_micromips32_o32
)
6437 / sizeof(plt0_entry_micromips32_o32
[0]));
6440 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
6446 // Write standard PLT header.
6447 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
6448 plt0_entry
[0] | gotplt_addr_high
);
6449 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
6450 plt0_entry
[1] | gotplt_addr_low
);
6451 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
6452 plt0_entry
[2] | gotplt_addr_low
);
6454 for (int i
= 3; i
< 8; i
++)
6456 elfcpp::Swap
<32, big_endian
>::writeval(pov
, plt0_entry
[i
]);
6462 unsigned char* gotplt_pov
= gotplt_view
;
6463 unsigned int got_entry_size
= size
/8; // TODO(sasa): MIPS_ELF_GOT_SIZE
6465 // The first two entries in .got.plt are reserved.
6466 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
, 0);
6467 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
+ got_entry_size
, 0);
6469 unsigned int gotplt_offset
= 2 * got_entry_size
;
6470 gotplt_pov
+= 2 * got_entry_size
;
6472 // Calculate the address of the PLT header.
6473 Mips_address header_address
= (plt_address
6474 + (this->is_plt_header_compressed() ? 1 : 0));
6476 // Initialize compressed PLT area view.
6477 unsigned char* pov2
= pov
+ this->plt_mips_offset_
;
6479 // Write the PLT entries.
6480 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
6481 p
= this->symbols_
.begin();
6482 p
!= this->symbols_
.end();
6483 ++p
, gotplt_pov
+= got_entry_size
, gotplt_offset
+= got_entry_size
)
6485 Mips_symbol
<size
>* mips_sym
= *p
;
6487 // Calculate the address of the .got.plt entry.
6488 uint32_t gotplt_entry_addr
= (gotplt_addr
+ gotplt_offset
);
6489 uint32_t gotplt_entry_addr_hi
= (((gotplt_entry_addr
+ 0x8000) >> 16)
6491 uint32_t gotplt_entry_addr_lo
= gotplt_entry_addr
& 0xffff;
6493 // Initially point the .got.plt entry at the PLT header.
6494 if (this->target_
->is_output_n64())
6495 elfcpp::Swap
<64, big_endian
>::writeval(gotplt_pov
, header_address
);
6497 elfcpp::Swap
<32, big_endian
>::writeval(gotplt_pov
, header_address
);
6499 // Now handle the PLT itself. First the standard entry.
6500 if (mips_sym
->has_mips_plt_offset())
6502 // Pick the load opcode (LW or LD).
6503 uint64_t load
= this->target_
->is_output_n64() ? 0xdc000000
6506 // Fill in the PLT entry itself.
6507 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
6508 plt_entry
[0] | gotplt_entry_addr_hi
);
6509 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
6510 plt_entry
[1] | gotplt_entry_addr_lo
| load
);
6511 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8, plt_entry
[2]);
6512 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12,
6513 plt_entry
[3] | gotplt_entry_addr_lo
);
6517 // Now the compressed entry. They come after any standard ones.
6518 if (mips_sym
->has_comp_plt_offset())
6520 if (!this->target_
->is_output_micromips())
6522 // Write MIPS16 PLT entry.
6523 const uint32_t* plt_entry
= plt_entry_mips16_o32
;
6525 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
6526 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2, plt_entry
[1]);
6527 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
6528 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
6529 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
6530 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
6531 elfcpp::Swap
<32, big_endian
>::writeval(pov2
+ 12,
6535 else if (this->target_
->use_32bit_micromips_instructions())
6537 // Write microMIPS PLT entry in insn32 mode.
6538 const uint32_t* plt_entry
= plt_entry_micromips32_o32
;
6540 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
6541 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2,
6542 gotplt_entry_addr_hi
);
6543 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
6544 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6,
6545 gotplt_entry_addr_lo
);
6546 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
6547 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
6548 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 12, plt_entry
[6]);
6549 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 14,
6550 gotplt_entry_addr_lo
);
6555 // Write microMIPS PLT entry.
6556 const uint32_t* plt_entry
= plt_entry_micromips_o32
;
6558 gold_assert(gotplt_entry_addr
% 4 == 0);
6560 Mips_address loc_address
= plt_address
+ pov2
- oview
;
6561 int gotpc_offset
= gotplt_entry_addr
- ((loc_address
| 3) ^ 3);
6563 // ADDIUPC has a span of +/-16MB, check we're in range.
6564 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
6566 gold_error(_(".got.plt offset of %ld from .plt beyond the "
6567 "range of ADDIUPC"), (long)gotpc_offset
);
6571 elfcpp::Swap
<16, big_endian
>::writeval(pov2
,
6572 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
6573 elfcpp::Swap
<16, big_endian
>::writeval(
6574 pov2
+ 2, (gotpc_offset
>> 2) & 0xffff);
6575 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
6576 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
6577 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
6578 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
6584 // Check the number of bytes written for standard entries.
6585 gold_assert(static_cast<section_size_type
>(
6586 pov
- oview
- this->plt_header_size_
) == this->plt_mips_offset_
);
6587 // Check the number of bytes written for compressed entries.
6588 gold_assert((static_cast<section_size_type
>(pov2
- pov
)
6589 == this->plt_comp_offset_
));
6590 // Check the total number of bytes written.
6591 gold_assert(static_cast<section_size_type
>(pov2
- oview
) == oview_size
);
6593 gold_assert(static_cast<section_size_type
>(gotplt_pov
- gotplt_view
)
6596 of
->write_output_view(offset
, oview_size
, oview
);
6597 of
->write_output_view(gotplt_file_offset
, gotplt_size
, gotplt_view
);
6600 // Mips_output_data_mips_stubs methods.
6602 // The format of the lazy binding stub when dynamic symbol count is less than
6603 // 64K, dynamic symbol index is less than 32K, and ABI is not N64.
6604 template<int size
, bool big_endian
>
6606 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1
[4] =
6608 0x8f998010, // lw t9,0x8010(gp)
6609 0x03e07825, // or t7,ra,zero
6610 0x0320f809, // jalr t9,ra
6611 0x24180000 // addiu t8,zero,DYN_INDEX sign extended
6614 // The format of the lazy binding stub when dynamic symbol count is less than
6615 // 64K, dynamic symbol index is less than 32K, and ABI is N64.
6616 template<int size
, bool big_endian
>
6618 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1_n64
[4] =
6620 0xdf998010, // ld t9,0x8010(gp)
6621 0x03e07825, // or t7,ra,zero
6622 0x0320f809, // jalr t9,ra
6623 0x64180000 // daddiu t8,zero,DYN_INDEX sign extended
6626 // The format of the lazy binding stub when dynamic symbol count is less than
6627 // 64K, dynamic symbol index is between 32K and 64K, and ABI is not N64.
6628 template<int size
, bool big_endian
>
6630 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2
[4] =
6632 0x8f998010, // lw t9,0x8010(gp)
6633 0x03e07825, // or t7,ra,zero
6634 0x0320f809, // jalr t9,ra
6635 0x34180000 // ori t8,zero,DYN_INDEX unsigned
6638 // The format of the lazy binding stub when dynamic symbol count is less than
6639 // 64K, dynamic symbol index is between 32K and 64K, and ABI is N64.
6640 template<int size
, bool big_endian
>
6642 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2_n64
[4] =
6644 0xdf998010, // ld t9,0x8010(gp)
6645 0x03e07825, // or t7,ra,zero
6646 0x0320f809, // jalr t9,ra
6647 0x34180000 // ori t8,zero,DYN_INDEX unsigned
6650 // The format of the lazy binding stub when dynamic symbol count is greater than
6651 // 64K, and ABI is not N64.
6652 template<int size
, bool big_endian
>
6653 const uint32_t Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big
[5] =
6655 0x8f998010, // lw t9,0x8010(gp)
6656 0x03e07825, // or t7,ra,zero
6657 0x3c180000, // lui t8,DYN_INDEX
6658 0x0320f809, // jalr t9,ra
6659 0x37180000 // ori t8,t8,DYN_INDEX
6662 // The format of the lazy binding stub when dynamic symbol count is greater than
6663 // 64K, and ABI is N64.
6664 template<int size
, bool big_endian
>
6666 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big_n64
[5] =
6668 0xdf998010, // ld t9,0x8010(gp)
6669 0x03e07825, // or t7,ra,zero
6670 0x3c180000, // lui t8,DYN_INDEX
6671 0x0320f809, // jalr t9,ra
6672 0x37180000 // ori t8,t8,DYN_INDEX
6677 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6678 // less than 64K, dynamic symbol index is less than 32K, and ABI is not N64.
6679 template<int size
, bool big_endian
>
6681 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_1
[] =
6683 0xff3c, 0x8010, // lw t9,0x8010(gp)
6684 0x0dff, // move t7,ra
6686 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
6689 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6690 // less than 64K, dynamic symbol index is less than 32K, and ABI is N64.
6691 template<int size
, bool big_endian
>
6693 Mips_output_data_mips_stubs
<size
, big_endian
>::
6694 lazy_stub_micromips_normal_1_n64
[] =
6696 0xdf3c, 0x8010, // ld t9,0x8010(gp)
6697 0x0dff, // move t7,ra
6699 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
6702 // The format of the microMIPS lazy binding stub when dynamic symbol
6703 // count is less than 64K, dynamic symbol index is between 32K and 64K,
6704 // and ABI is not N64.
6705 template<int size
, bool big_endian
>
6707 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_2
[] =
6709 0xff3c, 0x8010, // lw t9,0x8010(gp)
6710 0x0dff, // move t7,ra
6712 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
6715 // The format of the microMIPS lazy binding stub when dynamic symbol
6716 // count is less than 64K, dynamic symbol index is between 32K and 64K,
6718 template<int size
, bool big_endian
>
6720 Mips_output_data_mips_stubs
<size
, big_endian
>::
6721 lazy_stub_micromips_normal_2_n64
[] =
6723 0xdf3c, 0x8010, // ld t9,0x8010(gp)
6724 0x0dff, // move t7,ra
6726 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
6729 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6730 // greater than 64K, and ABI is not N64.
6731 template<int size
, bool big_endian
>
6733 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big
[] =
6735 0xff3c, 0x8010, // lw t9,0x8010(gp)
6736 0x0dff, // move t7,ra
6737 0x41b8, 0x0000, // lui t8,DYN_INDEX
6739 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
6742 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6743 // greater than 64K, and ABI is N64.
6744 template<int size
, bool big_endian
>
6746 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big_n64
[] =
6748 0xdf3c, 0x8010, // ld t9,0x8010(gp)
6749 0x0dff, // move t7,ra
6750 0x41b8, 0x0000, // lui t8,DYN_INDEX
6752 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
6755 // 32-bit microMIPS stubs.
6757 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6758 // less than 64K, dynamic symbol index is less than 32K, ABI is not N64, and we
6759 // can use only 32-bit instructions.
6760 template<int size
, bool big_endian
>
6762 Mips_output_data_mips_stubs
<size
, big_endian
>::
6763 lazy_stub_micromips32_normal_1
[] =
6765 0xff3c, 0x8010, // lw t9,0x8010(gp)
6766 0x001f, 0x7a90, // or t7,ra,zero
6767 0x03f9, 0x0f3c, // jalr ra,t9
6768 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
6771 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6772 // less than 64K, dynamic symbol index is less than 32K, ABI is N64, and we can
6773 // use only 32-bit instructions.
6774 template<int size
, bool big_endian
>
6776 Mips_output_data_mips_stubs
<size
, big_endian
>::
6777 lazy_stub_micromips32_normal_1_n64
[] =
6779 0xdf3c, 0x8010, // ld t9,0x8010(gp)
6780 0x001f, 0x7a90, // or t7,ra,zero
6781 0x03f9, 0x0f3c, // jalr ra,t9
6782 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
6785 // The format of the microMIPS lazy binding stub when dynamic symbol
6786 // count is less than 64K, dynamic symbol index is between 32K and 64K,
6787 // ABI is not N64, and we can use only 32-bit instructions.
6788 template<int size
, bool big_endian
>
6790 Mips_output_data_mips_stubs
<size
, big_endian
>::
6791 lazy_stub_micromips32_normal_2
[] =
6793 0xff3c, 0x8010, // lw t9,0x8010(gp)
6794 0x001f, 0x7a90, // or t7,ra,zero
6795 0x03f9, 0x0f3c, // jalr ra,t9
6796 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
6799 // The format of the microMIPS lazy binding stub when dynamic symbol
6800 // count is less than 64K, dynamic symbol index is between 32K and 64K,
6801 // ABI is N64, and we can use only 32-bit instructions.
6802 template<int size
, bool big_endian
>
6804 Mips_output_data_mips_stubs
<size
, big_endian
>::
6805 lazy_stub_micromips32_normal_2_n64
[] =
6807 0xdf3c, 0x8010, // ld t9,0x8010(gp)
6808 0x001f, 0x7a90, // or t7,ra,zero
6809 0x03f9, 0x0f3c, // jalr ra,t9
6810 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
6813 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6814 // greater than 64K, ABI is not N64, and we can use only 32-bit instructions.
6815 template<int size
, bool big_endian
>
6817 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big
[] =
6819 0xff3c, 0x8010, // lw t9,0x8010(gp)
6820 0x001f, 0x7a90, // or t7,ra,zero
6821 0x41b8, 0x0000, // lui t8,DYN_INDEX
6822 0x03f9, 0x0f3c, // jalr ra,t9
6823 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
6826 // The format of the microMIPS lazy binding stub when dynamic symbol count is
6827 // greater than 64K, ABI is N64, and we can use only 32-bit instructions.
6828 template<int size
, bool big_endian
>
6830 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big_n64
[] =
6832 0xdf3c, 0x8010, // ld t9,0x8010(gp)
6833 0x001f, 0x7a90, // or t7,ra,zero
6834 0x41b8, 0x0000, // lui t8,DYN_INDEX
6835 0x03f9, 0x0f3c, // jalr ra,t9
6836 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
6839 // Create entry for a symbol.
6841 template<int size
, bool big_endian
>
6843 Mips_output_data_mips_stubs
<size
, big_endian
>::make_entry(
6844 Mips_symbol
<size
>* gsym
)
6846 if (!gsym
->has_lazy_stub() && !gsym
->has_plt_offset())
6848 this->symbols_
.insert(gsym
);
6849 gsym
->set_has_lazy_stub(true);
6853 // Remove entry for a symbol.
6855 template<int size
, bool big_endian
>
6857 Mips_output_data_mips_stubs
<size
, big_endian
>::remove_entry(
6858 Mips_symbol
<size
>* gsym
)
6860 if (gsym
->has_lazy_stub())
6862 this->symbols_
.erase(gsym
);
6863 gsym
->set_has_lazy_stub(false);
6867 // Set stub offsets for symbols. This method expects that the number of
6868 // entries in dynamic symbol table is set.
6870 template<int size
, bool big_endian
>
6872 Mips_output_data_mips_stubs
<size
, big_endian
>::set_lazy_stub_offsets()
6874 gold_assert(this->dynsym_count_
!= -1U);
6876 if (this->stub_offsets_are_set_
)
6879 unsigned int stub_size
= this->stub_size();
6880 unsigned int offset
= 0;
6881 for (typename Unordered_set
<Mips_symbol
<size
>*>::const_iterator
6882 p
= this->symbols_
.begin();
6883 p
!= this->symbols_
.end();
6884 ++p
, offset
+= stub_size
)
6886 Mips_symbol
<size
>* mips_sym
= *p
;
6887 mips_sym
->set_lazy_stub_offset(offset
);
6889 this->stub_offsets_are_set_
= true;
6892 template<int size
, bool big_endian
>
6894 Mips_output_data_mips_stubs
<size
, big_endian
>::set_needs_dynsym_value()
6896 for (typename Unordered_set
<Mips_symbol
<size
>*>::const_iterator
6897 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
6899 Mips_symbol
<size
>* sym
= *p
;
6900 if (sym
->is_from_dynobj())
6901 sym
->set_needs_dynsym_value();
6905 // Write out the .MIPS.stubs. This uses the hand-coded instructions and
6906 // adjusts them as needed.
6908 template<int size
, bool big_endian
>
6910 Mips_output_data_mips_stubs
<size
, big_endian
>::do_write(Output_file
* of
)
6912 const off_t offset
= this->offset();
6913 const section_size_type oview_size
=
6914 convert_to_section_size_type(this->data_size());
6915 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6917 bool big_stub
= this->dynsym_count_
> 0x10000;
6919 unsigned char* pov
= oview
;
6920 for (typename Unordered_set
<Mips_symbol
<size
>*>::const_iterator
6921 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
6923 Mips_symbol
<size
>* sym
= *p
;
6924 const uint32_t* lazy_stub
;
6925 bool n64
= this->target_
->is_output_n64();
6927 if (!this->target_
->is_output_micromips())
6929 // Write standard (non-microMIPS) stub.
6932 if (sym
->dynsym_index() & ~0x7fff)
6933 // Dynsym index is between 32K and 64K.
6934 lazy_stub
= n64
? lazy_stub_normal_2_n64
: lazy_stub_normal_2
;
6936 // Dynsym index is less than 32K.
6937 lazy_stub
= n64
? lazy_stub_normal_1_n64
: lazy_stub_normal_1
;
6940 lazy_stub
= n64
? lazy_stub_big_n64
: lazy_stub_big
;
6943 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
6944 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 1]);
6950 // LUI instruction of the big stub. Paste high 16 bits of the
6952 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
6953 lazy_stub
[i
] | ((sym
->dynsym_index() >> 16) & 0x7fff));
6957 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
6958 // Last stub instruction. Paste low 16 bits of the dynsym index.
6959 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
6960 lazy_stub
[i
+ 1] | (sym
->dynsym_index() & 0xffff));
6963 else if (this->target_
->use_32bit_micromips_instructions())
6965 // Write microMIPS stub in insn32 mode.
6968 if (sym
->dynsym_index() & ~0x7fff)
6969 // Dynsym index is between 32K and 64K.
6970 lazy_stub
= n64
? lazy_stub_micromips32_normal_2_n64
6971 : lazy_stub_micromips32_normal_2
;
6973 // Dynsym index is less than 32K.
6974 lazy_stub
= n64
? lazy_stub_micromips32_normal_1_n64
6975 : lazy_stub_micromips32_normal_1
;
6978 lazy_stub
= n64
? lazy_stub_micromips32_big_n64
6979 : lazy_stub_micromips32_big
;
6982 // First stub instruction. We emit 32-bit microMIPS instructions by
6983 // emitting two 16-bit parts because on microMIPS the 16-bit part of
6984 // the instruction where the opcode is must always come first, for
6985 // both little and big endian.
6986 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
6987 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
6988 // Second stub instruction.
6989 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
6990 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, lazy_stub
[i
+ 3]);
6995 // LUI instruction of the big stub. Paste high 16 bits of the
6997 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
6998 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
6999 (sym
->dynsym_index() >> 16) & 0x7fff);
7003 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7004 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7005 // Last stub instruction. Paste low 16 bits of the dynsym index.
7006 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7007 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
7008 sym
->dynsym_index() & 0xffff);
7013 // Write microMIPS stub.
7016 if (sym
->dynsym_index() & ~0x7fff)
7017 // Dynsym index is between 32K and 64K.
7018 lazy_stub
= n64
? lazy_stub_micromips_normal_2_n64
7019 : lazy_stub_micromips_normal_2
;
7021 // Dynsym index is less than 32K.
7022 lazy_stub
= n64
? lazy_stub_micromips_normal_1_n64
7023 : lazy_stub_micromips_normal_1
;
7026 lazy_stub
= n64
? lazy_stub_micromips_big_n64
7027 : lazy_stub_micromips_big
;
7030 // First stub instruction. We emit 32-bit microMIPS instructions by
7031 // emitting two 16-bit parts because on microMIPS the 16-bit part of
7032 // the instruction where the opcode is must always come first, for
7033 // both little and big endian.
7034 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7035 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7036 // Second stub instruction.
7037 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7042 // LUI instruction of the big stub. Paste high 16 bits of the
7044 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7045 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7046 (sym
->dynsym_index() >> 16) & 0x7fff);
7050 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7051 // Last stub instruction. Paste low 16 bits of the dynsym index.
7052 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7053 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
7054 sym
->dynsym_index() & 0xffff);
7059 // We always allocate 20 bytes for every stub, because final dynsym count is
7060 // not known in method do_finalize_sections. There are 4 unused bytes per
7061 // stub if final dynsym count is less than 0x10000.
7062 unsigned int used
= pov
- oview
;
7063 unsigned int unused
= big_stub
? 0 : this->symbols_
.size() * 4;
7064 gold_assert(static_cast<section_size_type
>(used
+ unused
) == oview_size
);
7066 // Fill the unused space with zeroes.
7067 // TODO(sasa): Can we strip unused bytes during the relaxation?
7069 memset(pov
, 0, unused
);
7071 of
->write_output_view(offset
, oview_size
, oview
);
7074 // Mips_output_section_reginfo methods.
7076 template<int size
, bool big_endian
>
7078 Mips_output_section_reginfo
<size
, big_endian
>::do_write(Output_file
* of
)
7080 off_t offset
= this->offset();
7081 off_t data_size
= this->data_size();
7083 unsigned char* view
= of
->get_output_view(offset
, data_size
);
7084 elfcpp::Swap
<size
, big_endian
>::writeval(view
, this->gprmask_
);
7085 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 4, this->cprmask1_
);
7086 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 8, this->cprmask2_
);
7087 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 12, this->cprmask3_
);
7088 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 16, this->cprmask4_
);
7089 // Write the gp value.
7090 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 20,
7091 this->target_
->gp_value());
7093 of
->write_output_view(offset
, data_size
, view
);
7096 // Mips_copy_relocs methods.
7098 // Emit any saved relocs.
7100 template<int sh_type
, int size
, bool big_endian
>
7102 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_mips(
7103 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
7104 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
7106 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
7107 Copy_reloc_entries::iterator p
= this->entries_
.begin();
7108 p
!= this->entries_
.end();
7110 emit_entry(*p
, reloc_section
, symtab
, layout
, target
);
7112 // We no longer need the saved information.
7113 this->entries_
.clear();
7116 // Emit the reloc if appropriate.
7118 template<int sh_type
, int size
, bool big_endian
>
7120 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_entry(
7121 Copy_reloc_entry
& entry
,
7122 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
7123 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
7125 // If the symbol is no longer defined in a dynamic object, then we
7126 // emitted a COPY relocation, and we do not want to emit this
7127 // dynamic relocation.
7128 if (!entry
.sym_
->is_from_dynobj())
7131 bool can_make_dynamic
= (entry
.reloc_type_
== elfcpp::R_MIPS_32
7132 || entry
.reloc_type_
== elfcpp::R_MIPS_REL32
7133 || entry
.reloc_type_
== elfcpp::R_MIPS_64
);
7135 Mips_symbol
<size
>* sym
= Mips_symbol
<size
>::as_mips_sym(entry
.sym_
);
7136 if (can_make_dynamic
&& !sym
->has_static_relocs())
7138 Mips_relobj
<size
, big_endian
>* object
=
7139 Mips_relobj
<size
, big_endian
>::as_mips_relobj(entry
.relobj_
);
7140 target
->got_section(symtab
, layout
)->record_global_got_symbol(
7141 sym
, object
, entry
.reloc_type_
, true, false);
7142 if (!symbol_references_local(sym
, sym
->should_add_dynsym_entry(symtab
)))
7143 target
->rel_dyn_section(layout
)->add_global(sym
, elfcpp::R_MIPS_REL32
,
7144 entry
.output_section_
, entry
.relobj_
, entry
.shndx_
, entry
.address_
);
7146 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
7147 sym
, elfcpp::R_MIPS_REL32
, entry
.output_section_
, entry
.relobj_
,
7148 entry
.shndx_
, entry
.address_
);
7151 this->make_copy_reloc(symtab
, layout
,
7152 static_cast<Sized_symbol
<size
>*>(entry
.sym_
),
7156 // Target_mips methods.
7158 // Return the value to use for a dynamic symbol which requires special
7159 // treatment. This is how we support equality comparisons of function
7160 // pointers across shared library boundaries, as described in the
7161 // processor specific ABI supplement.
7163 template<int size
, bool big_endian
>
7165 Target_mips
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
7168 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
7170 if (!mips_sym
->has_lazy_stub())
7172 if (mips_sym
->has_plt_offset())
7174 // We distinguish between PLT entries and lazy-binding stubs by
7175 // giving the former an st_other value of STO_MIPS_PLT. Set the
7176 // value to the stub address if there are any relocations in the
7177 // binary where pointer equality matters.
7178 if (mips_sym
->pointer_equality_needed())
7180 // Prefer a standard MIPS PLT entry.
7181 if (mips_sym
->has_mips_plt_offset())
7182 value
= this->plt_section()->mips_entry_address(mips_sym
);
7184 value
= this->plt_section()->comp_entry_address(mips_sym
) + 1;
7192 // First, set stub offsets for symbols. This method expects that the
7193 // number of entries in dynamic symbol table is set.
7194 this->mips_stubs_section()->set_lazy_stub_offsets();
7196 // The run-time linker uses the st_value field of the symbol
7197 // to reset the global offset table entry for this external
7198 // to its stub address when unlinking a shared object.
7199 value
= this->mips_stubs_section()->stub_address(mips_sym
);
7202 if (mips_sym
->has_mips16_fn_stub())
7204 // If we have a MIPS16 function with a stub, the dynamic symbol must
7205 // refer to the stub, since only the stub uses the standard calling
7207 value
= mips_sym
->template
7208 get_mips16_fn_stub
<big_endian
>()->output_address();
7214 // Get the dynamic reloc section, creating it if necessary. It's always
7215 // .rel.dyn, even for MIPS64.
7217 template<int size
, bool big_endian
>
7218 typename Target_mips
<size
, big_endian
>::Reloc_section
*
7219 Target_mips
<size
, big_endian
>::rel_dyn_section(Layout
* layout
)
7221 if (this->rel_dyn_
== NULL
)
7223 gold_assert(layout
!= NULL
);
7224 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
7225 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
7226 elfcpp::SHF_ALLOC
, this->rel_dyn_
,
7227 ORDER_DYNAMIC_RELOCS
, false);
7229 // First entry in .rel.dyn has to be null.
7230 // This is hack - we define dummy output data and set its address to 0,
7231 // and define absolute R_MIPS_NONE relocation with offset 0 against it.
7232 // This ensures that the entry is null.
7233 Output_data
* od
= new Output_data_zero_fill(0, 0);
7235 this->rel_dyn_
->add_absolute(elfcpp::R_MIPS_NONE
, od
, 0);
7237 return this->rel_dyn_
;
7240 // Get the GOT section, creating it if necessary.
7242 template<int size
, bool big_endian
>
7243 Mips_output_data_got
<size
, big_endian
>*
7244 Target_mips
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
7247 if (this->got_
== NULL
)
7249 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
7251 this->got_
= new Mips_output_data_got
<size
, big_endian
>(this, symtab
,
7253 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
7254 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
|
7255 elfcpp::SHF_MIPS_GPREL
),
7256 this->got_
, ORDER_DATA
, false);
7258 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
7259 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
7260 Symbol_table::PREDEFINED
,
7262 0, 0, elfcpp::STT_OBJECT
,
7264 elfcpp::STV_DEFAULT
, 0,
7271 // Calculate value of _gp symbol.
7273 template<int size
, bool big_endian
>
7275 Target_mips
<size
, big_endian
>::set_gp(Layout
* layout
, Symbol_table
* symtab
)
7277 if (this->gp_
!= NULL
)
7280 Output_data
* section
= layout
->find_output_section(".got");
7281 if (section
== NULL
)
7283 // If there is no .got section, gp should be based on .sdata.
7284 // TODO(sasa): This is probably not needed. This was needed for older
7285 // MIPS architectures which accessed both GOT and .sdata section using
7286 // gp-relative addressing. Modern Mips Linux ELF architectures don't
7287 // access .sdata using gp-relative addressing.
7288 for (Layout::Section_list::const_iterator
7289 p
= layout
->section_list().begin();
7290 p
!= layout
->section_list().end();
7293 if (strcmp((*p
)->name(), ".sdata") == 0)
7301 Sized_symbol
<size
>* gp
=
7302 static_cast<Sized_symbol
<size
>*>(symtab
->lookup("_gp"));
7305 if (gp
->source() != Symbol::IS_CONSTANT
&& section
!= NULL
)
7306 gp
->init_output_data(gp
->name(), NULL
, section
, MIPS_GP_OFFSET
, 0,
7309 elfcpp::STV_DEFAULT
, 0,
7313 else if (section
!= NULL
)
7315 gp
= static_cast<Sized_symbol
<size
>*>(symtab
->define_in_output_data(
7316 "_gp", NULL
, Symbol_table::PREDEFINED
,
7317 section
, MIPS_GP_OFFSET
, 0,
7320 elfcpp::STV_DEFAULT
,
7326 // Set the dynamic symbol indexes. INDEX is the index of the first
7327 // global dynamic symbol. Pointers to the symbols are stored into the
7328 // vector SYMS. The names are added to DYNPOOL. This returns an
7329 // updated dynamic symbol index.
7331 template<int size
, bool big_endian
>
7333 Target_mips
<size
, big_endian
>::do_set_dynsym_indexes(
7334 std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
7335 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
7336 Versions
* versions
, Symbol_table
* symtab
) const
7338 std::vector
<Symbol
*> non_got_symbols
;
7339 std::vector
<Symbol
*> got_symbols
;
7341 reorder_dyn_symbols
<size
, big_endian
>(dyn_symbols
, &non_got_symbols
,
7344 for (std::vector
<Symbol
*>::iterator p
= non_got_symbols
.begin();
7345 p
!= non_got_symbols
.end();
7350 // Note that SYM may already have a dynamic symbol index, since
7351 // some symbols appear more than once in the symbol table, with
7352 // and without a version.
7354 if (!sym
->has_dynsym_index())
7356 sym
->set_dynsym_index(index
);
7358 syms
->push_back(sym
);
7359 dynpool
->add(sym
->name(), false, NULL
);
7361 // Record any version information.
7362 if (sym
->version() != NULL
)
7363 versions
->record_version(symtab
, dynpool
, sym
);
7365 // If the symbol is defined in a dynamic object and is
7366 // referenced in a regular object, then mark the dynamic
7367 // object as needed. This is used to implement --as-needed.
7368 if (sym
->is_from_dynobj() && sym
->in_reg())
7369 sym
->object()->set_is_needed();
7373 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
7374 p
!= got_symbols
.end();
7378 if (!sym
->has_dynsym_index())
7380 // Record any version information.
7381 if (sym
->version() != NULL
)
7382 versions
->record_version(symtab
, dynpool
, sym
);
7386 index
= versions
->finalize(symtab
, index
, syms
);
7388 int got_sym_count
= 0;
7389 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
7390 p
!= got_symbols
.end();
7395 if (!sym
->has_dynsym_index())
7398 sym
->set_dynsym_index(index
);
7400 syms
->push_back(sym
);
7401 dynpool
->add(sym
->name(), false, NULL
);
7403 // If the symbol is defined in a dynamic object and is
7404 // referenced in a regular object, then mark the dynamic
7405 // object as needed. This is used to implement --as-needed.
7406 if (sym
->is_from_dynobj() && sym
->in_reg())
7407 sym
->object()->set_is_needed();
7411 // Set index of the first symbol that has .got entry.
7412 this->got_
->set_first_global_got_dynsym_index(
7413 got_sym_count
> 0 ? index
- got_sym_count
: -1U);
7415 if (this->mips_stubs_
!= NULL
)
7416 this->mips_stubs_
->set_dynsym_count(index
);
7421 // Create a PLT entry for a global symbol referenced by r_type relocation.
7423 template<int size
, bool big_endian
>
7425 Target_mips
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7427 Mips_symbol
<size
>* gsym
,
7428 unsigned int r_type
)
7430 if (gsym
->has_lazy_stub() || gsym
->has_plt_offset())
7433 if (this->plt_
== NULL
)
7435 // Create the GOT section first.
7436 this->got_section(symtab
, layout
);
7438 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
7439 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
7440 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
7441 this->got_plt_
, ORDER_DATA
, false);
7443 // The first two entries are reserved.
7444 this->got_plt_
->set_current_data_size(2 * size
/8);
7446 this->plt_
= new Mips_output_data_plt
<size
, big_endian
>(layout
,
7449 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
7451 | elfcpp::SHF_EXECINSTR
),
7452 this->plt_
, ORDER_PLT
, false);
7455 this->plt_
->add_entry(gsym
, r_type
);
7459 // Get the .MIPS.stubs section, creating it if necessary.
7461 template<int size
, bool big_endian
>
7462 Mips_output_data_mips_stubs
<size
, big_endian
>*
7463 Target_mips
<size
, big_endian
>::mips_stubs_section(Layout
* layout
)
7465 if (this->mips_stubs_
== NULL
)
7468 new Mips_output_data_mips_stubs
<size
, big_endian
>(this);
7469 layout
->add_output_section_data(".MIPS.stubs", elfcpp::SHT_PROGBITS
,
7471 | elfcpp::SHF_EXECINSTR
),
7472 this->mips_stubs_
, ORDER_PLT
, false);
7474 return this->mips_stubs_
;
7477 // Get the LA25 stub section, creating it if necessary.
7479 template<int size
, bool big_endian
>
7480 Mips_output_data_la25_stub
<size
, big_endian
>*
7481 Target_mips
<size
, big_endian
>::la25_stub_section(Layout
* layout
)
7483 if (this->la25_stub_
== NULL
)
7485 this->la25_stub_
= new Mips_output_data_la25_stub
<size
, big_endian
>();
7486 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7488 | elfcpp::SHF_EXECINSTR
),
7489 this->la25_stub_
, ORDER_TEXT
, false);
7491 return this->la25_stub_
;
7494 // Process the relocations to determine unreferenced sections for
7495 // garbage collection.
7497 template<int size
, bool big_endian
>
7499 Target_mips
<size
, big_endian
>::gc_process_relocs(
7500 Symbol_table
* symtab
,
7502 Sized_relobj_file
<size
, big_endian
>* object
,
7503 unsigned int data_shndx
,
7505 const unsigned char* prelocs
,
7507 Output_section
* output_section
,
7508 bool needs_special_offset_handling
,
7509 size_t local_symbol_count
,
7510 const unsigned char* plocal_symbols
)
7512 typedef Target_mips
<size
, big_endian
> Mips
;
7513 typedef typename Target_mips
<size
, big_endian
>::Scan Scan
;
7515 gold::gc_process_relocs
<size
, big_endian
, Mips
, elfcpp::SHT_REL
, Scan
,
7516 typename
Target_mips::Relocatable_size_for_reloc
>(
7525 needs_special_offset_handling
,
7530 // Scan relocations for a section.
7532 template<int size
, bool big_endian
>
7534 Target_mips
<size
, big_endian
>::scan_relocs(
7535 Symbol_table
* symtab
,
7537 Sized_relobj_file
<size
, big_endian
>* object
,
7538 unsigned int data_shndx
,
7539 unsigned int sh_type
,
7540 const unsigned char* prelocs
,
7542 Output_section
* output_section
,
7543 bool needs_special_offset_handling
,
7544 size_t local_symbol_count
,
7545 const unsigned char* plocal_symbols
)
7547 typedef Target_mips
<size
, big_endian
> Mips
;
7548 typedef typename Target_mips
<size
, big_endian
>::Scan Scan
;
7550 if (sh_type
== elfcpp::SHT_REL
)
7551 gold::scan_relocs
<size
, big_endian
, Mips
, elfcpp::SHT_REL
, Scan
>(
7560 needs_special_offset_handling
,
7563 else if (sh_type
== elfcpp::SHT_RELA
)
7564 gold::scan_relocs
<size
, big_endian
, Mips
, elfcpp::SHT_RELA
, Scan
>(
7573 needs_special_offset_handling
,
7578 template<int size
, bool big_endian
>
7580 Target_mips
<size
, big_endian
>::mips_32bit_flags(elfcpp::Elf_Word flags
)
7582 return ((flags
& elfcpp::EF_MIPS_32BITMODE
) != 0
7583 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_O32
7584 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_EABI32
7585 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_1
7586 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_2
7587 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32
7588 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32R2
);
7591 // Return the MACH for a MIPS e_flags value.
7592 template<int size
, bool big_endian
>
7594 Target_mips
<size
, big_endian
>::elf_mips_mach(elfcpp::Elf_Word flags
)
7596 switch (flags
& elfcpp::EF_MIPS_MACH
)
7598 case elfcpp::E_MIPS_MACH_3900
:
7599 return mach_mips3900
;
7601 case elfcpp::E_MIPS_MACH_4010
:
7602 return mach_mips4010
;
7604 case elfcpp::E_MIPS_MACH_4100
:
7605 return mach_mips4100
;
7607 case elfcpp::E_MIPS_MACH_4111
:
7608 return mach_mips4111
;
7610 case elfcpp::E_MIPS_MACH_4120
:
7611 return mach_mips4120
;
7613 case elfcpp::E_MIPS_MACH_4650
:
7614 return mach_mips4650
;
7616 case elfcpp::E_MIPS_MACH_5400
:
7617 return mach_mips5400
;
7619 case elfcpp::E_MIPS_MACH_5500
:
7620 return mach_mips5500
;
7622 case elfcpp::E_MIPS_MACH_9000
:
7623 return mach_mips9000
;
7625 case elfcpp::E_MIPS_MACH_SB1
:
7626 return mach_mips_sb1
;
7628 case elfcpp::E_MIPS_MACH_LS2E
:
7629 return mach_mips_loongson_2e
;
7631 case elfcpp::E_MIPS_MACH_LS2F
:
7632 return mach_mips_loongson_2f
;
7634 case elfcpp::E_MIPS_MACH_LS3A
:
7635 return mach_mips_loongson_3a
;
7637 case elfcpp::E_MIPS_MACH_OCTEON2
:
7638 return mach_mips_octeon2
;
7640 case elfcpp::E_MIPS_MACH_OCTEON
:
7641 return mach_mips_octeon
;
7643 case elfcpp::E_MIPS_MACH_XLR
:
7644 return mach_mips_xlr
;
7647 switch (flags
& elfcpp::EF_MIPS_ARCH
)
7650 case elfcpp::E_MIPS_ARCH_1
:
7651 return mach_mips3000
;
7653 case elfcpp::E_MIPS_ARCH_2
:
7654 return mach_mips6000
;
7656 case elfcpp::E_MIPS_ARCH_3
:
7657 return mach_mips4000
;
7659 case elfcpp::E_MIPS_ARCH_4
:
7660 return mach_mips8000
;
7662 case elfcpp::E_MIPS_ARCH_5
:
7665 case elfcpp::E_MIPS_ARCH_32
:
7666 return mach_mipsisa32
;
7668 case elfcpp::E_MIPS_ARCH_64
:
7669 return mach_mipsisa64
;
7671 case elfcpp::E_MIPS_ARCH_32R2
:
7672 return mach_mipsisa32r2
;
7674 case elfcpp::E_MIPS_ARCH_64R2
:
7675 return mach_mipsisa64r2
;
7682 // Check whether machine EXTENSION is an extension of machine BASE.
7683 template<int size
, bool big_endian
>
7685 Target_mips
<size
, big_endian
>::mips_mach_extends(unsigned int base
,
7686 unsigned int extension
)
7688 if (extension
== base
)
7691 if ((base
== mach_mipsisa32
)
7692 && this->mips_mach_extends(mach_mipsisa64
, extension
))
7695 if ((base
== mach_mipsisa32r2
)
7696 && this->mips_mach_extends(mach_mipsisa64r2
, extension
))
7699 for (unsigned int i
= 0; i
< this->mips_mach_extensions_
.size(); ++i
)
7700 if (extension
== this->mips_mach_extensions_
[i
].first
)
7702 extension
= this->mips_mach_extensions_
[i
].second
;
7703 if (extension
== base
)
7710 template<int size
, bool big_endian
>
7712 Target_mips
<size
, big_endian
>::merge_processor_specific_flags(
7713 const std::string
& name
, elfcpp::Elf_Word in_flags
,
7714 unsigned char in_ei_class
, bool dyn_obj
)
7716 // If flags are not set yet, just copy them.
7717 if (!this->are_processor_specific_flags_set())
7719 this->set_processor_specific_flags(in_flags
);
7720 this->ei_class_
= in_ei_class
;
7721 this->mach_
= this->elf_mips_mach(in_flags
);
7725 elfcpp::Elf_Word new_flags
= in_flags
;
7726 elfcpp::Elf_Word old_flags
= this->processor_specific_flags();
7727 elfcpp::Elf_Word merged_flags
= this->processor_specific_flags();
7728 merged_flags
|= new_flags
& elfcpp::EF_MIPS_NOREORDER
;
7730 // Check flag compatibility.
7731 new_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
7732 old_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
7734 // Some IRIX 6 BSD-compatibility objects have this bit set. It
7735 // doesn't seem to matter.
7736 new_flags
&= ~elfcpp::EF_MIPS_XGOT
;
7737 old_flags
&= ~elfcpp::EF_MIPS_XGOT
;
7739 // MIPSpro generates ucode info in n64 objects. Again, we should
7740 // just be able to ignore this.
7741 new_flags
&= ~elfcpp::EF_MIPS_UCODE
;
7742 old_flags
&= ~elfcpp::EF_MIPS_UCODE
;
7744 // DSOs should only be linked with CPIC code.
7746 new_flags
|= elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
;
7748 if (new_flags
== old_flags
)
7750 this->set_processor_specific_flags(merged_flags
);
7754 if (((new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0)
7755 != ((old_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0))
7756 gold_warning(_("%s: linking abicalls files with non-abicalls files"),
7759 if (new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
))
7760 merged_flags
|= elfcpp::EF_MIPS_CPIC
;
7761 if (!(new_flags
& elfcpp::EF_MIPS_PIC
))
7762 merged_flags
&= ~elfcpp::EF_MIPS_PIC
;
7764 new_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
7765 old_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
7767 // Compare the ISAs.
7768 if (mips_32bit_flags(old_flags
) != mips_32bit_flags(new_flags
))
7769 gold_error(_("%s: linking 32-bit code with 64-bit code"), name
.c_str());
7770 else if (!this->mips_mach_extends(this->elf_mips_mach(in_flags
), this->mach_
))
7772 // Output ISA isn't the same as, or an extension of, input ISA.
7773 if (this->mips_mach_extends(this->mach_
, this->elf_mips_mach(in_flags
)))
7775 // Copy the architecture info from input object to output. Also copy
7776 // the 32-bit flag (if set) so that we continue to recognise
7777 // output as a 32-bit binary.
7778 this->mach_
= this->elf_mips_mach(in_flags
);
7779 merged_flags
&= ~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
);
7780 merged_flags
|= (new_flags
& (elfcpp::EF_MIPS_ARCH
7781 | elfcpp::EF_MIPS_MACH
| elfcpp::EF_MIPS_32BITMODE
));
7783 // Copy across the ABI flags if output doesn't use them
7784 // and if that was what caused us to treat input object as 32-bit.
7785 if ((old_flags
& elfcpp::EF_MIPS_ABI
) == 0
7786 && this->mips_32bit_flags(new_flags
)
7787 && !this->mips_32bit_flags(new_flags
& ~elfcpp::EF_MIPS_ABI
))
7788 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ABI
;
7791 // The ISAs aren't compatible.
7792 gold_error(_("%s: linking %s module with previous %s modules"),
7793 name
.c_str(), this->elf_mips_mach_name(in_flags
),
7794 this->elf_mips_mach_name(merged_flags
));
7797 new_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
7798 | elfcpp::EF_MIPS_32BITMODE
));
7799 old_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
7800 | elfcpp::EF_MIPS_32BITMODE
));
7802 // Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it does set
7803 // EI_CLASS differently from any 32-bit ABI.
7804 if ((new_flags
& elfcpp::EF_MIPS_ABI
) != (old_flags
& elfcpp::EF_MIPS_ABI
)
7805 || (in_ei_class
!= this->ei_class_
))
7807 // Only error if both are set (to different values).
7808 if (((new_flags
& elfcpp::EF_MIPS_ABI
)
7809 && (old_flags
& elfcpp::EF_MIPS_ABI
))
7810 || (in_ei_class
!= this->ei_class_
))
7811 gold_error(_("%s: ABI mismatch: linking %s module with "
7812 "previous %s modules"), name
.c_str(),
7813 this->elf_mips_abi_name(in_flags
, in_ei_class
),
7814 this->elf_mips_abi_name(merged_flags
, this->ei_class_
));
7816 new_flags
&= ~elfcpp::EF_MIPS_ABI
;
7817 old_flags
&= ~elfcpp::EF_MIPS_ABI
;
7820 // Compare ASEs. Forbid linking MIPS16 and microMIPS ASE modules together
7821 // and allow arbitrary mixing of the remaining ASEs (retain the union).
7822 if ((new_flags
& elfcpp::EF_MIPS_ARCH_ASE
)
7823 != (old_flags
& elfcpp::EF_MIPS_ARCH_ASE
))
7825 int old_micro
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
7826 int new_micro
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
7827 int old_m16
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
7828 int new_m16
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
7829 int micro_mis
= old_m16
&& new_micro
;
7830 int m16_mis
= old_micro
&& new_m16
;
7832 if (m16_mis
|| micro_mis
)
7833 gold_error(_("%s: ASE mismatch: linking %s module with "
7834 "previous %s modules"), name
.c_str(),
7835 m16_mis
? "MIPS16" : "microMIPS",
7836 m16_mis
? "microMIPS" : "MIPS16");
7838 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ARCH_ASE
;
7840 new_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
7841 old_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
7844 // Warn about any other mismatches.
7845 if (new_flags
!= old_flags
)
7846 gold_error(_("%s: uses different e_flags (0x%x) fields than previous "
7847 "modules (0x%x)"), name
.c_str(), new_flags
, old_flags
);
7849 this->set_processor_specific_flags(merged_flags
);
7852 // Adjust ELF file header.
7854 template<int size
, bool big_endian
>
7856 Target_mips
<size
, big_endian
>::do_adjust_elf_header(
7857 unsigned char* view
,
7860 gold_assert(len
== elfcpp::Elf_sizes
<size
>::ehdr_size
);
7862 elfcpp::Ehdr
<size
, big_endian
> ehdr(view
);
7863 unsigned char e_ident
[elfcpp::EI_NIDENT
];
7864 memcpy(e_ident
, ehdr
.get_e_ident(), elfcpp::EI_NIDENT
);
7866 e_ident
[elfcpp::EI_CLASS
] = this->ei_class_
;
7868 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
7869 oehdr
.put_e_ident(e_ident
);
7870 if (this->entry_symbol_is_compressed_
)
7871 oehdr
.put_e_entry(ehdr
.get_e_entry() + 1);
7874 // do_make_elf_object to override the same function in the base class.
7875 // We need to use a target-specific sub-class of
7876 // Sized_relobj_file<size, big_endian> to store Mips specific information.
7877 // Hence we need to have our own ELF object creation.
7879 template<int size
, bool big_endian
>
7881 Target_mips
<size
, big_endian
>::do_make_elf_object(
7882 const std::string
& name
,
7883 Input_file
* input_file
,
7884 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
7886 int et
= ehdr
.get_e_type();
7887 // ET_EXEC files are valid input for --just-symbols/-R,
7888 // and we treat them as relocatable objects.
7889 if (et
== elfcpp::ET_REL
7890 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
7892 Mips_relobj
<size
, big_endian
>* obj
=
7893 new Mips_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
7897 else if (et
== elfcpp::ET_DYN
)
7899 // TODO(sasa): Should we create Mips_dynobj?
7900 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
7904 gold_error(_("%s: unsupported ELF file type %d"),
7910 // Finalize the sections.
7912 template <int size
, bool big_endian
>
7914 Target_mips
<size
, big_endian
>::do_finalize_sections(Layout
* layout
,
7915 const Input_objects
* input_objects
,
7916 Symbol_table
* symtab
)
7918 // Add +1 to MIPS16 and microMIPS init_ and _fini symbols so that DT_INIT and
7919 // DT_FINI have correct values.
7920 Mips_symbol
<size
>* init
= static_cast<Mips_symbol
<size
>*>(
7921 symtab
->lookup(parameters
->options().init()));
7922 if (init
!= NULL
&& (init
->is_mips16() || init
->is_micromips()))
7923 init
->set_value(init
->value() | 1);
7924 Mips_symbol
<size
>* fini
= static_cast<Mips_symbol
<size
>*>(
7925 symtab
->lookup(parameters
->options().fini()));
7926 if (fini
!= NULL
&& (fini
->is_mips16() || fini
->is_micromips()))
7927 fini
->set_value(fini
->value() | 1);
7929 // Check whether the entry symbol is mips16 or micromips. This is needed to
7930 // adjust entry address in ELF header.
7931 Mips_symbol
<size
>* entry
=
7932 static_cast<Mips_symbol
<size
>*>(symtab
->lookup(this->entry_symbol_name()));
7933 this->entry_symbol_is_compressed_
= (entry
!= NULL
&& (entry
->is_mips16()
7934 || entry
->is_micromips()));
7936 if (!parameters
->doing_static_link()
7937 && (strcmp(parameters
->options().hash_style(), "gnu") == 0
7938 || strcmp(parameters
->options().hash_style(), "both") == 0))
7940 // .gnu.hash and the MIPS ABI require .dynsym to be sorted in different
7941 // ways. .gnu.hash needs symbols to be grouped by hash code whereas the
7942 // MIPS ABI requires a mapping between the GOT and the symbol table.
7943 gold_error(".gnu.hash is incompatible with the MIPS ABI");
7946 // Check whether the final section that was scanned has HI16 or GOT16
7947 // relocations without the corresponding LO16 part.
7948 if (this->got16_addends_
.size() > 0)
7949 gold_error("Can't find matching LO16 reloc");
7952 this->set_gp(layout
, symtab
);
7954 // Check for any mips16 stub sections that we can discard.
7955 if (!parameters
->options().relocatable())
7957 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
7958 p
!= input_objects
->relobj_end();
7961 Mips_relobj
<size
, big_endian
>* object
=
7962 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
7963 object
->discard_mips16_stub_sections(symtab
);
7967 // Merge processor-specific flags.
7968 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
7969 p
!= input_objects
->relobj_end();
7972 Mips_relobj
<size
, big_endian
>* relobj
=
7973 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
7975 Input_file::Format format
= relobj
->input_file()->format();
7976 if (format
== Input_file::FORMAT_ELF
)
7978 // Read processor-specific flags in ELF file header.
7979 const unsigned char* pehdr
= relobj
->get_view(
7980 elfcpp::file_header_offset
,
7981 elfcpp::Elf_sizes
<size
>::ehdr_size
,
7984 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
7985 elfcpp::Elf_Word in_flags
= ehdr
.get_e_flags();
7986 unsigned char ei_class
= ehdr
.get_e_ident()[elfcpp::EI_CLASS
];
7988 this->merge_processor_specific_flags(relobj
->name(), in_flags
,
7993 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
7994 p
!= input_objects
->dynobj_end();
7997 Sized_dynobj
<size
, big_endian
>* dynobj
=
7998 static_cast<Sized_dynobj
<size
, big_endian
>*>(*p
);
8000 // Read processor-specific flags.
8001 const unsigned char* pehdr
= dynobj
->get_view(elfcpp::file_header_offset
,
8002 elfcpp::Elf_sizes
<size
>::ehdr_size
,
8005 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
8006 elfcpp::Elf_Word in_flags
= ehdr
.get_e_flags();
8007 unsigned char ei_class
= ehdr
.get_e_ident()[elfcpp::EI_CLASS
];
8009 this->merge_processor_specific_flags(dynobj
->name(), in_flags
, ei_class
,
8013 // Merge .reginfo contents of input objects.
8014 Valtype gprmask
= 0;
8015 Valtype cprmask1
= 0;
8016 Valtype cprmask2
= 0;
8017 Valtype cprmask3
= 0;
8018 Valtype cprmask4
= 0;
8019 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8020 p
!= input_objects
->relobj_end();
8023 Mips_relobj
<size
, big_endian
>* relobj
=
8024 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
8026 gprmask
|= relobj
->gprmask();
8027 cprmask1
|= relobj
->cprmask1();
8028 cprmask2
|= relobj
->cprmask2();
8029 cprmask3
|= relobj
->cprmask3();
8030 cprmask4
|= relobj
->cprmask4();
8033 if (this->plt_
!= NULL
)
8035 // Set final PLT offsets for symbols.
8036 this->plt_section()->set_plt_offsets();
8038 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
8039 // Set STO_MICROMIPS flag if the output has microMIPS code, but only if
8040 // there are no standard PLT entries present.
8041 unsigned char nonvis
= 0;
8042 if (this->is_output_micromips()
8043 && !this->plt_section()->has_standard_entries())
8044 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
8045 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
8046 Symbol_table::PREDEFINED
,
8048 0, 0, elfcpp::STT_FUNC
,
8050 elfcpp::STV_DEFAULT
, nonvis
,
8054 if (this->mips_stubs_
!= NULL
)
8056 // Define _MIPS_STUBS_ at the start of the .MIPS.stubs section.
8057 unsigned char nonvis
= 0;
8058 if (this->is_output_micromips())
8059 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
8060 symtab
->define_in_output_data("_MIPS_STUBS_", NULL
,
8061 Symbol_table::PREDEFINED
,
8063 0, 0, elfcpp::STT_FUNC
,
8065 elfcpp::STV_DEFAULT
, nonvis
,
8069 if (!parameters
->options().relocatable() && !parameters
->doing_static_link())
8070 // In case there is no .got section, create one.
8071 this->got_section(symtab
, layout
);
8073 // Emit any relocs we saved in an attempt to avoid generating COPY
8075 if (this->copy_relocs_
.any_saved_relocs())
8076 this->copy_relocs_
.emit_mips(this->rel_dyn_section(layout
), symtab
, layout
,
8079 // Emit dynamic relocs.
8080 for (typename
std::vector
<Dyn_reloc
>::iterator p
= this->dyn_relocs_
.begin();
8081 p
!= this->dyn_relocs_
.end();
8083 p
->emit(this->rel_dyn_section(layout
), this->got_section(), symtab
);
8085 if (this->has_got_section())
8086 this->got_section()->lay_out_got(layout
, symtab
, input_objects
);
8088 if (this->mips_stubs_
!= NULL
)
8089 this->mips_stubs_
->set_needs_dynsym_value();
8091 // Check for functions that might need $25 to be valid on entry.
8092 // TODO(sasa): Can we do this without iterating over all symbols?
8093 typedef Symbol_visitor_check_symbols
<size
, big_endian
> Symbol_visitor
;
8094 symtab
->for_all_symbols
<size
, Symbol_visitor
>(Symbol_visitor(this, layout
,
8097 // Add NULL segment.
8098 if (!parameters
->options().relocatable())
8099 layout
->make_output_segment(elfcpp::PT_NULL
, 0);
8101 for (Layout::Section_list::const_iterator p
= layout
->section_list().begin();
8102 p
!= layout
->section_list().end();
8105 if ((*p
)->type() == elfcpp::SHT_MIPS_REGINFO
)
8107 Mips_output_section_reginfo
<size
, big_endian
>* reginfo
=
8108 Mips_output_section_reginfo
<size
, big_endian
>::
8109 as_mips_output_section_reginfo(*p
);
8111 reginfo
->set_masks(gprmask
, cprmask1
, cprmask2
, cprmask3
, cprmask4
);
8113 if (!parameters
->options().relocatable())
8115 Output_segment
* reginfo_segment
=
8116 layout
->make_output_segment(elfcpp::PT_MIPS_REGINFO
,
8118 reginfo_segment
->add_output_section_to_nonload(reginfo
,
8124 // Fill in some more dynamic tags.
8125 // TODO(sasa): Add more dynamic tags.
8126 const Reloc_section
* rel_plt
= (this->plt_
== NULL
8127 ? NULL
: this->plt_
->rel_plt());
8128 layout
->add_target_dynamic_tags(true, this->got_
, rel_plt
,
8129 this->rel_dyn_
, true, false);
8131 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
8133 && !parameters
->options().relocatable()
8134 && !parameters
->doing_static_link())
8137 // This element holds a 32-bit version id for the Runtime
8138 // Linker Interface. This will start at integer value 1.
8140 odyn
->add_constant(elfcpp::DT_MIPS_RLD_VERSION
, d_val
);
8143 d_val
= elfcpp::RHF_NOTPOT
;
8144 odyn
->add_constant(elfcpp::DT_MIPS_FLAGS
, d_val
);
8146 // Save layout for using when emiting custom dynamic tags.
8147 this->layout_
= layout
;
8149 // This member holds the base address of the segment.
8150 odyn
->add_custom(elfcpp::DT_MIPS_BASE_ADDRESS
);
8152 // This member holds the number of entries in the .dynsym section.
8153 odyn
->add_custom(elfcpp::DT_MIPS_SYMTABNO
);
8155 // This member holds the index of the first dynamic symbol
8156 // table entry that corresponds to an entry in the global offset table.
8157 odyn
->add_custom(elfcpp::DT_MIPS_GOTSYM
);
8159 // This member holds the number of local GOT entries.
8160 odyn
->add_constant(elfcpp::DT_MIPS_LOCAL_GOTNO
,
8161 this->got_
->get_local_gotno());
8163 if (this->plt_
!= NULL
)
8164 // DT_MIPS_PLTGOT dynamic tag
8165 odyn
->add_section_address(elfcpp::DT_MIPS_PLTGOT
, this->got_plt_
);
8169 // Get the custom dynamic tag value.
8170 template<int size
, bool big_endian
>
8172 Target_mips
<size
, big_endian
>::do_dynamic_tag_custom_value(elfcpp::DT tag
) const
8176 case elfcpp::DT_MIPS_BASE_ADDRESS
:
8178 // The base address of the segment.
8179 // At this point, the segment list has been sorted into final order,
8180 // so just return vaddr of the first readable PT_LOAD segment.
8181 Output_segment
* seg
=
8182 this->layout_
->find_output_segment(elfcpp::PT_LOAD
, elfcpp::PF_R
, 0);
8183 gold_assert(seg
!= NULL
);
8184 return seg
->vaddr();
8187 case elfcpp::DT_MIPS_SYMTABNO
:
8188 // The number of entries in the .dynsym section.
8189 return this->get_dt_mips_symtabno();
8191 case elfcpp::DT_MIPS_GOTSYM
:
8193 // The index of the first dynamic symbol table entry that corresponds
8194 // to an entry in the GOT.
8195 if (this->got_
->first_global_got_dynsym_index() != -1U)
8196 return this->got_
->first_global_got_dynsym_index();
8198 // In case if we don't have global GOT symbols we default to setting
8199 // DT_MIPS_GOTSYM to the same value as DT_MIPS_SYMTABNO.
8200 return this->get_dt_mips_symtabno();
8204 gold_error(_("Unknown dynamic tag 0x%x"), (unsigned int)tag
);
8207 return (unsigned int)-1;
8210 // Relocate section data.
8212 template<int size
, bool big_endian
>
8214 Target_mips
<size
, big_endian
>::relocate_section(
8215 const Relocate_info
<size
, big_endian
>* relinfo
,
8216 unsigned int sh_type
,
8217 const unsigned char* prelocs
,
8219 Output_section
* output_section
,
8220 bool needs_special_offset_handling
,
8221 unsigned char* view
,
8222 Mips_address address
,
8223 section_size_type view_size
,
8224 const Reloc_symbol_changes
* reloc_symbol_changes
)
8226 typedef Target_mips
<size
, big_endian
> Mips
;
8227 typedef typename Target_mips
<size
, big_endian
>::Relocate Mips_relocate
;
8229 if (sh_type
== elfcpp::SHT_REL
)
8230 gold::relocate_section
<size
, big_endian
, Mips
, elfcpp::SHT_REL
,
8231 Mips_relocate
, gold::Default_comdat_behavior
>(
8237 needs_special_offset_handling
,
8241 reloc_symbol_changes
);
8242 else if (sh_type
== elfcpp::SHT_RELA
)
8243 gold::relocate_section
<size
, big_endian
, Mips
, elfcpp::SHT_RELA
,
8244 Mips_relocate
, gold::Default_comdat_behavior
>(
8250 needs_special_offset_handling
,
8254 reloc_symbol_changes
);
8257 // Return the size of a relocation while scanning during a relocatable
8260 template<int size
, bool big_endian
>
8262 Target_mips
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
8263 unsigned int r_type
,
8268 case elfcpp::R_MIPS_NONE
:
8269 case elfcpp::R_MIPS_TLS_DTPMOD64
:
8270 case elfcpp::R_MIPS_TLS_DTPREL64
:
8271 case elfcpp::R_MIPS_TLS_TPREL64
:
8274 case elfcpp::R_MIPS_32
:
8275 case elfcpp::R_MIPS_TLS_DTPMOD32
:
8276 case elfcpp::R_MIPS_TLS_DTPREL32
:
8277 case elfcpp::R_MIPS_TLS_TPREL32
:
8278 case elfcpp::R_MIPS_REL32
:
8279 case elfcpp::R_MIPS_PC32
:
8280 case elfcpp::R_MIPS_GPREL32
:
8281 case elfcpp::R_MIPS_JALR
:
8284 case elfcpp::R_MIPS_16
:
8285 case elfcpp::R_MIPS_HI16
:
8286 case elfcpp::R_MIPS_LO16
:
8287 case elfcpp::R_MIPS_GPREL16
:
8288 case elfcpp::R_MIPS16_HI16
:
8289 case elfcpp::R_MIPS16_LO16
:
8290 case elfcpp::R_MIPS_PC16
:
8291 case elfcpp::R_MIPS_GOT16
:
8292 case elfcpp::R_MIPS16_GOT16
:
8293 case elfcpp::R_MIPS_CALL16
:
8294 case elfcpp::R_MIPS16_CALL16
:
8295 case elfcpp::R_MIPS_GOT_HI16
:
8296 case elfcpp::R_MIPS_CALL_HI16
:
8297 case elfcpp::R_MIPS_GOT_LO16
:
8298 case elfcpp::R_MIPS_CALL_LO16
:
8299 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
8300 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
8301 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
8302 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
8303 case elfcpp::R_MIPS16_GPREL
:
8304 case elfcpp::R_MIPS_GOT_DISP
:
8305 case elfcpp::R_MIPS_LITERAL
:
8306 case elfcpp::R_MIPS_GOT_PAGE
:
8307 case elfcpp::R_MIPS_GOT_OFST
:
8308 case elfcpp::R_MIPS_TLS_GD
:
8309 case elfcpp::R_MIPS_TLS_LDM
:
8310 case elfcpp::R_MIPS_TLS_GOTTPREL
:
8313 // These relocations are not byte sized
8314 case elfcpp::R_MIPS_26
:
8315 case elfcpp::R_MIPS16_26
:
8318 case elfcpp::R_MIPS_COPY
:
8319 case elfcpp::R_MIPS_JUMP_SLOT
:
8320 object
->error(_("unexpected reloc %u in object file"), r_type
);
8324 object
->error(_("unsupported reloc %u in object file"), r_type
);
8329 // Scan the relocs during a relocatable link.
8331 template<int size
, bool big_endian
>
8333 Target_mips
<size
, big_endian
>::scan_relocatable_relocs(
8334 Symbol_table
* symtab
,
8336 Sized_relobj_file
<size
, big_endian
>* object
,
8337 unsigned int data_shndx
,
8338 unsigned int sh_type
,
8339 const unsigned char* prelocs
,
8341 Output_section
* output_section
,
8342 bool needs_special_offset_handling
,
8343 size_t local_symbol_count
,
8344 const unsigned char* plocal_symbols
,
8345 Relocatable_relocs
* rr
)
8347 gold_assert(sh_type
== elfcpp::SHT_REL
);
8349 typedef Mips_scan_relocatable_relocs
<big_endian
, elfcpp::SHT_REL
,
8350 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
8352 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_REL
,
8353 Scan_relocatable_relocs
>(
8361 needs_special_offset_handling
,
8367 // Emit relocations for a section.
8369 template<int size
, bool big_endian
>
8371 Target_mips
<size
, big_endian
>::relocate_relocs(
8372 const Relocate_info
<size
, big_endian
>* relinfo
,
8373 unsigned int sh_type
,
8374 const unsigned char* prelocs
,
8376 Output_section
* output_section
,
8377 typename
elfcpp::Elf_types
<size
>::Elf_Off
8378 offset_in_output_section
,
8379 unsigned char* view
,
8380 Mips_address view_address
,
8381 section_size_type view_size
,
8382 unsigned char* reloc_view
,
8383 section_size_type reloc_view_size
)
8385 gold_assert(sh_type
== elfcpp::SHT_REL
);
8387 gold::relocate_relocs
<size
, big_endian
, elfcpp::SHT_REL
>(
8392 offset_in_output_section
,
8400 // Perform target-specific processing in a relocatable link. This is
8401 // only used if we use the relocation strategy RELOC_SPECIAL.
8403 template<int size
, bool big_endian
>
8405 Target_mips
<size
, big_endian
>::relocate_special_relocatable(
8406 const Relocate_info
<size
, big_endian
>* relinfo
,
8407 unsigned int sh_type
,
8408 const unsigned char* preloc_in
,
8410 Output_section
* output_section
,
8411 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
8412 unsigned char* view
,
8413 Mips_address view_address
,
8415 unsigned char* preloc_out
)
8417 // We can only handle REL type relocation sections.
8418 gold_assert(sh_type
== elfcpp::SHT_REL
);
8420 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
8422 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc_write
8425 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
8427 const Mips_address invalid_address
= static_cast<Mips_address
>(0) - 1;
8429 Mips_relobj
<size
, big_endian
>* object
=
8430 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
8431 const unsigned int local_count
= object
->local_symbol_count();
8433 Reltype
reloc(preloc_in
);
8434 Reltype_write
reloc_write(preloc_out
);
8436 elfcpp::Elf_types
<32>::Elf_WXword r_info
= reloc
.get_r_info();
8437 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
8438 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
8440 // Get the new symbol index.
8441 // We only use RELOC_SPECIAL strategy in local relocations.
8442 gold_assert(r_sym
< local_count
);
8444 // We are adjusting a section symbol. We need to find
8445 // the symbol table index of the section symbol for
8446 // the output section corresponding to input section
8447 // in which this symbol is defined.
8449 unsigned int shndx
= object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
8450 gold_assert(is_ordinary
);
8451 Output_section
* os
= object
->output_section(shndx
);
8452 gold_assert(os
!= NULL
);
8453 gold_assert(os
->needs_symtab_index());
8454 unsigned int new_symndx
= os
->symtab_index();
8456 // Get the new offset--the location in the output section where
8457 // this relocation should be applied.
8459 Mips_address offset
= reloc
.get_r_offset();
8460 Mips_address new_offset
;
8461 if (offset_in_output_section
!= invalid_address
)
8462 new_offset
= offset
+ offset_in_output_section
;
8465 section_offset_type sot_offset
=
8466 convert_types
<section_offset_type
, Mips_address
>(offset
);
8467 section_offset_type new_sot_offset
=
8468 output_section
->output_offset(object
, relinfo
->data_shndx
,
8470 gold_assert(new_sot_offset
!= -1);
8471 new_offset
= new_sot_offset
;
8474 // In an object file, r_offset is an offset within the section.
8475 // In an executable or dynamic object, generated by
8476 // --emit-relocs, r_offset is an absolute address.
8477 if (!parameters
->options().relocatable())
8479 new_offset
+= view_address
;
8480 if (offset_in_output_section
!= invalid_address
)
8481 new_offset
-= offset_in_output_section
;
8484 reloc_write
.put_r_offset(new_offset
);
8485 reloc_write
.put_r_info(elfcpp::elf_r_info
<32>(new_symndx
, r_type
));
8487 // Handle the reloc addend.
8488 // The relocation uses a section symbol in the input file.
8489 // We are adjusting it to use a section symbol in the output
8490 // file. The input section symbol refers to some address in
8491 // the input section. We need the relocation in the output
8492 // file to refer to that same address. This adjustment to
8493 // the addend is the same calculation we use for a simple
8494 // absolute relocation for the input section symbol.
8496 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
8498 unsigned char* paddend
= view
+ offset
;
8499 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
8502 case elfcpp::R_MIPS_26
:
8503 reloc_status
= Reloc_funcs::rel26(paddend
, object
, psymval
,
8504 offset_in_output_section
, true, 0, sh_type
== elfcpp::SHT_REL
, NULL
,
8505 false /*TODO(sasa): cross mode jump*/, r_type
, this->jal_to_bal());
8512 // Report any errors.
8513 switch (reloc_status
)
8515 case Reloc_funcs::STATUS_OKAY
:
8517 case Reloc_funcs::STATUS_OVERFLOW
:
8518 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
8519 _("relocation overflow"));
8521 case Reloc_funcs::STATUS_BAD_RELOC
:
8522 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
8523 _("unexpected opcode while processing relocation"));
8530 // Optimize the TLS relocation type based on what we know about the
8531 // symbol. IS_FINAL is true if the final address of this symbol is
8532 // known at link time.
8534 template<int size
, bool big_endian
>
8535 tls::Tls_optimization
8536 Target_mips
<size
, big_endian
>::optimize_tls_reloc(bool, int)
8538 // FIXME: Currently we do not do any TLS optimization.
8539 return tls::TLSOPT_NONE
;
8542 // Scan a relocation for a local symbol.
8544 template<int size
, bool big_endian
>
8546 Target_mips
<size
, big_endian
>::Scan::local(
8547 Symbol_table
* symtab
,
8549 Target_mips
<size
, big_endian
>* target
,
8550 Sized_relobj_file
<size
, big_endian
>* object
,
8551 unsigned int data_shndx
,
8552 Output_section
* output_section
,
8553 const elfcpp::Rela
<size
, big_endian
>* rela
,
8554 const elfcpp::Rel
<size
, big_endian
>* rel
,
8555 unsigned int rel_type
,
8556 unsigned int r_type
,
8557 const elfcpp::Sym
<size
, big_endian
>& lsym
,
8563 Mips_address r_offset
;
8564 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
;
8565 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
8567 if (rel_type
== elfcpp::SHT_RELA
)
8569 r_offset
= rela
->get_r_offset();
8570 r_info
= rela
->get_r_info();
8571 r_addend
= rela
->get_r_addend();
8575 r_offset
= rel
->get_r_offset();
8576 r_info
= rel
->get_r_info();
8580 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
8581 Mips_relobj
<size
, big_endian
>* mips_obj
=
8582 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
8584 if (mips_obj
->is_mips16_stub_section(data_shndx
))
8586 mips_obj
->get_mips16_stub_section(data_shndx
)
8587 ->new_local_reloc_found(r_type
, r_sym
);
8590 if (r_type
== elfcpp::R_MIPS_NONE
)
8591 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
8595 if (!mips16_call_reloc(r_type
)
8596 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
8597 // This reloc would need to refer to a MIPS16 hard-float stub, if
8598 // there is one. We ignore MIPS16 stub sections and .pdr section when
8599 // looking for relocs that would need to refer to MIPS16 stubs.
8600 mips_obj
->add_local_non_16bit_call(r_sym
);
8602 if (r_type
== elfcpp::R_MIPS16_26
8603 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
8604 mips_obj
->add_local_16bit_call(r_sym
);
8608 case elfcpp::R_MIPS_GOT16
:
8609 case elfcpp::R_MIPS_CALL16
:
8610 case elfcpp::R_MIPS_CALL_HI16
:
8611 case elfcpp::R_MIPS_CALL_LO16
:
8612 case elfcpp::R_MIPS_GOT_HI16
:
8613 case elfcpp::R_MIPS_GOT_LO16
:
8614 case elfcpp::R_MIPS_GOT_PAGE
:
8615 case elfcpp::R_MIPS_GOT_OFST
:
8616 case elfcpp::R_MIPS_GOT_DISP
:
8617 case elfcpp::R_MIPS_TLS_GOTTPREL
:
8618 case elfcpp::R_MIPS_TLS_GD
:
8619 case elfcpp::R_MIPS_TLS_LDM
:
8620 case elfcpp::R_MIPS16_GOT16
:
8621 case elfcpp::R_MIPS16_CALL16
:
8622 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
8623 case elfcpp::R_MIPS16_TLS_GD
:
8624 case elfcpp::R_MIPS16_TLS_LDM
:
8625 case elfcpp::R_MICROMIPS_GOT16
:
8626 case elfcpp::R_MICROMIPS_CALL16
:
8627 case elfcpp::R_MICROMIPS_CALL_HI16
:
8628 case elfcpp::R_MICROMIPS_CALL_LO16
:
8629 case elfcpp::R_MICROMIPS_GOT_HI16
:
8630 case elfcpp::R_MICROMIPS_GOT_LO16
:
8631 case elfcpp::R_MICROMIPS_GOT_PAGE
:
8632 case elfcpp::R_MICROMIPS_GOT_OFST
:
8633 case elfcpp::R_MICROMIPS_GOT_DISP
:
8634 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
8635 case elfcpp::R_MICROMIPS_TLS_GD
:
8636 case elfcpp::R_MICROMIPS_TLS_LDM
:
8637 // We need a GOT section.
8638 target
->got_section(symtab
, layout
);
8645 if (call_lo16_reloc(r_type
)
8646 || got_lo16_reloc(r_type
)
8647 || got_disp_reloc(r_type
))
8649 // We may need a local GOT entry for this relocation. We
8650 // don't count R_MIPS_GOT_PAGE because we can estimate the
8651 // maximum number of pages needed by looking at the size of
8652 // the segment. Similar comments apply to R_MIPS*_GOT16 and
8653 // R_MIPS*_CALL16. We don't count R_MIPS_GOT_HI16, or
8654 // R_MIPS_CALL_HI16 because these are always followed by an
8655 // R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
8656 Mips_output_data_got
<size
, big_endian
>* got
=
8657 target
->got_section(symtab
, layout
);
8658 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
8659 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
, -1U);
8664 case elfcpp::R_MIPS_CALL16
:
8665 case elfcpp::R_MIPS16_CALL16
:
8666 case elfcpp::R_MICROMIPS_CALL16
:
8667 gold_error(_("CALL16 reloc at 0x%lx not against global symbol "),
8668 (unsigned long)r_offset
);
8671 case elfcpp::R_MIPS_GOT_PAGE
:
8672 case elfcpp::R_MICROMIPS_GOT_PAGE
:
8673 case elfcpp::R_MIPS16_GOT16
:
8674 case elfcpp::R_MIPS_GOT16
:
8675 case elfcpp::R_MIPS_GOT_HI16
:
8676 case elfcpp::R_MIPS_GOT_LO16
:
8677 case elfcpp::R_MICROMIPS_GOT16
:
8678 case elfcpp::R_MICROMIPS_GOT_HI16
:
8679 case elfcpp::R_MICROMIPS_GOT_LO16
:
8681 // This relocation needs a page entry in the GOT.
8682 // Get the section contents.
8683 section_size_type view_size
= 0;
8684 const unsigned char* view
= object
->section_contents(data_shndx
,
8688 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
8689 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
8692 if (rel_type
== elfcpp::SHT_REL
&& got16_reloc(r_type
))
8693 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
8694 object
, data_shndx
, r_type
, r_sym
, addend
));
8696 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
, addend
);
8700 case elfcpp::R_MIPS_HI16
:
8701 case elfcpp::R_MIPS16_HI16
:
8702 case elfcpp::R_MICROMIPS_HI16
:
8703 // Record the reloc so that we can check whether the corresponding LO16
8705 if (rel_type
== elfcpp::SHT_REL
)
8706 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
8707 object
, data_shndx
, r_type
, r_sym
, 0));
8710 case elfcpp::R_MIPS_LO16
:
8711 case elfcpp::R_MIPS16_LO16
:
8712 case elfcpp::R_MICROMIPS_LO16
:
8714 if (rel_type
!= elfcpp::SHT_REL
)
8717 // Find corresponding GOT16/HI16 relocation.
8719 // According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
8720 // be immediately following. However, for the IRIX6 ABI, the next
8721 // relocation may be a composed relocation consisting of several
8722 // relocations for the same address. In that case, the R_MIPS_LO16
8723 // relocation may occur as one of these. We permit a similar
8724 // extension in general, as that is useful for GCC.
8726 // In some cases GCC dead code elimination removes the LO16 but
8727 // keeps the corresponding HI16. This is strictly speaking a
8728 // violation of the ABI but not immediately harmful.
8730 typename
std::list
<got16_addend
<size
, big_endian
> >::iterator it
=
8731 target
->got16_addends_
.begin();
8732 while (it
!= target
->got16_addends_
.end())
8734 got16_addend
<size
, big_endian
> _got16_addend
= *it
;
8736 // TODO(sasa): Split got16_addends_ list into two lists - one for
8737 // GOT16 relocs and the other for HI16 relocs.
8739 // Report an error if we find HI16 or GOT16 reloc from the
8740 // previous section without the matching LO16 part.
8741 if (_got16_addend
.object
!= object
8742 || _got16_addend
.shndx
!= data_shndx
)
8744 gold_error("Can't find matching LO16 reloc");
8748 if (_got16_addend
.r_sym
!= r_sym
8749 || !is_matching_lo16_reloc(_got16_addend
.r_type
, r_type
))
8755 // We found a matching HI16 or GOT16 reloc for this LO16 reloc.
8756 // For GOT16, we need to calculate combined addend and record GOT page
8758 if (got16_reloc(_got16_addend
.r_type
))
8761 section_size_type view_size
= 0;
8762 const unsigned char* view
= object
->section_contents(data_shndx
,
8767 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
8768 int32_t addend
= Bits
<16>::sign_extend32(val
& 0xffff);
8770 addend
= (_got16_addend
.addend
<< 16) + addend
;
8771 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
,
8775 it
= target
->got16_addends_
.erase(it
);
8783 case elfcpp::R_MIPS_32
:
8784 case elfcpp::R_MIPS_REL32
:
8785 case elfcpp::R_MIPS_64
:
8787 if (parameters
->options().output_is_position_independent())
8789 // If building a shared library (or a position-independent
8790 // executable), we need to create a dynamic relocation for
8792 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
8793 unsigned int r_sym
= elfcpp::elf_r_sym
<32>(r_info
);
8794 rel_dyn
->add_symbolless_local_addend(object
, r_sym
,
8795 elfcpp::R_MIPS_REL32
,
8796 output_section
, data_shndx
,
8802 case elfcpp::R_MIPS_TLS_GOTTPREL
:
8803 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
8804 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
8805 case elfcpp::R_MIPS_TLS_LDM
:
8806 case elfcpp::R_MIPS16_TLS_LDM
:
8807 case elfcpp::R_MICROMIPS_TLS_LDM
:
8808 case elfcpp::R_MIPS_TLS_GD
:
8809 case elfcpp::R_MIPS16_TLS_GD
:
8810 case elfcpp::R_MICROMIPS_TLS_GD
:
8812 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
8813 bool output_is_shared
= parameters
->options().shared();
8814 const tls::Tls_optimization optimized_type
8815 = Target_mips
<size
, big_endian
>::optimize_tls_reloc(
8816 !output_is_shared
, r_type
);
8819 case elfcpp::R_MIPS_TLS_GD
:
8820 case elfcpp::R_MIPS16_TLS_GD
:
8821 case elfcpp::R_MICROMIPS_TLS_GD
:
8822 if (optimized_type
== tls::TLSOPT_NONE
)
8824 // Create a pair of GOT entries for the module index and
8825 // dtv-relative offset.
8826 Mips_output_data_got
<size
, big_endian
>* got
=
8827 target
->got_section(symtab
, layout
);
8828 unsigned int shndx
= lsym
.get_st_shndx();
8830 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8833 object
->error(_("local symbol %u has bad shndx %u"),
8837 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
8842 // FIXME: TLS optimization not supported yet.
8847 case elfcpp::R_MIPS_TLS_LDM
:
8848 case elfcpp::R_MIPS16_TLS_LDM
:
8849 case elfcpp::R_MICROMIPS_TLS_LDM
:
8850 if (optimized_type
== tls::TLSOPT_NONE
)
8852 // We always record LDM symbols as local with index 0.
8853 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
8859 // FIXME: TLS optimization not supported yet.
8863 case elfcpp::R_MIPS_TLS_GOTTPREL
:
8864 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
8865 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
8866 layout
->set_has_static_tls();
8867 if (optimized_type
== tls::TLSOPT_NONE
)
8869 // Create a GOT entry for the tp-relative offset.
8870 Mips_output_data_got
<size
, big_endian
>* got
=
8871 target
->got_section(symtab
, layout
);
8872 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
8877 // FIXME: TLS optimization not supported yet.
8892 // Refuse some position-dependent relocations when creating a
8893 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
8894 // not PIC, but we can create dynamic relocations and the result
8895 // will be fine. Also do not refuse R_MIPS_LO16, which can be
8896 // combined with R_MIPS_GOT16.
8897 if (parameters
->options().shared())
8901 case elfcpp::R_MIPS16_HI16
:
8902 case elfcpp::R_MIPS_HI16
:
8903 case elfcpp::R_MICROMIPS_HI16
:
8904 // Don't refuse a high part relocation if it's against
8905 // no symbol (e.g. part of a compound relocation).
8911 case elfcpp::R_MIPS16_26
:
8912 case elfcpp::R_MIPS_26
:
8913 case elfcpp::R_MICROMIPS_26_S1
:
8914 gold_error(_("%s: relocation %u against `%s' can not be used when "
8915 "making a shared object; recompile with -fPIC"),
8916 object
->name().c_str(), r_type
, "a local symbol");
8923 template<int size
, bool big_endian
>
8925 Target_mips
<size
, big_endian
>::Scan::local(
8926 Symbol_table
* symtab
,
8928 Target_mips
<size
, big_endian
>* target
,
8929 Sized_relobj_file
<size
, big_endian
>* object
,
8930 unsigned int data_shndx
,
8931 Output_section
* output_section
,
8932 const elfcpp::Rel
<size
, big_endian
>& reloc
,
8933 unsigned int r_type
,
8934 const elfcpp::Sym
<size
, big_endian
>& lsym
,
8947 (const elfcpp::Rela
<size
, big_endian
>*) NULL
,
8951 lsym
, is_discarded
);
8955 template<int size
, bool big_endian
>
8957 Target_mips
<size
, big_endian
>::Scan::local(
8958 Symbol_table
* symtab
,
8960 Target_mips
<size
, big_endian
>* target
,
8961 Sized_relobj_file
<size
, big_endian
>* object
,
8962 unsigned int data_shndx
,
8963 Output_section
* output_section
,
8964 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8965 unsigned int r_type
,
8966 const elfcpp::Sym
<size
, big_endian
>& lsym
,
8980 (const elfcpp::Rel
<size
, big_endian
>*) NULL
,
8983 lsym
, is_discarded
);
8986 // Scan a relocation for a global symbol.
8988 template<int size
, bool big_endian
>
8990 Target_mips
<size
, big_endian
>::Scan::global(
8991 Symbol_table
* symtab
,
8993 Target_mips
<size
, big_endian
>* target
,
8994 Sized_relobj_file
<size
, big_endian
>* object
,
8995 unsigned int data_shndx
,
8996 Output_section
* output_section
,
8997 const elfcpp::Rela
<size
, big_endian
>* rela
,
8998 const elfcpp::Rel
<size
, big_endian
>* rel
,
8999 unsigned int rel_type
,
9000 unsigned int r_type
,
9003 Mips_address r_offset
;
9004 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
;
9005 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
9007 if (rel_type
== elfcpp::SHT_RELA
)
9009 r_offset
= rela
->get_r_offset();
9010 r_info
= rela
->get_r_info();
9011 r_addend
= rela
->get_r_addend();
9015 r_offset
= rel
->get_r_offset();
9016 r_info
= rel
->get_r_info();
9020 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
9021 Mips_relobj
<size
, big_endian
>* mips_obj
=
9022 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
9023 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
9025 if (mips_obj
->is_mips16_stub_section(data_shndx
))
9027 mips_obj
->get_mips16_stub_section(data_shndx
)
9028 ->new_global_reloc_found(r_type
, mips_sym
);
9031 if (r_type
== elfcpp::R_MIPS_NONE
)
9032 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
9036 if (!mips16_call_reloc(r_type
)
9037 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
9038 // This reloc would need to refer to a MIPS16 hard-float stub, if
9039 // there is one. We ignore MIPS16 stub sections and .pdr section when
9040 // looking for relocs that would need to refer to MIPS16 stubs.
9041 mips_sym
->set_need_fn_stub();
9043 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
9044 // section. We check here to avoid creating a dynamic reloc against
9045 // _GLOBAL_OFFSET_TABLE_.
9046 if (!target
->has_got_section()
9047 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9048 target
->got_section(symtab
, layout
);
9050 // We need PLT entries if there are static-only relocations against
9051 // an externally-defined function. This can technically occur for
9052 // shared libraries if there are branches to the symbol, although it
9053 // is unlikely that this will be used in practice due to the short
9054 // ranges involved. It can occur for any relative or absolute relocation
9055 // in executables; in that case, the PLT entry becomes the function's
9056 // canonical address.
9057 bool static_reloc
= false;
9059 // Set CAN_MAKE_DYNAMIC to true if we can convert this
9060 // relocation into a dynamic one.
9061 bool can_make_dynamic
= false;
9064 case elfcpp::R_MIPS_GOT16
:
9065 case elfcpp::R_MIPS_CALL16
:
9066 case elfcpp::R_MIPS_CALL_HI16
:
9067 case elfcpp::R_MIPS_CALL_LO16
:
9068 case elfcpp::R_MIPS_GOT_HI16
:
9069 case elfcpp::R_MIPS_GOT_LO16
:
9070 case elfcpp::R_MIPS_GOT_PAGE
:
9071 case elfcpp::R_MIPS_GOT_OFST
:
9072 case elfcpp::R_MIPS_GOT_DISP
:
9073 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9074 case elfcpp::R_MIPS_TLS_GD
:
9075 case elfcpp::R_MIPS_TLS_LDM
:
9076 case elfcpp::R_MIPS16_GOT16
:
9077 case elfcpp::R_MIPS16_CALL16
:
9078 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9079 case elfcpp::R_MIPS16_TLS_GD
:
9080 case elfcpp::R_MIPS16_TLS_LDM
:
9081 case elfcpp::R_MICROMIPS_GOT16
:
9082 case elfcpp::R_MICROMIPS_CALL16
:
9083 case elfcpp::R_MICROMIPS_CALL_HI16
:
9084 case elfcpp::R_MICROMIPS_CALL_LO16
:
9085 case elfcpp::R_MICROMIPS_GOT_HI16
:
9086 case elfcpp::R_MICROMIPS_GOT_LO16
:
9087 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9088 case elfcpp::R_MICROMIPS_GOT_OFST
:
9089 case elfcpp::R_MICROMIPS_GOT_DISP
:
9090 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9091 case elfcpp::R_MICROMIPS_TLS_GD
:
9092 case elfcpp::R_MICROMIPS_TLS_LDM
:
9093 // We need a GOT section.
9094 target
->got_section(symtab
, layout
);
9097 // This is just a hint; it can safely be ignored. Don't set
9098 // has_static_relocs for the corresponding symbol.
9099 case elfcpp::R_MIPS_JALR
:
9100 case elfcpp::R_MICROMIPS_JALR
:
9103 case elfcpp::R_MIPS_GPREL16
:
9104 case elfcpp::R_MIPS_GPREL32
:
9105 case elfcpp::R_MIPS16_GPREL
:
9106 case elfcpp::R_MICROMIPS_GPREL16
:
9108 // GP-relative relocations always resolve to a definition in a
9109 // regular input file, ignoring the one-definition rule. This is
9110 // important for the GP setup sequence in NewABI code, which
9111 // always resolves to a local function even if other relocations
9112 // against the symbol wouldn't.
9113 //constrain_symbol_p = FALSE;
9116 case elfcpp::R_MIPS_32
:
9117 case elfcpp::R_MIPS_REL32
:
9118 case elfcpp::R_MIPS_64
:
9119 if (parameters
->options().shared()
9120 || strcmp(gsym
->name(), "__gnu_local_gp") != 0)
9122 if (r_type
!= elfcpp::R_MIPS_REL32
)
9124 static_reloc
= true;
9125 mips_sym
->set_pointer_equality_needed();
9127 can_make_dynamic
= true;
9133 // Most static relocations require pointer equality, except
9135 mips_sym
->set_pointer_equality_needed();
9139 case elfcpp::R_MIPS_26
:
9140 case elfcpp::R_MIPS_PC16
:
9141 case elfcpp::R_MIPS16_26
:
9142 case elfcpp::R_MICROMIPS_26_S1
:
9143 case elfcpp::R_MICROMIPS_PC7_S1
:
9144 case elfcpp::R_MICROMIPS_PC10_S1
:
9145 case elfcpp::R_MICROMIPS_PC16_S1
:
9146 case elfcpp::R_MICROMIPS_PC23_S2
:
9147 static_reloc
= true;
9148 mips_sym
->set_has_static_relocs();
9152 // If there are call relocations against an externally-defined symbol,
9153 // see whether we can create a MIPS lazy-binding stub for it. We can
9154 // only do this if all references to the function are through call
9155 // relocations, and in that case, the traditional lazy-binding stubs
9156 // are much more efficient than PLT entries.
9159 case elfcpp::R_MIPS16_CALL16
:
9160 case elfcpp::R_MIPS_CALL16
:
9161 case elfcpp::R_MIPS_CALL_HI16
:
9162 case elfcpp::R_MIPS_CALL_LO16
:
9163 case elfcpp::R_MIPS_JALR
:
9164 case elfcpp::R_MICROMIPS_CALL16
:
9165 case elfcpp::R_MICROMIPS_CALL_HI16
:
9166 case elfcpp::R_MICROMIPS_CALL_LO16
:
9167 case elfcpp::R_MICROMIPS_JALR
:
9168 if (!mips_sym
->no_lazy_stub())
9170 if ((mips_sym
->needs_plt_entry() && mips_sym
->is_from_dynobj())
9171 // Calls from shared objects to undefined symbols of type
9172 // STT_NOTYPE need lazy-binding stub.
9173 || (mips_sym
->is_undefined() && parameters
->options().shared()))
9174 target
->mips_stubs_section(layout
)->make_entry(mips_sym
);
9179 // We must not create a stub for a symbol that has relocations
9180 // related to taking the function's address.
9181 mips_sym
->set_no_lazy_stub();
9182 target
->remove_lazy_stub_entry(mips_sym
);
9187 if (relocation_needs_la25_stub
<size
, big_endian
>(mips_obj
, r_type
,
9188 mips_sym
->is_mips16()))
9189 mips_sym
->set_has_nonpic_branches();
9191 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
9192 // and has a special meaning.
9193 bool gp_disp_against_hi16
= (!mips_obj
->is_newabi()
9194 && strcmp(gsym
->name(), "_gp_disp") == 0
9195 && (hi16_reloc(r_type
) || lo16_reloc(r_type
)));
9196 if (static_reloc
&& gsym
->needs_plt_entry())
9198 target
->make_plt_entry(symtab
, layout
, mips_sym
, r_type
);
9200 // Since this is not a PC-relative relocation, we may be
9201 // taking the address of a function. In that case we need to
9202 // set the entry in the dynamic symbol table to the address of
9204 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
9206 gsym
->set_needs_dynsym_value();
9207 // We distinguish between PLT entries and lazy-binding stubs by
9208 // giving the former an st_other value of STO_MIPS_PLT. Set the
9209 // flag if there are any relocations in the binary where pointer
9210 // equality matters.
9211 if (mips_sym
->pointer_equality_needed())
9212 mips_sym
->set_mips_plt();
9215 if ((static_reloc
|| can_make_dynamic
) && !gp_disp_against_hi16
)
9217 // Absolute addressing relocations.
9218 // Make a dynamic relocation if necessary.
9219 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
9221 if (gsym
->may_need_copy_reloc())
9223 target
->copy_reloc(symtab
, layout
, object
,
9224 data_shndx
, output_section
, gsym
, *rel
);
9226 else if (can_make_dynamic
)
9228 // Create .rel.dyn section.
9229 target
->rel_dyn_section(layout
);
9230 target
->dynamic_reloc(mips_sym
, elfcpp::R_MIPS_REL32
, mips_obj
,
9231 data_shndx
, output_section
, r_offset
);
9234 gold_error(_("non-dynamic relocations refer to dynamic symbol %s"),
9239 bool for_call
= false;
9242 case elfcpp::R_MIPS_CALL16
:
9243 case elfcpp::R_MIPS16_CALL16
:
9244 case elfcpp::R_MICROMIPS_CALL16
:
9245 case elfcpp::R_MIPS_CALL_HI16
:
9246 case elfcpp::R_MIPS_CALL_LO16
:
9247 case elfcpp::R_MICROMIPS_CALL_HI16
:
9248 case elfcpp::R_MICROMIPS_CALL_LO16
:
9252 case elfcpp::R_MIPS16_GOT16
:
9253 case elfcpp::R_MIPS_GOT16
:
9254 case elfcpp::R_MIPS_GOT_HI16
:
9255 case elfcpp::R_MIPS_GOT_LO16
:
9256 case elfcpp::R_MICROMIPS_GOT16
:
9257 case elfcpp::R_MICROMIPS_GOT_HI16
:
9258 case elfcpp::R_MICROMIPS_GOT_LO16
:
9259 case elfcpp::R_MIPS_GOT_DISP
:
9260 case elfcpp::R_MICROMIPS_GOT_DISP
:
9262 // The symbol requires a GOT entry.
9263 Mips_output_data_got
<size
, big_endian
>* got
=
9264 target
->got_section(symtab
, layout
);
9265 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
9267 mips_sym
->set_global_got_area(GGA_NORMAL
);
9271 case elfcpp::R_MIPS_GOT_PAGE
:
9272 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9274 // This relocation needs a page entry in the GOT.
9275 // Get the section contents.
9276 section_size_type view_size
= 0;
9277 const unsigned char* view
=
9278 object
->section_contents(data_shndx
, &view_size
, false);
9281 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
9282 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
9284 Mips_output_data_got
<size
, big_endian
>* got
=
9285 target
->got_section(symtab
, layout
);
9286 got
->record_got_page_entry(mips_obj
, r_sym
, addend
);
9288 // If this is a global, overridable symbol, GOT_PAGE will
9289 // decay to GOT_DISP, so we'll need a GOT entry for it.
9290 bool def_regular
= (mips_sym
->source() == Symbol::FROM_OBJECT
9291 && !mips_sym
->object()->is_dynamic()
9292 && !mips_sym
->is_undefined());
9294 || (parameters
->options().output_is_position_independent()
9295 && !parameters
->options().Bsymbolic()
9296 && !mips_sym
->is_forced_local()))
9298 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
9300 mips_sym
->set_global_got_area(GGA_NORMAL
);
9305 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9306 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9307 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9308 case elfcpp::R_MIPS_TLS_LDM
:
9309 case elfcpp::R_MIPS16_TLS_LDM
:
9310 case elfcpp::R_MICROMIPS_TLS_LDM
:
9311 case elfcpp::R_MIPS_TLS_GD
:
9312 case elfcpp::R_MIPS16_TLS_GD
:
9313 case elfcpp::R_MICROMIPS_TLS_GD
:
9315 const bool is_final
= gsym
->final_value_is_known();
9316 const tls::Tls_optimization optimized_type
=
9317 Target_mips
<size
, big_endian
>::optimize_tls_reloc(is_final
, r_type
);
9321 case elfcpp::R_MIPS_TLS_GD
:
9322 case elfcpp::R_MIPS16_TLS_GD
:
9323 case elfcpp::R_MICROMIPS_TLS_GD
:
9324 if (optimized_type
== tls::TLSOPT_NONE
)
9326 // Create a pair of GOT entries for the module index and
9327 // dtv-relative offset.
9328 Mips_output_data_got
<size
, big_endian
>* got
=
9329 target
->got_section(symtab
, layout
);
9330 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
9335 // FIXME: TLS optimization not supported yet.
9340 case elfcpp::R_MIPS_TLS_LDM
:
9341 case elfcpp::R_MIPS16_TLS_LDM
:
9342 case elfcpp::R_MICROMIPS_TLS_LDM
:
9343 if (optimized_type
== tls::TLSOPT_NONE
)
9345 // We always record LDM symbols as local with index 0.
9346 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
9352 // FIXME: TLS optimization not supported yet.
9356 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9357 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9358 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9359 layout
->set_has_static_tls();
9360 if (optimized_type
== tls::TLSOPT_NONE
)
9362 // Create a GOT entry for the tp-relative offset.
9363 Mips_output_data_got
<size
, big_endian
>* got
=
9364 target
->got_section(symtab
, layout
);
9365 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
9370 // FIXME: TLS optimization not supported yet.
9380 case elfcpp::R_MIPS_COPY
:
9381 case elfcpp::R_MIPS_JUMP_SLOT
:
9382 // These are relocations which should only be seen by the
9383 // dynamic linker, and should never be seen here.
9384 gold_error(_("%s: unexpected reloc %u in object file"),
9385 object
->name().c_str(), r_type
);
9392 // Refuse some position-dependent relocations when creating a
9393 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
9394 // not PIC, but we can create dynamic relocations and the result
9395 // will be fine. Also do not refuse R_MIPS_LO16, which can be
9396 // combined with R_MIPS_GOT16.
9397 if (parameters
->options().shared())
9401 case elfcpp::R_MIPS16_HI16
:
9402 case elfcpp::R_MIPS_HI16
:
9403 case elfcpp::R_MICROMIPS_HI16
:
9404 // Don't refuse a high part relocation if it's against
9405 // no symbol (e.g. part of a compound relocation).
9409 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
9410 // and has a special meaning.
9411 if (!mips_obj
->is_newabi() && strcmp(gsym
->name(), "_gp_disp") == 0)
9416 case elfcpp::R_MIPS16_26
:
9417 case elfcpp::R_MIPS_26
:
9418 case elfcpp::R_MICROMIPS_26_S1
:
9419 gold_error(_("%s: relocation %u against `%s' can not be used when "
9420 "making a shared object; recompile with -fPIC"),
9421 object
->name().c_str(), r_type
, gsym
->name());
9428 template<int size
, bool big_endian
>
9430 Target_mips
<size
, big_endian
>::Scan::global(
9431 Symbol_table
* symtab
,
9433 Target_mips
<size
, big_endian
>* target
,
9434 Sized_relobj_file
<size
, big_endian
>* object
,
9435 unsigned int data_shndx
,
9436 Output_section
* output_section
,
9437 const elfcpp::Rela
<size
, big_endian
>& reloc
,
9438 unsigned int r_type
,
9449 (const elfcpp::Rel
<size
, big_endian
>*) NULL
,
9455 template<int size
, bool big_endian
>
9457 Target_mips
<size
, big_endian
>::Scan::global(
9458 Symbol_table
* symtab
,
9460 Target_mips
<size
, big_endian
>* target
,
9461 Sized_relobj_file
<size
, big_endian
>* object
,
9462 unsigned int data_shndx
,
9463 Output_section
* output_section
,
9464 const elfcpp::Rel
<size
, big_endian
>& reloc
,
9465 unsigned int r_type
,
9475 (const elfcpp::Rela
<size
, big_endian
>*) NULL
,
9482 // Return whether a R_MIPS_32 relocation needs to be applied.
9484 template<int size
, bool big_endian
>
9486 Target_mips
<size
, big_endian
>::Relocate::should_apply_r_mips_32_reloc(
9487 const Mips_symbol
<size
>* gsym
,
9488 unsigned int r_type
,
9489 Output_section
* output_section
,
9490 Target_mips
* target
)
9492 // If the output section is not allocated, then we didn't call
9493 // scan_relocs, we didn't create a dynamic reloc, and we must apply
9495 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
9502 // For global symbols, we use the same helper routines used in the
9504 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
))
9505 && !gsym
->may_need_copy_reloc())
9507 // We have generated dynamic reloc (R_MIPS_REL32).
9509 bool multi_got
= false;
9510 if (target
->has_got_section())
9511 multi_got
= target
->got_section()->multi_got();
9512 bool has_got_offset
;
9514 has_got_offset
= gsym
->has_got_offset(GOT_TYPE_STANDARD
);
9516 has_got_offset
= gsym
->global_gotoffset() != -1U;
9517 if (!has_got_offset
)
9520 // Apply the relocation only if the symbol is in the local got.
9521 // Do not apply the relocation if the symbol is in the global
9523 return symbol_references_local(gsym
, gsym
->has_dynsym_index());
9526 // We have not generated dynamic reloc.
9531 // Perform a relocation.
9533 template<int size
, bool big_endian
>
9535 Target_mips
<size
, big_endian
>::Relocate::relocate(
9536 const Relocate_info
<size
, big_endian
>* relinfo
,
9537 unsigned int rel_type
,
9538 Target_mips
* target
,
9539 Output_section
* output_section
,
9541 const unsigned char* preloc
,
9542 const Sized_symbol
<size
>* gsym
,
9543 const Symbol_value
<size
>* psymval
,
9544 unsigned char* view
,
9545 Mips_address address
,
9548 Mips_address r_offset
;
9549 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
;
9550 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
9552 if (rel_type
== elfcpp::SHT_RELA
)
9554 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
9555 r_offset
= rela
.get_r_offset();
9556 r_info
= rela
.get_r_info();
9557 r_addend
= rela
.get_r_addend();
9561 const elfcpp::Rel
<size
, big_endian
> rel(preloc
);
9562 r_offset
= rel
.get_r_offset();
9563 r_info
= rel
.get_r_info();
9566 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
9568 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
9569 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
9571 Mips_relobj
<size
, big_endian
>* object
=
9572 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
9574 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
9575 bool target_is_16_bit_code
= false;
9576 bool target_is_micromips_code
= false;
9577 bool cross_mode_jump
;
9579 Symbol_value
<size
> symval
;
9581 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
9583 bool changed_symbol_value
= false;
9586 target_is_16_bit_code
= object
->local_symbol_is_mips16(r_sym
);
9587 target_is_micromips_code
= object
->local_symbol_is_micromips(r_sym
);
9588 if (target_is_16_bit_code
|| target_is_micromips_code
)
9590 // MIPS16/microMIPS text labels should be treated as odd.
9591 symval
.set_output_value(psymval
->value(object
, 1));
9593 changed_symbol_value
= true;
9598 target_is_16_bit_code
= mips_sym
->is_mips16();
9599 target_is_micromips_code
= mips_sym
->is_micromips();
9601 // If this is a mips16/microMIPS text symbol, add 1 to the value to make
9602 // it odd. This will cause something like .word SYM to come up with
9603 // the right value when it is loaded into the PC.
9605 if ((mips_sym
->is_mips16() || mips_sym
->is_micromips())
9606 && psymval
->value(object
, 0) != 0)
9608 symval
.set_output_value(psymval
->value(object
, 0) | 1);
9610 changed_symbol_value
= true;
9613 // Pick the value to use for symbols defined in shared objects.
9614 if (mips_sym
->use_plt_offset(Scan::get_reference_flags(r_type
))
9615 || mips_sym
->has_lazy_stub())
9618 if (!mips_sym
->has_lazy_stub())
9620 // Prefer a standard MIPS PLT entry.
9621 if (mips_sym
->has_mips_plt_offset())
9623 value
= target
->plt_section()->mips_entry_address(mips_sym
);
9624 target_is_micromips_code
= false;
9625 target_is_16_bit_code
= false;
9629 value
= (target
->plt_section()->comp_entry_address(mips_sym
)
9631 if (target
->is_output_micromips())
9632 target_is_micromips_code
= true;
9634 target_is_16_bit_code
= true;
9638 value
= target
->mips_stubs_section()->stub_address(mips_sym
);
9640 symval
.set_output_value(value
);
9645 // TRUE if the symbol referred to by this relocation is "_gp_disp".
9646 // Note that such a symbol must always be a global symbol.
9647 bool gp_disp
= (gsym
!= NULL
&& (strcmp(gsym
->name(), "_gp_disp") == 0)
9648 && !object
->is_newabi());
9650 // TRUE if the symbol referred to by this relocation is "__gnu_local_gp".
9651 // Note that such a symbol must always be a global symbol.
9652 bool gnu_local_gp
= gsym
&& (strcmp(gsym
->name(), "__gnu_local_gp") == 0);
9657 if (!hi16_reloc(r_type
) && !lo16_reloc(r_type
))
9658 gold_error_at_location(relinfo
, relnum
, r_offset
,
9659 _("relocations against _gp_disp are permitted only"
9660 " with R_MIPS_HI16 and R_MIPS_LO16 relocations."));
9662 else if (gnu_local_gp
)
9664 // __gnu_local_gp is _gp symbol.
9665 symval
.set_output_value(target
->adjusted_gp_value(object
));
9669 // If this is a reference to a 16-bit function with a stub, we need
9670 // to redirect the relocation to the stub unless:
9672 // (a) the relocation is for a MIPS16 JAL;
9674 // (b) the relocation is for a MIPS16 PIC call, and there are no
9675 // non-MIPS16 uses of the GOT slot; or
9677 // (c) the section allows direct references to MIPS16 functions.
9678 if (r_type
!= elfcpp::R_MIPS16_26
9679 && !parameters
->options().relocatable()
9680 && ((mips_sym
!= NULL
9681 && mips_sym
->has_mips16_fn_stub()
9682 && (r_type
!= elfcpp::R_MIPS16_CALL16
|| mips_sym
->need_fn_stub()))
9683 || (mips_sym
== NULL
9684 && object
->get_local_mips16_fn_stub(r_sym
) != NULL
))
9685 && !object
->section_allows_mips16_refs(relinfo
->data_shndx
))
9687 // This is a 32- or 64-bit call to a 16-bit function. We should
9688 // have already noticed that we were going to need the
9691 if (mips_sym
== NULL
)
9692 value
= object
->get_local_mips16_fn_stub(r_sym
)->output_address();
9695 gold_assert(mips_sym
->need_fn_stub());
9696 if (mips_sym
->has_la25_stub())
9697 value
= target
->la25_stub_section()->stub_address(mips_sym
);
9700 value
= mips_sym
->template
9701 get_mips16_fn_stub
<big_endian
>()->output_address();
9704 symval
.set_output_value(value
);
9706 changed_symbol_value
= true;
9708 // The target is 16-bit, but the stub isn't.
9709 target_is_16_bit_code
= false;
9711 // If this is a MIPS16 call with a stub, that is made through the PLT or
9712 // to a standard MIPS function, we need to redirect the call to the stub.
9713 // Note that we specifically exclude R_MIPS16_CALL16 from this behavior;
9714 // indirect calls should use an indirect stub instead.
9715 else if (r_type
== elfcpp::R_MIPS16_26
&& !parameters
->options().relocatable()
9716 && ((mips_sym
!= NULL
9717 && (mips_sym
->has_mips16_call_stub()
9718 || mips_sym
->has_mips16_call_fp_stub()))
9719 || (mips_sym
== NULL
9720 && object
->get_local_mips16_call_stub(r_sym
) != NULL
))
9721 && ((mips_sym
!= NULL
&& mips_sym
->has_plt_offset())
9722 || !target_is_16_bit_code
))
9724 Mips16_stub_section
<size
, big_endian
>* call_stub
;
9725 if (mips_sym
== NULL
)
9726 call_stub
= object
->get_local_mips16_call_stub(r_sym
);
9729 // If both call_stub and call_fp_stub are defined, we can figure
9730 // out which one to use by checking which one appears in the input
9732 if (mips_sym
->has_mips16_call_stub()
9733 && mips_sym
->has_mips16_call_fp_stub())
9736 for (unsigned int i
= 1; i
< object
->shnum(); ++i
)
9738 if (object
->is_mips16_call_fp_stub_section(i
))
9740 call_stub
= mips_sym
->template
9741 get_mips16_call_fp_stub
<big_endian
>();
9746 if (call_stub
== NULL
)
9748 mips_sym
->template get_mips16_call_stub
<big_endian
>();
9750 else if (mips_sym
->has_mips16_call_stub())
9751 call_stub
= mips_sym
->template get_mips16_call_stub
<big_endian
>();
9753 call_stub
= mips_sym
->template get_mips16_call_fp_stub
<big_endian
>();
9756 symval
.set_output_value(call_stub
->output_address());
9758 changed_symbol_value
= true;
9760 // If this is a direct call to a PIC function, redirect to the
9762 else if (mips_sym
!= NULL
9763 && mips_sym
->has_la25_stub()
9764 && relocation_needs_la25_stub
<size
, big_endian
>(
9765 object
, r_type
, target_is_16_bit_code
))
9767 Mips_address value
= target
->la25_stub_section()->stub_address(mips_sym
);
9768 if (mips_sym
->is_micromips())
9770 symval
.set_output_value(value
);
9773 // For direct MIPS16 and microMIPS calls make sure the compressed PLT
9774 // entry is used if a standard PLT entry has also been made.
9775 else if ((r_type
== elfcpp::R_MIPS16_26
9776 || r_type
== elfcpp::R_MICROMIPS_26_S1
)
9777 && !parameters
->options().relocatable()
9779 && mips_sym
->has_plt_offset()
9780 && mips_sym
->has_comp_plt_offset()
9781 && mips_sym
->has_mips_plt_offset())
9783 Mips_address value
= (target
->plt_section()->comp_entry_address(mips_sym
)
9785 symval
.set_output_value(value
);
9788 target_is_16_bit_code
= !target
->is_output_micromips();
9789 target_is_micromips_code
= target
->is_output_micromips();
9792 // Make sure MIPS16 and microMIPS are not used together.
9793 if ((r_type
== elfcpp::R_MIPS16_26
&& target_is_micromips_code
)
9794 || (micromips_branch_reloc(r_type
) && target_is_16_bit_code
))
9796 gold_error(_("MIPS16 and microMIPS functions cannot call each other"));
9799 // Calls from 16-bit code to 32-bit code and vice versa require the
9800 // mode change. However, we can ignore calls to undefined weak symbols,
9801 // which should never be executed at runtime. This exception is important
9802 // because the assembly writer may have "known" that any definition of the
9803 // symbol would be 16-bit code, and that direct jumps were therefore
9806 (!parameters
->options().relocatable()
9807 && !(gsym
!= NULL
&& gsym
->is_weak_undefined())
9808 && ((r_type
== elfcpp::R_MIPS16_26
&& !target_is_16_bit_code
)
9809 || (r_type
== elfcpp::R_MICROMIPS_26_S1
&& !target_is_micromips_code
)
9810 || ((r_type
== elfcpp::R_MIPS_26
|| r_type
== elfcpp::R_MIPS_JALR
)
9811 && (target_is_16_bit_code
|| target_is_micromips_code
))));
9813 bool local
= (mips_sym
== NULL
9814 || (mips_sym
->got_only_for_calls()
9815 ? symbol_calls_local(mips_sym
, mips_sym
->has_dynsym_index())
9816 : symbol_references_local(mips_sym
,
9817 mips_sym
->has_dynsym_index())));
9819 // Global R_MIPS_GOT_PAGE/R_MICROMIPS_GOT_PAGE relocations are equivalent
9820 // to R_MIPS_GOT_DISP/R_MICROMIPS_GOT_DISP. The addend is applied by the
9821 // corresponding R_MIPS_GOT_OFST/R_MICROMIPS_GOT_OFST.
9822 if (got_page_reloc(r_type
) && !local
)
9823 r_type
= (micromips_reloc(r_type
) ? elfcpp::R_MICROMIPS_GOT_DISP
9824 : elfcpp::R_MIPS_GOT_DISP
);
9826 unsigned int got_offset
= 0;
9829 bool update_got_entry
= false;
9830 bool extract_addend
= rel_type
== elfcpp::SHT_REL
;
9833 case elfcpp::R_MIPS_NONE
:
9835 case elfcpp::R_MIPS_16
:
9836 reloc_status
= Reloc_funcs::rel16(view
, object
, psymval
, r_addend
,
9837 extract_addend
, r_type
);
9840 case elfcpp::R_MIPS_32
:
9841 if (should_apply_r_mips_32_reloc(mips_sym
, r_type
, output_section
,
9843 reloc_status
= Reloc_funcs::rel32(view
, object
, psymval
, r_addend
,
9844 extract_addend
, r_type
);
9845 if (mips_sym
!= NULL
9846 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
9847 && mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
9849 // If mips_sym->has_mips16_fn_stub() is false, symbol value is
9850 // already updated by adding +1.
9851 if (mips_sym
->has_mips16_fn_stub())
9853 gold_assert(mips_sym
->need_fn_stub());
9854 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
9855 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
9857 symval
.set_output_value(fn_stub
->output_address());
9860 got_offset
= mips_sym
->global_gotoffset();
9861 update_got_entry
= true;
9865 case elfcpp::R_MIPS_REL32
:
9868 case elfcpp::R_MIPS_PC32
:
9869 reloc_status
= Reloc_funcs::relpc32(view
, object
, psymval
, address
,
9870 r_addend
, extract_addend
, r_type
);
9873 case elfcpp::R_MIPS16_26
:
9874 // The calculation for R_MIPS16_26 is just the same as for an
9875 // R_MIPS_26. It's only the storage of the relocated field into
9876 // the output file that's different. So, we just fall through to the
9877 // R_MIPS_26 case here.
9878 case elfcpp::R_MIPS_26
:
9879 case elfcpp::R_MICROMIPS_26_S1
:
9880 reloc_status
= Reloc_funcs::rel26(view
, object
, psymval
, address
,
9881 gsym
== NULL
, r_addend
, extract_addend
, gsym
, cross_mode_jump
, r_type
,
9882 target
->jal_to_bal());
9885 case elfcpp::R_MIPS_HI16
:
9886 case elfcpp::R_MIPS16_HI16
:
9887 case elfcpp::R_MICROMIPS_HI16
:
9888 reloc_status
= Reloc_funcs::relhi16(view
, object
, psymval
, r_addend
,
9889 address
, gp_disp
, r_type
, r_sym
,
9893 case elfcpp::R_MIPS_LO16
:
9894 case elfcpp::R_MIPS16_LO16
:
9895 case elfcpp::R_MICROMIPS_LO16
:
9896 case elfcpp::R_MICROMIPS_HI0_LO16
:
9897 reloc_status
= Reloc_funcs::rello16(target
, view
, object
, psymval
,
9898 r_addend
, extract_addend
, address
,
9899 gp_disp
, r_type
, r_sym
);
9902 case elfcpp::R_MIPS_LITERAL
:
9903 case elfcpp::R_MICROMIPS_LITERAL
:
9904 // Because we don't merge literal sections, we can handle this
9905 // just like R_MIPS_GPREL16. In the long run, we should merge
9906 // shared literals, and then we will need to additional work
9911 case elfcpp::R_MIPS_GPREL16
:
9912 case elfcpp::R_MIPS16_GPREL
:
9913 case elfcpp::R_MICROMIPS_GPREL7_S2
:
9914 case elfcpp::R_MICROMIPS_GPREL16
:
9915 reloc_status
= Reloc_funcs::relgprel(view
, object
, psymval
,
9916 target
->adjusted_gp_value(object
),
9917 r_addend
, extract_addend
,
9918 gsym
== NULL
, r_type
);
9921 case elfcpp::R_MIPS_PC16
:
9922 reloc_status
= Reloc_funcs::relpc16(view
, object
, psymval
, address
,
9923 r_addend
, extract_addend
, r_type
);
9925 case elfcpp::R_MICROMIPS_PC7_S1
:
9926 reloc_status
= Reloc_funcs::relmicromips_pc7_s1(view
, object
, psymval
,
9928 extract_addend
, r_type
);
9930 case elfcpp::R_MICROMIPS_PC10_S1
:
9931 reloc_status
= Reloc_funcs::relmicromips_pc10_s1(view
, object
, psymval
,
9933 extract_addend
, r_type
);
9935 case elfcpp::R_MICROMIPS_PC16_S1
:
9936 reloc_status
= Reloc_funcs::relmicromips_pc16_s1(view
, object
, psymval
,
9938 extract_addend
, r_type
);
9940 case elfcpp::R_MIPS_GPREL32
:
9941 reloc_status
= Reloc_funcs::relgprel32(view
, object
, psymval
,
9942 target
->adjusted_gp_value(object
),
9943 r_addend
, extract_addend
, r_type
);
9945 case elfcpp::R_MIPS_GOT_HI16
:
9946 case elfcpp::R_MIPS_CALL_HI16
:
9947 case elfcpp::R_MICROMIPS_GOT_HI16
:
9948 case elfcpp::R_MICROMIPS_CALL_HI16
:
9950 got_offset
= target
->got_section()->got_offset(gsym
, GOT_TYPE_STANDARD
,
9953 got_offset
= target
->got_section()->got_offset(r_sym
, GOT_TYPE_STANDARD
,
9955 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
9956 reloc_status
= Reloc_funcs::relgot_hi16(view
, gp_offset
, r_type
);
9957 update_got_entry
= changed_symbol_value
;
9960 case elfcpp::R_MIPS_GOT_LO16
:
9961 case elfcpp::R_MIPS_CALL_LO16
:
9962 case elfcpp::R_MICROMIPS_GOT_LO16
:
9963 case elfcpp::R_MICROMIPS_CALL_LO16
:
9965 got_offset
= target
->got_section()->got_offset(gsym
, GOT_TYPE_STANDARD
,
9968 got_offset
= target
->got_section()->got_offset(r_sym
, GOT_TYPE_STANDARD
,
9970 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
9971 reloc_status
= Reloc_funcs::relgot_lo16(view
, gp_offset
, r_type
);
9972 update_got_entry
= changed_symbol_value
;
9975 case elfcpp::R_MIPS_GOT_DISP
:
9976 case elfcpp::R_MICROMIPS_GOT_DISP
:
9978 got_offset
= target
->got_section()->got_offset(gsym
, GOT_TYPE_STANDARD
,
9981 got_offset
= target
->got_section()->got_offset(r_sym
, GOT_TYPE_STANDARD
,
9983 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
9984 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, r_type
);
9987 case elfcpp::R_MIPS_CALL16
:
9988 case elfcpp::R_MIPS16_CALL16
:
9989 case elfcpp::R_MICROMIPS_CALL16
:
9990 gold_assert(gsym
!= NULL
);
9991 got_offset
= target
->got_section()->got_offset(gsym
, GOT_TYPE_STANDARD
,
9993 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
9994 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, r_type
);
9995 // TODO(sasa): We should also initialize update_got_entry in other places
9996 // where relgot is called.
9997 update_got_entry
= changed_symbol_value
;
10000 case elfcpp::R_MIPS_GOT16
:
10001 case elfcpp::R_MIPS16_GOT16
:
10002 case elfcpp::R_MICROMIPS_GOT16
:
10005 got_offset
= target
->got_section()->got_offset(gsym
,
10008 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10009 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, r_type
);
10012 reloc_status
= Reloc_funcs::relgot16_local(view
, object
, psymval
,
10013 r_addend
, extract_addend
,
10015 update_got_entry
= changed_symbol_value
;
10018 case elfcpp::R_MIPS_TLS_GD
:
10019 case elfcpp::R_MIPS16_TLS_GD
:
10020 case elfcpp::R_MICROMIPS_TLS_GD
:
10022 got_offset
= target
->got_section()->got_offset(gsym
, GOT_TYPE_TLS_PAIR
,
10025 got_offset
= target
->got_section()->got_offset(r_sym
, GOT_TYPE_TLS_PAIR
,
10027 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10028 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, r_type
);
10031 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10032 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10033 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10035 got_offset
= target
->got_section()->got_offset(gsym
,
10036 GOT_TYPE_TLS_OFFSET
,
10039 got_offset
= target
->got_section()->got_offset(r_sym
,
10040 GOT_TYPE_TLS_OFFSET
,
10042 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10043 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, r_type
);
10046 case elfcpp::R_MIPS_TLS_LDM
:
10047 case elfcpp::R_MIPS16_TLS_LDM
:
10048 case elfcpp::R_MICROMIPS_TLS_LDM
:
10049 // Relocate the field with the offset of the GOT entry for
10050 // the module index.
10051 got_offset
= target
->got_section()->tls_ldm_offset(object
);
10052 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10053 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, r_type
);
10056 case elfcpp::R_MIPS_GOT_PAGE
:
10057 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10058 reloc_status
= Reloc_funcs::relgotpage(target
, view
, object
, psymval
,
10059 r_addend
, extract_addend
, r_type
);
10062 case elfcpp::R_MIPS_GOT_OFST
:
10063 case elfcpp::R_MICROMIPS_GOT_OFST
:
10064 reloc_status
= Reloc_funcs::relgotofst(target
, view
, object
, psymval
,
10065 r_addend
, extract_addend
, local
,
10069 case elfcpp::R_MIPS_JALR
:
10070 case elfcpp::R_MICROMIPS_JALR
:
10071 // This relocation is only a hint. In some cases, we optimize
10072 // it into a bal instruction. But we don't try to optimize
10073 // when the symbol does not resolve locally.
10074 if (gsym
== NULL
|| symbol_calls_local(gsym
, gsym
->has_dynsym_index()))
10075 reloc_status
= Reloc_funcs::reljalr(view
, object
, psymval
, address
,
10076 r_addend
, extract_addend
,
10077 cross_mode_jump
, r_type
,
10078 target
->jalr_to_bal(),
10079 target
->jr_to_b());
10082 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
10083 case elfcpp::R_MIPS16_TLS_DTPREL_HI16
:
10084 case elfcpp::R_MICROMIPS_TLS_DTPREL_HI16
:
10085 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
10086 elfcpp::DTP_OFFSET
, r_addend
,
10087 extract_addend
, r_type
);
10089 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
10090 case elfcpp::R_MIPS16_TLS_DTPREL_LO16
:
10091 case elfcpp::R_MICROMIPS_TLS_DTPREL_LO16
:
10092 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
10093 elfcpp::DTP_OFFSET
, r_addend
,
10094 extract_addend
, r_type
);
10096 case elfcpp::R_MIPS_TLS_DTPREL32
:
10097 case elfcpp::R_MIPS_TLS_DTPREL64
:
10098 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
10099 elfcpp::DTP_OFFSET
, r_addend
,
10100 extract_addend
, r_type
);
10102 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
10103 case elfcpp::R_MIPS16_TLS_TPREL_HI16
:
10104 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
10105 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
10106 elfcpp::TP_OFFSET
, r_addend
,
10107 extract_addend
, r_type
);
10109 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
10110 case elfcpp::R_MIPS16_TLS_TPREL_LO16
:
10111 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
10112 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
10113 elfcpp::TP_OFFSET
, r_addend
,
10114 extract_addend
, r_type
);
10116 case elfcpp::R_MIPS_TLS_TPREL32
:
10117 case elfcpp::R_MIPS_TLS_TPREL64
:
10118 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
10119 elfcpp::TP_OFFSET
, r_addend
,
10120 extract_addend
, r_type
);
10122 case elfcpp::R_MIPS_SUB
:
10123 case elfcpp::R_MICROMIPS_SUB
:
10124 reloc_status
= Reloc_funcs::relsub(view
, object
, psymval
, r_addend
,
10125 extract_addend
, r_type
);
10128 gold_error_at_location(relinfo
, relnum
, r_offset
,
10129 _("unsupported reloc %u"), r_type
);
10133 if (update_got_entry
)
10135 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
10136 if (mips_sym
!= NULL
&& mips_sym
->get_applied_secondary_got_fixup())
10137 got
->update_got_entry(got
->get_primary_got_offset(mips_sym
),
10138 psymval
->value(object
, 0));
10140 got
->update_got_entry(got_offset
, psymval
->value(object
, 0));
10143 // Report any errors.
10144 switch (reloc_status
)
10146 case Reloc_funcs::STATUS_OKAY
:
10148 case Reloc_funcs::STATUS_OVERFLOW
:
10149 gold_error_at_location(relinfo
, relnum
, r_offset
,
10150 _("relocation overflow"));
10152 case Reloc_funcs::STATUS_BAD_RELOC
:
10153 gold_error_at_location(relinfo
, relnum
, r_offset
,
10154 _("unexpected opcode while processing relocation"));
10157 gold_unreachable();
10163 // Get the Reference_flags for a particular relocation.
10165 template<int size
, bool big_endian
>
10167 Target_mips
<size
, big_endian
>::Scan::get_reference_flags(
10168 unsigned int r_type
)
10172 case elfcpp::R_MIPS_NONE
:
10173 // No symbol reference.
10176 case elfcpp::R_MIPS_16
:
10177 case elfcpp::R_MIPS_32
:
10178 case elfcpp::R_MIPS_64
:
10179 case elfcpp::R_MIPS_HI16
:
10180 case elfcpp::R_MIPS_LO16
:
10181 case elfcpp::R_MIPS16_HI16
:
10182 case elfcpp::R_MIPS16_LO16
:
10183 case elfcpp::R_MICROMIPS_HI16
:
10184 case elfcpp::R_MICROMIPS_LO16
:
10185 return Symbol::ABSOLUTE_REF
;
10187 case elfcpp::R_MIPS_26
:
10188 case elfcpp::R_MIPS16_26
:
10189 case elfcpp::R_MICROMIPS_26_S1
:
10190 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
10192 case elfcpp::R_MIPS_GPREL32
:
10193 case elfcpp::R_MIPS_GPREL16
:
10194 case elfcpp::R_MIPS_REL32
:
10195 case elfcpp::R_MIPS16_GPREL
:
10196 return Symbol::RELATIVE_REF
;
10198 case elfcpp::R_MIPS_PC16
:
10199 case elfcpp::R_MIPS_PC32
:
10200 case elfcpp::R_MIPS_JALR
:
10201 case elfcpp::R_MICROMIPS_JALR
:
10202 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
10204 case elfcpp::R_MIPS_GOT16
:
10205 case elfcpp::R_MIPS_CALL16
:
10206 case elfcpp::R_MIPS_GOT_DISP
:
10207 case elfcpp::R_MIPS_GOT_HI16
:
10208 case elfcpp::R_MIPS_GOT_LO16
:
10209 case elfcpp::R_MIPS_CALL_HI16
:
10210 case elfcpp::R_MIPS_CALL_LO16
:
10211 case elfcpp::R_MIPS_LITERAL
:
10212 case elfcpp::R_MIPS_GOT_PAGE
:
10213 case elfcpp::R_MIPS_GOT_OFST
:
10214 case elfcpp::R_MIPS16_GOT16
:
10215 case elfcpp::R_MIPS16_CALL16
:
10216 case elfcpp::R_MICROMIPS_GOT16
:
10217 case elfcpp::R_MICROMIPS_CALL16
:
10218 case elfcpp::R_MICROMIPS_GOT_HI16
:
10219 case elfcpp::R_MICROMIPS_GOT_LO16
:
10220 case elfcpp::R_MICROMIPS_CALL_HI16
:
10221 case elfcpp::R_MICROMIPS_CALL_LO16
:
10222 // Absolute in GOT.
10223 return Symbol::RELATIVE_REF
;
10225 case elfcpp::R_MIPS_TLS_DTPMOD32
:
10226 case elfcpp::R_MIPS_TLS_DTPREL32
:
10227 case elfcpp::R_MIPS_TLS_DTPMOD64
:
10228 case elfcpp::R_MIPS_TLS_DTPREL64
:
10229 case elfcpp::R_MIPS_TLS_GD
:
10230 case elfcpp::R_MIPS_TLS_LDM
:
10231 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
10232 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
10233 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10234 case elfcpp::R_MIPS_TLS_TPREL32
:
10235 case elfcpp::R_MIPS_TLS_TPREL64
:
10236 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
10237 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
10238 case elfcpp::R_MIPS16_TLS_GD
:
10239 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10240 case elfcpp::R_MICROMIPS_TLS_GD
:
10241 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10242 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
10243 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
10244 return Symbol::TLS_REF
;
10246 case elfcpp::R_MIPS_COPY
:
10247 case elfcpp::R_MIPS_JUMP_SLOT
:
10249 gold_unreachable();
10250 // Not expected. We will give an error later.
10255 // Report an unsupported relocation against a local symbol.
10257 template<int size
, bool big_endian
>
10259 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_local(
10260 Sized_relobj_file
<size
, big_endian
>* object
,
10261 unsigned int r_type
)
10263 gold_error(_("%s: unsupported reloc %u against local symbol"),
10264 object
->name().c_str(), r_type
);
10267 // Report an unsupported relocation against a global symbol.
10269 template<int size
, bool big_endian
>
10271 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_global(
10272 Sized_relobj_file
<size
, big_endian
>* object
,
10273 unsigned int r_type
,
10276 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
10277 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
10280 // Return printable name for ABI.
10281 template<int size
, bool big_endian
>
10283 Target_mips
<size
, big_endian
>::elf_mips_abi_name(elfcpp::Elf_Word e_flags
,
10284 unsigned char ei_class
)
10286 switch (e_flags
& elfcpp::EF_MIPS_ABI
)
10289 if ((e_flags
& elfcpp::EF_MIPS_ABI2
) != 0)
10291 else if (elfcpp::abi_64(ei_class
))
10295 case elfcpp::E_MIPS_ABI_O32
:
10297 case elfcpp::E_MIPS_ABI_O64
:
10299 case elfcpp::E_MIPS_ABI_EABI32
:
10301 case elfcpp::E_MIPS_ABI_EABI64
:
10304 return "unknown abi";
10308 template<int size
, bool big_endian
>
10310 Target_mips
<size
, big_endian
>::elf_mips_mach_name(elfcpp::Elf_Word e_flags
)
10312 switch (e_flags
& elfcpp::EF_MIPS_MACH
)
10314 case elfcpp::E_MIPS_MACH_3900
:
10315 return "mips:3900";
10316 case elfcpp::E_MIPS_MACH_4010
:
10317 return "mips:4010";
10318 case elfcpp::E_MIPS_MACH_4100
:
10319 return "mips:4100";
10320 case elfcpp::E_MIPS_MACH_4111
:
10321 return "mips:4111";
10322 case elfcpp::E_MIPS_MACH_4120
:
10323 return "mips:4120";
10324 case elfcpp::E_MIPS_MACH_4650
:
10325 return "mips:4650";
10326 case elfcpp::E_MIPS_MACH_5400
:
10327 return "mips:5400";
10328 case elfcpp::E_MIPS_MACH_5500
:
10329 return "mips:5500";
10330 case elfcpp::E_MIPS_MACH_SB1
:
10332 case elfcpp::E_MIPS_MACH_9000
:
10333 return "mips:9000";
10334 case elfcpp::E_MIPS_MACH_LS2E
:
10335 return "mips:loongson-2e";
10336 case elfcpp::E_MIPS_MACH_LS2F
:
10337 return "mips:loongson-2f";
10338 case elfcpp::E_MIPS_MACH_LS3A
:
10339 return "mips:loongson-3a";
10340 case elfcpp::E_MIPS_MACH_OCTEON
:
10341 return "mips:octeon";
10342 case elfcpp::E_MIPS_MACH_OCTEON2
:
10343 return "mips:octeon2";
10344 case elfcpp::E_MIPS_MACH_XLR
:
10347 switch (e_flags
& elfcpp::EF_MIPS_ARCH
)
10350 case elfcpp::E_MIPS_ARCH_1
:
10351 return "mips:3000";
10353 case elfcpp::E_MIPS_ARCH_2
:
10354 return "mips:6000";
10356 case elfcpp::E_MIPS_ARCH_3
:
10357 return "mips:4000";
10359 case elfcpp::E_MIPS_ARCH_4
:
10360 return "mips:8000";
10362 case elfcpp::E_MIPS_ARCH_5
:
10363 return "mips:mips5";
10365 case elfcpp::E_MIPS_ARCH_32
:
10366 return "mips:isa32";
10368 case elfcpp::E_MIPS_ARCH_64
:
10369 return "mips:isa64";
10371 case elfcpp::E_MIPS_ARCH_32R2
:
10372 return "mips:isa32r2";
10374 case elfcpp::E_MIPS_ARCH_64R2
:
10375 return "mips:isa64r2";
10378 return "unknown CPU";
10381 template<int size
, bool big_endian
>
10382 const Target::Target_info Target_mips
<size
, big_endian
>::mips_info
=
10385 big_endian
, // is_big_endian
10386 elfcpp::EM_MIPS
, // machine_code
10387 true, // has_make_symbol
10388 false, // has_resolve
10389 false, // has_code_fill
10390 true, // is_default_stack_executable
10391 false, // can_icf_inline_merge_sections
10393 "/lib/ld.so.1", // dynamic_linker
10394 0x400000, // default_text_segment_address
10395 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
10396 4 * 1024, // common_pagesize (overridable by -z common-page-size)
10397 false, // isolate_execinstr
10398 0, // rosegment_gap
10399 elfcpp::SHN_UNDEF
, // small_common_shndx
10400 elfcpp::SHN_UNDEF
, // large_common_shndx
10401 0, // small_common_section_flags
10402 0, // large_common_section_flags
10403 NULL
, // attributes_section
10404 NULL
, // attributes_vendor
10405 "__start", // entry_symbol_name
10406 32, // hash_entry_size
10409 template<int size
, bool big_endian
>
10410 class Target_mips_nacl
: public Target_mips
<size
, big_endian
>
10414 : Target_mips
<size
, big_endian
>(&mips_nacl_info
)
10418 static const Target::Target_info mips_nacl_info
;
10421 template<int size
, bool big_endian
>
10422 const Target::Target_info Target_mips_nacl
<size
, big_endian
>::mips_nacl_info
=
10425 big_endian
, // is_big_endian
10426 elfcpp::EM_MIPS
, // machine_code
10427 true, // has_make_symbol
10428 false, // has_resolve
10429 false, // has_code_fill
10430 true, // is_default_stack_executable
10431 false, // can_icf_inline_merge_sections
10433 "/lib/ld.so.1", // dynamic_linker
10434 0x20000, // default_text_segment_address
10435 0x10000, // abi_pagesize (overridable by -z max-page-size)
10436 0x10000, // common_pagesize (overridable by -z common-page-size)
10437 true, // isolate_execinstr
10438 0x10000000, // rosegment_gap
10439 elfcpp::SHN_UNDEF
, // small_common_shndx
10440 elfcpp::SHN_UNDEF
, // large_common_shndx
10441 0, // small_common_section_flags
10442 0, // large_common_section_flags
10443 NULL
, // attributes_section
10444 NULL
, // attributes_vendor
10445 "_start", // entry_symbol_name
10446 32, // hash_entry_size
10449 // Target selector for Mips. Note this is never instantiated directly.
10450 // It's only used in Target_selector_mips_nacl, below.
10452 template<int size
, bool big_endian
>
10453 class Target_selector_mips
: public Target_selector
10456 Target_selector_mips()
10457 : Target_selector(elfcpp::EM_MIPS
, size
, big_endian
,
10459 (big_endian
? "elf64-tradbigmips" : "elf64-tradlittlemips") :
10460 (big_endian
? "elf32-tradbigmips" : "elf32-tradlittlemips")),
10462 (big_endian
? "elf64-tradbigmips" : "elf64-tradlittlemips") :
10463 (big_endian
? "elf32-tradbigmips" : "elf32-tradlittlemips")))
10466 Target
* do_instantiate_target()
10467 { return new Target_mips
<size
, big_endian
>(); }
10470 template<int size
, bool big_endian
>
10471 class Target_selector_mips_nacl
10472 : public Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
10473 Target_mips_nacl
<size
, big_endian
> >
10476 Target_selector_mips_nacl()
10477 : Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
10478 Target_mips_nacl
<size
, big_endian
> >(
10479 // NaCl currently supports only MIPS32 little-endian.
10480 "mipsel", "elf32-tradlittlemips-nacl", "elf32-tradlittlemips-nacl")
10484 Target_selector_mips_nacl
<32, true> target_selector_mips32
;
10485 Target_selector_mips_nacl
<32, false> target_selector_mips32el
;
10486 Target_selector_mips_nacl
<64, true> target_selector_mips64
;
10487 Target_selector_mips_nacl
<64, false> target_selector_mips64el
;
10489 } // End anonymous namespace.