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 // Values found in the r_ssym field of a relocation entry.
136 enum Special_relocation_symbol
138 RSS_UNDEF
= 0, // None - value is zero.
139 RSS_GP
= 1, // Value of GP.
140 RSS_GP0
= 2, // Value of GP in object being relocated.
141 RSS_LOC
= 3 // Address of location being relocated.
144 // Whether the section is readonly.
146 is_readonly_section(Output_section
* output_section
)
148 elfcpp::Elf_Xword section_flags
= output_section
->flags();
149 elfcpp::Elf_Word section_type
= output_section
->type();
151 if (section_type
== elfcpp::SHT_NOBITS
)
154 if (section_flags
& elfcpp::SHF_WRITE
)
160 // Return TRUE if a relocation of type R_TYPE from OBJECT might
161 // require an la25 stub. See also local_pic_function, which determines
162 // whether the destination function ever requires a stub.
163 template<int size
, bool big_endian
>
165 relocation_needs_la25_stub(Mips_relobj
<size
, big_endian
>* object
,
166 unsigned int r_type
, bool target_is_16_bit_code
)
168 // We specifically ignore branches and jumps from EF_PIC objects,
169 // where the onus is on the compiler or programmer to perform any
170 // necessary initialization of $25. Sometimes such initialization
171 // is unnecessary; for example, -mno-shared functions do not use
172 // the incoming value of $25, and may therefore be called directly.
173 if (object
->is_pic())
178 case elfcpp::R_MIPS_26
:
179 case elfcpp::R_MIPS_PC16
:
180 case elfcpp::R_MICROMIPS_26_S1
:
181 case elfcpp::R_MICROMIPS_PC7_S1
:
182 case elfcpp::R_MICROMIPS_PC10_S1
:
183 case elfcpp::R_MICROMIPS_PC16_S1
:
184 case elfcpp::R_MICROMIPS_PC23_S2
:
187 case elfcpp::R_MIPS16_26
:
188 return !target_is_16_bit_code
;
195 // Return true if SYM is a locally-defined PIC function, in the sense
196 // that it or its fn_stub might need $25 to be valid on entry.
197 // Note that MIPS16 functions set up $gp using PC-relative instructions,
198 // so they themselves never need $25 to be valid. Only non-MIPS16
199 // entry points are of interest here.
200 template<int size
, bool big_endian
>
202 local_pic_function(Mips_symbol
<size
>* sym
)
204 bool def_regular
= (sym
->source() == Symbol::FROM_OBJECT
205 && !sym
->object()->is_dynamic()
206 && !sym
->is_undefined());
208 if (sym
->is_defined() && def_regular
)
210 Mips_relobj
<size
, big_endian
>* object
=
211 static_cast<Mips_relobj
<size
, big_endian
>*>(sym
->object());
213 if ((object
->is_pic() || sym
->is_pic())
214 && (!sym
->is_mips16()
215 || (sym
->has_mips16_fn_stub() && sym
->need_fn_stub())))
222 hi16_reloc(int r_type
)
224 return (r_type
== elfcpp::R_MIPS_HI16
225 || r_type
== elfcpp::R_MIPS16_HI16
226 || r_type
== elfcpp::R_MICROMIPS_HI16
);
230 lo16_reloc(int r_type
)
232 return (r_type
== elfcpp::R_MIPS_LO16
233 || r_type
== elfcpp::R_MIPS16_LO16
234 || r_type
== elfcpp::R_MICROMIPS_LO16
);
238 got16_reloc(unsigned int r_type
)
240 return (r_type
== elfcpp::R_MIPS_GOT16
241 || r_type
== elfcpp::R_MIPS16_GOT16
242 || r_type
== elfcpp::R_MICROMIPS_GOT16
);
246 call_lo16_reloc(unsigned int r_type
)
248 return (r_type
== elfcpp::R_MIPS_CALL_LO16
249 || r_type
== elfcpp::R_MICROMIPS_CALL_LO16
);
253 got_lo16_reloc(unsigned int r_type
)
255 return (r_type
== elfcpp::R_MIPS_GOT_LO16
256 || r_type
== elfcpp::R_MICROMIPS_GOT_LO16
);
260 eh_reloc(unsigned int r_type
)
262 return (r_type
== elfcpp::R_MIPS_EH
);
266 got_disp_reloc(unsigned int r_type
)
268 return (r_type
== elfcpp::R_MIPS_GOT_DISP
269 || r_type
== elfcpp::R_MICROMIPS_GOT_DISP
);
273 got_page_reloc(unsigned int r_type
)
275 return (r_type
== elfcpp::R_MIPS_GOT_PAGE
276 || r_type
== elfcpp::R_MICROMIPS_GOT_PAGE
);
280 tls_gd_reloc(unsigned int r_type
)
282 return (r_type
== elfcpp::R_MIPS_TLS_GD
283 || r_type
== elfcpp::R_MIPS16_TLS_GD
284 || r_type
== elfcpp::R_MICROMIPS_TLS_GD
);
288 tls_gottprel_reloc(unsigned int r_type
)
290 return (r_type
== elfcpp::R_MIPS_TLS_GOTTPREL
291 || r_type
== elfcpp::R_MIPS16_TLS_GOTTPREL
292 || r_type
== elfcpp::R_MICROMIPS_TLS_GOTTPREL
);
296 tls_ldm_reloc(unsigned int r_type
)
298 return (r_type
== elfcpp::R_MIPS_TLS_LDM
299 || r_type
== elfcpp::R_MIPS16_TLS_LDM
300 || r_type
== elfcpp::R_MICROMIPS_TLS_LDM
);
304 mips16_call_reloc(unsigned int r_type
)
306 return (r_type
== elfcpp::R_MIPS16_26
307 || r_type
== elfcpp::R_MIPS16_CALL16
);
311 jal_reloc(unsigned int r_type
)
313 return (r_type
== elfcpp::R_MIPS_26
314 || r_type
== elfcpp::R_MIPS16_26
315 || r_type
== elfcpp::R_MICROMIPS_26_S1
);
319 micromips_branch_reloc(unsigned int r_type
)
321 return (r_type
== elfcpp::R_MICROMIPS_26_S1
322 || r_type
== elfcpp::R_MICROMIPS_PC16_S1
323 || r_type
== elfcpp::R_MICROMIPS_PC10_S1
324 || r_type
== elfcpp::R_MICROMIPS_PC7_S1
);
327 // Check if R_TYPE is a MIPS16 reloc.
329 mips16_reloc(unsigned int r_type
)
333 case elfcpp::R_MIPS16_26
:
334 case elfcpp::R_MIPS16_GPREL
:
335 case elfcpp::R_MIPS16_GOT16
:
336 case elfcpp::R_MIPS16_CALL16
:
337 case elfcpp::R_MIPS16_HI16
:
338 case elfcpp::R_MIPS16_LO16
:
339 case elfcpp::R_MIPS16_TLS_GD
:
340 case elfcpp::R_MIPS16_TLS_LDM
:
341 case elfcpp::R_MIPS16_TLS_DTPREL_HI16
:
342 case elfcpp::R_MIPS16_TLS_DTPREL_LO16
:
343 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
344 case elfcpp::R_MIPS16_TLS_TPREL_HI16
:
345 case elfcpp::R_MIPS16_TLS_TPREL_LO16
:
353 // Check if R_TYPE is a microMIPS reloc.
355 micromips_reloc(unsigned int r_type
)
359 case elfcpp::R_MICROMIPS_26_S1
:
360 case elfcpp::R_MICROMIPS_HI16
:
361 case elfcpp::R_MICROMIPS_LO16
:
362 case elfcpp::R_MICROMIPS_GPREL16
:
363 case elfcpp::R_MICROMIPS_LITERAL
:
364 case elfcpp::R_MICROMIPS_GOT16
:
365 case elfcpp::R_MICROMIPS_PC7_S1
:
366 case elfcpp::R_MICROMIPS_PC10_S1
:
367 case elfcpp::R_MICROMIPS_PC16_S1
:
368 case elfcpp::R_MICROMIPS_CALL16
:
369 case elfcpp::R_MICROMIPS_GOT_DISP
:
370 case elfcpp::R_MICROMIPS_GOT_PAGE
:
371 case elfcpp::R_MICROMIPS_GOT_OFST
:
372 case elfcpp::R_MICROMIPS_GOT_HI16
:
373 case elfcpp::R_MICROMIPS_GOT_LO16
:
374 case elfcpp::R_MICROMIPS_SUB
:
375 case elfcpp::R_MICROMIPS_HIGHER
:
376 case elfcpp::R_MICROMIPS_HIGHEST
:
377 case elfcpp::R_MICROMIPS_CALL_HI16
:
378 case elfcpp::R_MICROMIPS_CALL_LO16
:
379 case elfcpp::R_MICROMIPS_SCN_DISP
:
380 case elfcpp::R_MICROMIPS_JALR
:
381 case elfcpp::R_MICROMIPS_HI0_LO16
:
382 case elfcpp::R_MICROMIPS_TLS_GD
:
383 case elfcpp::R_MICROMIPS_TLS_LDM
:
384 case elfcpp::R_MICROMIPS_TLS_DTPREL_HI16
:
385 case elfcpp::R_MICROMIPS_TLS_DTPREL_LO16
:
386 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
387 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
388 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
389 case elfcpp::R_MICROMIPS_GPREL7_S2
:
390 case elfcpp::R_MICROMIPS_PC23_S2
:
399 is_matching_lo16_reloc(unsigned int high_reloc
, unsigned int lo16_reloc
)
403 case elfcpp::R_MIPS_HI16
:
404 case elfcpp::R_MIPS_GOT16
:
405 return lo16_reloc
== elfcpp::R_MIPS_LO16
;
406 case elfcpp::R_MIPS16_HI16
:
407 case elfcpp::R_MIPS16_GOT16
:
408 return lo16_reloc
== elfcpp::R_MIPS16_LO16
;
409 case elfcpp::R_MICROMIPS_HI16
:
410 case elfcpp::R_MICROMIPS_GOT16
:
411 return lo16_reloc
== elfcpp::R_MICROMIPS_LO16
;
417 // This class is used to hold information about one GOT entry.
418 // There are three types of entry:
420 // (1) a SYMBOL + OFFSET address, where SYMBOL is local to an input object
421 // (object != NULL, symndx >= 0, tls_type != GOT_TLS_LDM)
422 // (2) a SYMBOL address, where SYMBOL is not local to an input object
423 // (object != NULL, symndx == -1)
424 // (3) a TLS LDM slot
425 // (object != NULL, symndx == 0, tls_type == GOT_TLS_LDM)
427 template<int size
, bool big_endian
>
430 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
433 Mips_got_entry(Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
,
434 Mips_address addend
, unsigned char tls_type
,
435 unsigned int shndx
, bool is_section_symbol
)
436 : object_(object
), symndx_(symndx
), tls_type_(tls_type
),
437 is_section_symbol_(is_section_symbol
), shndx_(shndx
)
438 { this->d
.addend
= addend
; }
440 Mips_got_entry(Mips_relobj
<size
, big_endian
>* object
, Mips_symbol
<size
>* sym
,
441 unsigned char tls_type
)
442 : object_(object
), symndx_(-1U), tls_type_(tls_type
),
443 is_section_symbol_(false), shndx_(-1U)
444 { this->d
.sym
= sym
; }
446 // Return whether this entry is for a local symbol.
448 is_for_local_symbol() const
449 { return this->symndx_
!= -1U; }
451 // Return whether this entry is for a global symbol.
453 is_for_global_symbol() const
454 { return this->symndx_
== -1U; }
456 // Return the hash of this entry.
460 if (this->tls_type_
== GOT_TLS_LDM
)
461 return this->symndx_
+ (1 << 18);
462 if (this->symndx_
!= -1U)
464 uintptr_t object_id
= reinterpret_cast<uintptr_t>(this->object());
465 return this->symndx_
+ object_id
+ this->d
.addend
;
469 uintptr_t sym_id
= reinterpret_cast<uintptr_t>(this->d
.sym
);
470 return this->symndx_
+ sym_id
;
474 // Return whether this entry is equal to OTHER.
476 equals(Mips_got_entry
<size
, big_endian
>* other
) const
478 if (this->symndx_
!= other
->symndx_
479 || this->tls_type_
!= other
->tls_type_
)
481 if (this->tls_type_
== GOT_TLS_LDM
)
483 if (this->symndx_
!= -1U)
484 return (this->object() == other
->object()
485 && this->d
.addend
== other
->d
.addend
);
487 return this->d
.sym
== other
->d
.sym
;
490 // Return input object that needs this GOT entry.
491 Mips_relobj
<size
, big_endian
>*
494 gold_assert(this->object_
!= NULL
);
495 return this->object_
;
498 // Return local symbol index for local GOT entries.
502 gold_assert(this->symndx_
!= -1U);
503 return this->symndx_
;
506 // Return the relocation addend for local GOT entries.
510 gold_assert(this->symndx_
!= -1U);
511 return this->d
.addend
;
514 // Return global symbol for global GOT entries.
518 gold_assert(this->symndx_
== -1U);
522 // Return whether this is a TLS GOT entry.
525 { return this->tls_type_
!= GOT_TLS_NONE
; }
527 // Return TLS type of this GOT entry.
530 { return this->tls_type_
; }
532 // Return section index of the local symbol for local GOT entries.
535 { return this->shndx_
; }
537 // Return whether this is a STT_SECTION symbol.
539 is_section_symbol() const
540 { return this->is_section_symbol_
; }
543 // The input object that needs the GOT entry.
544 Mips_relobj
<size
, big_endian
>* object_
;
545 // The index of the symbol if we have a local symbol; -1 otherwise.
546 unsigned int symndx_
;
550 // If symndx != -1, the addend of the relocation that should be added to the
553 // If symndx == -1, the global symbol corresponding to this GOT entry. The
554 // symbol's entry is in the local area if mips_sym->global_got_area is
555 // GGA_NONE, otherwise it is in the global area.
556 Mips_symbol
<size
>* sym
;
559 // The TLS type of this GOT entry. An LDM GOT entry will be a local
560 // symbol entry with r_symndx == 0.
561 unsigned char tls_type_
;
563 // Whether this is a STT_SECTION symbol.
564 bool is_section_symbol_
;
566 // For local GOT entries, section index of the local symbol.
570 // Hash for Mips_got_entry.
572 template<int size
, bool big_endian
>
573 class Mips_got_entry_hash
577 operator()(Mips_got_entry
<size
, big_endian
>* entry
) const
578 { return entry
->hash(); }
581 // Equality for Mips_got_entry.
583 template<int size
, bool big_endian
>
584 class Mips_got_entry_eq
588 operator()(Mips_got_entry
<size
, big_endian
>* e1
,
589 Mips_got_entry
<size
, big_endian
>* e2
) const
590 { return e1
->equals(e2
); }
593 // Got_page_range. This class describes a range of addends: [MIN_ADDEND,
594 // MAX_ADDEND]. The instances form a non-overlapping list that is sorted by
595 // increasing MIN_ADDEND.
597 struct Got_page_range
600 : next(NULL
), min_addend(0), max_addend(0)
603 Got_page_range
* next
;
607 // Return the maximum number of GOT page entries required.
610 { return (this->max_addend
- this->min_addend
+ 0x1ffff) >> 16; }
613 // Got_page_entry. This class describes the range of addends that are applied
614 // to page relocations against a given symbol.
616 struct Got_page_entry
619 : object(NULL
), symndx(-1U), ranges(NULL
), num_pages(0)
622 Got_page_entry(Object
* object_
, unsigned int symndx_
)
623 : object(object_
), symndx(symndx_
), ranges(NULL
), num_pages(0)
626 // The input object that needs the GOT page entry.
628 // The index of the symbol, as stored in the relocation r_info.
630 // The ranges for this page entry.
631 Got_page_range
* ranges
;
632 // The maximum number of page entries needed for RANGES.
633 unsigned int num_pages
;
636 // Hash for Got_page_entry.
638 struct Got_page_entry_hash
641 operator()(Got_page_entry
* entry
) const
642 { return reinterpret_cast<uintptr_t>(entry
->object
) + entry
->symndx
; }
645 // Equality for Got_page_entry.
647 struct Got_page_entry_eq
650 operator()(Got_page_entry
* entry1
, Got_page_entry
* entry2
) const
652 return entry1
->object
== entry2
->object
&& entry1
->symndx
== entry2
->symndx
;
656 // This class is used to hold .got information when linking.
658 template<int size
, bool big_endian
>
661 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
662 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
664 typedef Unordered_map
<unsigned int, unsigned int> Got_page_offsets
;
666 // Unordered set of GOT entries.
667 typedef Unordered_set
<Mips_got_entry
<size
, big_endian
>*,
668 Mips_got_entry_hash
<size
, big_endian
>,
669 Mips_got_entry_eq
<size
, big_endian
> > Got_entry_set
;
671 // Unordered set of GOT page entries.
672 typedef Unordered_set
<Got_page_entry
*,
673 Got_page_entry_hash
, Got_page_entry_eq
> Got_page_entry_set
;
677 : local_gotno_(0), page_gotno_(0), global_gotno_(0), reloc_only_gotno_(0),
678 tls_gotno_(0), tls_ldm_offset_(-1U), global_got_symbols_(),
679 got_entries_(), got_page_entries_(), got_page_offset_start_(0),
680 got_page_offset_next_(0), got_page_offsets_(), next_(NULL
), index_(-1U),
684 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
685 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
687 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
688 unsigned int symndx
, Mips_address addend
,
689 unsigned int r_type
, unsigned int shndx
,
690 bool is_section_symbol
);
692 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
693 // in OBJECT. FOR_CALL is true if the caller is only interested in
694 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
697 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
698 Mips_relobj
<size
, big_endian
>* object
,
699 unsigned int r_type
, bool dyn_reloc
, bool for_call
);
701 // Add ENTRY to master GOT and to OBJECT's GOT.
703 record_got_entry(Mips_got_entry
<size
, big_endian
>* entry
,
704 Mips_relobj
<size
, big_endian
>* object
);
706 // Record that OBJECT has a page relocation against symbol SYMNDX and
707 // that ADDEND is the addend for that relocation.
709 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
710 unsigned int symndx
, int addend
);
712 // Create all entries that should be in the local part of the GOT.
714 add_local_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
716 // Create GOT page entries.
718 add_page_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
720 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
722 add_global_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
723 unsigned int non_reloc_only_global_gotno
);
725 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
727 add_reloc_only_entries(Mips_output_data_got
<size
, big_endian
>* got
);
729 // Create TLS GOT entries.
731 add_tls_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
733 // Decide whether the symbol needs an entry in the global part of the primary
734 // GOT, setting global_got_area accordingly. Count the number of global
735 // symbols that are in the primary GOT only because they have dynamic
736 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
738 count_got_symbols(Symbol_table
* symtab
);
740 // Return the offset of GOT page entry for VALUE.
742 get_got_page_offset(Mips_address value
,
743 Mips_output_data_got
<size
, big_endian
>* got
);
745 // Count the number of GOT entries required.
749 // Count the number of GOT entries required by ENTRY. Accumulate the result.
751 count_got_entry(Mips_got_entry
<size
, big_endian
>* entry
);
753 // Add FROM's GOT entries.
755 add_got_entries(Mips_got_info
<size
, big_endian
>* from
);
757 // Add FROM's GOT page entries.
759 add_got_page_entries(Mips_got_info
<size
, big_endian
>* from
);
764 { return ((2 + this->local_gotno_
+ this->page_gotno_
+ this->global_gotno_
765 + this->tls_gotno_
) * size
/8);
768 // Return the number of local GOT entries.
771 { return this->local_gotno_
; }
773 // Return the maximum number of page GOT entries needed.
776 { return this->page_gotno_
; }
778 // Return the number of global GOT entries.
781 { return this->global_gotno_
; }
783 // Set the number of global GOT entries.
785 set_global_gotno(unsigned int global_gotno
)
786 { this->global_gotno_
= global_gotno
; }
788 // Return the number of GGA_RELOC_ONLY global GOT entries.
790 reloc_only_gotno() const
791 { return this->reloc_only_gotno_
; }
793 // Return the number of TLS GOT entries.
796 { return this->tls_gotno_
; }
798 // Return the GOT type for this GOT. Used for multi-GOT links only.
800 multigot_got_type(unsigned int got_type
) const
804 case GOT_TYPE_STANDARD
:
805 return GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
806 case GOT_TYPE_TLS_OFFSET
:
807 return GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
808 case GOT_TYPE_TLS_PAIR
:
809 return GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
815 // Remove lazy-binding stubs for global symbols in this GOT.
817 remove_lazy_stubs(Target_mips
<size
, big_endian
>* target
);
819 // Return offset of this GOT from the start of .got section.
822 { return this->offset_
; }
824 // Set offset of this GOT from the start of .got section.
826 set_offset(unsigned int offset
)
827 { this->offset_
= offset
; }
829 // Set index of this GOT in multi-GOT links.
831 set_index(unsigned int index
)
832 { this->index_
= index
; }
834 // Return next GOT in multi-GOT links.
835 Mips_got_info
<size
, big_endian
>*
837 { return this->next_
; }
839 // Set next GOT in multi-GOT links.
841 set_next(Mips_got_info
<size
, big_endian
>* next
)
842 { this->next_
= next
; }
844 // Return the offset of TLS LDM entry for this GOT.
846 tls_ldm_offset() const
847 { return this->tls_ldm_offset_
; }
849 // Set the offset of TLS LDM entry for this GOT.
851 set_tls_ldm_offset(unsigned int tls_ldm_offset
)
852 { this->tls_ldm_offset_
= tls_ldm_offset
; }
854 Unordered_set
<Mips_symbol
<size
>*>&
856 { return this->global_got_symbols_
; }
858 // Return the GOT_TLS_* type required by relocation type R_TYPE.
860 mips_elf_reloc_tls_type(unsigned int r_type
)
862 if (tls_gd_reloc(r_type
))
865 if (tls_ldm_reloc(r_type
))
868 if (tls_gottprel_reloc(r_type
))
874 // Return the number of GOT slots needed for GOT TLS type TYPE.
876 mips_tls_got_entries(unsigned int type
)
896 // The number of local GOT entries.
897 unsigned int local_gotno_
;
898 // The maximum number of page GOT entries needed.
899 unsigned int page_gotno_
;
900 // The number of global GOT entries.
901 unsigned int global_gotno_
;
902 // The number of global GOT entries that are in the GGA_RELOC_ONLY area.
903 unsigned int reloc_only_gotno_
;
904 // The number of TLS GOT entries.
905 unsigned int tls_gotno_
;
906 // The offset of TLS LDM entry for this GOT.
907 unsigned int tls_ldm_offset_
;
908 // All symbols that have global GOT entry.
909 Unordered_set
<Mips_symbol
<size
>*> global_got_symbols_
;
910 // A hash table holding GOT entries.
911 Got_entry_set got_entries_
;
912 // A hash table of GOT page entries.
913 Got_page_entry_set got_page_entries_
;
914 // The offset of first GOT page entry for this GOT.
915 unsigned int got_page_offset_start_
;
916 // The offset of next available GOT page entry for this GOT.
917 unsigned int got_page_offset_next_
;
918 // A hash table that maps GOT page entry value to the GOT offset where
919 // the entry is located.
920 Got_page_offsets got_page_offsets_
;
921 // In multi-GOT links, a pointer to the next GOT.
922 Mips_got_info
<size
, big_endian
>* next_
;
923 // Index of this GOT in multi-GOT links.
925 // The offset of this GOT in multi-GOT links.
926 unsigned int offset_
;
929 // This is a helper class used during relocation scan. It records GOT16 addend.
931 template<int size
, bool big_endian
>
934 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
936 got16_addend(const Sized_relobj_file
<size
, big_endian
>* _object
,
937 unsigned int _shndx
, unsigned int _r_type
, unsigned int _r_sym
,
938 Mips_address _addend
)
939 : object(_object
), shndx(_shndx
), r_type(_r_type
), r_sym(_r_sym
),
943 const Sized_relobj_file
<size
, big_endian
>* object
;
950 // Mips_symbol class. Holds additional symbol information needed for Mips.
953 class Mips_symbol
: public Sized_symbol
<size
>
957 : need_fn_stub_(false), has_nonpic_branches_(false), la25_stub_offset_(-1U),
958 has_static_relocs_(false), no_lazy_stub_(false), lazy_stub_offset_(0),
959 pointer_equality_needed_(false), global_got_area_(GGA_NONE
),
960 global_gotoffset_(-1U), got_only_for_calls_(true), has_lazy_stub_(false),
961 needs_mips_plt_(false), needs_comp_plt_(false), mips_plt_offset_(-1U),
962 comp_plt_offset_(-1U), mips16_fn_stub_(NULL
), mips16_call_stub_(NULL
),
963 mips16_call_fp_stub_(NULL
), applied_secondary_got_fixup_(false)
966 // Return whether this is a MIPS16 symbol.
970 // (st_other & STO_MIPS16) == STO_MIPS16
971 return ((this->nonvis() & (elfcpp::STO_MIPS16
>> 2))
972 == elfcpp::STO_MIPS16
>> 2);
975 // Return whether this is a microMIPS symbol.
979 // (st_other & STO_MIPS_ISA) == STO_MICROMIPS
980 return ((this->nonvis() & (elfcpp::STO_MIPS_ISA
>> 2))
981 == elfcpp::STO_MICROMIPS
>> 2);
984 // Return whether the symbol needs MIPS16 fn_stub.
987 { return this->need_fn_stub_
; }
989 // Set that the symbol needs MIPS16 fn_stub.
992 { this->need_fn_stub_
= true; }
994 // Return whether this symbol is referenced by branch relocations from
995 // any non-PIC input file.
997 has_nonpic_branches() const
998 { return this->has_nonpic_branches_
; }
1000 // Set that this symbol is referenced by branch relocations from
1001 // any non-PIC input file.
1003 set_has_nonpic_branches()
1004 { this->has_nonpic_branches_
= true; }
1006 // Return the offset of the la25 stub for this symbol from the start of the
1007 // la25 stub section.
1009 la25_stub_offset() const
1010 { return this->la25_stub_offset_
; }
1012 // Set the offset of the la25 stub for this symbol from the start of the
1013 // la25 stub section.
1015 set_la25_stub_offset(unsigned int offset
)
1016 { this->la25_stub_offset_
= offset
; }
1018 // Return whether the symbol has la25 stub. This is true if this symbol is
1019 // for a PIC function, and there are non-PIC branches and jumps to it.
1021 has_la25_stub() const
1022 { return this->la25_stub_offset_
!= -1U; }
1024 // Return whether there is a relocation against this symbol that must be
1025 // resolved by the static linker (that is, the relocation cannot possibly
1026 // be made dynamic).
1028 has_static_relocs() const
1029 { return this->has_static_relocs_
; }
1031 // Set that there is a relocation against this symbol that must be resolved
1032 // by the static linker (that is, the relocation cannot possibly be made
1035 set_has_static_relocs()
1036 { this->has_static_relocs_
= true; }
1038 // Return whether we must not create a lazy-binding stub for this symbol.
1040 no_lazy_stub() const
1041 { return this->no_lazy_stub_
; }
1043 // Set that we must not create a lazy-binding stub for this symbol.
1046 { this->no_lazy_stub_
= true; }
1048 // Return the offset of the lazy-binding stub for this symbol from the start
1049 // of .MIPS.stubs section.
1051 lazy_stub_offset() const
1052 { return this->lazy_stub_offset_
; }
1054 // Set the offset of the lazy-binding stub for this symbol from the start
1055 // of .MIPS.stubs section.
1057 set_lazy_stub_offset(unsigned int offset
)
1058 { this->lazy_stub_offset_
= offset
; }
1060 // Return whether there are any relocations for this symbol where
1061 // pointer equality matters.
1063 pointer_equality_needed() const
1064 { return this->pointer_equality_needed_
; }
1066 // Set that there are relocations for this symbol where pointer equality
1069 set_pointer_equality_needed()
1070 { this->pointer_equality_needed_
= true; }
1072 // Return global GOT area where this symbol in located.
1074 global_got_area() const
1075 { return this->global_got_area_
; }
1077 // Set global GOT area where this symbol in located.
1079 set_global_got_area(Global_got_area global_got_area
)
1080 { this->global_got_area_
= global_got_area
; }
1082 // Return the global GOT offset for this symbol. For multi-GOT links, this
1083 // returns the offset from the start of .got section to the first GOT entry
1084 // for the symbol. Note that in multi-GOT links the symbol can have entry
1085 // in more than one GOT.
1087 global_gotoffset() const
1088 { return this->global_gotoffset_
; }
1090 // Set the global GOT offset for this symbol. Note that in multi-GOT links
1091 // the symbol can have entry in more than one GOT. This method will set
1092 // the offset only if it is less than current offset.
1094 set_global_gotoffset(unsigned int offset
)
1096 if (this->global_gotoffset_
== -1U || offset
< this->global_gotoffset_
)
1097 this->global_gotoffset_
= offset
;
1100 // Return whether all GOT relocations for this symbol are for calls.
1102 got_only_for_calls() const
1103 { return this->got_only_for_calls_
; }
1105 // Set that there is a GOT relocation for this symbol that is not for call.
1107 set_got_not_only_for_calls()
1108 { this->got_only_for_calls_
= false; }
1110 // Return whether this is a PIC symbol.
1114 // (st_other & STO_MIPS_FLAGS) == STO_MIPS_PIC
1115 return ((this->nonvis() & (elfcpp::STO_MIPS_FLAGS
>> 2))
1116 == (elfcpp::STO_MIPS_PIC
>> 2));
1119 // Set the flag in st_other field that marks this symbol as PIC.
1123 if (this->is_mips16())
1124 // (st_other & ~(STO_MIPS16 | STO_MIPS_FLAGS)) | STO_MIPS_PIC
1125 this->set_nonvis((this->nonvis()
1126 & ~((elfcpp::STO_MIPS16
>> 2)
1127 | (elfcpp::STO_MIPS_FLAGS
>> 2)))
1128 | (elfcpp::STO_MIPS_PIC
>> 2));
1130 // (other & ~STO_MIPS_FLAGS) | STO_MIPS_PIC
1131 this->set_nonvis((this->nonvis() & ~(elfcpp::STO_MIPS_FLAGS
>> 2))
1132 | (elfcpp::STO_MIPS_PIC
>> 2));
1135 // Set the flag in st_other field that marks this symbol as PLT.
1139 if (this->is_mips16())
1140 // (st_other & (STO_MIPS16 | ~STO_MIPS_FLAGS)) | STO_MIPS_PLT
1141 this->set_nonvis((this->nonvis()
1142 & ((elfcpp::STO_MIPS16
>> 2)
1143 | ~(elfcpp::STO_MIPS_FLAGS
>> 2)))
1144 | (elfcpp::STO_MIPS_PLT
>> 2));
1147 // (st_other & ~STO_MIPS_FLAGS) | STO_MIPS_PLT
1148 this->set_nonvis((this->nonvis() & ~(elfcpp::STO_MIPS_FLAGS
>> 2))
1149 | (elfcpp::STO_MIPS_PLT
>> 2));
1152 // Downcast a base pointer to a Mips_symbol pointer.
1153 static Mips_symbol
<size
>*
1154 as_mips_sym(Symbol
* sym
)
1155 { return static_cast<Mips_symbol
<size
>*>(sym
); }
1157 // Downcast a base pointer to a Mips_symbol pointer.
1158 static const Mips_symbol
<size
>*
1159 as_mips_sym(const Symbol
* sym
)
1160 { return static_cast<const Mips_symbol
<size
>*>(sym
); }
1162 // Return whether the symbol has lazy-binding stub.
1164 has_lazy_stub() const
1165 { return this->has_lazy_stub_
; }
1167 // Set whether the symbol has lazy-binding stub.
1169 set_has_lazy_stub(bool has_lazy_stub
)
1170 { this->has_lazy_stub_
= has_lazy_stub
; }
1172 // Return whether the symbol needs a standard PLT entry.
1174 needs_mips_plt() const
1175 { return this->needs_mips_plt_
; }
1177 // Set whether the symbol needs a standard PLT entry.
1179 set_needs_mips_plt(bool needs_mips_plt
)
1180 { this->needs_mips_plt_
= needs_mips_plt
; }
1182 // Return whether the symbol needs a compressed (MIPS16 or microMIPS) PLT
1185 needs_comp_plt() const
1186 { return this->needs_comp_plt_
; }
1188 // Set whether the symbol needs a compressed (MIPS16 or microMIPS) PLT entry.
1190 set_needs_comp_plt(bool needs_comp_plt
)
1191 { this->needs_comp_plt_
= needs_comp_plt
; }
1193 // Return standard PLT entry offset, or -1 if none.
1195 mips_plt_offset() const
1196 { return this->mips_plt_offset_
; }
1198 // Set standard PLT entry offset.
1200 set_mips_plt_offset(unsigned int mips_plt_offset
)
1201 { this->mips_plt_offset_
= mips_plt_offset
; }
1203 // Return whether the symbol has standard PLT entry.
1205 has_mips_plt_offset() const
1206 { return this->mips_plt_offset_
!= -1U; }
1208 // Return compressed (MIPS16 or microMIPS) PLT entry offset, or -1 if none.
1210 comp_plt_offset() const
1211 { return this->comp_plt_offset_
; }
1213 // Set compressed (MIPS16 or microMIPS) PLT entry offset.
1215 set_comp_plt_offset(unsigned int comp_plt_offset
)
1216 { this->comp_plt_offset_
= comp_plt_offset
; }
1218 // Return whether the symbol has compressed (MIPS16 or microMIPS) PLT entry.
1220 has_comp_plt_offset() const
1221 { return this->comp_plt_offset_
!= -1U; }
1223 // Return MIPS16 fn stub for a symbol.
1224 template<bool big_endian
>
1225 Mips16_stub_section
<size
, big_endian
>*
1226 get_mips16_fn_stub() const
1228 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(mips16_fn_stub_
);
1231 // Set MIPS16 fn stub for a symbol.
1233 set_mips16_fn_stub(Mips16_stub_section_base
* stub
)
1234 { this->mips16_fn_stub_
= stub
; }
1236 // Return whether symbol has MIPS16 fn stub.
1238 has_mips16_fn_stub() const
1239 { return this->mips16_fn_stub_
!= NULL
; }
1241 // Return MIPS16 call stub for a symbol.
1242 template<bool big_endian
>
1243 Mips16_stub_section
<size
, big_endian
>*
1244 get_mips16_call_stub() const
1246 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(
1250 // Set MIPS16 call stub for a symbol.
1252 set_mips16_call_stub(Mips16_stub_section_base
* stub
)
1253 { this->mips16_call_stub_
= stub
; }
1255 // Return whether symbol has MIPS16 call stub.
1257 has_mips16_call_stub() const
1258 { return this->mips16_call_stub_
!= NULL
; }
1260 // Return MIPS16 call_fp stub for a symbol.
1261 template<bool big_endian
>
1262 Mips16_stub_section
<size
, big_endian
>*
1263 get_mips16_call_fp_stub() const
1265 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(
1266 mips16_call_fp_stub_
);
1269 // Set MIPS16 call_fp stub for a symbol.
1271 set_mips16_call_fp_stub(Mips16_stub_section_base
* stub
)
1272 { this->mips16_call_fp_stub_
= stub
; }
1274 // Return whether symbol has MIPS16 call_fp stub.
1276 has_mips16_call_fp_stub() const
1277 { return this->mips16_call_fp_stub_
!= NULL
; }
1280 get_applied_secondary_got_fixup() const
1281 { return applied_secondary_got_fixup_
; }
1284 set_applied_secondary_got_fixup()
1285 { this->applied_secondary_got_fixup_
= true; }
1288 // Whether the symbol needs MIPS16 fn_stub. This is true if this symbol
1289 // appears in any relocs other than a 16 bit call.
1292 // True if this symbol is referenced by branch relocations from
1293 // any non-PIC input file. This is used to determine whether an
1294 // la25 stub is required.
1295 bool has_nonpic_branches_
;
1297 // The offset of the la25 stub for this symbol from the start of the
1298 // la25 stub section.
1299 unsigned int la25_stub_offset_
;
1301 // True if there is a relocation against this symbol that must be
1302 // resolved by the static linker (that is, the relocation cannot
1303 // possibly be made dynamic).
1304 bool has_static_relocs_
;
1306 // Whether we must not create a lazy-binding stub for this symbol.
1307 // This is true if the symbol has relocations related to taking the
1308 // function's address.
1311 // The offset of the lazy-binding stub for this symbol from the start of
1312 // .MIPS.stubs section.
1313 unsigned int lazy_stub_offset_
;
1315 // True if there are any relocations for this symbol where pointer equality
1317 bool pointer_equality_needed_
;
1319 // Global GOT area where this symbol in located, or GGA_NONE if symbol is not
1320 // in the global part of the GOT.
1321 Global_got_area global_got_area_
;
1323 // The global GOT offset for this symbol. For multi-GOT links, this is offset
1324 // from the start of .got section to the first GOT entry for the symbol.
1325 // Note that in multi-GOT links the symbol can have entry in more than one GOT.
1326 unsigned int global_gotoffset_
;
1328 // Whether all GOT relocations for this symbol are for calls.
1329 bool got_only_for_calls_
;
1330 // Whether the symbol has lazy-binding stub.
1331 bool has_lazy_stub_
;
1332 // Whether the symbol needs a standard PLT entry.
1333 bool needs_mips_plt_
;
1334 // Whether the symbol needs a compressed (MIPS16 or microMIPS) PLT entry.
1335 bool needs_comp_plt_
;
1336 // Standard PLT entry offset, or -1 if none.
1337 unsigned int mips_plt_offset_
;
1338 // Compressed (MIPS16 or microMIPS) PLT entry offset, or -1 if none.
1339 unsigned int comp_plt_offset_
;
1340 // MIPS16 fn stub for a symbol.
1341 Mips16_stub_section_base
* mips16_fn_stub_
;
1342 // MIPS16 call stub for a symbol.
1343 Mips16_stub_section_base
* mips16_call_stub_
;
1344 // MIPS16 call_fp stub for a symbol.
1345 Mips16_stub_section_base
* mips16_call_fp_stub_
;
1347 bool applied_secondary_got_fixup_
;
1350 // Mips16_stub_section class.
1352 // The mips16 compiler uses a couple of special sections to handle
1353 // floating point arguments.
1355 // Section names that look like .mips16.fn.FNNAME contain stubs that
1356 // copy floating point arguments from the fp regs to the gp regs and
1357 // then jump to FNNAME. If any 32 bit function calls FNNAME, the
1358 // call should be redirected to the stub instead. If no 32 bit
1359 // function calls FNNAME, the stub should be discarded. We need to
1360 // consider any reference to the function, not just a call, because
1361 // if the address of the function is taken we will need the stub,
1362 // since the address might be passed to a 32 bit function.
1364 // Section names that look like .mips16.call.FNNAME contain stubs
1365 // that copy floating point arguments from the gp regs to the fp
1366 // regs and then jump to FNNAME. If FNNAME is a 32 bit function,
1367 // then any 16 bit function that calls FNNAME should be redirected
1368 // to the stub instead. If FNNAME is not a 32 bit function, the
1369 // stub should be discarded.
1371 // .mips16.call.fp.FNNAME sections are similar, but contain stubs
1372 // which call FNNAME and then copy the return value from the fp regs
1373 // to the gp regs. These stubs store the return address in $18 while
1374 // calling FNNAME; any function which might call one of these stubs
1375 // must arrange to save $18 around the call. (This case is not
1376 // needed for 32 bit functions that call 16 bit functions, because
1377 // 16 bit functions always return floating point values in both
1378 // $f0/$f1 and $2/$3.)
1380 // Note that in all cases FNNAME might be defined statically.
1381 // Therefore, FNNAME is not used literally. Instead, the relocation
1382 // information will indicate which symbol the section is for.
1384 // We record any stubs that we find in the symbol table.
1386 // TODO(sasa): All mips16 stub sections should be emitted in the .text section.
1388 class Mips16_stub_section_base
{ };
1390 template<int size
, bool big_endian
>
1391 class Mips16_stub_section
: public Mips16_stub_section_base
1393 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1396 Mips16_stub_section(Mips_relobj
<size
, big_endian
>* object
, unsigned int shndx
)
1397 : object_(object
), shndx_(shndx
), r_sym_(0), gsym_(NULL
),
1398 found_r_mips_none_(false)
1400 gold_assert(object
->is_mips16_fn_stub_section(shndx
)
1401 || object
->is_mips16_call_stub_section(shndx
)
1402 || object
->is_mips16_call_fp_stub_section(shndx
));
1405 // Return the object of this stub section.
1406 Mips_relobj
<size
, big_endian
>*
1408 { return this->object_
; }
1410 // Return the size of a section.
1412 section_size() const
1413 { return this->object_
->section_size(this->shndx_
); }
1415 // Return section index of this stub section.
1418 { return this->shndx_
; }
1420 // Return symbol index, if stub is for a local function.
1423 { return this->r_sym_
; }
1425 // Return symbol, if stub is for a global function.
1428 { return this->gsym_
; }
1430 // Return whether stub is for a local function.
1432 is_for_local_function() const
1433 { return this->gsym_
== NULL
; }
1435 // This method is called when a new relocation R_TYPE for local symbol R_SYM
1436 // is found in the stub section. Try to find stub target.
1438 new_local_reloc_found(unsigned int r_type
, unsigned int r_sym
)
1440 // To find target symbol for this stub, trust the first R_MIPS_NONE
1441 // relocation, if any. Otherwise trust the first relocation, whatever
1443 if (this->found_r_mips_none_
)
1445 if (r_type
== elfcpp::R_MIPS_NONE
)
1447 this->r_sym_
= r_sym
;
1449 this->found_r_mips_none_
= true;
1451 else if (!is_target_found())
1452 this->r_sym_
= r_sym
;
1455 // This method is called when a new relocation R_TYPE for global symbol GSYM
1456 // is found in the stub section. Try to find stub target.
1458 new_global_reloc_found(unsigned int r_type
, Mips_symbol
<size
>* gsym
)
1460 // To find target symbol for this stub, trust the first R_MIPS_NONE
1461 // relocation, if any. Otherwise trust the first relocation, whatever
1463 if (this->found_r_mips_none_
)
1465 if (r_type
== elfcpp::R_MIPS_NONE
)
1469 this->found_r_mips_none_
= true;
1471 else if (!is_target_found())
1475 // Return whether we found the stub target.
1477 is_target_found() const
1478 { return this->r_sym_
!= 0 || this->gsym_
!= NULL
; }
1480 // Return whether this is a fn stub.
1483 { return this->object_
->is_mips16_fn_stub_section(this->shndx_
); }
1485 // Return whether this is a call stub.
1487 is_call_stub() const
1488 { return this->object_
->is_mips16_call_stub_section(this->shndx_
); }
1490 // Return whether this is a call_fp stub.
1492 is_call_fp_stub() const
1493 { return this->object_
->is_mips16_call_fp_stub_section(this->shndx_
); }
1495 // Return the output address.
1497 output_address() const
1499 return (this->object_
->output_section(this->shndx_
)->address()
1500 + this->object_
->output_section_offset(this->shndx_
));
1504 // The object of this stub section.
1505 Mips_relobj
<size
, big_endian
>* object_
;
1506 // The section index of this stub section.
1507 unsigned int shndx_
;
1508 // The symbol index, if stub is for a local function.
1509 unsigned int r_sym_
;
1510 // The symbol, if stub is for a global function.
1511 Mips_symbol
<size
>* gsym_
;
1512 // True if we found R_MIPS_NONE relocation in this stub.
1513 bool found_r_mips_none_
;
1516 // Mips_relobj class.
1518 template<int size
, bool big_endian
>
1519 class Mips_relobj
: public Sized_relobj_file
<size
, big_endian
>
1521 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1522 typedef std::map
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>
1523 Mips16_stubs_int_map
;
1524 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1527 Mips_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
1528 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1529 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
1530 processor_specific_flags_(0), local_symbol_is_mips16_(),
1531 local_symbol_is_micromips_(), mips16_stub_sections_(),
1532 local_non_16bit_calls_(), local_16bit_calls_(), local_mips16_fn_stubs_(),
1533 local_mips16_call_stubs_(), gp_(0), got_info_(NULL
),
1534 section_is_mips16_fn_stub_(), section_is_mips16_call_stub_(),
1535 section_is_mips16_call_fp_stub_(), pdr_shndx_(-1U), gprmask_(0),
1536 cprmask1_(0), cprmask2_(0), cprmask3_(0), cprmask4_(0)
1538 this->is_pic_
= (ehdr
.get_e_flags() & elfcpp::EF_MIPS_PIC
) != 0;
1539 this->is_n32_
= elfcpp::abi_n32(ehdr
.get_e_flags());
1540 this->is_n64_
= elfcpp::abi_64(ehdr
.get_e_ident()[elfcpp::EI_CLASS
]);
1546 // Downcast a base pointer to a Mips_relobj pointer. This is
1547 // not type-safe but we only use Mips_relobj not the base class.
1548 static Mips_relobj
<size
, big_endian
>*
1549 as_mips_relobj(Relobj
* relobj
)
1550 { return static_cast<Mips_relobj
<size
, big_endian
>*>(relobj
); }
1552 // Downcast a base pointer to a Mips_relobj pointer. This is
1553 // not type-safe but we only use Mips_relobj not the base class.
1554 static const Mips_relobj
<size
, big_endian
>*
1555 as_mips_relobj(const Relobj
* relobj
)
1556 { return static_cast<const Mips_relobj
<size
, big_endian
>*>(relobj
); }
1558 // Processor-specific flags in ELF file header. This is valid only after
1561 processor_specific_flags() const
1562 { return this->processor_specific_flags_
; }
1564 // Whether a local symbol is MIPS16 symbol. R_SYM is the symbol table
1565 // index. This is only valid after do_count_local_symbol is called.
1567 local_symbol_is_mips16(unsigned int r_sym
) const
1569 gold_assert(r_sym
< this->local_symbol_is_mips16_
.size());
1570 return this->local_symbol_is_mips16_
[r_sym
];
1573 // Whether a local symbol is microMIPS symbol. R_SYM is the symbol table
1574 // index. This is only valid after do_count_local_symbol is called.
1576 local_symbol_is_micromips(unsigned int r_sym
) const
1578 gold_assert(r_sym
< this->local_symbol_is_micromips_
.size());
1579 return this->local_symbol_is_micromips_
[r_sym
];
1582 // Get or create MIPS16 stub section.
1583 Mips16_stub_section
<size
, big_endian
>*
1584 get_mips16_stub_section(unsigned int shndx
)
1586 typename
Mips16_stubs_int_map::const_iterator it
=
1587 this->mips16_stub_sections_
.find(shndx
);
1588 if (it
!= this->mips16_stub_sections_
.end())
1589 return (*it
).second
;
1591 Mips16_stub_section
<size
, big_endian
>* stub_section
=
1592 new Mips16_stub_section
<size
, big_endian
>(this, shndx
);
1593 this->mips16_stub_sections_
.insert(
1594 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1595 stub_section
->shndx(), stub_section
));
1596 return stub_section
;
1599 // Return MIPS16 fn stub section for local symbol R_SYM, or NULL if this
1600 // object doesn't have fn stub for R_SYM.
1601 Mips16_stub_section
<size
, big_endian
>*
1602 get_local_mips16_fn_stub(unsigned int r_sym
) const
1604 typename
Mips16_stubs_int_map::const_iterator it
=
1605 this->local_mips16_fn_stubs_
.find(r_sym
);
1606 if (it
!= this->local_mips16_fn_stubs_
.end())
1607 return (*it
).second
;
1611 // Record that this object has MIPS16 fn stub for local symbol. This method
1612 // is only called if we decided not to discard the stub.
1614 add_local_mips16_fn_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1616 gold_assert(stub
->is_for_local_function());
1617 unsigned int r_sym
= stub
->r_sym();
1618 this->local_mips16_fn_stubs_
.insert(
1619 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1623 // Return MIPS16 call stub section for local symbol R_SYM, or NULL if this
1624 // object doesn't have call stub for R_SYM.
1625 Mips16_stub_section
<size
, big_endian
>*
1626 get_local_mips16_call_stub(unsigned int r_sym
) const
1628 typename
Mips16_stubs_int_map::const_iterator it
=
1629 this->local_mips16_call_stubs_
.find(r_sym
);
1630 if (it
!= this->local_mips16_call_stubs_
.end())
1631 return (*it
).second
;
1635 // Record that this object has MIPS16 call stub for local symbol. This method
1636 // is only called if we decided not to discard the stub.
1638 add_local_mips16_call_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1640 gold_assert(stub
->is_for_local_function());
1641 unsigned int r_sym
= stub
->r_sym();
1642 this->local_mips16_call_stubs_
.insert(
1643 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1647 // Record that we found "non 16-bit" call relocation against local symbol
1648 // SYMNDX. This reloc would need to refer to a MIPS16 fn stub, if there
1651 add_local_non_16bit_call(unsigned int symndx
)
1652 { this->local_non_16bit_calls_
.insert(symndx
); }
1654 // Return true if there is any "non 16-bit" call relocation against local
1655 // symbol SYMNDX in this object.
1657 has_local_non_16bit_call_relocs(unsigned int symndx
)
1659 return (this->local_non_16bit_calls_
.find(symndx
)
1660 != this->local_non_16bit_calls_
.end());
1663 // Record that we found 16-bit call relocation R_MIPS16_26 against local
1664 // symbol SYMNDX. Local MIPS16 call or call_fp stubs will only be needed
1665 // if there is some R_MIPS16_26 relocation that refers to the stub symbol.
1667 add_local_16bit_call(unsigned int symndx
)
1668 { this->local_16bit_calls_
.insert(symndx
); }
1670 // Return true if there is any 16-bit call relocation R_MIPS16_26 against local
1671 // symbol SYMNDX in this object.
1673 has_local_16bit_call_relocs(unsigned int symndx
)
1675 return (this->local_16bit_calls_
.find(symndx
)
1676 != this->local_16bit_calls_
.end());
1679 // Get gp value that was used to create this object.
1682 { return this->gp_
; }
1684 // Return whether the object is a PIC object.
1687 { return this->is_pic_
; }
1689 // Return whether the object uses N32 ABI.
1692 { return this->is_n32_
; }
1694 // Return whether the object uses N64 ABI.
1697 { return this->is_n64_
; }
1699 // Return whether the object uses NewABI conventions.
1702 { return this->is_n32_
|| this->is_n64_
; }
1704 // Return Mips_got_info for this object.
1705 Mips_got_info
<size
, big_endian
>*
1706 get_got_info() const
1707 { return this->got_info_
; }
1709 // Return Mips_got_info for this object. Create new info if it doesn't exist.
1710 Mips_got_info
<size
, big_endian
>*
1711 get_or_create_got_info()
1713 if (!this->got_info_
)
1714 this->got_info_
= new Mips_got_info
<size
, big_endian
>();
1715 return this->got_info_
;
1718 // Set Mips_got_info for this object.
1720 set_got_info(Mips_got_info
<size
, big_endian
>* got_info
)
1721 { this->got_info_
= got_info
; }
1723 // Whether a section SHDNX is a MIPS16 stub section. This is only valid
1724 // after do_read_symbols is called.
1726 is_mips16_stub_section(unsigned int shndx
)
1728 return (is_mips16_fn_stub_section(shndx
)
1729 || is_mips16_call_stub_section(shndx
)
1730 || is_mips16_call_fp_stub_section(shndx
));
1733 // Return TRUE if relocations in section SHNDX can refer directly to a
1734 // MIPS16 function rather than to a hard-float stub. This is only valid
1735 // after do_read_symbols is called.
1737 section_allows_mips16_refs(unsigned int shndx
)
1739 return (this->is_mips16_stub_section(shndx
) || shndx
== this->pdr_shndx_
);
1742 // Whether a section SHDNX is a MIPS16 fn stub section. This is only valid
1743 // after do_read_symbols is called.
1745 is_mips16_fn_stub_section(unsigned int shndx
)
1747 gold_assert(shndx
< this->section_is_mips16_fn_stub_
.size());
1748 return this->section_is_mips16_fn_stub_
[shndx
];
1751 // Whether a section SHDNX is a MIPS16 call stub section. This is only valid
1752 // after do_read_symbols is called.
1754 is_mips16_call_stub_section(unsigned int shndx
)
1756 gold_assert(shndx
< this->section_is_mips16_call_stub_
.size());
1757 return this->section_is_mips16_call_stub_
[shndx
];
1760 // Whether a section SHDNX is a MIPS16 call_fp stub section. This is only
1761 // valid after do_read_symbols is called.
1763 is_mips16_call_fp_stub_section(unsigned int shndx
)
1765 gold_assert(shndx
< this->section_is_mips16_call_fp_stub_
.size());
1766 return this->section_is_mips16_call_fp_stub_
[shndx
];
1769 // Discard MIPS16 stub secions that are not needed.
1771 discard_mips16_stub_sections(Symbol_table
* symtab
);
1773 // Return gprmask from the .reginfo section of this object.
1776 { return this->gprmask_
; }
1778 // Return cprmask1 from the .reginfo section of this object.
1781 { return this->cprmask1_
; }
1783 // Return cprmask2 from the .reginfo section of this object.
1786 { return this->cprmask2_
; }
1788 // Return cprmask3 from the .reginfo section of this object.
1791 { return this->cprmask3_
; }
1793 // Return cprmask4 from the .reginfo section of this object.
1796 { return this->cprmask4_
; }
1799 // Count the local symbols.
1801 do_count_local_symbols(Stringpool_template
<char>*,
1802 Stringpool_template
<char>*);
1804 // Read the symbol information.
1806 do_read_symbols(Read_symbols_data
* sd
);
1809 // The name of the options section.
1810 const char* mips_elf_options_section_name()
1811 { return this->is_newabi() ? ".MIPS.options" : ".options"; }
1813 // processor-specific flags in ELF file header.
1814 elfcpp::Elf_Word processor_specific_flags_
;
1816 // Bit vector to tell if a local symbol is a MIPS16 symbol or not.
1817 // This is only valid after do_count_local_symbol is called.
1818 std::vector
<bool> local_symbol_is_mips16_
;
1820 // Bit vector to tell if a local symbol is a microMIPS symbol or not.
1821 // This is only valid after do_count_local_symbol is called.
1822 std::vector
<bool> local_symbol_is_micromips_
;
1824 // Map from section index to the MIPS16 stub for that section. This contains
1825 // all stubs found in this object.
1826 Mips16_stubs_int_map mips16_stub_sections_
;
1828 // Local symbols that have "non 16-bit" call relocation. This relocation
1829 // would need to refer to a MIPS16 fn stub, if there is one.
1830 std::set
<unsigned int> local_non_16bit_calls_
;
1832 // Local symbols that have 16-bit call relocation R_MIPS16_26. Local MIPS16
1833 // call or call_fp stubs will only be needed if there is some R_MIPS16_26
1834 // relocation that refers to the stub symbol.
1835 std::set
<unsigned int> local_16bit_calls_
;
1837 // Map from local symbol index to the MIPS16 fn stub for that symbol.
1838 // This contains only the stubs that we decided not to discard.
1839 Mips16_stubs_int_map local_mips16_fn_stubs_
;
1841 // Map from local symbol index to the MIPS16 call stub for that symbol.
1842 // This contains only the stubs that we decided not to discard.
1843 Mips16_stubs_int_map local_mips16_call_stubs_
;
1845 // gp value that was used to create this object.
1847 // Whether the object is a PIC object.
1849 // Whether the object uses N32 ABI.
1851 // Whether the object uses N64 ABI.
1853 // The Mips_got_info for this object.
1854 Mips_got_info
<size
, big_endian
>* got_info_
;
1856 // Bit vector to tell if a section is a MIPS16 fn stub section or not.
1857 // This is only valid after do_read_symbols is called.
1858 std::vector
<bool> section_is_mips16_fn_stub_
;
1860 // Bit vector to tell if a section is a MIPS16 call stub section or not.
1861 // This is only valid after do_read_symbols is called.
1862 std::vector
<bool> section_is_mips16_call_stub_
;
1864 // Bit vector to tell if a section is a MIPS16 call_fp stub section or not.
1865 // This is only valid after do_read_symbols is called.
1866 std::vector
<bool> section_is_mips16_call_fp_stub_
;
1868 // .pdr section index.
1869 unsigned int pdr_shndx_
;
1871 // gprmask from the .reginfo section of this object.
1873 // cprmask1 from the .reginfo section of this object.
1875 // cprmask2 from the .reginfo section of this object.
1877 // cprmask3 from the .reginfo section of this object.
1879 // cprmask4 from the .reginfo section of this object.
1883 // Mips_output_data_got class.
1885 template<int size
, bool big_endian
>
1886 class Mips_output_data_got
: public Output_data_got
<size
, big_endian
>
1888 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1889 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
1891 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1894 Mips_output_data_got(Target_mips
<size
, big_endian
>* target
,
1895 Symbol_table
* symtab
, Layout
* layout
)
1896 : Output_data_got
<size
, big_endian
>(), target_(target
),
1897 symbol_table_(symtab
), layout_(layout
), static_relocs_(), got_view_(NULL
),
1898 first_global_got_dynsym_index_(-1U), primary_got_(NULL
),
1899 secondary_got_relocs_()
1901 this->master_got_info_
= new Mips_got_info
<size
, big_endian
>();
1902 this->set_addralign(16);
1905 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
1906 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
1908 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
1909 unsigned int symndx
, Mips_address addend
,
1910 unsigned int r_type
, unsigned int shndx
,
1911 bool is_section_symbol
)
1913 this->master_got_info_
->record_local_got_symbol(object
, symndx
, addend
,
1918 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
1919 // in OBJECT. FOR_CALL is true if the caller is only interested in
1920 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
1923 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
1924 Mips_relobj
<size
, big_endian
>* object
,
1925 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
1927 this->master_got_info_
->record_global_got_symbol(mips_sym
, object
, r_type
,
1928 dyn_reloc
, for_call
);
1931 // Record that OBJECT has a page relocation against symbol SYMNDX and
1932 // that ADDEND is the addend for that relocation.
1934 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
1935 unsigned int symndx
, int addend
)
1936 { this->master_got_info_
->record_got_page_entry(object
, symndx
, addend
); }
1938 // Add a static entry for the GOT entry at OFFSET. GSYM is a global
1939 // symbol and R_TYPE is the code of a dynamic relocation that needs to be
1940 // applied in a static link.
1942 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
1943 Mips_symbol
<size
>* gsym
)
1944 { this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, gsym
)); }
1946 // Add a static reloc for the GOT entry at OFFSET. RELOBJ is an object
1947 // defining a local symbol with INDEX. R_TYPE is the code of a dynamic
1948 // relocation that needs to be applied in a static link.
1950 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
1951 Sized_relobj_file
<size
, big_endian
>* relobj
,
1954 this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, relobj
,
1958 // Record that global symbol GSYM has R_TYPE dynamic relocation in the
1959 // secondary GOT at OFFSET.
1961 add_secondary_got_reloc(unsigned int got_offset
, unsigned int r_type
,
1962 Mips_symbol
<size
>* gsym
)
1964 this->secondary_got_relocs_
.push_back(Static_reloc(got_offset
,
1968 // Update GOT entry at OFFSET with VALUE.
1970 update_got_entry(unsigned int offset
, Mips_address value
)
1972 elfcpp::Swap
<size
, big_endian
>::writeval(this->got_view_
+ offset
, value
);
1975 // Return the number of entries in local part of the GOT. This includes
1976 // local entries, page entries and 2 reserved entries.
1978 get_local_gotno() const
1980 if (!this->multi_got())
1982 return (2 + this->master_got_info_
->local_gotno()
1983 + this->master_got_info_
->page_gotno());
1986 return 2 + this->primary_got_
->local_gotno() + this->primary_got_
->page_gotno();
1989 // Return dynamic symbol table index of the first symbol with global GOT
1992 first_global_got_dynsym_index() const
1993 { return this->first_global_got_dynsym_index_
; }
1995 // Set dynamic symbol table index of the first symbol with global GOT entry.
1997 set_first_global_got_dynsym_index(unsigned int index
)
1998 { this->first_global_got_dynsym_index_
= index
; }
2000 // Lay out the GOT. Add local, global and TLS entries. If GOT is
2001 // larger than 64K, create multi-GOT.
2003 lay_out_got(Layout
* layout
, Symbol_table
* symtab
,
2004 const Input_objects
* input_objects
);
2006 // Create multi-GOT. For every GOT, add local, global and TLS entries.
2008 lay_out_multi_got(Layout
* layout
, const Input_objects
* input_objects
);
2010 // Attempt to merge GOTs of different input objects.
2012 merge_gots(const Input_objects
* input_objects
);
2014 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
2015 // this would lead to overflow, true if they were merged successfully.
2017 merge_got_with(Mips_got_info
<size
, big_endian
>* from
,
2018 Mips_relobj
<size
, big_endian
>* object
,
2019 Mips_got_info
<size
, big_endian
>* to
);
2021 // Return the offset of GOT page entry for VALUE. For multi-GOT links,
2022 // use OBJECT's GOT.
2024 get_got_page_offset(Mips_address value
,
2025 const Mips_relobj
<size
, big_endian
>* object
)
2027 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2028 ? this->master_got_info_
2029 : object
->get_got_info());
2030 gold_assert(g
!= NULL
);
2031 return g
->get_got_page_offset(value
, this);
2034 // Return the GOT offset of type GOT_TYPE of the global symbol
2035 // GSYM. For multi-GOT links, use OBJECT's GOT.
2036 unsigned int got_offset(const Symbol
* gsym
, unsigned int got_type
,
2037 Mips_relobj
<size
, big_endian
>* object
) const
2039 if (!this->multi_got())
2040 return gsym
->got_offset(got_type
);
2043 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
2044 gold_assert(g
!= NULL
);
2045 return gsym
->got_offset(g
->multigot_got_type(got_type
));
2049 // Return the GOT offset of type GOT_TYPE of the local symbol
2052 got_offset(unsigned int symndx
, unsigned int got_type
,
2053 Sized_relobj_file
<size
, big_endian
>* object
,
2054 uint64_t addend
) const
2055 { return object
->local_got_offset(symndx
, got_type
, addend
); }
2057 // Return the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2059 tls_ldm_offset(Mips_relobj
<size
, big_endian
>* object
) const
2061 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2062 ? this->master_got_info_
2063 : object
->get_got_info());
2064 gold_assert(g
!= NULL
);
2065 return g
->tls_ldm_offset();
2068 // Set the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2070 set_tls_ldm_offset(unsigned int tls_ldm_offset
,
2071 Mips_relobj
<size
, big_endian
>* object
)
2073 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2074 ? this->master_got_info_
2075 : object
->get_got_info());
2076 gold_assert(g
!= NULL
);
2077 g
->set_tls_ldm_offset(tls_ldm_offset
);
2080 // Return true for multi-GOT links.
2083 { return this->primary_got_
!= NULL
; }
2085 // Return the offset of OBJECT's GOT from the start of .got section.
2087 get_got_offset(const Mips_relobj
<size
, big_endian
>* object
)
2089 if (!this->multi_got())
2093 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
2094 return g
!= NULL
? g
->offset() : 0;
2098 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
2100 add_reloc_only_entries()
2101 { this->master_got_info_
->add_reloc_only_entries(this); }
2103 // Return offset of the primary GOT's entry for global symbol.
2105 get_primary_got_offset(const Mips_symbol
<size
>* sym
) const
2107 gold_assert(sym
->global_got_area() != GGA_NONE
);
2108 return (this->get_local_gotno() + sym
->dynsym_index()
2109 - this->first_global_got_dynsym_index()) * size
/8;
2112 // For the entry at offset GOT_OFFSET, return its offset from the gp.
2113 // Input argument GOT_OFFSET is always global offset from the start of
2114 // .got section, for both single and multi-GOT links.
2115 // For single GOT links, this returns GOT_OFFSET - 0x7FF0. For multi-GOT
2116 // links, the return value is object_got_offset - 0x7FF0, where
2117 // object_got_offset is offset in the OBJECT's GOT.
2119 gp_offset(unsigned int got_offset
,
2120 const Mips_relobj
<size
, big_endian
>* object
) const
2122 return (this->address() + got_offset
2123 - this->target_
->adjusted_gp_value(object
));
2127 // Write out the GOT table.
2129 do_write(Output_file
*);
2133 // This class represent dynamic relocations that need to be applied by
2134 // gold because we are using TLS relocations in a static link.
2138 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2139 Mips_symbol
<size
>* gsym
)
2140 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(true)
2141 { this->u_
.global
.symbol
= gsym
; }
2143 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2144 Sized_relobj_file
<size
, big_endian
>* relobj
, unsigned int index
)
2145 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(false)
2147 this->u_
.local
.relobj
= relobj
;
2148 this->u_
.local
.index
= index
;
2151 // Return the GOT offset.
2154 { return this->got_offset_
; }
2159 { return this->r_type_
; }
2161 // Whether the symbol is global or not.
2163 symbol_is_global() const
2164 { return this->symbol_is_global_
; }
2166 // For a relocation against a global symbol, the global symbol.
2170 gold_assert(this->symbol_is_global_
);
2171 return this->u_
.global
.symbol
;
2174 // For a relocation against a local symbol, the defining object.
2175 Sized_relobj_file
<size
, big_endian
>*
2178 gold_assert(!this->symbol_is_global_
);
2179 return this->u_
.local
.relobj
;
2182 // For a relocation against a local symbol, the local symbol index.
2186 gold_assert(!this->symbol_is_global_
);
2187 return this->u_
.local
.index
;
2191 // GOT offset of the entry to which this relocation is applied.
2192 unsigned int got_offset_
;
2193 // Type of relocation.
2194 unsigned int r_type_
;
2195 // Whether this relocation is against a global symbol.
2196 bool symbol_is_global_
;
2197 // A global or local symbol.
2202 // For a global symbol, the symbol itself.
2203 Mips_symbol
<size
>* symbol
;
2207 // For a local symbol, the object defining object.
2208 Sized_relobj_file
<size
, big_endian
>* relobj
;
2209 // For a local symbol, the symbol index.
2216 Target_mips
<size
, big_endian
>* target_
;
2217 // The symbol table.
2218 Symbol_table
* symbol_table_
;
2221 // Static relocs to be applied to the GOT.
2222 std::vector
<Static_reloc
> static_relocs_
;
2223 // .got section view.
2224 unsigned char* got_view_
;
2225 // The dynamic symbol table index of the first symbol with global GOT entry.
2226 unsigned int first_global_got_dynsym_index_
;
2227 // The master GOT information.
2228 Mips_got_info
<size
, big_endian
>* master_got_info_
;
2229 // The primary GOT information.
2230 Mips_got_info
<size
, big_endian
>* primary_got_
;
2231 // Secondary GOT fixups.
2232 std::vector
<Static_reloc
> secondary_got_relocs_
;
2235 // A class to handle LA25 stubs - non-PIC interface to a PIC function. There are
2236 // two ways of creating these interfaces. The first is to add:
2238 // lui $25,%hi(func)
2240 // addiu $25,$25,%lo(func)
2242 // to a separate trampoline section. The second is to add:
2244 // lui $25,%hi(func)
2245 // addiu $25,$25,%lo(func)
2247 // immediately before a PIC function "func", but only if a function is at the
2248 // beginning of the section, and the section is not too heavily aligned (i.e we
2249 // would need to add no more than 2 nops before the stub.)
2251 // We only create stubs of the first type.
2253 template<int size
, bool big_endian
>
2254 class Mips_output_data_la25_stub
: public Output_section_data
2256 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2259 Mips_output_data_la25_stub()
2260 : Output_section_data(size
== 32 ? 4 : 8), symbols_()
2263 // Create LA25 stub for a symbol.
2265 create_la25_stub(Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
2266 Mips_symbol
<size
>* gsym
);
2268 // Return output address of a stub.
2270 stub_address(const Mips_symbol
<size
>* sym
) const
2272 gold_assert(sym
->has_la25_stub());
2273 return this->address() + sym
->la25_stub_offset();
2278 do_adjust_output_section(Output_section
* os
)
2279 { os
->set_entsize(0); }
2282 // Template for standard LA25 stub.
2283 static const uint32_t la25_stub_entry
[];
2284 // Template for microMIPS LA25 stub.
2285 static const uint32_t la25_stub_micromips_entry
[];
2287 // Set the final size.
2289 set_final_data_size()
2290 { this->set_data_size(this->symbols_
.size() * 16); }
2292 // Create a symbol for SYM stub's value and size, to help make the
2293 // disassembly easier to read.
2295 create_stub_symbol(Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
2296 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
);
2298 // Write to a map file.
2300 do_print_to_mapfile(Mapfile
* mapfile
) const
2301 { mapfile
->print_output_data(this, _(".LA25.stubs")); }
2303 // Write out the LA25 stub section.
2305 do_write(Output_file
*);
2307 // Symbols that have LA25 stubs.
2308 Unordered_set
<Mips_symbol
<size
>*> symbols_
;
2311 // MIPS-specific relocation writer.
2313 template<int sh_type
, bool dynamic
, int size
, bool big_endian
>
2314 struct Mips_output_reloc_writer
;
2316 template<int sh_type
, bool dynamic
, bool big_endian
>
2317 struct Mips_output_reloc_writer
<sh_type
, dynamic
, 32, big_endian
>
2319 typedef Output_reloc
<sh_type
, dynamic
, 32, big_endian
> Output_reloc_type
;
2320 typedef std::vector
<Output_reloc_type
> Relocs
;
2323 write(typename
Relocs::const_iterator p
, unsigned char* pov
)
2327 template<int sh_type
, bool dynamic
, bool big_endian
>
2328 struct Mips_output_reloc_writer
<sh_type
, dynamic
, 64, big_endian
>
2330 typedef Output_reloc
<sh_type
, dynamic
, 64, big_endian
> Output_reloc_type
;
2331 typedef std::vector
<Output_reloc_type
> Relocs
;
2334 write(typename
Relocs::const_iterator p
, unsigned char* pov
)
2336 elfcpp::Mips64_rel_write
<big_endian
> orel(pov
);
2337 orel
.put_r_offset(p
->get_address());
2338 orel
.put_r_sym(p
->get_symbol_index());
2339 orel
.put_r_ssym(RSS_UNDEF
);
2340 orel
.put_r_type(p
->type());
2341 if (p
->type() == elfcpp::R_MIPS_REL32
)
2342 orel
.put_r_type2(elfcpp::R_MIPS_64
);
2344 orel
.put_r_type2(elfcpp::R_MIPS_NONE
);
2345 orel
.put_r_type3(elfcpp::R_MIPS_NONE
);
2349 template<int sh_type
, bool dynamic
, int size
, bool big_endian
>
2350 class Mips_output_data_reloc
: public Output_data_reloc
<sh_type
, dynamic
,
2354 Mips_output_data_reloc(bool sort_relocs
)
2355 : Output_data_reloc
<sh_type
, dynamic
, size
, big_endian
>(sort_relocs
)
2359 // Write out the data.
2361 do_write(Output_file
* of
)
2363 typedef Mips_output_reloc_writer
<sh_type
, dynamic
, size
,
2365 this->template do_write_generic
<Writer
>(of
);
2370 // A class to handle the PLT data.
2372 template<int size
, bool big_endian
>
2373 class Mips_output_data_plt
: public Output_section_data
2375 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2376 typedef Mips_output_data_reloc
<elfcpp::SHT_REL
, true,
2377 size
, big_endian
> Reloc_section
;
2380 // Create the PLT section. The ordinary .got section is an argument,
2381 // since we need to refer to the start.
2382 Mips_output_data_plt(Layout
* layout
, Output_data_space
* got_plt
,
2383 Target_mips
<size
, big_endian
>* target
)
2384 : Output_section_data(size
== 32 ? 4 : 8), got_plt_(got_plt
), symbols_(),
2385 plt_mips_offset_(0), plt_comp_offset_(0), plt_header_size_(0),
2388 this->rel_
= new Reloc_section(false);
2389 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
2390 elfcpp::SHF_ALLOC
, this->rel_
,
2391 ORDER_DYNAMIC_PLT_RELOCS
, false);
2394 // Add an entry to the PLT for a symbol referenced by r_type relocation.
2396 add_entry(Mips_symbol
<size
>* gsym
, unsigned int r_type
);
2398 // Return the .rel.plt section data.
2399 const Reloc_section
*
2401 { return this->rel_
; }
2403 // Return the number of PLT entries.
2406 { return this->symbols_
.size(); }
2408 // Return the offset of the first non-reserved PLT entry.
2410 first_plt_entry_offset() const
2411 { return sizeof(plt0_entry_o32
); }
2413 // Return the size of a PLT entry.
2415 plt_entry_size() const
2416 { return sizeof(plt_entry
); }
2418 // Set final PLT offsets. For each symbol, determine whether standard or
2419 // compressed (MIPS16 or microMIPS) PLT entry is used.
2423 // Return the offset of the first standard PLT entry.
2425 first_mips_plt_offset() const
2426 { return this->plt_header_size_
; }
2428 // Return the offset of the first compressed PLT entry.
2430 first_comp_plt_offset() const
2431 { return this->plt_header_size_
+ this->plt_mips_offset_
; }
2433 // Return whether there are any standard PLT entries.
2435 has_standard_entries() const
2436 { return this->plt_mips_offset_
> 0; }
2438 // Return the output address of standard PLT entry.
2440 mips_entry_address(const Mips_symbol
<size
>* sym
) const
2442 gold_assert (sym
->has_mips_plt_offset());
2443 return (this->address() + this->first_mips_plt_offset()
2444 + sym
->mips_plt_offset());
2447 // Return the output address of compressed (MIPS16 or microMIPS) PLT entry.
2449 comp_entry_address(const Mips_symbol
<size
>* sym
) const
2451 gold_assert (sym
->has_comp_plt_offset());
2452 return (this->address() + this->first_comp_plt_offset()
2453 + sym
->comp_plt_offset());
2458 do_adjust_output_section(Output_section
* os
)
2459 { os
->set_entsize(0); }
2461 // Write to a map file.
2463 do_print_to_mapfile(Mapfile
* mapfile
) const
2464 { mapfile
->print_output_data(this, _(".plt")); }
2467 // Template for the first PLT entry.
2468 static const uint32_t plt0_entry_o32
[];
2469 static const uint32_t plt0_entry_n32
[];
2470 static const uint32_t plt0_entry_n64
[];
2471 static const uint32_t plt0_entry_micromips_o32
[];
2472 static const uint32_t plt0_entry_micromips32_o32
[];
2474 // Template for subsequent PLT entries.
2475 static const uint32_t plt_entry
[];
2476 static const uint32_t plt_entry_mips16_o32
[];
2477 static const uint32_t plt_entry_micromips_o32
[];
2478 static const uint32_t plt_entry_micromips32_o32
[];
2480 // Set the final size.
2482 set_final_data_size()
2484 this->set_data_size(this->plt_header_size_
+ this->plt_mips_offset_
2485 + this->plt_comp_offset_
);
2488 // Write out the PLT data.
2490 do_write(Output_file
*);
2492 // Return whether the plt header contains microMIPS code. For the sake of
2493 // cache alignment always use a standard header whenever any standard entries
2494 // are present even if microMIPS entries are present as well. This also lets
2495 // the microMIPS header rely on the value of $v0 only set by microMIPS
2496 // entries, for a small size reduction.
2498 is_plt_header_compressed() const
2500 gold_assert(this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0);
2501 return this->target_
->is_output_micromips() && this->plt_mips_offset_
== 0;
2504 // Return the size of the PLT header.
2506 get_plt_header_size() const
2508 if (this->target_
->is_output_n64())
2509 return 4 * sizeof(plt0_entry_n64
) / sizeof(plt0_entry_n64
[0]);
2510 else if (this->target_
->is_output_n32())
2511 return 4 * sizeof(plt0_entry_n32
) / sizeof(plt0_entry_n32
[0]);
2512 else if (!this->is_plt_header_compressed())
2513 return 4 * sizeof(plt0_entry_o32
) / sizeof(plt0_entry_o32
[0]);
2514 else if (this->target_
->use_32bit_micromips_instructions())
2515 return (2 * sizeof(plt0_entry_micromips32_o32
)
2516 / sizeof(plt0_entry_micromips32_o32
[0]));
2518 return (2 * sizeof(plt0_entry_micromips_o32
)
2519 / sizeof(plt0_entry_micromips_o32
[0]));
2522 // Return the PLT header entry.
2524 get_plt_header_entry() const
2526 if (this->target_
->is_output_n64())
2527 return plt0_entry_n64
;
2528 else if (this->target_
->is_output_n32())
2529 return plt0_entry_n32
;
2530 else if (!this->is_plt_header_compressed())
2531 return plt0_entry_o32
;
2532 else if (this->target_
->use_32bit_micromips_instructions())
2533 return plt0_entry_micromips32_o32
;
2535 return plt0_entry_micromips_o32
;
2538 // Return the size of the standard PLT entry.
2540 standard_plt_entry_size() const
2541 { return 4 * sizeof(plt_entry
) / sizeof(plt_entry
[0]); }
2543 // Return the size of the compressed PLT entry.
2545 compressed_plt_entry_size() const
2547 gold_assert(!this->target_
->is_output_newabi());
2549 if (!this->target_
->is_output_micromips())
2550 return (2 * sizeof(plt_entry_mips16_o32
)
2551 / sizeof(plt_entry_mips16_o32
[0]));
2552 else if (this->target_
->use_32bit_micromips_instructions())
2553 return (2 * sizeof(plt_entry_micromips32_o32
)
2554 / sizeof(plt_entry_micromips32_o32
[0]));
2556 return (2 * sizeof(plt_entry_micromips_o32
)
2557 / sizeof(plt_entry_micromips_o32
[0]));
2560 // The reloc section.
2561 Reloc_section
* rel_
;
2562 // The .got.plt section.
2563 Output_data_space
* got_plt_
;
2564 // Symbols that have PLT entry.
2565 std::vector
<Mips_symbol
<size
>*> symbols_
;
2566 // The offset of the next standard PLT entry to create.
2567 unsigned int plt_mips_offset_
;
2568 // The offset of the next compressed PLT entry to create.
2569 unsigned int plt_comp_offset_
;
2570 // The size of the PLT header in bytes.
2571 unsigned int plt_header_size_
;
2573 Target_mips
<size
, big_endian
>* target_
;
2576 // A class to handle the .MIPS.stubs data.
2578 template<int size
, bool big_endian
>
2579 class Mips_output_data_mips_stubs
: public Output_section_data
2581 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2584 Mips_output_data_mips_stubs(Target_mips
<size
, big_endian
>* target
)
2585 : Output_section_data(size
== 32 ? 4 : 8), symbols_(), dynsym_count_(-1U),
2586 stub_offsets_are_set_(false), target_(target
)
2589 // Create entry for a symbol.
2591 make_entry(Mips_symbol
<size
>*);
2593 // Remove entry for a symbol.
2595 remove_entry(Mips_symbol
<size
>* gsym
);
2597 // Set stub offsets for symbols. This method expects that the number of
2598 // entries in dynamic symbol table is set.
2600 set_lazy_stub_offsets();
2603 set_needs_dynsym_value();
2605 // Set the number of entries in dynamic symbol table.
2607 set_dynsym_count(unsigned int dynsym_count
)
2608 { this->dynsym_count_
= dynsym_count
; }
2610 // Return maximum size of the stub, ie. the stub size if the dynamic symbol
2611 // count is greater than 0x10000. If the dynamic symbol count is less than
2612 // 0x10000, the stub will be 4 bytes smaller.
2613 // There's no disadvantage from using microMIPS code here, so for the sake of
2614 // pure-microMIPS binaries we prefer it whenever there's any microMIPS code in
2615 // output produced at all. This has a benefit of stubs being shorter by
2616 // 4 bytes each too, unless in the insn32 mode.
2618 stub_max_size() const
2620 if (!this->target_
->is_output_micromips()
2621 || this->target_
->use_32bit_micromips_instructions())
2627 // Return the size of the stub. This method expects that the final dynsym
2632 gold_assert(this->dynsym_count_
!= -1U);
2633 if (this->dynsym_count_
> 0x10000)
2634 return this->stub_max_size();
2636 return this->stub_max_size() - 4;
2639 // Return output address of a stub.
2641 stub_address(const Mips_symbol
<size
>* sym
) const
2643 gold_assert(sym
->has_lazy_stub());
2644 return this->address() + sym
->lazy_stub_offset();
2649 do_adjust_output_section(Output_section
* os
)
2650 { os
->set_entsize(0); }
2652 // Write to a map file.
2654 do_print_to_mapfile(Mapfile
* mapfile
) const
2655 { mapfile
->print_output_data(this, _(".MIPS.stubs")); }
2658 static const uint32_t lazy_stub_normal_1
[];
2659 static const uint32_t lazy_stub_normal_1_n64
[];
2660 static const uint32_t lazy_stub_normal_2
[];
2661 static const uint32_t lazy_stub_normal_2_n64
[];
2662 static const uint32_t lazy_stub_big
[];
2663 static const uint32_t lazy_stub_big_n64
[];
2665 static const uint32_t lazy_stub_micromips_normal_1
[];
2666 static const uint32_t lazy_stub_micromips_normal_1_n64
[];
2667 static const uint32_t lazy_stub_micromips_normal_2
[];
2668 static const uint32_t lazy_stub_micromips_normal_2_n64
[];
2669 static const uint32_t lazy_stub_micromips_big
[];
2670 static const uint32_t lazy_stub_micromips_big_n64
[];
2672 static const uint32_t lazy_stub_micromips32_normal_1
[];
2673 static const uint32_t lazy_stub_micromips32_normal_1_n64
[];
2674 static const uint32_t lazy_stub_micromips32_normal_2
[];
2675 static const uint32_t lazy_stub_micromips32_normal_2_n64
[];
2676 static const uint32_t lazy_stub_micromips32_big
[];
2677 static const uint32_t lazy_stub_micromips32_big_n64
[];
2679 // Set the final size.
2681 set_final_data_size()
2682 { this->set_data_size(this->symbols_
.size() * this->stub_max_size()); }
2684 // Write out the .MIPS.stubs data.
2686 do_write(Output_file
*);
2688 // .MIPS.stubs symbols
2689 Unordered_set
<Mips_symbol
<size
>*> symbols_
;
2690 // Number of entries in dynamic symbol table.
2691 unsigned int dynsym_count_
;
2692 // Whether the stub offsets are set.
2693 bool stub_offsets_are_set_
;
2695 Target_mips
<size
, big_endian
>* target_
;
2698 // This class handles Mips .reginfo output section.
2700 template<int size
, bool big_endian
>
2701 class Mips_output_section_reginfo
: public Output_section
2703 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
2706 Mips_output_section_reginfo(const char* name
, elfcpp::Elf_Word type
,
2707 elfcpp::Elf_Xword flags
,
2708 Target_mips
<size
, big_endian
>* target
)
2709 : Output_section(name
, type
, flags
), target_(target
), gprmask_(0),
2710 cprmask1_(0), cprmask2_(0), cprmask3_(0), cprmask4_(0)
2713 // Downcast a base pointer to a Mips_output_section_reginfo pointer.
2714 static Mips_output_section_reginfo
<size
, big_endian
>*
2715 as_mips_output_section_reginfo(Output_section
* os
)
2716 { return static_cast<Mips_output_section_reginfo
<size
, big_endian
>*>(os
); }
2718 // Set masks of the output .reginfo section.
2720 set_masks(Valtype gprmask
, Valtype cprmask1
, Valtype cprmask2
,
2721 Valtype cprmask3
, Valtype cprmask4
)
2723 this->gprmask_
= gprmask
;
2724 this->cprmask1_
= cprmask1
;
2725 this->cprmask2_
= cprmask2
;
2726 this->cprmask3_
= cprmask3
;
2727 this->cprmask4_
= cprmask4
;
2731 // Set the final data size.
2733 set_final_data_size()
2734 { this->set_data_size(24); }
2736 // Write out reginfo section.
2738 do_write(Output_file
* of
);
2741 Target_mips
<size
, big_endian
>* target_
;
2743 // gprmask of the output .reginfo section.
2745 // cprmask1 of the output .reginfo section.
2747 // cprmask2 of the output .reginfo section.
2749 // cprmask3 of the output .reginfo section.
2751 // cprmask4 of the output .reginfo section.
2755 // The MIPS target has relocation types which default handling of relocatable
2756 // relocation cannot process. So we have to extend the default code.
2758 template<bool big_endian
, typename Classify_reloc
>
2759 class Mips_scan_relocatable_relocs
:
2760 public Default_scan_relocatable_relocs
<Classify_reloc
>
2763 // Return the strategy to use for a local symbol which is a section
2764 // symbol, given the relocation type.
2765 inline Relocatable_relocs::Reloc_strategy
2766 local_section_strategy(unsigned int r_type
, Relobj
* object
)
2768 if (Classify_reloc::sh_type
== elfcpp::SHT_RELA
)
2769 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
2774 case elfcpp::R_MIPS_26
:
2775 return Relocatable_relocs::RELOC_SPECIAL
;
2778 return Default_scan_relocatable_relocs
<Classify_reloc
>::
2779 local_section_strategy(r_type
, object
);
2785 // Mips_copy_relocs class. The only difference from the base class is the
2786 // method emit_mips, which should be called instead of Copy_reloc_entry::emit.
2787 // Mips cannot convert all relocation types to dynamic relocs. If a reloc
2788 // cannot be made dynamic, a COPY reloc is emitted.
2790 template<int sh_type
, int size
, bool big_endian
>
2791 class Mips_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
2795 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_MIPS_COPY
)
2798 // Emit any saved relocations which turn out to be needed. This is
2799 // called after all the relocs have been scanned.
2801 emit_mips(Output_data_reloc
<sh_type
, true, size
, big_endian
>*,
2802 Symbol_table
*, Layout
*, Target_mips
<size
, big_endian
>*);
2805 typedef typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
2808 // Emit this reloc if appropriate. This is called after we have
2809 // scanned all the relocations, so we know whether we emitted a
2810 // COPY relocation for SYM_.
2812 emit_entry(Copy_reloc_entry
& entry
,
2813 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
2814 Symbol_table
* symtab
, Layout
* layout
,
2815 Target_mips
<size
, big_endian
>* target
);
2819 // Return true if the symbol SYM should be considered to resolve local
2820 // to the current module, and false otherwise. The logic is taken from
2821 // GNU ld's method _bfd_elf_symbol_refs_local_p.
2823 symbol_refs_local(const Symbol
* sym
, bool has_dynsym_entry
,
2824 bool local_protected
)
2826 // If it's a local sym, of course we resolve locally.
2830 // STV_HIDDEN or STV_INTERNAL ones must be local.
2831 if (sym
->visibility() == elfcpp::STV_HIDDEN
2832 || sym
->visibility() == elfcpp::STV_INTERNAL
)
2835 // If we don't have a definition in a regular file, then we can't
2836 // resolve locally. The sym is either undefined or dynamic.
2837 if (sym
->source() != Symbol::FROM_OBJECT
|| sym
->object()->is_dynamic()
2838 || sym
->is_undefined())
2841 // Forced local symbols resolve locally.
2842 if (sym
->is_forced_local())
2845 // As do non-dynamic symbols.
2846 if (!has_dynsym_entry
)
2849 // At this point, we know the symbol is defined and dynamic. In an
2850 // executable it must resolve locally, likewise when building symbolic
2851 // shared libraries.
2852 if (parameters
->options().output_is_executable()
2853 || parameters
->options().Bsymbolic())
2856 // Now deal with defined dynamic symbols in shared libraries. Ones
2857 // with default visibility might not resolve locally.
2858 if (sym
->visibility() == elfcpp::STV_DEFAULT
)
2861 // STV_PROTECTED non-function symbols are local.
2862 if (sym
->type() != elfcpp::STT_FUNC
)
2865 // Function pointer equality tests may require that STV_PROTECTED
2866 // symbols be treated as dynamic symbols. If the address of a
2867 // function not defined in an executable is set to that function's
2868 // plt entry in the executable, then the address of the function in
2869 // a shared library must also be the plt entry in the executable.
2870 return local_protected
;
2873 // Return TRUE if references to this symbol always reference the symbol in this
2876 symbol_references_local(const Symbol
* sym
, bool has_dynsym_entry
)
2878 return symbol_refs_local(sym
, has_dynsym_entry
, false);
2881 // Return TRUE if calls to this symbol always call the version in this object.
2883 symbol_calls_local(const Symbol
* sym
, bool has_dynsym_entry
)
2885 return symbol_refs_local(sym
, has_dynsym_entry
, true);
2888 // Compare GOT offsets of two symbols.
2890 template<int size
, bool big_endian
>
2892 got_offset_compare(Symbol
* sym1
, Symbol
* sym2
)
2894 Mips_symbol
<size
>* mips_sym1
= Mips_symbol
<size
>::as_mips_sym(sym1
);
2895 Mips_symbol
<size
>* mips_sym2
= Mips_symbol
<size
>::as_mips_sym(sym2
);
2896 unsigned int area1
= mips_sym1
->global_got_area();
2897 unsigned int area2
= mips_sym2
->global_got_area();
2898 gold_assert(area1
!= GGA_NONE
&& area1
!= GGA_NONE
);
2900 // GGA_NORMAL entries always come before GGA_RELOC_ONLY.
2902 return area1
< area2
;
2904 return mips_sym1
->global_gotoffset() < mips_sym2
->global_gotoffset();
2907 // This method divides dynamic symbols into symbols that have GOT entry, and
2908 // symbols that don't have GOT entry. It also sorts symbols with the GOT entry.
2909 // Mips ABI requires that symbols with the GOT entry must be at the end of
2910 // dynamic symbol table, and the order in dynamic symbol table must match the
2913 template<int size
, bool big_endian
>
2915 reorder_dyn_symbols(std::vector
<Symbol
*>* dyn_symbols
,
2916 std::vector
<Symbol
*>* non_got_symbols
,
2917 std::vector
<Symbol
*>* got_symbols
)
2919 for (std::vector
<Symbol
*>::iterator p
= dyn_symbols
->begin();
2920 p
!= dyn_symbols
->end();
2923 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(*p
);
2924 if (mips_sym
->global_got_area() == GGA_NORMAL
2925 || mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
2926 got_symbols
->push_back(mips_sym
);
2928 non_got_symbols
->push_back(mips_sym
);
2931 std::sort(got_symbols
->begin(), got_symbols
->end(),
2932 got_offset_compare
<size
, big_endian
>);
2935 // Functor class for processing the global symbol table.
2937 template<int size
, bool big_endian
>
2938 class Symbol_visitor_check_symbols
2941 Symbol_visitor_check_symbols(Target_mips
<size
, big_endian
>* target
,
2942 Layout
* layout
, Symbol_table
* symtab
)
2943 : target_(target
), layout_(layout
), symtab_(symtab
)
2947 operator()(Sized_symbol
<size
>* sym
)
2949 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
2950 if (local_pic_function
<size
, big_endian
>(mips_sym
))
2952 // SYM is a function that might need $25 to be valid on entry.
2953 // If we're creating a non-PIC relocatable object, mark SYM as
2954 // being PIC. If we're creating a non-relocatable object with
2955 // non-PIC branches and jumps to SYM, make sure that SYM has an la25
2957 if (parameters
->options().relocatable())
2959 if (!parameters
->options().output_is_position_independent())
2960 mips_sym
->set_pic();
2962 else if (mips_sym
->has_nonpic_branches())
2964 this->target_
->la25_stub_section(layout_
)
2965 ->create_la25_stub(this->symtab_
, this->target_
, mips_sym
);
2971 Target_mips
<size
, big_endian
>* target_
;
2973 Symbol_table
* symtab_
;
2976 // Relocation types, parameterized by SHT_REL vs. SHT_RELA, size,
2977 // and endianness. The relocation format for MIPS-64 is non-standard.
2979 template<int sh_type
, int size
, bool big_endian
>
2980 struct Mips_reloc_types
;
2982 template<bool big_endian
>
2983 struct Mips_reloc_types
<elfcpp::SHT_REL
, 32, big_endian
>
2985 typedef typename
elfcpp::Rel
<32, big_endian
> Reloc
;
2986 typedef typename
elfcpp::Rel_write
<32, big_endian
> Reloc_write
;
2988 static typename
elfcpp::Elf_types
<32>::Elf_Swxword
2989 get_r_addend(const Reloc
*)
2993 set_reloc_addend(Reloc_write
*,
2994 typename
elfcpp::Elf_types
<32>::Elf_Swxword
)
2995 { gold_unreachable(); }
2998 template<bool big_endian
>
2999 struct Mips_reloc_types
<elfcpp::SHT_RELA
, 32, big_endian
>
3001 typedef typename
elfcpp::Rela
<32, big_endian
> Reloc
;
3002 typedef typename
elfcpp::Rela_write
<32, big_endian
> Reloc_write
;
3004 static typename
elfcpp::Elf_types
<32>::Elf_Swxword
3005 get_r_addend(const Reloc
* reloc
)
3006 { return reloc
->get_r_addend(); }
3009 set_reloc_addend(Reloc_write
* p
,
3010 typename
elfcpp::Elf_types
<32>::Elf_Swxword val
)
3011 { p
->put_r_addend(val
); }
3014 template<bool big_endian
>
3015 struct Mips_reloc_types
<elfcpp::SHT_REL
, 64, big_endian
>
3017 typedef typename
elfcpp::Mips64_rel
<big_endian
> Reloc
;
3018 typedef typename
elfcpp::Mips64_rel_write
<big_endian
> Reloc_write
;
3020 static typename
elfcpp::Elf_types
<64>::Elf_Swxword
3021 get_r_addend(const Reloc
*)
3025 set_reloc_addend(Reloc_write
*,
3026 typename
elfcpp::Elf_types
<64>::Elf_Swxword
)
3027 { gold_unreachable(); }
3030 template<bool big_endian
>
3031 struct Mips_reloc_types
<elfcpp::SHT_RELA
, 64, big_endian
>
3033 typedef typename
elfcpp::Mips64_rela
<big_endian
> Reloc
;
3034 typedef typename
elfcpp::Mips64_rela_write
<big_endian
> Reloc_write
;
3036 static typename
elfcpp::Elf_types
<64>::Elf_Swxword
3037 get_r_addend(const Reloc
* reloc
)
3038 { return reloc
->get_r_addend(); }
3041 set_reloc_addend(Reloc_write
* p
,
3042 typename
elfcpp::Elf_types
<64>::Elf_Swxword val
)
3043 { p
->put_r_addend(val
); }
3046 // Forward declaration.
3048 mips_get_size_for_reloc(unsigned int, Relobj
*);
3050 // A class for inquiring about properties of a relocation,
3051 // used while scanning relocs during a relocatable link and
3052 // garbage collection.
3054 template<int sh_type_
, int size
, bool big_endian
>
3055 class Mips_classify_reloc
;
3057 template<int sh_type_
, bool big_endian
>
3058 class Mips_classify_reloc
<sh_type_
, 32, big_endian
> :
3059 public gold::Default_classify_reloc
<sh_type_
, 32, big_endian
>
3062 typedef typename Mips_reloc_types
<sh_type_
, 32, big_endian
>::Reloc
3064 typedef typename Mips_reloc_types
<sh_type_
, 32, big_endian
>::Reloc_write
3067 // Return the symbol referred to by the relocation.
3068 static inline unsigned int
3069 get_r_sym(const Reltype
* reloc
)
3070 { return elfcpp::elf_r_sym
<32>(reloc
->get_r_info()); }
3072 // Return the type of the relocation.
3073 static inline unsigned int
3074 get_r_type(const Reltype
* reloc
)
3075 { return elfcpp::elf_r_type
<32>(reloc
->get_r_info()); }
3077 static inline unsigned int
3078 get_r_type2(const Reltype
*)
3081 static inline unsigned int
3082 get_r_type3(const Reltype
*)
3085 static inline unsigned int
3086 get_r_ssym(const Reltype
*)
3089 // Return the explicit addend of the relocation (return 0 for SHT_REL).
3090 static inline unsigned int
3091 get_r_addend(const Reltype
* reloc
)
3093 if (sh_type_
== elfcpp::SHT_REL
)
3095 return Mips_reloc_types
<sh_type_
, 32, big_endian
>::get_r_addend(reloc
);
3098 // Write the r_info field to a new reloc, using the r_info field from
3099 // the original reloc, replacing the r_sym field with R_SYM.
3101 put_r_info(Reltype_write
* new_reloc
, Reltype
* reloc
, unsigned int r_sym
)
3103 unsigned int r_type
= elfcpp::elf_r_type
<32>(reloc
->get_r_info());
3104 new_reloc
->put_r_info(elfcpp::elf_r_info
<32>(r_sym
, r_type
));
3107 // Write the r_addend field to a new reloc.
3109 put_r_addend(Reltype_write
* to
,
3110 typename
elfcpp::Elf_types
<32>::Elf_Swxword addend
)
3111 { Mips_reloc_types
<sh_type_
, 32, big_endian
>::set_reloc_addend(to
, addend
); }
3113 // Return the size of the addend of the relocation (only used for SHT_REL).
3115 get_size_for_reloc(unsigned int r_type
, Relobj
* obj
)
3116 { return mips_get_size_for_reloc(r_type
, obj
); }
3119 template<int sh_type_
, bool big_endian
>
3120 class Mips_classify_reloc
<sh_type_
, 64, big_endian
> :
3121 public gold::Default_classify_reloc
<sh_type_
, 64, big_endian
>
3124 typedef typename Mips_reloc_types
<sh_type_
, 64, big_endian
>::Reloc
3126 typedef typename Mips_reloc_types
<sh_type_
, 64, big_endian
>::Reloc_write
3129 // Return the symbol referred to by the relocation.
3130 static inline unsigned int
3131 get_r_sym(const Reltype
* reloc
)
3132 { return reloc
->get_r_sym(); }
3134 // Return the r_type of the relocation.
3135 static inline unsigned int
3136 get_r_type(const Reltype
* reloc
)
3137 { return reloc
->get_r_type(); }
3139 // Return the r_type2 of the relocation.
3140 static inline unsigned int
3141 get_r_type2(const Reltype
* reloc
)
3142 { return reloc
->get_r_type2(); }
3144 // Return the r_type3 of the relocation.
3145 static inline unsigned int
3146 get_r_type3(const Reltype
* reloc
)
3147 { return reloc
->get_r_type3(); }
3149 // Return the special symbol of the relocation.
3150 static inline unsigned int
3151 get_r_ssym(const Reltype
* reloc
)
3152 { return reloc
->get_r_ssym(); }
3154 // Return the explicit addend of the relocation (return 0 for SHT_REL).
3155 static inline typename
elfcpp::Elf_types
<64>::Elf_Swxword
3156 get_r_addend(const Reltype
* reloc
)
3158 if (sh_type_
== elfcpp::SHT_REL
)
3160 return Mips_reloc_types
<sh_type_
, 64, big_endian
>::get_r_addend(reloc
);
3163 // Write the r_info field to a new reloc, using the r_info field from
3164 // the original reloc, replacing the r_sym field with R_SYM.
3166 put_r_info(Reltype_write
* new_reloc
, Reltype
* reloc
, unsigned int r_sym
)
3168 new_reloc
->put_r_sym(r_sym
);
3169 new_reloc
->put_r_ssym(reloc
->get_r_ssym());
3170 new_reloc
->put_r_type3(reloc
->get_r_type3());
3171 new_reloc
->put_r_type2(reloc
->get_r_type2());
3172 new_reloc
->put_r_type(reloc
->get_r_type());
3175 // Write the r_addend field to a new reloc.
3177 put_r_addend(Reltype_write
* to
,
3178 typename
elfcpp::Elf_types
<64>::Elf_Swxword addend
)
3179 { Mips_reloc_types
<sh_type_
, 64, big_endian
>::set_reloc_addend(to
, addend
); }
3181 // Return the size of the addend of the relocation (only used for SHT_REL).
3183 get_size_for_reloc(unsigned int r_type
, Relobj
* obj
)
3184 { return mips_get_size_for_reloc(r_type
, obj
); }
3187 template<int size
, bool big_endian
>
3188 class Target_mips
: public Sized_target
<size
, big_endian
>
3190 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
3191 typedef Mips_output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
3193 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
3194 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
3195 typedef typename Mips_reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
3197 typedef typename Mips_reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
3201 Target_mips(const Target::Target_info
* info
= &mips_info
)
3202 : Sized_target
<size
, big_endian
>(info
), got_(NULL
), gp_(NULL
), plt_(NULL
),
3203 got_plt_(NULL
), rel_dyn_(NULL
), copy_relocs_(),
3204 dyn_relocs_(), la25_stub_(NULL
), mips_mach_extensions_(),
3205 mips_stubs_(NULL
), ei_class_(0), mach_(0), layout_(NULL
),
3206 got16_addends_(), entry_symbol_is_compressed_(false), insn32_(false)
3208 this->add_machine_extensions();
3211 // The offset of $gp from the beginning of the .got section.
3212 static const unsigned int MIPS_GP_OFFSET
= 0x7ff0;
3214 // The maximum size of the GOT for it to be addressable using 16-bit
3215 // offsets from $gp.
3216 static const unsigned int MIPS_GOT_MAX_SIZE
= MIPS_GP_OFFSET
+ 0x7fff;
3218 // Make a new symbol table entry for the Mips target.
3220 make_symbol(const char*, elfcpp::STT
, Object
*, unsigned int, uint64_t)
3221 { return new Mips_symbol
<size
>(); }
3223 // Process the relocations to determine unreferenced sections for
3224 // garbage collection.
3226 gc_process_relocs(Symbol_table
* symtab
,
3228 Sized_relobj_file
<size
, big_endian
>* object
,
3229 unsigned int data_shndx
,
3230 unsigned int sh_type
,
3231 const unsigned char* prelocs
,
3233 Output_section
* output_section
,
3234 bool needs_special_offset_handling
,
3235 size_t local_symbol_count
,
3236 const unsigned char* plocal_symbols
);
3238 // Scan the relocations to look for symbol adjustments.
3240 scan_relocs(Symbol_table
* symtab
,
3242 Sized_relobj_file
<size
, big_endian
>* object
,
3243 unsigned int data_shndx
,
3244 unsigned int sh_type
,
3245 const unsigned char* prelocs
,
3247 Output_section
* output_section
,
3248 bool needs_special_offset_handling
,
3249 size_t local_symbol_count
,
3250 const unsigned char* plocal_symbols
);
3252 // Finalize the sections.
3254 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
3256 // Relocate a section.
3258 relocate_section(const Relocate_info
<size
, big_endian
>*,
3259 unsigned int sh_type
,
3260 const unsigned char* prelocs
,
3262 Output_section
* output_section
,
3263 bool needs_special_offset_handling
,
3264 unsigned char* view
,
3265 Mips_address view_address
,
3266 section_size_type view_size
,
3267 const Reloc_symbol_changes
*);
3269 // Scan the relocs during a relocatable link.
3271 scan_relocatable_relocs(Symbol_table
* symtab
,
3273 Sized_relobj_file
<size
, big_endian
>* object
,
3274 unsigned int data_shndx
,
3275 unsigned int sh_type
,
3276 const unsigned char* prelocs
,
3278 Output_section
* output_section
,
3279 bool needs_special_offset_handling
,
3280 size_t local_symbol_count
,
3281 const unsigned char* plocal_symbols
,
3282 Relocatable_relocs
*);
3284 // Scan the relocs for --emit-relocs.
3286 emit_relocs_scan(Symbol_table
* symtab
,
3288 Sized_relobj_file
<size
, big_endian
>* object
,
3289 unsigned int data_shndx
,
3290 unsigned int sh_type
,
3291 const unsigned char* prelocs
,
3293 Output_section
* output_section
,
3294 bool needs_special_offset_handling
,
3295 size_t local_symbol_count
,
3296 const unsigned char* plocal_syms
,
3297 Relocatable_relocs
* rr
);
3299 // Emit relocations for a section.
3301 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
3302 unsigned int sh_type
,
3303 const unsigned char* prelocs
,
3305 Output_section
* output_section
,
3306 typename
elfcpp::Elf_types
<size
>::Elf_Off
3307 offset_in_output_section
,
3308 unsigned char* view
,
3309 Mips_address view_address
,
3310 section_size_type view_size
,
3311 unsigned char* reloc_view
,
3312 section_size_type reloc_view_size
);
3314 // Perform target-specific processing in a relocatable link. This is
3315 // only used if we use the relocation strategy RELOC_SPECIAL.
3317 relocate_special_relocatable(const Relocate_info
<size
, big_endian
>* relinfo
,
3318 unsigned int sh_type
,
3319 const unsigned char* preloc_in
,
3321 Output_section
* output_section
,
3322 typename
elfcpp::Elf_types
<size
>::Elf_Off
3323 offset_in_output_section
,
3324 unsigned char* view
,
3325 Mips_address view_address
,
3326 section_size_type view_size
,
3327 unsigned char* preloc_out
);
3329 // Return whether SYM is defined by the ABI.
3331 do_is_defined_by_abi(const Symbol
* sym
) const
3333 return ((strcmp(sym
->name(), "__gnu_local_gp") == 0)
3334 || (strcmp(sym
->name(), "_gp_disp") == 0)
3335 || (strcmp(sym
->name(), "___tls_get_addr") == 0));
3338 // Return the number of entries in the GOT.
3340 got_entry_count() const
3342 if (!this->has_got_section())
3344 return this->got_size() / (size
/8);
3347 // Return the number of entries in the PLT.
3349 plt_entry_count() const
3351 if (this->plt_
== NULL
)
3353 return this->plt_
->entry_count();
3356 // Return the offset of the first non-reserved PLT entry.
3358 first_plt_entry_offset() const
3359 { return this->plt_
->first_plt_entry_offset(); }
3361 // Return the size of each PLT entry.
3363 plt_entry_size() const
3364 { return this->plt_
->plt_entry_size(); }
3366 // Get the GOT section, creating it if necessary.
3367 Mips_output_data_got
<size
, big_endian
>*
3368 got_section(Symbol_table
*, Layout
*);
3370 // Get the GOT section.
3371 Mips_output_data_got
<size
, big_endian
>*
3374 gold_assert(this->got_
!= NULL
);
3378 // Get the .MIPS.stubs section, creating it if necessary.
3379 Mips_output_data_mips_stubs
<size
, big_endian
>*
3380 mips_stubs_section(Layout
* layout
);
3382 // Get the .MIPS.stubs section.
3383 Mips_output_data_mips_stubs
<size
, big_endian
>*
3384 mips_stubs_section() const
3386 gold_assert(this->mips_stubs_
!= NULL
);
3387 return this->mips_stubs_
;
3390 // Get the LA25 stub section, creating it if necessary.
3391 Mips_output_data_la25_stub
<size
, big_endian
>*
3392 la25_stub_section(Layout
*);
3394 // Get the LA25 stub section.
3395 Mips_output_data_la25_stub
<size
, big_endian
>*
3398 gold_assert(this->la25_stub_
!= NULL
);
3399 return this->la25_stub_
;
3402 // Get gp value. It has the value of .got + 0x7FF0.
3406 if (this->gp_
!= NULL
)
3407 return this->gp_
->value();
3411 // Get gp value. It has the value of .got + 0x7FF0. Adjust it for
3412 // multi-GOT links so that OBJECT's GOT + 0x7FF0 is returned.
3414 adjusted_gp_value(const Mips_relobj
<size
, big_endian
>* object
)
3416 if (this->gp_
== NULL
)
3419 bool multi_got
= false;
3420 if (this->has_got_section())
3421 multi_got
= this->got_section()->multi_got();
3423 return this->gp_
->value();
3425 return this->gp_
->value() + this->got_section()->get_got_offset(object
);
3428 // Get the dynamic reloc section, creating it if necessary.
3430 rel_dyn_section(Layout
*);
3433 do_has_custom_set_dynsym_indexes() const
3436 // Don't emit input .reginfo sections to output .reginfo.
3438 do_should_include_section(elfcpp::Elf_Word sh_type
) const
3439 { return sh_type
!= elfcpp::SHT_MIPS_REGINFO
; }
3441 // Set the dynamic symbol indexes. INDEX is the index of the first
3442 // global dynamic symbol. Pointers to the symbols are stored into the
3443 // vector SYMS. The names are added to DYNPOOL. This returns an
3444 // updated dynamic symbol index.
3446 do_set_dynsym_indexes(std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
3447 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
3448 Versions
* versions
, Symbol_table
* symtab
) const;
3450 // Remove .MIPS.stubs entry for a symbol.
3452 remove_lazy_stub_entry(Mips_symbol
<size
>* sym
)
3454 if (this->mips_stubs_
!= NULL
)
3455 this->mips_stubs_
->remove_entry(sym
);
3458 // The value to write into got[1] for SVR4 targets, to identify it is
3459 // a GNU object. The dynamic linker can then use got[1] to store the
3462 mips_elf_gnu_got1_mask()
3464 if (this->is_output_n64())
3465 return (uint64_t)1 << 63;
3470 // Whether the output has microMIPS code. This is valid only after
3471 // merge_processor_specific_flags() is called.
3473 is_output_micromips() const
3475 gold_assert(this->are_processor_specific_flags_set());
3476 return elfcpp::is_micromips(this->processor_specific_flags());
3479 // Whether the output uses N32 ABI. This is valid only after
3480 // merge_processor_specific_flags() is called.
3482 is_output_n32() const
3484 gold_assert(this->are_processor_specific_flags_set());
3485 return elfcpp::abi_n32(this->processor_specific_flags());
3488 // Whether the output uses N64 ABI. This is valid only after
3489 // merge_processor_specific_flags() is called.
3491 is_output_n64() const
3493 gold_assert(this->are_processor_specific_flags_set());
3494 return elfcpp::abi_64(this->ei_class_
);
3497 // Whether the output uses NEWABI. This is valid only after
3498 // merge_processor_specific_flags() is called.
3500 is_output_newabi() const
3501 { return this->is_output_n32() || this->is_output_n64(); }
3503 // Whether we can only use 32-bit microMIPS instructions.
3505 use_32bit_micromips_instructions() const
3506 { return this->insn32_
; }
3508 // Return the r_sym field from a relocation.
3510 get_r_sym(const unsigned char* preloc
) const
3512 // Since REL and RELA relocs share the same structure through
3513 // the r_info field, we can just use REL here.
3514 Reltype
rel(preloc
);
3515 return Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
3520 // Return the value to use for a dynamic symbol which requires special
3521 // treatment. This is how we support equality comparisons of function
3522 // pointers across shared library boundaries, as described in the
3523 // processor specific ABI supplement.
3525 do_dynsym_value(const Symbol
* gsym
) const;
3527 // Make an ELF object.
3529 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
3530 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
);
3533 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
3534 const elfcpp::Ehdr
<size
, !big_endian
>&)
3535 { gold_unreachable(); }
3537 // Make an output section.
3539 do_make_output_section(const char* name
, elfcpp::Elf_Word type
,
3540 elfcpp::Elf_Xword flags
)
3542 if (type
== elfcpp::SHT_MIPS_REGINFO
)
3543 return new Mips_output_section_reginfo
<size
, big_endian
>(name
, type
,
3546 return new Output_section(name
, type
, flags
);
3549 // Adjust ELF file header.
3551 do_adjust_elf_header(unsigned char* view
, int len
);
3553 // Get the custom dynamic tag value.
3555 do_dynamic_tag_custom_value(elfcpp::DT
) const;
3557 // Adjust the value written to the dynamic symbol table.
3559 do_adjust_dyn_symbol(const Symbol
* sym
, unsigned char* view
) const
3561 elfcpp::Sym
<size
, big_endian
> isym(view
);
3562 elfcpp::Sym_write
<size
, big_endian
> osym(view
);
3563 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
3565 // Keep dynamic compressed symbols odd. This allows the dynamic linker
3566 // to treat compressed symbols like any other.
3567 Mips_address value
= isym
.get_st_value();
3568 if (mips_sym
->is_mips16() && value
!= 0)
3570 if (!mips_sym
->has_mips16_fn_stub())
3574 // If we have a MIPS16 function with a stub, the dynamic symbol
3575 // must refer to the stub, since only the stub uses the standard
3576 // calling conventions. Stub contains MIPS32 code, so don't add +1
3579 // There is a code which does this in the method
3580 // Target_mips::do_dynsym_value, but that code will only be
3581 // executed if the symbol is from dynobj.
3582 // TODO(sasa): GNU ld also changes the value in non-dynamic symbol
3585 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
3586 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
3587 value
= fn_stub
->output_address();
3588 osym
.put_st_size(fn_stub
->section_size());
3591 osym
.put_st_value(value
);
3592 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(),
3593 mips_sym
->nonvis() - (elfcpp::STO_MIPS16
>> 2)));
3595 else if ((mips_sym
->is_micromips()
3596 // Stubs are always microMIPS if there is any microMIPS code in
3598 || (this->is_output_micromips() && mips_sym
->has_lazy_stub()))
3601 osym
.put_st_value(value
| 1);
3602 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(),
3603 mips_sym
->nonvis() - (elfcpp::STO_MICROMIPS
>> 2)));
3608 // The class which scans relocations.
3616 get_reference_flags(unsigned int r_type
);
3619 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3620 Sized_relobj_file
<size
, big_endian
>* object
,
3621 unsigned int data_shndx
,
3622 Output_section
* output_section
,
3623 const Reltype
& reloc
, unsigned int r_type
,
3624 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3628 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3629 Sized_relobj_file
<size
, big_endian
>* object
,
3630 unsigned int data_shndx
,
3631 Output_section
* output_section
,
3632 const Relatype
& reloc
, unsigned int r_type
,
3633 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3637 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3638 Sized_relobj_file
<size
, big_endian
>* object
,
3639 unsigned int data_shndx
,
3640 Output_section
* output_section
,
3641 const Relatype
* rela
,
3643 unsigned int rel_type
,
3644 unsigned int r_type
,
3645 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3649 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3650 Sized_relobj_file
<size
, big_endian
>* object
,
3651 unsigned int data_shndx
,
3652 Output_section
* output_section
,
3653 const Reltype
& reloc
, unsigned int r_type
,
3657 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3658 Sized_relobj_file
<size
, big_endian
>* object
,
3659 unsigned int data_shndx
,
3660 Output_section
* output_section
,
3661 const Relatype
& reloc
, unsigned int r_type
,
3665 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3666 Sized_relobj_file
<size
, big_endian
>* object
,
3667 unsigned int data_shndx
,
3668 Output_section
* output_section
,
3669 const Relatype
* rela
,
3671 unsigned int rel_type
,
3672 unsigned int r_type
,
3676 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
*,
3678 Sized_relobj_file
<size
, big_endian
>*,
3683 const elfcpp::Sym
<size
, big_endian
>&)
3687 global_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3689 Sized_relobj_file
<size
, big_endian
>*,
3693 unsigned int, Symbol
*)
3697 local_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3699 Sized_relobj_file
<size
, big_endian
>*,
3704 const elfcpp::Sym
<size
, big_endian
>&)
3708 global_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3710 Sized_relobj_file
<size
, big_endian
>*,
3714 unsigned int, Symbol
*)
3718 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
3719 unsigned int r_type
);
3722 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
3723 unsigned int r_type
, Symbol
*);
3726 // The class which implements relocation.
3736 // Return whether a R_MIPS_32/R_MIPS_64 relocation needs to be applied.
3738 should_apply_static_reloc(const Mips_symbol
<size
>* gsym
,
3739 unsigned int r_type
,
3740 Output_section
* output_section
,
3741 Target_mips
* target
);
3743 // Do a relocation. Return false if the caller should not issue
3744 // any warnings about this relocation.
3746 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
3747 Target_mips
*, Output_section
*, size_t, const unsigned char*,
3748 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
3749 unsigned char*, Mips_address
, section_size_type
);
3752 // This POD class holds the dynamic relocations that should be emitted instead
3753 // of R_MIPS_32, R_MIPS_REL32 and R_MIPS_64 relocations. We will emit these
3754 // relocations if it turns out that the symbol does not have static
3759 Dyn_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
3760 Mips_relobj
<size
, big_endian
>* relobj
, unsigned int shndx
,
3761 Output_section
* output_section
, Mips_address r_offset
)
3762 : sym_(sym
), r_type_(r_type
), relobj_(relobj
),
3763 shndx_(shndx
), output_section_(output_section
),
3767 // Emit this reloc if appropriate. This is called after we have
3768 // scanned all the relocations, so we know whether the symbol has
3769 // static relocations.
3771 emit(Reloc_section
* rel_dyn
, Mips_output_data_got
<size
, big_endian
>* got
,
3772 Symbol_table
* symtab
)
3774 if (!this->sym_
->has_static_relocs())
3776 got
->record_global_got_symbol(this->sym_
, this->relobj_
,
3777 this->r_type_
, true, false);
3778 if (!symbol_references_local(this->sym_
,
3779 this->sym_
->should_add_dynsym_entry(symtab
)))
3780 rel_dyn
->add_global(this->sym_
, this->r_type_
,
3781 this->output_section_
, this->relobj_
,
3782 this->shndx_
, this->r_offset_
);
3784 rel_dyn
->add_symbolless_global_addend(this->sym_
, this->r_type_
,
3785 this->output_section_
, this->relobj_
,
3786 this->shndx_
, this->r_offset_
);
3791 Mips_symbol
<size
>* sym_
;
3792 unsigned int r_type_
;
3793 Mips_relobj
<size
, big_endian
>* relobj_
;
3794 unsigned int shndx_
;
3795 Output_section
* output_section_
;
3796 Mips_address r_offset_
;
3799 // Adjust TLS relocation type based on the options and whether this
3800 // is a local symbol.
3801 static tls::Tls_optimization
3802 optimize_tls_reloc(bool is_final
, int r_type
);
3804 // Return whether there is a GOT section.
3806 has_got_section() const
3807 { return this->got_
!= NULL
; }
3809 // Check whether the given ELF header flags describe a 32-bit binary.
3811 mips_32bit_flags(elfcpp::Elf_Word
);
3814 mach_mips3000
= 3000,
3815 mach_mips3900
= 3900,
3816 mach_mips4000
= 4000,
3817 mach_mips4010
= 4010,
3818 mach_mips4100
= 4100,
3819 mach_mips4111
= 4111,
3820 mach_mips4120
= 4120,
3821 mach_mips4300
= 4300,
3822 mach_mips4400
= 4400,
3823 mach_mips4600
= 4600,
3824 mach_mips4650
= 4650,
3825 mach_mips5000
= 5000,
3826 mach_mips5400
= 5400,
3827 mach_mips5500
= 5500,
3828 mach_mips6000
= 6000,
3829 mach_mips7000
= 7000,
3830 mach_mips8000
= 8000,
3831 mach_mips9000
= 9000,
3832 mach_mips10000
= 10000,
3833 mach_mips12000
= 12000,
3834 mach_mips14000
= 14000,
3835 mach_mips16000
= 16000,
3838 mach_mips_loongson_2e
= 3001,
3839 mach_mips_loongson_2f
= 3002,
3840 mach_mips_loongson_3a
= 3003,
3841 mach_mips_sb1
= 12310201, // octal 'SB', 01
3842 mach_mips_octeon
= 6501,
3843 mach_mips_octeonp
= 6601,
3844 mach_mips_octeon2
= 6502,
3845 mach_mips_xlr
= 887682, // decimal 'XLR'
3846 mach_mipsisa32
= 32,
3847 mach_mipsisa32r2
= 33,
3848 mach_mipsisa64
= 64,
3849 mach_mipsisa64r2
= 65,
3850 mach_mips_micromips
= 96
3853 // Return the MACH for a MIPS e_flags value.
3855 elf_mips_mach(elfcpp::Elf_Word
);
3857 // Check whether machine EXTENSION is an extension of machine BASE.
3859 mips_mach_extends(unsigned int, unsigned int);
3861 // Merge processor specific flags.
3863 merge_processor_specific_flags(const std::string
&, elfcpp::Elf_Word
,
3864 unsigned char, bool);
3866 // True if we are linking for CPUs that are faster if JAL is converted to BAL.
3871 // True if we are linking for CPUs that are faster if JALR is converted to
3872 // BAL. This should be safe for all architectures. We enable this predicate
3878 // True if we are linking for CPUs that are faster if JR is converted to B.
3879 // This should be safe for all architectures. We enable this predicate for
3885 // Return the size of the GOT section.
3889 gold_assert(this->got_
!= NULL
);
3890 return this->got_
->data_size();
3893 // Create a PLT entry for a global symbol referenced by r_type relocation.
3895 make_plt_entry(Symbol_table
*, Layout
*, Mips_symbol
<size
>*,
3896 unsigned int r_type
);
3898 // Get the PLT section.
3899 Mips_output_data_plt
<size
, big_endian
>*
3902 gold_assert(this->plt_
!= NULL
);
3906 // Get the GOT PLT section.
3907 const Mips_output_data_plt
<size
, big_endian
>*
3908 got_plt_section() const
3910 gold_assert(this->got_plt_
!= NULL
);
3911 return this->got_plt_
;
3914 // Copy a relocation against a global symbol.
3916 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
3917 Sized_relobj_file
<size
, big_endian
>* object
,
3918 unsigned int shndx
, Output_section
* output_section
,
3919 Symbol
* sym
, unsigned int r_type
, Mips_address r_offset
)
3921 this->copy_relocs_
.copy_reloc(symtab
, layout
,
3922 symtab
->get_sized_symbol
<size
>(sym
),
3923 object
, shndx
, output_section
,
3924 r_type
, r_offset
, 0,
3925 this->rel_dyn_section(layout
));
3929 dynamic_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
3930 Mips_relobj
<size
, big_endian
>* relobj
,
3931 unsigned int shndx
, Output_section
* output_section
,
3932 Mips_address r_offset
)
3934 this->dyn_relocs_
.push_back(Dyn_reloc(sym
, r_type
, relobj
, shndx
,
3935 output_section
, r_offset
));
3938 // Calculate value of _gp symbol.
3940 set_gp(Layout
*, Symbol_table
*);
3943 elf_mips_abi_name(elfcpp::Elf_Word e_flags
, unsigned char ei_class
);
3945 elf_mips_mach_name(elfcpp::Elf_Word e_flags
);
3947 // Adds entries that describe how machines relate to one another. The entries
3948 // are ordered topologically with MIPS I extensions listed last. First
3949 // element is extension, second element is base.
3951 add_machine_extensions()
3953 // MIPS64r2 extensions.
3954 this->add_extension(mach_mips_octeon2
, mach_mips_octeonp
);
3955 this->add_extension(mach_mips_octeonp
, mach_mips_octeon
);
3956 this->add_extension(mach_mips_octeon
, mach_mipsisa64r2
);
3958 // MIPS64 extensions.
3959 this->add_extension(mach_mipsisa64r2
, mach_mipsisa64
);
3960 this->add_extension(mach_mips_sb1
, mach_mipsisa64
);
3961 this->add_extension(mach_mips_xlr
, mach_mipsisa64
);
3962 this->add_extension(mach_mips_loongson_3a
, mach_mipsisa64
);
3964 // MIPS V extensions.
3965 this->add_extension(mach_mipsisa64
, mach_mips5
);
3967 // R10000 extensions.
3968 this->add_extension(mach_mips12000
, mach_mips10000
);
3969 this->add_extension(mach_mips14000
, mach_mips10000
);
3970 this->add_extension(mach_mips16000
, mach_mips10000
);
3972 // R5000 extensions. Note: the vr5500 ISA is an extension of the core
3973 // vr5400 ISA, but doesn't include the multimedia stuff. It seems
3974 // better to allow vr5400 and vr5500 code to be merged anyway, since
3975 // many libraries will just use the core ISA. Perhaps we could add
3976 // some sort of ASE flag if this ever proves a problem.
3977 this->add_extension(mach_mips5500
, mach_mips5400
);
3978 this->add_extension(mach_mips5400
, mach_mips5000
);
3980 // MIPS IV extensions.
3981 this->add_extension(mach_mips5
, mach_mips8000
);
3982 this->add_extension(mach_mips10000
, mach_mips8000
);
3983 this->add_extension(mach_mips5000
, mach_mips8000
);
3984 this->add_extension(mach_mips7000
, mach_mips8000
);
3985 this->add_extension(mach_mips9000
, mach_mips8000
);
3987 // VR4100 extensions.
3988 this->add_extension(mach_mips4120
, mach_mips4100
);
3989 this->add_extension(mach_mips4111
, mach_mips4100
);
3991 // MIPS III extensions.
3992 this->add_extension(mach_mips_loongson_2e
, mach_mips4000
);
3993 this->add_extension(mach_mips_loongson_2f
, mach_mips4000
);
3994 this->add_extension(mach_mips8000
, mach_mips4000
);
3995 this->add_extension(mach_mips4650
, mach_mips4000
);
3996 this->add_extension(mach_mips4600
, mach_mips4000
);
3997 this->add_extension(mach_mips4400
, mach_mips4000
);
3998 this->add_extension(mach_mips4300
, mach_mips4000
);
3999 this->add_extension(mach_mips4100
, mach_mips4000
);
4000 this->add_extension(mach_mips4010
, mach_mips4000
);
4002 // MIPS32 extensions.
4003 this->add_extension(mach_mipsisa32r2
, mach_mipsisa32
);
4005 // MIPS II extensions.
4006 this->add_extension(mach_mips4000
, mach_mips6000
);
4007 this->add_extension(mach_mipsisa32
, mach_mips6000
);
4009 // MIPS I extensions.
4010 this->add_extension(mach_mips6000
, mach_mips3000
);
4011 this->add_extension(mach_mips3900
, mach_mips3000
);
4014 // Add value to MIPS extenstions.
4016 add_extension(unsigned int base
, unsigned int extension
)
4018 std::pair
<unsigned int, unsigned int> ext(base
, extension
);
4019 this->mips_mach_extensions_
.push_back(ext
);
4022 // Return the number of entries in the .dynsym section.
4023 unsigned int get_dt_mips_symtabno() const
4025 return ((unsigned int)(this->layout_
->dynsym_section()->data_size()
4026 / elfcpp::Elf_sizes
<size
>::sym_size
));
4027 // TODO(sasa): Entry size is MIPS_ELF_SYM_SIZE.
4030 // Information about this specific target which we pass to the
4031 // general Target structure.
4032 static const Target::Target_info mips_info
;
4034 Mips_output_data_got
<size
, big_endian
>* got_
;
4035 // gp symbol. It has the value of .got + 0x7FF0.
4036 Sized_symbol
<size
>* gp_
;
4038 Mips_output_data_plt
<size
, big_endian
>* plt_
;
4039 // The GOT PLT section.
4040 Output_data_space
* got_plt_
;
4041 // The dynamic reloc section.
4042 Reloc_section
* rel_dyn_
;
4043 // Relocs saved to avoid a COPY reloc.
4044 Mips_copy_relocs
<elfcpp::SHT_REL
, size
, big_endian
> copy_relocs_
;
4046 // A list of dyn relocs to be saved.
4047 std::vector
<Dyn_reloc
> dyn_relocs_
;
4049 // The LA25 stub section.
4050 Mips_output_data_la25_stub
<size
, big_endian
>* la25_stub_
;
4051 // Architecture extensions.
4052 std::vector
<std::pair
<unsigned int, unsigned int> > mips_mach_extensions_
;
4054 Mips_output_data_mips_stubs
<size
, big_endian
>* mips_stubs_
;
4056 unsigned char ei_class_
;
4060 typename
std::list
<got16_addend
<size
, big_endian
> > got16_addends_
;
4062 // Whether the entry symbol is mips16 or micromips.
4063 bool entry_symbol_is_compressed_
;
4065 // Whether we can use only 32-bit microMIPS instructions.
4066 // TODO(sasa): This should be a linker option.
4070 // Helper structure for R_MIPS*_HI16/LO16 and R_MIPS*_GOT16/LO16 relocations.
4071 // It records high part of the relocation pair.
4073 template<int size
, bool big_endian
>
4076 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
4078 reloc_high(unsigned char* _view
, const Mips_relobj
<size
, big_endian
>* _object
,
4079 const Symbol_value
<size
>* _psymval
, Mips_address _addend
,
4080 unsigned int _r_type
, unsigned int _r_sym
, bool _extract_addend
,
4081 Mips_address _address
= 0, bool _gp_disp
= false)
4082 : view(_view
), object(_object
), psymval(_psymval
), addend(_addend
),
4083 r_type(_r_type
), r_sym(_r_sym
), extract_addend(_extract_addend
),
4084 address(_address
), gp_disp(_gp_disp
)
4087 unsigned char* view
;
4088 const Mips_relobj
<size
, big_endian
>* object
;
4089 const Symbol_value
<size
>* psymval
;
4090 Mips_address addend
;
4091 unsigned int r_type
;
4093 bool extract_addend
;
4094 Mips_address address
;
4098 template<int size
, bool big_endian
>
4099 class Mips_relocate_functions
: public Relocate_functions
<size
, big_endian
>
4101 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
4102 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
4103 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype16
;
4104 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
4105 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype64
;
4110 STATUS_OKAY
, // No error during relocation.
4111 STATUS_OVERFLOW
, // Relocation overflow.
4112 STATUS_BAD_RELOC
// Relocation cannot be applied.
4116 typedef Relocate_functions
<size
, big_endian
> Base
;
4117 typedef Mips_relocate_functions
<size
, big_endian
> This
;
4119 static typename
std::list
<reloc_high
<size
, big_endian
> > hi16_relocs
;
4120 static typename
std::list
<reloc_high
<size
, big_endian
> > got16_relocs
;
4122 template<int valsize
>
4123 static inline typename
This::Status
4124 check_overflow(Valtype value
)
4127 return (Bits
<valsize
>::has_overflow32(value
)
4128 ? This::STATUS_OVERFLOW
4129 : This::STATUS_OKAY
);
4131 return (Bits
<valsize
>::has_overflow(value
)
4132 ? This::STATUS_OVERFLOW
4133 : This::STATUS_OKAY
);
4137 should_shuffle_micromips_reloc(unsigned int r_type
)
4139 return (micromips_reloc(r_type
)
4140 && r_type
!= elfcpp::R_MICROMIPS_PC7_S1
4141 && r_type
!= elfcpp::R_MICROMIPS_PC10_S1
);
4145 // R_MIPS16_26 is used for the mips16 jal and jalx instructions.
4146 // Most mips16 instructions are 16 bits, but these instructions
4149 // The format of these instructions is:
4151 // +--------------+--------------------------------+
4152 // | JALX | X| Imm 20:16 | Imm 25:21 |
4153 // +--------------+--------------------------------+
4154 // | Immediate 15:0 |
4155 // +-----------------------------------------------+
4157 // JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
4158 // Note that the immediate value in the first word is swapped.
4160 // When producing a relocatable object file, R_MIPS16_26 is
4161 // handled mostly like R_MIPS_26. In particular, the addend is
4162 // stored as a straight 26-bit value in a 32-bit instruction.
4163 // (gas makes life simpler for itself by never adjusting a
4164 // R_MIPS16_26 reloc to be against a section, so the addend is
4165 // always zero). However, the 32 bit instruction is stored as 2
4166 // 16-bit values, rather than a single 32-bit value. In a
4167 // big-endian file, the result is the same; in a little-endian
4168 // file, the two 16-bit halves of the 32 bit value are swapped.
4169 // This is so that a disassembler can recognize the jal
4172 // When doing a final link, R_MIPS16_26 is treated as a 32 bit
4173 // instruction stored as two 16-bit values. The addend A is the
4174 // contents of the targ26 field. The calculation is the same as
4175 // R_MIPS_26. When storing the calculated value, reorder the
4176 // immediate value as shown above, and don't forget to store the
4177 // value as two 16-bit values.
4179 // To put it in MIPS ABI terms, the relocation field is T-targ26-16,
4183 // +--------+----------------------+
4187 // +--------+----------------------+
4190 // +----------+------+-------------+
4192 // | sub1 | | sub2 |
4193 // |0 9|10 15|16 31|
4194 // +----------+--------------------+
4195 // where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
4196 // ((sub1 << 16) | sub2)).
4198 // When producing a relocatable object file, the calculation is
4199 // (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
4200 // When producing a fully linked file, the calculation is
4201 // let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
4202 // ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
4204 // The table below lists the other MIPS16 instruction relocations.
4205 // Each one is calculated in the same way as the non-MIPS16 relocation
4206 // given on the right, but using the extended MIPS16 layout of 16-bit
4207 // immediate fields:
4209 // R_MIPS16_GPREL R_MIPS_GPREL16
4210 // R_MIPS16_GOT16 R_MIPS_GOT16
4211 // R_MIPS16_CALL16 R_MIPS_CALL16
4212 // R_MIPS16_HI16 R_MIPS_HI16
4213 // R_MIPS16_LO16 R_MIPS_LO16
4215 // A typical instruction will have a format like this:
4217 // +--------------+--------------------------------+
4218 // | EXTEND | Imm 10:5 | Imm 15:11 |
4219 // +--------------+--------------------------------+
4220 // | Major | rx | ry | Imm 4:0 |
4221 // +--------------+--------------------------------+
4223 // EXTEND is the five bit value 11110. Major is the instruction
4226 // All we need to do here is shuffle the bits appropriately.
4227 // As above, the two 16-bit halves must be swapped on a
4228 // little-endian system.
4230 // Similar to MIPS16, the two 16-bit halves in microMIPS must be swapped
4231 // on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1
4232 // and R_MICROMIPS_PC10_S1 relocs that apply to 16-bit instructions.
4235 mips_reloc_unshuffle(unsigned char* view
, unsigned int r_type
,
4238 if (!mips16_reloc(r_type
)
4239 && !should_shuffle_micromips_reloc(r_type
))
4242 // Pick up the first and second halfwords of the instruction.
4243 Valtype16 first
= elfcpp::Swap
<16, big_endian
>::readval(view
);
4244 Valtype16 second
= elfcpp::Swap
<16, big_endian
>::readval(view
+ 2);
4247 if (micromips_reloc(r_type
)
4248 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
4249 val
= first
<< 16 | second
;
4250 else if (r_type
!= elfcpp::R_MIPS16_26
)
4251 val
= (((first
& 0xf800) << 16) | ((second
& 0xffe0) << 11)
4252 | ((first
& 0x1f) << 11) | (first
& 0x7e0) | (second
& 0x1f));
4254 val
= (((first
& 0xfc00) << 16) | ((first
& 0x3e0) << 11)
4255 | ((first
& 0x1f) << 21) | second
);
4257 elfcpp::Swap
<32, big_endian
>::writeval(view
, val
);
4261 mips_reloc_shuffle(unsigned char* view
, unsigned int r_type
, bool jal_shuffle
)
4263 if (!mips16_reloc(r_type
)
4264 && !should_shuffle_micromips_reloc(r_type
))
4267 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4268 Valtype16 first
, second
;
4270 if (micromips_reloc(r_type
)
4271 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
4273 second
= val
& 0xffff;
4276 else if (r_type
!= elfcpp::R_MIPS16_26
)
4278 second
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
4279 first
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
4283 second
= val
& 0xffff;
4284 first
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
4285 | ((val
>> 21) & 0x1f);
4288 elfcpp::Swap
<16, big_endian
>::writeval(view
+ 2, second
);
4289 elfcpp::Swap
<16, big_endian
>::writeval(view
, first
);
4292 // R_MIPS_16: S + sign-extend(A)
4293 static inline typename
This::Status
4294 rel16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4295 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4296 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
4298 Valtype16
* wv
= reinterpret_cast<Valtype16
*>(view
);
4299 Valtype16 val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
4301 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
)
4304 Valtype x
= psymval
->value(object
, addend
);
4305 val
= Bits
<16>::bit_select32(val
, x
, 0xffffU
);
4309 *calculated_value
= x
;
4310 return This::STATUS_OKAY
;
4313 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
4315 return check_overflow
<16>(x
);
4319 static inline typename
This::Status
4320 rel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4321 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4322 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
4324 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4325 Valtype addend
= (extract_addend
4326 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
4328 Valtype x
= psymval
->value(object
, addend
);
4331 *calculated_value
= x
;
4333 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4335 return This::STATUS_OKAY
;
4338 // R_MIPS_JALR, R_MICROMIPS_JALR
4339 static inline typename
This::Status
4340 reljalr(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4341 const Symbol_value
<size
>* psymval
, Mips_address address
,
4342 Mips_address addend_a
, bool extract_addend
, bool cross_mode_jump
,
4343 unsigned int r_type
, bool jalr_to_bal
, bool jr_to_b
,
4344 bool calculate_only
, Valtype
* calculated_value
)
4346 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4347 Valtype addend
= extract_addend
? 0 : addend_a
;
4348 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4350 // Try converting J(AL)R to B(AL), if the target is in range.
4351 if (!parameters
->options().relocatable()
4352 && r_type
== elfcpp::R_MIPS_JALR
4354 && ((jalr_to_bal
&& val
== 0x0320f809) // jalr t9
4355 || (jr_to_b
&& val
== 0x03200008))) // jr t9
4357 int offset
= psymval
->value(object
, addend
) - (address
+ 4);
4358 if (!Bits
<18>::has_overflow32(offset
))
4360 if (val
== 0x03200008) // jr t9
4361 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4363 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4368 *calculated_value
= val
;
4370 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4372 return This::STATUS_OKAY
;
4375 // R_MIPS_PC32: S + A - P
4376 static inline typename
This::Status
4377 relpc32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4378 const Symbol_value
<size
>* psymval
, Mips_address address
,
4379 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4380 Valtype
* calculated_value
)
4382 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4383 Valtype addend
= (extract_addend
4384 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
4386 Valtype x
= psymval
->value(object
, addend
) - address
;
4389 *calculated_value
= x
;
4391 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4393 return This::STATUS_OKAY
;
4396 // R_MIPS_26, R_MIPS16_26, R_MICROMIPS_26_S1
4397 static inline typename
This::Status
4398 rel26(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4399 const Symbol_value
<size
>* psymval
, Mips_address address
,
4400 bool local
, Mips_address addend_a
, bool extract_addend
,
4401 const Symbol
* gsym
, bool cross_mode_jump
, unsigned int r_type
,
4402 bool jal_to_bal
, bool calculate_only
, Valtype
* calculated_value
)
4404 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4405 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4410 if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4411 addend
= (val
& 0x03ffffff) << 1;
4413 addend
= (val
& 0x03ffffff) << 2;
4418 // Make sure the target of JALX is word-aligned. Bit 0 must be
4419 // the correct ISA mode selector and bit 1 must be 0.
4420 if (!calculate_only
&& cross_mode_jump
4421 && (psymval
->value(object
, 0) & 3) != (r_type
== elfcpp::R_MIPS_26
))
4423 gold_warning(_("JALX to a non-word-aligned address"));
4424 return This::STATUS_BAD_RELOC
;
4427 // Shift is 2, unusually, for microMIPS JALX.
4428 unsigned int shift
=
4429 (!cross_mode_jump
&& r_type
== elfcpp::R_MICROMIPS_26_S1
) ? 1 : 2;
4433 x
= addend
| ((address
+ 4) & (0xfc000000 << shift
));
4437 x
= Bits
<27>::sign_extend32(addend
);
4439 x
= Bits
<28>::sign_extend32(addend
);
4441 x
= psymval
->value(object
, x
) >> shift
;
4443 if (!calculate_only
&& !local
&& !gsym
->is_weak_undefined())
4445 if ((x
>> 26) != ((address
+ 4) >> (26 + shift
)))
4447 gold_error(_("relocation truncated to fit: %u against '%s'"),
4448 r_type
, gsym
->name());
4449 return This::STATUS_OVERFLOW
;
4453 val
= Bits
<32>::bit_select32(val
, x
, 0x03ffffff);
4455 // If required, turn JAL into JALX.
4456 if (cross_mode_jump
)
4459 Valtype32 opcode
= val
>> 26;
4460 Valtype32 jalx_opcode
;
4462 // Check to see if the opcode is already JAL or JALX.
4463 if (r_type
== elfcpp::R_MIPS16_26
)
4465 ok
= (opcode
== 0x6) || (opcode
== 0x7);
4468 else if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4470 ok
= (opcode
== 0x3d) || (opcode
== 0x3c);
4475 ok
= (opcode
== 0x3) || (opcode
== 0x1d);
4479 // If the opcode is not JAL or JALX, there's a problem. We cannot
4480 // convert J or JALS to JALX.
4481 if (!calculate_only
&& !ok
)
4483 gold_error(_("Unsupported jump between ISA modes; consider "
4484 "recompiling with interlinking enabled."));
4485 return This::STATUS_BAD_RELOC
;
4488 // Make this the JALX opcode.
4489 val
= (val
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
4492 // Try converting JAL to BAL, if the target is in range.
4493 if (!parameters
->options().relocatable()
4496 && r_type
== elfcpp::R_MIPS_26
4497 && (val
>> 26) == 0x3))) // jal addr
4499 Valtype32 dest
= (x
<< 2) | (((address
+ 4) >> 28) << 28);
4500 int offset
= dest
- (address
+ 4);
4501 if (!Bits
<18>::has_overflow32(offset
))
4503 if (val
== 0x03200008) // jr t9
4504 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4506 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4511 *calculated_value
= val
;
4513 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4515 return This::STATUS_OKAY
;
4519 static inline typename
This::Status
4520 relpc16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4521 const Symbol_value
<size
>* psymval
, Mips_address address
,
4522 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4523 Valtype
* calculated_value
)
4525 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4526 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4528 Valtype addend
= (extract_addend
4529 ? Bits
<18>::sign_extend32((val
& 0xffff) << 2)
4532 Valtype x
= psymval
->value(object
, addend
) - address
;
4533 val
= Bits
<16>::bit_select32(val
, x
>> 2, 0xffff);
4537 *calculated_value
= x
>> 2;
4538 return This::STATUS_OKAY
;
4541 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4543 return check_overflow
<18>(x
);
4546 // R_MICROMIPS_PC7_S1
4547 static inline typename
This::Status
4548 relmicromips_pc7_s1(unsigned char* view
,
4549 const Mips_relobj
<size
, big_endian
>* object
,
4550 const Symbol_value
<size
>* psymval
, Mips_address address
,
4551 Mips_address addend_a
, bool extract_addend
,
4552 bool calculate_only
, Valtype
* calculated_value
)
4554 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4555 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4557 Valtype addend
= extract_addend
? Bits
<8>::sign_extend32((val
& 0x7f) << 1)
4560 Valtype x
= psymval
->value(object
, addend
) - address
;
4561 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x7f);
4565 *calculated_value
= x
>> 1;
4566 return This::STATUS_OKAY
;
4569 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4571 return check_overflow
<8>(x
);
4574 // R_MICROMIPS_PC10_S1
4575 static inline typename
This::Status
4576 relmicromips_pc10_s1(unsigned char* view
,
4577 const Mips_relobj
<size
, big_endian
>* object
,
4578 const Symbol_value
<size
>* psymval
, Mips_address address
,
4579 Mips_address addend_a
, bool extract_addend
,
4580 bool calculate_only
, Valtype
* calculated_value
)
4582 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4583 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4585 Valtype addend
= (extract_addend
4586 ? Bits
<11>::sign_extend32((val
& 0x3ff) << 1)
4589 Valtype x
= psymval
->value(object
, addend
) - address
;
4590 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x3ff);
4594 *calculated_value
= x
>> 1;
4595 return This::STATUS_OKAY
;
4598 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4600 return check_overflow
<11>(x
);
4603 // R_MICROMIPS_PC16_S1
4604 static inline typename
This::Status
4605 relmicromips_pc16_s1(unsigned char* view
,
4606 const Mips_relobj
<size
, big_endian
>* object
,
4607 const Symbol_value
<size
>* psymval
, Mips_address address
,
4608 Mips_address addend_a
, bool extract_addend
,
4609 bool calculate_only
, Valtype
* calculated_value
)
4611 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4612 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4614 Valtype addend
= (extract_addend
4615 ? Bits
<17>::sign_extend32((val
& 0xffff) << 1)
4618 Valtype x
= psymval
->value(object
, addend
) - address
;
4619 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0xffff);
4623 *calculated_value
= x
>> 1;
4624 return This::STATUS_OKAY
;
4627 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4629 return check_overflow
<17>(x
);
4632 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
4633 static inline typename
This::Status
4634 relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4635 const Symbol_value
<size
>* psymval
, Mips_address addend
,
4636 Mips_address address
, bool gp_disp
, unsigned int r_type
,
4637 unsigned int r_sym
, bool extract_addend
)
4639 // Record the relocation. It will be resolved when we find lo16 part.
4640 hi16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
4641 addend
, r_type
, r_sym
, extract_addend
, address
,
4643 return This::STATUS_OKAY
;
4646 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
4647 static inline typename
This::Status
4648 do_relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4649 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
4650 Mips_address address
, bool is_gp_disp
, unsigned int r_type
,
4651 bool extract_addend
, Valtype32 addend_lo
,
4652 Target_mips
<size
, big_endian
>* target
, bool calculate_only
,
4653 Valtype
* calculated_value
)
4655 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4656 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4658 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
4663 value
= psymval
->value(object
, addend
);
4666 // For MIPS16 ABI code we generate this sequence
4667 // 0: li $v0,%hi(_gp_disp)
4668 // 4: addiupc $v1,%lo(_gp_disp)
4672 // So the offsets of hi and lo relocs are the same, but the
4673 // base $pc is that used by the ADDIUPC instruction at $t9 + 4.
4674 // ADDIUPC clears the low two bits of the instruction address,
4675 // so the base is ($t9 + 4) & ~3.
4677 if (r_type
== elfcpp::R_MIPS16_HI16
)
4678 gp_disp
= (target
->adjusted_gp_value(object
)
4679 - ((address
+ 4) & ~0x3));
4680 // The microMIPS .cpload sequence uses the same assembly
4681 // instructions as the traditional psABI version, but the
4682 // incoming $t9 has the low bit set.
4683 else if (r_type
== elfcpp::R_MICROMIPS_HI16
)
4684 gp_disp
= target
->adjusted_gp_value(object
) - address
- 1;
4686 gp_disp
= target
->adjusted_gp_value(object
) - address
;
4687 value
= gp_disp
+ addend
;
4689 Valtype x
= ((value
+ 0x8000) >> 16) & 0xffff;
4690 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4694 *calculated_value
= x
;
4695 return This::STATUS_OKAY
;
4698 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4700 return (is_gp_disp
? check_overflow
<16>(x
)
4701 : This::STATUS_OKAY
);
4704 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4705 static inline typename
This::Status
4706 relgot16_local(unsigned char* view
,
4707 const Mips_relobj
<size
, big_endian
>* object
,
4708 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4709 bool extract_addend
, unsigned int r_type
, unsigned int r_sym
)
4711 // Record the relocation. It will be resolved when we find lo16 part.
4712 got16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
4713 addend_a
, r_type
, r_sym
, extract_addend
));
4714 return This::STATUS_OKAY
;
4717 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4718 static inline typename
This::Status
4719 do_relgot16_local(unsigned char* view
,
4720 const Mips_relobj
<size
, big_endian
>* object
,
4721 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
4722 bool extract_addend
, Valtype32 addend_lo
,
4723 Target_mips
<size
, big_endian
>* target
, bool calculate_only
,
4724 Valtype
* calculated_value
)
4726 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4727 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4729 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
4732 // Find GOT page entry.
4733 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000) >> 16)
4736 unsigned int got_offset
=
4737 target
->got_section()->get_got_page_offset(value
, object
);
4739 // Resolve the relocation.
4740 Valtype x
= target
->got_section()->gp_offset(got_offset
, object
);
4741 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4745 *calculated_value
= x
;
4746 return This::STATUS_OKAY
;
4749 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4751 return check_overflow
<16>(x
);
4754 // R_MIPS_LO16, R_MIPS16_LO16, R_MICROMIPS_LO16, R_MICROMIPS_HI0_LO16
4755 static inline typename
This::Status
4756 rello16(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4757 const Mips_relobj
<size
, big_endian
>* object
,
4758 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4759 bool extract_addend
, Mips_address address
, bool is_gp_disp
,
4760 unsigned int r_type
, unsigned int r_sym
, unsigned int rel_type
,
4761 bool calculate_only
, Valtype
* calculated_value
)
4763 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4764 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4766 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
4769 if (rel_type
== elfcpp::SHT_REL
)
4771 typename
This::Status reloc_status
= This::STATUS_OKAY
;
4772 // Resolve pending R_MIPS_HI16 relocations.
4773 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it
=
4774 hi16_relocs
.begin();
4775 while (it
!= hi16_relocs
.end())
4777 reloc_high
<size
, big_endian
> hi16
= *it
;
4778 if (hi16
.r_sym
== r_sym
4779 && is_matching_lo16_reloc(hi16
.r_type
, r_type
))
4781 mips_reloc_unshuffle(hi16
.view
, hi16
.r_type
, false);
4782 reloc_status
= do_relhi16(hi16
.view
, hi16
.object
, hi16
.psymval
,
4783 hi16
.addend
, hi16
.address
, hi16
.gp_disp
,
4784 hi16
.r_type
, hi16
.extract_addend
, addend
,
4785 target
, calculate_only
, calculated_value
);
4786 mips_reloc_shuffle(hi16
.view
, hi16
.r_type
, false);
4787 if (reloc_status
== This::STATUS_OVERFLOW
)
4788 return This::STATUS_OVERFLOW
;
4789 it
= hi16_relocs
.erase(it
);
4795 // Resolve pending local R_MIPS_GOT16 relocations.
4796 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it2
=
4797 got16_relocs
.begin();
4798 while (it2
!= got16_relocs
.end())
4800 reloc_high
<size
, big_endian
> got16
= *it2
;
4801 if (got16
.r_sym
== r_sym
4802 && is_matching_lo16_reloc(got16
.r_type
, r_type
))
4804 mips_reloc_unshuffle(got16
.view
, got16
.r_type
, false);
4806 reloc_status
= do_relgot16_local(got16
.view
, got16
.object
,
4807 got16
.psymval
, got16
.addend
,
4808 got16
.extract_addend
, addend
, target
,
4809 calculate_only
, calculated_value
);
4811 mips_reloc_shuffle(got16
.view
, got16
.r_type
, false);
4812 if (reloc_status
== This::STATUS_OVERFLOW
)
4813 return This::STATUS_OVERFLOW
;
4814 it2
= got16_relocs
.erase(it2
);
4821 // Resolve R_MIPS_LO16 relocation.
4824 x
= psymval
->value(object
, addend
);
4827 // See the comment for R_MIPS16_HI16 above for the reason
4828 // for this conditional.
4830 if (r_type
== elfcpp::R_MIPS16_LO16
)
4831 gp_disp
= target
->adjusted_gp_value(object
) - (address
& ~0x3);
4832 else if (r_type
== elfcpp::R_MICROMIPS_LO16
4833 || r_type
== elfcpp::R_MICROMIPS_HI0_LO16
)
4834 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 3;
4836 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 4;
4837 // The MIPS ABI requires checking the R_MIPS_LO16 relocation
4838 // for overflow. Relocations against _gp_disp are normally
4839 // generated from the .cpload pseudo-op. It generates code
4840 // that normally looks like this:
4842 // lui $gp,%hi(_gp_disp)
4843 // addiu $gp,$gp,%lo(_gp_disp)
4846 // Here $t9 holds the address of the function being called,
4847 // as required by the MIPS ELF ABI. The R_MIPS_LO16
4848 // relocation can easily overflow in this situation, but the
4849 // R_MIPS_HI16 relocation will handle the overflow.
4850 // Therefore, we consider this a bug in the MIPS ABI, and do
4851 // not check for overflow here.
4852 x
= gp_disp
+ addend
;
4854 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4857 *calculated_value
= x
;
4859 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4861 return This::STATUS_OKAY
;
4864 // R_MIPS_CALL16, R_MIPS16_CALL16, R_MICROMIPS_CALL16
4865 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4866 // R_MIPS_TLS_GD, R_MIPS16_TLS_GD, R_MICROMIPS_TLS_GD
4867 // R_MIPS_TLS_GOTTPREL, R_MIPS16_TLS_GOTTPREL, R_MICROMIPS_TLS_GOTTPREL
4868 // R_MIPS_TLS_LDM, R_MIPS16_TLS_LDM, R_MICROMIPS_TLS_LDM
4869 // R_MIPS_GOT_DISP, R_MICROMIPS_GOT_DISP
4870 static inline typename
This::Status
4871 relgot(unsigned char* view
, int gp_offset
, bool calculate_only
,
4872 Valtype
* calculated_value
)
4874 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4875 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4876 Valtype x
= gp_offset
;
4877 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4881 *calculated_value
= x
;
4882 return This::STATUS_OKAY
;
4885 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4887 return check_overflow
<16>(x
);
4891 static inline typename
This::Status
4892 releh(unsigned char* view
, int gp_offset
, bool calculate_only
,
4893 Valtype
* calculated_value
)
4895 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4896 Valtype x
= gp_offset
;
4900 *calculated_value
= x
;
4901 return This::STATUS_OKAY
;
4904 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4906 return check_overflow
<32>(x
);
4909 // R_MIPS_GOT_PAGE, R_MICROMIPS_GOT_PAGE
4910 static inline typename
This::Status
4911 relgotpage(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4912 const Mips_relobj
<size
, big_endian
>* object
,
4913 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4914 bool extract_addend
, bool calculate_only
,
4915 Valtype
* calculated_value
)
4917 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4918 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4919 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
4921 // Find a GOT page entry that points to within 32KB of symbol + addend.
4922 Mips_address value
= (psymval
->value(object
, addend
) + 0x8000) & ~0xffff;
4923 unsigned int got_offset
=
4924 target
->got_section()->get_got_page_offset(value
, object
);
4926 Valtype x
= target
->got_section()->gp_offset(got_offset
, object
);
4927 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4931 *calculated_value
= x
;
4932 return This::STATUS_OKAY
;
4935 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4937 return check_overflow
<16>(x
);
4940 // R_MIPS_GOT_OFST, R_MICROMIPS_GOT_OFST
4941 static inline typename
This::Status
4942 relgotofst(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4943 const Mips_relobj
<size
, big_endian
>* object
,
4944 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4945 bool extract_addend
, bool local
, bool calculate_only
,
4946 Valtype
* calculated_value
)
4948 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4949 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4950 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
4952 // For a local symbol, find a GOT page entry that points to within 32KB of
4953 // symbol + addend. Relocation value is the offset of the GOT page entry's
4954 // value from symbol + addend.
4955 // For a global symbol, relocation value is addend.
4959 // Find GOT page entry.
4960 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000)
4962 target
->got_section()->get_got_page_offset(value
, object
);
4964 x
= psymval
->value(object
, addend
) - value
;
4968 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4972 *calculated_value
= x
;
4973 return This::STATUS_OKAY
;
4976 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4978 return check_overflow
<16>(x
);
4981 // R_MIPS_GOT_HI16, R_MIPS_CALL_HI16,
4982 // R_MICROMIPS_GOT_HI16, R_MICROMIPS_CALL_HI16
4983 static inline typename
This::Status
4984 relgot_hi16(unsigned char* view
, int gp_offset
, bool calculate_only
,
4985 Valtype
* calculated_value
)
4987 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4988 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4989 Valtype x
= gp_offset
;
4990 x
= ((x
+ 0x8000) >> 16) & 0xffff;
4991 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4994 *calculated_value
= x
;
4996 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4998 return This::STATUS_OKAY
;
5001 // R_MIPS_GOT_LO16, R_MIPS_CALL_LO16,
5002 // R_MICROMIPS_GOT_LO16, R_MICROMIPS_CALL_LO16
5003 static inline typename
This::Status
5004 relgot_lo16(unsigned char* view
, int gp_offset
, bool calculate_only
,
5005 Valtype
* calculated_value
)
5007 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5008 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5009 Valtype x
= gp_offset
;
5010 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5013 *calculated_value
= x
;
5015 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5017 return This::STATUS_OKAY
;
5020 // R_MIPS_GPREL16, R_MIPS16_GPREL, R_MIPS_LITERAL, R_MICROMIPS_LITERAL
5021 // R_MICROMIPS_GPREL7_S2, R_MICROMIPS_GPREL16
5022 static inline typename
This::Status
5023 relgprel(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5024 const Symbol_value
<size
>* psymval
, Mips_address gp
,
5025 Mips_address addend_a
, bool extract_addend
, bool local
,
5026 unsigned int r_type
, bool calculate_only
,
5027 Valtype
* calculated_value
)
5029 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5030 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5035 if (r_type
== elfcpp::R_MICROMIPS_GPREL7_S2
)
5036 addend
= (val
& 0x7f) << 2;
5038 addend
= val
& 0xffff;
5039 // Only sign-extend the addend if it was extracted from the
5040 // instruction. If the addend was separate, leave it alone,
5041 // otherwise we may lose significant bits.
5042 addend
= Bits
<16>::sign_extend32(addend
);
5047 Valtype x
= psymval
->value(object
, addend
) - gp
;
5049 // If the symbol was local, any earlier relocatable links will
5050 // have adjusted its addend with the gp offset, so compensate
5051 // for that now. Don't do it for symbols forced local in this
5052 // link, though, since they won't have had the gp offset applied
5055 x
+= object
->gp_value();
5057 if (r_type
== elfcpp::R_MICROMIPS_GPREL7_S2
)
5058 val
= Bits
<32>::bit_select32(val
, x
, 0x7f);
5060 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5064 *calculated_value
= x
;
5065 return This::STATUS_OKAY
;
5068 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5070 if (check_overflow
<16>(x
) == This::STATUS_OVERFLOW
)
5072 gold_error(_("small-data section exceeds 64KB; lower small-data size "
5073 "limit (see option -G)"));
5074 return This::STATUS_OVERFLOW
;
5076 return This::STATUS_OKAY
;
5080 static inline typename
This::Status
5081 relgprel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5082 const Symbol_value
<size
>* psymval
, Mips_address gp
,
5083 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5084 Valtype
* calculated_value
)
5086 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5087 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5088 Valtype addend
= extract_addend
? val
: addend_a
;
5090 // R_MIPS_GPREL32 relocations are defined for local symbols only.
5091 Valtype x
= psymval
->value(object
, addend
) + object
->gp_value() - gp
;
5094 *calculated_value
= x
;
5096 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5098 return This::STATUS_OKAY
;
5101 // R_MIPS_TLS_TPREL_HI16, R_MIPS16_TLS_TPREL_HI16, R_MICROMIPS_TLS_TPREL_HI16
5102 // R_MIPS_TLS_DTPREL_HI16, R_MIPS16_TLS_DTPREL_HI16,
5103 // R_MICROMIPS_TLS_DTPREL_HI16
5104 static inline typename
This::Status
5105 tlsrelhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5106 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5107 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5108 Valtype
* calculated_value
)
5110 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5111 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5112 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5114 // tls symbol values are relative to tls_segment()->vaddr()
5115 Valtype x
= ((psymval
->value(object
, addend
) - tp_offset
) + 0x8000) >> 16;
5116 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5119 *calculated_value
= x
;
5121 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5123 return This::STATUS_OKAY
;
5126 // R_MIPS_TLS_TPREL_LO16, R_MIPS16_TLS_TPREL_LO16, R_MICROMIPS_TLS_TPREL_LO16,
5127 // R_MIPS_TLS_DTPREL_LO16, R_MIPS16_TLS_DTPREL_LO16,
5128 // R_MICROMIPS_TLS_DTPREL_LO16,
5129 static inline typename
This::Status
5130 tlsrello16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5131 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5132 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5133 Valtype
* calculated_value
)
5135 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5136 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5137 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5139 // tls symbol values are relative to tls_segment()->vaddr()
5140 Valtype x
= psymval
->value(object
, addend
) - tp_offset
;
5141 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5144 *calculated_value
= x
;
5146 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5148 return This::STATUS_OKAY
;
5151 // R_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL64,
5152 // R_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL64
5153 static inline typename
This::Status
5154 tlsrel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5155 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5156 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5157 Valtype
* calculated_value
)
5159 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5160 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5161 Valtype addend
= extract_addend
? val
: addend_a
;
5163 // tls symbol values are relative to tls_segment()->vaddr()
5164 Valtype x
= psymval
->value(object
, addend
) - tp_offset
;
5167 *calculated_value
= x
;
5169 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5171 return This::STATUS_OKAY
;
5174 // R_MIPS_SUB, R_MICROMIPS_SUB
5175 static inline typename
This::Status
5176 relsub(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5177 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5178 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
5180 Valtype64
* wv
= reinterpret_cast<Valtype64
*>(view
);
5181 Valtype64 addend
= (extract_addend
5182 ? elfcpp::Swap
<64, big_endian
>::readval(wv
)
5185 Valtype64 x
= psymval
->value(object
, -addend
);
5187 *calculated_value
= x
;
5189 elfcpp::Swap
<64, big_endian
>::writeval(wv
, x
);
5191 return This::STATUS_OKAY
;
5195 static inline typename
This::Status
5196 rel64(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5197 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5198 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
,
5199 bool apply_addend_only
)
5201 Valtype64
* wv
= reinterpret_cast<Valtype64
*>(view
);
5202 Valtype64 addend
= (extract_addend
5203 ? elfcpp::Swap
<64, big_endian
>::readval(wv
)
5206 Valtype64 x
= psymval
->value(object
, addend
);
5208 *calculated_value
= x
;
5211 if (apply_addend_only
)
5213 elfcpp::Swap
<64, big_endian
>::writeval(wv
, x
);
5216 return This::STATUS_OKAY
;
5221 template<int size
, bool big_endian
>
5222 typename
std::list
<reloc_high
<size
, big_endian
> >
5223 Mips_relocate_functions
<size
, big_endian
>::hi16_relocs
;
5225 template<int size
, bool big_endian
>
5226 typename
std::list
<reloc_high
<size
, big_endian
> >
5227 Mips_relocate_functions
<size
, big_endian
>::got16_relocs
;
5229 // Mips_got_info methods.
5231 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
5232 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
5234 template<int size
, bool big_endian
>
5236 Mips_got_info
<size
, big_endian
>::record_local_got_symbol(
5237 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
,
5238 Mips_address addend
, unsigned int r_type
, unsigned int shndx
,
5239 bool is_section_symbol
)
5241 Mips_got_entry
<size
, big_endian
>* entry
=
5242 new Mips_got_entry
<size
, big_endian
>(object
, symndx
, addend
,
5243 mips_elf_reloc_tls_type(r_type
),
5244 shndx
, is_section_symbol
);
5245 this->record_got_entry(entry
, object
);
5248 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
5249 // in OBJECT. FOR_CALL is true if the caller is only interested in
5250 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
5253 template<int size
, bool big_endian
>
5255 Mips_got_info
<size
, big_endian
>::record_global_got_symbol(
5256 Mips_symbol
<size
>* mips_sym
, Mips_relobj
<size
, big_endian
>* object
,
5257 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
5260 mips_sym
->set_got_not_only_for_calls();
5262 // A global symbol in the GOT must also be in the dynamic symbol table.
5263 if (!mips_sym
->needs_dynsym_entry())
5265 switch (mips_sym
->visibility())
5267 case elfcpp::STV_INTERNAL
:
5268 case elfcpp::STV_HIDDEN
:
5269 mips_sym
->set_is_forced_local();
5272 mips_sym
->set_needs_dynsym_entry();
5277 unsigned char tls_type
= mips_elf_reloc_tls_type(r_type
);
5278 if (tls_type
== GOT_TLS_NONE
)
5279 this->global_got_symbols_
.insert(mips_sym
);
5283 if (mips_sym
->global_got_area() == GGA_NONE
)
5284 mips_sym
->set_global_got_area(GGA_RELOC_ONLY
);
5288 Mips_got_entry
<size
, big_endian
>* entry
=
5289 new Mips_got_entry
<size
, big_endian
>(object
, mips_sym
, tls_type
);
5291 this->record_got_entry(entry
, object
);
5294 // Add ENTRY to master GOT and to OBJECT's GOT.
5296 template<int size
, bool big_endian
>
5298 Mips_got_info
<size
, big_endian
>::record_got_entry(
5299 Mips_got_entry
<size
, big_endian
>* entry
,
5300 Mips_relobj
<size
, big_endian
>* object
)
5302 if (this->got_entries_
.find(entry
) == this->got_entries_
.end())
5303 this->got_entries_
.insert(entry
);
5305 // Create the GOT entry for the OBJECT's GOT.
5306 Mips_got_info
<size
, big_endian
>* g
= object
->get_or_create_got_info();
5307 Mips_got_entry
<size
, big_endian
>* entry2
=
5308 new Mips_got_entry
<size
, big_endian
>(*entry
);
5310 if (g
->got_entries_
.find(entry2
) == g
->got_entries_
.end())
5311 g
->got_entries_
.insert(entry2
);
5314 // Record that OBJECT has a page relocation against symbol SYMNDX and
5315 // that ADDEND is the addend for that relocation.
5316 // This function creates an upper bound on the number of GOT slots
5317 // required; no attempt is made to combine references to non-overridable
5318 // global symbols across multiple input files.
5320 template<int size
, bool big_endian
>
5322 Mips_got_info
<size
, big_endian
>::record_got_page_entry(
5323 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
, int addend
)
5325 struct Got_page_range
**range_ptr
, *range
;
5326 int old_pages
, new_pages
;
5328 // Find the Got_page_entry for this symbol.
5329 Got_page_entry
* entry
= new Got_page_entry(object
, symndx
);
5330 typename
Got_page_entry_set::iterator it
=
5331 this->got_page_entries_
.find(entry
);
5332 if (it
!= this->got_page_entries_
.end())
5335 this->got_page_entries_
.insert(entry
);
5337 // Add the same entry to the OBJECT's GOT.
5338 Got_page_entry
* entry2
= NULL
;
5339 Mips_got_info
<size
, big_endian
>* g2
= object
->get_or_create_got_info();
5340 if (g2
->got_page_entries_
.find(entry
) == g2
->got_page_entries_
.end())
5342 entry2
= new Got_page_entry(*entry
);
5343 g2
->got_page_entries_
.insert(entry2
);
5346 // Skip over ranges whose maximum extent cannot share a page entry
5348 range_ptr
= &entry
->ranges
;
5349 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
5350 range_ptr
= &(*range_ptr
)->next
;
5352 // If we scanned to the end of the list, or found a range whose
5353 // minimum extent cannot share a page entry with ADDEND, create
5354 // a new singleton range.
5356 if (!range
|| addend
< range
->min_addend
- 0xffff)
5358 range
= new Got_page_range();
5359 range
->next
= *range_ptr
;
5360 range
->min_addend
= addend
;
5361 range
->max_addend
= addend
;
5366 ++entry2
->num_pages
;
5367 ++this->page_gotno_
;
5372 // Remember how many pages the old range contributed.
5373 old_pages
= range
->get_max_pages();
5375 // Update the ranges.
5376 if (addend
< range
->min_addend
)
5377 range
->min_addend
= addend
;
5378 else if (addend
> range
->max_addend
)
5380 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
5382 old_pages
+= range
->next
->get_max_pages();
5383 range
->max_addend
= range
->next
->max_addend
;
5384 range
->next
= range
->next
->next
;
5387 range
->max_addend
= addend
;
5390 // Record any change in the total estimate.
5391 new_pages
= range
->get_max_pages();
5392 if (old_pages
!= new_pages
)
5394 entry
->num_pages
+= new_pages
- old_pages
;
5396 entry2
->num_pages
+= new_pages
- old_pages
;
5397 this->page_gotno_
+= new_pages
- old_pages
;
5398 g2
->page_gotno_
+= new_pages
- old_pages
;
5402 // Create all entries that should be in the local part of the GOT.
5404 template<int size
, bool big_endian
>
5406 Mips_got_info
<size
, big_endian
>::add_local_entries(
5407 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5409 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5410 // First two GOT entries are reserved. The first entry will be filled at
5411 // runtime. The second entry will be used by some runtime loaders.
5412 got
->add_constant(0);
5413 got
->add_constant(target
->mips_elf_gnu_got1_mask());
5415 for (typename
Got_entry_set::iterator
5416 p
= this->got_entries_
.begin();
5417 p
!= this->got_entries_
.end();
5420 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5421 if (entry
->is_for_local_symbol() && !entry
->is_tls_entry())
5423 got
->add_local(entry
->object(), entry
->symndx(),
5424 GOT_TYPE_STANDARD
, entry
->addend());
5425 unsigned int got_offset
= entry
->object()->local_got_offset(
5426 entry
->symndx(), GOT_TYPE_STANDARD
, entry
->addend());
5427 if (got
->multi_got() && this->index_
> 0
5428 && parameters
->options().output_is_position_independent())
5430 if (!entry
->is_section_symbol())
5431 target
->rel_dyn_section(layout
)->add_local(entry
->object(),
5432 entry
->symndx(), elfcpp::R_MIPS_REL32
, got
, got_offset
);
5434 target
->rel_dyn_section(layout
)->add_symbolless_local_addend(
5435 entry
->object(), entry
->symndx(), elfcpp::R_MIPS_REL32
,
5441 this->add_page_entries(target
, layout
);
5443 // Add global entries that should be in the local area.
5444 for (typename
Got_entry_set::iterator
5445 p
= this->got_entries_
.begin();
5446 p
!= this->got_entries_
.end();
5449 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5450 if (!entry
->is_for_global_symbol())
5453 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5454 if (mips_sym
->global_got_area() == GGA_NONE
&& !entry
->is_tls_entry())
5456 unsigned int got_type
;
5457 if (!got
->multi_got())
5458 got_type
= GOT_TYPE_STANDARD
;
5460 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
5461 if (got
->add_global(mips_sym
, got_type
))
5463 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5464 if (got
->multi_got() && this->index_
> 0
5465 && parameters
->options().output_is_position_independent())
5466 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
5467 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
5468 mips_sym
->got_offset(got_type
));
5474 // Create GOT page entries.
5476 template<int size
, bool big_endian
>
5478 Mips_got_info
<size
, big_endian
>::add_page_entries(
5479 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5481 if (this->page_gotno_
== 0)
5484 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5485 this->got_page_offset_start_
= got
->add_constant(0);
5486 if (got
->multi_got() && this->index_
> 0
5487 && parameters
->options().output_is_position_independent())
5488 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
5489 this->got_page_offset_start_
);
5490 int num_entries
= this->page_gotno_
;
5491 unsigned int prev_offset
= this->got_page_offset_start_
;
5492 while (--num_entries
> 0)
5494 unsigned int next_offset
= got
->add_constant(0);
5495 if (got
->multi_got() && this->index_
> 0
5496 && parameters
->options().output_is_position_independent())
5497 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
5499 gold_assert(next_offset
== prev_offset
+ size
/8);
5500 prev_offset
= next_offset
;
5502 this->got_page_offset_next_
= this->got_page_offset_start_
;
5505 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
5507 template<int size
, bool big_endian
>
5509 Mips_got_info
<size
, big_endian
>::add_global_entries(
5510 Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
5511 unsigned int non_reloc_only_global_gotno
)
5513 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5514 // Add GGA_NORMAL entries.
5515 unsigned int count
= 0;
5516 for (typename
Got_entry_set::iterator
5517 p
= this->got_entries_
.begin();
5518 p
!= this->got_entries_
.end();
5521 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5522 if (!entry
->is_for_global_symbol())
5525 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5526 if (mips_sym
->global_got_area() != GGA_NORMAL
)
5529 unsigned int got_type
;
5530 if (!got
->multi_got())
5531 got_type
= GOT_TYPE_STANDARD
;
5533 // In multi-GOT links, global symbol can be in both primary and
5534 // secondary GOT(s). By creating custom GOT type
5535 // (GOT_TYPE_STANDARD_MULTIGOT + got_index) we ensure that symbol
5536 // is added to secondary GOT(s).
5537 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
5538 if (!got
->add_global(mips_sym
, got_type
))
5541 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5542 if (got
->multi_got() && this->index_
== 0)
5544 if (got
->multi_got() && this->index_
> 0)
5546 if (parameters
->options().output_is_position_independent()
5547 || (!parameters
->doing_static_link()
5548 && mips_sym
->is_from_dynobj() && !mips_sym
->is_undefined()))
5550 target
->rel_dyn_section(layout
)->add_global(
5551 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
5552 mips_sym
->got_offset(got_type
));
5553 got
->add_secondary_got_reloc(mips_sym
->got_offset(got_type
),
5554 elfcpp::R_MIPS_REL32
, mips_sym
);
5559 if (!got
->multi_got() || this->index_
== 0)
5561 if (got
->multi_got())
5563 // We need to allocate space in the primary GOT for GGA_NORMAL entries
5564 // of secondary GOTs, to ensure that GOT offsets of GGA_RELOC_ONLY
5565 // entries correspond to dynamic symbol indexes.
5566 while (count
< non_reloc_only_global_gotno
)
5568 got
->add_constant(0);
5573 // Add GGA_RELOC_ONLY entries.
5574 got
->add_reloc_only_entries();
5578 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
5580 template<int size
, bool big_endian
>
5582 Mips_got_info
<size
, big_endian
>::add_reloc_only_entries(
5583 Mips_output_data_got
<size
, big_endian
>* got
)
5585 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
5586 p
= this->global_got_symbols_
.begin();
5587 p
!= this->global_got_symbols_
.end();
5590 Mips_symbol
<size
>* mips_sym
= *p
;
5591 if (mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
5593 unsigned int got_type
;
5594 if (!got
->multi_got())
5595 got_type
= GOT_TYPE_STANDARD
;
5597 got_type
= GOT_TYPE_STANDARD_MULTIGOT
;
5598 if (got
->add_global(mips_sym
, got_type
))
5599 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5604 // Create TLS GOT entries.
5606 template<int size
, bool big_endian
>
5608 Mips_got_info
<size
, big_endian
>::add_tls_entries(
5609 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5611 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5612 // Add local tls entries.
5613 for (typename
Got_entry_set::iterator
5614 p
= this->got_entries_
.begin();
5615 p
!= this->got_entries_
.end();
5618 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5619 if (!entry
->is_tls_entry() || !entry
->is_for_local_symbol())
5622 if (entry
->tls_type() == GOT_TLS_GD
)
5624 unsigned int got_type
= GOT_TYPE_TLS_PAIR
;
5625 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5626 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5627 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
5628 : elfcpp::R_MIPS_TLS_DTPREL64
);
5630 if (!parameters
->doing_static_link())
5632 got
->add_local_pair_with_rel(entry
->object(), entry
->symndx(),
5633 entry
->shndx(), got_type
,
5634 target
->rel_dyn_section(layout
),
5635 r_type1
, entry
->addend());
5636 unsigned int got_offset
=
5637 entry
->object()->local_got_offset(entry
->symndx(), got_type
,
5639 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
5640 entry
->object(), entry
->symndx());
5644 // We are doing a static link. Mark it as belong to module 1,
5646 unsigned int got_offset
= got
->add_constant(1);
5647 entry
->object()->set_local_got_offset(entry
->symndx(), got_type
,
5650 got
->add_constant(0);
5651 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
5652 entry
->object(), entry
->symndx());
5655 else if (entry
->tls_type() == GOT_TLS_IE
)
5657 unsigned int got_type
= GOT_TYPE_TLS_OFFSET
;
5658 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
5659 : elfcpp::R_MIPS_TLS_TPREL64
);
5660 if (!parameters
->doing_static_link())
5661 got
->add_local_with_rel(entry
->object(), entry
->symndx(), got_type
,
5662 target
->rel_dyn_section(layout
), r_type
,
5666 got
->add_local(entry
->object(), entry
->symndx(), got_type
,
5668 unsigned int got_offset
=
5669 entry
->object()->local_got_offset(entry
->symndx(), got_type
,
5671 got
->add_static_reloc(got_offset
, r_type
, entry
->object(),
5675 else if (entry
->tls_type() == GOT_TLS_LDM
)
5677 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5678 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5679 unsigned int got_offset
;
5680 if (!parameters
->doing_static_link())
5682 got_offset
= got
->add_constant(0);
5683 target
->rel_dyn_section(layout
)->add_local(
5684 entry
->object(), 0, r_type
, got
, got_offset
);
5687 // We are doing a static link. Just mark it as belong to module 1,
5689 got_offset
= got
->add_constant(1);
5691 got
->add_constant(0);
5692 got
->set_tls_ldm_offset(got_offset
, entry
->object());
5698 // Add global tls entries.
5699 for (typename
Got_entry_set::iterator
5700 p
= this->got_entries_
.begin();
5701 p
!= this->got_entries_
.end();
5704 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5705 if (!entry
->is_tls_entry() || !entry
->is_for_global_symbol())
5708 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5709 if (entry
->tls_type() == GOT_TLS_GD
)
5711 unsigned int got_type
;
5712 if (!got
->multi_got())
5713 got_type
= GOT_TYPE_TLS_PAIR
;
5715 got_type
= GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
5716 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5717 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5718 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
5719 : elfcpp::R_MIPS_TLS_DTPREL64
);
5720 if (!parameters
->doing_static_link())
5721 got
->add_global_pair_with_rel(mips_sym
, got_type
,
5722 target
->rel_dyn_section(layout
), r_type1
, r_type2
);
5725 // Add a GOT pair for for R_MIPS_TLS_GD. The creates a pair of
5726 // GOT entries. The first one is initialized to be 1, which is the
5727 // module index for the main executable and the second one 0. A
5728 // reloc of the type R_MIPS_TLS_DTPREL32/64 will be created for
5729 // the second GOT entry and will be applied by gold.
5730 unsigned int got_offset
= got
->add_constant(1);
5731 mips_sym
->set_got_offset(got_type
, got_offset
);
5732 got
->add_constant(0);
5733 got
->add_static_reloc(got_offset
+ size
/8, r_type2
, mips_sym
);
5736 else if (entry
->tls_type() == GOT_TLS_IE
)
5738 unsigned int got_type
;
5739 if (!got
->multi_got())
5740 got_type
= GOT_TYPE_TLS_OFFSET
;
5742 got_type
= GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
5743 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
5744 : elfcpp::R_MIPS_TLS_TPREL64
);
5745 if (!parameters
->doing_static_link())
5746 got
->add_global_with_rel(mips_sym
, got_type
,
5747 target
->rel_dyn_section(layout
), r_type
);
5750 got
->add_global(mips_sym
, got_type
);
5751 unsigned int got_offset
= mips_sym
->got_offset(got_type
);
5752 got
->add_static_reloc(got_offset
, r_type
, mips_sym
);
5760 // Decide whether the symbol needs an entry in the global part of the primary
5761 // GOT, setting global_got_area accordingly. Count the number of global
5762 // symbols that are in the primary GOT only because they have dynamic
5763 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
5765 template<int size
, bool big_endian
>
5767 Mips_got_info
<size
, big_endian
>::count_got_symbols(Symbol_table
* symtab
)
5769 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
5770 p
= this->global_got_symbols_
.begin();
5771 p
!= this->global_got_symbols_
.end();
5774 Mips_symbol
<size
>* sym
= *p
;
5775 // Make a final decision about whether the symbol belongs in the
5776 // local or global GOT. Symbols that bind locally can (and in the
5777 // case of forced-local symbols, must) live in the local GOT.
5778 // Those that are aren't in the dynamic symbol table must also
5779 // live in the local GOT.
5781 if (!sym
->should_add_dynsym_entry(symtab
)
5782 || (sym
->got_only_for_calls()
5783 ? symbol_calls_local(sym
, sym
->should_add_dynsym_entry(symtab
))
5784 : symbol_references_local(sym
,
5785 sym
->should_add_dynsym_entry(symtab
))))
5786 // The symbol belongs in the local GOT. We no longer need this
5787 // entry if it was only used for relocations; those relocations
5788 // will be against the null or section symbol instead.
5789 sym
->set_global_got_area(GGA_NONE
);
5790 else if (sym
->global_got_area() == GGA_RELOC_ONLY
)
5792 ++this->reloc_only_gotno_
;
5793 ++this->global_gotno_
;
5798 // Return the offset of GOT page entry for VALUE. Initialize the entry with
5799 // VALUE if it is not initialized.
5801 template<int size
, bool big_endian
>
5803 Mips_got_info
<size
, big_endian
>::get_got_page_offset(Mips_address value
,
5804 Mips_output_data_got
<size
, big_endian
>* got
)
5806 typename
Got_page_offsets::iterator it
= this->got_page_offsets_
.find(value
);
5807 if (it
!= this->got_page_offsets_
.end())
5810 gold_assert(this->got_page_offset_next_
< this->got_page_offset_start_
5811 + (size
/8) * this->page_gotno_
);
5813 unsigned int got_offset
= this->got_page_offset_next_
;
5814 this->got_page_offsets_
[value
] = got_offset
;
5815 this->got_page_offset_next_
+= size
/8;
5816 got
->update_got_entry(got_offset
, value
);
5820 // Remove lazy-binding stubs for global symbols in this GOT.
5822 template<int size
, bool big_endian
>
5824 Mips_got_info
<size
, big_endian
>::remove_lazy_stubs(
5825 Target_mips
<size
, big_endian
>* target
)
5827 for (typename
Got_entry_set::iterator
5828 p
= this->got_entries_
.begin();
5829 p
!= this->got_entries_
.end();
5832 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5833 if (entry
->is_for_global_symbol())
5834 target
->remove_lazy_stub_entry(entry
->sym());
5838 // Count the number of GOT entries required.
5840 template<int size
, bool big_endian
>
5842 Mips_got_info
<size
, big_endian
>::count_got_entries()
5844 for (typename
Got_entry_set::iterator
5845 p
= this->got_entries_
.begin();
5846 p
!= this->got_entries_
.end();
5849 this->count_got_entry(*p
);
5853 // Count the number of GOT entries required by ENTRY. Accumulate the result.
5855 template<int size
, bool big_endian
>
5857 Mips_got_info
<size
, big_endian
>::count_got_entry(
5858 Mips_got_entry
<size
, big_endian
>* entry
)
5860 if (entry
->is_tls_entry())
5861 this->tls_gotno_
+= mips_tls_got_entries(entry
->tls_type());
5862 else if (entry
->is_for_local_symbol()
5863 || entry
->sym()->global_got_area() == GGA_NONE
)
5864 ++this->local_gotno_
;
5866 ++this->global_gotno_
;
5869 // Add FROM's GOT entries.
5871 template<int size
, bool big_endian
>
5873 Mips_got_info
<size
, big_endian
>::add_got_entries(
5874 Mips_got_info
<size
, big_endian
>* from
)
5876 for (typename
Got_entry_set::iterator
5877 p
= from
->got_entries_
.begin();
5878 p
!= from
->got_entries_
.end();
5881 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5882 if (this->got_entries_
.find(entry
) == this->got_entries_
.end())
5884 Mips_got_entry
<size
, big_endian
>* entry2
=
5885 new Mips_got_entry
<size
, big_endian
>(*entry
);
5886 this->got_entries_
.insert(entry2
);
5887 this->count_got_entry(entry
);
5892 // Add FROM's GOT page entries.
5894 template<int size
, bool big_endian
>
5896 Mips_got_info
<size
, big_endian
>::add_got_page_entries(
5897 Mips_got_info
<size
, big_endian
>* from
)
5899 for (typename
Got_page_entry_set::iterator
5900 p
= from
->got_page_entries_
.begin();
5901 p
!= from
->got_page_entries_
.end();
5904 Got_page_entry
* entry
= *p
;
5905 if (this->got_page_entries_
.find(entry
) == this->got_page_entries_
.end())
5907 Got_page_entry
* entry2
= new Got_page_entry(*entry
);
5908 this->got_page_entries_
.insert(entry2
);
5909 this->page_gotno_
+= entry
->num_pages
;
5914 // Mips_output_data_got methods.
5916 // Lay out the GOT. Add local, global and TLS entries. If GOT is
5917 // larger than 64K, create multi-GOT.
5919 template<int size
, bool big_endian
>
5921 Mips_output_data_got
<size
, big_endian
>::lay_out_got(Layout
* layout
,
5922 Symbol_table
* symtab
, const Input_objects
* input_objects
)
5924 // Decide which symbols need to go in the global part of the GOT and
5925 // count the number of reloc-only GOT symbols.
5926 this->master_got_info_
->count_got_symbols(symtab
);
5928 // Count the number of GOT entries.
5929 this->master_got_info_
->count_got_entries();
5931 unsigned int got_size
= this->master_got_info_
->got_size();
5932 if (got_size
> Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
)
5933 this->lay_out_multi_got(layout
, input_objects
);
5936 // Record that all objects use single GOT.
5937 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
5938 p
!= input_objects
->relobj_end();
5941 Mips_relobj
<size
, big_endian
>* object
=
5942 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
5943 if (object
->get_got_info() != NULL
)
5944 object
->set_got_info(this->master_got_info_
);
5947 this->master_got_info_
->add_local_entries(this->target_
, layout
);
5948 this->master_got_info_
->add_global_entries(this->target_
, layout
,
5950 this->master_got_info_
->add_tls_entries(this->target_
, layout
);
5954 // Create multi-GOT. For every GOT, add local, global and TLS entries.
5956 template<int size
, bool big_endian
>
5958 Mips_output_data_got
<size
, big_endian
>::lay_out_multi_got(Layout
* layout
,
5959 const Input_objects
* input_objects
)
5961 // Try to merge the GOTs of input objects together, as long as they
5962 // don't seem to exceed the maximum GOT size, choosing one of them
5963 // to be the primary GOT.
5964 this->merge_gots(input_objects
);
5966 // Every symbol that is referenced in a dynamic relocation must be
5967 // present in the primary GOT.
5968 this->primary_got_
->set_global_gotno(this->master_got_info_
->global_gotno());
5972 unsigned int offset
= 0;
5973 Mips_got_info
<size
, big_endian
>* g
= this->primary_got_
;
5977 g
->set_offset(offset
);
5979 g
->add_local_entries(this->target_
, layout
);
5981 g
->add_global_entries(this->target_
, layout
,
5982 (this->master_got_info_
->global_gotno()
5983 - this->master_got_info_
->reloc_only_gotno()));
5985 g
->add_global_entries(this->target_
, layout
, /*not used*/-1U);
5986 g
->add_tls_entries(this->target_
, layout
);
5988 // Forbid global symbols in every non-primary GOT from having
5989 // lazy-binding stubs.
5991 g
->remove_lazy_stubs(this->target_
);
5994 offset
+= g
->got_size();
6000 // Attempt to merge GOTs of different input objects. Try to use as much as
6001 // possible of the primary GOT, since it doesn't require explicit dynamic
6002 // relocations, but don't use objects that would reference global symbols
6003 // out of the addressable range. Failing the primary GOT, attempt to merge
6004 // with the current GOT, or finish the current GOT and then make make the new
6007 template<int size
, bool big_endian
>
6009 Mips_output_data_got
<size
, big_endian
>::merge_gots(
6010 const Input_objects
* input_objects
)
6012 gold_assert(this->primary_got_
== NULL
);
6013 Mips_got_info
<size
, big_endian
>* current
= NULL
;
6015 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
6016 p
!= input_objects
->relobj_end();
6019 Mips_relobj
<size
, big_endian
>* object
=
6020 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
6022 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
6026 g
->count_got_entries();
6028 // Work out the number of page, local and TLS entries.
6029 unsigned int estimate
= this->master_got_info_
->page_gotno();
6030 if (estimate
> g
->page_gotno())
6031 estimate
= g
->page_gotno();
6032 estimate
+= g
->local_gotno() + g
->tls_gotno();
6034 // We place TLS GOT entries after both locals and globals. The globals
6035 // for the primary GOT may overflow the normal GOT size limit, so be
6036 // sure not to merge a GOT which requires TLS with the primary GOT in that
6037 // case. This doesn't affect non-primary GOTs.
6038 estimate
+= (g
->tls_gotno() > 0 ? this->master_got_info_
->global_gotno()
6039 : g
->global_gotno());
6041 unsigned int max_count
=
6042 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
6043 if (estimate
<= max_count
)
6045 // If we don't have a primary GOT, use it as
6046 // a starting point for the primary GOT.
6047 if (!this->primary_got_
)
6049 this->primary_got_
= g
;
6053 // Try merging with the primary GOT.
6054 if (this->merge_got_with(g
, object
, this->primary_got_
))
6058 // If we can merge with the last-created GOT, do it.
6059 if (current
&& this->merge_got_with(g
, object
, current
))
6062 // Well, we couldn't merge, so create a new GOT. Don't check if it
6063 // fits; if it turns out that it doesn't, we'll get relocation
6064 // overflows anyway.
6065 g
->set_next(current
);
6069 // If we do not find any suitable primary GOT, create an empty one.
6070 if (this->primary_got_
== NULL
)
6071 this->primary_got_
= new Mips_got_info
<size
, big_endian
>();
6073 // Link primary GOT with secondary GOTs.
6074 this->primary_got_
->set_next(current
);
6077 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
6078 // this would lead to overflow, true if they were merged successfully.
6080 template<int size
, bool big_endian
>
6082 Mips_output_data_got
<size
, big_endian
>::merge_got_with(
6083 Mips_got_info
<size
, big_endian
>* from
,
6084 Mips_relobj
<size
, big_endian
>* object
,
6085 Mips_got_info
<size
, big_endian
>* to
)
6087 // Work out how many page entries we would need for the combined GOT.
6088 unsigned int estimate
= this->master_got_info_
->page_gotno();
6089 if (estimate
>= from
->page_gotno() + to
->page_gotno())
6090 estimate
= from
->page_gotno() + to
->page_gotno();
6092 // Conservatively estimate how many local and TLS entries would be needed.
6093 estimate
+= from
->local_gotno() + to
->local_gotno();
6094 estimate
+= from
->tls_gotno() + to
->tls_gotno();
6096 // If we're merging with the primary got, any TLS relocations will
6097 // come after the full set of global entries. Otherwise estimate those
6098 // conservatively as well.
6099 if (to
== this->primary_got_
&& (from
->tls_gotno() + to
->tls_gotno()) > 0)
6100 estimate
+= this->master_got_info_
->global_gotno();
6102 estimate
+= from
->global_gotno() + to
->global_gotno();
6104 // Bail out if the combined GOT might be too big.
6105 unsigned int max_count
=
6106 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
6107 if (estimate
> max_count
)
6110 // Transfer the object's GOT information from FROM to TO.
6111 to
->add_got_entries(from
);
6112 to
->add_got_page_entries(from
);
6114 // Record that OBJECT should use output GOT TO.
6115 object
->set_got_info(to
);
6120 // Write out the GOT.
6122 template<int size
, bool big_endian
>
6124 Mips_output_data_got
<size
, big_endian
>::do_write(Output_file
* of
)
6126 // Call parent to write out GOT.
6127 Output_data_got
<size
, big_endian
>::do_write(of
);
6129 const off_t offset
= this->offset();
6130 const section_size_type oview_size
=
6131 convert_to_section_size_type(this->data_size());
6132 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6134 // Needed for fixing values of .got section.
6135 this->got_view_
= oview
;
6137 // Write lazy stub addresses.
6138 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
6139 p
= this->master_got_info_
->global_got_symbols().begin();
6140 p
!= this->master_got_info_
->global_got_symbols().end();
6143 Mips_symbol
<size
>* mips_sym
= *p
;
6144 if (mips_sym
->has_lazy_stub())
6146 Valtype
* wv
= reinterpret_cast<Valtype
*>(
6147 oview
+ this->get_primary_got_offset(mips_sym
));
6149 this->target_
->mips_stubs_section()->stub_address(mips_sym
);
6150 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
6154 // Add +1 to GGA_NONE nonzero MIPS16 and microMIPS entries.
6155 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
6156 p
= this->master_got_info_
->global_got_symbols().begin();
6157 p
!= this->master_got_info_
->global_got_symbols().end();
6160 Mips_symbol
<size
>* mips_sym
= *p
;
6161 if (!this->multi_got()
6162 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
6163 && mips_sym
->global_got_area() == GGA_NONE
6164 && mips_sym
->has_got_offset(GOT_TYPE_STANDARD
))
6166 Valtype
* wv
= reinterpret_cast<Valtype
*>(
6167 oview
+ mips_sym
->got_offset(GOT_TYPE_STANDARD
));
6168 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv
);
6172 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
6177 if (!this->secondary_got_relocs_
.empty())
6179 // Fixup for the secondary GOT R_MIPS_REL32 relocs. For global
6180 // secondary GOT entries with non-zero initial value copy the value
6181 // to the corresponding primary GOT entry, and set the secondary GOT
6183 // TODO(sasa): This is workaround. It needs to be investigated further.
6185 for (size_t i
= 0; i
< this->secondary_got_relocs_
.size(); ++i
)
6187 Static_reloc
& reloc(this->secondary_got_relocs_
[i
]);
6188 if (reloc
.symbol_is_global())
6190 Mips_symbol
<size
>* gsym
= reloc
.symbol();
6191 gold_assert(gsym
!= NULL
);
6193 unsigned got_offset
= reloc
.got_offset();
6194 gold_assert(got_offset
< oview_size
);
6196 // Find primary GOT entry.
6197 Valtype
* wv_prim
= reinterpret_cast<Valtype
*>(
6198 oview
+ this->get_primary_got_offset(gsym
));
6200 // Find secondary GOT entry.
6201 Valtype
* wv_sec
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6203 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv_sec
);
6206 elfcpp::Swap
<size
, big_endian
>::writeval(wv_prim
, value
);
6207 elfcpp::Swap
<size
, big_endian
>::writeval(wv_sec
, 0);
6208 gsym
->set_applied_secondary_got_fixup();
6213 of
->write_output_view(offset
, oview_size
, oview
);
6216 // We are done if there is no fix up.
6217 if (this->static_relocs_
.empty())
6220 Output_segment
* tls_segment
= this->layout_
->tls_segment();
6221 gold_assert(tls_segment
!= NULL
);
6223 for (size_t i
= 0; i
< this->static_relocs_
.size(); ++i
)
6225 Static_reloc
& reloc(this->static_relocs_
[i
]);
6228 if (!reloc
.symbol_is_global())
6230 Sized_relobj_file
<size
, big_endian
>* object
= reloc
.relobj();
6231 const Symbol_value
<size
>* psymval
=
6232 object
->local_symbol(reloc
.index());
6234 // We are doing static linking. Issue an error and skip this
6235 // relocation if the symbol is undefined or in a discarded_section.
6237 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
6238 if ((shndx
== elfcpp::SHN_UNDEF
)
6240 && shndx
!= elfcpp::SHN_UNDEF
6241 && !object
->is_section_included(shndx
)
6242 && !this->symbol_table_
->is_section_folded(object
, shndx
)))
6244 gold_error(_("undefined or discarded local symbol %u from "
6245 " object %s in GOT"),
6246 reloc
.index(), reloc
.relobj()->name().c_str());
6250 value
= psymval
->value(object
, 0);
6254 const Mips_symbol
<size
>* gsym
= reloc
.symbol();
6255 gold_assert(gsym
!= NULL
);
6257 // We are doing static linking. Issue an error and skip this
6258 // relocation if the symbol is undefined or in a discarded_section
6259 // unless it is a weakly_undefined symbol.
6260 if ((gsym
->is_defined_in_discarded_section() || gsym
->is_undefined())
6261 && !gsym
->is_weak_undefined())
6263 gold_error(_("undefined or discarded symbol %s in GOT"),
6268 if (!gsym
->is_weak_undefined())
6269 value
= gsym
->value();
6274 unsigned got_offset
= reloc
.got_offset();
6275 gold_assert(got_offset
< oview_size
);
6277 Valtype
* wv
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6280 switch (reloc
.r_type())
6282 case elfcpp::R_MIPS_TLS_DTPMOD32
:
6283 case elfcpp::R_MIPS_TLS_DTPMOD64
:
6286 case elfcpp::R_MIPS_TLS_DTPREL32
:
6287 case elfcpp::R_MIPS_TLS_DTPREL64
:
6288 x
= value
- elfcpp::DTP_OFFSET
;
6290 case elfcpp::R_MIPS_TLS_TPREL32
:
6291 case elfcpp::R_MIPS_TLS_TPREL64
:
6292 x
= value
- elfcpp::TP_OFFSET
;
6299 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, x
);
6302 of
->write_output_view(offset
, oview_size
, oview
);
6305 // Mips_relobj methods.
6307 // Count the local symbols. The Mips backend needs to know if a symbol
6308 // is a MIPS16 or microMIPS function or not. For global symbols, it is easy
6309 // because the Symbol object keeps the ELF symbol type and st_other field.
6310 // For local symbol it is harder because we cannot access this information.
6311 // So we override the do_count_local_symbol in parent and scan local symbols to
6312 // mark MIPS16 and microMIPS functions. This is not the most efficient way but
6313 // I do not want to slow down other ports by calling a per symbol target hook
6314 // inside Sized_relobj_file<size, big_endian>::do_count_local_symbols.
6316 template<int size
, bool big_endian
>
6318 Mips_relobj
<size
, big_endian
>::do_count_local_symbols(
6319 Stringpool_template
<char>* pool
,
6320 Stringpool_template
<char>* dynpool
)
6322 // Ask parent to count the local symbols.
6323 Sized_relobj_file
<size
, big_endian
>::do_count_local_symbols(pool
, dynpool
);
6324 const unsigned int loccount
= this->local_symbol_count();
6328 // Initialize the mips16 and micromips function bit-vector.
6329 this->local_symbol_is_mips16_
.resize(loccount
, false);
6330 this->local_symbol_is_micromips_
.resize(loccount
, false);
6332 // Read the symbol table section header.
6333 const unsigned int symtab_shndx
= this->symtab_shndx();
6334 elfcpp::Shdr
<size
, big_endian
>
6335 symtabshdr(this, this->elf_file()->section_header(symtab_shndx
));
6336 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
6338 // Read the local symbols.
6339 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
6340 gold_assert(loccount
== symtabshdr
.get_sh_info());
6341 off_t locsize
= loccount
* sym_size
;
6342 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
6343 locsize
, true, true);
6345 // Loop over the local symbols and mark any MIPS16 or microMIPS local symbols.
6347 // Skip the first dummy symbol.
6349 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
6351 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
6352 unsigned char st_other
= sym
.get_st_other();
6353 this->local_symbol_is_mips16_
[i
] = elfcpp::elf_st_is_mips16(st_other
);
6354 this->local_symbol_is_micromips_
[i
] =
6355 elfcpp::elf_st_is_micromips(st_other
);
6359 // Read the symbol information.
6361 template<int size
, bool big_endian
>
6363 Mips_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
6365 // Call parent class to read symbol information.
6366 this->base_read_symbols(sd
);
6368 // Read processor-specific flags in ELF file header.
6369 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
6370 elfcpp::Elf_sizes
<size
>::ehdr_size
,
6372 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
6373 this->processor_specific_flags_
= ehdr
.get_e_flags();
6375 // Get the section names.
6376 const unsigned char* pnamesu
= sd
->section_names
->data();
6377 const char* pnames
= reinterpret_cast<const char*>(pnamesu
);
6379 // Initialize the mips16 stub section bit-vectors.
6380 this->section_is_mips16_fn_stub_
.resize(this->shnum(), false);
6381 this->section_is_mips16_call_stub_
.resize(this->shnum(), false);
6382 this->section_is_mips16_call_fp_stub_
.resize(this->shnum(), false);
6384 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
6385 const unsigned char* pshdrs
= sd
->section_headers
->data();
6386 const unsigned char* ps
= pshdrs
+ shdr_size
;
6387 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
6389 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
6391 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_REGINFO
)
6393 // Read the gp value that was used to create this object. We need the
6394 // gp value while processing relocs. The .reginfo section is not used
6395 // in the 64-bit MIPS ELF ABI.
6396 section_offset_type section_offset
= shdr
.get_sh_offset();
6397 section_size_type section_size
=
6398 convert_to_section_size_type(shdr
.get_sh_size());
6399 const unsigned char* view
=
6400 this->get_view(section_offset
, section_size
, true, false);
6402 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 20);
6404 // Read the rest of .reginfo.
6405 this->gprmask_
= elfcpp::Swap
<size
, big_endian
>::readval(view
);
6406 this->cprmask1_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 4);
6407 this->cprmask2_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 8);
6408 this->cprmask3_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 12);
6409 this->cprmask4_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 16);
6412 // In the 64-bit ABI, .MIPS.options section holds register information.
6413 // A SHT_MIPS_OPTIONS section contains a series of options, each of which
6414 // starts with this header:
6418 // // Type of option.
6419 // unsigned char kind[1];
6420 // // Size of option descriptor, including header.
6421 // unsigned char size[1];
6422 // // Section index of affected section, or 0 for global option.
6423 // unsigned char section[2];
6424 // // Information specific to this kind of option.
6425 // unsigned char info[4];
6428 // For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and set
6429 // the gp value based on what we find. We may see both SHT_MIPS_REGINFO
6430 // and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case, they should agree.
6432 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_OPTIONS
)
6434 section_offset_type section_offset
= shdr
.get_sh_offset();
6435 section_size_type section_size
=
6436 convert_to_section_size_type(shdr
.get_sh_size());
6437 const unsigned char* view
=
6438 this->get_view(section_offset
, section_size
, true, false);
6439 const unsigned char* end
= view
+ section_size
;
6441 while (view
+ 8 <= end
)
6443 unsigned char kind
= elfcpp::Swap
<8, big_endian
>::readval(view
);
6444 unsigned char sz
= elfcpp::Swap
<8, big_endian
>::readval(view
+ 1);
6447 gold_error(_("%s: Warning: bad `%s' option size %u smaller "
6449 this->name().c_str(),
6450 this->mips_elf_options_section_name(), sz
);
6454 if (this->is_n64() && kind
== elfcpp::ODK_REGINFO
)
6456 // In the 64 bit ABI, an ODK_REGINFO option is the following
6457 // structure. The info field of the options header is not
6462 // // Mask of general purpose registers used.
6463 // unsigned char ri_gprmask[4];
6465 // unsigned char ri_pad[4];
6466 // // Mask of co-processor registers used.
6467 // unsigned char ri_cprmask[4][4];
6468 // // GP register value for this object file.
6469 // unsigned char ri_gp_value[8];
6472 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
6475 else if (kind
== elfcpp::ODK_REGINFO
)
6477 // In the 32 bit ABI, an ODK_REGINFO option is the following
6478 // structure. The info field of the options header is not
6479 // used. The same structure is used in .reginfo section.
6483 // unsigned char ri_gprmask[4];
6484 // unsigned char ri_cprmask[4][4];
6485 // unsigned char ri_gp_value[4];
6488 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
6495 const char* name
= pnames
+ shdr
.get_sh_name();
6496 this->section_is_mips16_fn_stub_
[i
] = is_prefix_of(".mips16.fn", name
);
6497 this->section_is_mips16_call_stub_
[i
] =
6498 is_prefix_of(".mips16.call.", name
);
6499 this->section_is_mips16_call_fp_stub_
[i
] =
6500 is_prefix_of(".mips16.call.fp.", name
);
6502 if (strcmp(name
, ".pdr") == 0)
6504 gold_assert(this->pdr_shndx_
== -1U);
6505 this->pdr_shndx_
= i
;
6510 // Discard MIPS16 stub secions that are not needed.
6512 template<int size
, bool big_endian
>
6514 Mips_relobj
<size
, big_endian
>::discard_mips16_stub_sections(Symbol_table
* symtab
)
6516 for (typename
Mips16_stubs_int_map::const_iterator
6517 it
= this->mips16_stub_sections_
.begin();
6518 it
!= this->mips16_stub_sections_
.end(); ++it
)
6520 Mips16_stub_section
<size
, big_endian
>* stub_section
= it
->second
;
6521 if (!stub_section
->is_target_found())
6523 gold_error(_("no relocation found in mips16 stub section '%s'"),
6524 stub_section
->object()
6525 ->section_name(stub_section
->shndx()).c_str());
6528 bool discard
= false;
6529 if (stub_section
->is_for_local_function())
6531 if (stub_section
->is_fn_stub())
6533 // This stub is for a local symbol. This stub will only
6534 // be needed if there is some relocation in this object,
6535 // other than a 16 bit function call, which refers to this
6537 if (!this->has_local_non_16bit_call_relocs(stub_section
->r_sym()))
6540 this->add_local_mips16_fn_stub(stub_section
);
6544 // This stub is for a local symbol. This stub will only
6545 // be needed if there is some relocation (R_MIPS16_26) in
6546 // this object that refers to this symbol.
6547 gold_assert(stub_section
->is_call_stub()
6548 || stub_section
->is_call_fp_stub());
6549 if (!this->has_local_16bit_call_relocs(stub_section
->r_sym()))
6552 this->add_local_mips16_call_stub(stub_section
);
6557 Mips_symbol
<size
>* gsym
= stub_section
->gsym();
6558 if (stub_section
->is_fn_stub())
6560 if (gsym
->has_mips16_fn_stub())
6561 // We already have a stub for this function.
6565 gsym
->set_mips16_fn_stub(stub_section
);
6566 if (gsym
->should_add_dynsym_entry(symtab
))
6568 // If we have a MIPS16 function with a stub, the
6569 // dynamic symbol must refer to the stub, since only
6570 // the stub uses the standard calling conventions.
6571 gsym
->set_need_fn_stub();
6572 if (gsym
->is_from_dynobj())
6573 gsym
->set_needs_dynsym_value();
6576 if (!gsym
->need_fn_stub())
6579 else if (stub_section
->is_call_stub())
6581 if (gsym
->is_mips16())
6582 // We don't need the call_stub; this is a 16 bit
6583 // function, so calls from other 16 bit functions are
6586 else if (gsym
->has_mips16_call_stub())
6587 // We already have a stub for this function.
6590 gsym
->set_mips16_call_stub(stub_section
);
6594 gold_assert(stub_section
->is_call_fp_stub());
6595 if (gsym
->is_mips16())
6596 // We don't need the call_stub; this is a 16 bit
6597 // function, so calls from other 16 bit functions are
6600 else if (gsym
->has_mips16_call_fp_stub())
6601 // We already have a stub for this function.
6604 gsym
->set_mips16_call_fp_stub(stub_section
);
6608 this->set_output_section(stub_section
->shndx(), NULL
);
6612 // Mips_output_data_la25_stub methods.
6614 // Template for standard LA25 stub.
6615 template<int size
, bool big_endian
>
6617 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_entry
[] =
6619 0x3c190000, // lui $25,%hi(func)
6620 0x08000000, // j func
6621 0x27390000, // add $25,$25,%lo(func)
6625 // Template for microMIPS LA25 stub.
6626 template<int size
, bool big_endian
>
6628 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_micromips_entry
[] =
6630 0x41b9, 0x0000, // lui t9,%hi(func)
6631 0xd400, 0x0000, // j func
6632 0x3339, 0x0000, // addiu t9,t9,%lo(func)
6633 0x0000, 0x0000 // nop
6636 // Create la25 stub for a symbol.
6638 template<int size
, bool big_endian
>
6640 Mips_output_data_la25_stub
<size
, big_endian
>::create_la25_stub(
6641 Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
6642 Mips_symbol
<size
>* gsym
)
6644 if (!gsym
->has_la25_stub())
6646 gsym
->set_la25_stub_offset(this->symbols_
.size() * 16);
6647 this->symbols_
.insert(gsym
);
6648 this->create_stub_symbol(gsym
, symtab
, target
, 16);
6652 // Create a symbol for SYM stub's value and size, to help make the disassembly
6655 template<int size
, bool big_endian
>
6657 Mips_output_data_la25_stub
<size
, big_endian
>::create_stub_symbol(
6658 Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
6659 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
)
6661 std::string
name(".pic.");
6662 name
+= sym
->name();
6664 unsigned int offset
= sym
->la25_stub_offset();
6665 if (sym
->is_micromips())
6668 // Make it a local function.
6669 Symbol
* new_sym
= symtab
->define_in_output_data(name
.c_str(), NULL
,
6670 Symbol_table::PREDEFINED
,
6671 target
->la25_stub_section(),
6672 offset
, symsize
, elfcpp::STT_FUNC
,
6674 elfcpp::STV_DEFAULT
, 0,
6676 new_sym
->set_is_forced_local();
6679 // Write out la25 stubs. This uses the hand-coded instructions above,
6680 // and adjusts them as needed.
6682 template<int size
, bool big_endian
>
6684 Mips_output_data_la25_stub
<size
, big_endian
>::do_write(Output_file
* of
)
6686 const off_t offset
= this->offset();
6687 const section_size_type oview_size
=
6688 convert_to_section_size_type(this->data_size());
6689 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6691 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
6692 p
= this->symbols_
.begin();
6693 p
!= this->symbols_
.end();
6696 Mips_symbol
<size
>* sym
= *p
;
6697 unsigned char* pov
= oview
+ sym
->la25_stub_offset();
6699 Mips_address target
= sym
->value();
6700 if (!sym
->is_micromips())
6702 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
6703 la25_stub_entry
[0] | (((target
+ 0x8000) >> 16) & 0xffff));
6704 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
6705 la25_stub_entry
[1] | ((target
>> 2) & 0x3ffffff));
6706 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
6707 la25_stub_entry
[2] | (target
& 0xffff));
6708 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12, la25_stub_entry
[3]);
6713 // First stub instruction. Paste high 16-bits of the target.
6714 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
6715 la25_stub_micromips_entry
[0]);
6716 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
6717 ((target
+ 0x8000) >> 16) & 0xffff);
6718 // Second stub instruction. Paste low 26-bits of the target, shifted
6720 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
6721 la25_stub_micromips_entry
[2] | ((target
>> 17) & 0x3ff));
6722 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
6723 la25_stub_micromips_entry
[3] | ((target
>> 1) & 0xffff));
6724 // Third stub instruction. Paste low 16-bits of the target.
6725 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8,
6726 la25_stub_micromips_entry
[4]);
6727 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, target
& 0xffff);
6728 // Fourth stub instruction.
6729 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 12,
6730 la25_stub_micromips_entry
[6]);
6731 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 14,
6732 la25_stub_micromips_entry
[7]);
6736 of
->write_output_view(offset
, oview_size
, oview
);
6739 // Mips_output_data_plt methods.
6741 // The format of the first PLT entry in an O32 executable.
6742 template<int size
, bool big_endian
>
6743 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_o32
[] =
6745 0x3c1c0000, // lui $28, %hi(&GOTPLT[0])
6746 0x8f990000, // lw $25, %lo(&GOTPLT[0])($28)
6747 0x279c0000, // addiu $28, $28, %lo(&GOTPLT[0])
6748 0x031cc023, // subu $24, $24, $28
6749 0x03e07825, // or $15, $31, zero
6750 0x0018c082, // srl $24, $24, 2
6751 0x0320f809, // jalr $25
6752 0x2718fffe // subu $24, $24, 2
6755 // The format of the first PLT entry in an N32 executable. Different
6756 // because gp ($28) is not available; we use t2 ($14) instead.
6757 template<int size
, bool big_endian
>
6758 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n32
[] =
6760 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
6761 0x8dd90000, // lw $25, %lo(&GOTPLT[0])($14)
6762 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
6763 0x030ec023, // subu $24, $24, $14
6764 0x03e07825, // or $15, $31, zero
6765 0x0018c082, // srl $24, $24, 2
6766 0x0320f809, // jalr $25
6767 0x2718fffe // subu $24, $24, 2
6770 // The format of the first PLT entry in an N64 executable. Different
6771 // from N32 because of the increased size of GOT entries.
6772 template<int size
, bool big_endian
>
6773 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n64
[] =
6775 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
6776 0xddd90000, // ld $25, %lo(&GOTPLT[0])($14)
6777 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
6778 0x030ec023, // subu $24, $24, $14
6779 0x03e07825, // or $15, $31, zero
6780 0x0018c0c2, // srl $24, $24, 3
6781 0x0320f809, // jalr $25
6782 0x2718fffe // subu $24, $24, 2
6785 // The format of the microMIPS first PLT entry in an O32 executable.
6786 // We rely on v0 ($2) rather than t8 ($24) to contain the address
6787 // of the GOTPLT entry handled, so this stub may only be used when
6788 // all the subsequent PLT entries are microMIPS code too.
6790 // The trailing NOP is for alignment and correct disassembly only.
6791 template<int size
, bool big_endian
>
6792 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6793 plt0_entry_micromips_o32
[] =
6795 0x7980, 0x0000, // addiupc $3, (&GOTPLT[0]) - .
6796 0xff23, 0x0000, // lw $25, 0($3)
6797 0x0535, // subu $2, $2, $3
6798 0x2525, // srl $2, $2, 2
6799 0x3302, 0xfffe, // subu $24, $2, 2
6800 0x0dff, // move $15, $31
6801 0x45f9, // jalrs $25
6802 0x0f83, // move $28, $3
6806 // The format of the microMIPS first PLT entry in an O32 executable
6807 // in the insn32 mode.
6808 template<int size
, bool big_endian
>
6809 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6810 plt0_entry_micromips32_o32
[] =
6812 0x41bc, 0x0000, // lui $28, %hi(&GOTPLT[0])
6813 0xff3c, 0x0000, // lw $25, %lo(&GOTPLT[0])($28)
6814 0x339c, 0x0000, // addiu $28, $28, %lo(&GOTPLT[0])
6815 0x0398, 0xc1d0, // subu $24, $24, $28
6816 0x001f, 0x7a90, // or $15, $31, zero
6817 0x0318, 0x1040, // srl $24, $24, 2
6818 0x03f9, 0x0f3c, // jalr $25
6819 0x3318, 0xfffe // subu $24, $24, 2
6822 // The format of subsequent standard entries in the PLT.
6823 template<int size
, bool big_endian
>
6824 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry
[] =
6826 0x3c0f0000, // lui $15, %hi(.got.plt entry)
6827 0x01f90000, // l[wd] $25, %lo(.got.plt entry)($15)
6828 0x03200008, // jr $25
6829 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
6832 // The format of subsequent MIPS16 o32 PLT entries. We use v1 ($3) as a
6833 // temporary because t8 ($24) and t9 ($25) are not directly addressable.
6834 // Note that this differs from the GNU ld which uses both v0 ($2) and v1 ($3).
6835 // We cannot use v0 because MIPS16 call stubs from the CS toolchain expect
6836 // target function address in register v0.
6837 template<int size
, bool big_endian
>
6838 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry_mips16_o32
[] =
6840 0xb303, // lw $3, 12($pc)
6841 0x651b, // move $24, $3
6842 0x9b60, // lw $3, 0($3)
6844 0x653b, // move $25, $3
6846 0x0000, 0x0000 // .word (.got.plt entry)
6849 // The format of subsequent microMIPS o32 PLT entries. We use v0 ($2)
6850 // as a temporary because t8 ($24) is not addressable with ADDIUPC.
6851 template<int size
, bool big_endian
>
6852 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6853 plt_entry_micromips_o32
[] =
6855 0x7900, 0x0000, // addiupc $2, (.got.plt entry) - .
6856 0xff22, 0x0000, // lw $25, 0($2)
6858 0x0f02 // move $24, $2
6861 // The format of subsequent microMIPS o32 PLT entries in the insn32 mode.
6862 template<int size
, bool big_endian
>
6863 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6864 plt_entry_micromips32_o32
[] =
6866 0x41af, 0x0000, // lui $15, %hi(.got.plt entry)
6867 0xff2f, 0x0000, // lw $25, %lo(.got.plt entry)($15)
6868 0x0019, 0x0f3c, // jr $25
6869 0x330f, 0x0000 // addiu $24, $15, %lo(.got.plt entry)
6872 // Add an entry to the PLT for a symbol referenced by r_type relocation.
6874 template<int size
, bool big_endian
>
6876 Mips_output_data_plt
<size
, big_endian
>::add_entry(Mips_symbol
<size
>* gsym
,
6877 unsigned int r_type
)
6879 gold_assert(!gsym
->has_plt_offset());
6881 // Final PLT offset for a symbol will be set in method set_plt_offsets().
6882 gsym
->set_plt_offset(this->entry_count() * sizeof(plt_entry
)
6883 + sizeof(plt0_entry_o32
));
6884 this->symbols_
.push_back(gsym
);
6886 // Record whether the relocation requires a standard MIPS
6887 // or a compressed code entry.
6888 if (jal_reloc(r_type
))
6890 if (r_type
== elfcpp::R_MIPS_26
)
6891 gsym
->set_needs_mips_plt(true);
6893 gsym
->set_needs_comp_plt(true);
6896 section_offset_type got_offset
= this->got_plt_
->current_data_size();
6898 // Every PLT entry needs a GOT entry which points back to the PLT
6899 // entry (this will be changed by the dynamic linker, normally
6900 // lazily when the function is called).
6901 this->got_plt_
->set_current_data_size(got_offset
+ size
/8);
6903 gsym
->set_needs_dynsym_entry();
6904 this->rel_
->add_global(gsym
, elfcpp::R_MIPS_JUMP_SLOT
, this->got_plt_
,
6908 // Set final PLT offsets. For each symbol, determine whether standard or
6909 // compressed (MIPS16 or microMIPS) PLT entry is used.
6911 template<int size
, bool big_endian
>
6913 Mips_output_data_plt
<size
, big_endian
>::set_plt_offsets()
6915 // The sizes of individual PLT entries.
6916 unsigned int plt_mips_entry_size
= this->standard_plt_entry_size();
6917 unsigned int plt_comp_entry_size
= (!this->target_
->is_output_newabi()
6918 ? this->compressed_plt_entry_size() : 0);
6920 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
6921 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
6923 Mips_symbol
<size
>* mips_sym
= *p
;
6925 // There are no defined MIPS16 or microMIPS PLT entries for n32 or n64,
6926 // so always use a standard entry there.
6928 // If the symbol has a MIPS16 call stub and gets a PLT entry, then
6929 // all MIPS16 calls will go via that stub, and there is no benefit
6930 // to having a MIPS16 entry. And in the case of call_stub a
6931 // standard entry actually has to be used as the stub ends with a J
6933 if (this->target_
->is_output_newabi()
6934 || mips_sym
->has_mips16_call_stub()
6935 || mips_sym
->has_mips16_call_fp_stub())
6937 mips_sym
->set_needs_mips_plt(true);
6938 mips_sym
->set_needs_comp_plt(false);
6941 // Otherwise, if there are no direct calls to the function, we
6942 // have a free choice of whether to use standard or compressed
6943 // entries. Prefer microMIPS entries if the object is known to
6944 // contain microMIPS code, so that it becomes possible to create
6945 // pure microMIPS binaries. Prefer standard entries otherwise,
6946 // because MIPS16 ones are no smaller and are usually slower.
6947 if (!mips_sym
->needs_mips_plt() && !mips_sym
->needs_comp_plt())
6949 if (this->target_
->is_output_micromips())
6950 mips_sym
->set_needs_comp_plt(true);
6952 mips_sym
->set_needs_mips_plt(true);
6955 if (mips_sym
->needs_mips_plt())
6957 mips_sym
->set_mips_plt_offset(this->plt_mips_offset_
);
6958 this->plt_mips_offset_
+= plt_mips_entry_size
;
6960 if (mips_sym
->needs_comp_plt())
6962 mips_sym
->set_comp_plt_offset(this->plt_comp_offset_
);
6963 this->plt_comp_offset_
+= plt_comp_entry_size
;
6967 // Figure out the size of the PLT header if we know that we are using it.
6968 if (this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0)
6969 this->plt_header_size_
= this->get_plt_header_size();
6972 // Write out the PLT. This uses the hand-coded instructions above,
6973 // and adjusts them as needed.
6975 template<int size
, bool big_endian
>
6977 Mips_output_data_plt
<size
, big_endian
>::do_write(Output_file
* of
)
6979 const off_t offset
= this->offset();
6980 const section_size_type oview_size
=
6981 convert_to_section_size_type(this->data_size());
6982 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6984 const off_t gotplt_file_offset
= this->got_plt_
->offset();
6985 const section_size_type gotplt_size
=
6986 convert_to_section_size_type(this->got_plt_
->data_size());
6987 unsigned char* const gotplt_view
= of
->get_output_view(gotplt_file_offset
,
6989 unsigned char* pov
= oview
;
6991 Mips_address plt_address
= this->address();
6993 // Calculate the address of .got.plt.
6994 Mips_address gotplt_addr
= this->got_plt_
->address();
6995 Mips_address gotplt_addr_high
= ((gotplt_addr
+ 0x8000) >> 16) & 0xffff;
6996 Mips_address gotplt_addr_low
= gotplt_addr
& 0xffff;
6998 // The PLT sequence is not safe for N64 if .got.plt's address can
6999 // not be loaded in two instructions.
7000 gold_assert((gotplt_addr
& ~(Mips_address
) 0x7fffffff) == 0
7001 || ~(gotplt_addr
| 0x7fffffff) == 0);
7003 // Write the PLT header.
7004 const uint32_t* plt0_entry
= this->get_plt_header_entry();
7005 if (plt0_entry
== plt0_entry_micromips_o32
)
7007 // Write microMIPS PLT header.
7008 gold_assert(gotplt_addr
% 4 == 0);
7010 Mips_address gotpc_offset
= gotplt_addr
- ((plt_address
| 3) ^ 3);
7012 // ADDIUPC has a span of +/-16MB, check we're in range.
7013 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
7015 gold_error(_(".got.plt offset of %ld from .plt beyond the range of "
7016 "ADDIUPC"), (long)gotpc_offset
);
7020 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
7021 plt0_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
7022 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7023 (gotpc_offset
>> 2) & 0xffff);
7025 for (unsigned int i
= 2;
7026 i
< (sizeof(plt0_entry_micromips_o32
)
7027 / sizeof(plt0_entry_micromips_o32
[0]));
7030 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7034 else if (plt0_entry
== plt0_entry_micromips32_o32
)
7036 // Write microMIPS PLT header in insn32 mode.
7037 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[0]);
7038 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, gotplt_addr_high
);
7039 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, plt0_entry
[2]);
7040 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, gotplt_addr_low
);
7041 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8, plt0_entry
[4]);
7042 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, gotplt_addr_low
);
7044 for (unsigned int i
= 6;
7045 i
< (sizeof(plt0_entry_micromips32_o32
)
7046 / sizeof(plt0_entry_micromips32_o32
[0]));
7049 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7055 // Write standard PLT header.
7056 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7057 plt0_entry
[0] | gotplt_addr_high
);
7058 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7059 plt0_entry
[1] | gotplt_addr_low
);
7060 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
7061 plt0_entry
[2] | gotplt_addr_low
);
7063 for (int i
= 3; i
< 8; i
++)
7065 elfcpp::Swap
<32, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7071 unsigned char* gotplt_pov
= gotplt_view
;
7072 unsigned int got_entry_size
= size
/8; // TODO(sasa): MIPS_ELF_GOT_SIZE
7074 // The first two entries in .got.plt are reserved.
7075 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
, 0);
7076 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
+ got_entry_size
, 0);
7078 unsigned int gotplt_offset
= 2 * got_entry_size
;
7079 gotplt_pov
+= 2 * got_entry_size
;
7081 // Calculate the address of the PLT header.
7082 Mips_address header_address
= (plt_address
7083 + (this->is_plt_header_compressed() ? 1 : 0));
7085 // Initialize compressed PLT area view.
7086 unsigned char* pov2
= pov
+ this->plt_mips_offset_
;
7088 // Write the PLT entries.
7089 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
7090 p
= this->symbols_
.begin();
7091 p
!= this->symbols_
.end();
7092 ++p
, gotplt_pov
+= got_entry_size
, gotplt_offset
+= got_entry_size
)
7094 Mips_symbol
<size
>* mips_sym
= *p
;
7096 // Calculate the address of the .got.plt entry.
7097 uint32_t gotplt_entry_addr
= (gotplt_addr
+ gotplt_offset
);
7098 uint32_t gotplt_entry_addr_hi
= (((gotplt_entry_addr
+ 0x8000) >> 16)
7100 uint32_t gotplt_entry_addr_lo
= gotplt_entry_addr
& 0xffff;
7102 // Initially point the .got.plt entry at the PLT header.
7103 if (this->target_
->is_output_n64())
7104 elfcpp::Swap
<64, big_endian
>::writeval(gotplt_pov
, header_address
);
7106 elfcpp::Swap
<32, big_endian
>::writeval(gotplt_pov
, header_address
);
7108 // Now handle the PLT itself. First the standard entry.
7109 if (mips_sym
->has_mips_plt_offset())
7111 // Pick the load opcode (LW or LD).
7112 uint64_t load
= this->target_
->is_output_n64() ? 0xdc000000
7115 // Fill in the PLT entry itself.
7116 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7117 plt_entry
[0] | gotplt_entry_addr_hi
);
7118 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7119 plt_entry
[1] | gotplt_entry_addr_lo
| load
);
7120 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8, plt_entry
[2]);
7121 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12,
7122 plt_entry
[3] | gotplt_entry_addr_lo
);
7126 // Now the compressed entry. They come after any standard ones.
7127 if (mips_sym
->has_comp_plt_offset())
7129 if (!this->target_
->is_output_micromips())
7131 // Write MIPS16 PLT entry.
7132 const uint32_t* plt_entry
= plt_entry_mips16_o32
;
7134 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
7135 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2, plt_entry
[1]);
7136 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7137 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
7138 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7139 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7140 elfcpp::Swap
<32, big_endian
>::writeval(pov2
+ 12,
7144 else if (this->target_
->use_32bit_micromips_instructions())
7146 // Write microMIPS PLT entry in insn32 mode.
7147 const uint32_t* plt_entry
= plt_entry_micromips32_o32
;
7149 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
7150 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2,
7151 gotplt_entry_addr_hi
);
7152 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7153 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6,
7154 gotplt_entry_addr_lo
);
7155 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7156 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7157 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 12, plt_entry
[6]);
7158 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 14,
7159 gotplt_entry_addr_lo
);
7164 // Write microMIPS PLT entry.
7165 const uint32_t* plt_entry
= plt_entry_micromips_o32
;
7167 gold_assert(gotplt_entry_addr
% 4 == 0);
7169 Mips_address loc_address
= plt_address
+ pov2
- oview
;
7170 int gotpc_offset
= gotplt_entry_addr
- ((loc_address
| 3) ^ 3);
7172 // ADDIUPC has a span of +/-16MB, check we're in range.
7173 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
7175 gold_error(_(".got.plt offset of %ld from .plt beyond the "
7176 "range of ADDIUPC"), (long)gotpc_offset
);
7180 elfcpp::Swap
<16, big_endian
>::writeval(pov2
,
7181 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
7182 elfcpp::Swap
<16, big_endian
>::writeval(
7183 pov2
+ 2, (gotpc_offset
>> 2) & 0xffff);
7184 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7185 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
7186 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7187 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7193 // Check the number of bytes written for standard entries.
7194 gold_assert(static_cast<section_size_type
>(
7195 pov
- oview
- this->plt_header_size_
) == this->plt_mips_offset_
);
7196 // Check the number of bytes written for compressed entries.
7197 gold_assert((static_cast<section_size_type
>(pov2
- pov
)
7198 == this->plt_comp_offset_
));
7199 // Check the total number of bytes written.
7200 gold_assert(static_cast<section_size_type
>(pov2
- oview
) == oview_size
);
7202 gold_assert(static_cast<section_size_type
>(gotplt_pov
- gotplt_view
)
7205 of
->write_output_view(offset
, oview_size
, oview
);
7206 of
->write_output_view(gotplt_file_offset
, gotplt_size
, gotplt_view
);
7209 // Mips_output_data_mips_stubs methods.
7211 // The format of the lazy binding stub when dynamic symbol count is less than
7212 // 64K, dynamic symbol index is less than 32K, and ABI is not N64.
7213 template<int size
, bool big_endian
>
7215 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1
[4] =
7217 0x8f998010, // lw t9,0x8010(gp)
7218 0x03e07825, // or t7,ra,zero
7219 0x0320f809, // jalr t9,ra
7220 0x24180000 // addiu t8,zero,DYN_INDEX sign extended
7223 // The format of the lazy binding stub when dynamic symbol count is less than
7224 // 64K, dynamic symbol index is less than 32K, and ABI is N64.
7225 template<int size
, bool big_endian
>
7227 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1_n64
[4] =
7229 0xdf998010, // ld t9,0x8010(gp)
7230 0x03e07825, // or t7,ra,zero
7231 0x0320f809, // jalr t9,ra
7232 0x64180000 // daddiu t8,zero,DYN_INDEX sign extended
7235 // The format of the lazy binding stub when dynamic symbol count is less than
7236 // 64K, dynamic symbol index is between 32K and 64K, and ABI is not N64.
7237 template<int size
, bool big_endian
>
7239 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2
[4] =
7241 0x8f998010, // lw t9,0x8010(gp)
7242 0x03e07825, // or t7,ra,zero
7243 0x0320f809, // jalr t9,ra
7244 0x34180000 // ori t8,zero,DYN_INDEX unsigned
7247 // The format of the lazy binding stub when dynamic symbol count is less than
7248 // 64K, dynamic symbol index is between 32K and 64K, and ABI is N64.
7249 template<int size
, bool big_endian
>
7251 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2_n64
[4] =
7253 0xdf998010, // ld t9,0x8010(gp)
7254 0x03e07825, // or t7,ra,zero
7255 0x0320f809, // jalr t9,ra
7256 0x34180000 // ori t8,zero,DYN_INDEX unsigned
7259 // The format of the lazy binding stub when dynamic symbol count is greater than
7260 // 64K, and ABI is not N64.
7261 template<int size
, bool big_endian
>
7262 const uint32_t Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big
[5] =
7264 0x8f998010, // lw t9,0x8010(gp)
7265 0x03e07825, // or t7,ra,zero
7266 0x3c180000, // lui t8,DYN_INDEX
7267 0x0320f809, // jalr t9,ra
7268 0x37180000 // ori t8,t8,DYN_INDEX
7271 // The format of the lazy binding stub when dynamic symbol count is greater than
7272 // 64K, and ABI is N64.
7273 template<int size
, bool big_endian
>
7275 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big_n64
[5] =
7277 0xdf998010, // ld t9,0x8010(gp)
7278 0x03e07825, // or t7,ra,zero
7279 0x3c180000, // lui t8,DYN_INDEX
7280 0x0320f809, // jalr t9,ra
7281 0x37180000 // ori t8,t8,DYN_INDEX
7286 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7287 // less than 64K, dynamic symbol index is less than 32K, and ABI is not N64.
7288 template<int size
, bool big_endian
>
7290 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_1
[] =
7292 0xff3c, 0x8010, // lw t9,0x8010(gp)
7293 0x0dff, // move t7,ra
7295 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
7298 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7299 // less than 64K, dynamic symbol index is less than 32K, and ABI is N64.
7300 template<int size
, bool big_endian
>
7302 Mips_output_data_mips_stubs
<size
, big_endian
>::
7303 lazy_stub_micromips_normal_1_n64
[] =
7305 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7306 0x0dff, // move t7,ra
7308 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
7311 // The format of the microMIPS lazy binding stub when dynamic symbol
7312 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7313 // and ABI is not N64.
7314 template<int size
, bool big_endian
>
7316 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_2
[] =
7318 0xff3c, 0x8010, // lw t9,0x8010(gp)
7319 0x0dff, // move t7,ra
7321 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7324 // The format of the microMIPS lazy binding stub when dynamic symbol
7325 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7327 template<int size
, bool big_endian
>
7329 Mips_output_data_mips_stubs
<size
, big_endian
>::
7330 lazy_stub_micromips_normal_2_n64
[] =
7332 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7333 0x0dff, // move t7,ra
7335 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7338 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7339 // greater than 64K, and ABI is not N64.
7340 template<int size
, bool big_endian
>
7342 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big
[] =
7344 0xff3c, 0x8010, // lw t9,0x8010(gp)
7345 0x0dff, // move t7,ra
7346 0x41b8, 0x0000, // lui t8,DYN_INDEX
7348 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7351 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7352 // greater than 64K, and ABI is N64.
7353 template<int size
, bool big_endian
>
7355 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big_n64
[] =
7357 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7358 0x0dff, // move t7,ra
7359 0x41b8, 0x0000, // lui t8,DYN_INDEX
7361 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7364 // 32-bit microMIPS stubs.
7366 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7367 // less than 64K, dynamic symbol index is less than 32K, ABI is not N64, and we
7368 // can use only 32-bit instructions.
7369 template<int size
, bool big_endian
>
7371 Mips_output_data_mips_stubs
<size
, big_endian
>::
7372 lazy_stub_micromips32_normal_1
[] =
7374 0xff3c, 0x8010, // lw t9,0x8010(gp)
7375 0x001f, 0x7a90, // or t7,ra,zero
7376 0x03f9, 0x0f3c, // jalr ra,t9
7377 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
7380 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7381 // less than 64K, dynamic symbol index is less than 32K, ABI is N64, and we can
7382 // use only 32-bit instructions.
7383 template<int size
, bool big_endian
>
7385 Mips_output_data_mips_stubs
<size
, big_endian
>::
7386 lazy_stub_micromips32_normal_1_n64
[] =
7388 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7389 0x001f, 0x7a90, // or t7,ra,zero
7390 0x03f9, 0x0f3c, // jalr ra,t9
7391 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
7394 // The format of the microMIPS lazy binding stub when dynamic symbol
7395 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7396 // ABI is not N64, and we can use only 32-bit instructions.
7397 template<int size
, bool big_endian
>
7399 Mips_output_data_mips_stubs
<size
, big_endian
>::
7400 lazy_stub_micromips32_normal_2
[] =
7402 0xff3c, 0x8010, // lw t9,0x8010(gp)
7403 0x001f, 0x7a90, // or t7,ra,zero
7404 0x03f9, 0x0f3c, // jalr ra,t9
7405 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7408 // The format of the microMIPS lazy binding stub when dynamic symbol
7409 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7410 // ABI is N64, and we can use only 32-bit instructions.
7411 template<int size
, bool big_endian
>
7413 Mips_output_data_mips_stubs
<size
, big_endian
>::
7414 lazy_stub_micromips32_normal_2_n64
[] =
7416 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7417 0x001f, 0x7a90, // or t7,ra,zero
7418 0x03f9, 0x0f3c, // jalr ra,t9
7419 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7422 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7423 // greater than 64K, ABI is not N64, and we can use only 32-bit instructions.
7424 template<int size
, bool big_endian
>
7426 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big
[] =
7428 0xff3c, 0x8010, // lw t9,0x8010(gp)
7429 0x001f, 0x7a90, // or t7,ra,zero
7430 0x41b8, 0x0000, // lui t8,DYN_INDEX
7431 0x03f9, 0x0f3c, // jalr ra,t9
7432 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7435 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7436 // greater than 64K, ABI is N64, and we can use only 32-bit instructions.
7437 template<int size
, bool big_endian
>
7439 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big_n64
[] =
7441 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7442 0x001f, 0x7a90, // or t7,ra,zero
7443 0x41b8, 0x0000, // lui t8,DYN_INDEX
7444 0x03f9, 0x0f3c, // jalr ra,t9
7445 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7448 // Create entry for a symbol.
7450 template<int size
, bool big_endian
>
7452 Mips_output_data_mips_stubs
<size
, big_endian
>::make_entry(
7453 Mips_symbol
<size
>* gsym
)
7455 if (!gsym
->has_lazy_stub() && !gsym
->has_plt_offset())
7457 this->symbols_
.insert(gsym
);
7458 gsym
->set_has_lazy_stub(true);
7462 // Remove entry for a symbol.
7464 template<int size
, bool big_endian
>
7466 Mips_output_data_mips_stubs
<size
, big_endian
>::remove_entry(
7467 Mips_symbol
<size
>* gsym
)
7469 if (gsym
->has_lazy_stub())
7471 this->symbols_
.erase(gsym
);
7472 gsym
->set_has_lazy_stub(false);
7476 // Set stub offsets for symbols. This method expects that the number of
7477 // entries in dynamic symbol table is set.
7479 template<int size
, bool big_endian
>
7481 Mips_output_data_mips_stubs
<size
, big_endian
>::set_lazy_stub_offsets()
7483 gold_assert(this->dynsym_count_
!= -1U);
7485 if (this->stub_offsets_are_set_
)
7488 unsigned int stub_size
= this->stub_size();
7489 unsigned int offset
= 0;
7490 for (typename Unordered_set
<Mips_symbol
<size
>*>::const_iterator
7491 p
= this->symbols_
.begin();
7492 p
!= this->symbols_
.end();
7493 ++p
, offset
+= stub_size
)
7495 Mips_symbol
<size
>* mips_sym
= *p
;
7496 mips_sym
->set_lazy_stub_offset(offset
);
7498 this->stub_offsets_are_set_
= true;
7501 template<int size
, bool big_endian
>
7503 Mips_output_data_mips_stubs
<size
, big_endian
>::set_needs_dynsym_value()
7505 for (typename Unordered_set
<Mips_symbol
<size
>*>::const_iterator
7506 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
7508 Mips_symbol
<size
>* sym
= *p
;
7509 if (sym
->is_from_dynobj())
7510 sym
->set_needs_dynsym_value();
7514 // Write out the .MIPS.stubs. This uses the hand-coded instructions and
7515 // adjusts them as needed.
7517 template<int size
, bool big_endian
>
7519 Mips_output_data_mips_stubs
<size
, big_endian
>::do_write(Output_file
* of
)
7521 const off_t offset
= this->offset();
7522 const section_size_type oview_size
=
7523 convert_to_section_size_type(this->data_size());
7524 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
7526 bool big_stub
= this->dynsym_count_
> 0x10000;
7528 unsigned char* pov
= oview
;
7529 for (typename Unordered_set
<Mips_symbol
<size
>*>::const_iterator
7530 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
7532 Mips_symbol
<size
>* sym
= *p
;
7533 const uint32_t* lazy_stub
;
7534 bool n64
= this->target_
->is_output_n64();
7536 if (!this->target_
->is_output_micromips())
7538 // Write standard (non-microMIPS) stub.
7541 if (sym
->dynsym_index() & ~0x7fff)
7542 // Dynsym index is between 32K and 64K.
7543 lazy_stub
= n64
? lazy_stub_normal_2_n64
: lazy_stub_normal_2
;
7545 // Dynsym index is less than 32K.
7546 lazy_stub
= n64
? lazy_stub_normal_1_n64
: lazy_stub_normal_1
;
7549 lazy_stub
= n64
? lazy_stub_big_n64
: lazy_stub_big
;
7552 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7553 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 1]);
7559 // LUI instruction of the big stub. Paste high 16 bits of the
7561 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7562 lazy_stub
[i
] | ((sym
->dynsym_index() >> 16) & 0x7fff));
7566 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7567 // Last stub instruction. Paste low 16 bits of the dynsym index.
7568 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7569 lazy_stub
[i
+ 1] | (sym
->dynsym_index() & 0xffff));
7572 else if (this->target_
->use_32bit_micromips_instructions())
7574 // Write microMIPS stub in insn32 mode.
7577 if (sym
->dynsym_index() & ~0x7fff)
7578 // Dynsym index is between 32K and 64K.
7579 lazy_stub
= n64
? lazy_stub_micromips32_normal_2_n64
7580 : lazy_stub_micromips32_normal_2
;
7582 // Dynsym index is less than 32K.
7583 lazy_stub
= n64
? lazy_stub_micromips32_normal_1_n64
7584 : lazy_stub_micromips32_normal_1
;
7587 lazy_stub
= n64
? lazy_stub_micromips32_big_n64
7588 : lazy_stub_micromips32_big
;
7591 // First stub instruction. We emit 32-bit microMIPS instructions by
7592 // emitting two 16-bit parts because on microMIPS the 16-bit part of
7593 // the instruction where the opcode is must always come first, for
7594 // both little and big endian.
7595 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7596 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7597 // Second stub instruction.
7598 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7599 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, lazy_stub
[i
+ 3]);
7604 // LUI instruction of the big stub. Paste high 16 bits of the
7606 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7607 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7608 (sym
->dynsym_index() >> 16) & 0x7fff);
7612 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7613 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7614 // Last stub instruction. Paste low 16 bits of the dynsym index.
7615 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7616 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
7617 sym
->dynsym_index() & 0xffff);
7622 // Write microMIPS stub.
7625 if (sym
->dynsym_index() & ~0x7fff)
7626 // Dynsym index is between 32K and 64K.
7627 lazy_stub
= n64
? lazy_stub_micromips_normal_2_n64
7628 : lazy_stub_micromips_normal_2
;
7630 // Dynsym index is less than 32K.
7631 lazy_stub
= n64
? lazy_stub_micromips_normal_1_n64
7632 : lazy_stub_micromips_normal_1
;
7635 lazy_stub
= n64
? lazy_stub_micromips_big_n64
7636 : lazy_stub_micromips_big
;
7639 // First stub instruction. We emit 32-bit microMIPS instructions by
7640 // emitting two 16-bit parts because on microMIPS the 16-bit part of
7641 // the instruction where the opcode is must always come first, for
7642 // both little and big endian.
7643 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7644 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7645 // Second stub instruction.
7646 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7651 // LUI instruction of the big stub. Paste high 16 bits of the
7653 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7654 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7655 (sym
->dynsym_index() >> 16) & 0x7fff);
7659 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7660 // Last stub instruction. Paste low 16 bits of the dynsym index.
7661 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7662 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
7663 sym
->dynsym_index() & 0xffff);
7668 // We always allocate 20 bytes for every stub, because final dynsym count is
7669 // not known in method do_finalize_sections. There are 4 unused bytes per
7670 // stub if final dynsym count is less than 0x10000.
7671 unsigned int used
= pov
- oview
;
7672 unsigned int unused
= big_stub
? 0 : this->symbols_
.size() * 4;
7673 gold_assert(static_cast<section_size_type
>(used
+ unused
) == oview_size
);
7675 // Fill the unused space with zeroes.
7676 // TODO(sasa): Can we strip unused bytes during the relaxation?
7678 memset(pov
, 0, unused
);
7680 of
->write_output_view(offset
, oview_size
, oview
);
7683 // Mips_output_section_reginfo methods.
7685 template<int size
, bool big_endian
>
7687 Mips_output_section_reginfo
<size
, big_endian
>::do_write(Output_file
* of
)
7689 off_t offset
= this->offset();
7690 off_t data_size
= this->data_size();
7692 unsigned char* view
= of
->get_output_view(offset
, data_size
);
7693 elfcpp::Swap
<size
, big_endian
>::writeval(view
, this->gprmask_
);
7694 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 4, this->cprmask1_
);
7695 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 8, this->cprmask2_
);
7696 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 12, this->cprmask3_
);
7697 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 16, this->cprmask4_
);
7698 // Write the gp value.
7699 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 20,
7700 this->target_
->gp_value());
7702 of
->write_output_view(offset
, data_size
, view
);
7705 // Mips_copy_relocs methods.
7707 // Emit any saved relocs.
7709 template<int sh_type
, int size
, bool big_endian
>
7711 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_mips(
7712 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
7713 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
7715 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
7716 Copy_reloc_entries::iterator p
= this->entries_
.begin();
7717 p
!= this->entries_
.end();
7719 emit_entry(*p
, reloc_section
, symtab
, layout
, target
);
7721 // We no longer need the saved information.
7722 this->entries_
.clear();
7725 // Emit the reloc if appropriate.
7727 template<int sh_type
, int size
, bool big_endian
>
7729 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_entry(
7730 Copy_reloc_entry
& entry
,
7731 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
7732 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
7734 // If the symbol is no longer defined in a dynamic object, then we
7735 // emitted a COPY relocation, and we do not want to emit this
7736 // dynamic relocation.
7737 if (!entry
.sym_
->is_from_dynobj())
7740 bool can_make_dynamic
= (entry
.reloc_type_
== elfcpp::R_MIPS_32
7741 || entry
.reloc_type_
== elfcpp::R_MIPS_REL32
7742 || entry
.reloc_type_
== elfcpp::R_MIPS_64
);
7744 Mips_symbol
<size
>* sym
= Mips_symbol
<size
>::as_mips_sym(entry
.sym_
);
7745 if (can_make_dynamic
&& !sym
->has_static_relocs())
7747 Mips_relobj
<size
, big_endian
>* object
=
7748 Mips_relobj
<size
, big_endian
>::as_mips_relobj(entry
.relobj_
);
7749 target
->got_section(symtab
, layout
)->record_global_got_symbol(
7750 sym
, object
, entry
.reloc_type_
, true, false);
7751 if (!symbol_references_local(sym
, sym
->should_add_dynsym_entry(symtab
)))
7752 target
->rel_dyn_section(layout
)->add_global(sym
, elfcpp::R_MIPS_REL32
,
7753 entry
.output_section_
, entry
.relobj_
, entry
.shndx_
, entry
.address_
);
7755 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
7756 sym
, elfcpp::R_MIPS_REL32
, entry
.output_section_
, entry
.relobj_
,
7757 entry
.shndx_
, entry
.address_
);
7760 this->make_copy_reloc(symtab
, layout
,
7761 static_cast<Sized_symbol
<size
>*>(entry
.sym_
),
7765 // Target_mips methods.
7767 // Return the value to use for a dynamic symbol which requires special
7768 // treatment. This is how we support equality comparisons of function
7769 // pointers across shared library boundaries, as described in the
7770 // processor specific ABI supplement.
7772 template<int size
, bool big_endian
>
7774 Target_mips
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
7777 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
7779 if (!mips_sym
->has_lazy_stub())
7781 if (mips_sym
->has_plt_offset())
7783 // We distinguish between PLT entries and lazy-binding stubs by
7784 // giving the former an st_other value of STO_MIPS_PLT. Set the
7785 // value to the stub address if there are any relocations in the
7786 // binary where pointer equality matters.
7787 if (mips_sym
->pointer_equality_needed())
7789 // Prefer a standard MIPS PLT entry.
7790 if (mips_sym
->has_mips_plt_offset())
7791 value
= this->plt_section()->mips_entry_address(mips_sym
);
7793 value
= this->plt_section()->comp_entry_address(mips_sym
) + 1;
7801 // First, set stub offsets for symbols. This method expects that the
7802 // number of entries in dynamic symbol table is set.
7803 this->mips_stubs_section()->set_lazy_stub_offsets();
7805 // The run-time linker uses the st_value field of the symbol
7806 // to reset the global offset table entry for this external
7807 // to its stub address when unlinking a shared object.
7808 value
= this->mips_stubs_section()->stub_address(mips_sym
);
7811 if (mips_sym
->has_mips16_fn_stub())
7813 // If we have a MIPS16 function with a stub, the dynamic symbol must
7814 // refer to the stub, since only the stub uses the standard calling
7816 value
= mips_sym
->template
7817 get_mips16_fn_stub
<big_endian
>()->output_address();
7823 // Get the dynamic reloc section, creating it if necessary. It's always
7824 // .rel.dyn, even for MIPS64.
7826 template<int size
, bool big_endian
>
7827 typename Target_mips
<size
, big_endian
>::Reloc_section
*
7828 Target_mips
<size
, big_endian
>::rel_dyn_section(Layout
* layout
)
7830 if (this->rel_dyn_
== NULL
)
7832 gold_assert(layout
!= NULL
);
7833 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
7834 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
7835 elfcpp::SHF_ALLOC
, this->rel_dyn_
,
7836 ORDER_DYNAMIC_RELOCS
, false);
7838 // First entry in .rel.dyn has to be null.
7839 // This is hack - we define dummy output data and set its address to 0,
7840 // and define absolute R_MIPS_NONE relocation with offset 0 against it.
7841 // This ensures that the entry is null.
7842 Output_data
* od
= new Output_data_zero_fill(0, 0);
7844 this->rel_dyn_
->add_absolute(elfcpp::R_MIPS_NONE
, od
, 0);
7846 return this->rel_dyn_
;
7849 // Get the GOT section, creating it if necessary.
7851 template<int size
, bool big_endian
>
7852 Mips_output_data_got
<size
, big_endian
>*
7853 Target_mips
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
7856 if (this->got_
== NULL
)
7858 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
7860 this->got_
= new Mips_output_data_got
<size
, big_endian
>(this, symtab
,
7862 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
7863 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
|
7864 elfcpp::SHF_MIPS_GPREL
),
7865 this->got_
, ORDER_DATA
, false);
7867 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
7868 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
7869 Symbol_table::PREDEFINED
,
7871 0, 0, elfcpp::STT_OBJECT
,
7873 elfcpp::STV_DEFAULT
, 0,
7880 // Calculate value of _gp symbol.
7882 template<int size
, bool big_endian
>
7884 Target_mips
<size
, big_endian
>::set_gp(Layout
* layout
, Symbol_table
* symtab
)
7886 if (this->gp_
!= NULL
)
7889 Output_data
* section
= layout
->find_output_section(".got");
7890 if (section
== NULL
)
7892 // If there is no .got section, gp should be based on .sdata.
7893 // TODO(sasa): This is probably not needed. This was needed for older
7894 // MIPS architectures which accessed both GOT and .sdata section using
7895 // gp-relative addressing. Modern Mips Linux ELF architectures don't
7896 // access .sdata using gp-relative addressing.
7897 for (Layout::Section_list::const_iterator
7898 p
= layout
->section_list().begin();
7899 p
!= layout
->section_list().end();
7902 if (strcmp((*p
)->name(), ".sdata") == 0)
7910 Sized_symbol
<size
>* gp
=
7911 static_cast<Sized_symbol
<size
>*>(symtab
->lookup("_gp"));
7914 if (gp
->source() != Symbol::IS_CONSTANT
&& section
!= NULL
)
7915 gp
->init_output_data(gp
->name(), NULL
, section
, MIPS_GP_OFFSET
, 0,
7918 elfcpp::STV_DEFAULT
, 0,
7922 else if (section
!= NULL
)
7924 gp
= static_cast<Sized_symbol
<size
>*>(symtab
->define_in_output_data(
7925 "_gp", NULL
, Symbol_table::PREDEFINED
,
7926 section
, MIPS_GP_OFFSET
, 0,
7929 elfcpp::STV_DEFAULT
,
7935 // Set the dynamic symbol indexes. INDEX is the index of the first
7936 // global dynamic symbol. Pointers to the symbols are stored into the
7937 // vector SYMS. The names are added to DYNPOOL. This returns an
7938 // updated dynamic symbol index.
7940 template<int size
, bool big_endian
>
7942 Target_mips
<size
, big_endian
>::do_set_dynsym_indexes(
7943 std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
7944 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
7945 Versions
* versions
, Symbol_table
* symtab
) const
7947 std::vector
<Symbol
*> non_got_symbols
;
7948 std::vector
<Symbol
*> got_symbols
;
7950 reorder_dyn_symbols
<size
, big_endian
>(dyn_symbols
, &non_got_symbols
,
7953 for (std::vector
<Symbol
*>::iterator p
= non_got_symbols
.begin();
7954 p
!= non_got_symbols
.end();
7959 // Note that SYM may already have a dynamic symbol index, since
7960 // some symbols appear more than once in the symbol table, with
7961 // and without a version.
7963 if (!sym
->has_dynsym_index())
7965 sym
->set_dynsym_index(index
);
7967 syms
->push_back(sym
);
7968 dynpool
->add(sym
->name(), false, NULL
);
7970 // Record any version information.
7971 if (sym
->version() != NULL
)
7972 versions
->record_version(symtab
, dynpool
, sym
);
7974 // If the symbol is defined in a dynamic object and is
7975 // referenced in a regular object, then mark the dynamic
7976 // object as needed. This is used to implement --as-needed.
7977 if (sym
->is_from_dynobj() && sym
->in_reg())
7978 sym
->object()->set_is_needed();
7982 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
7983 p
!= got_symbols
.end();
7987 if (!sym
->has_dynsym_index())
7989 // Record any version information.
7990 if (sym
->version() != NULL
)
7991 versions
->record_version(symtab
, dynpool
, sym
);
7995 index
= versions
->finalize(symtab
, index
, syms
);
7997 int got_sym_count
= 0;
7998 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
7999 p
!= got_symbols
.end();
8004 if (!sym
->has_dynsym_index())
8007 sym
->set_dynsym_index(index
);
8009 syms
->push_back(sym
);
8010 dynpool
->add(sym
->name(), false, NULL
);
8012 // If the symbol is defined in a dynamic object and is
8013 // referenced in a regular object, then mark the dynamic
8014 // object as needed. This is used to implement --as-needed.
8015 if (sym
->is_from_dynobj() && sym
->in_reg())
8016 sym
->object()->set_is_needed();
8020 // Set index of the first symbol that has .got entry.
8021 this->got_
->set_first_global_got_dynsym_index(
8022 got_sym_count
> 0 ? index
- got_sym_count
: -1U);
8024 if (this->mips_stubs_
!= NULL
)
8025 this->mips_stubs_
->set_dynsym_count(index
);
8030 // Create a PLT entry for a global symbol referenced by r_type relocation.
8032 template<int size
, bool big_endian
>
8034 Target_mips
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
8036 Mips_symbol
<size
>* gsym
,
8037 unsigned int r_type
)
8039 if (gsym
->has_lazy_stub() || gsym
->has_plt_offset())
8042 if (this->plt_
== NULL
)
8044 // Create the GOT section first.
8045 this->got_section(symtab
, layout
);
8047 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
8048 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
8049 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
8050 this->got_plt_
, ORDER_DATA
, false);
8052 // The first two entries are reserved.
8053 this->got_plt_
->set_current_data_size(2 * size
/8);
8055 this->plt_
= new Mips_output_data_plt
<size
, big_endian
>(layout
,
8058 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
8060 | elfcpp::SHF_EXECINSTR
),
8061 this->plt_
, ORDER_PLT
, false);
8064 this->plt_
->add_entry(gsym
, r_type
);
8068 // Get the .MIPS.stubs section, creating it if necessary.
8070 template<int size
, bool big_endian
>
8071 Mips_output_data_mips_stubs
<size
, big_endian
>*
8072 Target_mips
<size
, big_endian
>::mips_stubs_section(Layout
* layout
)
8074 if (this->mips_stubs_
== NULL
)
8077 new Mips_output_data_mips_stubs
<size
, big_endian
>(this);
8078 layout
->add_output_section_data(".MIPS.stubs", elfcpp::SHT_PROGBITS
,
8080 | elfcpp::SHF_EXECINSTR
),
8081 this->mips_stubs_
, ORDER_PLT
, false);
8083 return this->mips_stubs_
;
8086 // Get the LA25 stub section, creating it if necessary.
8088 template<int size
, bool big_endian
>
8089 Mips_output_data_la25_stub
<size
, big_endian
>*
8090 Target_mips
<size
, big_endian
>::la25_stub_section(Layout
* layout
)
8092 if (this->la25_stub_
== NULL
)
8094 this->la25_stub_
= new Mips_output_data_la25_stub
<size
, big_endian
>();
8095 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
8097 | elfcpp::SHF_EXECINSTR
),
8098 this->la25_stub_
, ORDER_TEXT
, false);
8100 return this->la25_stub_
;
8103 // Process the relocations to determine unreferenced sections for
8104 // garbage collection.
8106 template<int size
, bool big_endian
>
8108 Target_mips
<size
, big_endian
>::gc_process_relocs(
8109 Symbol_table
* symtab
,
8111 Sized_relobj_file
<size
, big_endian
>* object
,
8112 unsigned int data_shndx
,
8113 unsigned int sh_type
,
8114 const unsigned char* prelocs
,
8116 Output_section
* output_section
,
8117 bool needs_special_offset_handling
,
8118 size_t local_symbol_count
,
8119 const unsigned char* plocal_symbols
)
8121 typedef Target_mips
<size
, big_endian
> Mips
;
8123 if (sh_type
== elfcpp::SHT_REL
)
8125 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8128 gold::gc_process_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8137 needs_special_offset_handling
,
8141 else if (sh_type
== elfcpp::SHT_RELA
)
8143 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8146 gold::gc_process_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8155 needs_special_offset_handling
,
8163 // Scan relocations for a section.
8165 template<int size
, bool big_endian
>
8167 Target_mips
<size
, big_endian
>::scan_relocs(
8168 Symbol_table
* symtab
,
8170 Sized_relobj_file
<size
, big_endian
>* object
,
8171 unsigned int data_shndx
,
8172 unsigned int sh_type
,
8173 const unsigned char* prelocs
,
8175 Output_section
* output_section
,
8176 bool needs_special_offset_handling
,
8177 size_t local_symbol_count
,
8178 const unsigned char* plocal_symbols
)
8180 typedef Target_mips
<size
, big_endian
> Mips
;
8182 if (sh_type
== elfcpp::SHT_REL
)
8184 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8187 gold::scan_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8196 needs_special_offset_handling
,
8200 else if (sh_type
== elfcpp::SHT_RELA
)
8202 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8205 gold::scan_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8214 needs_special_offset_handling
,
8220 template<int size
, bool big_endian
>
8222 Target_mips
<size
, big_endian
>::mips_32bit_flags(elfcpp::Elf_Word flags
)
8224 return ((flags
& elfcpp::EF_MIPS_32BITMODE
) != 0
8225 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_O32
8226 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_EABI32
8227 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_1
8228 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_2
8229 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32
8230 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32R2
);
8233 // Return the MACH for a MIPS e_flags value.
8234 template<int size
, bool big_endian
>
8236 Target_mips
<size
, big_endian
>::elf_mips_mach(elfcpp::Elf_Word flags
)
8238 switch (flags
& elfcpp::EF_MIPS_MACH
)
8240 case elfcpp::E_MIPS_MACH_3900
:
8241 return mach_mips3900
;
8243 case elfcpp::E_MIPS_MACH_4010
:
8244 return mach_mips4010
;
8246 case elfcpp::E_MIPS_MACH_4100
:
8247 return mach_mips4100
;
8249 case elfcpp::E_MIPS_MACH_4111
:
8250 return mach_mips4111
;
8252 case elfcpp::E_MIPS_MACH_4120
:
8253 return mach_mips4120
;
8255 case elfcpp::E_MIPS_MACH_4650
:
8256 return mach_mips4650
;
8258 case elfcpp::E_MIPS_MACH_5400
:
8259 return mach_mips5400
;
8261 case elfcpp::E_MIPS_MACH_5500
:
8262 return mach_mips5500
;
8264 case elfcpp::E_MIPS_MACH_9000
:
8265 return mach_mips9000
;
8267 case elfcpp::E_MIPS_MACH_SB1
:
8268 return mach_mips_sb1
;
8270 case elfcpp::E_MIPS_MACH_LS2E
:
8271 return mach_mips_loongson_2e
;
8273 case elfcpp::E_MIPS_MACH_LS2F
:
8274 return mach_mips_loongson_2f
;
8276 case elfcpp::E_MIPS_MACH_LS3A
:
8277 return mach_mips_loongson_3a
;
8279 case elfcpp::E_MIPS_MACH_OCTEON2
:
8280 return mach_mips_octeon2
;
8282 case elfcpp::E_MIPS_MACH_OCTEON
:
8283 return mach_mips_octeon
;
8285 case elfcpp::E_MIPS_MACH_XLR
:
8286 return mach_mips_xlr
;
8289 switch (flags
& elfcpp::EF_MIPS_ARCH
)
8292 case elfcpp::E_MIPS_ARCH_1
:
8293 return mach_mips3000
;
8295 case elfcpp::E_MIPS_ARCH_2
:
8296 return mach_mips6000
;
8298 case elfcpp::E_MIPS_ARCH_3
:
8299 return mach_mips4000
;
8301 case elfcpp::E_MIPS_ARCH_4
:
8302 return mach_mips8000
;
8304 case elfcpp::E_MIPS_ARCH_5
:
8307 case elfcpp::E_MIPS_ARCH_32
:
8308 return mach_mipsisa32
;
8310 case elfcpp::E_MIPS_ARCH_64
:
8311 return mach_mipsisa64
;
8313 case elfcpp::E_MIPS_ARCH_32R2
:
8314 return mach_mipsisa32r2
;
8316 case elfcpp::E_MIPS_ARCH_64R2
:
8317 return mach_mipsisa64r2
;
8324 // Check whether machine EXTENSION is an extension of machine BASE.
8325 template<int size
, bool big_endian
>
8327 Target_mips
<size
, big_endian
>::mips_mach_extends(unsigned int base
,
8328 unsigned int extension
)
8330 if (extension
== base
)
8333 if ((base
== mach_mipsisa32
)
8334 && this->mips_mach_extends(mach_mipsisa64
, extension
))
8337 if ((base
== mach_mipsisa32r2
)
8338 && this->mips_mach_extends(mach_mipsisa64r2
, extension
))
8341 for (unsigned int i
= 0; i
< this->mips_mach_extensions_
.size(); ++i
)
8342 if (extension
== this->mips_mach_extensions_
[i
].first
)
8344 extension
= this->mips_mach_extensions_
[i
].second
;
8345 if (extension
== base
)
8352 template<int size
, bool big_endian
>
8354 Target_mips
<size
, big_endian
>::merge_processor_specific_flags(
8355 const std::string
& name
, elfcpp::Elf_Word in_flags
,
8356 unsigned char in_ei_class
, bool dyn_obj
)
8358 // If flags are not set yet, just copy them.
8359 if (!this->are_processor_specific_flags_set())
8361 this->set_processor_specific_flags(in_flags
);
8362 this->ei_class_
= in_ei_class
;
8363 this->mach_
= this->elf_mips_mach(in_flags
);
8367 elfcpp::Elf_Word new_flags
= in_flags
;
8368 elfcpp::Elf_Word old_flags
= this->processor_specific_flags();
8369 elfcpp::Elf_Word merged_flags
= this->processor_specific_flags();
8370 merged_flags
|= new_flags
& elfcpp::EF_MIPS_NOREORDER
;
8372 // Check flag compatibility.
8373 new_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
8374 old_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
8376 // Some IRIX 6 BSD-compatibility objects have this bit set. It
8377 // doesn't seem to matter.
8378 new_flags
&= ~elfcpp::EF_MIPS_XGOT
;
8379 old_flags
&= ~elfcpp::EF_MIPS_XGOT
;
8381 // MIPSpro generates ucode info in n64 objects. Again, we should
8382 // just be able to ignore this.
8383 new_flags
&= ~elfcpp::EF_MIPS_UCODE
;
8384 old_flags
&= ~elfcpp::EF_MIPS_UCODE
;
8386 // DSOs should only be linked with CPIC code.
8388 new_flags
|= elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
;
8390 if (new_flags
== old_flags
)
8392 this->set_processor_specific_flags(merged_flags
);
8396 if (((new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0)
8397 != ((old_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0))
8398 gold_warning(_("%s: linking abicalls files with non-abicalls files"),
8401 if (new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
))
8402 merged_flags
|= elfcpp::EF_MIPS_CPIC
;
8403 if (!(new_flags
& elfcpp::EF_MIPS_PIC
))
8404 merged_flags
&= ~elfcpp::EF_MIPS_PIC
;
8406 new_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
8407 old_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
8409 // Compare the ISAs.
8410 if (mips_32bit_flags(old_flags
) != mips_32bit_flags(new_flags
))
8411 gold_error(_("%s: linking 32-bit code with 64-bit code"), name
.c_str());
8412 else if (!this->mips_mach_extends(this->elf_mips_mach(in_flags
), this->mach_
))
8414 // Output ISA isn't the same as, or an extension of, input ISA.
8415 if (this->mips_mach_extends(this->mach_
, this->elf_mips_mach(in_flags
)))
8417 // Copy the architecture info from input object to output. Also copy
8418 // the 32-bit flag (if set) so that we continue to recognise
8419 // output as a 32-bit binary.
8420 this->mach_
= this->elf_mips_mach(in_flags
);
8421 merged_flags
&= ~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
);
8422 merged_flags
|= (new_flags
& (elfcpp::EF_MIPS_ARCH
8423 | elfcpp::EF_MIPS_MACH
| elfcpp::EF_MIPS_32BITMODE
));
8425 // Copy across the ABI flags if output doesn't use them
8426 // and if that was what caused us to treat input object as 32-bit.
8427 if ((old_flags
& elfcpp::EF_MIPS_ABI
) == 0
8428 && this->mips_32bit_flags(new_flags
)
8429 && !this->mips_32bit_flags(new_flags
& ~elfcpp::EF_MIPS_ABI
))
8430 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ABI
;
8433 // The ISAs aren't compatible.
8434 gold_error(_("%s: linking %s module with previous %s modules"),
8435 name
.c_str(), this->elf_mips_mach_name(in_flags
),
8436 this->elf_mips_mach_name(merged_flags
));
8439 new_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
8440 | elfcpp::EF_MIPS_32BITMODE
));
8441 old_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
8442 | elfcpp::EF_MIPS_32BITMODE
));
8444 // Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it does set
8445 // EI_CLASS differently from any 32-bit ABI.
8446 if ((new_flags
& elfcpp::EF_MIPS_ABI
) != (old_flags
& elfcpp::EF_MIPS_ABI
)
8447 || (in_ei_class
!= this->ei_class_
))
8449 // Only error if both are set (to different values).
8450 if (((new_flags
& elfcpp::EF_MIPS_ABI
)
8451 && (old_flags
& elfcpp::EF_MIPS_ABI
))
8452 || (in_ei_class
!= this->ei_class_
))
8453 gold_error(_("%s: ABI mismatch: linking %s module with "
8454 "previous %s modules"), name
.c_str(),
8455 this->elf_mips_abi_name(in_flags
, in_ei_class
),
8456 this->elf_mips_abi_name(merged_flags
, this->ei_class_
));
8458 new_flags
&= ~elfcpp::EF_MIPS_ABI
;
8459 old_flags
&= ~elfcpp::EF_MIPS_ABI
;
8462 // Compare ASEs. Forbid linking MIPS16 and microMIPS ASE modules together
8463 // and allow arbitrary mixing of the remaining ASEs (retain the union).
8464 if ((new_flags
& elfcpp::EF_MIPS_ARCH_ASE
)
8465 != (old_flags
& elfcpp::EF_MIPS_ARCH_ASE
))
8467 int old_micro
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
8468 int new_micro
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
8469 int old_m16
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
8470 int new_m16
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
8471 int micro_mis
= old_m16
&& new_micro
;
8472 int m16_mis
= old_micro
&& new_m16
;
8474 if (m16_mis
|| micro_mis
)
8475 gold_error(_("%s: ASE mismatch: linking %s module with "
8476 "previous %s modules"), name
.c_str(),
8477 m16_mis
? "MIPS16" : "microMIPS",
8478 m16_mis
? "microMIPS" : "MIPS16");
8480 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ARCH_ASE
;
8482 new_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
8483 old_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
8486 // Warn about any other mismatches.
8487 if (new_flags
!= old_flags
)
8488 gold_error(_("%s: uses different e_flags (0x%x) fields than previous "
8489 "modules (0x%x)"), name
.c_str(), new_flags
, old_flags
);
8491 this->set_processor_specific_flags(merged_flags
);
8494 // Adjust ELF file header.
8496 template<int size
, bool big_endian
>
8498 Target_mips
<size
, big_endian
>::do_adjust_elf_header(
8499 unsigned char* view
,
8502 gold_assert(len
== elfcpp::Elf_sizes
<size
>::ehdr_size
);
8504 elfcpp::Ehdr
<size
, big_endian
> ehdr(view
);
8505 unsigned char e_ident
[elfcpp::EI_NIDENT
];
8506 memcpy(e_ident
, ehdr
.get_e_ident(), elfcpp::EI_NIDENT
);
8508 e_ident
[elfcpp::EI_CLASS
] = this->ei_class_
;
8510 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
8511 oehdr
.put_e_ident(e_ident
);
8512 if (this->entry_symbol_is_compressed_
)
8513 oehdr
.put_e_entry(ehdr
.get_e_entry() + 1);
8516 // do_make_elf_object to override the same function in the base class.
8517 // We need to use a target-specific sub-class of
8518 // Sized_relobj_file<size, big_endian> to store Mips specific information.
8519 // Hence we need to have our own ELF object creation.
8521 template<int size
, bool big_endian
>
8523 Target_mips
<size
, big_endian
>::do_make_elf_object(
8524 const std::string
& name
,
8525 Input_file
* input_file
,
8526 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
8528 int et
= ehdr
.get_e_type();
8529 // ET_EXEC files are valid input for --just-symbols/-R,
8530 // and we treat them as relocatable objects.
8531 if (et
== elfcpp::ET_REL
8532 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
8534 Mips_relobj
<size
, big_endian
>* obj
=
8535 new Mips_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
8539 else if (et
== elfcpp::ET_DYN
)
8541 // TODO(sasa): Should we create Mips_dynobj?
8542 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
8546 gold_error(_("%s: unsupported ELF file type %d"),
8552 // Finalize the sections.
8554 template <int size
, bool big_endian
>
8556 Target_mips
<size
, big_endian
>::do_finalize_sections(Layout
* layout
,
8557 const Input_objects
* input_objects
,
8558 Symbol_table
* symtab
)
8560 // Add +1 to MIPS16 and microMIPS init_ and _fini symbols so that DT_INIT and
8561 // DT_FINI have correct values.
8562 Mips_symbol
<size
>* init
= static_cast<Mips_symbol
<size
>*>(
8563 symtab
->lookup(parameters
->options().init()));
8564 if (init
!= NULL
&& (init
->is_mips16() || init
->is_micromips()))
8565 init
->set_value(init
->value() | 1);
8566 Mips_symbol
<size
>* fini
= static_cast<Mips_symbol
<size
>*>(
8567 symtab
->lookup(parameters
->options().fini()));
8568 if (fini
!= NULL
&& (fini
->is_mips16() || fini
->is_micromips()))
8569 fini
->set_value(fini
->value() | 1);
8571 // Check whether the entry symbol is mips16 or micromips. This is needed to
8572 // adjust entry address in ELF header.
8573 Mips_symbol
<size
>* entry
=
8574 static_cast<Mips_symbol
<size
>*>(symtab
->lookup(this->entry_symbol_name()));
8575 this->entry_symbol_is_compressed_
= (entry
!= NULL
&& (entry
->is_mips16()
8576 || entry
->is_micromips()));
8578 if (!parameters
->doing_static_link()
8579 && (strcmp(parameters
->options().hash_style(), "gnu") == 0
8580 || strcmp(parameters
->options().hash_style(), "both") == 0))
8582 // .gnu.hash and the MIPS ABI require .dynsym to be sorted in different
8583 // ways. .gnu.hash needs symbols to be grouped by hash code whereas the
8584 // MIPS ABI requires a mapping between the GOT and the symbol table.
8585 gold_error(".gnu.hash is incompatible with the MIPS ABI");
8588 // Check whether the final section that was scanned has HI16 or GOT16
8589 // relocations without the corresponding LO16 part.
8590 if (this->got16_addends_
.size() > 0)
8591 gold_error("Can't find matching LO16 reloc");
8594 this->set_gp(layout
, symtab
);
8596 // Check for any mips16 stub sections that we can discard.
8597 if (!parameters
->options().relocatable())
8599 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8600 p
!= input_objects
->relobj_end();
8603 Mips_relobj
<size
, big_endian
>* object
=
8604 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
8605 object
->discard_mips16_stub_sections(symtab
);
8609 // Merge processor-specific flags.
8610 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8611 p
!= input_objects
->relobj_end();
8614 Mips_relobj
<size
, big_endian
>* relobj
=
8615 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
8617 Input_file::Format format
= relobj
->input_file()->format();
8618 if (format
== Input_file::FORMAT_ELF
)
8620 // Read processor-specific flags in ELF file header.
8621 const unsigned char* pehdr
= relobj
->get_view(
8622 elfcpp::file_header_offset
,
8623 elfcpp::Elf_sizes
<size
>::ehdr_size
,
8626 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
8627 elfcpp::Elf_Word in_flags
= ehdr
.get_e_flags();
8628 unsigned char ei_class
= ehdr
.get_e_ident()[elfcpp::EI_CLASS
];
8629 // If all input sections will be discarded, don't use this object
8630 // file for merging processor specific flags.
8631 bool should_merge_processor_specific_flags
= false;
8633 for (unsigned int i
= 1; i
< relobj
->shnum(); ++i
)
8634 if (relobj
->output_section(i
) != NULL
)
8636 should_merge_processor_specific_flags
= true;
8640 if (should_merge_processor_specific_flags
)
8641 this->merge_processor_specific_flags(relobj
->name(), in_flags
,
8646 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
8647 p
!= input_objects
->dynobj_end();
8650 Sized_dynobj
<size
, big_endian
>* dynobj
=
8651 static_cast<Sized_dynobj
<size
, big_endian
>*>(*p
);
8653 // Read processor-specific flags.
8654 const unsigned char* pehdr
= dynobj
->get_view(elfcpp::file_header_offset
,
8655 elfcpp::Elf_sizes
<size
>::ehdr_size
,
8658 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
8659 elfcpp::Elf_Word in_flags
= ehdr
.get_e_flags();
8660 unsigned char ei_class
= ehdr
.get_e_ident()[elfcpp::EI_CLASS
];
8662 this->merge_processor_specific_flags(dynobj
->name(), in_flags
, ei_class
,
8666 // Merge .reginfo contents of input objects.
8667 Valtype gprmask
= 0;
8668 Valtype cprmask1
= 0;
8669 Valtype cprmask2
= 0;
8670 Valtype cprmask3
= 0;
8671 Valtype cprmask4
= 0;
8672 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8673 p
!= input_objects
->relobj_end();
8676 Mips_relobj
<size
, big_endian
>* relobj
=
8677 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
8679 gprmask
|= relobj
->gprmask();
8680 cprmask1
|= relobj
->cprmask1();
8681 cprmask2
|= relobj
->cprmask2();
8682 cprmask3
|= relobj
->cprmask3();
8683 cprmask4
|= relobj
->cprmask4();
8686 if (this->plt_
!= NULL
)
8688 // Set final PLT offsets for symbols.
8689 this->plt_section()->set_plt_offsets();
8691 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
8692 // Set STO_MICROMIPS flag if the output has microMIPS code, but only if
8693 // there are no standard PLT entries present.
8694 unsigned char nonvis
= 0;
8695 if (this->is_output_micromips()
8696 && !this->plt_section()->has_standard_entries())
8697 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
8698 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
8699 Symbol_table::PREDEFINED
,
8701 0, 0, elfcpp::STT_FUNC
,
8703 elfcpp::STV_DEFAULT
, nonvis
,
8707 if (this->mips_stubs_
!= NULL
)
8709 // Define _MIPS_STUBS_ at the start of the .MIPS.stubs section.
8710 unsigned char nonvis
= 0;
8711 if (this->is_output_micromips())
8712 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
8713 symtab
->define_in_output_data("_MIPS_STUBS_", NULL
,
8714 Symbol_table::PREDEFINED
,
8716 0, 0, elfcpp::STT_FUNC
,
8718 elfcpp::STV_DEFAULT
, nonvis
,
8722 if (!parameters
->options().relocatable() && !parameters
->doing_static_link())
8723 // In case there is no .got section, create one.
8724 this->got_section(symtab
, layout
);
8726 // Emit any relocs we saved in an attempt to avoid generating COPY
8728 if (this->copy_relocs_
.any_saved_relocs())
8729 this->copy_relocs_
.emit_mips(this->rel_dyn_section(layout
), symtab
, layout
,
8732 // Emit dynamic relocs.
8733 for (typename
std::vector
<Dyn_reloc
>::iterator p
= this->dyn_relocs_
.begin();
8734 p
!= this->dyn_relocs_
.end();
8736 p
->emit(this->rel_dyn_section(layout
), this->got_section(), symtab
);
8738 if (this->has_got_section())
8739 this->got_section()->lay_out_got(layout
, symtab
, input_objects
);
8741 if (this->mips_stubs_
!= NULL
)
8742 this->mips_stubs_
->set_needs_dynsym_value();
8744 // Check for functions that might need $25 to be valid on entry.
8745 // TODO(sasa): Can we do this without iterating over all symbols?
8746 typedef Symbol_visitor_check_symbols
<size
, big_endian
> Symbol_visitor
;
8747 symtab
->for_all_symbols
<size
, Symbol_visitor
>(Symbol_visitor(this, layout
,
8750 // Add NULL segment.
8751 if (!parameters
->options().relocatable())
8752 layout
->make_output_segment(elfcpp::PT_NULL
, 0);
8754 for (Layout::Section_list::const_iterator p
= layout
->section_list().begin();
8755 p
!= layout
->section_list().end();
8758 if ((*p
)->type() == elfcpp::SHT_MIPS_REGINFO
)
8760 Mips_output_section_reginfo
<size
, big_endian
>* reginfo
=
8761 Mips_output_section_reginfo
<size
, big_endian
>::
8762 as_mips_output_section_reginfo(*p
);
8764 reginfo
->set_masks(gprmask
, cprmask1
, cprmask2
, cprmask3
, cprmask4
);
8766 if (!parameters
->options().relocatable())
8768 Output_segment
* reginfo_segment
=
8769 layout
->make_output_segment(elfcpp::PT_MIPS_REGINFO
,
8771 reginfo_segment
->add_output_section_to_nonload(reginfo
,
8777 // Fill in some more dynamic tags.
8778 // TODO(sasa): Add more dynamic tags.
8779 const Reloc_section
* rel_plt
= (this->plt_
== NULL
8780 ? NULL
: this->plt_
->rel_plt());
8781 layout
->add_target_dynamic_tags(true, this->got_
, rel_plt
,
8782 this->rel_dyn_
, true, false);
8784 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
8786 && !parameters
->options().relocatable()
8787 && !parameters
->doing_static_link())
8790 // This element holds a 32-bit version id for the Runtime
8791 // Linker Interface. This will start at integer value 1.
8793 odyn
->add_constant(elfcpp::DT_MIPS_RLD_VERSION
, d_val
);
8796 d_val
= elfcpp::RHF_NOTPOT
;
8797 odyn
->add_constant(elfcpp::DT_MIPS_FLAGS
, d_val
);
8799 // Save layout for using when emiting custom dynamic tags.
8800 this->layout_
= layout
;
8802 // This member holds the base address of the segment.
8803 odyn
->add_custom(elfcpp::DT_MIPS_BASE_ADDRESS
);
8805 // This member holds the number of entries in the .dynsym section.
8806 odyn
->add_custom(elfcpp::DT_MIPS_SYMTABNO
);
8808 // This member holds the index of the first dynamic symbol
8809 // table entry that corresponds to an entry in the global offset table.
8810 odyn
->add_custom(elfcpp::DT_MIPS_GOTSYM
);
8812 // This member holds the number of local GOT entries.
8813 odyn
->add_constant(elfcpp::DT_MIPS_LOCAL_GOTNO
,
8814 this->got_
->get_local_gotno());
8816 if (this->plt_
!= NULL
)
8817 // DT_MIPS_PLTGOT dynamic tag
8818 odyn
->add_section_address(elfcpp::DT_MIPS_PLTGOT
, this->got_plt_
);
8822 // Get the custom dynamic tag value.
8823 template<int size
, bool big_endian
>
8825 Target_mips
<size
, big_endian
>::do_dynamic_tag_custom_value(elfcpp::DT tag
) const
8829 case elfcpp::DT_MIPS_BASE_ADDRESS
:
8831 // The base address of the segment.
8832 // At this point, the segment list has been sorted into final order,
8833 // so just return vaddr of the first readable PT_LOAD segment.
8834 Output_segment
* seg
=
8835 this->layout_
->find_output_segment(elfcpp::PT_LOAD
, elfcpp::PF_R
, 0);
8836 gold_assert(seg
!= NULL
);
8837 return seg
->vaddr();
8840 case elfcpp::DT_MIPS_SYMTABNO
:
8841 // The number of entries in the .dynsym section.
8842 return this->get_dt_mips_symtabno();
8844 case elfcpp::DT_MIPS_GOTSYM
:
8846 // The index of the first dynamic symbol table entry that corresponds
8847 // to an entry in the GOT.
8848 if (this->got_
->first_global_got_dynsym_index() != -1U)
8849 return this->got_
->first_global_got_dynsym_index();
8851 // In case if we don't have global GOT symbols we default to setting
8852 // DT_MIPS_GOTSYM to the same value as DT_MIPS_SYMTABNO.
8853 return this->get_dt_mips_symtabno();
8857 gold_error(_("Unknown dynamic tag 0x%x"), (unsigned int)tag
);
8860 return (unsigned int)-1;
8863 // Relocate section data.
8865 template<int size
, bool big_endian
>
8867 Target_mips
<size
, big_endian
>::relocate_section(
8868 const Relocate_info
<size
, big_endian
>* relinfo
,
8869 unsigned int sh_type
,
8870 const unsigned char* prelocs
,
8872 Output_section
* output_section
,
8873 bool needs_special_offset_handling
,
8874 unsigned char* view
,
8875 Mips_address address
,
8876 section_size_type view_size
,
8877 const Reloc_symbol_changes
* reloc_symbol_changes
)
8879 typedef Target_mips
<size
, big_endian
> Mips
;
8880 typedef typename Target_mips
<size
, big_endian
>::Relocate Mips_relocate
;
8882 if (sh_type
== elfcpp::SHT_REL
)
8884 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8887 gold::relocate_section
<size
, big_endian
, Mips
, Mips_relocate
,
8888 gold::Default_comdat_behavior
, Classify_reloc
>(
8894 needs_special_offset_handling
,
8898 reloc_symbol_changes
);
8900 else if (sh_type
== elfcpp::SHT_RELA
)
8902 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8905 gold::relocate_section
<size
, big_endian
, Mips
, Mips_relocate
,
8906 gold::Default_comdat_behavior
, Classify_reloc
>(
8912 needs_special_offset_handling
,
8916 reloc_symbol_changes
);
8920 // Return the size of a relocation while scanning during a relocatable
8924 mips_get_size_for_reloc(unsigned int r_type
, Relobj
* object
)
8928 case elfcpp::R_MIPS_NONE
:
8929 case elfcpp::R_MIPS_TLS_DTPMOD64
:
8930 case elfcpp::R_MIPS_TLS_DTPREL64
:
8931 case elfcpp::R_MIPS_TLS_TPREL64
:
8934 case elfcpp::R_MIPS_32
:
8935 case elfcpp::R_MIPS_TLS_DTPMOD32
:
8936 case elfcpp::R_MIPS_TLS_DTPREL32
:
8937 case elfcpp::R_MIPS_TLS_TPREL32
:
8938 case elfcpp::R_MIPS_REL32
:
8939 case elfcpp::R_MIPS_PC32
:
8940 case elfcpp::R_MIPS_GPREL32
:
8941 case elfcpp::R_MIPS_JALR
:
8942 case elfcpp::R_MIPS_EH
:
8945 case elfcpp::R_MIPS_16
:
8946 case elfcpp::R_MIPS_HI16
:
8947 case elfcpp::R_MIPS_LO16
:
8948 case elfcpp::R_MIPS_GPREL16
:
8949 case elfcpp::R_MIPS16_HI16
:
8950 case elfcpp::R_MIPS16_LO16
:
8951 case elfcpp::R_MIPS_PC16
:
8952 case elfcpp::R_MIPS_GOT16
:
8953 case elfcpp::R_MIPS16_GOT16
:
8954 case elfcpp::R_MIPS_CALL16
:
8955 case elfcpp::R_MIPS16_CALL16
:
8956 case elfcpp::R_MIPS_GOT_HI16
:
8957 case elfcpp::R_MIPS_CALL_HI16
:
8958 case elfcpp::R_MIPS_GOT_LO16
:
8959 case elfcpp::R_MIPS_CALL_LO16
:
8960 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
8961 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
8962 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
8963 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
8964 case elfcpp::R_MIPS16_GPREL
:
8965 case elfcpp::R_MIPS_GOT_DISP
:
8966 case elfcpp::R_MIPS_LITERAL
:
8967 case elfcpp::R_MIPS_GOT_PAGE
:
8968 case elfcpp::R_MIPS_GOT_OFST
:
8969 case elfcpp::R_MIPS_TLS_GD
:
8970 case elfcpp::R_MIPS_TLS_LDM
:
8971 case elfcpp::R_MIPS_TLS_GOTTPREL
:
8974 // These relocations are not byte sized
8975 case elfcpp::R_MIPS_26
:
8976 case elfcpp::R_MIPS16_26
:
8979 case elfcpp::R_MIPS_COPY
:
8980 case elfcpp::R_MIPS_JUMP_SLOT
:
8981 object
->error(_("unexpected reloc %u in object file"), r_type
);
8985 object
->error(_("unsupported reloc %u in object file"), r_type
);
8990 // Scan the relocs during a relocatable link.
8992 template<int size
, bool big_endian
>
8994 Target_mips
<size
, big_endian
>::scan_relocatable_relocs(
8995 Symbol_table
* symtab
,
8997 Sized_relobj_file
<size
, big_endian
>* object
,
8998 unsigned int data_shndx
,
8999 unsigned int sh_type
,
9000 const unsigned char* prelocs
,
9002 Output_section
* output_section
,
9003 bool needs_special_offset_handling
,
9004 size_t local_symbol_count
,
9005 const unsigned char* plocal_symbols
,
9006 Relocatable_relocs
* rr
)
9008 if (sh_type
== elfcpp::SHT_REL
)
9010 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
9012 typedef Mips_scan_relocatable_relocs
<big_endian
, Classify_reloc
>
9013 Scan_relocatable_relocs
;
9015 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_relocatable_relocs
>(
9023 needs_special_offset_handling
,
9028 else if (sh_type
== elfcpp::SHT_RELA
)
9030 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9032 typedef Mips_scan_relocatable_relocs
<big_endian
, Classify_reloc
>
9033 Scan_relocatable_relocs
;
9035 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_relocatable_relocs
>(
9043 needs_special_offset_handling
,
9052 // Scan the relocs for --emit-relocs.
9054 template<int size
, bool big_endian
>
9056 Target_mips
<size
, big_endian
>::emit_relocs_scan(
9057 Symbol_table
* symtab
,
9059 Sized_relobj_file
<size
, big_endian
>* object
,
9060 unsigned int data_shndx
,
9061 unsigned int sh_type
,
9062 const unsigned char* prelocs
,
9064 Output_section
* output_section
,
9065 bool needs_special_offset_handling
,
9066 size_t local_symbol_count
,
9067 const unsigned char* plocal_syms
,
9068 Relocatable_relocs
* rr
)
9070 if (sh_type
== elfcpp::SHT_REL
)
9072 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
9074 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
9075 Emit_relocs_strategy
;
9077 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
9085 needs_special_offset_handling
,
9090 else if (sh_type
== elfcpp::SHT_RELA
)
9092 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9094 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
9095 Emit_relocs_strategy
;
9097 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
9105 needs_special_offset_handling
,
9114 // Emit relocations for a section.
9116 template<int size
, bool big_endian
>
9118 Target_mips
<size
, big_endian
>::relocate_relocs(
9119 const Relocate_info
<size
, big_endian
>* relinfo
,
9120 unsigned int sh_type
,
9121 const unsigned char* prelocs
,
9123 Output_section
* output_section
,
9124 typename
elfcpp::Elf_types
<size
>::Elf_Off
9125 offset_in_output_section
,
9126 unsigned char* view
,
9127 Mips_address view_address
,
9128 section_size_type view_size
,
9129 unsigned char* reloc_view
,
9130 section_size_type reloc_view_size
)
9132 if (sh_type
== elfcpp::SHT_REL
)
9134 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
9137 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
9142 offset_in_output_section
,
9149 else if (sh_type
== elfcpp::SHT_RELA
)
9151 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9154 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
9159 offset_in_output_section
,
9170 // Perform target-specific processing in a relocatable link. This is
9171 // only used if we use the relocation strategy RELOC_SPECIAL.
9173 template<int size
, bool big_endian
>
9175 Target_mips
<size
, big_endian
>::relocate_special_relocatable(
9176 const Relocate_info
<size
, big_endian
>* relinfo
,
9177 unsigned int sh_type
,
9178 const unsigned char* preloc_in
,
9180 Output_section
* output_section
,
9181 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
9182 unsigned char* view
,
9183 Mips_address view_address
,
9185 unsigned char* preloc_out
)
9187 // We can only handle REL type relocation sections.
9188 gold_assert(sh_type
== elfcpp::SHT_REL
);
9190 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
9192 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc_write
9195 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
9197 const Mips_address invalid_address
= static_cast<Mips_address
>(0) - 1;
9199 Mips_relobj
<size
, big_endian
>* object
=
9200 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
9201 const unsigned int local_count
= object
->local_symbol_count();
9203 Reltype
reloc(preloc_in
);
9204 Reltype_write
reloc_write(preloc_out
);
9206 elfcpp::Elf_types
<32>::Elf_WXword r_info
= reloc
.get_r_info();
9207 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
9208 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
9210 // Get the new symbol index.
9211 // We only use RELOC_SPECIAL strategy in local relocations.
9212 gold_assert(r_sym
< local_count
);
9214 // We are adjusting a section symbol. We need to find
9215 // the symbol table index of the section symbol for
9216 // the output section corresponding to input section
9217 // in which this symbol is defined.
9219 unsigned int shndx
= object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
9220 gold_assert(is_ordinary
);
9221 Output_section
* os
= object
->output_section(shndx
);
9222 gold_assert(os
!= NULL
);
9223 gold_assert(os
->needs_symtab_index());
9224 unsigned int new_symndx
= os
->symtab_index();
9226 // Get the new offset--the location in the output section where
9227 // this relocation should be applied.
9229 Mips_address offset
= reloc
.get_r_offset();
9230 Mips_address new_offset
;
9231 if (offset_in_output_section
!= invalid_address
)
9232 new_offset
= offset
+ offset_in_output_section
;
9235 section_offset_type sot_offset
=
9236 convert_types
<section_offset_type
, Mips_address
>(offset
);
9237 section_offset_type new_sot_offset
=
9238 output_section
->output_offset(object
, relinfo
->data_shndx
,
9240 gold_assert(new_sot_offset
!= -1);
9241 new_offset
= new_sot_offset
;
9244 // In an object file, r_offset is an offset within the section.
9245 // In an executable or dynamic object, generated by
9246 // --emit-relocs, r_offset is an absolute address.
9247 if (!parameters
->options().relocatable())
9249 new_offset
+= view_address
;
9250 if (offset_in_output_section
!= invalid_address
)
9251 new_offset
-= offset_in_output_section
;
9254 reloc_write
.put_r_offset(new_offset
);
9255 reloc_write
.put_r_info(elfcpp::elf_r_info
<32>(new_symndx
, r_type
));
9257 // Handle the reloc addend.
9258 // The relocation uses a section symbol in the input file.
9259 // We are adjusting it to use a section symbol in the output
9260 // file. The input section symbol refers to some address in
9261 // the input section. We need the relocation in the output
9262 // file to refer to that same address. This adjustment to
9263 // the addend is the same calculation we use for a simple
9264 // absolute relocation for the input section symbol.
9265 Valtype calculated_value
= 0;
9266 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
9268 unsigned char* paddend
= view
+ offset
;
9269 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
9272 case elfcpp::R_MIPS_26
:
9273 reloc_status
= Reloc_funcs::rel26(paddend
, object
, psymval
,
9274 offset_in_output_section
, true, 0, sh_type
== elfcpp::SHT_REL
, NULL
,
9275 false /*TODO(sasa): cross mode jump*/, r_type
, this->jal_to_bal(),
9276 false, &calculated_value
);
9283 // Report any errors.
9284 switch (reloc_status
)
9286 case Reloc_funcs::STATUS_OKAY
:
9288 case Reloc_funcs::STATUS_OVERFLOW
:
9289 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
9290 _("relocation overflow"));
9292 case Reloc_funcs::STATUS_BAD_RELOC
:
9293 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
9294 _("unexpected opcode while processing relocation"));
9301 // Optimize the TLS relocation type based on what we know about the
9302 // symbol. IS_FINAL is true if the final address of this symbol is
9303 // known at link time.
9305 template<int size
, bool big_endian
>
9306 tls::Tls_optimization
9307 Target_mips
<size
, big_endian
>::optimize_tls_reloc(bool, int)
9309 // FIXME: Currently we do not do any TLS optimization.
9310 return tls::TLSOPT_NONE
;
9313 // Scan a relocation for a local symbol.
9315 template<int size
, bool big_endian
>
9317 Target_mips
<size
, big_endian
>::Scan::local(
9318 Symbol_table
* symtab
,
9320 Target_mips
<size
, big_endian
>* target
,
9321 Sized_relobj_file
<size
, big_endian
>* object
,
9322 unsigned int data_shndx
,
9323 Output_section
* output_section
,
9324 const Relatype
* rela
,
9326 unsigned int rel_type
,
9327 unsigned int r_type
,
9328 const elfcpp::Sym
<size
, big_endian
>& lsym
,
9334 Mips_address r_offset
;
9336 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
9338 if (rel_type
== elfcpp::SHT_RELA
)
9340 r_offset
= rela
->get_r_offset();
9341 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
9343 r_addend
= rela
->get_r_addend();
9347 r_offset
= rel
->get_r_offset();
9348 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
9353 Mips_relobj
<size
, big_endian
>* mips_obj
=
9354 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
9356 if (mips_obj
->is_mips16_stub_section(data_shndx
))
9358 mips_obj
->get_mips16_stub_section(data_shndx
)
9359 ->new_local_reloc_found(r_type
, r_sym
);
9362 if (r_type
== elfcpp::R_MIPS_NONE
)
9363 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
9367 if (!mips16_call_reloc(r_type
)
9368 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
9369 // This reloc would need to refer to a MIPS16 hard-float stub, if
9370 // there is one. We ignore MIPS16 stub sections and .pdr section when
9371 // looking for relocs that would need to refer to MIPS16 stubs.
9372 mips_obj
->add_local_non_16bit_call(r_sym
);
9374 if (r_type
== elfcpp::R_MIPS16_26
9375 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
9376 mips_obj
->add_local_16bit_call(r_sym
);
9380 case elfcpp::R_MIPS_GOT16
:
9381 case elfcpp::R_MIPS_CALL16
:
9382 case elfcpp::R_MIPS_CALL_HI16
:
9383 case elfcpp::R_MIPS_CALL_LO16
:
9384 case elfcpp::R_MIPS_GOT_HI16
:
9385 case elfcpp::R_MIPS_GOT_LO16
:
9386 case elfcpp::R_MIPS_GOT_PAGE
:
9387 case elfcpp::R_MIPS_GOT_OFST
:
9388 case elfcpp::R_MIPS_GOT_DISP
:
9389 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9390 case elfcpp::R_MIPS_TLS_GD
:
9391 case elfcpp::R_MIPS_TLS_LDM
:
9392 case elfcpp::R_MIPS16_GOT16
:
9393 case elfcpp::R_MIPS16_CALL16
:
9394 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9395 case elfcpp::R_MIPS16_TLS_GD
:
9396 case elfcpp::R_MIPS16_TLS_LDM
:
9397 case elfcpp::R_MICROMIPS_GOT16
:
9398 case elfcpp::R_MICROMIPS_CALL16
:
9399 case elfcpp::R_MICROMIPS_CALL_HI16
:
9400 case elfcpp::R_MICROMIPS_CALL_LO16
:
9401 case elfcpp::R_MICROMIPS_GOT_HI16
:
9402 case elfcpp::R_MICROMIPS_GOT_LO16
:
9403 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9404 case elfcpp::R_MICROMIPS_GOT_OFST
:
9405 case elfcpp::R_MICROMIPS_GOT_DISP
:
9406 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9407 case elfcpp::R_MICROMIPS_TLS_GD
:
9408 case elfcpp::R_MICROMIPS_TLS_LDM
:
9409 case elfcpp::R_MIPS_EH
:
9410 // We need a GOT section.
9411 target
->got_section(symtab
, layout
);
9418 if (call_lo16_reloc(r_type
)
9419 || got_lo16_reloc(r_type
)
9420 || got_disp_reloc(r_type
)
9421 || eh_reloc(r_type
))
9423 // We may need a local GOT entry for this relocation. We
9424 // don't count R_MIPS_GOT_PAGE because we can estimate the
9425 // maximum number of pages needed by looking at the size of
9426 // the segment. Similar comments apply to R_MIPS*_GOT16 and
9427 // R_MIPS*_CALL16. We don't count R_MIPS_GOT_HI16, or
9428 // R_MIPS_CALL_HI16 because these are always followed by an
9429 // R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
9430 Mips_output_data_got
<size
, big_endian
>* got
=
9431 target
->got_section(symtab
, layout
);
9432 bool is_section_symbol
= lsym
.get_st_type() == elfcpp::STT_SECTION
;
9433 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
, -1U,
9439 case elfcpp::R_MIPS_CALL16
:
9440 case elfcpp::R_MIPS16_CALL16
:
9441 case elfcpp::R_MICROMIPS_CALL16
:
9442 gold_error(_("CALL16 reloc at 0x%lx not against global symbol "),
9443 (unsigned long)r_offset
);
9446 case elfcpp::R_MIPS_GOT_PAGE
:
9447 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9448 case elfcpp::R_MIPS16_GOT16
:
9449 case elfcpp::R_MIPS_GOT16
:
9450 case elfcpp::R_MIPS_GOT_HI16
:
9451 case elfcpp::R_MIPS_GOT_LO16
:
9452 case elfcpp::R_MICROMIPS_GOT16
:
9453 case elfcpp::R_MICROMIPS_GOT_HI16
:
9454 case elfcpp::R_MICROMIPS_GOT_LO16
:
9456 // This relocation needs a page entry in the GOT.
9457 // Get the section contents.
9458 section_size_type view_size
= 0;
9459 const unsigned char* view
= object
->section_contents(data_shndx
,
9463 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
9464 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
9467 if (rel_type
== elfcpp::SHT_REL
&& got16_reloc(r_type
))
9468 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
9469 object
, data_shndx
, r_type
, r_sym
, addend
));
9471 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
, addend
);
9475 case elfcpp::R_MIPS_HI16
:
9476 case elfcpp::R_MIPS16_HI16
:
9477 case elfcpp::R_MICROMIPS_HI16
:
9478 // Record the reloc so that we can check whether the corresponding LO16
9480 if (rel_type
== elfcpp::SHT_REL
)
9481 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
9482 object
, data_shndx
, r_type
, r_sym
, 0));
9485 case elfcpp::R_MIPS_LO16
:
9486 case elfcpp::R_MIPS16_LO16
:
9487 case elfcpp::R_MICROMIPS_LO16
:
9489 if (rel_type
!= elfcpp::SHT_REL
)
9492 // Find corresponding GOT16/HI16 relocation.
9494 // According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
9495 // be immediately following. However, for the IRIX6 ABI, the next
9496 // relocation may be a composed relocation consisting of several
9497 // relocations for the same address. In that case, the R_MIPS_LO16
9498 // relocation may occur as one of these. We permit a similar
9499 // extension in general, as that is useful for GCC.
9501 // In some cases GCC dead code elimination removes the LO16 but
9502 // keeps the corresponding HI16. This is strictly speaking a
9503 // violation of the ABI but not immediately harmful.
9505 typename
std::list
<got16_addend
<size
, big_endian
> >::iterator it
=
9506 target
->got16_addends_
.begin();
9507 while (it
!= target
->got16_addends_
.end())
9509 got16_addend
<size
, big_endian
> _got16_addend
= *it
;
9511 // TODO(sasa): Split got16_addends_ list into two lists - one for
9512 // GOT16 relocs and the other for HI16 relocs.
9514 // Report an error if we find HI16 or GOT16 reloc from the
9515 // previous section without the matching LO16 part.
9516 if (_got16_addend
.object
!= object
9517 || _got16_addend
.shndx
!= data_shndx
)
9519 gold_error("Can't find matching LO16 reloc");
9523 if (_got16_addend
.r_sym
!= r_sym
9524 || !is_matching_lo16_reloc(_got16_addend
.r_type
, r_type
))
9530 // We found a matching HI16 or GOT16 reloc for this LO16 reloc.
9531 // For GOT16, we need to calculate combined addend and record GOT page
9533 if (got16_reloc(_got16_addend
.r_type
))
9536 section_size_type view_size
= 0;
9537 const unsigned char* view
= object
->section_contents(data_shndx
,
9542 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
9543 int32_t addend
= Bits
<16>::sign_extend32(val
& 0xffff);
9545 addend
= (_got16_addend
.addend
<< 16) + addend
;
9546 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
,
9550 it
= target
->got16_addends_
.erase(it
);
9558 case elfcpp::R_MIPS_32
:
9559 case elfcpp::R_MIPS_REL32
:
9560 case elfcpp::R_MIPS_64
:
9562 if (parameters
->options().output_is_position_independent())
9564 // If building a shared library (or a position-independent
9565 // executable), we need to create a dynamic relocation for
9567 if (is_readonly_section(output_section
))
9569 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
9570 rel_dyn
->add_symbolless_local_addend(object
, r_sym
,
9571 elfcpp::R_MIPS_REL32
,
9572 output_section
, data_shndx
,
9578 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9579 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9580 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9581 case elfcpp::R_MIPS_TLS_LDM
:
9582 case elfcpp::R_MIPS16_TLS_LDM
:
9583 case elfcpp::R_MICROMIPS_TLS_LDM
:
9584 case elfcpp::R_MIPS_TLS_GD
:
9585 case elfcpp::R_MIPS16_TLS_GD
:
9586 case elfcpp::R_MICROMIPS_TLS_GD
:
9588 bool output_is_shared
= parameters
->options().shared();
9589 const tls::Tls_optimization optimized_type
9590 = Target_mips
<size
, big_endian
>::optimize_tls_reloc(
9591 !output_is_shared
, r_type
);
9594 case elfcpp::R_MIPS_TLS_GD
:
9595 case elfcpp::R_MIPS16_TLS_GD
:
9596 case elfcpp::R_MICROMIPS_TLS_GD
:
9597 if (optimized_type
== tls::TLSOPT_NONE
)
9599 // Create a pair of GOT entries for the module index and
9600 // dtv-relative offset.
9601 Mips_output_data_got
<size
, big_endian
>* got
=
9602 target
->got_section(symtab
, layout
);
9603 unsigned int shndx
= lsym
.get_st_shndx();
9605 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
9608 object
->error(_("local symbol %u has bad shndx %u"),
9612 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
9617 // FIXME: TLS optimization not supported yet.
9622 case elfcpp::R_MIPS_TLS_LDM
:
9623 case elfcpp::R_MIPS16_TLS_LDM
:
9624 case elfcpp::R_MICROMIPS_TLS_LDM
:
9625 if (optimized_type
== tls::TLSOPT_NONE
)
9627 // We always record LDM symbols as local with index 0.
9628 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
9634 // FIXME: TLS optimization not supported yet.
9638 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9639 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9640 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9641 layout
->set_has_static_tls();
9642 if (optimized_type
== tls::TLSOPT_NONE
)
9644 // Create a GOT entry for the tp-relative offset.
9645 Mips_output_data_got
<size
, big_endian
>* got
=
9646 target
->got_section(symtab
, layout
);
9647 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
9652 // FIXME: TLS optimization not supported yet.
9667 // Refuse some position-dependent relocations when creating a
9668 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
9669 // not PIC, but we can create dynamic relocations and the result
9670 // will be fine. Also do not refuse R_MIPS_LO16, which can be
9671 // combined with R_MIPS_GOT16.
9672 if (parameters
->options().shared())
9676 case elfcpp::R_MIPS16_HI16
:
9677 case elfcpp::R_MIPS_HI16
:
9678 case elfcpp::R_MICROMIPS_HI16
:
9679 // Don't refuse a high part relocation if it's against
9680 // no symbol (e.g. part of a compound relocation).
9686 case elfcpp::R_MIPS16_26
:
9687 case elfcpp::R_MIPS_26
:
9688 case elfcpp::R_MICROMIPS_26_S1
:
9689 gold_error(_("%s: relocation %u against `%s' can not be used when "
9690 "making a shared object; recompile with -fPIC"),
9691 object
->name().c_str(), r_type
, "a local symbol");
9698 template<int size
, bool big_endian
>
9700 Target_mips
<size
, big_endian
>::Scan::local(
9701 Symbol_table
* symtab
,
9703 Target_mips
<size
, big_endian
>* target
,
9704 Sized_relobj_file
<size
, big_endian
>* object
,
9705 unsigned int data_shndx
,
9706 Output_section
* output_section
,
9707 const Reltype
& reloc
,
9708 unsigned int r_type
,
9709 const elfcpp::Sym
<size
, big_endian
>& lsym
,
9722 (const Relatype
*) NULL
,
9726 lsym
, is_discarded
);
9730 template<int size
, bool big_endian
>
9732 Target_mips
<size
, big_endian
>::Scan::local(
9733 Symbol_table
* symtab
,
9735 Target_mips
<size
, big_endian
>* target
,
9736 Sized_relobj_file
<size
, big_endian
>* object
,
9737 unsigned int data_shndx
,
9738 Output_section
* output_section
,
9739 const Relatype
& reloc
,
9740 unsigned int r_type
,
9741 const elfcpp::Sym
<size
, big_endian
>& lsym
,
9755 (const Reltype
*) NULL
,
9758 lsym
, is_discarded
);
9761 // Scan a relocation for a global symbol.
9763 template<int size
, bool big_endian
>
9765 Target_mips
<size
, big_endian
>::Scan::global(
9766 Symbol_table
* symtab
,
9768 Target_mips
<size
, big_endian
>* target
,
9769 Sized_relobj_file
<size
, big_endian
>* object
,
9770 unsigned int data_shndx
,
9771 Output_section
* output_section
,
9772 const Relatype
* rela
,
9774 unsigned int rel_type
,
9775 unsigned int r_type
,
9778 Mips_address r_offset
;
9780 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
9782 if (rel_type
== elfcpp::SHT_RELA
)
9784 r_offset
= rela
->get_r_offset();
9785 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
9787 r_addend
= rela
->get_r_addend();
9791 r_offset
= rel
->get_r_offset();
9792 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
9797 Mips_relobj
<size
, big_endian
>* mips_obj
=
9798 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
9799 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
9801 if (mips_obj
->is_mips16_stub_section(data_shndx
))
9803 mips_obj
->get_mips16_stub_section(data_shndx
)
9804 ->new_global_reloc_found(r_type
, mips_sym
);
9807 if (r_type
== elfcpp::R_MIPS_NONE
)
9808 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
9812 if (!mips16_call_reloc(r_type
)
9813 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
9814 // This reloc would need to refer to a MIPS16 hard-float stub, if
9815 // there is one. We ignore MIPS16 stub sections and .pdr section when
9816 // looking for relocs that would need to refer to MIPS16 stubs.
9817 mips_sym
->set_need_fn_stub();
9819 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
9820 // section. We check here to avoid creating a dynamic reloc against
9821 // _GLOBAL_OFFSET_TABLE_.
9822 if (!target
->has_got_section()
9823 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9824 target
->got_section(symtab
, layout
);
9826 // We need PLT entries if there are static-only relocations against
9827 // an externally-defined function. This can technically occur for
9828 // shared libraries if there are branches to the symbol, although it
9829 // is unlikely that this will be used in practice due to the short
9830 // ranges involved. It can occur for any relative or absolute relocation
9831 // in executables; in that case, the PLT entry becomes the function's
9832 // canonical address.
9833 bool static_reloc
= false;
9835 // Set CAN_MAKE_DYNAMIC to true if we can convert this
9836 // relocation into a dynamic one.
9837 bool can_make_dynamic
= false;
9840 case elfcpp::R_MIPS_GOT16
:
9841 case elfcpp::R_MIPS_CALL16
:
9842 case elfcpp::R_MIPS_CALL_HI16
:
9843 case elfcpp::R_MIPS_CALL_LO16
:
9844 case elfcpp::R_MIPS_GOT_HI16
:
9845 case elfcpp::R_MIPS_GOT_LO16
:
9846 case elfcpp::R_MIPS_GOT_PAGE
:
9847 case elfcpp::R_MIPS_GOT_OFST
:
9848 case elfcpp::R_MIPS_GOT_DISP
:
9849 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9850 case elfcpp::R_MIPS_TLS_GD
:
9851 case elfcpp::R_MIPS_TLS_LDM
:
9852 case elfcpp::R_MIPS16_GOT16
:
9853 case elfcpp::R_MIPS16_CALL16
:
9854 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9855 case elfcpp::R_MIPS16_TLS_GD
:
9856 case elfcpp::R_MIPS16_TLS_LDM
:
9857 case elfcpp::R_MICROMIPS_GOT16
:
9858 case elfcpp::R_MICROMIPS_CALL16
:
9859 case elfcpp::R_MICROMIPS_CALL_HI16
:
9860 case elfcpp::R_MICROMIPS_CALL_LO16
:
9861 case elfcpp::R_MICROMIPS_GOT_HI16
:
9862 case elfcpp::R_MICROMIPS_GOT_LO16
:
9863 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9864 case elfcpp::R_MICROMIPS_GOT_OFST
:
9865 case elfcpp::R_MICROMIPS_GOT_DISP
:
9866 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9867 case elfcpp::R_MICROMIPS_TLS_GD
:
9868 case elfcpp::R_MICROMIPS_TLS_LDM
:
9869 case elfcpp::R_MIPS_EH
:
9870 // We need a GOT section.
9871 target
->got_section(symtab
, layout
);
9874 // This is just a hint; it can safely be ignored. Don't set
9875 // has_static_relocs for the corresponding symbol.
9876 case elfcpp::R_MIPS_JALR
:
9877 case elfcpp::R_MICROMIPS_JALR
:
9880 case elfcpp::R_MIPS_GPREL16
:
9881 case elfcpp::R_MIPS_GPREL32
:
9882 case elfcpp::R_MIPS16_GPREL
:
9883 case elfcpp::R_MICROMIPS_GPREL16
:
9885 // GP-relative relocations always resolve to a definition in a
9886 // regular input file, ignoring the one-definition rule. This is
9887 // important for the GP setup sequence in NewABI code, which
9888 // always resolves to a local function even if other relocations
9889 // against the symbol wouldn't.
9890 //constrain_symbol_p = FALSE;
9893 case elfcpp::R_MIPS_32
:
9894 case elfcpp::R_MIPS_REL32
:
9895 case elfcpp::R_MIPS_64
:
9896 if ((parameters
->options().shared()
9897 || (strcmp(gsym
->name(), "__gnu_local_gp") != 0
9898 && (!is_readonly_section(output_section
)
9899 || mips_obj
->is_pic())))
9900 && (output_section
->flags() & elfcpp::SHF_ALLOC
) != 0)
9902 if (r_type
!= elfcpp::R_MIPS_REL32
)
9903 mips_sym
->set_pointer_equality_needed();
9904 can_make_dynamic
= true;
9910 // Most static relocations require pointer equality, except
9912 mips_sym
->set_pointer_equality_needed();
9916 case elfcpp::R_MIPS_26
:
9917 case elfcpp::R_MIPS_PC16
:
9918 case elfcpp::R_MIPS16_26
:
9919 case elfcpp::R_MICROMIPS_26_S1
:
9920 case elfcpp::R_MICROMIPS_PC7_S1
:
9921 case elfcpp::R_MICROMIPS_PC10_S1
:
9922 case elfcpp::R_MICROMIPS_PC16_S1
:
9923 case elfcpp::R_MICROMIPS_PC23_S2
:
9924 static_reloc
= true;
9925 mips_sym
->set_has_static_relocs();
9929 // If there are call relocations against an externally-defined symbol,
9930 // see whether we can create a MIPS lazy-binding stub for it. We can
9931 // only do this if all references to the function are through call
9932 // relocations, and in that case, the traditional lazy-binding stubs
9933 // are much more efficient than PLT entries.
9936 case elfcpp::R_MIPS16_CALL16
:
9937 case elfcpp::R_MIPS_CALL16
:
9938 case elfcpp::R_MIPS_CALL_HI16
:
9939 case elfcpp::R_MIPS_CALL_LO16
:
9940 case elfcpp::R_MIPS_JALR
:
9941 case elfcpp::R_MICROMIPS_CALL16
:
9942 case elfcpp::R_MICROMIPS_CALL_HI16
:
9943 case elfcpp::R_MICROMIPS_CALL_LO16
:
9944 case elfcpp::R_MICROMIPS_JALR
:
9945 if (!mips_sym
->no_lazy_stub())
9947 if ((mips_sym
->needs_plt_entry() && mips_sym
->is_from_dynobj())
9948 // Calls from shared objects to undefined symbols of type
9949 // STT_NOTYPE need lazy-binding stub.
9950 || (mips_sym
->is_undefined() && parameters
->options().shared()))
9951 target
->mips_stubs_section(layout
)->make_entry(mips_sym
);
9956 // We must not create a stub for a symbol that has relocations
9957 // related to taking the function's address.
9958 mips_sym
->set_no_lazy_stub();
9959 target
->remove_lazy_stub_entry(mips_sym
);
9964 if (relocation_needs_la25_stub
<size
, big_endian
>(mips_obj
, r_type
,
9965 mips_sym
->is_mips16()))
9966 mips_sym
->set_has_nonpic_branches();
9968 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
9969 // and has a special meaning.
9970 bool gp_disp_against_hi16
= (!mips_obj
->is_newabi()
9971 && strcmp(gsym
->name(), "_gp_disp") == 0
9972 && (hi16_reloc(r_type
) || lo16_reloc(r_type
)));
9973 if (static_reloc
&& gsym
->needs_plt_entry())
9975 target
->make_plt_entry(symtab
, layout
, mips_sym
, r_type
);
9977 // Since this is not a PC-relative relocation, we may be
9978 // taking the address of a function. In that case we need to
9979 // set the entry in the dynamic symbol table to the address of
9981 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
9983 gsym
->set_needs_dynsym_value();
9984 // We distinguish between PLT entries and lazy-binding stubs by
9985 // giving the former an st_other value of STO_MIPS_PLT. Set the
9986 // flag if there are any relocations in the binary where pointer
9987 // equality matters.
9988 if (mips_sym
->pointer_equality_needed())
9989 mips_sym
->set_mips_plt();
9992 if ((static_reloc
|| can_make_dynamic
) && !gp_disp_against_hi16
)
9994 // Absolute addressing relocations.
9995 // Make a dynamic relocation if necessary.
9996 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
9998 if (gsym
->may_need_copy_reloc())
10000 target
->copy_reloc(symtab
, layout
, object
, data_shndx
,
10001 output_section
, gsym
, r_type
, r_offset
);
10003 else if (can_make_dynamic
)
10005 // Create .rel.dyn section.
10006 target
->rel_dyn_section(layout
);
10007 target
->dynamic_reloc(mips_sym
, elfcpp::R_MIPS_REL32
, mips_obj
,
10008 data_shndx
, output_section
, r_offset
);
10011 gold_error(_("non-dynamic relocations refer to dynamic symbol %s"),
10016 bool for_call
= false;
10019 case elfcpp::R_MIPS_CALL16
:
10020 case elfcpp::R_MIPS16_CALL16
:
10021 case elfcpp::R_MICROMIPS_CALL16
:
10022 case elfcpp::R_MIPS_CALL_HI16
:
10023 case elfcpp::R_MIPS_CALL_LO16
:
10024 case elfcpp::R_MICROMIPS_CALL_HI16
:
10025 case elfcpp::R_MICROMIPS_CALL_LO16
:
10029 case elfcpp::R_MIPS16_GOT16
:
10030 case elfcpp::R_MIPS_GOT16
:
10031 case elfcpp::R_MIPS_GOT_HI16
:
10032 case elfcpp::R_MIPS_GOT_LO16
:
10033 case elfcpp::R_MICROMIPS_GOT16
:
10034 case elfcpp::R_MICROMIPS_GOT_HI16
:
10035 case elfcpp::R_MICROMIPS_GOT_LO16
:
10036 case elfcpp::R_MIPS_GOT_DISP
:
10037 case elfcpp::R_MICROMIPS_GOT_DISP
:
10038 case elfcpp::R_MIPS_EH
:
10040 // The symbol requires a GOT entry.
10041 Mips_output_data_got
<size
, big_endian
>* got
=
10042 target
->got_section(symtab
, layout
);
10043 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10045 mips_sym
->set_global_got_area(GGA_NORMAL
);
10049 case elfcpp::R_MIPS_GOT_PAGE
:
10050 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10052 // This relocation needs a page entry in the GOT.
10053 // Get the section contents.
10054 section_size_type view_size
= 0;
10055 const unsigned char* view
=
10056 object
->section_contents(data_shndx
, &view_size
, false);
10059 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
10060 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
10062 Mips_output_data_got
<size
, big_endian
>* got
=
10063 target
->got_section(symtab
, layout
);
10064 got
->record_got_page_entry(mips_obj
, r_sym
, addend
);
10066 // If this is a global, overridable symbol, GOT_PAGE will
10067 // decay to GOT_DISP, so we'll need a GOT entry for it.
10068 bool def_regular
= (mips_sym
->source() == Symbol::FROM_OBJECT
10069 && !mips_sym
->object()->is_dynamic()
10070 && !mips_sym
->is_undefined());
10072 || (parameters
->options().output_is_position_independent()
10073 && !parameters
->options().Bsymbolic()
10074 && !mips_sym
->is_forced_local()))
10076 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10078 mips_sym
->set_global_got_area(GGA_NORMAL
);
10083 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10084 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10085 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10086 case elfcpp::R_MIPS_TLS_LDM
:
10087 case elfcpp::R_MIPS16_TLS_LDM
:
10088 case elfcpp::R_MICROMIPS_TLS_LDM
:
10089 case elfcpp::R_MIPS_TLS_GD
:
10090 case elfcpp::R_MIPS16_TLS_GD
:
10091 case elfcpp::R_MICROMIPS_TLS_GD
:
10093 const bool is_final
= gsym
->final_value_is_known();
10094 const tls::Tls_optimization optimized_type
=
10095 Target_mips
<size
, big_endian
>::optimize_tls_reloc(is_final
, r_type
);
10099 case elfcpp::R_MIPS_TLS_GD
:
10100 case elfcpp::R_MIPS16_TLS_GD
:
10101 case elfcpp::R_MICROMIPS_TLS_GD
:
10102 if (optimized_type
== tls::TLSOPT_NONE
)
10104 // Create a pair of GOT entries for the module index and
10105 // dtv-relative offset.
10106 Mips_output_data_got
<size
, big_endian
>* got
=
10107 target
->got_section(symtab
, layout
);
10108 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10113 // FIXME: TLS optimization not supported yet.
10114 gold_unreachable();
10118 case elfcpp::R_MIPS_TLS_LDM
:
10119 case elfcpp::R_MIPS16_TLS_LDM
:
10120 case elfcpp::R_MICROMIPS_TLS_LDM
:
10121 if (optimized_type
== tls::TLSOPT_NONE
)
10123 // We always record LDM symbols as local with index 0.
10124 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
10130 // FIXME: TLS optimization not supported yet.
10131 gold_unreachable();
10134 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10135 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10136 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10137 layout
->set_has_static_tls();
10138 if (optimized_type
== tls::TLSOPT_NONE
)
10140 // Create a GOT entry for the tp-relative offset.
10141 Mips_output_data_got
<size
, big_endian
>* got
=
10142 target
->got_section(symtab
, layout
);
10143 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10148 // FIXME: TLS optimization not supported yet.
10149 gold_unreachable();
10154 gold_unreachable();
10158 case elfcpp::R_MIPS_COPY
:
10159 case elfcpp::R_MIPS_JUMP_SLOT
:
10160 // These are relocations which should only be seen by the
10161 // dynamic linker, and should never be seen here.
10162 gold_error(_("%s: unexpected reloc %u in object file"),
10163 object
->name().c_str(), r_type
);
10170 // Refuse some position-dependent relocations when creating a
10171 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
10172 // not PIC, but we can create dynamic relocations and the result
10173 // will be fine. Also do not refuse R_MIPS_LO16, which can be
10174 // combined with R_MIPS_GOT16.
10175 if (parameters
->options().shared())
10179 case elfcpp::R_MIPS16_HI16
:
10180 case elfcpp::R_MIPS_HI16
:
10181 case elfcpp::R_MICROMIPS_HI16
:
10182 // Don't refuse a high part relocation if it's against
10183 // no symbol (e.g. part of a compound relocation).
10187 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
10188 // and has a special meaning.
10189 if (!mips_obj
->is_newabi() && strcmp(gsym
->name(), "_gp_disp") == 0)
10194 case elfcpp::R_MIPS16_26
:
10195 case elfcpp::R_MIPS_26
:
10196 case elfcpp::R_MICROMIPS_26_S1
:
10197 gold_error(_("%s: relocation %u against `%s' can not be used when "
10198 "making a shared object; recompile with -fPIC"),
10199 object
->name().c_str(), r_type
, gsym
->name());
10206 template<int size
, bool big_endian
>
10208 Target_mips
<size
, big_endian
>::Scan::global(
10209 Symbol_table
* symtab
,
10211 Target_mips
<size
, big_endian
>* target
,
10212 Sized_relobj_file
<size
, big_endian
>* object
,
10213 unsigned int data_shndx
,
10214 Output_section
* output_section
,
10215 const Relatype
& reloc
,
10216 unsigned int r_type
,
10227 (const Reltype
*) NULL
,
10233 template<int size
, bool big_endian
>
10235 Target_mips
<size
, big_endian
>::Scan::global(
10236 Symbol_table
* symtab
,
10238 Target_mips
<size
, big_endian
>* target
,
10239 Sized_relobj_file
<size
, big_endian
>* object
,
10240 unsigned int data_shndx
,
10241 Output_section
* output_section
,
10242 const Reltype
& reloc
,
10243 unsigned int r_type
,
10253 (const Relatype
*) NULL
,
10260 // Return whether a R_MIPS_32/R_MIPS64 relocation needs to be applied.
10261 // In cases where Scan::local() or Scan::global() has created
10262 // a dynamic relocation, the addend of the relocation is carried
10263 // in the data, and we must not apply the static relocation.
10265 template<int size
, bool big_endian
>
10267 Target_mips
<size
, big_endian
>::Relocate::should_apply_static_reloc(
10268 const Mips_symbol
<size
>* gsym
,
10269 unsigned int r_type
,
10270 Output_section
* output_section
,
10271 Target_mips
* target
)
10273 // If the output section is not allocated, then we didn't call
10274 // scan_relocs, we didn't create a dynamic reloc, and we must apply
10276 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
10283 // For global symbols, we use the same helper routines used in the
10285 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
))
10286 && !gsym
->may_need_copy_reloc())
10288 // We have generated dynamic reloc (R_MIPS_REL32).
10290 bool multi_got
= false;
10291 if (target
->has_got_section())
10292 multi_got
= target
->got_section()->multi_got();
10293 bool has_got_offset
;
10295 has_got_offset
= gsym
->has_got_offset(GOT_TYPE_STANDARD
);
10297 has_got_offset
= gsym
->global_gotoffset() != -1U;
10298 if (!has_got_offset
)
10301 // Apply the relocation only if the symbol is in the local got.
10302 // Do not apply the relocation if the symbol is in the global
10304 return symbol_references_local(gsym
, gsym
->has_dynsym_index());
10307 // We have not generated dynamic reloc.
10312 // Perform a relocation.
10314 template<int size
, bool big_endian
>
10316 Target_mips
<size
, big_endian
>::Relocate::relocate(
10317 const Relocate_info
<size
, big_endian
>* relinfo
,
10318 unsigned int rel_type
,
10319 Target_mips
* target
,
10320 Output_section
* output_section
,
10322 const unsigned char* preloc
,
10323 const Sized_symbol
<size
>* gsym
,
10324 const Symbol_value
<size
>* psymval
,
10325 unsigned char* view
,
10326 Mips_address address
,
10329 Mips_address r_offset
;
10330 unsigned int r_sym
;
10331 unsigned int r_type
;
10332 unsigned int r_type2
;
10333 unsigned int r_type3
;
10334 unsigned char r_ssym
;
10335 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
10337 if (rel_type
== elfcpp::SHT_RELA
)
10339 const Relatype
rela(preloc
);
10340 r_offset
= rela
.get_r_offset();
10341 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10343 r_type
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10345 r_type2
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10346 get_r_type2(&rela
);
10347 r_type3
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10348 get_r_type3(&rela
);
10349 r_ssym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10351 r_addend
= rela
.get_r_addend();
10355 const Reltype
rel(preloc
);
10356 r_offset
= rel
.get_r_offset();
10357 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
10359 r_type
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
10367 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
10368 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
10370 Mips_relobj
<size
, big_endian
>* object
=
10371 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
10373 bool target_is_16_bit_code
= false;
10374 bool target_is_micromips_code
= false;
10375 bool cross_mode_jump
;
10377 Symbol_value
<size
> symval
;
10379 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
10381 bool changed_symbol_value
= false;
10384 target_is_16_bit_code
= object
->local_symbol_is_mips16(r_sym
);
10385 target_is_micromips_code
= object
->local_symbol_is_micromips(r_sym
);
10386 if (target_is_16_bit_code
|| target_is_micromips_code
)
10388 // MIPS16/microMIPS text labels should be treated as odd.
10389 symval
.set_output_value(psymval
->value(object
, 1));
10391 changed_symbol_value
= true;
10396 target_is_16_bit_code
= mips_sym
->is_mips16();
10397 target_is_micromips_code
= mips_sym
->is_micromips();
10399 // If this is a mips16/microMIPS text symbol, add 1 to the value to make
10400 // it odd. This will cause something like .word SYM to come up with
10401 // the right value when it is loaded into the PC.
10403 if ((mips_sym
->is_mips16() || mips_sym
->is_micromips())
10404 && psymval
->value(object
, 0) != 0)
10406 symval
.set_output_value(psymval
->value(object
, 0) | 1);
10408 changed_symbol_value
= true;
10411 // Pick the value to use for symbols defined in shared objects.
10412 if (mips_sym
->use_plt_offset(Scan::get_reference_flags(r_type
))
10413 || mips_sym
->has_lazy_stub())
10415 Mips_address value
;
10416 if (!mips_sym
->has_lazy_stub())
10418 // Prefer a standard MIPS PLT entry.
10419 if (mips_sym
->has_mips_plt_offset())
10421 value
= target
->plt_section()->mips_entry_address(mips_sym
);
10422 target_is_micromips_code
= false;
10423 target_is_16_bit_code
= false;
10427 value
= (target
->plt_section()->comp_entry_address(mips_sym
)
10429 if (target
->is_output_micromips())
10430 target_is_micromips_code
= true;
10432 target_is_16_bit_code
= true;
10436 value
= target
->mips_stubs_section()->stub_address(mips_sym
);
10438 symval
.set_output_value(value
);
10443 // TRUE if the symbol referred to by this relocation is "_gp_disp".
10444 // Note that such a symbol must always be a global symbol.
10445 bool gp_disp
= (gsym
!= NULL
&& (strcmp(gsym
->name(), "_gp_disp") == 0)
10446 && !object
->is_newabi());
10448 // TRUE if the symbol referred to by this relocation is "__gnu_local_gp".
10449 // Note that such a symbol must always be a global symbol.
10450 bool gnu_local_gp
= gsym
&& (strcmp(gsym
->name(), "__gnu_local_gp") == 0);
10455 if (!hi16_reloc(r_type
) && !lo16_reloc(r_type
))
10456 gold_error_at_location(relinfo
, relnum
, r_offset
,
10457 _("relocations against _gp_disp are permitted only"
10458 " with R_MIPS_HI16 and R_MIPS_LO16 relocations."));
10460 else if (gnu_local_gp
)
10462 // __gnu_local_gp is _gp symbol.
10463 symval
.set_output_value(target
->adjusted_gp_value(object
));
10467 // If this is a reference to a 16-bit function with a stub, we need
10468 // to redirect the relocation to the stub unless:
10470 // (a) the relocation is for a MIPS16 JAL;
10472 // (b) the relocation is for a MIPS16 PIC call, and there are no
10473 // non-MIPS16 uses of the GOT slot; or
10475 // (c) the section allows direct references to MIPS16 functions.
10476 if (r_type
!= elfcpp::R_MIPS16_26
10477 && !parameters
->options().relocatable()
10478 && ((mips_sym
!= NULL
10479 && mips_sym
->has_mips16_fn_stub()
10480 && (r_type
!= elfcpp::R_MIPS16_CALL16
|| mips_sym
->need_fn_stub()))
10481 || (mips_sym
== NULL
10482 && object
->get_local_mips16_fn_stub(r_sym
) != NULL
))
10483 && !object
->section_allows_mips16_refs(relinfo
->data_shndx
))
10485 // This is a 32- or 64-bit call to a 16-bit function. We should
10486 // have already noticed that we were going to need the
10488 Mips_address value
;
10489 if (mips_sym
== NULL
)
10490 value
= object
->get_local_mips16_fn_stub(r_sym
)->output_address();
10493 gold_assert(mips_sym
->need_fn_stub());
10494 if (mips_sym
->has_la25_stub())
10495 value
= target
->la25_stub_section()->stub_address(mips_sym
);
10498 value
= mips_sym
->template
10499 get_mips16_fn_stub
<big_endian
>()->output_address();
10502 symval
.set_output_value(value
);
10504 changed_symbol_value
= true;
10506 // The target is 16-bit, but the stub isn't.
10507 target_is_16_bit_code
= false;
10509 // If this is a MIPS16 call with a stub, that is made through the PLT or
10510 // to a standard MIPS function, we need to redirect the call to the stub.
10511 // Note that we specifically exclude R_MIPS16_CALL16 from this behavior;
10512 // indirect calls should use an indirect stub instead.
10513 else if (r_type
== elfcpp::R_MIPS16_26
&& !parameters
->options().relocatable()
10514 && ((mips_sym
!= NULL
10515 && (mips_sym
->has_mips16_call_stub()
10516 || mips_sym
->has_mips16_call_fp_stub()))
10517 || (mips_sym
== NULL
10518 && object
->get_local_mips16_call_stub(r_sym
) != NULL
))
10519 && ((mips_sym
!= NULL
&& mips_sym
->has_plt_offset())
10520 || !target_is_16_bit_code
))
10522 Mips16_stub_section
<size
, big_endian
>* call_stub
;
10523 if (mips_sym
== NULL
)
10524 call_stub
= object
->get_local_mips16_call_stub(r_sym
);
10527 // If both call_stub and call_fp_stub are defined, we can figure
10528 // out which one to use by checking which one appears in the input
10530 if (mips_sym
->has_mips16_call_stub()
10531 && mips_sym
->has_mips16_call_fp_stub())
10534 for (unsigned int i
= 1; i
< object
->shnum(); ++i
)
10536 if (object
->is_mips16_call_fp_stub_section(i
))
10538 call_stub
= mips_sym
->template
10539 get_mips16_call_fp_stub
<big_endian
>();
10544 if (call_stub
== NULL
)
10546 mips_sym
->template get_mips16_call_stub
<big_endian
>();
10548 else if (mips_sym
->has_mips16_call_stub())
10549 call_stub
= mips_sym
->template get_mips16_call_stub
<big_endian
>();
10551 call_stub
= mips_sym
->template get_mips16_call_fp_stub
<big_endian
>();
10554 symval
.set_output_value(call_stub
->output_address());
10556 changed_symbol_value
= true;
10558 // If this is a direct call to a PIC function, redirect to the
10560 else if (mips_sym
!= NULL
10561 && mips_sym
->has_la25_stub()
10562 && relocation_needs_la25_stub
<size
, big_endian
>(
10563 object
, r_type
, target_is_16_bit_code
))
10565 Mips_address value
= target
->la25_stub_section()->stub_address(mips_sym
);
10566 if (mips_sym
->is_micromips())
10568 symval
.set_output_value(value
);
10571 // For direct MIPS16 and microMIPS calls make sure the compressed PLT
10572 // entry is used if a standard PLT entry has also been made.
10573 else if ((r_type
== elfcpp::R_MIPS16_26
10574 || r_type
== elfcpp::R_MICROMIPS_26_S1
)
10575 && !parameters
->options().relocatable()
10576 && mips_sym
!= NULL
10577 && mips_sym
->has_plt_offset()
10578 && mips_sym
->has_comp_plt_offset()
10579 && mips_sym
->has_mips_plt_offset())
10581 Mips_address value
= (target
->plt_section()->comp_entry_address(mips_sym
)
10583 symval
.set_output_value(value
);
10586 target_is_16_bit_code
= !target
->is_output_micromips();
10587 target_is_micromips_code
= target
->is_output_micromips();
10590 // Make sure MIPS16 and microMIPS are not used together.
10591 if ((r_type
== elfcpp::R_MIPS16_26
&& target_is_micromips_code
)
10592 || (micromips_branch_reloc(r_type
) && target_is_16_bit_code
))
10594 gold_error(_("MIPS16 and microMIPS functions cannot call each other"));
10597 // Calls from 16-bit code to 32-bit code and vice versa require the
10598 // mode change. However, we can ignore calls to undefined weak symbols,
10599 // which should never be executed at runtime. This exception is important
10600 // because the assembly writer may have "known" that any definition of the
10601 // symbol would be 16-bit code, and that direct jumps were therefore
10604 (!parameters
->options().relocatable()
10605 && !(gsym
!= NULL
&& gsym
->is_weak_undefined())
10606 && ((r_type
== elfcpp::R_MIPS16_26
&& !target_is_16_bit_code
)
10607 || (r_type
== elfcpp::R_MICROMIPS_26_S1
&& !target_is_micromips_code
)
10608 || ((r_type
== elfcpp::R_MIPS_26
|| r_type
== elfcpp::R_MIPS_JALR
)
10609 && (target_is_16_bit_code
|| target_is_micromips_code
))));
10611 bool local
= (mips_sym
== NULL
10612 || (mips_sym
->got_only_for_calls()
10613 ? symbol_calls_local(mips_sym
, mips_sym
->has_dynsym_index())
10614 : symbol_references_local(mips_sym
,
10615 mips_sym
->has_dynsym_index())));
10617 // Global R_MIPS_GOT_PAGE/R_MICROMIPS_GOT_PAGE relocations are equivalent
10618 // to R_MIPS_GOT_DISP/R_MICROMIPS_GOT_DISP. The addend is applied by the
10619 // corresponding R_MIPS_GOT_OFST/R_MICROMIPS_GOT_OFST.
10620 if (got_page_reloc(r_type
) && !local
)
10621 r_type
= (micromips_reloc(r_type
) ? elfcpp::R_MICROMIPS_GOT_DISP
10622 : elfcpp::R_MIPS_GOT_DISP
);
10624 unsigned int got_offset
= 0;
10627 bool calculate_only
= false;
10628 Valtype calculated_value
= 0;
10629 bool extract_addend
= rel_type
== elfcpp::SHT_REL
;
10630 unsigned int r_types
[3] = { r_type
, r_type2
, r_type3
};
10632 Reloc_funcs::mips_reloc_unshuffle(view
, r_type
, false);
10634 // For Mips64 N64 ABI, there may be up to three operations specified per
10635 // record, by the fields r_type, r_type2, and r_type3. The first operation
10636 // takes its addend from the relocation record. Each subsequent operation
10637 // takes as its addend the result of the previous operation.
10638 // The first operation in a record which references a symbol uses the symbol
10639 // implied by r_sym. The next operation in a record which references a symbol
10640 // uses the special symbol value given by the r_ssym field. A third operation
10641 // in a record which references a symbol will assume a NULL symbol,
10642 // i.e. value zero.
10645 // Check if a record references to a symbol.
10646 for (unsigned int i
= 0; i
< 3; ++i
)
10648 if (r_types
[i
] == elfcpp::R_MIPS_NONE
)
10652 // Check if the next relocation is for the same instruction.
10653 calculate_only
= i
== 2 ? false
10654 : r_types
[i
+1] != elfcpp::R_MIPS_NONE
;
10656 if (object
->is_n64())
10660 // Handle special symbol for r_type2 relocation type.
10664 symval
.set_output_value(0);
10667 symval
.set_output_value(target
->gp_value());
10670 symval
.set_output_value(object
->gp_value());
10673 symval
.set_output_value(address
);
10676 gold_unreachable();
10682 // For r_type3 symbol value is 0.
10683 symval
.set_output_value(0);
10687 bool update_got_entry
= false;
10688 switch (r_types
[i
])
10690 case elfcpp::R_MIPS_NONE
:
10692 case elfcpp::R_MIPS_16
:
10693 reloc_status
= Reloc_funcs::rel16(view
, object
, psymval
, r_addend
,
10694 extract_addend
, calculate_only
,
10695 &calculated_value
);
10698 case elfcpp::R_MIPS_32
:
10699 if (should_apply_static_reloc(mips_sym
, r_types
[i
], output_section
,
10701 reloc_status
= Reloc_funcs::rel32(view
, object
, psymval
, r_addend
,
10702 extract_addend
, calculate_only
,
10703 &calculated_value
);
10704 if (mips_sym
!= NULL
10705 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
10706 && mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
10708 // If mips_sym->has_mips16_fn_stub() is false, symbol value is
10709 // already updated by adding +1.
10710 if (mips_sym
->has_mips16_fn_stub())
10712 gold_assert(mips_sym
->need_fn_stub());
10713 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
10714 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
10716 symval
.set_output_value(fn_stub
->output_address());
10719 got_offset
= mips_sym
->global_gotoffset();
10720 update_got_entry
= true;
10724 case elfcpp::R_MIPS_64
:
10725 if (should_apply_static_reloc(mips_sym
, r_types
[i
], output_section
,
10727 reloc_status
= Reloc_funcs::rel64(view
, object
, psymval
, r_addend
,
10728 extract_addend
, calculate_only
,
10729 &calculated_value
, false);
10730 else if (target
->is_output_n64() && r_addend
!= 0)
10731 // Only apply the addend. The static relocation was RELA, but the
10732 // dynamic relocation is REL, so we need to apply the addend.
10733 reloc_status
= Reloc_funcs::rel64(view
, object
, psymval
, r_addend
,
10734 extract_addend
, calculate_only
,
10735 &calculated_value
, true);
10737 case elfcpp::R_MIPS_REL32
:
10738 gold_unreachable();
10740 case elfcpp::R_MIPS_PC32
:
10741 reloc_status
= Reloc_funcs::relpc32(view
, object
, psymval
, address
,
10742 r_addend
, extract_addend
,
10744 &calculated_value
);
10747 case elfcpp::R_MIPS16_26
:
10748 // The calculation for R_MIPS16_26 is just the same as for an
10749 // R_MIPS_26. It's only the storage of the relocated field into
10750 // the output file that's different. So, we just fall through to the
10751 // R_MIPS_26 case here.
10752 case elfcpp::R_MIPS_26
:
10753 case elfcpp::R_MICROMIPS_26_S1
:
10754 reloc_status
= Reloc_funcs::rel26(view
, object
, psymval
, address
,
10755 gsym
== NULL
, r_addend
, extract_addend
, gsym
, cross_mode_jump
,
10756 r_types
[i
], target
->jal_to_bal(), calculate_only
,
10757 &calculated_value
);
10760 case elfcpp::R_MIPS_HI16
:
10761 case elfcpp::R_MIPS16_HI16
:
10762 case elfcpp::R_MICROMIPS_HI16
:
10763 if (rel_type
== elfcpp::SHT_RELA
)
10764 reloc_status
= Reloc_funcs::do_relhi16(view
, object
, psymval
,
10766 gp_disp
, r_types
[i
],
10768 target
, calculate_only
,
10769 &calculated_value
);
10770 else if (rel_type
== elfcpp::SHT_REL
)
10771 reloc_status
= Reloc_funcs::relhi16(view
, object
, psymval
, r_addend
,
10772 address
, gp_disp
, r_types
[i
],
10773 r_sym
, extract_addend
);
10775 gold_unreachable();
10778 case elfcpp::R_MIPS_LO16
:
10779 case elfcpp::R_MIPS16_LO16
:
10780 case elfcpp::R_MICROMIPS_LO16
:
10781 case elfcpp::R_MICROMIPS_HI0_LO16
:
10782 reloc_status
= Reloc_funcs::rello16(target
, view
, object
, psymval
,
10783 r_addend
, extract_addend
, address
,
10784 gp_disp
, r_types
[i
], r_sym
,
10785 rel_type
, calculate_only
,
10786 &calculated_value
);
10789 case elfcpp::R_MIPS_LITERAL
:
10790 case elfcpp::R_MICROMIPS_LITERAL
:
10791 // Because we don't merge literal sections, we can handle this
10792 // just like R_MIPS_GPREL16. In the long run, we should merge
10793 // shared literals, and then we will need to additional work
10798 case elfcpp::R_MIPS_GPREL16
:
10799 case elfcpp::R_MIPS16_GPREL
:
10800 case elfcpp::R_MICROMIPS_GPREL7_S2
:
10801 case elfcpp::R_MICROMIPS_GPREL16
:
10802 reloc_status
= Reloc_funcs::relgprel(view
, object
, psymval
,
10803 target
->adjusted_gp_value(object
),
10804 r_addend
, extract_addend
,
10805 gsym
== NULL
, r_types
[i
],
10806 calculate_only
, &calculated_value
);
10809 case elfcpp::R_MIPS_PC16
:
10810 reloc_status
= Reloc_funcs::relpc16(view
, object
, psymval
, address
,
10811 r_addend
, extract_addend
,
10813 &calculated_value
);
10815 case elfcpp::R_MICROMIPS_PC7_S1
:
10816 reloc_status
= Reloc_funcs::relmicromips_pc7_s1(view
, object
, psymval
,
10820 &calculated_value
);
10822 case elfcpp::R_MICROMIPS_PC10_S1
:
10823 reloc_status
= Reloc_funcs::relmicromips_pc10_s1(view
, object
,
10825 r_addend
, extract_addend
,
10827 &calculated_value
);
10829 case elfcpp::R_MICROMIPS_PC16_S1
:
10830 reloc_status
= Reloc_funcs::relmicromips_pc16_s1(view
, object
,
10832 r_addend
, extract_addend
,
10834 &calculated_value
);
10836 case elfcpp::R_MIPS_GPREL32
:
10837 reloc_status
= Reloc_funcs::relgprel32(view
, object
, psymval
,
10838 target
->adjusted_gp_value(object
),
10839 r_addend
, extract_addend
,
10841 &calculated_value
);
10843 case elfcpp::R_MIPS_GOT_HI16
:
10844 case elfcpp::R_MIPS_CALL_HI16
:
10845 case elfcpp::R_MICROMIPS_GOT_HI16
:
10846 case elfcpp::R_MICROMIPS_CALL_HI16
:
10848 got_offset
= target
->got_section()->got_offset(gsym
,
10852 got_offset
= target
->got_section()->got_offset(r_sym
,
10855 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10856 reloc_status
= Reloc_funcs::relgot_hi16(view
, gp_offset
,
10858 &calculated_value
);
10859 update_got_entry
= changed_symbol_value
;
10862 case elfcpp::R_MIPS_GOT_LO16
:
10863 case elfcpp::R_MIPS_CALL_LO16
:
10864 case elfcpp::R_MICROMIPS_GOT_LO16
:
10865 case elfcpp::R_MICROMIPS_CALL_LO16
:
10867 got_offset
= target
->got_section()->got_offset(gsym
,
10871 got_offset
= target
->got_section()->got_offset(r_sym
,
10874 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10875 reloc_status
= Reloc_funcs::relgot_lo16(view
, gp_offset
,
10877 &calculated_value
);
10878 update_got_entry
= changed_symbol_value
;
10881 case elfcpp::R_MIPS_GOT_DISP
:
10882 case elfcpp::R_MICROMIPS_GOT_DISP
:
10883 case elfcpp::R_MIPS_EH
:
10885 got_offset
= target
->got_section()->got_offset(gsym
,
10889 got_offset
= target
->got_section()->got_offset(r_sym
,
10892 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10893 if (eh_reloc(r_types
[i
]))
10894 reloc_status
= Reloc_funcs::releh(view
, gp_offset
,
10896 &calculated_value
);
10898 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
10900 &calculated_value
);
10902 case elfcpp::R_MIPS_CALL16
:
10903 case elfcpp::R_MIPS16_CALL16
:
10904 case elfcpp::R_MICROMIPS_CALL16
:
10905 gold_assert(gsym
!= NULL
);
10906 got_offset
= target
->got_section()->got_offset(gsym
,
10909 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10910 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
10911 calculate_only
, &calculated_value
);
10912 // TODO(sasa): We should also initialize update_got_entry
10913 // in other place swhere relgot is called.
10914 update_got_entry
= changed_symbol_value
;
10917 case elfcpp::R_MIPS_GOT16
:
10918 case elfcpp::R_MIPS16_GOT16
:
10919 case elfcpp::R_MICROMIPS_GOT16
:
10922 got_offset
= target
->got_section()->got_offset(gsym
,
10925 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10926 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
10928 &calculated_value
);
10932 if (rel_type
== elfcpp::SHT_RELA
)
10933 reloc_status
= Reloc_funcs::do_relgot16_local(view
, object
,
10938 &calculated_value
);
10939 else if (rel_type
== elfcpp::SHT_REL
)
10940 reloc_status
= Reloc_funcs::relgot16_local(view
, object
,
10943 r_types
[i
], r_sym
);
10945 gold_unreachable();
10947 update_got_entry
= changed_symbol_value
;
10950 case elfcpp::R_MIPS_TLS_GD
:
10951 case elfcpp::R_MIPS16_TLS_GD
:
10952 case elfcpp::R_MICROMIPS_TLS_GD
:
10954 got_offset
= target
->got_section()->got_offset(gsym
,
10958 got_offset
= target
->got_section()->got_offset(r_sym
,
10961 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10962 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
10963 &calculated_value
);
10966 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10967 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10968 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10970 got_offset
= target
->got_section()->got_offset(gsym
,
10971 GOT_TYPE_TLS_OFFSET
,
10974 got_offset
= target
->got_section()->got_offset(r_sym
,
10975 GOT_TYPE_TLS_OFFSET
,
10977 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10978 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
10979 &calculated_value
);
10982 case elfcpp::R_MIPS_TLS_LDM
:
10983 case elfcpp::R_MIPS16_TLS_LDM
:
10984 case elfcpp::R_MICROMIPS_TLS_LDM
:
10985 // Relocate the field with the offset of the GOT entry for
10986 // the module index.
10987 got_offset
= target
->got_section()->tls_ldm_offset(object
);
10988 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10989 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
10990 &calculated_value
);
10993 case elfcpp::R_MIPS_GOT_PAGE
:
10994 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10995 reloc_status
= Reloc_funcs::relgotpage(target
, view
, object
, psymval
,
10996 r_addend
, extract_addend
,
10998 &calculated_value
);
11001 case elfcpp::R_MIPS_GOT_OFST
:
11002 case elfcpp::R_MICROMIPS_GOT_OFST
:
11003 reloc_status
= Reloc_funcs::relgotofst(target
, view
, object
, psymval
,
11004 r_addend
, extract_addend
,
11005 local
, calculate_only
,
11006 &calculated_value
);
11009 case elfcpp::R_MIPS_JALR
:
11010 case elfcpp::R_MICROMIPS_JALR
:
11011 // This relocation is only a hint. In some cases, we optimize
11012 // it into a bal instruction. But we don't try to optimize
11013 // when the symbol does not resolve locally.
11015 || symbol_calls_local(gsym
, gsym
->has_dynsym_index()))
11016 reloc_status
= Reloc_funcs::reljalr(view
, object
, psymval
, address
,
11017 r_addend
, extract_addend
,
11018 cross_mode_jump
, r_types
[i
],
11019 target
->jalr_to_bal(),
11022 &calculated_value
);
11025 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
11026 case elfcpp::R_MIPS16_TLS_DTPREL_HI16
:
11027 case elfcpp::R_MICROMIPS_TLS_DTPREL_HI16
:
11028 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
11029 elfcpp::DTP_OFFSET
, r_addend
,
11030 extract_addend
, calculate_only
,
11031 &calculated_value
);
11033 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
11034 case elfcpp::R_MIPS16_TLS_DTPREL_LO16
:
11035 case elfcpp::R_MICROMIPS_TLS_DTPREL_LO16
:
11036 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
11037 elfcpp::DTP_OFFSET
, r_addend
,
11038 extract_addend
, calculate_only
,
11039 &calculated_value
);
11041 case elfcpp::R_MIPS_TLS_DTPREL32
:
11042 case elfcpp::R_MIPS_TLS_DTPREL64
:
11043 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
11044 elfcpp::DTP_OFFSET
, r_addend
,
11045 extract_addend
, calculate_only
,
11046 &calculated_value
);
11048 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
11049 case elfcpp::R_MIPS16_TLS_TPREL_HI16
:
11050 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
11051 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
11052 elfcpp::TP_OFFSET
, r_addend
,
11053 extract_addend
, calculate_only
,
11054 &calculated_value
);
11056 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
11057 case elfcpp::R_MIPS16_TLS_TPREL_LO16
:
11058 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
11059 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
11060 elfcpp::TP_OFFSET
, r_addend
,
11061 extract_addend
, calculate_only
,
11062 &calculated_value
);
11064 case elfcpp::R_MIPS_TLS_TPREL32
:
11065 case elfcpp::R_MIPS_TLS_TPREL64
:
11066 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
11067 elfcpp::TP_OFFSET
, r_addend
,
11068 extract_addend
, calculate_only
,
11069 &calculated_value
);
11071 case elfcpp::R_MIPS_SUB
:
11072 case elfcpp::R_MICROMIPS_SUB
:
11073 reloc_status
= Reloc_funcs::relsub(view
, object
, psymval
, r_addend
,
11075 calculate_only
, &calculated_value
);
11078 gold_error_at_location(relinfo
, relnum
, r_offset
,
11079 _("unsupported reloc %u"), r_types
[i
]);
11083 if (update_got_entry
)
11085 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
11086 if (mips_sym
!= NULL
&& mips_sym
->get_applied_secondary_got_fixup())
11087 got
->update_got_entry(got
->get_primary_got_offset(mips_sym
),
11088 psymval
->value(object
, 0));
11090 got
->update_got_entry(got_offset
, psymval
->value(object
, 0));
11093 r_addend
= calculated_value
;
11096 bool jal_shuffle
= jal_reloc(r_type
) ? !parameters
->options().relocatable()
11098 Reloc_funcs::mips_reloc_shuffle(view
, r_type
, jal_shuffle
);
11100 // Report any errors.
11101 switch (reloc_status
)
11103 case Reloc_funcs::STATUS_OKAY
:
11105 case Reloc_funcs::STATUS_OVERFLOW
:
11106 gold_error_at_location(relinfo
, relnum
, r_offset
,
11107 _("relocation overflow"));
11109 case Reloc_funcs::STATUS_BAD_RELOC
:
11110 gold_error_at_location(relinfo
, relnum
, r_offset
,
11111 _("unexpected opcode while processing relocation"));
11114 gold_unreachable();
11120 // Get the Reference_flags for a particular relocation.
11122 template<int size
, bool big_endian
>
11124 Target_mips
<size
, big_endian
>::Scan::get_reference_flags(
11125 unsigned int r_type
)
11129 case elfcpp::R_MIPS_NONE
:
11130 // No symbol reference.
11133 case elfcpp::R_MIPS_16
:
11134 case elfcpp::R_MIPS_32
:
11135 case elfcpp::R_MIPS_64
:
11136 case elfcpp::R_MIPS_HI16
:
11137 case elfcpp::R_MIPS_LO16
:
11138 case elfcpp::R_MIPS16_HI16
:
11139 case elfcpp::R_MIPS16_LO16
:
11140 case elfcpp::R_MICROMIPS_HI16
:
11141 case elfcpp::R_MICROMIPS_LO16
:
11142 return Symbol::ABSOLUTE_REF
;
11144 case elfcpp::R_MIPS_26
:
11145 case elfcpp::R_MIPS16_26
:
11146 case elfcpp::R_MICROMIPS_26_S1
:
11147 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
11149 case elfcpp::R_MIPS_GPREL32
:
11150 case elfcpp::R_MIPS_GPREL16
:
11151 case elfcpp::R_MIPS_REL32
:
11152 case elfcpp::R_MIPS16_GPREL
:
11153 return Symbol::RELATIVE_REF
;
11155 case elfcpp::R_MIPS_PC16
:
11156 case elfcpp::R_MIPS_PC32
:
11157 case elfcpp::R_MIPS_JALR
:
11158 case elfcpp::R_MICROMIPS_JALR
:
11159 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
11161 case elfcpp::R_MIPS_GOT16
:
11162 case elfcpp::R_MIPS_CALL16
:
11163 case elfcpp::R_MIPS_GOT_DISP
:
11164 case elfcpp::R_MIPS_GOT_HI16
:
11165 case elfcpp::R_MIPS_GOT_LO16
:
11166 case elfcpp::R_MIPS_CALL_HI16
:
11167 case elfcpp::R_MIPS_CALL_LO16
:
11168 case elfcpp::R_MIPS_LITERAL
:
11169 case elfcpp::R_MIPS_GOT_PAGE
:
11170 case elfcpp::R_MIPS_GOT_OFST
:
11171 case elfcpp::R_MIPS16_GOT16
:
11172 case elfcpp::R_MIPS16_CALL16
:
11173 case elfcpp::R_MICROMIPS_GOT16
:
11174 case elfcpp::R_MICROMIPS_CALL16
:
11175 case elfcpp::R_MICROMIPS_GOT_HI16
:
11176 case elfcpp::R_MICROMIPS_GOT_LO16
:
11177 case elfcpp::R_MICROMIPS_CALL_HI16
:
11178 case elfcpp::R_MICROMIPS_CALL_LO16
:
11179 case elfcpp::R_MIPS_EH
:
11180 // Absolute in GOT.
11181 return Symbol::RELATIVE_REF
;
11183 case elfcpp::R_MIPS_TLS_DTPMOD32
:
11184 case elfcpp::R_MIPS_TLS_DTPREL32
:
11185 case elfcpp::R_MIPS_TLS_DTPMOD64
:
11186 case elfcpp::R_MIPS_TLS_DTPREL64
:
11187 case elfcpp::R_MIPS_TLS_GD
:
11188 case elfcpp::R_MIPS_TLS_LDM
:
11189 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
11190 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
11191 case elfcpp::R_MIPS_TLS_GOTTPREL
:
11192 case elfcpp::R_MIPS_TLS_TPREL32
:
11193 case elfcpp::R_MIPS_TLS_TPREL64
:
11194 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
11195 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
11196 case elfcpp::R_MIPS16_TLS_GD
:
11197 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
11198 case elfcpp::R_MICROMIPS_TLS_GD
:
11199 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
11200 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
11201 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
11202 return Symbol::TLS_REF
;
11204 case elfcpp::R_MIPS_COPY
:
11205 case elfcpp::R_MIPS_JUMP_SLOT
:
11207 gold_unreachable();
11208 // Not expected. We will give an error later.
11213 // Report an unsupported relocation against a local symbol.
11215 template<int size
, bool big_endian
>
11217 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_local(
11218 Sized_relobj_file
<size
, big_endian
>* object
,
11219 unsigned int r_type
)
11221 gold_error(_("%s: unsupported reloc %u against local symbol"),
11222 object
->name().c_str(), r_type
);
11225 // Report an unsupported relocation against a global symbol.
11227 template<int size
, bool big_endian
>
11229 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_global(
11230 Sized_relobj_file
<size
, big_endian
>* object
,
11231 unsigned int r_type
,
11234 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
11235 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
11238 // Return printable name for ABI.
11239 template<int size
, bool big_endian
>
11241 Target_mips
<size
, big_endian
>::elf_mips_abi_name(elfcpp::Elf_Word e_flags
,
11242 unsigned char ei_class
)
11244 switch (e_flags
& elfcpp::EF_MIPS_ABI
)
11247 if ((e_flags
& elfcpp::EF_MIPS_ABI2
) != 0)
11249 else if (elfcpp::abi_64(ei_class
))
11253 case elfcpp::E_MIPS_ABI_O32
:
11255 case elfcpp::E_MIPS_ABI_O64
:
11257 case elfcpp::E_MIPS_ABI_EABI32
:
11259 case elfcpp::E_MIPS_ABI_EABI64
:
11262 return "unknown abi";
11266 template<int size
, bool big_endian
>
11268 Target_mips
<size
, big_endian
>::elf_mips_mach_name(elfcpp::Elf_Word e_flags
)
11270 switch (e_flags
& elfcpp::EF_MIPS_MACH
)
11272 case elfcpp::E_MIPS_MACH_3900
:
11273 return "mips:3900";
11274 case elfcpp::E_MIPS_MACH_4010
:
11275 return "mips:4010";
11276 case elfcpp::E_MIPS_MACH_4100
:
11277 return "mips:4100";
11278 case elfcpp::E_MIPS_MACH_4111
:
11279 return "mips:4111";
11280 case elfcpp::E_MIPS_MACH_4120
:
11281 return "mips:4120";
11282 case elfcpp::E_MIPS_MACH_4650
:
11283 return "mips:4650";
11284 case elfcpp::E_MIPS_MACH_5400
:
11285 return "mips:5400";
11286 case elfcpp::E_MIPS_MACH_5500
:
11287 return "mips:5500";
11288 case elfcpp::E_MIPS_MACH_SB1
:
11290 case elfcpp::E_MIPS_MACH_9000
:
11291 return "mips:9000";
11292 case elfcpp::E_MIPS_MACH_LS2E
:
11293 return "mips:loongson-2e";
11294 case elfcpp::E_MIPS_MACH_LS2F
:
11295 return "mips:loongson-2f";
11296 case elfcpp::E_MIPS_MACH_LS3A
:
11297 return "mips:loongson-3a";
11298 case elfcpp::E_MIPS_MACH_OCTEON
:
11299 return "mips:octeon";
11300 case elfcpp::E_MIPS_MACH_OCTEON2
:
11301 return "mips:octeon2";
11302 case elfcpp::E_MIPS_MACH_XLR
:
11305 switch (e_flags
& elfcpp::EF_MIPS_ARCH
)
11308 case elfcpp::E_MIPS_ARCH_1
:
11309 return "mips:3000";
11311 case elfcpp::E_MIPS_ARCH_2
:
11312 return "mips:6000";
11314 case elfcpp::E_MIPS_ARCH_3
:
11315 return "mips:4000";
11317 case elfcpp::E_MIPS_ARCH_4
:
11318 return "mips:8000";
11320 case elfcpp::E_MIPS_ARCH_5
:
11321 return "mips:mips5";
11323 case elfcpp::E_MIPS_ARCH_32
:
11324 return "mips:isa32";
11326 case elfcpp::E_MIPS_ARCH_64
:
11327 return "mips:isa64";
11329 case elfcpp::E_MIPS_ARCH_32R2
:
11330 return "mips:isa32r2";
11332 case elfcpp::E_MIPS_ARCH_64R2
:
11333 return "mips:isa64r2";
11336 return "unknown CPU";
11339 template<int size
, bool big_endian
>
11340 const Target::Target_info Target_mips
<size
, big_endian
>::mips_info
=
11343 big_endian
, // is_big_endian
11344 elfcpp::EM_MIPS
, // machine_code
11345 true, // has_make_symbol
11346 false, // has_resolve
11347 false, // has_code_fill
11348 true, // is_default_stack_executable
11349 false, // can_icf_inline_merge_sections
11351 size
== 32 ? "/lib/ld.so.1" : "/lib64/ld.so.1", // dynamic_linker
11352 0x400000, // default_text_segment_address
11353 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
11354 4 * 1024, // common_pagesize (overridable by -z common-page-size)
11355 false, // isolate_execinstr
11356 0, // rosegment_gap
11357 elfcpp::SHN_UNDEF
, // small_common_shndx
11358 elfcpp::SHN_UNDEF
, // large_common_shndx
11359 0, // small_common_section_flags
11360 0, // large_common_section_flags
11361 NULL
, // attributes_section
11362 NULL
, // attributes_vendor
11363 "__start", // entry_symbol_name
11364 32, // hash_entry_size
11367 template<int size
, bool big_endian
>
11368 class Target_mips_nacl
: public Target_mips
<size
, big_endian
>
11372 : Target_mips
<size
, big_endian
>(&mips_nacl_info
)
11376 static const Target::Target_info mips_nacl_info
;
11379 template<int size
, bool big_endian
>
11380 const Target::Target_info Target_mips_nacl
<size
, big_endian
>::mips_nacl_info
=
11383 big_endian
, // is_big_endian
11384 elfcpp::EM_MIPS
, // machine_code
11385 true, // has_make_symbol
11386 false, // has_resolve
11387 false, // has_code_fill
11388 true, // is_default_stack_executable
11389 false, // can_icf_inline_merge_sections
11391 "/lib/ld.so.1", // dynamic_linker
11392 0x20000, // default_text_segment_address
11393 0x10000, // abi_pagesize (overridable by -z max-page-size)
11394 0x10000, // common_pagesize (overridable by -z common-page-size)
11395 true, // isolate_execinstr
11396 0x10000000, // rosegment_gap
11397 elfcpp::SHN_UNDEF
, // small_common_shndx
11398 elfcpp::SHN_UNDEF
, // large_common_shndx
11399 0, // small_common_section_flags
11400 0, // large_common_section_flags
11401 NULL
, // attributes_section
11402 NULL
, // attributes_vendor
11403 "_start", // entry_symbol_name
11404 32, // hash_entry_size
11407 // Target selector for Mips. Note this is never instantiated directly.
11408 // It's only used in Target_selector_mips_nacl, below.
11410 template<int size
, bool big_endian
>
11411 class Target_selector_mips
: public Target_selector
11414 Target_selector_mips()
11415 : Target_selector(elfcpp::EM_MIPS
, size
, big_endian
,
11417 (big_endian
? "elf64-tradbigmips" : "elf64-tradlittlemips") :
11418 (big_endian
? "elf32-tradbigmips" : "elf32-tradlittlemips")),
11420 (big_endian
? "elf64btsmip" : "elf64ltsmip") :
11421 (big_endian
? "elf32btsmip" : "elf32ltsmip")))
11424 Target
* do_instantiate_target()
11425 { return new Target_mips
<size
, big_endian
>(); }
11428 template<int size
, bool big_endian
>
11429 class Target_selector_mips_nacl
11430 : public Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
11431 Target_mips_nacl
<size
, big_endian
> >
11434 Target_selector_mips_nacl()
11435 : Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
11436 Target_mips_nacl
<size
, big_endian
> >(
11437 // NaCl currently supports only MIPS32 little-endian.
11438 "mipsel", "elf32-tradlittlemips-nacl", "elf32-tradlittlemips-nacl")
11442 Target_selector_mips_nacl
<32, true> target_selector_mips32
;
11443 Target_selector_mips_nacl
<32, false> target_selector_mips32el
;
11444 Target_selector_mips_nacl
<64, true> target_selector_mips64
;
11445 Target_selector_mips_nacl
<64, false> target_selector_mips64el
;
11447 } // End anonymous namespace.