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());
1545 // Downcast a base pointer to a Mips_relobj pointer. This is
1546 // not type-safe but we only use Mips_relobj not the base class.
1547 static Mips_relobj
<size
, big_endian
>*
1548 as_mips_relobj(Relobj
* relobj
)
1549 { return static_cast<Mips_relobj
<size
, big_endian
>*>(relobj
); }
1551 // Downcast a base pointer to a Mips_relobj pointer. This is
1552 // not type-safe but we only use Mips_relobj not the base class.
1553 static const Mips_relobj
<size
, big_endian
>*
1554 as_mips_relobj(const Relobj
* relobj
)
1555 { return static_cast<const Mips_relobj
<size
, big_endian
>*>(relobj
); }
1557 // Processor-specific flags in ELF file header. This is valid only after
1560 processor_specific_flags() const
1561 { return this->processor_specific_flags_
; }
1563 // Whether a local symbol is MIPS16 symbol. R_SYM is the symbol table
1564 // index. This is only valid after do_count_local_symbol is called.
1566 local_symbol_is_mips16(unsigned int r_sym
) const
1568 gold_assert(r_sym
< this->local_symbol_is_mips16_
.size());
1569 return this->local_symbol_is_mips16_
[r_sym
];
1572 // Whether a local symbol is microMIPS symbol. R_SYM is the symbol table
1573 // index. This is only valid after do_count_local_symbol is called.
1575 local_symbol_is_micromips(unsigned int r_sym
) const
1577 gold_assert(r_sym
< this->local_symbol_is_micromips_
.size());
1578 return this->local_symbol_is_micromips_
[r_sym
];
1581 // Get or create MIPS16 stub section.
1582 Mips16_stub_section
<size
, big_endian
>*
1583 get_mips16_stub_section(unsigned int shndx
)
1585 typename
Mips16_stubs_int_map::const_iterator it
=
1586 this->mips16_stub_sections_
.find(shndx
);
1587 if (it
!= this->mips16_stub_sections_
.end())
1588 return (*it
).second
;
1590 Mips16_stub_section
<size
, big_endian
>* stub_section
=
1591 new Mips16_stub_section
<size
, big_endian
>(this, shndx
);
1592 this->mips16_stub_sections_
.insert(
1593 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1594 stub_section
->shndx(), stub_section
));
1595 return stub_section
;
1598 // Return MIPS16 fn stub section for local symbol R_SYM, or NULL if this
1599 // object doesn't have fn stub for R_SYM.
1600 Mips16_stub_section
<size
, big_endian
>*
1601 get_local_mips16_fn_stub(unsigned int r_sym
) const
1603 typename
Mips16_stubs_int_map::const_iterator it
=
1604 this->local_mips16_fn_stubs_
.find(r_sym
);
1605 if (it
!= this->local_mips16_fn_stubs_
.end())
1606 return (*it
).second
;
1610 // Record that this object has MIPS16 fn stub for local symbol. This method
1611 // is only called if we decided not to discard the stub.
1613 add_local_mips16_fn_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1615 gold_assert(stub
->is_for_local_function());
1616 unsigned int r_sym
= stub
->r_sym();
1617 this->local_mips16_fn_stubs_
.insert(
1618 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1622 // Return MIPS16 call stub section for local symbol R_SYM, or NULL if this
1623 // object doesn't have call stub for R_SYM.
1624 Mips16_stub_section
<size
, big_endian
>*
1625 get_local_mips16_call_stub(unsigned int r_sym
) const
1627 typename
Mips16_stubs_int_map::const_iterator it
=
1628 this->local_mips16_call_stubs_
.find(r_sym
);
1629 if (it
!= this->local_mips16_call_stubs_
.end())
1630 return (*it
).second
;
1634 // Record that this object has MIPS16 call stub for local symbol. This method
1635 // is only called if we decided not to discard the stub.
1637 add_local_mips16_call_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1639 gold_assert(stub
->is_for_local_function());
1640 unsigned int r_sym
= stub
->r_sym();
1641 this->local_mips16_call_stubs_
.insert(
1642 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1646 // Record that we found "non 16-bit" call relocation against local symbol
1647 // SYMNDX. This reloc would need to refer to a MIPS16 fn stub, if there
1650 add_local_non_16bit_call(unsigned int symndx
)
1651 { this->local_non_16bit_calls_
.insert(symndx
); }
1653 // Return true if there is any "non 16-bit" call relocation against local
1654 // symbol SYMNDX in this object.
1656 has_local_non_16bit_call_relocs(unsigned int symndx
)
1658 return (this->local_non_16bit_calls_
.find(symndx
)
1659 != this->local_non_16bit_calls_
.end());
1662 // Record that we found 16-bit call relocation R_MIPS16_26 against local
1663 // symbol SYMNDX. Local MIPS16 call or call_fp stubs will only be needed
1664 // if there is some R_MIPS16_26 relocation that refers to the stub symbol.
1666 add_local_16bit_call(unsigned int symndx
)
1667 { this->local_16bit_calls_
.insert(symndx
); }
1669 // Return true if there is any 16-bit call relocation R_MIPS16_26 against local
1670 // symbol SYMNDX in this object.
1672 has_local_16bit_call_relocs(unsigned int symndx
)
1674 return (this->local_16bit_calls_
.find(symndx
)
1675 != this->local_16bit_calls_
.end());
1678 // Get gp value that was used to create this object.
1681 { return this->gp_
; }
1683 // Return whether the object is a PIC object.
1686 { return this->is_pic_
; }
1688 // Return whether the object uses N32 ABI.
1691 { return this->is_n32_
; }
1693 // Return whether the object uses N64 ABI.
1696 { return size
== 64; }
1698 // Return whether the object uses NewABI conventions.
1701 { return this->is_n32() || this->is_n64(); }
1703 // Return Mips_got_info for this object.
1704 Mips_got_info
<size
, big_endian
>*
1705 get_got_info() const
1706 { return this->got_info_
; }
1708 // Return Mips_got_info for this object. Create new info if it doesn't exist.
1709 Mips_got_info
<size
, big_endian
>*
1710 get_or_create_got_info()
1712 if (!this->got_info_
)
1713 this->got_info_
= new Mips_got_info
<size
, big_endian
>();
1714 return this->got_info_
;
1717 // Set Mips_got_info for this object.
1719 set_got_info(Mips_got_info
<size
, big_endian
>* got_info
)
1720 { this->got_info_
= got_info
; }
1722 // Whether a section SHDNX is a MIPS16 stub section. This is only valid
1723 // after do_read_symbols is called.
1725 is_mips16_stub_section(unsigned int shndx
)
1727 return (is_mips16_fn_stub_section(shndx
)
1728 || is_mips16_call_stub_section(shndx
)
1729 || is_mips16_call_fp_stub_section(shndx
));
1732 // Return TRUE if relocations in section SHNDX can refer directly to a
1733 // MIPS16 function rather than to a hard-float stub. This is only valid
1734 // after do_read_symbols is called.
1736 section_allows_mips16_refs(unsigned int shndx
)
1738 return (this->is_mips16_stub_section(shndx
) || shndx
== this->pdr_shndx_
);
1741 // Whether a section SHDNX is a MIPS16 fn stub section. This is only valid
1742 // after do_read_symbols is called.
1744 is_mips16_fn_stub_section(unsigned int shndx
)
1746 gold_assert(shndx
< this->section_is_mips16_fn_stub_
.size());
1747 return this->section_is_mips16_fn_stub_
[shndx
];
1750 // Whether a section SHDNX is a MIPS16 call stub section. This is only valid
1751 // after do_read_symbols is called.
1753 is_mips16_call_stub_section(unsigned int shndx
)
1755 gold_assert(shndx
< this->section_is_mips16_call_stub_
.size());
1756 return this->section_is_mips16_call_stub_
[shndx
];
1759 // Whether a section SHDNX is a MIPS16 call_fp stub section. This is only
1760 // valid after do_read_symbols is called.
1762 is_mips16_call_fp_stub_section(unsigned int shndx
)
1764 gold_assert(shndx
< this->section_is_mips16_call_fp_stub_
.size());
1765 return this->section_is_mips16_call_fp_stub_
[shndx
];
1768 // Discard MIPS16 stub secions that are not needed.
1770 discard_mips16_stub_sections(Symbol_table
* symtab
);
1772 // Return gprmask from the .reginfo section of this object.
1775 { return this->gprmask_
; }
1777 // Return cprmask1 from the .reginfo section of this object.
1780 { return this->cprmask1_
; }
1782 // Return cprmask2 from the .reginfo section of this object.
1785 { return this->cprmask2_
; }
1787 // Return cprmask3 from the .reginfo section of this object.
1790 { return this->cprmask3_
; }
1792 // Return cprmask4 from the .reginfo section of this object.
1795 { return this->cprmask4_
; }
1798 // Count the local symbols.
1800 do_count_local_symbols(Stringpool_template
<char>*,
1801 Stringpool_template
<char>*);
1803 // Read the symbol information.
1805 do_read_symbols(Read_symbols_data
* sd
);
1808 // The name of the options section.
1809 const char* mips_elf_options_section_name()
1810 { return this->is_newabi() ? ".MIPS.options" : ".options"; }
1812 // processor-specific flags in ELF file header.
1813 elfcpp::Elf_Word processor_specific_flags_
;
1815 // Bit vector to tell if a local symbol is a MIPS16 symbol or not.
1816 // This is only valid after do_count_local_symbol is called.
1817 std::vector
<bool> local_symbol_is_mips16_
;
1819 // Bit vector to tell if a local symbol is a microMIPS symbol or not.
1820 // This is only valid after do_count_local_symbol is called.
1821 std::vector
<bool> local_symbol_is_micromips_
;
1823 // Map from section index to the MIPS16 stub for that section. This contains
1824 // all stubs found in this object.
1825 Mips16_stubs_int_map mips16_stub_sections_
;
1827 // Local symbols that have "non 16-bit" call relocation. This relocation
1828 // would need to refer to a MIPS16 fn stub, if there is one.
1829 std::set
<unsigned int> local_non_16bit_calls_
;
1831 // Local symbols that have 16-bit call relocation R_MIPS16_26. Local MIPS16
1832 // call or call_fp stubs will only be needed if there is some R_MIPS16_26
1833 // relocation that refers to the stub symbol.
1834 std::set
<unsigned int> local_16bit_calls_
;
1836 // Map from local symbol index to the MIPS16 fn stub for that symbol.
1837 // This contains only the stubs that we decided not to discard.
1838 Mips16_stubs_int_map local_mips16_fn_stubs_
;
1840 // Map from local symbol index to the MIPS16 call stub for that symbol.
1841 // This contains only the stubs that we decided not to discard.
1842 Mips16_stubs_int_map local_mips16_call_stubs_
;
1844 // gp value that was used to create this object.
1846 // Whether the object is a PIC object.
1848 // Whether the object uses N32 ABI.
1850 // The Mips_got_info for this object.
1851 Mips_got_info
<size
, big_endian
>* got_info_
;
1853 // Bit vector to tell if a section is a MIPS16 fn stub section or not.
1854 // This is only valid after do_read_symbols is called.
1855 std::vector
<bool> section_is_mips16_fn_stub_
;
1857 // Bit vector to tell if a section is a MIPS16 call stub section or not.
1858 // This is only valid after do_read_symbols is called.
1859 std::vector
<bool> section_is_mips16_call_stub_
;
1861 // Bit vector to tell if a section is a MIPS16 call_fp stub section or not.
1862 // This is only valid after do_read_symbols is called.
1863 std::vector
<bool> section_is_mips16_call_fp_stub_
;
1865 // .pdr section index.
1866 unsigned int pdr_shndx_
;
1868 // gprmask from the .reginfo section of this object.
1870 // cprmask1 from the .reginfo section of this object.
1872 // cprmask2 from the .reginfo section of this object.
1874 // cprmask3 from the .reginfo section of this object.
1876 // cprmask4 from the .reginfo section of this object.
1880 // Mips_output_data_got class.
1882 template<int size
, bool big_endian
>
1883 class Mips_output_data_got
: public Output_data_got
<size
, big_endian
>
1885 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1886 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
1888 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1891 Mips_output_data_got(Target_mips
<size
, big_endian
>* target
,
1892 Symbol_table
* symtab
, Layout
* layout
)
1893 : Output_data_got
<size
, big_endian
>(), target_(target
),
1894 symbol_table_(symtab
), layout_(layout
), static_relocs_(), got_view_(NULL
),
1895 first_global_got_dynsym_index_(-1U), primary_got_(NULL
),
1896 secondary_got_relocs_()
1898 this->master_got_info_
= new Mips_got_info
<size
, big_endian
>();
1899 this->set_addralign(16);
1902 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
1903 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
1905 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
1906 unsigned int symndx
, Mips_address addend
,
1907 unsigned int r_type
, unsigned int shndx
,
1908 bool is_section_symbol
)
1910 this->master_got_info_
->record_local_got_symbol(object
, symndx
, addend
,
1915 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
1916 // in OBJECT. FOR_CALL is true if the caller is only interested in
1917 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
1920 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
1921 Mips_relobj
<size
, big_endian
>* object
,
1922 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
1924 this->master_got_info_
->record_global_got_symbol(mips_sym
, object
, r_type
,
1925 dyn_reloc
, for_call
);
1928 // Record that OBJECT has a page relocation against symbol SYMNDX and
1929 // that ADDEND is the addend for that relocation.
1931 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
1932 unsigned int symndx
, int addend
)
1933 { this->master_got_info_
->record_got_page_entry(object
, symndx
, addend
); }
1935 // Add a static entry for the GOT entry at OFFSET. GSYM is a global
1936 // symbol and R_TYPE is the code of a dynamic relocation that needs to be
1937 // applied in a static link.
1939 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
1940 Mips_symbol
<size
>* gsym
)
1941 { this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, gsym
)); }
1943 // Add a static reloc for the GOT entry at OFFSET. RELOBJ is an object
1944 // defining a local symbol with INDEX. R_TYPE is the code of a dynamic
1945 // relocation that needs to be applied in a static link.
1947 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
1948 Sized_relobj_file
<size
, big_endian
>* relobj
,
1951 this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, relobj
,
1955 // Record that global symbol GSYM has R_TYPE dynamic relocation in the
1956 // secondary GOT at OFFSET.
1958 add_secondary_got_reloc(unsigned int got_offset
, unsigned int r_type
,
1959 Mips_symbol
<size
>* gsym
)
1961 this->secondary_got_relocs_
.push_back(Static_reloc(got_offset
,
1965 // Update GOT entry at OFFSET with VALUE.
1967 update_got_entry(unsigned int offset
, Mips_address value
)
1969 elfcpp::Swap
<size
, big_endian
>::writeval(this->got_view_
+ offset
, value
);
1972 // Return the number of entries in local part of the GOT. This includes
1973 // local entries, page entries and 2 reserved entries.
1975 get_local_gotno() const
1977 if (!this->multi_got())
1979 return (2 + this->master_got_info_
->local_gotno()
1980 + this->master_got_info_
->page_gotno());
1983 return 2 + this->primary_got_
->local_gotno() + this->primary_got_
->page_gotno();
1986 // Return dynamic symbol table index of the first symbol with global GOT
1989 first_global_got_dynsym_index() const
1990 { return this->first_global_got_dynsym_index_
; }
1992 // Set dynamic symbol table index of the first symbol with global GOT entry.
1994 set_first_global_got_dynsym_index(unsigned int index
)
1995 { this->first_global_got_dynsym_index_
= index
; }
1997 // Lay out the GOT. Add local, global and TLS entries. If GOT is
1998 // larger than 64K, create multi-GOT.
2000 lay_out_got(Layout
* layout
, Symbol_table
* symtab
,
2001 const Input_objects
* input_objects
);
2003 // Create multi-GOT. For every GOT, add local, global and TLS entries.
2005 lay_out_multi_got(Layout
* layout
, const Input_objects
* input_objects
);
2007 // Attempt to merge GOTs of different input objects.
2009 merge_gots(const Input_objects
* input_objects
);
2011 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
2012 // this would lead to overflow, true if they were merged successfully.
2014 merge_got_with(Mips_got_info
<size
, big_endian
>* from
,
2015 Mips_relobj
<size
, big_endian
>* object
,
2016 Mips_got_info
<size
, big_endian
>* to
);
2018 // Return the offset of GOT page entry for VALUE. For multi-GOT links,
2019 // use OBJECT's GOT.
2021 get_got_page_offset(Mips_address value
,
2022 const Mips_relobj
<size
, big_endian
>* object
)
2024 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2025 ? this->master_got_info_
2026 : object
->get_got_info());
2027 gold_assert(g
!= NULL
);
2028 return g
->get_got_page_offset(value
, this);
2031 // Return the GOT offset of type GOT_TYPE of the global symbol
2032 // GSYM. For multi-GOT links, use OBJECT's GOT.
2033 unsigned int got_offset(const Symbol
* gsym
, unsigned int got_type
,
2034 Mips_relobj
<size
, big_endian
>* object
) const
2036 if (!this->multi_got())
2037 return gsym
->got_offset(got_type
);
2040 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
2041 gold_assert(g
!= NULL
);
2042 return gsym
->got_offset(g
->multigot_got_type(got_type
));
2046 // Return the GOT offset of type GOT_TYPE of the local symbol
2049 got_offset(unsigned int symndx
, unsigned int got_type
,
2050 Sized_relobj_file
<size
, big_endian
>* object
,
2051 uint64_t addend
) const
2052 { return object
->local_got_offset(symndx
, got_type
, addend
); }
2054 // Return the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2056 tls_ldm_offset(Mips_relobj
<size
, big_endian
>* object
) const
2058 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2059 ? this->master_got_info_
2060 : object
->get_got_info());
2061 gold_assert(g
!= NULL
);
2062 return g
->tls_ldm_offset();
2065 // Set the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2067 set_tls_ldm_offset(unsigned int tls_ldm_offset
,
2068 Mips_relobj
<size
, big_endian
>* object
)
2070 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2071 ? this->master_got_info_
2072 : object
->get_got_info());
2073 gold_assert(g
!= NULL
);
2074 g
->set_tls_ldm_offset(tls_ldm_offset
);
2077 // Return true for multi-GOT links.
2080 { return this->primary_got_
!= NULL
; }
2082 // Return the offset of OBJECT's GOT from the start of .got section.
2084 get_got_offset(const Mips_relobj
<size
, big_endian
>* object
)
2086 if (!this->multi_got())
2090 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
2091 return g
!= NULL
? g
->offset() : 0;
2095 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
2097 add_reloc_only_entries()
2098 { this->master_got_info_
->add_reloc_only_entries(this); }
2100 // Return offset of the primary GOT's entry for global symbol.
2102 get_primary_got_offset(const Mips_symbol
<size
>* sym
) const
2104 gold_assert(sym
->global_got_area() != GGA_NONE
);
2105 return (this->get_local_gotno() + sym
->dynsym_index()
2106 - this->first_global_got_dynsym_index()) * size
/8;
2109 // For the entry at offset GOT_OFFSET, return its offset from the gp.
2110 // Input argument GOT_OFFSET is always global offset from the start of
2111 // .got section, for both single and multi-GOT links.
2112 // For single GOT links, this returns GOT_OFFSET - 0x7FF0. For multi-GOT
2113 // links, the return value is object_got_offset - 0x7FF0, where
2114 // object_got_offset is offset in the OBJECT's GOT.
2116 gp_offset(unsigned int got_offset
,
2117 const Mips_relobj
<size
, big_endian
>* object
) const
2119 return (this->address() + got_offset
2120 - this->target_
->adjusted_gp_value(object
));
2124 // Write out the GOT table.
2126 do_write(Output_file
*);
2130 // This class represent dynamic relocations that need to be applied by
2131 // gold because we are using TLS relocations in a static link.
2135 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2136 Mips_symbol
<size
>* gsym
)
2137 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(true)
2138 { this->u_
.global
.symbol
= gsym
; }
2140 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2141 Sized_relobj_file
<size
, big_endian
>* relobj
, unsigned int index
)
2142 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(false)
2144 this->u_
.local
.relobj
= relobj
;
2145 this->u_
.local
.index
= index
;
2148 // Return the GOT offset.
2151 { return this->got_offset_
; }
2156 { return this->r_type_
; }
2158 // Whether the symbol is global or not.
2160 symbol_is_global() const
2161 { return this->symbol_is_global_
; }
2163 // For a relocation against a global symbol, the global symbol.
2167 gold_assert(this->symbol_is_global_
);
2168 return this->u_
.global
.symbol
;
2171 // For a relocation against a local symbol, the defining object.
2172 Sized_relobj_file
<size
, big_endian
>*
2175 gold_assert(!this->symbol_is_global_
);
2176 return this->u_
.local
.relobj
;
2179 // For a relocation against a local symbol, the local symbol index.
2183 gold_assert(!this->symbol_is_global_
);
2184 return this->u_
.local
.index
;
2188 // GOT offset of the entry to which this relocation is applied.
2189 unsigned int got_offset_
;
2190 // Type of relocation.
2191 unsigned int r_type_
;
2192 // Whether this relocation is against a global symbol.
2193 bool symbol_is_global_
;
2194 // A global or local symbol.
2199 // For a global symbol, the symbol itself.
2200 Mips_symbol
<size
>* symbol
;
2204 // For a local symbol, the object defining object.
2205 Sized_relobj_file
<size
, big_endian
>* relobj
;
2206 // For a local symbol, the symbol index.
2213 Target_mips
<size
, big_endian
>* target_
;
2214 // The symbol table.
2215 Symbol_table
* symbol_table_
;
2218 // Static relocs to be applied to the GOT.
2219 std::vector
<Static_reloc
> static_relocs_
;
2220 // .got section view.
2221 unsigned char* got_view_
;
2222 // The dynamic symbol table index of the first symbol with global GOT entry.
2223 unsigned int first_global_got_dynsym_index_
;
2224 // The master GOT information.
2225 Mips_got_info
<size
, big_endian
>* master_got_info_
;
2226 // The primary GOT information.
2227 Mips_got_info
<size
, big_endian
>* primary_got_
;
2228 // Secondary GOT fixups.
2229 std::vector
<Static_reloc
> secondary_got_relocs_
;
2232 // A class to handle LA25 stubs - non-PIC interface to a PIC function. There are
2233 // two ways of creating these interfaces. The first is to add:
2235 // lui $25,%hi(func)
2237 // addiu $25,$25,%lo(func)
2239 // to a separate trampoline section. The second is to add:
2241 // lui $25,%hi(func)
2242 // addiu $25,$25,%lo(func)
2244 // immediately before a PIC function "func", but only if a function is at the
2245 // beginning of the section, and the section is not too heavily aligned (i.e we
2246 // would need to add no more than 2 nops before the stub.)
2248 // We only create stubs of the first type.
2250 template<int size
, bool big_endian
>
2251 class Mips_output_data_la25_stub
: public Output_section_data
2253 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2256 Mips_output_data_la25_stub()
2257 : Output_section_data(size
== 32 ? 4 : 8), symbols_()
2260 // Create LA25 stub for a symbol.
2262 create_la25_stub(Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
2263 Mips_symbol
<size
>* gsym
);
2265 // Return output address of a stub.
2267 stub_address(const Mips_symbol
<size
>* sym
) const
2269 gold_assert(sym
->has_la25_stub());
2270 return this->address() + sym
->la25_stub_offset();
2275 do_adjust_output_section(Output_section
* os
)
2276 { os
->set_entsize(0); }
2279 // Template for standard LA25 stub.
2280 static const uint32_t la25_stub_entry
[];
2281 // Template for microMIPS LA25 stub.
2282 static const uint32_t la25_stub_micromips_entry
[];
2284 // Set the final size.
2286 set_final_data_size()
2287 { this->set_data_size(this->symbols_
.size() * 16); }
2289 // Create a symbol for SYM stub's value and size, to help make the
2290 // disassembly easier to read.
2292 create_stub_symbol(Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
2293 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
);
2295 // Write to a map file.
2297 do_print_to_mapfile(Mapfile
* mapfile
) const
2298 { mapfile
->print_output_data(this, _(".LA25.stubs")); }
2300 // Write out the LA25 stub section.
2302 do_write(Output_file
*);
2304 // Symbols that have LA25 stubs.
2305 Unordered_set
<Mips_symbol
<size
>*> symbols_
;
2308 // MIPS-specific relocation writer.
2310 template<int sh_type
, bool dynamic
, int size
, bool big_endian
>
2311 struct Mips_output_reloc_writer
;
2313 template<int sh_type
, bool dynamic
, bool big_endian
>
2314 struct Mips_output_reloc_writer
<sh_type
, dynamic
, 32, big_endian
>
2316 typedef Output_reloc
<sh_type
, dynamic
, 32, big_endian
> Output_reloc_type
;
2317 typedef std::vector
<Output_reloc_type
> Relocs
;
2320 write(typename
Relocs::const_iterator p
, unsigned char* pov
)
2324 template<int sh_type
, bool dynamic
, bool big_endian
>
2325 struct Mips_output_reloc_writer
<sh_type
, dynamic
, 64, big_endian
>
2327 typedef Output_reloc
<sh_type
, dynamic
, 64, big_endian
> Output_reloc_type
;
2328 typedef std::vector
<Output_reloc_type
> Relocs
;
2331 write(typename
Relocs::const_iterator p
, unsigned char* pov
)
2333 elfcpp::Mips64_rel_write
<big_endian
> orel(pov
);
2334 orel
.put_r_offset(p
->get_address());
2335 orel
.put_r_sym(p
->get_symbol_index());
2336 orel
.put_r_ssym(RSS_UNDEF
);
2337 orel
.put_r_type(p
->type());
2338 if (p
->type() == elfcpp::R_MIPS_REL32
)
2339 orel
.put_r_type2(elfcpp::R_MIPS_64
);
2341 orel
.put_r_type2(elfcpp::R_MIPS_NONE
);
2342 orel
.put_r_type3(elfcpp::R_MIPS_NONE
);
2346 template<int sh_type
, bool dynamic
, int size
, bool big_endian
>
2347 class Mips_output_data_reloc
: public Output_data_reloc
<sh_type
, dynamic
,
2351 Mips_output_data_reloc(bool sort_relocs
)
2352 : Output_data_reloc
<sh_type
, dynamic
, size
, big_endian
>(sort_relocs
)
2356 // Write out the data.
2358 do_write(Output_file
* of
)
2360 typedef Mips_output_reloc_writer
<sh_type
, dynamic
, size
,
2362 this->template do_write_generic
<Writer
>(of
);
2367 // A class to handle the PLT data.
2369 template<int size
, bool big_endian
>
2370 class Mips_output_data_plt
: public Output_section_data
2372 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2373 typedef Mips_output_data_reloc
<elfcpp::SHT_REL
, true,
2374 size
, big_endian
> Reloc_section
;
2377 // Create the PLT section. The ordinary .got section is an argument,
2378 // since we need to refer to the start.
2379 Mips_output_data_plt(Layout
* layout
, Output_data_space
* got_plt
,
2380 Target_mips
<size
, big_endian
>* target
)
2381 : Output_section_data(size
== 32 ? 4 : 8), got_plt_(got_plt
), symbols_(),
2382 plt_mips_offset_(0), plt_comp_offset_(0), plt_header_size_(0),
2385 this->rel_
= new Reloc_section(false);
2386 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
2387 elfcpp::SHF_ALLOC
, this->rel_
,
2388 ORDER_DYNAMIC_PLT_RELOCS
, false);
2391 // Add an entry to the PLT for a symbol referenced by r_type relocation.
2393 add_entry(Mips_symbol
<size
>* gsym
, unsigned int r_type
);
2395 // Return the .rel.plt section data.
2396 const Reloc_section
*
2398 { return this->rel_
; }
2400 // Return the number of PLT entries.
2403 { return this->symbols_
.size(); }
2405 // Return the offset of the first non-reserved PLT entry.
2407 first_plt_entry_offset() const
2408 { return sizeof(plt0_entry_o32
); }
2410 // Return the size of a PLT entry.
2412 plt_entry_size() const
2413 { return sizeof(plt_entry
); }
2415 // Set final PLT offsets. For each symbol, determine whether standard or
2416 // compressed (MIPS16 or microMIPS) PLT entry is used.
2420 // Return the offset of the first standard PLT entry.
2422 first_mips_plt_offset() const
2423 { return this->plt_header_size_
; }
2425 // Return the offset of the first compressed PLT entry.
2427 first_comp_plt_offset() const
2428 { return this->plt_header_size_
+ this->plt_mips_offset_
; }
2430 // Return whether there are any standard PLT entries.
2432 has_standard_entries() const
2433 { return this->plt_mips_offset_
> 0; }
2435 // Return the output address of standard PLT entry.
2437 mips_entry_address(const Mips_symbol
<size
>* sym
) const
2439 gold_assert (sym
->has_mips_plt_offset());
2440 return (this->address() + this->first_mips_plt_offset()
2441 + sym
->mips_plt_offset());
2444 // Return the output address of compressed (MIPS16 or microMIPS) PLT entry.
2446 comp_entry_address(const Mips_symbol
<size
>* sym
) const
2448 gold_assert (sym
->has_comp_plt_offset());
2449 return (this->address() + this->first_comp_plt_offset()
2450 + sym
->comp_plt_offset());
2455 do_adjust_output_section(Output_section
* os
)
2456 { os
->set_entsize(0); }
2458 // Write to a map file.
2460 do_print_to_mapfile(Mapfile
* mapfile
) const
2461 { mapfile
->print_output_data(this, _(".plt")); }
2464 // Template for the first PLT entry.
2465 static const uint32_t plt0_entry_o32
[];
2466 static const uint32_t plt0_entry_n32
[];
2467 static const uint32_t plt0_entry_n64
[];
2468 static const uint32_t plt0_entry_micromips_o32
[];
2469 static const uint32_t plt0_entry_micromips32_o32
[];
2471 // Template for subsequent PLT entries.
2472 static const uint32_t plt_entry
[];
2473 static const uint32_t plt_entry_mips16_o32
[];
2474 static const uint32_t plt_entry_micromips_o32
[];
2475 static const uint32_t plt_entry_micromips32_o32
[];
2477 // Set the final size.
2479 set_final_data_size()
2481 this->set_data_size(this->plt_header_size_
+ this->plt_mips_offset_
2482 + this->plt_comp_offset_
);
2485 // Write out the PLT data.
2487 do_write(Output_file
*);
2489 // Return whether the plt header contains microMIPS code. For the sake of
2490 // cache alignment always use a standard header whenever any standard entries
2491 // are present even if microMIPS entries are present as well. This also lets
2492 // the microMIPS header rely on the value of $v0 only set by microMIPS
2493 // entries, for a small size reduction.
2495 is_plt_header_compressed() const
2497 gold_assert(this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0);
2498 return this->target_
->is_output_micromips() && this->plt_mips_offset_
== 0;
2501 // Return the size of the PLT header.
2503 get_plt_header_size() const
2505 if (this->target_
->is_output_n64())
2506 return 4 * sizeof(plt0_entry_n64
) / sizeof(plt0_entry_n64
[0]);
2507 else if (this->target_
->is_output_n32())
2508 return 4 * sizeof(plt0_entry_n32
) / sizeof(plt0_entry_n32
[0]);
2509 else if (!this->is_plt_header_compressed())
2510 return 4 * sizeof(plt0_entry_o32
) / sizeof(plt0_entry_o32
[0]);
2511 else if (this->target_
->use_32bit_micromips_instructions())
2512 return (2 * sizeof(plt0_entry_micromips32_o32
)
2513 / sizeof(plt0_entry_micromips32_o32
[0]));
2515 return (2 * sizeof(plt0_entry_micromips_o32
)
2516 / sizeof(plt0_entry_micromips_o32
[0]));
2519 // Return the PLT header entry.
2521 get_plt_header_entry() const
2523 if (this->target_
->is_output_n64())
2524 return plt0_entry_n64
;
2525 else if (this->target_
->is_output_n32())
2526 return plt0_entry_n32
;
2527 else if (!this->is_plt_header_compressed())
2528 return plt0_entry_o32
;
2529 else if (this->target_
->use_32bit_micromips_instructions())
2530 return plt0_entry_micromips32_o32
;
2532 return plt0_entry_micromips_o32
;
2535 // Return the size of the standard PLT entry.
2537 standard_plt_entry_size() const
2538 { return 4 * sizeof(plt_entry
) / sizeof(plt_entry
[0]); }
2540 // Return the size of the compressed PLT entry.
2542 compressed_plt_entry_size() const
2544 gold_assert(!this->target_
->is_output_newabi());
2546 if (!this->target_
->is_output_micromips())
2547 return (2 * sizeof(plt_entry_mips16_o32
)
2548 / sizeof(plt_entry_mips16_o32
[0]));
2549 else if (this->target_
->use_32bit_micromips_instructions())
2550 return (2 * sizeof(plt_entry_micromips32_o32
)
2551 / sizeof(plt_entry_micromips32_o32
[0]));
2553 return (2 * sizeof(plt_entry_micromips_o32
)
2554 / sizeof(plt_entry_micromips_o32
[0]));
2557 // The reloc section.
2558 Reloc_section
* rel_
;
2559 // The .got.plt section.
2560 Output_data_space
* got_plt_
;
2561 // Symbols that have PLT entry.
2562 std::vector
<Mips_symbol
<size
>*> symbols_
;
2563 // The offset of the next standard PLT entry to create.
2564 unsigned int plt_mips_offset_
;
2565 // The offset of the next compressed PLT entry to create.
2566 unsigned int plt_comp_offset_
;
2567 // The size of the PLT header in bytes.
2568 unsigned int plt_header_size_
;
2570 Target_mips
<size
, big_endian
>* target_
;
2573 // A class to handle the .MIPS.stubs data.
2575 template<int size
, bool big_endian
>
2576 class Mips_output_data_mips_stubs
: public Output_section_data
2578 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2581 Mips_output_data_mips_stubs(Target_mips
<size
, big_endian
>* target
)
2582 : Output_section_data(size
== 32 ? 4 : 8), symbols_(), dynsym_count_(-1U),
2583 stub_offsets_are_set_(false), target_(target
)
2586 // Create entry for a symbol.
2588 make_entry(Mips_symbol
<size
>*);
2590 // Remove entry for a symbol.
2592 remove_entry(Mips_symbol
<size
>* gsym
);
2594 // Set stub offsets for symbols. This method expects that the number of
2595 // entries in dynamic symbol table is set.
2597 set_lazy_stub_offsets();
2600 set_needs_dynsym_value();
2602 // Set the number of entries in dynamic symbol table.
2604 set_dynsym_count(unsigned int dynsym_count
)
2605 { this->dynsym_count_
= dynsym_count
; }
2607 // Return maximum size of the stub, ie. the stub size if the dynamic symbol
2608 // count is greater than 0x10000. If the dynamic symbol count is less than
2609 // 0x10000, the stub will be 4 bytes smaller.
2610 // There's no disadvantage from using microMIPS code here, so for the sake of
2611 // pure-microMIPS binaries we prefer it whenever there's any microMIPS code in
2612 // output produced at all. This has a benefit of stubs being shorter by
2613 // 4 bytes each too, unless in the insn32 mode.
2615 stub_max_size() const
2617 if (!this->target_
->is_output_micromips()
2618 || this->target_
->use_32bit_micromips_instructions())
2624 // Return the size of the stub. This method expects that the final dynsym
2629 gold_assert(this->dynsym_count_
!= -1U);
2630 if (this->dynsym_count_
> 0x10000)
2631 return this->stub_max_size();
2633 return this->stub_max_size() - 4;
2636 // Return output address of a stub.
2638 stub_address(const Mips_symbol
<size
>* sym
) const
2640 gold_assert(sym
->has_lazy_stub());
2641 return this->address() + sym
->lazy_stub_offset();
2646 do_adjust_output_section(Output_section
* os
)
2647 { os
->set_entsize(0); }
2649 // Write to a map file.
2651 do_print_to_mapfile(Mapfile
* mapfile
) const
2652 { mapfile
->print_output_data(this, _(".MIPS.stubs")); }
2655 static const uint32_t lazy_stub_normal_1
[];
2656 static const uint32_t lazy_stub_normal_1_n64
[];
2657 static const uint32_t lazy_stub_normal_2
[];
2658 static const uint32_t lazy_stub_normal_2_n64
[];
2659 static const uint32_t lazy_stub_big
[];
2660 static const uint32_t lazy_stub_big_n64
[];
2662 static const uint32_t lazy_stub_micromips_normal_1
[];
2663 static const uint32_t lazy_stub_micromips_normal_1_n64
[];
2664 static const uint32_t lazy_stub_micromips_normal_2
[];
2665 static const uint32_t lazy_stub_micromips_normal_2_n64
[];
2666 static const uint32_t lazy_stub_micromips_big
[];
2667 static const uint32_t lazy_stub_micromips_big_n64
[];
2669 static const uint32_t lazy_stub_micromips32_normal_1
[];
2670 static const uint32_t lazy_stub_micromips32_normal_1_n64
[];
2671 static const uint32_t lazy_stub_micromips32_normal_2
[];
2672 static const uint32_t lazy_stub_micromips32_normal_2_n64
[];
2673 static const uint32_t lazy_stub_micromips32_big
[];
2674 static const uint32_t lazy_stub_micromips32_big_n64
[];
2676 // Set the final size.
2678 set_final_data_size()
2679 { this->set_data_size(this->symbols_
.size() * this->stub_max_size()); }
2681 // Write out the .MIPS.stubs data.
2683 do_write(Output_file
*);
2685 // .MIPS.stubs symbols
2686 Unordered_set
<Mips_symbol
<size
>*> symbols_
;
2687 // Number of entries in dynamic symbol table.
2688 unsigned int dynsym_count_
;
2689 // Whether the stub offsets are set.
2690 bool stub_offsets_are_set_
;
2692 Target_mips
<size
, big_endian
>* target_
;
2695 // This class handles Mips .reginfo output section.
2697 template<int size
, bool big_endian
>
2698 class Mips_output_section_reginfo
: public Output_section
2700 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
2703 Mips_output_section_reginfo(const char* name
, elfcpp::Elf_Word type
,
2704 elfcpp::Elf_Xword flags
,
2705 Target_mips
<size
, big_endian
>* target
)
2706 : Output_section(name
, type
, flags
), target_(target
), gprmask_(0),
2707 cprmask1_(0), cprmask2_(0), cprmask3_(0), cprmask4_(0)
2710 // Downcast a base pointer to a Mips_output_section_reginfo pointer.
2711 static Mips_output_section_reginfo
<size
, big_endian
>*
2712 as_mips_output_section_reginfo(Output_section
* os
)
2713 { return static_cast<Mips_output_section_reginfo
<size
, big_endian
>*>(os
); }
2715 // Set masks of the output .reginfo section.
2717 set_masks(Valtype gprmask
, Valtype cprmask1
, Valtype cprmask2
,
2718 Valtype cprmask3
, Valtype cprmask4
)
2720 this->gprmask_
= gprmask
;
2721 this->cprmask1_
= cprmask1
;
2722 this->cprmask2_
= cprmask2
;
2723 this->cprmask3_
= cprmask3
;
2724 this->cprmask4_
= cprmask4
;
2728 // Set the final data size.
2730 set_final_data_size()
2731 { this->set_data_size(24); }
2733 // Write out reginfo section.
2735 do_write(Output_file
* of
);
2738 Target_mips
<size
, big_endian
>* target_
;
2740 // gprmask of the output .reginfo section.
2742 // cprmask1 of the output .reginfo section.
2744 // cprmask2 of the output .reginfo section.
2746 // cprmask3 of the output .reginfo section.
2748 // cprmask4 of the output .reginfo section.
2752 // The MIPS target has relocation types which default handling of relocatable
2753 // relocation cannot process. So we have to extend the default code.
2755 template<bool big_endian
, typename Classify_reloc
>
2756 class Mips_scan_relocatable_relocs
:
2757 public Default_scan_relocatable_relocs
<Classify_reloc
>
2760 // Return the strategy to use for a local symbol which is a section
2761 // symbol, given the relocation type.
2762 inline Relocatable_relocs::Reloc_strategy
2763 local_section_strategy(unsigned int r_type
, Relobj
* object
)
2765 if (Classify_reloc::sh_type
== elfcpp::SHT_RELA
)
2766 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
2771 case elfcpp::R_MIPS_26
:
2772 return Relocatable_relocs::RELOC_SPECIAL
;
2775 return Default_scan_relocatable_relocs
<Classify_reloc
>::
2776 local_section_strategy(r_type
, object
);
2782 // Mips_copy_relocs class. The only difference from the base class is the
2783 // method emit_mips, which should be called instead of Copy_reloc_entry::emit.
2784 // Mips cannot convert all relocation types to dynamic relocs. If a reloc
2785 // cannot be made dynamic, a COPY reloc is emitted.
2787 template<int sh_type
, int size
, bool big_endian
>
2788 class Mips_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
2792 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_MIPS_COPY
)
2795 // Emit any saved relocations which turn out to be needed. This is
2796 // called after all the relocs have been scanned.
2798 emit_mips(Output_data_reloc
<sh_type
, true, size
, big_endian
>*,
2799 Symbol_table
*, Layout
*, Target_mips
<size
, big_endian
>*);
2802 typedef typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
2805 // Emit this reloc if appropriate. This is called after we have
2806 // scanned all the relocations, so we know whether we emitted a
2807 // COPY relocation for SYM_.
2809 emit_entry(Copy_reloc_entry
& entry
,
2810 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
2811 Symbol_table
* symtab
, Layout
* layout
,
2812 Target_mips
<size
, big_endian
>* target
);
2816 // Return true if the symbol SYM should be considered to resolve local
2817 // to the current module, and false otherwise. The logic is taken from
2818 // GNU ld's method _bfd_elf_symbol_refs_local_p.
2820 symbol_refs_local(const Symbol
* sym
, bool has_dynsym_entry
,
2821 bool local_protected
)
2823 // If it's a local sym, of course we resolve locally.
2827 // STV_HIDDEN or STV_INTERNAL ones must be local.
2828 if (sym
->visibility() == elfcpp::STV_HIDDEN
2829 || sym
->visibility() == elfcpp::STV_INTERNAL
)
2832 // If we don't have a definition in a regular file, then we can't
2833 // resolve locally. The sym is either undefined or dynamic.
2834 if (sym
->source() != Symbol::FROM_OBJECT
|| sym
->object()->is_dynamic()
2835 || sym
->is_undefined())
2838 // Forced local symbols resolve locally.
2839 if (sym
->is_forced_local())
2842 // As do non-dynamic symbols.
2843 if (!has_dynsym_entry
)
2846 // At this point, we know the symbol is defined and dynamic. In an
2847 // executable it must resolve locally, likewise when building symbolic
2848 // shared libraries.
2849 if (parameters
->options().output_is_executable()
2850 || parameters
->options().Bsymbolic())
2853 // Now deal with defined dynamic symbols in shared libraries. Ones
2854 // with default visibility might not resolve locally.
2855 if (sym
->visibility() == elfcpp::STV_DEFAULT
)
2858 // STV_PROTECTED non-function symbols are local.
2859 if (sym
->type() != elfcpp::STT_FUNC
)
2862 // Function pointer equality tests may require that STV_PROTECTED
2863 // symbols be treated as dynamic symbols. If the address of a
2864 // function not defined in an executable is set to that function's
2865 // plt entry in the executable, then the address of the function in
2866 // a shared library must also be the plt entry in the executable.
2867 return local_protected
;
2870 // Return TRUE if references to this symbol always reference the symbol in this
2873 symbol_references_local(const Symbol
* sym
, bool has_dynsym_entry
)
2875 return symbol_refs_local(sym
, has_dynsym_entry
, false);
2878 // Return TRUE if calls to this symbol always call the version in this object.
2880 symbol_calls_local(const Symbol
* sym
, bool has_dynsym_entry
)
2882 return symbol_refs_local(sym
, has_dynsym_entry
, true);
2885 // Compare GOT offsets of two symbols.
2887 template<int size
, bool big_endian
>
2889 got_offset_compare(Symbol
* sym1
, Symbol
* sym2
)
2891 Mips_symbol
<size
>* mips_sym1
= Mips_symbol
<size
>::as_mips_sym(sym1
);
2892 Mips_symbol
<size
>* mips_sym2
= Mips_symbol
<size
>::as_mips_sym(sym2
);
2893 unsigned int area1
= mips_sym1
->global_got_area();
2894 unsigned int area2
= mips_sym2
->global_got_area();
2895 gold_assert(area1
!= GGA_NONE
&& area1
!= GGA_NONE
);
2897 // GGA_NORMAL entries always come before GGA_RELOC_ONLY.
2899 return area1
< area2
;
2901 return mips_sym1
->global_gotoffset() < mips_sym2
->global_gotoffset();
2904 // This method divides dynamic symbols into symbols that have GOT entry, and
2905 // symbols that don't have GOT entry. It also sorts symbols with the GOT entry.
2906 // Mips ABI requires that symbols with the GOT entry must be at the end of
2907 // dynamic symbol table, and the order in dynamic symbol table must match the
2910 template<int size
, bool big_endian
>
2912 reorder_dyn_symbols(std::vector
<Symbol
*>* dyn_symbols
,
2913 std::vector
<Symbol
*>* non_got_symbols
,
2914 std::vector
<Symbol
*>* got_symbols
)
2916 for (std::vector
<Symbol
*>::iterator p
= dyn_symbols
->begin();
2917 p
!= dyn_symbols
->end();
2920 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(*p
);
2921 if (mips_sym
->global_got_area() == GGA_NORMAL
2922 || mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
2923 got_symbols
->push_back(mips_sym
);
2925 non_got_symbols
->push_back(mips_sym
);
2928 std::sort(got_symbols
->begin(), got_symbols
->end(),
2929 got_offset_compare
<size
, big_endian
>);
2932 // Functor class for processing the global symbol table.
2934 template<int size
, bool big_endian
>
2935 class Symbol_visitor_check_symbols
2938 Symbol_visitor_check_symbols(Target_mips
<size
, big_endian
>* target
,
2939 Layout
* layout
, Symbol_table
* symtab
)
2940 : target_(target
), layout_(layout
), symtab_(symtab
)
2944 operator()(Sized_symbol
<size
>* sym
)
2946 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
2947 if (local_pic_function
<size
, big_endian
>(mips_sym
))
2949 // SYM is a function that might need $25 to be valid on entry.
2950 // If we're creating a non-PIC relocatable object, mark SYM as
2951 // being PIC. If we're creating a non-relocatable object with
2952 // non-PIC branches and jumps to SYM, make sure that SYM has an la25
2954 if (parameters
->options().relocatable())
2956 if (!parameters
->options().output_is_position_independent())
2957 mips_sym
->set_pic();
2959 else if (mips_sym
->has_nonpic_branches())
2961 this->target_
->la25_stub_section(layout_
)
2962 ->create_la25_stub(this->symtab_
, this->target_
, mips_sym
);
2968 Target_mips
<size
, big_endian
>* target_
;
2970 Symbol_table
* symtab_
;
2973 // Relocation types, parameterized by SHT_REL vs. SHT_RELA, size,
2974 // and endianness. The relocation format for MIPS-64 is non-standard.
2976 template<int sh_type
, int size
, bool big_endian
>
2977 struct Mips_reloc_types
;
2979 template<bool big_endian
>
2980 struct Mips_reloc_types
<elfcpp::SHT_REL
, 32, big_endian
>
2982 typedef typename
elfcpp::Rel
<32, big_endian
> Reloc
;
2983 typedef typename
elfcpp::Rel_write
<32, big_endian
> Reloc_write
;
2985 static typename
elfcpp::Elf_types
<32>::Elf_Swxword
2986 get_r_addend(const Reloc
*)
2990 set_reloc_addend(Reloc_write
*,
2991 typename
elfcpp::Elf_types
<32>::Elf_Swxword
)
2992 { gold_unreachable(); }
2995 template<bool big_endian
>
2996 struct Mips_reloc_types
<elfcpp::SHT_RELA
, 32, big_endian
>
2998 typedef typename
elfcpp::Rela
<32, big_endian
> Reloc
;
2999 typedef typename
elfcpp::Rela_write
<32, big_endian
> Reloc_write
;
3001 static typename
elfcpp::Elf_types
<32>::Elf_Swxword
3002 get_r_addend(const Reloc
* reloc
)
3003 { return reloc
->get_r_addend(); }
3006 set_reloc_addend(Reloc_write
* p
,
3007 typename
elfcpp::Elf_types
<32>::Elf_Swxword val
)
3008 { p
->put_r_addend(val
); }
3011 template<bool big_endian
>
3012 struct Mips_reloc_types
<elfcpp::SHT_REL
, 64, big_endian
>
3014 typedef typename
elfcpp::Mips64_rel
<big_endian
> Reloc
;
3015 typedef typename
elfcpp::Mips64_rel_write
<big_endian
> Reloc_write
;
3017 static typename
elfcpp::Elf_types
<64>::Elf_Swxword
3018 get_r_addend(const Reloc
*)
3022 set_reloc_addend(Reloc_write
*,
3023 typename
elfcpp::Elf_types
<64>::Elf_Swxword
)
3024 { gold_unreachable(); }
3027 template<bool big_endian
>
3028 struct Mips_reloc_types
<elfcpp::SHT_RELA
, 64, big_endian
>
3030 typedef typename
elfcpp::Mips64_rela
<big_endian
> Reloc
;
3031 typedef typename
elfcpp::Mips64_rela_write
<big_endian
> Reloc_write
;
3033 static typename
elfcpp::Elf_types
<64>::Elf_Swxword
3034 get_r_addend(const Reloc
* reloc
)
3035 { return reloc
->get_r_addend(); }
3038 set_reloc_addend(Reloc_write
* p
,
3039 typename
elfcpp::Elf_types
<64>::Elf_Swxword val
)
3040 { p
->put_r_addend(val
); }
3043 // Forward declaration.
3045 mips_get_size_for_reloc(unsigned int, Relobj
*);
3047 // A class for inquiring about properties of a relocation,
3048 // used while scanning relocs during a relocatable link and
3049 // garbage collection.
3051 template<int sh_type_
, int size
, bool big_endian
>
3052 class Mips_classify_reloc
;
3054 template<int sh_type_
, bool big_endian
>
3055 class Mips_classify_reloc
<sh_type_
, 32, big_endian
> :
3056 public gold::Default_classify_reloc
<sh_type_
, 32, big_endian
>
3059 typedef typename Mips_reloc_types
<sh_type_
, 32, big_endian
>::Reloc
3061 typedef typename Mips_reloc_types
<sh_type_
, 32, big_endian
>::Reloc_write
3064 // Return the symbol referred to by the relocation.
3065 static inline unsigned int
3066 get_r_sym(const Reltype
* reloc
)
3067 { return elfcpp::elf_r_sym
<32>(reloc
->get_r_info()); }
3069 // Return the type of the relocation.
3070 static inline unsigned int
3071 get_r_type(const Reltype
* reloc
)
3072 { return elfcpp::elf_r_type
<32>(reloc
->get_r_info()); }
3074 static inline unsigned int
3075 get_r_type2(const Reltype
*)
3078 static inline unsigned int
3079 get_r_type3(const Reltype
*)
3082 static inline unsigned int
3083 get_r_ssym(const Reltype
*)
3086 // Return the explicit addend of the relocation (return 0 for SHT_REL).
3087 static inline unsigned int
3088 get_r_addend(const Reltype
* reloc
)
3090 if (sh_type_
== elfcpp::SHT_REL
)
3092 return Mips_reloc_types
<sh_type_
, 32, big_endian
>::get_r_addend(reloc
);
3095 // Write the r_info field to a new reloc, using the r_info field from
3096 // the original reloc, replacing the r_sym field with R_SYM.
3098 put_r_info(Reltype_write
* new_reloc
, Reltype
* reloc
, unsigned int r_sym
)
3100 unsigned int r_type
= elfcpp::elf_r_type
<32>(reloc
->get_r_info());
3101 new_reloc
->put_r_info(elfcpp::elf_r_info
<32>(r_sym
, r_type
));
3104 // Write the r_addend field to a new reloc.
3106 put_r_addend(Reltype_write
* to
,
3107 typename
elfcpp::Elf_types
<32>::Elf_Swxword addend
)
3108 { Mips_reloc_types
<sh_type_
, 32, big_endian
>::set_reloc_addend(to
, addend
); }
3110 // Return the size of the addend of the relocation (only used for SHT_REL).
3112 get_size_for_reloc(unsigned int r_type
, Relobj
* obj
)
3113 { return mips_get_size_for_reloc(r_type
, obj
); }
3116 template<int sh_type_
, bool big_endian
>
3117 class Mips_classify_reloc
<sh_type_
, 64, big_endian
> :
3118 public gold::Default_classify_reloc
<sh_type_
, 64, big_endian
>
3121 typedef typename Mips_reloc_types
<sh_type_
, 64, big_endian
>::Reloc
3123 typedef typename Mips_reloc_types
<sh_type_
, 64, big_endian
>::Reloc_write
3126 // Return the symbol referred to by the relocation.
3127 static inline unsigned int
3128 get_r_sym(const Reltype
* reloc
)
3129 { return reloc
->get_r_sym(); }
3131 // Return the r_type of the relocation.
3132 static inline unsigned int
3133 get_r_type(const Reltype
* reloc
)
3134 { return reloc
->get_r_type(); }
3136 // Return the r_type2 of the relocation.
3137 static inline unsigned int
3138 get_r_type2(const Reltype
* reloc
)
3139 { return reloc
->get_r_type2(); }
3141 // Return the r_type3 of the relocation.
3142 static inline unsigned int
3143 get_r_type3(const Reltype
* reloc
)
3144 { return reloc
->get_r_type3(); }
3146 // Return the special symbol of the relocation.
3147 static inline unsigned int
3148 get_r_ssym(const Reltype
* reloc
)
3149 { return reloc
->get_r_ssym(); }
3151 // Return the explicit addend of the relocation (return 0 for SHT_REL).
3152 static inline typename
elfcpp::Elf_types
<64>::Elf_Swxword
3153 get_r_addend(const Reltype
* reloc
)
3155 if (sh_type_
== elfcpp::SHT_REL
)
3157 return Mips_reloc_types
<sh_type_
, 64, big_endian
>::get_r_addend(reloc
);
3160 // Write the r_info field to a new reloc, using the r_info field from
3161 // the original reloc, replacing the r_sym field with R_SYM.
3163 put_r_info(Reltype_write
* new_reloc
, Reltype
* reloc
, unsigned int r_sym
)
3165 new_reloc
->put_r_sym(r_sym
);
3166 new_reloc
->put_r_ssym(reloc
->get_r_ssym());
3167 new_reloc
->put_r_type3(reloc
->get_r_type3());
3168 new_reloc
->put_r_type2(reloc
->get_r_type2());
3169 new_reloc
->put_r_type(reloc
->get_r_type());
3172 // Write the r_addend field to a new reloc.
3174 put_r_addend(Reltype_write
* to
,
3175 typename
elfcpp::Elf_types
<64>::Elf_Swxword addend
)
3176 { Mips_reloc_types
<sh_type_
, 64, big_endian
>::set_reloc_addend(to
, addend
); }
3178 // Return the size of the addend of the relocation (only used for SHT_REL).
3180 get_size_for_reloc(unsigned int r_type
, Relobj
* obj
)
3181 { return mips_get_size_for_reloc(r_type
, obj
); }
3184 template<int size
, bool big_endian
>
3185 class Target_mips
: public Sized_target
<size
, big_endian
>
3187 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
3188 typedef Mips_output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
3190 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
3191 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
3192 typedef typename Mips_reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
3194 typedef typename Mips_reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
3198 Target_mips(const Target::Target_info
* info
= &mips_info
)
3199 : Sized_target
<size
, big_endian
>(info
), got_(NULL
), gp_(NULL
), plt_(NULL
),
3200 got_plt_(NULL
), rel_dyn_(NULL
), copy_relocs_(),
3201 dyn_relocs_(), la25_stub_(NULL
), mips_mach_extensions_(),
3202 mips_stubs_(NULL
), mach_(0), layout_(NULL
), got16_addends_(),
3203 entry_symbol_is_compressed_(false), insn32_(false)
3205 this->add_machine_extensions();
3208 // The offset of $gp from the beginning of the .got section.
3209 static const unsigned int MIPS_GP_OFFSET
= 0x7ff0;
3211 // The maximum size of the GOT for it to be addressable using 16-bit
3212 // offsets from $gp.
3213 static const unsigned int MIPS_GOT_MAX_SIZE
= MIPS_GP_OFFSET
+ 0x7fff;
3215 // Make a new symbol table entry for the Mips target.
3217 make_symbol(const char*, elfcpp::STT
, Object
*, unsigned int, uint64_t)
3218 { return new Mips_symbol
<size
>(); }
3220 // Process the relocations to determine unreferenced sections for
3221 // garbage collection.
3223 gc_process_relocs(Symbol_table
* symtab
,
3225 Sized_relobj_file
<size
, big_endian
>* object
,
3226 unsigned int data_shndx
,
3227 unsigned int sh_type
,
3228 const unsigned char* prelocs
,
3230 Output_section
* output_section
,
3231 bool needs_special_offset_handling
,
3232 size_t local_symbol_count
,
3233 const unsigned char* plocal_symbols
);
3235 // Scan the relocations to look for symbol adjustments.
3237 scan_relocs(Symbol_table
* symtab
,
3239 Sized_relobj_file
<size
, big_endian
>* object
,
3240 unsigned int data_shndx
,
3241 unsigned int sh_type
,
3242 const unsigned char* prelocs
,
3244 Output_section
* output_section
,
3245 bool needs_special_offset_handling
,
3246 size_t local_symbol_count
,
3247 const unsigned char* plocal_symbols
);
3249 // Finalize the sections.
3251 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
3253 // Relocate a section.
3255 relocate_section(const Relocate_info
<size
, big_endian
>*,
3256 unsigned int sh_type
,
3257 const unsigned char* prelocs
,
3259 Output_section
* output_section
,
3260 bool needs_special_offset_handling
,
3261 unsigned char* view
,
3262 Mips_address view_address
,
3263 section_size_type view_size
,
3264 const Reloc_symbol_changes
*);
3266 // Scan the relocs during a relocatable link.
3268 scan_relocatable_relocs(Symbol_table
* symtab
,
3270 Sized_relobj_file
<size
, big_endian
>* object
,
3271 unsigned int data_shndx
,
3272 unsigned int sh_type
,
3273 const unsigned char* prelocs
,
3275 Output_section
* output_section
,
3276 bool needs_special_offset_handling
,
3277 size_t local_symbol_count
,
3278 const unsigned char* plocal_symbols
,
3279 Relocatable_relocs
*);
3281 // Scan the relocs for --emit-relocs.
3283 emit_relocs_scan(Symbol_table
* symtab
,
3285 Sized_relobj_file
<size
, big_endian
>* object
,
3286 unsigned int data_shndx
,
3287 unsigned int sh_type
,
3288 const unsigned char* prelocs
,
3290 Output_section
* output_section
,
3291 bool needs_special_offset_handling
,
3292 size_t local_symbol_count
,
3293 const unsigned char* plocal_syms
,
3294 Relocatable_relocs
* rr
);
3296 // Emit relocations for a section.
3298 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
3299 unsigned int sh_type
,
3300 const unsigned char* prelocs
,
3302 Output_section
* output_section
,
3303 typename
elfcpp::Elf_types
<size
>::Elf_Off
3304 offset_in_output_section
,
3305 unsigned char* view
,
3306 Mips_address view_address
,
3307 section_size_type view_size
,
3308 unsigned char* reloc_view
,
3309 section_size_type reloc_view_size
);
3311 // Perform target-specific processing in a relocatable link. This is
3312 // only used if we use the relocation strategy RELOC_SPECIAL.
3314 relocate_special_relocatable(const Relocate_info
<size
, big_endian
>* relinfo
,
3315 unsigned int sh_type
,
3316 const unsigned char* preloc_in
,
3318 Output_section
* output_section
,
3319 typename
elfcpp::Elf_types
<size
>::Elf_Off
3320 offset_in_output_section
,
3321 unsigned char* view
,
3322 Mips_address view_address
,
3323 section_size_type view_size
,
3324 unsigned char* preloc_out
);
3326 // Return whether SYM is defined by the ABI.
3328 do_is_defined_by_abi(const Symbol
* sym
) const
3330 return ((strcmp(sym
->name(), "__gnu_local_gp") == 0)
3331 || (strcmp(sym
->name(), "_gp_disp") == 0)
3332 || (strcmp(sym
->name(), "___tls_get_addr") == 0));
3335 // Return the number of entries in the GOT.
3337 got_entry_count() const
3339 if (!this->has_got_section())
3341 return this->got_size() / (size
/8);
3344 // Return the number of entries in the PLT.
3346 plt_entry_count() const
3348 if (this->plt_
== NULL
)
3350 return this->plt_
->entry_count();
3353 // Return the offset of the first non-reserved PLT entry.
3355 first_plt_entry_offset() const
3356 { return this->plt_
->first_plt_entry_offset(); }
3358 // Return the size of each PLT entry.
3360 plt_entry_size() const
3361 { return this->plt_
->plt_entry_size(); }
3363 // Get the GOT section, creating it if necessary.
3364 Mips_output_data_got
<size
, big_endian
>*
3365 got_section(Symbol_table
*, Layout
*);
3367 // Get the GOT section.
3368 Mips_output_data_got
<size
, big_endian
>*
3371 gold_assert(this->got_
!= NULL
);
3375 // Get the .MIPS.stubs section, creating it if necessary.
3376 Mips_output_data_mips_stubs
<size
, big_endian
>*
3377 mips_stubs_section(Layout
* layout
);
3379 // Get the .MIPS.stubs section.
3380 Mips_output_data_mips_stubs
<size
, big_endian
>*
3381 mips_stubs_section() const
3383 gold_assert(this->mips_stubs_
!= NULL
);
3384 return this->mips_stubs_
;
3387 // Get the LA25 stub section, creating it if necessary.
3388 Mips_output_data_la25_stub
<size
, big_endian
>*
3389 la25_stub_section(Layout
*);
3391 // Get the LA25 stub section.
3392 Mips_output_data_la25_stub
<size
, big_endian
>*
3395 gold_assert(this->la25_stub_
!= NULL
);
3396 return this->la25_stub_
;
3399 // Get gp value. It has the value of .got + 0x7FF0.
3403 if (this->gp_
!= NULL
)
3404 return this->gp_
->value();
3408 // Get gp value. It has the value of .got + 0x7FF0. Adjust it for
3409 // multi-GOT links so that OBJECT's GOT + 0x7FF0 is returned.
3411 adjusted_gp_value(const Mips_relobj
<size
, big_endian
>* object
)
3413 if (this->gp_
== NULL
)
3416 bool multi_got
= false;
3417 if (this->has_got_section())
3418 multi_got
= this->got_section()->multi_got();
3420 return this->gp_
->value();
3422 return this->gp_
->value() + this->got_section()->get_got_offset(object
);
3425 // Get the dynamic reloc section, creating it if necessary.
3427 rel_dyn_section(Layout
*);
3430 do_has_custom_set_dynsym_indexes() const
3433 // Don't emit input .reginfo sections to output .reginfo.
3435 do_should_include_section(elfcpp::Elf_Word sh_type
) const
3436 { return sh_type
!= elfcpp::SHT_MIPS_REGINFO
; }
3438 // Set the dynamic symbol indexes. INDEX is the index of the first
3439 // global dynamic symbol. Pointers to the symbols are stored into the
3440 // vector SYMS. The names are added to DYNPOOL. This returns an
3441 // updated dynamic symbol index.
3443 do_set_dynsym_indexes(std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
3444 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
3445 Versions
* versions
, Symbol_table
* symtab
) const;
3447 // Remove .MIPS.stubs entry for a symbol.
3449 remove_lazy_stub_entry(Mips_symbol
<size
>* sym
)
3451 if (this->mips_stubs_
!= NULL
)
3452 this->mips_stubs_
->remove_entry(sym
);
3455 // The value to write into got[1] for SVR4 targets, to identify it is
3456 // a GNU object. The dynamic linker can then use got[1] to store the
3459 mips_elf_gnu_got1_mask()
3461 if (this->is_output_n64())
3462 return (uint64_t)1 << 63;
3467 // Whether the output has microMIPS code. This is valid only after
3468 // merge_processor_specific_flags() is called.
3470 is_output_micromips() const
3472 gold_assert(this->are_processor_specific_flags_set());
3473 return elfcpp::is_micromips(this->processor_specific_flags());
3476 // Whether the output uses N32 ABI. This is valid only after
3477 // merge_processor_specific_flags() is called.
3479 is_output_n32() const
3481 gold_assert(this->are_processor_specific_flags_set());
3482 return elfcpp::abi_n32(this->processor_specific_flags());
3485 // Whether the output uses N64 ABI.
3487 is_output_n64() const
3488 { return size
== 64; }
3490 // Whether the output uses NEWABI. This is valid only after
3491 // merge_processor_specific_flags() is called.
3493 is_output_newabi() const
3494 { return this->is_output_n32() || this->is_output_n64(); }
3496 // Whether we can only use 32-bit microMIPS instructions.
3498 use_32bit_micromips_instructions() const
3499 { return this->insn32_
; }
3501 // Return the r_sym field from a relocation.
3503 get_r_sym(const unsigned char* preloc
) const
3505 // Since REL and RELA relocs share the same structure through
3506 // the r_info field, we can just use REL here.
3507 Reltype
rel(preloc
);
3508 return Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
3513 // Return the value to use for a dynamic symbol which requires special
3514 // treatment. This is how we support equality comparisons of function
3515 // pointers across shared library boundaries, as described in the
3516 // processor specific ABI supplement.
3518 do_dynsym_value(const Symbol
* gsym
) const;
3520 // Make an ELF object.
3522 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
3523 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
);
3526 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
3527 const elfcpp::Ehdr
<size
, !big_endian
>&)
3528 { gold_unreachable(); }
3530 // Make an output section.
3532 do_make_output_section(const char* name
, elfcpp::Elf_Word type
,
3533 elfcpp::Elf_Xword flags
)
3535 if (type
== elfcpp::SHT_MIPS_REGINFO
)
3536 return new Mips_output_section_reginfo
<size
, big_endian
>(name
, type
,
3539 return new Output_section(name
, type
, flags
);
3542 // Adjust ELF file header.
3544 do_adjust_elf_header(unsigned char* view
, int len
);
3546 // Get the custom dynamic tag value.
3548 do_dynamic_tag_custom_value(elfcpp::DT
) const;
3550 // Adjust the value written to the dynamic symbol table.
3552 do_adjust_dyn_symbol(const Symbol
* sym
, unsigned char* view
) const
3554 elfcpp::Sym
<size
, big_endian
> isym(view
);
3555 elfcpp::Sym_write
<size
, big_endian
> osym(view
);
3556 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
3558 // Keep dynamic compressed symbols odd. This allows the dynamic linker
3559 // to treat compressed symbols like any other.
3560 Mips_address value
= isym
.get_st_value();
3561 if (mips_sym
->is_mips16() && value
!= 0)
3563 if (!mips_sym
->has_mips16_fn_stub())
3567 // If we have a MIPS16 function with a stub, the dynamic symbol
3568 // must refer to the stub, since only the stub uses the standard
3569 // calling conventions. Stub contains MIPS32 code, so don't add +1
3572 // There is a code which does this in the method
3573 // Target_mips::do_dynsym_value, but that code will only be
3574 // executed if the symbol is from dynobj.
3575 // TODO(sasa): GNU ld also changes the value in non-dynamic symbol
3578 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
3579 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
3580 value
= fn_stub
->output_address();
3581 osym
.put_st_size(fn_stub
->section_size());
3584 osym
.put_st_value(value
);
3585 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(),
3586 mips_sym
->nonvis() - (elfcpp::STO_MIPS16
>> 2)));
3588 else if ((mips_sym
->is_micromips()
3589 // Stubs are always microMIPS if there is any microMIPS code in
3591 || (this->is_output_micromips() && mips_sym
->has_lazy_stub()))
3594 osym
.put_st_value(value
| 1);
3595 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(),
3596 mips_sym
->nonvis() - (elfcpp::STO_MICROMIPS
>> 2)));
3601 // The class which scans relocations.
3609 get_reference_flags(unsigned int r_type
);
3612 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3613 Sized_relobj_file
<size
, big_endian
>* object
,
3614 unsigned int data_shndx
,
3615 Output_section
* output_section
,
3616 const Reltype
& reloc
, unsigned int r_type
,
3617 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3621 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3622 Sized_relobj_file
<size
, big_endian
>* object
,
3623 unsigned int data_shndx
,
3624 Output_section
* output_section
,
3625 const Relatype
& reloc
, unsigned int r_type
,
3626 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3630 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3631 Sized_relobj_file
<size
, big_endian
>* object
,
3632 unsigned int data_shndx
,
3633 Output_section
* output_section
,
3634 const Relatype
* rela
,
3636 unsigned int rel_type
,
3637 unsigned int r_type
,
3638 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3642 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3643 Sized_relobj_file
<size
, big_endian
>* object
,
3644 unsigned int data_shndx
,
3645 Output_section
* output_section
,
3646 const Reltype
& reloc
, unsigned int r_type
,
3650 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3651 Sized_relobj_file
<size
, big_endian
>* object
,
3652 unsigned int data_shndx
,
3653 Output_section
* output_section
,
3654 const Relatype
& reloc
, unsigned int r_type
,
3658 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3659 Sized_relobj_file
<size
, big_endian
>* object
,
3660 unsigned int data_shndx
,
3661 Output_section
* output_section
,
3662 const Relatype
* rela
,
3664 unsigned int rel_type
,
3665 unsigned int r_type
,
3669 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
*,
3671 Sized_relobj_file
<size
, big_endian
>*,
3676 const elfcpp::Sym
<size
, big_endian
>&)
3680 global_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3682 Sized_relobj_file
<size
, big_endian
>*,
3686 unsigned int, Symbol
*)
3690 local_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3692 Sized_relobj_file
<size
, big_endian
>*,
3697 const elfcpp::Sym
<size
, big_endian
>&)
3701 global_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3703 Sized_relobj_file
<size
, big_endian
>*,
3707 unsigned int, Symbol
*)
3711 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
3712 unsigned int r_type
);
3715 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
3716 unsigned int r_type
, Symbol
*);
3719 // The class which implements relocation.
3729 // Return whether a R_MIPS_32/R_MIPS_64 relocation needs to be applied.
3731 should_apply_static_reloc(const Mips_symbol
<size
>* gsym
,
3732 unsigned int r_type
,
3733 Output_section
* output_section
,
3734 Target_mips
* target
);
3736 // Do a relocation. Return false if the caller should not issue
3737 // any warnings about this relocation.
3739 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
3740 Target_mips
*, Output_section
*, size_t, const unsigned char*,
3741 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
3742 unsigned char*, Mips_address
, section_size_type
);
3745 // This POD class holds the dynamic relocations that should be emitted instead
3746 // of R_MIPS_32, R_MIPS_REL32 and R_MIPS_64 relocations. We will emit these
3747 // relocations if it turns out that the symbol does not have static
3752 Dyn_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
3753 Mips_relobj
<size
, big_endian
>* relobj
, unsigned int shndx
,
3754 Output_section
* output_section
, Mips_address r_offset
)
3755 : sym_(sym
), r_type_(r_type
), relobj_(relobj
),
3756 shndx_(shndx
), output_section_(output_section
),
3760 // Emit this reloc if appropriate. This is called after we have
3761 // scanned all the relocations, so we know whether the symbol has
3762 // static relocations.
3764 emit(Reloc_section
* rel_dyn
, Mips_output_data_got
<size
, big_endian
>* got
,
3765 Symbol_table
* symtab
)
3767 if (!this->sym_
->has_static_relocs())
3769 got
->record_global_got_symbol(this->sym_
, this->relobj_
,
3770 this->r_type_
, true, false);
3771 if (!symbol_references_local(this->sym_
,
3772 this->sym_
->should_add_dynsym_entry(symtab
)))
3773 rel_dyn
->add_global(this->sym_
, this->r_type_
,
3774 this->output_section_
, this->relobj_
,
3775 this->shndx_
, this->r_offset_
);
3777 rel_dyn
->add_symbolless_global_addend(this->sym_
, this->r_type_
,
3778 this->output_section_
, this->relobj_
,
3779 this->shndx_
, this->r_offset_
);
3784 Mips_symbol
<size
>* sym_
;
3785 unsigned int r_type_
;
3786 Mips_relobj
<size
, big_endian
>* relobj_
;
3787 unsigned int shndx_
;
3788 Output_section
* output_section_
;
3789 Mips_address r_offset_
;
3792 // Adjust TLS relocation type based on the options and whether this
3793 // is a local symbol.
3794 static tls::Tls_optimization
3795 optimize_tls_reloc(bool is_final
, int r_type
);
3797 // Return whether there is a GOT section.
3799 has_got_section() const
3800 { return this->got_
!= NULL
; }
3802 // Check whether the given ELF header flags describe a 32-bit binary.
3804 mips_32bit_flags(elfcpp::Elf_Word
);
3807 mach_mips3000
= 3000,
3808 mach_mips3900
= 3900,
3809 mach_mips4000
= 4000,
3810 mach_mips4010
= 4010,
3811 mach_mips4100
= 4100,
3812 mach_mips4111
= 4111,
3813 mach_mips4120
= 4120,
3814 mach_mips4300
= 4300,
3815 mach_mips4400
= 4400,
3816 mach_mips4600
= 4600,
3817 mach_mips4650
= 4650,
3818 mach_mips5000
= 5000,
3819 mach_mips5400
= 5400,
3820 mach_mips5500
= 5500,
3821 mach_mips6000
= 6000,
3822 mach_mips7000
= 7000,
3823 mach_mips8000
= 8000,
3824 mach_mips9000
= 9000,
3825 mach_mips10000
= 10000,
3826 mach_mips12000
= 12000,
3827 mach_mips14000
= 14000,
3828 mach_mips16000
= 16000,
3831 mach_mips_loongson_2e
= 3001,
3832 mach_mips_loongson_2f
= 3002,
3833 mach_mips_loongson_3a
= 3003,
3834 mach_mips_sb1
= 12310201, // octal 'SB', 01
3835 mach_mips_octeon
= 6501,
3836 mach_mips_octeonp
= 6601,
3837 mach_mips_octeon2
= 6502,
3838 mach_mips_xlr
= 887682, // decimal 'XLR'
3839 mach_mipsisa32
= 32,
3840 mach_mipsisa32r2
= 33,
3841 mach_mipsisa64
= 64,
3842 mach_mipsisa64r2
= 65,
3843 mach_mips_micromips
= 96
3846 // Return the MACH for a MIPS e_flags value.
3848 elf_mips_mach(elfcpp::Elf_Word
);
3850 // Check whether machine EXTENSION is an extension of machine BASE.
3852 mips_mach_extends(unsigned int, unsigned int);
3854 // Merge processor specific flags.
3856 merge_processor_specific_flags(const std::string
&, elfcpp::Elf_Word
, bool);
3858 // True if we are linking for CPUs that are faster if JAL is converted to BAL.
3863 // True if we are linking for CPUs that are faster if JALR is converted to
3864 // BAL. This should be safe for all architectures. We enable this predicate
3870 // True if we are linking for CPUs that are faster if JR is converted to B.
3871 // This should be safe for all architectures. We enable this predicate for
3877 // Return the size of the GOT section.
3881 gold_assert(this->got_
!= NULL
);
3882 return this->got_
->data_size();
3885 // Create a PLT entry for a global symbol referenced by r_type relocation.
3887 make_plt_entry(Symbol_table
*, Layout
*, Mips_symbol
<size
>*,
3888 unsigned int r_type
);
3890 // Get the PLT section.
3891 Mips_output_data_plt
<size
, big_endian
>*
3894 gold_assert(this->plt_
!= NULL
);
3898 // Get the GOT PLT section.
3899 const Mips_output_data_plt
<size
, big_endian
>*
3900 got_plt_section() const
3902 gold_assert(this->got_plt_
!= NULL
);
3903 return this->got_plt_
;
3906 // Copy a relocation against a global symbol.
3908 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
3909 Sized_relobj_file
<size
, big_endian
>* object
,
3910 unsigned int shndx
, Output_section
* output_section
,
3911 Symbol
* sym
, unsigned int r_type
, Mips_address r_offset
)
3913 this->copy_relocs_
.copy_reloc(symtab
, layout
,
3914 symtab
->get_sized_symbol
<size
>(sym
),
3915 object
, shndx
, output_section
,
3916 r_type
, r_offset
, 0,
3917 this->rel_dyn_section(layout
));
3921 dynamic_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
3922 Mips_relobj
<size
, big_endian
>* relobj
,
3923 unsigned int shndx
, Output_section
* output_section
,
3924 Mips_address r_offset
)
3926 this->dyn_relocs_
.push_back(Dyn_reloc(sym
, r_type
, relobj
, shndx
,
3927 output_section
, r_offset
));
3930 // Calculate value of _gp symbol.
3932 set_gp(Layout
*, Symbol_table
*);
3935 elf_mips_abi_name(elfcpp::Elf_Word e_flags
);
3937 elf_mips_mach_name(elfcpp::Elf_Word e_flags
);
3939 // Adds entries that describe how machines relate to one another. The entries
3940 // are ordered topologically with MIPS I extensions listed last. First
3941 // element is extension, second element is base.
3943 add_machine_extensions()
3945 // MIPS64r2 extensions.
3946 this->add_extension(mach_mips_octeon2
, mach_mips_octeonp
);
3947 this->add_extension(mach_mips_octeonp
, mach_mips_octeon
);
3948 this->add_extension(mach_mips_octeon
, mach_mipsisa64r2
);
3950 // MIPS64 extensions.
3951 this->add_extension(mach_mipsisa64r2
, mach_mipsisa64
);
3952 this->add_extension(mach_mips_sb1
, mach_mipsisa64
);
3953 this->add_extension(mach_mips_xlr
, mach_mipsisa64
);
3954 this->add_extension(mach_mips_loongson_3a
, mach_mipsisa64
);
3956 // MIPS V extensions.
3957 this->add_extension(mach_mipsisa64
, mach_mips5
);
3959 // R10000 extensions.
3960 this->add_extension(mach_mips12000
, mach_mips10000
);
3961 this->add_extension(mach_mips14000
, mach_mips10000
);
3962 this->add_extension(mach_mips16000
, mach_mips10000
);
3964 // R5000 extensions. Note: the vr5500 ISA is an extension of the core
3965 // vr5400 ISA, but doesn't include the multimedia stuff. It seems
3966 // better to allow vr5400 and vr5500 code to be merged anyway, since
3967 // many libraries will just use the core ISA. Perhaps we could add
3968 // some sort of ASE flag if this ever proves a problem.
3969 this->add_extension(mach_mips5500
, mach_mips5400
);
3970 this->add_extension(mach_mips5400
, mach_mips5000
);
3972 // MIPS IV extensions.
3973 this->add_extension(mach_mips5
, mach_mips8000
);
3974 this->add_extension(mach_mips10000
, mach_mips8000
);
3975 this->add_extension(mach_mips5000
, mach_mips8000
);
3976 this->add_extension(mach_mips7000
, mach_mips8000
);
3977 this->add_extension(mach_mips9000
, mach_mips8000
);
3979 // VR4100 extensions.
3980 this->add_extension(mach_mips4120
, mach_mips4100
);
3981 this->add_extension(mach_mips4111
, mach_mips4100
);
3983 // MIPS III extensions.
3984 this->add_extension(mach_mips_loongson_2e
, mach_mips4000
);
3985 this->add_extension(mach_mips_loongson_2f
, mach_mips4000
);
3986 this->add_extension(mach_mips8000
, mach_mips4000
);
3987 this->add_extension(mach_mips4650
, mach_mips4000
);
3988 this->add_extension(mach_mips4600
, mach_mips4000
);
3989 this->add_extension(mach_mips4400
, mach_mips4000
);
3990 this->add_extension(mach_mips4300
, mach_mips4000
);
3991 this->add_extension(mach_mips4100
, mach_mips4000
);
3992 this->add_extension(mach_mips4010
, mach_mips4000
);
3994 // MIPS32 extensions.
3995 this->add_extension(mach_mipsisa32r2
, mach_mipsisa32
);
3997 // MIPS II extensions.
3998 this->add_extension(mach_mips4000
, mach_mips6000
);
3999 this->add_extension(mach_mipsisa32
, mach_mips6000
);
4001 // MIPS I extensions.
4002 this->add_extension(mach_mips6000
, mach_mips3000
);
4003 this->add_extension(mach_mips3900
, mach_mips3000
);
4006 // Add value to MIPS extenstions.
4008 add_extension(unsigned int base
, unsigned int extension
)
4010 std::pair
<unsigned int, unsigned int> ext(base
, extension
);
4011 this->mips_mach_extensions_
.push_back(ext
);
4014 // Return the number of entries in the .dynsym section.
4015 unsigned int get_dt_mips_symtabno() const
4017 return ((unsigned int)(this->layout_
->dynsym_section()->data_size()
4018 / elfcpp::Elf_sizes
<size
>::sym_size
));
4019 // TODO(sasa): Entry size is MIPS_ELF_SYM_SIZE.
4022 // Information about this specific target which we pass to the
4023 // general Target structure.
4024 static const Target::Target_info mips_info
;
4026 Mips_output_data_got
<size
, big_endian
>* got_
;
4027 // gp symbol. It has the value of .got + 0x7FF0.
4028 Sized_symbol
<size
>* gp_
;
4030 Mips_output_data_plt
<size
, big_endian
>* plt_
;
4031 // The GOT PLT section.
4032 Output_data_space
* got_plt_
;
4033 // The dynamic reloc section.
4034 Reloc_section
* rel_dyn_
;
4035 // Relocs saved to avoid a COPY reloc.
4036 Mips_copy_relocs
<elfcpp::SHT_REL
, size
, big_endian
> copy_relocs_
;
4038 // A list of dyn relocs to be saved.
4039 std::vector
<Dyn_reloc
> dyn_relocs_
;
4041 // The LA25 stub section.
4042 Mips_output_data_la25_stub
<size
, big_endian
>* la25_stub_
;
4043 // Architecture extensions.
4044 std::vector
<std::pair
<unsigned int, unsigned int> > mips_mach_extensions_
;
4046 Mips_output_data_mips_stubs
<size
, big_endian
>* mips_stubs_
;
4051 typename
std::list
<got16_addend
<size
, big_endian
> > got16_addends_
;
4053 // Whether the entry symbol is mips16 or micromips.
4054 bool entry_symbol_is_compressed_
;
4056 // Whether we can use only 32-bit microMIPS instructions.
4057 // TODO(sasa): This should be a linker option.
4061 // Helper structure for R_MIPS*_HI16/LO16 and R_MIPS*_GOT16/LO16 relocations.
4062 // It records high part of the relocation pair.
4064 template<int size
, bool big_endian
>
4067 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
4069 reloc_high(unsigned char* _view
, const Mips_relobj
<size
, big_endian
>* _object
,
4070 const Symbol_value
<size
>* _psymval
, Mips_address _addend
,
4071 unsigned int _r_type
, unsigned int _r_sym
, bool _extract_addend
,
4072 Mips_address _address
= 0, bool _gp_disp
= false)
4073 : view(_view
), object(_object
), psymval(_psymval
), addend(_addend
),
4074 r_type(_r_type
), r_sym(_r_sym
), extract_addend(_extract_addend
),
4075 address(_address
), gp_disp(_gp_disp
)
4078 unsigned char* view
;
4079 const Mips_relobj
<size
, big_endian
>* object
;
4080 const Symbol_value
<size
>* psymval
;
4081 Mips_address addend
;
4082 unsigned int r_type
;
4084 bool extract_addend
;
4085 Mips_address address
;
4089 template<int size
, bool big_endian
>
4090 class Mips_relocate_functions
: public Relocate_functions
<size
, big_endian
>
4092 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
4093 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
4094 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype16
;
4095 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
4096 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype64
;
4101 STATUS_OKAY
, // No error during relocation.
4102 STATUS_OVERFLOW
, // Relocation overflow.
4103 STATUS_BAD_RELOC
// Relocation cannot be applied.
4107 typedef Relocate_functions
<size
, big_endian
> Base
;
4108 typedef Mips_relocate_functions
<size
, big_endian
> This
;
4110 static typename
std::list
<reloc_high
<size
, big_endian
> > hi16_relocs
;
4111 static typename
std::list
<reloc_high
<size
, big_endian
> > got16_relocs
;
4113 template<int valsize
>
4114 static inline typename
This::Status
4115 check_overflow(Valtype value
)
4118 return (Bits
<valsize
>::has_overflow32(value
)
4119 ? This::STATUS_OVERFLOW
4120 : This::STATUS_OKAY
);
4122 return (Bits
<valsize
>::has_overflow(value
)
4123 ? This::STATUS_OVERFLOW
4124 : This::STATUS_OKAY
);
4128 should_shuffle_micromips_reloc(unsigned int r_type
)
4130 return (micromips_reloc(r_type
)
4131 && r_type
!= elfcpp::R_MICROMIPS_PC7_S1
4132 && r_type
!= elfcpp::R_MICROMIPS_PC10_S1
);
4136 // R_MIPS16_26 is used for the mips16 jal and jalx instructions.
4137 // Most mips16 instructions are 16 bits, but these instructions
4140 // The format of these instructions is:
4142 // +--------------+--------------------------------+
4143 // | JALX | X| Imm 20:16 | Imm 25:21 |
4144 // +--------------+--------------------------------+
4145 // | Immediate 15:0 |
4146 // +-----------------------------------------------+
4148 // JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
4149 // Note that the immediate value in the first word is swapped.
4151 // When producing a relocatable object file, R_MIPS16_26 is
4152 // handled mostly like R_MIPS_26. In particular, the addend is
4153 // stored as a straight 26-bit value in a 32-bit instruction.
4154 // (gas makes life simpler for itself by never adjusting a
4155 // R_MIPS16_26 reloc to be against a section, so the addend is
4156 // always zero). However, the 32 bit instruction is stored as 2
4157 // 16-bit values, rather than a single 32-bit value. In a
4158 // big-endian file, the result is the same; in a little-endian
4159 // file, the two 16-bit halves of the 32 bit value are swapped.
4160 // This is so that a disassembler can recognize the jal
4163 // When doing a final link, R_MIPS16_26 is treated as a 32 bit
4164 // instruction stored as two 16-bit values. The addend A is the
4165 // contents of the targ26 field. The calculation is the same as
4166 // R_MIPS_26. When storing the calculated value, reorder the
4167 // immediate value as shown above, and don't forget to store the
4168 // value as two 16-bit values.
4170 // To put it in MIPS ABI terms, the relocation field is T-targ26-16,
4174 // +--------+----------------------+
4178 // +--------+----------------------+
4181 // +----------+------+-------------+
4183 // | sub1 | | sub2 |
4184 // |0 9|10 15|16 31|
4185 // +----------+--------------------+
4186 // where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
4187 // ((sub1 << 16) | sub2)).
4189 // When producing a relocatable object file, the calculation is
4190 // (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
4191 // When producing a fully linked file, the calculation is
4192 // let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
4193 // ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
4195 // The table below lists the other MIPS16 instruction relocations.
4196 // Each one is calculated in the same way as the non-MIPS16 relocation
4197 // given on the right, but using the extended MIPS16 layout of 16-bit
4198 // immediate fields:
4200 // R_MIPS16_GPREL R_MIPS_GPREL16
4201 // R_MIPS16_GOT16 R_MIPS_GOT16
4202 // R_MIPS16_CALL16 R_MIPS_CALL16
4203 // R_MIPS16_HI16 R_MIPS_HI16
4204 // R_MIPS16_LO16 R_MIPS_LO16
4206 // A typical instruction will have a format like this:
4208 // +--------------+--------------------------------+
4209 // | EXTEND | Imm 10:5 | Imm 15:11 |
4210 // +--------------+--------------------------------+
4211 // | Major | rx | ry | Imm 4:0 |
4212 // +--------------+--------------------------------+
4214 // EXTEND is the five bit value 11110. Major is the instruction
4217 // All we need to do here is shuffle the bits appropriately.
4218 // As above, the two 16-bit halves must be swapped on a
4219 // little-endian system.
4221 // Similar to MIPS16, the two 16-bit halves in microMIPS must be swapped
4222 // on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1
4223 // and R_MICROMIPS_PC10_S1 relocs that apply to 16-bit instructions.
4226 mips_reloc_unshuffle(unsigned char* view
, unsigned int r_type
,
4229 if (!mips16_reloc(r_type
)
4230 && !should_shuffle_micromips_reloc(r_type
))
4233 // Pick up the first and second halfwords of the instruction.
4234 Valtype16 first
= elfcpp::Swap
<16, big_endian
>::readval(view
);
4235 Valtype16 second
= elfcpp::Swap
<16, big_endian
>::readval(view
+ 2);
4238 if (micromips_reloc(r_type
)
4239 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
4240 val
= first
<< 16 | second
;
4241 else if (r_type
!= elfcpp::R_MIPS16_26
)
4242 val
= (((first
& 0xf800) << 16) | ((second
& 0xffe0) << 11)
4243 | ((first
& 0x1f) << 11) | (first
& 0x7e0) | (second
& 0x1f));
4245 val
= (((first
& 0xfc00) << 16) | ((first
& 0x3e0) << 11)
4246 | ((first
& 0x1f) << 21) | second
);
4248 elfcpp::Swap
<32, big_endian
>::writeval(view
, val
);
4252 mips_reloc_shuffle(unsigned char* view
, unsigned int r_type
, bool jal_shuffle
)
4254 if (!mips16_reloc(r_type
)
4255 && !should_shuffle_micromips_reloc(r_type
))
4258 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4259 Valtype16 first
, second
;
4261 if (micromips_reloc(r_type
)
4262 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
4264 second
= val
& 0xffff;
4267 else if (r_type
!= elfcpp::R_MIPS16_26
)
4269 second
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
4270 first
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
4274 second
= val
& 0xffff;
4275 first
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
4276 | ((val
>> 21) & 0x1f);
4279 elfcpp::Swap
<16, big_endian
>::writeval(view
+ 2, second
);
4280 elfcpp::Swap
<16, big_endian
>::writeval(view
, first
);
4283 // R_MIPS_16: S + sign-extend(A)
4284 static inline typename
This::Status
4285 rel16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4286 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4287 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
4289 Valtype16
* wv
= reinterpret_cast<Valtype16
*>(view
);
4290 Valtype16 val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
4292 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
)
4295 Valtype x
= psymval
->value(object
, addend
);
4296 val
= Bits
<16>::bit_select32(val
, x
, 0xffffU
);
4300 *calculated_value
= x
;
4301 return This::STATUS_OKAY
;
4304 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
4306 return check_overflow
<16>(x
);
4310 static inline typename
This::Status
4311 rel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4312 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4313 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
4315 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4316 Valtype addend
= (extract_addend
4317 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
4319 Valtype x
= psymval
->value(object
, addend
);
4322 *calculated_value
= x
;
4324 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4326 return This::STATUS_OKAY
;
4329 // R_MIPS_JALR, R_MICROMIPS_JALR
4330 static inline typename
This::Status
4331 reljalr(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4332 const Symbol_value
<size
>* psymval
, Mips_address address
,
4333 Mips_address addend_a
, bool extract_addend
, bool cross_mode_jump
,
4334 unsigned int r_type
, bool jalr_to_bal
, bool jr_to_b
,
4335 bool calculate_only
, Valtype
* calculated_value
)
4337 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4338 Valtype addend
= extract_addend
? 0 : addend_a
;
4339 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4341 // Try converting J(AL)R to B(AL), if the target is in range.
4342 if (!parameters
->options().relocatable()
4343 && r_type
== elfcpp::R_MIPS_JALR
4345 && ((jalr_to_bal
&& val
== 0x0320f809) // jalr t9
4346 || (jr_to_b
&& val
== 0x03200008))) // jr t9
4348 int offset
= psymval
->value(object
, addend
) - (address
+ 4);
4349 if (!Bits
<18>::has_overflow32(offset
))
4351 if (val
== 0x03200008) // jr t9
4352 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4354 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4359 *calculated_value
= val
;
4361 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4363 return This::STATUS_OKAY
;
4366 // R_MIPS_PC32: S + A - P
4367 static inline typename
This::Status
4368 relpc32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4369 const Symbol_value
<size
>* psymval
, Mips_address address
,
4370 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4371 Valtype
* calculated_value
)
4373 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4374 Valtype addend
= (extract_addend
4375 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
4377 Valtype x
= psymval
->value(object
, addend
) - address
;
4380 *calculated_value
= x
;
4382 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4384 return This::STATUS_OKAY
;
4387 // R_MIPS_26, R_MIPS16_26, R_MICROMIPS_26_S1
4388 static inline typename
This::Status
4389 rel26(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4390 const Symbol_value
<size
>* psymval
, Mips_address address
,
4391 bool local
, Mips_address addend_a
, bool extract_addend
,
4392 const Symbol
* gsym
, bool cross_mode_jump
, unsigned int r_type
,
4393 bool jal_to_bal
, bool calculate_only
, Valtype
* calculated_value
)
4395 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4396 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4401 if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4402 addend
= (val
& 0x03ffffff) << 1;
4404 addend
= (val
& 0x03ffffff) << 2;
4409 // Make sure the target of JALX is word-aligned. Bit 0 must be
4410 // the correct ISA mode selector and bit 1 must be 0.
4411 if (!calculate_only
&& cross_mode_jump
4412 && (psymval
->value(object
, 0) & 3) != (r_type
== elfcpp::R_MIPS_26
))
4414 gold_warning(_("JALX to a non-word-aligned address"));
4415 return This::STATUS_BAD_RELOC
;
4418 // Shift is 2, unusually, for microMIPS JALX.
4419 unsigned int shift
=
4420 (!cross_mode_jump
&& r_type
== elfcpp::R_MICROMIPS_26_S1
) ? 1 : 2;
4424 x
= addend
| ((address
+ 4) & (0xfc000000 << shift
));
4428 x
= Bits
<27>::sign_extend32(addend
);
4430 x
= Bits
<28>::sign_extend32(addend
);
4432 x
= psymval
->value(object
, x
) >> shift
;
4434 if (!calculate_only
&& !local
&& !gsym
->is_weak_undefined())
4436 if ((x
>> 26) != ((address
+ 4) >> (26 + shift
)))
4438 gold_error(_("relocation truncated to fit: %u against '%s'"),
4439 r_type
, gsym
->name());
4440 return This::STATUS_OVERFLOW
;
4444 val
= Bits
<32>::bit_select32(val
, x
, 0x03ffffff);
4446 // If required, turn JAL into JALX.
4447 if (cross_mode_jump
)
4450 Valtype32 opcode
= val
>> 26;
4451 Valtype32 jalx_opcode
;
4453 // Check to see if the opcode is already JAL or JALX.
4454 if (r_type
== elfcpp::R_MIPS16_26
)
4456 ok
= (opcode
== 0x6) || (opcode
== 0x7);
4459 else if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4461 ok
= (opcode
== 0x3d) || (opcode
== 0x3c);
4466 ok
= (opcode
== 0x3) || (opcode
== 0x1d);
4470 // If the opcode is not JAL or JALX, there's a problem. We cannot
4471 // convert J or JALS to JALX.
4472 if (!calculate_only
&& !ok
)
4474 gold_error(_("Unsupported jump between ISA modes; consider "
4475 "recompiling with interlinking enabled."));
4476 return This::STATUS_BAD_RELOC
;
4479 // Make this the JALX opcode.
4480 val
= (val
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
4483 // Try converting JAL to BAL, if the target is in range.
4484 if (!parameters
->options().relocatable()
4487 && r_type
== elfcpp::R_MIPS_26
4488 && (val
>> 26) == 0x3))) // jal addr
4490 Valtype32 dest
= (x
<< 2) | (((address
+ 4) >> 28) << 28);
4491 int offset
= dest
- (address
+ 4);
4492 if (!Bits
<18>::has_overflow32(offset
))
4494 if (val
== 0x03200008) // jr t9
4495 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4497 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4502 *calculated_value
= val
;
4504 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4506 return This::STATUS_OKAY
;
4510 static inline typename
This::Status
4511 relpc16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4512 const Symbol_value
<size
>* psymval
, Mips_address address
,
4513 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4514 Valtype
* calculated_value
)
4516 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4517 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4519 Valtype addend
= (extract_addend
4520 ? Bits
<18>::sign_extend32((val
& 0xffff) << 2)
4523 Valtype x
= psymval
->value(object
, addend
) - address
;
4524 val
= Bits
<16>::bit_select32(val
, x
>> 2, 0xffff);
4528 *calculated_value
= x
>> 2;
4529 return This::STATUS_OKAY
;
4532 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4534 return check_overflow
<18>(x
);
4537 // R_MICROMIPS_PC7_S1
4538 static inline typename
This::Status
4539 relmicromips_pc7_s1(unsigned char* view
,
4540 const Mips_relobj
<size
, big_endian
>* object
,
4541 const Symbol_value
<size
>* psymval
, Mips_address address
,
4542 Mips_address addend_a
, bool extract_addend
,
4543 bool calculate_only
, Valtype
* calculated_value
)
4545 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4546 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4548 Valtype addend
= extract_addend
? Bits
<8>::sign_extend32((val
& 0x7f) << 1)
4551 Valtype x
= psymval
->value(object
, addend
) - address
;
4552 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x7f);
4556 *calculated_value
= x
>> 1;
4557 return This::STATUS_OKAY
;
4560 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4562 return check_overflow
<8>(x
);
4565 // R_MICROMIPS_PC10_S1
4566 static inline typename
This::Status
4567 relmicromips_pc10_s1(unsigned char* view
,
4568 const Mips_relobj
<size
, big_endian
>* object
,
4569 const Symbol_value
<size
>* psymval
, Mips_address address
,
4570 Mips_address addend_a
, bool extract_addend
,
4571 bool calculate_only
, Valtype
* calculated_value
)
4573 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4574 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4576 Valtype addend
= (extract_addend
4577 ? Bits
<11>::sign_extend32((val
& 0x3ff) << 1)
4580 Valtype x
= psymval
->value(object
, addend
) - address
;
4581 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x3ff);
4585 *calculated_value
= x
>> 1;
4586 return This::STATUS_OKAY
;
4589 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4591 return check_overflow
<11>(x
);
4594 // R_MICROMIPS_PC16_S1
4595 static inline typename
This::Status
4596 relmicromips_pc16_s1(unsigned char* view
,
4597 const Mips_relobj
<size
, big_endian
>* object
,
4598 const Symbol_value
<size
>* psymval
, Mips_address address
,
4599 Mips_address addend_a
, bool extract_addend
,
4600 bool calculate_only
, Valtype
* calculated_value
)
4602 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4603 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4605 Valtype addend
= (extract_addend
4606 ? Bits
<17>::sign_extend32((val
& 0xffff) << 1)
4609 Valtype x
= psymval
->value(object
, addend
) - address
;
4610 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0xffff);
4614 *calculated_value
= x
>> 1;
4615 return This::STATUS_OKAY
;
4618 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4620 return check_overflow
<17>(x
);
4623 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
4624 static inline typename
This::Status
4625 relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4626 const Symbol_value
<size
>* psymval
, Mips_address addend
,
4627 Mips_address address
, bool gp_disp
, unsigned int r_type
,
4628 unsigned int r_sym
, bool extract_addend
)
4630 // Record the relocation. It will be resolved when we find lo16 part.
4631 hi16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
4632 addend
, r_type
, r_sym
, extract_addend
, address
,
4634 return This::STATUS_OKAY
;
4637 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
4638 static inline typename
This::Status
4639 do_relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4640 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
4641 Mips_address address
, bool is_gp_disp
, unsigned int r_type
,
4642 bool extract_addend
, Valtype32 addend_lo
,
4643 Target_mips
<size
, big_endian
>* target
, bool calculate_only
,
4644 Valtype
* calculated_value
)
4646 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4647 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4649 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
4654 value
= psymval
->value(object
, addend
);
4657 // For MIPS16 ABI code we generate this sequence
4658 // 0: li $v0,%hi(_gp_disp)
4659 // 4: addiupc $v1,%lo(_gp_disp)
4663 // So the offsets of hi and lo relocs are the same, but the
4664 // base $pc is that used by the ADDIUPC instruction at $t9 + 4.
4665 // ADDIUPC clears the low two bits of the instruction address,
4666 // so the base is ($t9 + 4) & ~3.
4668 if (r_type
== elfcpp::R_MIPS16_HI16
)
4669 gp_disp
= (target
->adjusted_gp_value(object
)
4670 - ((address
+ 4) & ~0x3));
4671 // The microMIPS .cpload sequence uses the same assembly
4672 // instructions as the traditional psABI version, but the
4673 // incoming $t9 has the low bit set.
4674 else if (r_type
== elfcpp::R_MICROMIPS_HI16
)
4675 gp_disp
= target
->adjusted_gp_value(object
) - address
- 1;
4677 gp_disp
= target
->adjusted_gp_value(object
) - address
;
4678 value
= gp_disp
+ addend
;
4680 Valtype x
= ((value
+ 0x8000) >> 16) & 0xffff;
4681 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4685 *calculated_value
= x
;
4686 return This::STATUS_OKAY
;
4689 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4691 return (is_gp_disp
? check_overflow
<16>(x
)
4692 : This::STATUS_OKAY
);
4695 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4696 static inline typename
This::Status
4697 relgot16_local(unsigned char* view
,
4698 const Mips_relobj
<size
, big_endian
>* object
,
4699 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4700 bool extract_addend
, unsigned int r_type
, unsigned int r_sym
)
4702 // Record the relocation. It will be resolved when we find lo16 part.
4703 got16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
4704 addend_a
, r_type
, r_sym
, extract_addend
));
4705 return This::STATUS_OKAY
;
4708 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4709 static inline typename
This::Status
4710 do_relgot16_local(unsigned char* view
,
4711 const Mips_relobj
<size
, big_endian
>* object
,
4712 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
4713 bool extract_addend
, Valtype32 addend_lo
,
4714 Target_mips
<size
, big_endian
>* target
, bool calculate_only
,
4715 Valtype
* calculated_value
)
4717 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4718 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4720 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
4723 // Find GOT page entry.
4724 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000) >> 16)
4727 unsigned int got_offset
=
4728 target
->got_section()->get_got_page_offset(value
, object
);
4730 // Resolve the relocation.
4731 Valtype x
= target
->got_section()->gp_offset(got_offset
, object
);
4732 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4736 *calculated_value
= x
;
4737 return This::STATUS_OKAY
;
4740 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4742 return check_overflow
<16>(x
);
4745 // R_MIPS_LO16, R_MIPS16_LO16, R_MICROMIPS_LO16, R_MICROMIPS_HI0_LO16
4746 static inline typename
This::Status
4747 rello16(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4748 const Mips_relobj
<size
, big_endian
>* object
,
4749 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4750 bool extract_addend
, Mips_address address
, bool is_gp_disp
,
4751 unsigned int r_type
, unsigned int r_sym
, unsigned int rel_type
,
4752 bool calculate_only
, Valtype
* calculated_value
)
4754 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4755 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4757 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
4760 if (rel_type
== elfcpp::SHT_REL
)
4762 typename
This::Status reloc_status
= This::STATUS_OKAY
;
4763 // Resolve pending R_MIPS_HI16 relocations.
4764 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it
=
4765 hi16_relocs
.begin();
4766 while (it
!= hi16_relocs
.end())
4768 reloc_high
<size
, big_endian
> hi16
= *it
;
4769 if (hi16
.r_sym
== r_sym
4770 && is_matching_lo16_reloc(hi16
.r_type
, r_type
))
4772 mips_reloc_unshuffle(hi16
.view
, hi16
.r_type
, false);
4773 reloc_status
= do_relhi16(hi16
.view
, hi16
.object
, hi16
.psymval
,
4774 hi16
.addend
, hi16
.address
, hi16
.gp_disp
,
4775 hi16
.r_type
, hi16
.extract_addend
, addend
,
4776 target
, calculate_only
, calculated_value
);
4777 mips_reloc_shuffle(hi16
.view
, hi16
.r_type
, false);
4778 if (reloc_status
== This::STATUS_OVERFLOW
)
4779 return This::STATUS_OVERFLOW
;
4780 it
= hi16_relocs
.erase(it
);
4786 // Resolve pending local R_MIPS_GOT16 relocations.
4787 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it2
=
4788 got16_relocs
.begin();
4789 while (it2
!= got16_relocs
.end())
4791 reloc_high
<size
, big_endian
> got16
= *it2
;
4792 if (got16
.r_sym
== r_sym
4793 && is_matching_lo16_reloc(got16
.r_type
, r_type
))
4795 mips_reloc_unshuffle(got16
.view
, got16
.r_type
, false);
4797 reloc_status
= do_relgot16_local(got16
.view
, got16
.object
,
4798 got16
.psymval
, got16
.addend
,
4799 got16
.extract_addend
, addend
, target
,
4800 calculate_only
, calculated_value
);
4802 mips_reloc_shuffle(got16
.view
, got16
.r_type
, false);
4803 if (reloc_status
== This::STATUS_OVERFLOW
)
4804 return This::STATUS_OVERFLOW
;
4805 it2
= got16_relocs
.erase(it2
);
4812 // Resolve R_MIPS_LO16 relocation.
4815 x
= psymval
->value(object
, addend
);
4818 // See the comment for R_MIPS16_HI16 above for the reason
4819 // for this conditional.
4821 if (r_type
== elfcpp::R_MIPS16_LO16
)
4822 gp_disp
= target
->adjusted_gp_value(object
) - (address
& ~0x3);
4823 else if (r_type
== elfcpp::R_MICROMIPS_LO16
4824 || r_type
== elfcpp::R_MICROMIPS_HI0_LO16
)
4825 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 3;
4827 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 4;
4828 // The MIPS ABI requires checking the R_MIPS_LO16 relocation
4829 // for overflow. Relocations against _gp_disp are normally
4830 // generated from the .cpload pseudo-op. It generates code
4831 // that normally looks like this:
4833 // lui $gp,%hi(_gp_disp)
4834 // addiu $gp,$gp,%lo(_gp_disp)
4837 // Here $t9 holds the address of the function being called,
4838 // as required by the MIPS ELF ABI. The R_MIPS_LO16
4839 // relocation can easily overflow in this situation, but the
4840 // R_MIPS_HI16 relocation will handle the overflow.
4841 // Therefore, we consider this a bug in the MIPS ABI, and do
4842 // not check for overflow here.
4843 x
= gp_disp
+ addend
;
4845 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4848 *calculated_value
= x
;
4850 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4852 return This::STATUS_OKAY
;
4855 // R_MIPS_CALL16, R_MIPS16_CALL16, R_MICROMIPS_CALL16
4856 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4857 // R_MIPS_TLS_GD, R_MIPS16_TLS_GD, R_MICROMIPS_TLS_GD
4858 // R_MIPS_TLS_GOTTPREL, R_MIPS16_TLS_GOTTPREL, R_MICROMIPS_TLS_GOTTPREL
4859 // R_MIPS_TLS_LDM, R_MIPS16_TLS_LDM, R_MICROMIPS_TLS_LDM
4860 // R_MIPS_GOT_DISP, R_MICROMIPS_GOT_DISP
4861 static inline typename
This::Status
4862 relgot(unsigned char* view
, int gp_offset
, bool calculate_only
,
4863 Valtype
* calculated_value
)
4865 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4866 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4867 Valtype x
= gp_offset
;
4868 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4872 *calculated_value
= x
;
4873 return This::STATUS_OKAY
;
4876 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4878 return check_overflow
<16>(x
);
4882 static inline typename
This::Status
4883 releh(unsigned char* view
, int gp_offset
, bool calculate_only
,
4884 Valtype
* calculated_value
)
4886 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4887 Valtype x
= gp_offset
;
4891 *calculated_value
= x
;
4892 return This::STATUS_OKAY
;
4895 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4897 return check_overflow
<32>(x
);
4900 // R_MIPS_GOT_PAGE, R_MICROMIPS_GOT_PAGE
4901 static inline typename
This::Status
4902 relgotpage(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4903 const Mips_relobj
<size
, big_endian
>* object
,
4904 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4905 bool extract_addend
, bool calculate_only
,
4906 Valtype
* calculated_value
)
4908 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4909 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4910 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
4912 // Find a GOT page entry that points to within 32KB of symbol + addend.
4913 Mips_address value
= (psymval
->value(object
, addend
) + 0x8000) & ~0xffff;
4914 unsigned int got_offset
=
4915 target
->got_section()->get_got_page_offset(value
, object
);
4917 Valtype x
= target
->got_section()->gp_offset(got_offset
, object
);
4918 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4922 *calculated_value
= x
;
4923 return This::STATUS_OKAY
;
4926 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4928 return check_overflow
<16>(x
);
4931 // R_MIPS_GOT_OFST, R_MICROMIPS_GOT_OFST
4932 static inline typename
This::Status
4933 relgotofst(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4934 const Mips_relobj
<size
, big_endian
>* object
,
4935 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4936 bool extract_addend
, bool local
, bool calculate_only
,
4937 Valtype
* calculated_value
)
4939 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4940 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4941 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
4943 // For a local symbol, find a GOT page entry that points to within 32KB of
4944 // symbol + addend. Relocation value is the offset of the GOT page entry's
4945 // value from symbol + addend.
4946 // For a global symbol, relocation value is addend.
4950 // Find GOT page entry.
4951 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000)
4953 target
->got_section()->get_got_page_offset(value
, object
);
4955 x
= psymval
->value(object
, addend
) - value
;
4959 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4963 *calculated_value
= x
;
4964 return This::STATUS_OKAY
;
4967 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4969 return check_overflow
<16>(x
);
4972 // R_MIPS_GOT_HI16, R_MIPS_CALL_HI16,
4973 // R_MICROMIPS_GOT_HI16, R_MICROMIPS_CALL_HI16
4974 static inline typename
This::Status
4975 relgot_hi16(unsigned char* view
, int gp_offset
, bool calculate_only
,
4976 Valtype
* calculated_value
)
4978 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4979 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4980 Valtype x
= gp_offset
;
4981 x
= ((x
+ 0x8000) >> 16) & 0xffff;
4982 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4985 *calculated_value
= x
;
4987 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4989 return This::STATUS_OKAY
;
4992 // R_MIPS_GOT_LO16, R_MIPS_CALL_LO16,
4993 // R_MICROMIPS_GOT_LO16, R_MICROMIPS_CALL_LO16
4994 static inline typename
This::Status
4995 relgot_lo16(unsigned char* view
, int gp_offset
, bool calculate_only
,
4996 Valtype
* calculated_value
)
4998 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4999 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5000 Valtype x
= gp_offset
;
5001 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5004 *calculated_value
= x
;
5006 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5008 return This::STATUS_OKAY
;
5011 // R_MIPS_GPREL16, R_MIPS16_GPREL, R_MIPS_LITERAL, R_MICROMIPS_LITERAL
5012 // R_MICROMIPS_GPREL7_S2, R_MICROMIPS_GPREL16
5013 static inline typename
This::Status
5014 relgprel(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5015 const Symbol_value
<size
>* psymval
, Mips_address gp
,
5016 Mips_address addend_a
, bool extract_addend
, bool local
,
5017 unsigned int r_type
, bool calculate_only
,
5018 Valtype
* calculated_value
)
5020 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5021 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5026 if (r_type
== elfcpp::R_MICROMIPS_GPREL7_S2
)
5027 addend
= (val
& 0x7f) << 2;
5029 addend
= val
& 0xffff;
5030 // Only sign-extend the addend if it was extracted from the
5031 // instruction. If the addend was separate, leave it alone,
5032 // otherwise we may lose significant bits.
5033 addend
= Bits
<16>::sign_extend32(addend
);
5038 Valtype x
= psymval
->value(object
, addend
) - gp
;
5040 // If the symbol was local, any earlier relocatable links will
5041 // have adjusted its addend with the gp offset, so compensate
5042 // for that now. Don't do it for symbols forced local in this
5043 // link, though, since they won't have had the gp offset applied
5046 x
+= object
->gp_value();
5048 if (r_type
== elfcpp::R_MICROMIPS_GPREL7_S2
)
5049 val
= Bits
<32>::bit_select32(val
, x
, 0x7f);
5051 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5055 *calculated_value
= x
;
5056 return This::STATUS_OKAY
;
5059 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5061 if (check_overflow
<16>(x
) == This::STATUS_OVERFLOW
)
5063 gold_error(_("small-data section exceeds 64KB; lower small-data size "
5064 "limit (see option -G)"));
5065 return This::STATUS_OVERFLOW
;
5067 return This::STATUS_OKAY
;
5071 static inline typename
This::Status
5072 relgprel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5073 const Symbol_value
<size
>* psymval
, Mips_address gp
,
5074 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5075 Valtype
* calculated_value
)
5077 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5078 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5079 Valtype addend
= extract_addend
? val
: addend_a
;
5081 // R_MIPS_GPREL32 relocations are defined for local symbols only.
5082 Valtype x
= psymval
->value(object
, addend
) + object
->gp_value() - gp
;
5085 *calculated_value
= x
;
5087 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5089 return This::STATUS_OKAY
;
5092 // R_MIPS_TLS_TPREL_HI16, R_MIPS16_TLS_TPREL_HI16, R_MICROMIPS_TLS_TPREL_HI16
5093 // R_MIPS_TLS_DTPREL_HI16, R_MIPS16_TLS_DTPREL_HI16,
5094 // R_MICROMIPS_TLS_DTPREL_HI16
5095 static inline typename
This::Status
5096 tlsrelhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5097 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5098 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5099 Valtype
* calculated_value
)
5101 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5102 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5103 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5105 // tls symbol values are relative to tls_segment()->vaddr()
5106 Valtype x
= ((psymval
->value(object
, addend
) - tp_offset
) + 0x8000) >> 16;
5107 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5110 *calculated_value
= x
;
5112 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5114 return This::STATUS_OKAY
;
5117 // R_MIPS_TLS_TPREL_LO16, R_MIPS16_TLS_TPREL_LO16, R_MICROMIPS_TLS_TPREL_LO16,
5118 // R_MIPS_TLS_DTPREL_LO16, R_MIPS16_TLS_DTPREL_LO16,
5119 // R_MICROMIPS_TLS_DTPREL_LO16,
5120 static inline typename
This::Status
5121 tlsrello16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5122 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5123 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5124 Valtype
* calculated_value
)
5126 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5127 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5128 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5130 // tls symbol values are relative to tls_segment()->vaddr()
5131 Valtype x
= psymval
->value(object
, addend
) - tp_offset
;
5132 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5135 *calculated_value
= x
;
5137 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5139 return This::STATUS_OKAY
;
5142 // R_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL64,
5143 // R_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL64
5144 static inline typename
This::Status
5145 tlsrel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5146 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5147 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5148 Valtype
* calculated_value
)
5150 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5151 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5152 Valtype addend
= extract_addend
? val
: addend_a
;
5154 // tls symbol values are relative to tls_segment()->vaddr()
5155 Valtype x
= psymval
->value(object
, addend
) - tp_offset
;
5158 *calculated_value
= x
;
5160 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5162 return This::STATUS_OKAY
;
5165 // R_MIPS_SUB, R_MICROMIPS_SUB
5166 static inline typename
This::Status
5167 relsub(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5168 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5169 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
5171 Valtype64
* wv
= reinterpret_cast<Valtype64
*>(view
);
5172 Valtype64 addend
= (extract_addend
5173 ? elfcpp::Swap
<64, big_endian
>::readval(wv
)
5176 Valtype64 x
= psymval
->value(object
, -addend
);
5178 *calculated_value
= x
;
5180 elfcpp::Swap
<64, big_endian
>::writeval(wv
, x
);
5182 return This::STATUS_OKAY
;
5186 static inline typename
This::Status
5187 rel64(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5188 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5189 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
,
5190 bool apply_addend_only
)
5192 Valtype64
* wv
= reinterpret_cast<Valtype64
*>(view
);
5193 Valtype64 addend
= (extract_addend
5194 ? elfcpp::Swap
<64, big_endian
>::readval(wv
)
5197 Valtype64 x
= psymval
->value(object
, addend
);
5199 *calculated_value
= x
;
5202 if (apply_addend_only
)
5204 elfcpp::Swap
<64, big_endian
>::writeval(wv
, x
);
5207 return This::STATUS_OKAY
;
5212 template<int size
, bool big_endian
>
5213 typename
std::list
<reloc_high
<size
, big_endian
> >
5214 Mips_relocate_functions
<size
, big_endian
>::hi16_relocs
;
5216 template<int size
, bool big_endian
>
5217 typename
std::list
<reloc_high
<size
, big_endian
> >
5218 Mips_relocate_functions
<size
, big_endian
>::got16_relocs
;
5220 // Mips_got_info methods.
5222 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
5223 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
5225 template<int size
, bool big_endian
>
5227 Mips_got_info
<size
, big_endian
>::record_local_got_symbol(
5228 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
,
5229 Mips_address addend
, unsigned int r_type
, unsigned int shndx
,
5230 bool is_section_symbol
)
5232 Mips_got_entry
<size
, big_endian
>* entry
=
5233 new Mips_got_entry
<size
, big_endian
>(object
, symndx
, addend
,
5234 mips_elf_reloc_tls_type(r_type
),
5235 shndx
, is_section_symbol
);
5236 this->record_got_entry(entry
, object
);
5239 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
5240 // in OBJECT. FOR_CALL is true if the caller is only interested in
5241 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
5244 template<int size
, bool big_endian
>
5246 Mips_got_info
<size
, big_endian
>::record_global_got_symbol(
5247 Mips_symbol
<size
>* mips_sym
, Mips_relobj
<size
, big_endian
>* object
,
5248 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
5251 mips_sym
->set_got_not_only_for_calls();
5253 // A global symbol in the GOT must also be in the dynamic symbol table.
5254 if (!mips_sym
->needs_dynsym_entry())
5256 switch (mips_sym
->visibility())
5258 case elfcpp::STV_INTERNAL
:
5259 case elfcpp::STV_HIDDEN
:
5260 mips_sym
->set_is_forced_local();
5263 mips_sym
->set_needs_dynsym_entry();
5268 unsigned char tls_type
= mips_elf_reloc_tls_type(r_type
);
5269 if (tls_type
== GOT_TLS_NONE
)
5270 this->global_got_symbols_
.insert(mips_sym
);
5274 if (mips_sym
->global_got_area() == GGA_NONE
)
5275 mips_sym
->set_global_got_area(GGA_RELOC_ONLY
);
5279 Mips_got_entry
<size
, big_endian
>* entry
=
5280 new Mips_got_entry
<size
, big_endian
>(object
, mips_sym
, tls_type
);
5282 this->record_got_entry(entry
, object
);
5285 // Add ENTRY to master GOT and to OBJECT's GOT.
5287 template<int size
, bool big_endian
>
5289 Mips_got_info
<size
, big_endian
>::record_got_entry(
5290 Mips_got_entry
<size
, big_endian
>* entry
,
5291 Mips_relobj
<size
, big_endian
>* object
)
5293 if (this->got_entries_
.find(entry
) == this->got_entries_
.end())
5294 this->got_entries_
.insert(entry
);
5296 // Create the GOT entry for the OBJECT's GOT.
5297 Mips_got_info
<size
, big_endian
>* g
= object
->get_or_create_got_info();
5298 Mips_got_entry
<size
, big_endian
>* entry2
=
5299 new Mips_got_entry
<size
, big_endian
>(*entry
);
5301 if (g
->got_entries_
.find(entry2
) == g
->got_entries_
.end())
5302 g
->got_entries_
.insert(entry2
);
5305 // Record that OBJECT has a page relocation against symbol SYMNDX and
5306 // that ADDEND is the addend for that relocation.
5307 // This function creates an upper bound on the number of GOT slots
5308 // required; no attempt is made to combine references to non-overridable
5309 // global symbols across multiple input files.
5311 template<int size
, bool big_endian
>
5313 Mips_got_info
<size
, big_endian
>::record_got_page_entry(
5314 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
, int addend
)
5316 struct Got_page_range
**range_ptr
, *range
;
5317 int old_pages
, new_pages
;
5319 // Find the Got_page_entry for this symbol.
5320 Got_page_entry
* entry
= new Got_page_entry(object
, symndx
);
5321 typename
Got_page_entry_set::iterator it
=
5322 this->got_page_entries_
.find(entry
);
5323 if (it
!= this->got_page_entries_
.end())
5326 this->got_page_entries_
.insert(entry
);
5328 // Add the same entry to the OBJECT's GOT.
5329 Got_page_entry
* entry2
= NULL
;
5330 Mips_got_info
<size
, big_endian
>* g2
= object
->get_or_create_got_info();
5331 if (g2
->got_page_entries_
.find(entry
) == g2
->got_page_entries_
.end())
5333 entry2
= new Got_page_entry(*entry
);
5334 g2
->got_page_entries_
.insert(entry2
);
5337 // Skip over ranges whose maximum extent cannot share a page entry
5339 range_ptr
= &entry
->ranges
;
5340 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
5341 range_ptr
= &(*range_ptr
)->next
;
5343 // If we scanned to the end of the list, or found a range whose
5344 // minimum extent cannot share a page entry with ADDEND, create
5345 // a new singleton range.
5347 if (!range
|| addend
< range
->min_addend
- 0xffff)
5349 range
= new Got_page_range();
5350 range
->next
= *range_ptr
;
5351 range
->min_addend
= addend
;
5352 range
->max_addend
= addend
;
5357 ++entry2
->num_pages
;
5358 ++this->page_gotno_
;
5363 // Remember how many pages the old range contributed.
5364 old_pages
= range
->get_max_pages();
5366 // Update the ranges.
5367 if (addend
< range
->min_addend
)
5368 range
->min_addend
= addend
;
5369 else if (addend
> range
->max_addend
)
5371 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
5373 old_pages
+= range
->next
->get_max_pages();
5374 range
->max_addend
= range
->next
->max_addend
;
5375 range
->next
= range
->next
->next
;
5378 range
->max_addend
= addend
;
5381 // Record any change in the total estimate.
5382 new_pages
= range
->get_max_pages();
5383 if (old_pages
!= new_pages
)
5385 entry
->num_pages
+= new_pages
- old_pages
;
5387 entry2
->num_pages
+= new_pages
- old_pages
;
5388 this->page_gotno_
+= new_pages
- old_pages
;
5389 g2
->page_gotno_
+= new_pages
- old_pages
;
5393 // Create all entries that should be in the local part of the GOT.
5395 template<int size
, bool big_endian
>
5397 Mips_got_info
<size
, big_endian
>::add_local_entries(
5398 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5400 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5401 // First two GOT entries are reserved. The first entry will be filled at
5402 // runtime. The second entry will be used by some runtime loaders.
5403 got
->add_constant(0);
5404 got
->add_constant(target
->mips_elf_gnu_got1_mask());
5406 for (typename
Got_entry_set::iterator
5407 p
= this->got_entries_
.begin();
5408 p
!= this->got_entries_
.end();
5411 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5412 if (entry
->is_for_local_symbol() && !entry
->is_tls_entry())
5414 got
->add_local(entry
->object(), entry
->symndx(),
5415 GOT_TYPE_STANDARD
, entry
->addend());
5416 unsigned int got_offset
= entry
->object()->local_got_offset(
5417 entry
->symndx(), GOT_TYPE_STANDARD
, entry
->addend());
5418 if (got
->multi_got() && this->index_
> 0
5419 && parameters
->options().output_is_position_independent())
5421 if (!entry
->is_section_symbol())
5422 target
->rel_dyn_section(layout
)->add_local(entry
->object(),
5423 entry
->symndx(), elfcpp::R_MIPS_REL32
, got
, got_offset
);
5425 target
->rel_dyn_section(layout
)->add_symbolless_local_addend(
5426 entry
->object(), entry
->symndx(), elfcpp::R_MIPS_REL32
,
5432 this->add_page_entries(target
, layout
);
5434 // Add global entries that should be in the local area.
5435 for (typename
Got_entry_set::iterator
5436 p
= this->got_entries_
.begin();
5437 p
!= this->got_entries_
.end();
5440 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5441 if (!entry
->is_for_global_symbol())
5444 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5445 if (mips_sym
->global_got_area() == GGA_NONE
&& !entry
->is_tls_entry())
5447 unsigned int got_type
;
5448 if (!got
->multi_got())
5449 got_type
= GOT_TYPE_STANDARD
;
5451 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
5452 if (got
->add_global(mips_sym
, got_type
))
5454 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5455 if (got
->multi_got() && this->index_
> 0
5456 && parameters
->options().output_is_position_independent())
5457 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
5458 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
5459 mips_sym
->got_offset(got_type
));
5465 // Create GOT page entries.
5467 template<int size
, bool big_endian
>
5469 Mips_got_info
<size
, big_endian
>::add_page_entries(
5470 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5472 if (this->page_gotno_
== 0)
5475 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5476 this->got_page_offset_start_
= got
->add_constant(0);
5477 if (got
->multi_got() && this->index_
> 0
5478 && parameters
->options().output_is_position_independent())
5479 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
5480 this->got_page_offset_start_
);
5481 int num_entries
= this->page_gotno_
;
5482 unsigned int prev_offset
= this->got_page_offset_start_
;
5483 while (--num_entries
> 0)
5485 unsigned int next_offset
= 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
,
5490 gold_assert(next_offset
== prev_offset
+ size
/8);
5491 prev_offset
= next_offset
;
5493 this->got_page_offset_next_
= this->got_page_offset_start_
;
5496 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
5498 template<int size
, bool big_endian
>
5500 Mips_got_info
<size
, big_endian
>::add_global_entries(
5501 Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
5502 unsigned int non_reloc_only_global_gotno
)
5504 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5505 // Add GGA_NORMAL entries.
5506 unsigned int count
= 0;
5507 for (typename
Got_entry_set::iterator
5508 p
= this->got_entries_
.begin();
5509 p
!= this->got_entries_
.end();
5512 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5513 if (!entry
->is_for_global_symbol())
5516 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5517 if (mips_sym
->global_got_area() != GGA_NORMAL
)
5520 unsigned int got_type
;
5521 if (!got
->multi_got())
5522 got_type
= GOT_TYPE_STANDARD
;
5524 // In multi-GOT links, global symbol can be in both primary and
5525 // secondary GOT(s). By creating custom GOT type
5526 // (GOT_TYPE_STANDARD_MULTIGOT + got_index) we ensure that symbol
5527 // is added to secondary GOT(s).
5528 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
5529 if (!got
->add_global(mips_sym
, got_type
))
5532 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5533 if (got
->multi_got() && this->index_
== 0)
5535 if (got
->multi_got() && this->index_
> 0)
5537 if (parameters
->options().output_is_position_independent()
5538 || (!parameters
->doing_static_link()
5539 && mips_sym
->is_from_dynobj() && !mips_sym
->is_undefined()))
5541 target
->rel_dyn_section(layout
)->add_global(
5542 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
5543 mips_sym
->got_offset(got_type
));
5544 got
->add_secondary_got_reloc(mips_sym
->got_offset(got_type
),
5545 elfcpp::R_MIPS_REL32
, mips_sym
);
5550 if (!got
->multi_got() || this->index_
== 0)
5552 if (got
->multi_got())
5554 // We need to allocate space in the primary GOT for GGA_NORMAL entries
5555 // of secondary GOTs, to ensure that GOT offsets of GGA_RELOC_ONLY
5556 // entries correspond to dynamic symbol indexes.
5557 while (count
< non_reloc_only_global_gotno
)
5559 got
->add_constant(0);
5564 // Add GGA_RELOC_ONLY entries.
5565 got
->add_reloc_only_entries();
5569 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
5571 template<int size
, bool big_endian
>
5573 Mips_got_info
<size
, big_endian
>::add_reloc_only_entries(
5574 Mips_output_data_got
<size
, big_endian
>* got
)
5576 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
5577 p
= this->global_got_symbols_
.begin();
5578 p
!= this->global_got_symbols_
.end();
5581 Mips_symbol
<size
>* mips_sym
= *p
;
5582 if (mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
5584 unsigned int got_type
;
5585 if (!got
->multi_got())
5586 got_type
= GOT_TYPE_STANDARD
;
5588 got_type
= GOT_TYPE_STANDARD_MULTIGOT
;
5589 if (got
->add_global(mips_sym
, got_type
))
5590 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5595 // Create TLS GOT entries.
5597 template<int size
, bool big_endian
>
5599 Mips_got_info
<size
, big_endian
>::add_tls_entries(
5600 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5602 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5603 // Add local tls entries.
5604 for (typename
Got_entry_set::iterator
5605 p
= this->got_entries_
.begin();
5606 p
!= this->got_entries_
.end();
5609 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5610 if (!entry
->is_tls_entry() || !entry
->is_for_local_symbol())
5613 if (entry
->tls_type() == GOT_TLS_GD
)
5615 unsigned int got_type
= GOT_TYPE_TLS_PAIR
;
5616 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5617 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5618 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
5619 : elfcpp::R_MIPS_TLS_DTPREL64
);
5621 if (!parameters
->doing_static_link())
5623 got
->add_local_pair_with_rel(entry
->object(), entry
->symndx(),
5624 entry
->shndx(), got_type
,
5625 target
->rel_dyn_section(layout
),
5626 r_type1
, entry
->addend());
5627 unsigned int got_offset
=
5628 entry
->object()->local_got_offset(entry
->symndx(), got_type
,
5630 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
5631 entry
->object(), entry
->symndx());
5635 // We are doing a static link. Mark it as belong to module 1,
5637 unsigned int got_offset
= got
->add_constant(1);
5638 entry
->object()->set_local_got_offset(entry
->symndx(), got_type
,
5641 got
->add_constant(0);
5642 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
5643 entry
->object(), entry
->symndx());
5646 else if (entry
->tls_type() == GOT_TLS_IE
)
5648 unsigned int got_type
= GOT_TYPE_TLS_OFFSET
;
5649 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
5650 : elfcpp::R_MIPS_TLS_TPREL64
);
5651 if (!parameters
->doing_static_link())
5652 got
->add_local_with_rel(entry
->object(), entry
->symndx(), got_type
,
5653 target
->rel_dyn_section(layout
), r_type
,
5657 got
->add_local(entry
->object(), entry
->symndx(), got_type
,
5659 unsigned int got_offset
=
5660 entry
->object()->local_got_offset(entry
->symndx(), got_type
,
5662 got
->add_static_reloc(got_offset
, r_type
, entry
->object(),
5666 else if (entry
->tls_type() == GOT_TLS_LDM
)
5668 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5669 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5670 unsigned int got_offset
;
5671 if (!parameters
->doing_static_link())
5673 got_offset
= got
->add_constant(0);
5674 target
->rel_dyn_section(layout
)->add_local(
5675 entry
->object(), 0, r_type
, got
, got_offset
);
5678 // We are doing a static link. Just mark it as belong to module 1,
5680 got_offset
= got
->add_constant(1);
5682 got
->add_constant(0);
5683 got
->set_tls_ldm_offset(got_offset
, entry
->object());
5689 // Add global tls entries.
5690 for (typename
Got_entry_set::iterator
5691 p
= this->got_entries_
.begin();
5692 p
!= this->got_entries_
.end();
5695 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5696 if (!entry
->is_tls_entry() || !entry
->is_for_global_symbol())
5699 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5700 if (entry
->tls_type() == GOT_TLS_GD
)
5702 unsigned int got_type
;
5703 if (!got
->multi_got())
5704 got_type
= GOT_TYPE_TLS_PAIR
;
5706 got_type
= GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
5707 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5708 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5709 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
5710 : elfcpp::R_MIPS_TLS_DTPREL64
);
5711 if (!parameters
->doing_static_link())
5712 got
->add_global_pair_with_rel(mips_sym
, got_type
,
5713 target
->rel_dyn_section(layout
), r_type1
, r_type2
);
5716 // Add a GOT pair for for R_MIPS_TLS_GD. The creates a pair of
5717 // GOT entries. The first one is initialized to be 1, which is the
5718 // module index for the main executable and the second one 0. A
5719 // reloc of the type R_MIPS_TLS_DTPREL32/64 will be created for
5720 // the second GOT entry and will be applied by gold.
5721 unsigned int got_offset
= got
->add_constant(1);
5722 mips_sym
->set_got_offset(got_type
, got_offset
);
5723 got
->add_constant(0);
5724 got
->add_static_reloc(got_offset
+ size
/8, r_type2
, mips_sym
);
5727 else if (entry
->tls_type() == GOT_TLS_IE
)
5729 unsigned int got_type
;
5730 if (!got
->multi_got())
5731 got_type
= GOT_TYPE_TLS_OFFSET
;
5733 got_type
= GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
5734 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
5735 : elfcpp::R_MIPS_TLS_TPREL64
);
5736 if (!parameters
->doing_static_link())
5737 got
->add_global_with_rel(mips_sym
, got_type
,
5738 target
->rel_dyn_section(layout
), r_type
);
5741 got
->add_global(mips_sym
, got_type
);
5742 unsigned int got_offset
= mips_sym
->got_offset(got_type
);
5743 got
->add_static_reloc(got_offset
, r_type
, mips_sym
);
5751 // Decide whether the symbol needs an entry in the global part of the primary
5752 // GOT, setting global_got_area accordingly. Count the number of global
5753 // symbols that are in the primary GOT only because they have dynamic
5754 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
5756 template<int size
, bool big_endian
>
5758 Mips_got_info
<size
, big_endian
>::count_got_symbols(Symbol_table
* symtab
)
5760 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
5761 p
= this->global_got_symbols_
.begin();
5762 p
!= this->global_got_symbols_
.end();
5765 Mips_symbol
<size
>* sym
= *p
;
5766 // Make a final decision about whether the symbol belongs in the
5767 // local or global GOT. Symbols that bind locally can (and in the
5768 // case of forced-local symbols, must) live in the local GOT.
5769 // Those that are aren't in the dynamic symbol table must also
5770 // live in the local GOT.
5772 if (!sym
->should_add_dynsym_entry(symtab
)
5773 || (sym
->got_only_for_calls()
5774 ? symbol_calls_local(sym
, sym
->should_add_dynsym_entry(symtab
))
5775 : symbol_references_local(sym
,
5776 sym
->should_add_dynsym_entry(symtab
))))
5777 // The symbol belongs in the local GOT. We no longer need this
5778 // entry if it was only used for relocations; those relocations
5779 // will be against the null or section symbol instead.
5780 sym
->set_global_got_area(GGA_NONE
);
5781 else if (sym
->global_got_area() == GGA_RELOC_ONLY
)
5783 ++this->reloc_only_gotno_
;
5784 ++this->global_gotno_
;
5789 // Return the offset of GOT page entry for VALUE. Initialize the entry with
5790 // VALUE if it is not initialized.
5792 template<int size
, bool big_endian
>
5794 Mips_got_info
<size
, big_endian
>::get_got_page_offset(Mips_address value
,
5795 Mips_output_data_got
<size
, big_endian
>* got
)
5797 typename
Got_page_offsets::iterator it
= this->got_page_offsets_
.find(value
);
5798 if (it
!= this->got_page_offsets_
.end())
5801 gold_assert(this->got_page_offset_next_
< this->got_page_offset_start_
5802 + (size
/8) * this->page_gotno_
);
5804 unsigned int got_offset
= this->got_page_offset_next_
;
5805 this->got_page_offsets_
[value
] = got_offset
;
5806 this->got_page_offset_next_
+= size
/8;
5807 got
->update_got_entry(got_offset
, value
);
5811 // Remove lazy-binding stubs for global symbols in this GOT.
5813 template<int size
, bool big_endian
>
5815 Mips_got_info
<size
, big_endian
>::remove_lazy_stubs(
5816 Target_mips
<size
, big_endian
>* target
)
5818 for (typename
Got_entry_set::iterator
5819 p
= this->got_entries_
.begin();
5820 p
!= this->got_entries_
.end();
5823 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5824 if (entry
->is_for_global_symbol())
5825 target
->remove_lazy_stub_entry(entry
->sym());
5829 // Count the number of GOT entries required.
5831 template<int size
, bool big_endian
>
5833 Mips_got_info
<size
, big_endian
>::count_got_entries()
5835 for (typename
Got_entry_set::iterator
5836 p
= this->got_entries_
.begin();
5837 p
!= this->got_entries_
.end();
5840 this->count_got_entry(*p
);
5844 // Count the number of GOT entries required by ENTRY. Accumulate the result.
5846 template<int size
, bool big_endian
>
5848 Mips_got_info
<size
, big_endian
>::count_got_entry(
5849 Mips_got_entry
<size
, big_endian
>* entry
)
5851 if (entry
->is_tls_entry())
5852 this->tls_gotno_
+= mips_tls_got_entries(entry
->tls_type());
5853 else if (entry
->is_for_local_symbol()
5854 || entry
->sym()->global_got_area() == GGA_NONE
)
5855 ++this->local_gotno_
;
5857 ++this->global_gotno_
;
5860 // Add FROM's GOT entries.
5862 template<int size
, bool big_endian
>
5864 Mips_got_info
<size
, big_endian
>::add_got_entries(
5865 Mips_got_info
<size
, big_endian
>* from
)
5867 for (typename
Got_entry_set::iterator
5868 p
= from
->got_entries_
.begin();
5869 p
!= from
->got_entries_
.end();
5872 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5873 if (this->got_entries_
.find(entry
) == this->got_entries_
.end())
5875 Mips_got_entry
<size
, big_endian
>* entry2
=
5876 new Mips_got_entry
<size
, big_endian
>(*entry
);
5877 this->got_entries_
.insert(entry2
);
5878 this->count_got_entry(entry
);
5883 // Add FROM's GOT page entries.
5885 template<int size
, bool big_endian
>
5887 Mips_got_info
<size
, big_endian
>::add_got_page_entries(
5888 Mips_got_info
<size
, big_endian
>* from
)
5890 for (typename
Got_page_entry_set::iterator
5891 p
= from
->got_page_entries_
.begin();
5892 p
!= from
->got_page_entries_
.end();
5895 Got_page_entry
* entry
= *p
;
5896 if (this->got_page_entries_
.find(entry
) == this->got_page_entries_
.end())
5898 Got_page_entry
* entry2
= new Got_page_entry(*entry
);
5899 this->got_page_entries_
.insert(entry2
);
5900 this->page_gotno_
+= entry
->num_pages
;
5905 // Mips_output_data_got methods.
5907 // Lay out the GOT. Add local, global and TLS entries. If GOT is
5908 // larger than 64K, create multi-GOT.
5910 template<int size
, bool big_endian
>
5912 Mips_output_data_got
<size
, big_endian
>::lay_out_got(Layout
* layout
,
5913 Symbol_table
* symtab
, const Input_objects
* input_objects
)
5915 // Decide which symbols need to go in the global part of the GOT and
5916 // count the number of reloc-only GOT symbols.
5917 this->master_got_info_
->count_got_symbols(symtab
);
5919 // Count the number of GOT entries.
5920 this->master_got_info_
->count_got_entries();
5922 unsigned int got_size
= this->master_got_info_
->got_size();
5923 if (got_size
> Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
)
5924 this->lay_out_multi_got(layout
, input_objects
);
5927 // Record that all objects use single GOT.
5928 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
5929 p
!= input_objects
->relobj_end();
5932 Mips_relobj
<size
, big_endian
>* object
=
5933 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
5934 if (object
->get_got_info() != NULL
)
5935 object
->set_got_info(this->master_got_info_
);
5938 this->master_got_info_
->add_local_entries(this->target_
, layout
);
5939 this->master_got_info_
->add_global_entries(this->target_
, layout
,
5941 this->master_got_info_
->add_tls_entries(this->target_
, layout
);
5945 // Create multi-GOT. For every GOT, add local, global and TLS entries.
5947 template<int size
, bool big_endian
>
5949 Mips_output_data_got
<size
, big_endian
>::lay_out_multi_got(Layout
* layout
,
5950 const Input_objects
* input_objects
)
5952 // Try to merge the GOTs of input objects together, as long as they
5953 // don't seem to exceed the maximum GOT size, choosing one of them
5954 // to be the primary GOT.
5955 this->merge_gots(input_objects
);
5957 // Every symbol that is referenced in a dynamic relocation must be
5958 // present in the primary GOT.
5959 this->primary_got_
->set_global_gotno(this->master_got_info_
->global_gotno());
5963 unsigned int offset
= 0;
5964 Mips_got_info
<size
, big_endian
>* g
= this->primary_got_
;
5968 g
->set_offset(offset
);
5970 g
->add_local_entries(this->target_
, layout
);
5972 g
->add_global_entries(this->target_
, layout
,
5973 (this->master_got_info_
->global_gotno()
5974 - this->master_got_info_
->reloc_only_gotno()));
5976 g
->add_global_entries(this->target_
, layout
, /*not used*/-1U);
5977 g
->add_tls_entries(this->target_
, layout
);
5979 // Forbid global symbols in every non-primary GOT from having
5980 // lazy-binding stubs.
5982 g
->remove_lazy_stubs(this->target_
);
5985 offset
+= g
->got_size();
5991 // Attempt to merge GOTs of different input objects. Try to use as much as
5992 // possible of the primary GOT, since it doesn't require explicit dynamic
5993 // relocations, but don't use objects that would reference global symbols
5994 // out of the addressable range. Failing the primary GOT, attempt to merge
5995 // with the current GOT, or finish the current GOT and then make make the new
5998 template<int size
, bool big_endian
>
6000 Mips_output_data_got
<size
, big_endian
>::merge_gots(
6001 const Input_objects
* input_objects
)
6003 gold_assert(this->primary_got_
== NULL
);
6004 Mips_got_info
<size
, big_endian
>* current
= NULL
;
6006 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
6007 p
!= input_objects
->relobj_end();
6010 Mips_relobj
<size
, big_endian
>* object
=
6011 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
6013 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
6017 g
->count_got_entries();
6019 // Work out the number of page, local and TLS entries.
6020 unsigned int estimate
= this->master_got_info_
->page_gotno();
6021 if (estimate
> g
->page_gotno())
6022 estimate
= g
->page_gotno();
6023 estimate
+= g
->local_gotno() + g
->tls_gotno();
6025 // We place TLS GOT entries after both locals and globals. The globals
6026 // for the primary GOT may overflow the normal GOT size limit, so be
6027 // sure not to merge a GOT which requires TLS with the primary GOT in that
6028 // case. This doesn't affect non-primary GOTs.
6029 estimate
+= (g
->tls_gotno() > 0 ? this->master_got_info_
->global_gotno()
6030 : g
->global_gotno());
6032 unsigned int max_count
=
6033 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
6034 if (estimate
<= max_count
)
6036 // If we don't have a primary GOT, use it as
6037 // a starting point for the primary GOT.
6038 if (!this->primary_got_
)
6040 this->primary_got_
= g
;
6044 // Try merging with the primary GOT.
6045 if (this->merge_got_with(g
, object
, this->primary_got_
))
6049 // If we can merge with the last-created GOT, do it.
6050 if (current
&& this->merge_got_with(g
, object
, current
))
6053 // Well, we couldn't merge, so create a new GOT. Don't check if it
6054 // fits; if it turns out that it doesn't, we'll get relocation
6055 // overflows anyway.
6056 g
->set_next(current
);
6060 // If we do not find any suitable primary GOT, create an empty one.
6061 if (this->primary_got_
== NULL
)
6062 this->primary_got_
= new Mips_got_info
<size
, big_endian
>();
6064 // Link primary GOT with secondary GOTs.
6065 this->primary_got_
->set_next(current
);
6068 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
6069 // this would lead to overflow, true if they were merged successfully.
6071 template<int size
, bool big_endian
>
6073 Mips_output_data_got
<size
, big_endian
>::merge_got_with(
6074 Mips_got_info
<size
, big_endian
>* from
,
6075 Mips_relobj
<size
, big_endian
>* object
,
6076 Mips_got_info
<size
, big_endian
>* to
)
6078 // Work out how many page entries we would need for the combined GOT.
6079 unsigned int estimate
= this->master_got_info_
->page_gotno();
6080 if (estimate
>= from
->page_gotno() + to
->page_gotno())
6081 estimate
= from
->page_gotno() + to
->page_gotno();
6083 // Conservatively estimate how many local and TLS entries would be needed.
6084 estimate
+= from
->local_gotno() + to
->local_gotno();
6085 estimate
+= from
->tls_gotno() + to
->tls_gotno();
6087 // If we're merging with the primary got, any TLS relocations will
6088 // come after the full set of global entries. Otherwise estimate those
6089 // conservatively as well.
6090 if (to
== this->primary_got_
&& (from
->tls_gotno() + to
->tls_gotno()) > 0)
6091 estimate
+= this->master_got_info_
->global_gotno();
6093 estimate
+= from
->global_gotno() + to
->global_gotno();
6095 // Bail out if the combined GOT might be too big.
6096 unsigned int max_count
=
6097 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
6098 if (estimate
> max_count
)
6101 // Transfer the object's GOT information from FROM to TO.
6102 to
->add_got_entries(from
);
6103 to
->add_got_page_entries(from
);
6105 // Record that OBJECT should use output GOT TO.
6106 object
->set_got_info(to
);
6111 // Write out the GOT.
6113 template<int size
, bool big_endian
>
6115 Mips_output_data_got
<size
, big_endian
>::do_write(Output_file
* of
)
6117 // Call parent to write out GOT.
6118 Output_data_got
<size
, big_endian
>::do_write(of
);
6120 const off_t offset
= this->offset();
6121 const section_size_type oview_size
=
6122 convert_to_section_size_type(this->data_size());
6123 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6125 // Needed for fixing values of .got section.
6126 this->got_view_
= oview
;
6128 // Write lazy stub addresses.
6129 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
6130 p
= this->master_got_info_
->global_got_symbols().begin();
6131 p
!= this->master_got_info_
->global_got_symbols().end();
6134 Mips_symbol
<size
>* mips_sym
= *p
;
6135 if (mips_sym
->has_lazy_stub())
6137 Valtype
* wv
= reinterpret_cast<Valtype
*>(
6138 oview
+ this->get_primary_got_offset(mips_sym
));
6140 this->target_
->mips_stubs_section()->stub_address(mips_sym
);
6141 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
6145 // Add +1 to GGA_NONE nonzero MIPS16 and microMIPS entries.
6146 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
6147 p
= this->master_got_info_
->global_got_symbols().begin();
6148 p
!= this->master_got_info_
->global_got_symbols().end();
6151 Mips_symbol
<size
>* mips_sym
= *p
;
6152 if (!this->multi_got()
6153 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
6154 && mips_sym
->global_got_area() == GGA_NONE
6155 && mips_sym
->has_got_offset(GOT_TYPE_STANDARD
))
6157 Valtype
* wv
= reinterpret_cast<Valtype
*>(
6158 oview
+ mips_sym
->got_offset(GOT_TYPE_STANDARD
));
6159 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv
);
6163 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
6168 if (!this->secondary_got_relocs_
.empty())
6170 // Fixup for the secondary GOT R_MIPS_REL32 relocs. For global
6171 // secondary GOT entries with non-zero initial value copy the value
6172 // to the corresponding primary GOT entry, and set the secondary GOT
6174 // TODO(sasa): This is workaround. It needs to be investigated further.
6176 for (size_t i
= 0; i
< this->secondary_got_relocs_
.size(); ++i
)
6178 Static_reloc
& reloc(this->secondary_got_relocs_
[i
]);
6179 if (reloc
.symbol_is_global())
6181 Mips_symbol
<size
>* gsym
= reloc
.symbol();
6182 gold_assert(gsym
!= NULL
);
6184 unsigned got_offset
= reloc
.got_offset();
6185 gold_assert(got_offset
< oview_size
);
6187 // Find primary GOT entry.
6188 Valtype
* wv_prim
= reinterpret_cast<Valtype
*>(
6189 oview
+ this->get_primary_got_offset(gsym
));
6191 // Find secondary GOT entry.
6192 Valtype
* wv_sec
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6194 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv_sec
);
6197 elfcpp::Swap
<size
, big_endian
>::writeval(wv_prim
, value
);
6198 elfcpp::Swap
<size
, big_endian
>::writeval(wv_sec
, 0);
6199 gsym
->set_applied_secondary_got_fixup();
6204 of
->write_output_view(offset
, oview_size
, oview
);
6207 // We are done if there is no fix up.
6208 if (this->static_relocs_
.empty())
6211 Output_segment
* tls_segment
= this->layout_
->tls_segment();
6212 gold_assert(tls_segment
!= NULL
);
6214 for (size_t i
= 0; i
< this->static_relocs_
.size(); ++i
)
6216 Static_reloc
& reloc(this->static_relocs_
[i
]);
6219 if (!reloc
.symbol_is_global())
6221 Sized_relobj_file
<size
, big_endian
>* object
= reloc
.relobj();
6222 const Symbol_value
<size
>* psymval
=
6223 object
->local_symbol(reloc
.index());
6225 // We are doing static linking. Issue an error and skip this
6226 // relocation if the symbol is undefined or in a discarded_section.
6228 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
6229 if ((shndx
== elfcpp::SHN_UNDEF
)
6231 && shndx
!= elfcpp::SHN_UNDEF
6232 && !object
->is_section_included(shndx
)
6233 && !this->symbol_table_
->is_section_folded(object
, shndx
)))
6235 gold_error(_("undefined or discarded local symbol %u from "
6236 " object %s in GOT"),
6237 reloc
.index(), reloc
.relobj()->name().c_str());
6241 value
= psymval
->value(object
, 0);
6245 const Mips_symbol
<size
>* gsym
= reloc
.symbol();
6246 gold_assert(gsym
!= NULL
);
6248 // We are doing static linking. Issue an error and skip this
6249 // relocation if the symbol is undefined or in a discarded_section
6250 // unless it is a weakly_undefined symbol.
6251 if ((gsym
->is_defined_in_discarded_section() || gsym
->is_undefined())
6252 && !gsym
->is_weak_undefined())
6254 gold_error(_("undefined or discarded symbol %s in GOT"),
6259 if (!gsym
->is_weak_undefined())
6260 value
= gsym
->value();
6265 unsigned got_offset
= reloc
.got_offset();
6266 gold_assert(got_offset
< oview_size
);
6268 Valtype
* wv
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6271 switch (reloc
.r_type())
6273 case elfcpp::R_MIPS_TLS_DTPMOD32
:
6274 case elfcpp::R_MIPS_TLS_DTPMOD64
:
6277 case elfcpp::R_MIPS_TLS_DTPREL32
:
6278 case elfcpp::R_MIPS_TLS_DTPREL64
:
6279 x
= value
- elfcpp::DTP_OFFSET
;
6281 case elfcpp::R_MIPS_TLS_TPREL32
:
6282 case elfcpp::R_MIPS_TLS_TPREL64
:
6283 x
= value
- elfcpp::TP_OFFSET
;
6290 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, x
);
6293 of
->write_output_view(offset
, oview_size
, oview
);
6296 // Mips_relobj methods.
6298 // Count the local symbols. The Mips backend needs to know if a symbol
6299 // is a MIPS16 or microMIPS function or not. For global symbols, it is easy
6300 // because the Symbol object keeps the ELF symbol type and st_other field.
6301 // For local symbol it is harder because we cannot access this information.
6302 // So we override the do_count_local_symbol in parent and scan local symbols to
6303 // mark MIPS16 and microMIPS functions. This is not the most efficient way but
6304 // I do not want to slow down other ports by calling a per symbol target hook
6305 // inside Sized_relobj_file<size, big_endian>::do_count_local_symbols.
6307 template<int size
, bool big_endian
>
6309 Mips_relobj
<size
, big_endian
>::do_count_local_symbols(
6310 Stringpool_template
<char>* pool
,
6311 Stringpool_template
<char>* dynpool
)
6313 // Ask parent to count the local symbols.
6314 Sized_relobj_file
<size
, big_endian
>::do_count_local_symbols(pool
, dynpool
);
6315 const unsigned int loccount
= this->local_symbol_count();
6319 // Initialize the mips16 and micromips function bit-vector.
6320 this->local_symbol_is_mips16_
.resize(loccount
, false);
6321 this->local_symbol_is_micromips_
.resize(loccount
, false);
6323 // Read the symbol table section header.
6324 const unsigned int symtab_shndx
= this->symtab_shndx();
6325 elfcpp::Shdr
<size
, big_endian
>
6326 symtabshdr(this, this->elf_file()->section_header(symtab_shndx
));
6327 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
6329 // Read the local symbols.
6330 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
6331 gold_assert(loccount
== symtabshdr
.get_sh_info());
6332 off_t locsize
= loccount
* sym_size
;
6333 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
6334 locsize
, true, true);
6336 // Loop over the local symbols and mark any MIPS16 or microMIPS local symbols.
6338 // Skip the first dummy symbol.
6340 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
6342 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
6343 unsigned char st_other
= sym
.get_st_other();
6344 this->local_symbol_is_mips16_
[i
] = elfcpp::elf_st_is_mips16(st_other
);
6345 this->local_symbol_is_micromips_
[i
] =
6346 elfcpp::elf_st_is_micromips(st_other
);
6350 // Read the symbol information.
6352 template<int size
, bool big_endian
>
6354 Mips_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
6356 // Call parent class to read symbol information.
6357 this->base_read_symbols(sd
);
6359 // Read processor-specific flags in ELF file header.
6360 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
6361 elfcpp::Elf_sizes
<size
>::ehdr_size
,
6363 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
6364 this->processor_specific_flags_
= ehdr
.get_e_flags();
6366 // Get the section names.
6367 const unsigned char* pnamesu
= sd
->section_names
->data();
6368 const char* pnames
= reinterpret_cast<const char*>(pnamesu
);
6370 // Initialize the mips16 stub section bit-vectors.
6371 this->section_is_mips16_fn_stub_
.resize(this->shnum(), false);
6372 this->section_is_mips16_call_stub_
.resize(this->shnum(), false);
6373 this->section_is_mips16_call_fp_stub_
.resize(this->shnum(), false);
6375 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
6376 const unsigned char* pshdrs
= sd
->section_headers
->data();
6377 const unsigned char* ps
= pshdrs
+ shdr_size
;
6378 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
6380 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
6382 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_REGINFO
)
6384 // Read the gp value that was used to create this object. We need the
6385 // gp value while processing relocs. The .reginfo section is not used
6386 // in the 64-bit MIPS ELF ABI.
6387 section_offset_type section_offset
= shdr
.get_sh_offset();
6388 section_size_type section_size
=
6389 convert_to_section_size_type(shdr
.get_sh_size());
6390 const unsigned char* view
=
6391 this->get_view(section_offset
, section_size
, true, false);
6393 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 20);
6395 // Read the rest of .reginfo.
6396 this->gprmask_
= elfcpp::Swap
<size
, big_endian
>::readval(view
);
6397 this->cprmask1_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 4);
6398 this->cprmask2_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 8);
6399 this->cprmask3_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 12);
6400 this->cprmask4_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 16);
6403 // In the 64-bit ABI, .MIPS.options section holds register information.
6404 // A SHT_MIPS_OPTIONS section contains a series of options, each of which
6405 // starts with this header:
6409 // // Type of option.
6410 // unsigned char kind[1];
6411 // // Size of option descriptor, including header.
6412 // unsigned char size[1];
6413 // // Section index of affected section, or 0 for global option.
6414 // unsigned char section[2];
6415 // // Information specific to this kind of option.
6416 // unsigned char info[4];
6419 // For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and set
6420 // the gp value based on what we find. We may see both SHT_MIPS_REGINFO
6421 // and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case, they should agree.
6423 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_OPTIONS
)
6425 section_offset_type section_offset
= shdr
.get_sh_offset();
6426 section_size_type section_size
=
6427 convert_to_section_size_type(shdr
.get_sh_size());
6428 const unsigned char* view
=
6429 this->get_view(section_offset
, section_size
, true, false);
6430 const unsigned char* end
= view
+ section_size
;
6432 while (view
+ 8 <= end
)
6434 unsigned char kind
= elfcpp::Swap
<8, big_endian
>::readval(view
);
6435 unsigned char sz
= elfcpp::Swap
<8, big_endian
>::readval(view
+ 1);
6438 gold_error(_("%s: Warning: bad `%s' option size %u smaller "
6440 this->name().c_str(),
6441 this->mips_elf_options_section_name(), sz
);
6445 if (this->is_n64() && kind
== elfcpp::ODK_REGINFO
)
6447 // In the 64 bit ABI, an ODK_REGINFO option is the following
6448 // structure. The info field of the options header is not
6453 // // Mask of general purpose registers used.
6454 // unsigned char ri_gprmask[4];
6456 // unsigned char ri_pad[4];
6457 // // Mask of co-processor registers used.
6458 // unsigned char ri_cprmask[4][4];
6459 // // GP register value for this object file.
6460 // unsigned char ri_gp_value[8];
6463 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
6466 else if (kind
== elfcpp::ODK_REGINFO
)
6468 // In the 32 bit ABI, an ODK_REGINFO option is the following
6469 // structure. The info field of the options header is not
6470 // used. The same structure is used in .reginfo section.
6474 // unsigned char ri_gprmask[4];
6475 // unsigned char ri_cprmask[4][4];
6476 // unsigned char ri_gp_value[4];
6479 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
6486 const char* name
= pnames
+ shdr
.get_sh_name();
6487 this->section_is_mips16_fn_stub_
[i
] = is_prefix_of(".mips16.fn", name
);
6488 this->section_is_mips16_call_stub_
[i
] =
6489 is_prefix_of(".mips16.call.", name
);
6490 this->section_is_mips16_call_fp_stub_
[i
] =
6491 is_prefix_of(".mips16.call.fp.", name
);
6493 if (strcmp(name
, ".pdr") == 0)
6495 gold_assert(this->pdr_shndx_
== -1U);
6496 this->pdr_shndx_
= i
;
6501 // Discard MIPS16 stub secions that are not needed.
6503 template<int size
, bool big_endian
>
6505 Mips_relobj
<size
, big_endian
>::discard_mips16_stub_sections(Symbol_table
* symtab
)
6507 for (typename
Mips16_stubs_int_map::const_iterator
6508 it
= this->mips16_stub_sections_
.begin();
6509 it
!= this->mips16_stub_sections_
.end(); ++it
)
6511 Mips16_stub_section
<size
, big_endian
>* stub_section
= it
->second
;
6512 if (!stub_section
->is_target_found())
6514 gold_error(_("no relocation found in mips16 stub section '%s'"),
6515 stub_section
->object()
6516 ->section_name(stub_section
->shndx()).c_str());
6519 bool discard
= false;
6520 if (stub_section
->is_for_local_function())
6522 if (stub_section
->is_fn_stub())
6524 // This stub is for a local symbol. This stub will only
6525 // be needed if there is some relocation in this object,
6526 // other than a 16 bit function call, which refers to this
6528 if (!this->has_local_non_16bit_call_relocs(stub_section
->r_sym()))
6531 this->add_local_mips16_fn_stub(stub_section
);
6535 // This stub is for a local symbol. This stub will only
6536 // be needed if there is some relocation (R_MIPS16_26) in
6537 // this object that refers to this symbol.
6538 gold_assert(stub_section
->is_call_stub()
6539 || stub_section
->is_call_fp_stub());
6540 if (!this->has_local_16bit_call_relocs(stub_section
->r_sym()))
6543 this->add_local_mips16_call_stub(stub_section
);
6548 Mips_symbol
<size
>* gsym
= stub_section
->gsym();
6549 if (stub_section
->is_fn_stub())
6551 if (gsym
->has_mips16_fn_stub())
6552 // We already have a stub for this function.
6556 gsym
->set_mips16_fn_stub(stub_section
);
6557 if (gsym
->should_add_dynsym_entry(symtab
))
6559 // If we have a MIPS16 function with a stub, the
6560 // dynamic symbol must refer to the stub, since only
6561 // the stub uses the standard calling conventions.
6562 gsym
->set_need_fn_stub();
6563 if (gsym
->is_from_dynobj())
6564 gsym
->set_needs_dynsym_value();
6567 if (!gsym
->need_fn_stub())
6570 else if (stub_section
->is_call_stub())
6572 if (gsym
->is_mips16())
6573 // We don't need the call_stub; this is a 16 bit
6574 // function, so calls from other 16 bit functions are
6577 else if (gsym
->has_mips16_call_stub())
6578 // We already have a stub for this function.
6581 gsym
->set_mips16_call_stub(stub_section
);
6585 gold_assert(stub_section
->is_call_fp_stub());
6586 if (gsym
->is_mips16())
6587 // We don't need the call_stub; this is a 16 bit
6588 // function, so calls from other 16 bit functions are
6591 else if (gsym
->has_mips16_call_fp_stub())
6592 // We already have a stub for this function.
6595 gsym
->set_mips16_call_fp_stub(stub_section
);
6599 this->set_output_section(stub_section
->shndx(), NULL
);
6603 // Mips_output_data_la25_stub methods.
6605 // Template for standard LA25 stub.
6606 template<int size
, bool big_endian
>
6608 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_entry
[] =
6610 0x3c190000, // lui $25,%hi(func)
6611 0x08000000, // j func
6612 0x27390000, // add $25,$25,%lo(func)
6616 // Template for microMIPS LA25 stub.
6617 template<int size
, bool big_endian
>
6619 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_micromips_entry
[] =
6621 0x41b9, 0x0000, // lui t9,%hi(func)
6622 0xd400, 0x0000, // j func
6623 0x3339, 0x0000, // addiu t9,t9,%lo(func)
6624 0x0000, 0x0000 // nop
6627 // Create la25 stub for a symbol.
6629 template<int size
, bool big_endian
>
6631 Mips_output_data_la25_stub
<size
, big_endian
>::create_la25_stub(
6632 Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
6633 Mips_symbol
<size
>* gsym
)
6635 if (!gsym
->has_la25_stub())
6637 gsym
->set_la25_stub_offset(this->symbols_
.size() * 16);
6638 this->symbols_
.insert(gsym
);
6639 this->create_stub_symbol(gsym
, symtab
, target
, 16);
6643 // Create a symbol for SYM stub's value and size, to help make the disassembly
6646 template<int size
, bool big_endian
>
6648 Mips_output_data_la25_stub
<size
, big_endian
>::create_stub_symbol(
6649 Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
6650 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
)
6652 std::string
name(".pic.");
6653 name
+= sym
->name();
6655 unsigned int offset
= sym
->la25_stub_offset();
6656 if (sym
->is_micromips())
6659 // Make it a local function.
6660 Symbol
* new_sym
= symtab
->define_in_output_data(name
.c_str(), NULL
,
6661 Symbol_table::PREDEFINED
,
6662 target
->la25_stub_section(),
6663 offset
, symsize
, elfcpp::STT_FUNC
,
6665 elfcpp::STV_DEFAULT
, 0,
6667 new_sym
->set_is_forced_local();
6670 // Write out la25 stubs. This uses the hand-coded instructions above,
6671 // and adjusts them as needed.
6673 template<int size
, bool big_endian
>
6675 Mips_output_data_la25_stub
<size
, big_endian
>::do_write(Output_file
* of
)
6677 const off_t offset
= this->offset();
6678 const section_size_type oview_size
=
6679 convert_to_section_size_type(this->data_size());
6680 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6682 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
6683 p
= this->symbols_
.begin();
6684 p
!= this->symbols_
.end();
6687 Mips_symbol
<size
>* sym
= *p
;
6688 unsigned char* pov
= oview
+ sym
->la25_stub_offset();
6690 Mips_address target
= sym
->value();
6691 if (!sym
->is_micromips())
6693 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
6694 la25_stub_entry
[0] | (((target
+ 0x8000) >> 16) & 0xffff));
6695 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
6696 la25_stub_entry
[1] | ((target
>> 2) & 0x3ffffff));
6697 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
6698 la25_stub_entry
[2] | (target
& 0xffff));
6699 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12, la25_stub_entry
[3]);
6704 // First stub instruction. Paste high 16-bits of the target.
6705 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
6706 la25_stub_micromips_entry
[0]);
6707 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
6708 ((target
+ 0x8000) >> 16) & 0xffff);
6709 // Second stub instruction. Paste low 26-bits of the target, shifted
6711 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
6712 la25_stub_micromips_entry
[2] | ((target
>> 17) & 0x3ff));
6713 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
6714 la25_stub_micromips_entry
[3] | ((target
>> 1) & 0xffff));
6715 // Third stub instruction. Paste low 16-bits of the target.
6716 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8,
6717 la25_stub_micromips_entry
[4]);
6718 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, target
& 0xffff);
6719 // Fourth stub instruction.
6720 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 12,
6721 la25_stub_micromips_entry
[6]);
6722 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 14,
6723 la25_stub_micromips_entry
[7]);
6727 of
->write_output_view(offset
, oview_size
, oview
);
6730 // Mips_output_data_plt methods.
6732 // The format of the first PLT entry in an O32 executable.
6733 template<int size
, bool big_endian
>
6734 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_o32
[] =
6736 0x3c1c0000, // lui $28, %hi(&GOTPLT[0])
6737 0x8f990000, // lw $25, %lo(&GOTPLT[0])($28)
6738 0x279c0000, // addiu $28, $28, %lo(&GOTPLT[0])
6739 0x031cc023, // subu $24, $24, $28
6740 0x03e07825, // or $15, $31, zero
6741 0x0018c082, // srl $24, $24, 2
6742 0x0320f809, // jalr $25
6743 0x2718fffe // subu $24, $24, 2
6746 // The format of the first PLT entry in an N32 executable. Different
6747 // because gp ($28) is not available; we use t2 ($14) instead.
6748 template<int size
, bool big_endian
>
6749 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n32
[] =
6751 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
6752 0x8dd90000, // lw $25, %lo(&GOTPLT[0])($14)
6753 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
6754 0x030ec023, // subu $24, $24, $14
6755 0x03e07825, // or $15, $31, zero
6756 0x0018c082, // srl $24, $24, 2
6757 0x0320f809, // jalr $25
6758 0x2718fffe // subu $24, $24, 2
6761 // The format of the first PLT entry in an N64 executable. Different
6762 // from N32 because of the increased size of GOT entries.
6763 template<int size
, bool big_endian
>
6764 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n64
[] =
6766 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
6767 0xddd90000, // ld $25, %lo(&GOTPLT[0])($14)
6768 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
6769 0x030ec023, // subu $24, $24, $14
6770 0x03e07825, // or $15, $31, zero
6771 0x0018c0c2, // srl $24, $24, 3
6772 0x0320f809, // jalr $25
6773 0x2718fffe // subu $24, $24, 2
6776 // The format of the microMIPS first PLT entry in an O32 executable.
6777 // We rely on v0 ($2) rather than t8 ($24) to contain the address
6778 // of the GOTPLT entry handled, so this stub may only be used when
6779 // all the subsequent PLT entries are microMIPS code too.
6781 // The trailing NOP is for alignment and correct disassembly only.
6782 template<int size
, bool big_endian
>
6783 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6784 plt0_entry_micromips_o32
[] =
6786 0x7980, 0x0000, // addiupc $3, (&GOTPLT[0]) - .
6787 0xff23, 0x0000, // lw $25, 0($3)
6788 0x0535, // subu $2, $2, $3
6789 0x2525, // srl $2, $2, 2
6790 0x3302, 0xfffe, // subu $24, $2, 2
6791 0x0dff, // move $15, $31
6792 0x45f9, // jalrs $25
6793 0x0f83, // move $28, $3
6797 // The format of the microMIPS first PLT entry in an O32 executable
6798 // in the insn32 mode.
6799 template<int size
, bool big_endian
>
6800 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6801 plt0_entry_micromips32_o32
[] =
6803 0x41bc, 0x0000, // lui $28, %hi(&GOTPLT[0])
6804 0xff3c, 0x0000, // lw $25, %lo(&GOTPLT[0])($28)
6805 0x339c, 0x0000, // addiu $28, $28, %lo(&GOTPLT[0])
6806 0x0398, 0xc1d0, // subu $24, $24, $28
6807 0x001f, 0x7a90, // or $15, $31, zero
6808 0x0318, 0x1040, // srl $24, $24, 2
6809 0x03f9, 0x0f3c, // jalr $25
6810 0x3318, 0xfffe // subu $24, $24, 2
6813 // The format of subsequent standard entries in the PLT.
6814 template<int size
, bool big_endian
>
6815 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry
[] =
6817 0x3c0f0000, // lui $15, %hi(.got.plt entry)
6818 0x01f90000, // l[wd] $25, %lo(.got.plt entry)($15)
6819 0x03200008, // jr $25
6820 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
6823 // The format of subsequent MIPS16 o32 PLT entries. We use v1 ($3) as a
6824 // temporary because t8 ($24) and t9 ($25) are not directly addressable.
6825 // Note that this differs from the GNU ld which uses both v0 ($2) and v1 ($3).
6826 // We cannot use v0 because MIPS16 call stubs from the CS toolchain expect
6827 // target function address in register v0.
6828 template<int size
, bool big_endian
>
6829 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry_mips16_o32
[] =
6831 0xb303, // lw $3, 12($pc)
6832 0x651b, // move $24, $3
6833 0x9b60, // lw $3, 0($3)
6835 0x653b, // move $25, $3
6837 0x0000, 0x0000 // .word (.got.plt entry)
6840 // The format of subsequent microMIPS o32 PLT entries. We use v0 ($2)
6841 // as a temporary because t8 ($24) is not addressable with ADDIUPC.
6842 template<int size
, bool big_endian
>
6843 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6844 plt_entry_micromips_o32
[] =
6846 0x7900, 0x0000, // addiupc $2, (.got.plt entry) - .
6847 0xff22, 0x0000, // lw $25, 0($2)
6849 0x0f02 // move $24, $2
6852 // The format of subsequent microMIPS o32 PLT entries in the insn32 mode.
6853 template<int size
, bool big_endian
>
6854 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6855 plt_entry_micromips32_o32
[] =
6857 0x41af, 0x0000, // lui $15, %hi(.got.plt entry)
6858 0xff2f, 0x0000, // lw $25, %lo(.got.plt entry)($15)
6859 0x0019, 0x0f3c, // jr $25
6860 0x330f, 0x0000 // addiu $24, $15, %lo(.got.plt entry)
6863 // Add an entry to the PLT for a symbol referenced by r_type relocation.
6865 template<int size
, bool big_endian
>
6867 Mips_output_data_plt
<size
, big_endian
>::add_entry(Mips_symbol
<size
>* gsym
,
6868 unsigned int r_type
)
6870 gold_assert(!gsym
->has_plt_offset());
6872 // Final PLT offset for a symbol will be set in method set_plt_offsets().
6873 gsym
->set_plt_offset(this->entry_count() * sizeof(plt_entry
)
6874 + sizeof(plt0_entry_o32
));
6875 this->symbols_
.push_back(gsym
);
6877 // Record whether the relocation requires a standard MIPS
6878 // or a compressed code entry.
6879 if (jal_reloc(r_type
))
6881 if (r_type
== elfcpp::R_MIPS_26
)
6882 gsym
->set_needs_mips_plt(true);
6884 gsym
->set_needs_comp_plt(true);
6887 section_offset_type got_offset
= this->got_plt_
->current_data_size();
6889 // Every PLT entry needs a GOT entry which points back to the PLT
6890 // entry (this will be changed by the dynamic linker, normally
6891 // lazily when the function is called).
6892 this->got_plt_
->set_current_data_size(got_offset
+ size
/8);
6894 gsym
->set_needs_dynsym_entry();
6895 this->rel_
->add_global(gsym
, elfcpp::R_MIPS_JUMP_SLOT
, this->got_plt_
,
6899 // Set final PLT offsets. For each symbol, determine whether standard or
6900 // compressed (MIPS16 or microMIPS) PLT entry is used.
6902 template<int size
, bool big_endian
>
6904 Mips_output_data_plt
<size
, big_endian
>::set_plt_offsets()
6906 // The sizes of individual PLT entries.
6907 unsigned int plt_mips_entry_size
= this->standard_plt_entry_size();
6908 unsigned int plt_comp_entry_size
= (!this->target_
->is_output_newabi()
6909 ? this->compressed_plt_entry_size() : 0);
6911 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
6912 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
6914 Mips_symbol
<size
>* mips_sym
= *p
;
6916 // There are no defined MIPS16 or microMIPS PLT entries for n32 or n64,
6917 // so always use a standard entry there.
6919 // If the symbol has a MIPS16 call stub and gets a PLT entry, then
6920 // all MIPS16 calls will go via that stub, and there is no benefit
6921 // to having a MIPS16 entry. And in the case of call_stub a
6922 // standard entry actually has to be used as the stub ends with a J
6924 if (this->target_
->is_output_newabi()
6925 || mips_sym
->has_mips16_call_stub()
6926 || mips_sym
->has_mips16_call_fp_stub())
6928 mips_sym
->set_needs_mips_plt(true);
6929 mips_sym
->set_needs_comp_plt(false);
6932 // Otherwise, if there are no direct calls to the function, we
6933 // have a free choice of whether to use standard or compressed
6934 // entries. Prefer microMIPS entries if the object is known to
6935 // contain microMIPS code, so that it becomes possible to create
6936 // pure microMIPS binaries. Prefer standard entries otherwise,
6937 // because MIPS16 ones are no smaller and are usually slower.
6938 if (!mips_sym
->needs_mips_plt() && !mips_sym
->needs_comp_plt())
6940 if (this->target_
->is_output_micromips())
6941 mips_sym
->set_needs_comp_plt(true);
6943 mips_sym
->set_needs_mips_plt(true);
6946 if (mips_sym
->needs_mips_plt())
6948 mips_sym
->set_mips_plt_offset(this->plt_mips_offset_
);
6949 this->plt_mips_offset_
+= plt_mips_entry_size
;
6951 if (mips_sym
->needs_comp_plt())
6953 mips_sym
->set_comp_plt_offset(this->plt_comp_offset_
);
6954 this->plt_comp_offset_
+= plt_comp_entry_size
;
6958 // Figure out the size of the PLT header if we know that we are using it.
6959 if (this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0)
6960 this->plt_header_size_
= this->get_plt_header_size();
6963 // Write out the PLT. This uses the hand-coded instructions above,
6964 // and adjusts them as needed.
6966 template<int size
, bool big_endian
>
6968 Mips_output_data_plt
<size
, big_endian
>::do_write(Output_file
* of
)
6970 const off_t offset
= this->offset();
6971 const section_size_type oview_size
=
6972 convert_to_section_size_type(this->data_size());
6973 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6975 const off_t gotplt_file_offset
= this->got_plt_
->offset();
6976 const section_size_type gotplt_size
=
6977 convert_to_section_size_type(this->got_plt_
->data_size());
6978 unsigned char* const gotplt_view
= of
->get_output_view(gotplt_file_offset
,
6980 unsigned char* pov
= oview
;
6982 Mips_address plt_address
= this->address();
6984 // Calculate the address of .got.plt.
6985 Mips_address gotplt_addr
= this->got_plt_
->address();
6986 Mips_address gotplt_addr_high
= ((gotplt_addr
+ 0x8000) >> 16) & 0xffff;
6987 Mips_address gotplt_addr_low
= gotplt_addr
& 0xffff;
6989 // The PLT sequence is not safe for N64 if .got.plt's address can
6990 // not be loaded in two instructions.
6991 gold_assert((gotplt_addr
& ~(Mips_address
) 0x7fffffff) == 0
6992 || ~(gotplt_addr
| 0x7fffffff) == 0);
6994 // Write the PLT header.
6995 const uint32_t* plt0_entry
= this->get_plt_header_entry();
6996 if (plt0_entry
== plt0_entry_micromips_o32
)
6998 // Write microMIPS PLT header.
6999 gold_assert(gotplt_addr
% 4 == 0);
7001 Mips_address gotpc_offset
= gotplt_addr
- ((plt_address
| 3) ^ 3);
7003 // ADDIUPC has a span of +/-16MB, check we're in range.
7004 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
7006 gold_error(_(".got.plt offset of %ld from .plt beyond the range of "
7007 "ADDIUPC"), (long)gotpc_offset
);
7011 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
7012 plt0_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
7013 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7014 (gotpc_offset
>> 2) & 0xffff);
7016 for (unsigned int i
= 2;
7017 i
< (sizeof(plt0_entry_micromips_o32
)
7018 / sizeof(plt0_entry_micromips_o32
[0]));
7021 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7025 else if (plt0_entry
== plt0_entry_micromips32_o32
)
7027 // Write microMIPS PLT header in insn32 mode.
7028 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[0]);
7029 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, gotplt_addr_high
);
7030 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, plt0_entry
[2]);
7031 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, gotplt_addr_low
);
7032 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8, plt0_entry
[4]);
7033 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, gotplt_addr_low
);
7035 for (unsigned int i
= 6;
7036 i
< (sizeof(plt0_entry_micromips32_o32
)
7037 / sizeof(plt0_entry_micromips32_o32
[0]));
7040 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7046 // Write standard PLT header.
7047 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7048 plt0_entry
[0] | gotplt_addr_high
);
7049 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7050 plt0_entry
[1] | gotplt_addr_low
);
7051 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
7052 plt0_entry
[2] | gotplt_addr_low
);
7054 for (int i
= 3; i
< 8; i
++)
7056 elfcpp::Swap
<32, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7062 unsigned char* gotplt_pov
= gotplt_view
;
7063 unsigned int got_entry_size
= size
/8; // TODO(sasa): MIPS_ELF_GOT_SIZE
7065 // The first two entries in .got.plt are reserved.
7066 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
, 0);
7067 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
+ got_entry_size
, 0);
7069 unsigned int gotplt_offset
= 2 * got_entry_size
;
7070 gotplt_pov
+= 2 * got_entry_size
;
7072 // Calculate the address of the PLT header.
7073 Mips_address header_address
= (plt_address
7074 + (this->is_plt_header_compressed() ? 1 : 0));
7076 // Initialize compressed PLT area view.
7077 unsigned char* pov2
= pov
+ this->plt_mips_offset_
;
7079 // Write the PLT entries.
7080 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
7081 p
= this->symbols_
.begin();
7082 p
!= this->symbols_
.end();
7083 ++p
, gotplt_pov
+= got_entry_size
, gotplt_offset
+= got_entry_size
)
7085 Mips_symbol
<size
>* mips_sym
= *p
;
7087 // Calculate the address of the .got.plt entry.
7088 uint32_t gotplt_entry_addr
= (gotplt_addr
+ gotplt_offset
);
7089 uint32_t gotplt_entry_addr_hi
= (((gotplt_entry_addr
+ 0x8000) >> 16)
7091 uint32_t gotplt_entry_addr_lo
= gotplt_entry_addr
& 0xffff;
7093 // Initially point the .got.plt entry at the PLT header.
7094 if (this->target_
->is_output_n64())
7095 elfcpp::Swap
<64, big_endian
>::writeval(gotplt_pov
, header_address
);
7097 elfcpp::Swap
<32, big_endian
>::writeval(gotplt_pov
, header_address
);
7099 // Now handle the PLT itself. First the standard entry.
7100 if (mips_sym
->has_mips_plt_offset())
7102 // Pick the load opcode (LW or LD).
7103 uint64_t load
= this->target_
->is_output_n64() ? 0xdc000000
7106 // Fill in the PLT entry itself.
7107 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7108 plt_entry
[0] | gotplt_entry_addr_hi
);
7109 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7110 plt_entry
[1] | gotplt_entry_addr_lo
| load
);
7111 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8, plt_entry
[2]);
7112 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12,
7113 plt_entry
[3] | gotplt_entry_addr_lo
);
7117 // Now the compressed entry. They come after any standard ones.
7118 if (mips_sym
->has_comp_plt_offset())
7120 if (!this->target_
->is_output_micromips())
7122 // Write MIPS16 PLT entry.
7123 const uint32_t* plt_entry
= plt_entry_mips16_o32
;
7125 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
7126 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2, plt_entry
[1]);
7127 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7128 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
7129 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7130 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7131 elfcpp::Swap
<32, big_endian
>::writeval(pov2
+ 12,
7135 else if (this->target_
->use_32bit_micromips_instructions())
7137 // Write microMIPS PLT entry in insn32 mode.
7138 const uint32_t* plt_entry
= plt_entry_micromips32_o32
;
7140 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
7141 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2,
7142 gotplt_entry_addr_hi
);
7143 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7144 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6,
7145 gotplt_entry_addr_lo
);
7146 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7147 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7148 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 12, plt_entry
[6]);
7149 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 14,
7150 gotplt_entry_addr_lo
);
7155 // Write microMIPS PLT entry.
7156 const uint32_t* plt_entry
= plt_entry_micromips_o32
;
7158 gold_assert(gotplt_entry_addr
% 4 == 0);
7160 Mips_address loc_address
= plt_address
+ pov2
- oview
;
7161 int gotpc_offset
= gotplt_entry_addr
- ((loc_address
| 3) ^ 3);
7163 // ADDIUPC has a span of +/-16MB, check we're in range.
7164 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
7166 gold_error(_(".got.plt offset of %ld from .plt beyond the "
7167 "range of ADDIUPC"), (long)gotpc_offset
);
7171 elfcpp::Swap
<16, big_endian
>::writeval(pov2
,
7172 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
7173 elfcpp::Swap
<16, big_endian
>::writeval(
7174 pov2
+ 2, (gotpc_offset
>> 2) & 0xffff);
7175 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7176 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
7177 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7178 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7184 // Check the number of bytes written for standard entries.
7185 gold_assert(static_cast<section_size_type
>(
7186 pov
- oview
- this->plt_header_size_
) == this->plt_mips_offset_
);
7187 // Check the number of bytes written for compressed entries.
7188 gold_assert((static_cast<section_size_type
>(pov2
- pov
)
7189 == this->plt_comp_offset_
));
7190 // Check the total number of bytes written.
7191 gold_assert(static_cast<section_size_type
>(pov2
- oview
) == oview_size
);
7193 gold_assert(static_cast<section_size_type
>(gotplt_pov
- gotplt_view
)
7196 of
->write_output_view(offset
, oview_size
, oview
);
7197 of
->write_output_view(gotplt_file_offset
, gotplt_size
, gotplt_view
);
7200 // Mips_output_data_mips_stubs methods.
7202 // The format of the lazy binding stub when dynamic symbol count is less than
7203 // 64K, dynamic symbol index is less than 32K, and ABI is not N64.
7204 template<int size
, bool big_endian
>
7206 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1
[4] =
7208 0x8f998010, // lw t9,0x8010(gp)
7209 0x03e07825, // or t7,ra,zero
7210 0x0320f809, // jalr t9,ra
7211 0x24180000 // addiu t8,zero,DYN_INDEX sign extended
7214 // The format of the lazy binding stub when dynamic symbol count is less than
7215 // 64K, dynamic symbol index is less than 32K, and ABI is N64.
7216 template<int size
, bool big_endian
>
7218 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1_n64
[4] =
7220 0xdf998010, // ld t9,0x8010(gp)
7221 0x03e07825, // or t7,ra,zero
7222 0x0320f809, // jalr t9,ra
7223 0x64180000 // daddiu t8,zero,DYN_INDEX sign extended
7226 // The format of the lazy binding stub when dynamic symbol count is less than
7227 // 64K, dynamic symbol index is between 32K and 64K, and ABI is not N64.
7228 template<int size
, bool big_endian
>
7230 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2
[4] =
7232 0x8f998010, // lw t9,0x8010(gp)
7233 0x03e07825, // or t7,ra,zero
7234 0x0320f809, // jalr t9,ra
7235 0x34180000 // ori t8,zero,DYN_INDEX unsigned
7238 // The format of the lazy binding stub when dynamic symbol count is less than
7239 // 64K, dynamic symbol index is between 32K and 64K, and ABI is N64.
7240 template<int size
, bool big_endian
>
7242 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2_n64
[4] =
7244 0xdf998010, // ld t9,0x8010(gp)
7245 0x03e07825, // or t7,ra,zero
7246 0x0320f809, // jalr t9,ra
7247 0x34180000 // ori t8,zero,DYN_INDEX unsigned
7250 // The format of the lazy binding stub when dynamic symbol count is greater than
7251 // 64K, and ABI is not N64.
7252 template<int size
, bool big_endian
>
7253 const uint32_t Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big
[5] =
7255 0x8f998010, // lw t9,0x8010(gp)
7256 0x03e07825, // or t7,ra,zero
7257 0x3c180000, // lui t8,DYN_INDEX
7258 0x0320f809, // jalr t9,ra
7259 0x37180000 // ori t8,t8,DYN_INDEX
7262 // The format of the lazy binding stub when dynamic symbol count is greater than
7263 // 64K, and ABI is N64.
7264 template<int size
, bool big_endian
>
7266 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big_n64
[5] =
7268 0xdf998010, // ld t9,0x8010(gp)
7269 0x03e07825, // or t7,ra,zero
7270 0x3c180000, // lui t8,DYN_INDEX
7271 0x0320f809, // jalr t9,ra
7272 0x37180000 // ori t8,t8,DYN_INDEX
7277 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7278 // less than 64K, dynamic symbol index is less than 32K, and ABI is not N64.
7279 template<int size
, bool big_endian
>
7281 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_1
[] =
7283 0xff3c, 0x8010, // lw t9,0x8010(gp)
7284 0x0dff, // move t7,ra
7286 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
7289 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7290 // less than 64K, dynamic symbol index is less than 32K, and ABI is N64.
7291 template<int size
, bool big_endian
>
7293 Mips_output_data_mips_stubs
<size
, big_endian
>::
7294 lazy_stub_micromips_normal_1_n64
[] =
7296 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7297 0x0dff, // move t7,ra
7299 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
7302 // The format of the microMIPS lazy binding stub when dynamic symbol
7303 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7304 // and ABI is not N64.
7305 template<int size
, bool big_endian
>
7307 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_2
[] =
7309 0xff3c, 0x8010, // lw t9,0x8010(gp)
7310 0x0dff, // move t7,ra
7312 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7315 // The format of the microMIPS lazy binding stub when dynamic symbol
7316 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7318 template<int size
, bool big_endian
>
7320 Mips_output_data_mips_stubs
<size
, big_endian
>::
7321 lazy_stub_micromips_normal_2_n64
[] =
7323 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7324 0x0dff, // move t7,ra
7326 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7329 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7330 // greater than 64K, and ABI is not N64.
7331 template<int size
, bool big_endian
>
7333 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big
[] =
7335 0xff3c, 0x8010, // lw t9,0x8010(gp)
7336 0x0dff, // move t7,ra
7337 0x41b8, 0x0000, // lui t8,DYN_INDEX
7339 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7342 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7343 // greater than 64K, and ABI is N64.
7344 template<int size
, bool big_endian
>
7346 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big_n64
[] =
7348 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7349 0x0dff, // move t7,ra
7350 0x41b8, 0x0000, // lui t8,DYN_INDEX
7352 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7355 // 32-bit microMIPS stubs.
7357 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7358 // less than 64K, dynamic symbol index is less than 32K, ABI is not N64, and we
7359 // can use only 32-bit instructions.
7360 template<int size
, bool big_endian
>
7362 Mips_output_data_mips_stubs
<size
, big_endian
>::
7363 lazy_stub_micromips32_normal_1
[] =
7365 0xff3c, 0x8010, // lw t9,0x8010(gp)
7366 0x001f, 0x7a90, // or t7,ra,zero
7367 0x03f9, 0x0f3c, // jalr ra,t9
7368 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
7371 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7372 // less than 64K, dynamic symbol index is less than 32K, ABI is N64, and we can
7373 // use only 32-bit instructions.
7374 template<int size
, bool big_endian
>
7376 Mips_output_data_mips_stubs
<size
, big_endian
>::
7377 lazy_stub_micromips32_normal_1_n64
[] =
7379 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7380 0x001f, 0x7a90, // or t7,ra,zero
7381 0x03f9, 0x0f3c, // jalr ra,t9
7382 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
7385 // The format of the microMIPS lazy binding stub when dynamic symbol
7386 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7387 // ABI is not N64, and we can use only 32-bit instructions.
7388 template<int size
, bool big_endian
>
7390 Mips_output_data_mips_stubs
<size
, big_endian
>::
7391 lazy_stub_micromips32_normal_2
[] =
7393 0xff3c, 0x8010, // lw t9,0x8010(gp)
7394 0x001f, 0x7a90, // or t7,ra,zero
7395 0x03f9, 0x0f3c, // jalr ra,t9
7396 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7399 // The format of the microMIPS lazy binding stub when dynamic symbol
7400 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7401 // ABI is N64, and we can use only 32-bit instructions.
7402 template<int size
, bool big_endian
>
7404 Mips_output_data_mips_stubs
<size
, big_endian
>::
7405 lazy_stub_micromips32_normal_2_n64
[] =
7407 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7408 0x001f, 0x7a90, // or t7,ra,zero
7409 0x03f9, 0x0f3c, // jalr ra,t9
7410 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7413 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7414 // greater than 64K, ABI is not N64, and we can use only 32-bit instructions.
7415 template<int size
, bool big_endian
>
7417 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big
[] =
7419 0xff3c, 0x8010, // lw t9,0x8010(gp)
7420 0x001f, 0x7a90, // or t7,ra,zero
7421 0x41b8, 0x0000, // lui t8,DYN_INDEX
7422 0x03f9, 0x0f3c, // jalr ra,t9
7423 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7426 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7427 // greater than 64K, ABI is N64, and we can use only 32-bit instructions.
7428 template<int size
, bool big_endian
>
7430 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big_n64
[] =
7432 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7433 0x001f, 0x7a90, // or t7,ra,zero
7434 0x41b8, 0x0000, // lui t8,DYN_INDEX
7435 0x03f9, 0x0f3c, // jalr ra,t9
7436 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7439 // Create entry for a symbol.
7441 template<int size
, bool big_endian
>
7443 Mips_output_data_mips_stubs
<size
, big_endian
>::make_entry(
7444 Mips_symbol
<size
>* gsym
)
7446 if (!gsym
->has_lazy_stub() && !gsym
->has_plt_offset())
7448 this->symbols_
.insert(gsym
);
7449 gsym
->set_has_lazy_stub(true);
7453 // Remove entry for a symbol.
7455 template<int size
, bool big_endian
>
7457 Mips_output_data_mips_stubs
<size
, big_endian
>::remove_entry(
7458 Mips_symbol
<size
>* gsym
)
7460 if (gsym
->has_lazy_stub())
7462 this->symbols_
.erase(gsym
);
7463 gsym
->set_has_lazy_stub(false);
7467 // Set stub offsets for symbols. This method expects that the number of
7468 // entries in dynamic symbol table is set.
7470 template<int size
, bool big_endian
>
7472 Mips_output_data_mips_stubs
<size
, big_endian
>::set_lazy_stub_offsets()
7474 gold_assert(this->dynsym_count_
!= -1U);
7476 if (this->stub_offsets_are_set_
)
7479 unsigned int stub_size
= this->stub_size();
7480 unsigned int offset
= 0;
7481 for (typename Unordered_set
<Mips_symbol
<size
>*>::const_iterator
7482 p
= this->symbols_
.begin();
7483 p
!= this->symbols_
.end();
7484 ++p
, offset
+= stub_size
)
7486 Mips_symbol
<size
>* mips_sym
= *p
;
7487 mips_sym
->set_lazy_stub_offset(offset
);
7489 this->stub_offsets_are_set_
= true;
7492 template<int size
, bool big_endian
>
7494 Mips_output_data_mips_stubs
<size
, big_endian
>::set_needs_dynsym_value()
7496 for (typename Unordered_set
<Mips_symbol
<size
>*>::const_iterator
7497 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
7499 Mips_symbol
<size
>* sym
= *p
;
7500 if (sym
->is_from_dynobj())
7501 sym
->set_needs_dynsym_value();
7505 // Write out the .MIPS.stubs. This uses the hand-coded instructions and
7506 // adjusts them as needed.
7508 template<int size
, bool big_endian
>
7510 Mips_output_data_mips_stubs
<size
, big_endian
>::do_write(Output_file
* of
)
7512 const off_t offset
= this->offset();
7513 const section_size_type oview_size
=
7514 convert_to_section_size_type(this->data_size());
7515 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
7517 bool big_stub
= this->dynsym_count_
> 0x10000;
7519 unsigned char* pov
= oview
;
7520 for (typename Unordered_set
<Mips_symbol
<size
>*>::const_iterator
7521 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
7523 Mips_symbol
<size
>* sym
= *p
;
7524 const uint32_t* lazy_stub
;
7525 bool n64
= this->target_
->is_output_n64();
7527 if (!this->target_
->is_output_micromips())
7529 // Write standard (non-microMIPS) stub.
7532 if (sym
->dynsym_index() & ~0x7fff)
7533 // Dynsym index is between 32K and 64K.
7534 lazy_stub
= n64
? lazy_stub_normal_2_n64
: lazy_stub_normal_2
;
7536 // Dynsym index is less than 32K.
7537 lazy_stub
= n64
? lazy_stub_normal_1_n64
: lazy_stub_normal_1
;
7540 lazy_stub
= n64
? lazy_stub_big_n64
: lazy_stub_big
;
7543 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7544 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 1]);
7550 // LUI instruction of the big stub. Paste high 16 bits of the
7552 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7553 lazy_stub
[i
] | ((sym
->dynsym_index() >> 16) & 0x7fff));
7557 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7558 // Last stub instruction. Paste low 16 bits of the dynsym index.
7559 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7560 lazy_stub
[i
+ 1] | (sym
->dynsym_index() & 0xffff));
7563 else if (this->target_
->use_32bit_micromips_instructions())
7565 // Write microMIPS stub in insn32 mode.
7568 if (sym
->dynsym_index() & ~0x7fff)
7569 // Dynsym index is between 32K and 64K.
7570 lazy_stub
= n64
? lazy_stub_micromips32_normal_2_n64
7571 : lazy_stub_micromips32_normal_2
;
7573 // Dynsym index is less than 32K.
7574 lazy_stub
= n64
? lazy_stub_micromips32_normal_1_n64
7575 : lazy_stub_micromips32_normal_1
;
7578 lazy_stub
= n64
? lazy_stub_micromips32_big_n64
7579 : lazy_stub_micromips32_big
;
7582 // First stub instruction. We emit 32-bit microMIPS instructions by
7583 // emitting two 16-bit parts because on microMIPS the 16-bit part of
7584 // the instruction where the opcode is must always come first, for
7585 // both little and big endian.
7586 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7587 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7588 // Second stub instruction.
7589 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7590 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, lazy_stub
[i
+ 3]);
7595 // LUI instruction of the big stub. Paste high 16 bits of the
7597 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7598 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7599 (sym
->dynsym_index() >> 16) & 0x7fff);
7603 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7604 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7605 // Last stub instruction. Paste low 16 bits of the dynsym index.
7606 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7607 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
7608 sym
->dynsym_index() & 0xffff);
7613 // Write microMIPS stub.
7616 if (sym
->dynsym_index() & ~0x7fff)
7617 // Dynsym index is between 32K and 64K.
7618 lazy_stub
= n64
? lazy_stub_micromips_normal_2_n64
7619 : lazy_stub_micromips_normal_2
;
7621 // Dynsym index is less than 32K.
7622 lazy_stub
= n64
? lazy_stub_micromips_normal_1_n64
7623 : lazy_stub_micromips_normal_1
;
7626 lazy_stub
= n64
? lazy_stub_micromips_big_n64
7627 : lazy_stub_micromips_big
;
7630 // First stub instruction. We emit 32-bit microMIPS instructions by
7631 // emitting two 16-bit parts because on microMIPS the 16-bit part of
7632 // the instruction where the opcode is must always come first, for
7633 // both little and big endian.
7634 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7635 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7636 // Second stub instruction.
7637 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7642 // LUI instruction of the big stub. Paste high 16 bits of the
7644 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7645 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7646 (sym
->dynsym_index() >> 16) & 0x7fff);
7650 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7651 // Last stub instruction. Paste low 16 bits of the dynsym index.
7652 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7653 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
7654 sym
->dynsym_index() & 0xffff);
7659 // We always allocate 20 bytes for every stub, because final dynsym count is
7660 // not known in method do_finalize_sections. There are 4 unused bytes per
7661 // stub if final dynsym count is less than 0x10000.
7662 unsigned int used
= pov
- oview
;
7663 unsigned int unused
= big_stub
? 0 : this->symbols_
.size() * 4;
7664 gold_assert(static_cast<section_size_type
>(used
+ unused
) == oview_size
);
7666 // Fill the unused space with zeroes.
7667 // TODO(sasa): Can we strip unused bytes during the relaxation?
7669 memset(pov
, 0, unused
);
7671 of
->write_output_view(offset
, oview_size
, oview
);
7674 // Mips_output_section_reginfo methods.
7676 template<int size
, bool big_endian
>
7678 Mips_output_section_reginfo
<size
, big_endian
>::do_write(Output_file
* of
)
7680 off_t offset
= this->offset();
7681 off_t data_size
= this->data_size();
7683 unsigned char* view
= of
->get_output_view(offset
, data_size
);
7684 elfcpp::Swap
<size
, big_endian
>::writeval(view
, this->gprmask_
);
7685 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 4, this->cprmask1_
);
7686 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 8, this->cprmask2_
);
7687 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 12, this->cprmask3_
);
7688 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 16, this->cprmask4_
);
7689 // Write the gp value.
7690 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 20,
7691 this->target_
->gp_value());
7693 of
->write_output_view(offset
, data_size
, view
);
7696 // Mips_copy_relocs methods.
7698 // Emit any saved relocs.
7700 template<int sh_type
, int size
, bool big_endian
>
7702 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_mips(
7703 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
7704 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
7706 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
7707 Copy_reloc_entries::iterator p
= this->entries_
.begin();
7708 p
!= this->entries_
.end();
7710 emit_entry(*p
, reloc_section
, symtab
, layout
, target
);
7712 // We no longer need the saved information.
7713 this->entries_
.clear();
7716 // Emit the reloc if appropriate.
7718 template<int sh_type
, int size
, bool big_endian
>
7720 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_entry(
7721 Copy_reloc_entry
& entry
,
7722 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
7723 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
7725 // If the symbol is no longer defined in a dynamic object, then we
7726 // emitted a COPY relocation, and we do not want to emit this
7727 // dynamic relocation.
7728 if (!entry
.sym_
->is_from_dynobj())
7731 bool can_make_dynamic
= (entry
.reloc_type_
== elfcpp::R_MIPS_32
7732 || entry
.reloc_type_
== elfcpp::R_MIPS_REL32
7733 || entry
.reloc_type_
== elfcpp::R_MIPS_64
);
7735 Mips_symbol
<size
>* sym
= Mips_symbol
<size
>::as_mips_sym(entry
.sym_
);
7736 if (can_make_dynamic
&& !sym
->has_static_relocs())
7738 Mips_relobj
<size
, big_endian
>* object
=
7739 Mips_relobj
<size
, big_endian
>::as_mips_relobj(entry
.relobj_
);
7740 target
->got_section(symtab
, layout
)->record_global_got_symbol(
7741 sym
, object
, entry
.reloc_type_
, true, false);
7742 if (!symbol_references_local(sym
, sym
->should_add_dynsym_entry(symtab
)))
7743 target
->rel_dyn_section(layout
)->add_global(sym
, elfcpp::R_MIPS_REL32
,
7744 entry
.output_section_
, entry
.relobj_
, entry
.shndx_
, entry
.address_
);
7746 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
7747 sym
, elfcpp::R_MIPS_REL32
, entry
.output_section_
, entry
.relobj_
,
7748 entry
.shndx_
, entry
.address_
);
7751 this->make_copy_reloc(symtab
, layout
,
7752 static_cast<Sized_symbol
<size
>*>(entry
.sym_
),
7756 // Target_mips methods.
7758 // Return the value to use for a dynamic symbol which requires special
7759 // treatment. This is how we support equality comparisons of function
7760 // pointers across shared library boundaries, as described in the
7761 // processor specific ABI supplement.
7763 template<int size
, bool big_endian
>
7765 Target_mips
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
7768 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
7770 if (!mips_sym
->has_lazy_stub())
7772 if (mips_sym
->has_plt_offset())
7774 // We distinguish between PLT entries and lazy-binding stubs by
7775 // giving the former an st_other value of STO_MIPS_PLT. Set the
7776 // value to the stub address if there are any relocations in the
7777 // binary where pointer equality matters.
7778 if (mips_sym
->pointer_equality_needed())
7780 // Prefer a standard MIPS PLT entry.
7781 if (mips_sym
->has_mips_plt_offset())
7782 value
= this->plt_section()->mips_entry_address(mips_sym
);
7784 value
= this->plt_section()->comp_entry_address(mips_sym
) + 1;
7792 // First, set stub offsets for symbols. This method expects that the
7793 // number of entries in dynamic symbol table is set.
7794 this->mips_stubs_section()->set_lazy_stub_offsets();
7796 // The run-time linker uses the st_value field of the symbol
7797 // to reset the global offset table entry for this external
7798 // to its stub address when unlinking a shared object.
7799 value
= this->mips_stubs_section()->stub_address(mips_sym
);
7802 if (mips_sym
->has_mips16_fn_stub())
7804 // If we have a MIPS16 function with a stub, the dynamic symbol must
7805 // refer to the stub, since only the stub uses the standard calling
7807 value
= mips_sym
->template
7808 get_mips16_fn_stub
<big_endian
>()->output_address();
7814 // Get the dynamic reloc section, creating it if necessary. It's always
7815 // .rel.dyn, even for MIPS64.
7817 template<int size
, bool big_endian
>
7818 typename Target_mips
<size
, big_endian
>::Reloc_section
*
7819 Target_mips
<size
, big_endian
>::rel_dyn_section(Layout
* layout
)
7821 if (this->rel_dyn_
== NULL
)
7823 gold_assert(layout
!= NULL
);
7824 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
7825 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
7826 elfcpp::SHF_ALLOC
, this->rel_dyn_
,
7827 ORDER_DYNAMIC_RELOCS
, false);
7829 // First entry in .rel.dyn has to be null.
7830 // This is hack - we define dummy output data and set its address to 0,
7831 // and define absolute R_MIPS_NONE relocation with offset 0 against it.
7832 // This ensures that the entry is null.
7833 Output_data
* od
= new Output_data_zero_fill(0, 0);
7835 this->rel_dyn_
->add_absolute(elfcpp::R_MIPS_NONE
, od
, 0);
7837 return this->rel_dyn_
;
7840 // Get the GOT section, creating it if necessary.
7842 template<int size
, bool big_endian
>
7843 Mips_output_data_got
<size
, big_endian
>*
7844 Target_mips
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
7847 if (this->got_
== NULL
)
7849 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
7851 this->got_
= new Mips_output_data_got
<size
, big_endian
>(this, symtab
,
7853 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
7854 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
|
7855 elfcpp::SHF_MIPS_GPREL
),
7856 this->got_
, ORDER_DATA
, false);
7858 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
7859 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
7860 Symbol_table::PREDEFINED
,
7862 0, 0, elfcpp::STT_OBJECT
,
7864 elfcpp::STV_DEFAULT
, 0,
7871 // Calculate value of _gp symbol.
7873 template<int size
, bool big_endian
>
7875 Target_mips
<size
, big_endian
>::set_gp(Layout
* layout
, Symbol_table
* symtab
)
7877 if (this->gp_
!= NULL
)
7880 Output_data
* section
= layout
->find_output_section(".got");
7881 if (section
== NULL
)
7883 // If there is no .got section, gp should be based on .sdata.
7884 // TODO(sasa): This is probably not needed. This was needed for older
7885 // MIPS architectures which accessed both GOT and .sdata section using
7886 // gp-relative addressing. Modern Mips Linux ELF architectures don't
7887 // access .sdata using gp-relative addressing.
7888 for (Layout::Section_list::const_iterator
7889 p
= layout
->section_list().begin();
7890 p
!= layout
->section_list().end();
7893 if (strcmp((*p
)->name(), ".sdata") == 0)
7901 Sized_symbol
<size
>* gp
=
7902 static_cast<Sized_symbol
<size
>*>(symtab
->lookup("_gp"));
7905 if (gp
->source() != Symbol::IS_CONSTANT
&& section
!= NULL
)
7906 gp
->init_output_data(gp
->name(), NULL
, section
, MIPS_GP_OFFSET
, 0,
7909 elfcpp::STV_DEFAULT
, 0,
7913 else if (section
!= NULL
)
7915 gp
= static_cast<Sized_symbol
<size
>*>(symtab
->define_in_output_data(
7916 "_gp", NULL
, Symbol_table::PREDEFINED
,
7917 section
, MIPS_GP_OFFSET
, 0,
7920 elfcpp::STV_DEFAULT
,
7926 // Set the dynamic symbol indexes. INDEX is the index of the first
7927 // global dynamic symbol. Pointers to the symbols are stored into the
7928 // vector SYMS. The names are added to DYNPOOL. This returns an
7929 // updated dynamic symbol index.
7931 template<int size
, bool big_endian
>
7933 Target_mips
<size
, big_endian
>::do_set_dynsym_indexes(
7934 std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
7935 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
7936 Versions
* versions
, Symbol_table
* symtab
) const
7938 std::vector
<Symbol
*> non_got_symbols
;
7939 std::vector
<Symbol
*> got_symbols
;
7941 reorder_dyn_symbols
<size
, big_endian
>(dyn_symbols
, &non_got_symbols
,
7944 for (std::vector
<Symbol
*>::iterator p
= non_got_symbols
.begin();
7945 p
!= non_got_symbols
.end();
7950 // Note that SYM may already have a dynamic symbol index, since
7951 // some symbols appear more than once in the symbol table, with
7952 // and without a version.
7954 if (!sym
->has_dynsym_index())
7956 sym
->set_dynsym_index(index
);
7958 syms
->push_back(sym
);
7959 dynpool
->add(sym
->name(), false, NULL
);
7961 // Record any version information.
7962 if (sym
->version() != NULL
)
7963 versions
->record_version(symtab
, dynpool
, sym
);
7965 // If the symbol is defined in a dynamic object and is
7966 // referenced in a regular object, then mark the dynamic
7967 // object as needed. This is used to implement --as-needed.
7968 if (sym
->is_from_dynobj() && sym
->in_reg())
7969 sym
->object()->set_is_needed();
7973 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
7974 p
!= got_symbols
.end();
7978 if (!sym
->has_dynsym_index())
7980 // Record any version information.
7981 if (sym
->version() != NULL
)
7982 versions
->record_version(symtab
, dynpool
, sym
);
7986 index
= versions
->finalize(symtab
, index
, syms
);
7988 int got_sym_count
= 0;
7989 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
7990 p
!= got_symbols
.end();
7995 if (!sym
->has_dynsym_index())
7998 sym
->set_dynsym_index(index
);
8000 syms
->push_back(sym
);
8001 dynpool
->add(sym
->name(), false, NULL
);
8003 // If the symbol is defined in a dynamic object and is
8004 // referenced in a regular object, then mark the dynamic
8005 // object as needed. This is used to implement --as-needed.
8006 if (sym
->is_from_dynobj() && sym
->in_reg())
8007 sym
->object()->set_is_needed();
8011 // Set index of the first symbol that has .got entry.
8012 this->got_
->set_first_global_got_dynsym_index(
8013 got_sym_count
> 0 ? index
- got_sym_count
: -1U);
8015 if (this->mips_stubs_
!= NULL
)
8016 this->mips_stubs_
->set_dynsym_count(index
);
8021 // Create a PLT entry for a global symbol referenced by r_type relocation.
8023 template<int size
, bool big_endian
>
8025 Target_mips
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
8027 Mips_symbol
<size
>* gsym
,
8028 unsigned int r_type
)
8030 if (gsym
->has_lazy_stub() || gsym
->has_plt_offset())
8033 if (this->plt_
== NULL
)
8035 // Create the GOT section first.
8036 this->got_section(symtab
, layout
);
8038 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
8039 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
8040 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
8041 this->got_plt_
, ORDER_DATA
, false);
8043 // The first two entries are reserved.
8044 this->got_plt_
->set_current_data_size(2 * size
/8);
8046 this->plt_
= new Mips_output_data_plt
<size
, big_endian
>(layout
,
8049 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
8051 | elfcpp::SHF_EXECINSTR
),
8052 this->plt_
, ORDER_PLT
, false);
8055 this->plt_
->add_entry(gsym
, r_type
);
8059 // Get the .MIPS.stubs section, creating it if necessary.
8061 template<int size
, bool big_endian
>
8062 Mips_output_data_mips_stubs
<size
, big_endian
>*
8063 Target_mips
<size
, big_endian
>::mips_stubs_section(Layout
* layout
)
8065 if (this->mips_stubs_
== NULL
)
8068 new Mips_output_data_mips_stubs
<size
, big_endian
>(this);
8069 layout
->add_output_section_data(".MIPS.stubs", elfcpp::SHT_PROGBITS
,
8071 | elfcpp::SHF_EXECINSTR
),
8072 this->mips_stubs_
, ORDER_PLT
, false);
8074 return this->mips_stubs_
;
8077 // Get the LA25 stub section, creating it if necessary.
8079 template<int size
, bool big_endian
>
8080 Mips_output_data_la25_stub
<size
, big_endian
>*
8081 Target_mips
<size
, big_endian
>::la25_stub_section(Layout
* layout
)
8083 if (this->la25_stub_
== NULL
)
8085 this->la25_stub_
= new Mips_output_data_la25_stub
<size
, big_endian
>();
8086 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
8088 | elfcpp::SHF_EXECINSTR
),
8089 this->la25_stub_
, ORDER_TEXT
, false);
8091 return this->la25_stub_
;
8094 // Process the relocations to determine unreferenced sections for
8095 // garbage collection.
8097 template<int size
, bool big_endian
>
8099 Target_mips
<size
, big_endian
>::gc_process_relocs(
8100 Symbol_table
* symtab
,
8102 Sized_relobj_file
<size
, big_endian
>* object
,
8103 unsigned int data_shndx
,
8104 unsigned int sh_type
,
8105 const unsigned char* prelocs
,
8107 Output_section
* output_section
,
8108 bool needs_special_offset_handling
,
8109 size_t local_symbol_count
,
8110 const unsigned char* plocal_symbols
)
8112 typedef Target_mips
<size
, big_endian
> Mips
;
8114 if (sh_type
== elfcpp::SHT_REL
)
8116 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8119 gold::gc_process_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8128 needs_special_offset_handling
,
8132 else if (sh_type
== elfcpp::SHT_RELA
)
8134 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8137 gold::gc_process_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8146 needs_special_offset_handling
,
8154 // Scan relocations for a section.
8156 template<int size
, bool big_endian
>
8158 Target_mips
<size
, big_endian
>::scan_relocs(
8159 Symbol_table
* symtab
,
8161 Sized_relobj_file
<size
, big_endian
>* object
,
8162 unsigned int data_shndx
,
8163 unsigned int sh_type
,
8164 const unsigned char* prelocs
,
8166 Output_section
* output_section
,
8167 bool needs_special_offset_handling
,
8168 size_t local_symbol_count
,
8169 const unsigned char* plocal_symbols
)
8171 typedef Target_mips
<size
, big_endian
> Mips
;
8173 if (sh_type
== elfcpp::SHT_REL
)
8175 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8178 gold::scan_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8187 needs_special_offset_handling
,
8191 else if (sh_type
== elfcpp::SHT_RELA
)
8193 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8196 gold::scan_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8205 needs_special_offset_handling
,
8211 template<int size
, bool big_endian
>
8213 Target_mips
<size
, big_endian
>::mips_32bit_flags(elfcpp::Elf_Word flags
)
8215 return ((flags
& elfcpp::EF_MIPS_32BITMODE
) != 0
8216 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_O32
8217 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_EABI32
8218 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_1
8219 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_2
8220 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32
8221 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32R2
);
8224 // Return the MACH for a MIPS e_flags value.
8225 template<int size
, bool big_endian
>
8227 Target_mips
<size
, big_endian
>::elf_mips_mach(elfcpp::Elf_Word flags
)
8229 switch (flags
& elfcpp::EF_MIPS_MACH
)
8231 case elfcpp::E_MIPS_MACH_3900
:
8232 return mach_mips3900
;
8234 case elfcpp::E_MIPS_MACH_4010
:
8235 return mach_mips4010
;
8237 case elfcpp::E_MIPS_MACH_4100
:
8238 return mach_mips4100
;
8240 case elfcpp::E_MIPS_MACH_4111
:
8241 return mach_mips4111
;
8243 case elfcpp::E_MIPS_MACH_4120
:
8244 return mach_mips4120
;
8246 case elfcpp::E_MIPS_MACH_4650
:
8247 return mach_mips4650
;
8249 case elfcpp::E_MIPS_MACH_5400
:
8250 return mach_mips5400
;
8252 case elfcpp::E_MIPS_MACH_5500
:
8253 return mach_mips5500
;
8255 case elfcpp::E_MIPS_MACH_9000
:
8256 return mach_mips9000
;
8258 case elfcpp::E_MIPS_MACH_SB1
:
8259 return mach_mips_sb1
;
8261 case elfcpp::E_MIPS_MACH_LS2E
:
8262 return mach_mips_loongson_2e
;
8264 case elfcpp::E_MIPS_MACH_LS2F
:
8265 return mach_mips_loongson_2f
;
8267 case elfcpp::E_MIPS_MACH_LS3A
:
8268 return mach_mips_loongson_3a
;
8270 case elfcpp::E_MIPS_MACH_OCTEON2
:
8271 return mach_mips_octeon2
;
8273 case elfcpp::E_MIPS_MACH_OCTEON
:
8274 return mach_mips_octeon
;
8276 case elfcpp::E_MIPS_MACH_XLR
:
8277 return mach_mips_xlr
;
8280 switch (flags
& elfcpp::EF_MIPS_ARCH
)
8283 case elfcpp::E_MIPS_ARCH_1
:
8284 return mach_mips3000
;
8286 case elfcpp::E_MIPS_ARCH_2
:
8287 return mach_mips6000
;
8289 case elfcpp::E_MIPS_ARCH_3
:
8290 return mach_mips4000
;
8292 case elfcpp::E_MIPS_ARCH_4
:
8293 return mach_mips8000
;
8295 case elfcpp::E_MIPS_ARCH_5
:
8298 case elfcpp::E_MIPS_ARCH_32
:
8299 return mach_mipsisa32
;
8301 case elfcpp::E_MIPS_ARCH_64
:
8302 return mach_mipsisa64
;
8304 case elfcpp::E_MIPS_ARCH_32R2
:
8305 return mach_mipsisa32r2
;
8307 case elfcpp::E_MIPS_ARCH_64R2
:
8308 return mach_mipsisa64r2
;
8315 // Check whether machine EXTENSION is an extension of machine BASE.
8316 template<int size
, bool big_endian
>
8318 Target_mips
<size
, big_endian
>::mips_mach_extends(unsigned int base
,
8319 unsigned int extension
)
8321 if (extension
== base
)
8324 if ((base
== mach_mipsisa32
)
8325 && this->mips_mach_extends(mach_mipsisa64
, extension
))
8328 if ((base
== mach_mipsisa32r2
)
8329 && this->mips_mach_extends(mach_mipsisa64r2
, extension
))
8332 for (unsigned int i
= 0; i
< this->mips_mach_extensions_
.size(); ++i
)
8333 if (extension
== this->mips_mach_extensions_
[i
].first
)
8335 extension
= this->mips_mach_extensions_
[i
].second
;
8336 if (extension
== base
)
8343 template<int size
, bool big_endian
>
8345 Target_mips
<size
, big_endian
>::merge_processor_specific_flags(
8346 const std::string
& name
, elfcpp::Elf_Word in_flags
, bool dyn_obj
)
8348 // If flags are not set yet, just copy them.
8349 if (!this->are_processor_specific_flags_set())
8351 this->set_processor_specific_flags(in_flags
);
8352 this->mach_
= this->elf_mips_mach(in_flags
);
8356 elfcpp::Elf_Word new_flags
= in_flags
;
8357 elfcpp::Elf_Word old_flags
= this->processor_specific_flags();
8358 elfcpp::Elf_Word merged_flags
= this->processor_specific_flags();
8359 merged_flags
|= new_flags
& elfcpp::EF_MIPS_NOREORDER
;
8361 // Check flag compatibility.
8362 new_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
8363 old_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
8365 // Some IRIX 6 BSD-compatibility objects have this bit set. It
8366 // doesn't seem to matter.
8367 new_flags
&= ~elfcpp::EF_MIPS_XGOT
;
8368 old_flags
&= ~elfcpp::EF_MIPS_XGOT
;
8370 // MIPSpro generates ucode info in n64 objects. Again, we should
8371 // just be able to ignore this.
8372 new_flags
&= ~elfcpp::EF_MIPS_UCODE
;
8373 old_flags
&= ~elfcpp::EF_MIPS_UCODE
;
8375 // DSOs should only be linked with CPIC code.
8377 new_flags
|= elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
;
8379 if (new_flags
== old_flags
)
8381 this->set_processor_specific_flags(merged_flags
);
8385 if (((new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0)
8386 != ((old_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0))
8387 gold_warning(_("%s: linking abicalls files with non-abicalls files"),
8390 if (new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
))
8391 merged_flags
|= elfcpp::EF_MIPS_CPIC
;
8392 if (!(new_flags
& elfcpp::EF_MIPS_PIC
))
8393 merged_flags
&= ~elfcpp::EF_MIPS_PIC
;
8395 new_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
8396 old_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
8398 // Compare the ISAs.
8399 if (mips_32bit_flags(old_flags
) != mips_32bit_flags(new_flags
))
8400 gold_error(_("%s: linking 32-bit code with 64-bit code"), name
.c_str());
8401 else if (!this->mips_mach_extends(this->elf_mips_mach(in_flags
), this->mach_
))
8403 // Output ISA isn't the same as, or an extension of, input ISA.
8404 if (this->mips_mach_extends(this->mach_
, this->elf_mips_mach(in_flags
)))
8406 // Copy the architecture info from input object to output. Also copy
8407 // the 32-bit flag (if set) so that we continue to recognise
8408 // output as a 32-bit binary.
8409 this->mach_
= this->elf_mips_mach(in_flags
);
8410 merged_flags
&= ~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
);
8411 merged_flags
|= (new_flags
& (elfcpp::EF_MIPS_ARCH
8412 | elfcpp::EF_MIPS_MACH
| elfcpp::EF_MIPS_32BITMODE
));
8414 // Copy across the ABI flags if output doesn't use them
8415 // and if that was what caused us to treat input object as 32-bit.
8416 if ((old_flags
& elfcpp::EF_MIPS_ABI
) == 0
8417 && this->mips_32bit_flags(new_flags
)
8418 && !this->mips_32bit_flags(new_flags
& ~elfcpp::EF_MIPS_ABI
))
8419 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ABI
;
8422 // The ISAs aren't compatible.
8423 gold_error(_("%s: linking %s module with previous %s modules"),
8424 name
.c_str(), this->elf_mips_mach_name(in_flags
),
8425 this->elf_mips_mach_name(merged_flags
));
8428 new_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
8429 | elfcpp::EF_MIPS_32BITMODE
));
8430 old_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
8431 | elfcpp::EF_MIPS_32BITMODE
));
8434 if ((new_flags
& elfcpp::EF_MIPS_ABI
) != (old_flags
& elfcpp::EF_MIPS_ABI
))
8436 // Only error if both are set (to different values).
8437 if ((new_flags
& elfcpp::EF_MIPS_ABI
)
8438 && (old_flags
& elfcpp::EF_MIPS_ABI
))
8439 gold_error(_("%s: ABI mismatch: linking %s module with "
8440 "previous %s modules"), name
.c_str(),
8441 this->elf_mips_abi_name(in_flags
),
8442 this->elf_mips_abi_name(merged_flags
));
8444 new_flags
&= ~elfcpp::EF_MIPS_ABI
;
8445 old_flags
&= ~elfcpp::EF_MIPS_ABI
;
8448 // Compare ASEs. Forbid linking MIPS16 and microMIPS ASE modules together
8449 // and allow arbitrary mixing of the remaining ASEs (retain the union).
8450 if ((new_flags
& elfcpp::EF_MIPS_ARCH_ASE
)
8451 != (old_flags
& elfcpp::EF_MIPS_ARCH_ASE
))
8453 int old_micro
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
8454 int new_micro
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
8455 int old_m16
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
8456 int new_m16
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
8457 int micro_mis
= old_m16
&& new_micro
;
8458 int m16_mis
= old_micro
&& new_m16
;
8460 if (m16_mis
|| micro_mis
)
8461 gold_error(_("%s: ASE mismatch: linking %s module with "
8462 "previous %s modules"), name
.c_str(),
8463 m16_mis
? "MIPS16" : "microMIPS",
8464 m16_mis
? "microMIPS" : "MIPS16");
8466 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ARCH_ASE
;
8468 new_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
8469 old_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
8472 // Warn about any other mismatches.
8473 if (new_flags
!= old_flags
)
8474 gold_error(_("%s: uses different e_flags (0x%x) fields than previous "
8475 "modules (0x%x)"), name
.c_str(), new_flags
, old_flags
);
8477 this->set_processor_specific_flags(merged_flags
);
8480 // Adjust ELF file header.
8482 template<int size
, bool big_endian
>
8484 Target_mips
<size
, big_endian
>::do_adjust_elf_header(
8485 unsigned char* view
,
8488 gold_assert(len
== elfcpp::Elf_sizes
<size
>::ehdr_size
);
8490 if (!this->entry_symbol_is_compressed_
)
8493 elfcpp::Ehdr
<size
, big_endian
> ehdr(view
);
8494 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
8496 oehdr
.put_e_entry(ehdr
.get_e_entry() + 1);
8499 // do_make_elf_object to override the same function in the base class.
8500 // We need to use a target-specific sub-class of
8501 // Sized_relobj_file<size, big_endian> to store Mips specific information.
8502 // Hence we need to have our own ELF object creation.
8504 template<int size
, bool big_endian
>
8506 Target_mips
<size
, big_endian
>::do_make_elf_object(
8507 const std::string
& name
,
8508 Input_file
* input_file
,
8509 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
8511 int et
= ehdr
.get_e_type();
8512 // ET_EXEC files are valid input for --just-symbols/-R,
8513 // and we treat them as relocatable objects.
8514 if (et
== elfcpp::ET_REL
8515 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
8517 Mips_relobj
<size
, big_endian
>* obj
=
8518 new Mips_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
8522 else if (et
== elfcpp::ET_DYN
)
8524 // TODO(sasa): Should we create Mips_dynobj?
8525 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
8529 gold_error(_("%s: unsupported ELF file type %d"),
8535 // Finalize the sections.
8537 template <int size
, bool big_endian
>
8539 Target_mips
<size
, big_endian
>::do_finalize_sections(Layout
* layout
,
8540 const Input_objects
* input_objects
,
8541 Symbol_table
* symtab
)
8543 // Add +1 to MIPS16 and microMIPS init_ and _fini symbols so that DT_INIT and
8544 // DT_FINI have correct values.
8545 Mips_symbol
<size
>* init
= static_cast<Mips_symbol
<size
>*>(
8546 symtab
->lookup(parameters
->options().init()));
8547 if (init
!= NULL
&& (init
->is_mips16() || init
->is_micromips()))
8548 init
->set_value(init
->value() | 1);
8549 Mips_symbol
<size
>* fini
= static_cast<Mips_symbol
<size
>*>(
8550 symtab
->lookup(parameters
->options().fini()));
8551 if (fini
!= NULL
&& (fini
->is_mips16() || fini
->is_micromips()))
8552 fini
->set_value(fini
->value() | 1);
8554 // Check whether the entry symbol is mips16 or micromips. This is needed to
8555 // adjust entry address in ELF header.
8556 Mips_symbol
<size
>* entry
=
8557 static_cast<Mips_symbol
<size
>*>(symtab
->lookup(this->entry_symbol_name()));
8558 this->entry_symbol_is_compressed_
= (entry
!= NULL
&& (entry
->is_mips16()
8559 || entry
->is_micromips()));
8561 if (!parameters
->doing_static_link()
8562 && (strcmp(parameters
->options().hash_style(), "gnu") == 0
8563 || strcmp(parameters
->options().hash_style(), "both") == 0))
8565 // .gnu.hash and the MIPS ABI require .dynsym to be sorted in different
8566 // ways. .gnu.hash needs symbols to be grouped by hash code whereas the
8567 // MIPS ABI requires a mapping between the GOT and the symbol table.
8568 gold_error(".gnu.hash is incompatible with the MIPS ABI");
8571 // Check whether the final section that was scanned has HI16 or GOT16
8572 // relocations without the corresponding LO16 part.
8573 if (this->got16_addends_
.size() > 0)
8574 gold_error("Can't find matching LO16 reloc");
8577 this->set_gp(layout
, symtab
);
8579 // Check for any mips16 stub sections that we can discard.
8580 if (!parameters
->options().relocatable())
8582 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8583 p
!= input_objects
->relobj_end();
8586 Mips_relobj
<size
, big_endian
>* object
=
8587 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
8588 object
->discard_mips16_stub_sections(symtab
);
8592 // Merge processor-specific flags.
8593 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8594 p
!= input_objects
->relobj_end();
8597 Mips_relobj
<size
, big_endian
>* relobj
=
8598 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
8600 Input_file::Format format
= relobj
->input_file()->format();
8601 if (format
== Input_file::FORMAT_ELF
)
8603 // Read processor-specific flags in ELF file header.
8604 const unsigned char* pehdr
= relobj
->get_view(
8605 elfcpp::file_header_offset
,
8606 elfcpp::Elf_sizes
<size
>::ehdr_size
,
8609 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
8610 elfcpp::Elf_Word in_flags
= ehdr
.get_e_flags();
8611 // If all input sections will be discarded, don't use this object
8612 // file for merging processor specific flags.
8613 bool should_merge_processor_specific_flags
= false;
8615 for (unsigned int i
= 1; i
< relobj
->shnum(); ++i
)
8616 if (relobj
->output_section(i
) != NULL
)
8618 should_merge_processor_specific_flags
= true;
8622 if (should_merge_processor_specific_flags
)
8623 this->merge_processor_specific_flags(relobj
->name(), in_flags
,
8628 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
8629 p
!= input_objects
->dynobj_end();
8632 Sized_dynobj
<size
, big_endian
>* dynobj
=
8633 static_cast<Sized_dynobj
<size
, big_endian
>*>(*p
);
8635 // Read processor-specific flags.
8636 const unsigned char* pehdr
= dynobj
->get_view(elfcpp::file_header_offset
,
8637 elfcpp::Elf_sizes
<size
>::ehdr_size
,
8640 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
8641 elfcpp::Elf_Word in_flags
= ehdr
.get_e_flags();
8643 this->merge_processor_specific_flags(dynobj
->name(), in_flags
, true);
8646 // Merge .reginfo contents of input objects.
8647 Valtype gprmask
= 0;
8648 Valtype cprmask1
= 0;
8649 Valtype cprmask2
= 0;
8650 Valtype cprmask3
= 0;
8651 Valtype cprmask4
= 0;
8652 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8653 p
!= input_objects
->relobj_end();
8656 Mips_relobj
<size
, big_endian
>* relobj
=
8657 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
8659 gprmask
|= relobj
->gprmask();
8660 cprmask1
|= relobj
->cprmask1();
8661 cprmask2
|= relobj
->cprmask2();
8662 cprmask3
|= relobj
->cprmask3();
8663 cprmask4
|= relobj
->cprmask4();
8666 if (this->plt_
!= NULL
)
8668 // Set final PLT offsets for symbols.
8669 this->plt_section()->set_plt_offsets();
8671 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
8672 // Set STO_MICROMIPS flag if the output has microMIPS code, but only if
8673 // there are no standard PLT entries present.
8674 unsigned char nonvis
= 0;
8675 if (this->is_output_micromips()
8676 && !this->plt_section()->has_standard_entries())
8677 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
8678 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
8679 Symbol_table::PREDEFINED
,
8681 0, 0, elfcpp::STT_FUNC
,
8683 elfcpp::STV_DEFAULT
, nonvis
,
8687 if (this->mips_stubs_
!= NULL
)
8689 // Define _MIPS_STUBS_ at the start of the .MIPS.stubs section.
8690 unsigned char nonvis
= 0;
8691 if (this->is_output_micromips())
8692 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
8693 symtab
->define_in_output_data("_MIPS_STUBS_", NULL
,
8694 Symbol_table::PREDEFINED
,
8696 0, 0, elfcpp::STT_FUNC
,
8698 elfcpp::STV_DEFAULT
, nonvis
,
8702 if (!parameters
->options().relocatable() && !parameters
->doing_static_link())
8703 // In case there is no .got section, create one.
8704 this->got_section(symtab
, layout
);
8706 // Emit any relocs we saved in an attempt to avoid generating COPY
8708 if (this->copy_relocs_
.any_saved_relocs())
8709 this->copy_relocs_
.emit_mips(this->rel_dyn_section(layout
), symtab
, layout
,
8712 // Emit dynamic relocs.
8713 for (typename
std::vector
<Dyn_reloc
>::iterator p
= this->dyn_relocs_
.begin();
8714 p
!= this->dyn_relocs_
.end();
8716 p
->emit(this->rel_dyn_section(layout
), this->got_section(), symtab
);
8718 if (this->has_got_section())
8719 this->got_section()->lay_out_got(layout
, symtab
, input_objects
);
8721 if (this->mips_stubs_
!= NULL
)
8722 this->mips_stubs_
->set_needs_dynsym_value();
8724 // Check for functions that might need $25 to be valid on entry.
8725 // TODO(sasa): Can we do this without iterating over all symbols?
8726 typedef Symbol_visitor_check_symbols
<size
, big_endian
> Symbol_visitor
;
8727 symtab
->for_all_symbols
<size
, Symbol_visitor
>(Symbol_visitor(this, layout
,
8730 // Add NULL segment.
8731 if (!parameters
->options().relocatable())
8732 layout
->make_output_segment(elfcpp::PT_NULL
, 0);
8734 for (Layout::Section_list::const_iterator p
= layout
->section_list().begin();
8735 p
!= layout
->section_list().end();
8738 if ((*p
)->type() == elfcpp::SHT_MIPS_REGINFO
)
8740 Mips_output_section_reginfo
<size
, big_endian
>* reginfo
=
8741 Mips_output_section_reginfo
<size
, big_endian
>::
8742 as_mips_output_section_reginfo(*p
);
8744 reginfo
->set_masks(gprmask
, cprmask1
, cprmask2
, cprmask3
, cprmask4
);
8746 if (!parameters
->options().relocatable())
8748 Output_segment
* reginfo_segment
=
8749 layout
->make_output_segment(elfcpp::PT_MIPS_REGINFO
,
8751 reginfo_segment
->add_output_section_to_nonload(reginfo
,
8757 // Fill in some more dynamic tags.
8758 // TODO(sasa): Add more dynamic tags.
8759 const Reloc_section
* rel_plt
= (this->plt_
== NULL
8760 ? NULL
: this->plt_
->rel_plt());
8761 layout
->add_target_dynamic_tags(true, this->got_
, rel_plt
,
8762 this->rel_dyn_
, true, false);
8764 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
8766 && !parameters
->options().relocatable()
8767 && !parameters
->doing_static_link())
8770 // This element holds a 32-bit version id for the Runtime
8771 // Linker Interface. This will start at integer value 1.
8773 odyn
->add_constant(elfcpp::DT_MIPS_RLD_VERSION
, d_val
);
8776 d_val
= elfcpp::RHF_NOTPOT
;
8777 odyn
->add_constant(elfcpp::DT_MIPS_FLAGS
, d_val
);
8779 // Save layout for using when emiting custom dynamic tags.
8780 this->layout_
= layout
;
8782 // This member holds the base address of the segment.
8783 odyn
->add_custom(elfcpp::DT_MIPS_BASE_ADDRESS
);
8785 // This member holds the number of entries in the .dynsym section.
8786 odyn
->add_custom(elfcpp::DT_MIPS_SYMTABNO
);
8788 // This member holds the index of the first dynamic symbol
8789 // table entry that corresponds to an entry in the global offset table.
8790 odyn
->add_custom(elfcpp::DT_MIPS_GOTSYM
);
8792 // This member holds the number of local GOT entries.
8793 odyn
->add_constant(elfcpp::DT_MIPS_LOCAL_GOTNO
,
8794 this->got_
->get_local_gotno());
8796 if (this->plt_
!= NULL
)
8797 // DT_MIPS_PLTGOT dynamic tag
8798 odyn
->add_section_address(elfcpp::DT_MIPS_PLTGOT
, this->got_plt_
);
8802 // Get the custom dynamic tag value.
8803 template<int size
, bool big_endian
>
8805 Target_mips
<size
, big_endian
>::do_dynamic_tag_custom_value(elfcpp::DT tag
) const
8809 case elfcpp::DT_MIPS_BASE_ADDRESS
:
8811 // The base address of the segment.
8812 // At this point, the segment list has been sorted into final order,
8813 // so just return vaddr of the first readable PT_LOAD segment.
8814 Output_segment
* seg
=
8815 this->layout_
->find_output_segment(elfcpp::PT_LOAD
, elfcpp::PF_R
, 0);
8816 gold_assert(seg
!= NULL
);
8817 return seg
->vaddr();
8820 case elfcpp::DT_MIPS_SYMTABNO
:
8821 // The number of entries in the .dynsym section.
8822 return this->get_dt_mips_symtabno();
8824 case elfcpp::DT_MIPS_GOTSYM
:
8826 // The index of the first dynamic symbol table entry that corresponds
8827 // to an entry in the GOT.
8828 if (this->got_
->first_global_got_dynsym_index() != -1U)
8829 return this->got_
->first_global_got_dynsym_index();
8831 // In case if we don't have global GOT symbols we default to setting
8832 // DT_MIPS_GOTSYM to the same value as DT_MIPS_SYMTABNO.
8833 return this->get_dt_mips_symtabno();
8837 gold_error(_("Unknown dynamic tag 0x%x"), (unsigned int)tag
);
8840 return (unsigned int)-1;
8843 // Relocate section data.
8845 template<int size
, bool big_endian
>
8847 Target_mips
<size
, big_endian
>::relocate_section(
8848 const Relocate_info
<size
, big_endian
>* relinfo
,
8849 unsigned int sh_type
,
8850 const unsigned char* prelocs
,
8852 Output_section
* output_section
,
8853 bool needs_special_offset_handling
,
8854 unsigned char* view
,
8855 Mips_address address
,
8856 section_size_type view_size
,
8857 const Reloc_symbol_changes
* reloc_symbol_changes
)
8859 typedef Target_mips
<size
, big_endian
> Mips
;
8860 typedef typename Target_mips
<size
, big_endian
>::Relocate Mips_relocate
;
8862 if (sh_type
== elfcpp::SHT_REL
)
8864 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8867 gold::relocate_section
<size
, big_endian
, Mips
, Mips_relocate
,
8868 gold::Default_comdat_behavior
, Classify_reloc
>(
8874 needs_special_offset_handling
,
8878 reloc_symbol_changes
);
8880 else if (sh_type
== elfcpp::SHT_RELA
)
8882 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8885 gold::relocate_section
<size
, big_endian
, Mips
, Mips_relocate
,
8886 gold::Default_comdat_behavior
, Classify_reloc
>(
8892 needs_special_offset_handling
,
8896 reloc_symbol_changes
);
8900 // Return the size of a relocation while scanning during a relocatable
8904 mips_get_size_for_reloc(unsigned int r_type
, Relobj
* object
)
8908 case elfcpp::R_MIPS_NONE
:
8909 case elfcpp::R_MIPS_TLS_DTPMOD64
:
8910 case elfcpp::R_MIPS_TLS_DTPREL64
:
8911 case elfcpp::R_MIPS_TLS_TPREL64
:
8914 case elfcpp::R_MIPS_32
:
8915 case elfcpp::R_MIPS_TLS_DTPMOD32
:
8916 case elfcpp::R_MIPS_TLS_DTPREL32
:
8917 case elfcpp::R_MIPS_TLS_TPREL32
:
8918 case elfcpp::R_MIPS_REL32
:
8919 case elfcpp::R_MIPS_PC32
:
8920 case elfcpp::R_MIPS_GPREL32
:
8921 case elfcpp::R_MIPS_JALR
:
8922 case elfcpp::R_MIPS_EH
:
8925 case elfcpp::R_MIPS_16
:
8926 case elfcpp::R_MIPS_HI16
:
8927 case elfcpp::R_MIPS_LO16
:
8928 case elfcpp::R_MIPS_GPREL16
:
8929 case elfcpp::R_MIPS16_HI16
:
8930 case elfcpp::R_MIPS16_LO16
:
8931 case elfcpp::R_MIPS_PC16
:
8932 case elfcpp::R_MIPS_GOT16
:
8933 case elfcpp::R_MIPS16_GOT16
:
8934 case elfcpp::R_MIPS_CALL16
:
8935 case elfcpp::R_MIPS16_CALL16
:
8936 case elfcpp::R_MIPS_GOT_HI16
:
8937 case elfcpp::R_MIPS_CALL_HI16
:
8938 case elfcpp::R_MIPS_GOT_LO16
:
8939 case elfcpp::R_MIPS_CALL_LO16
:
8940 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
8941 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
8942 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
8943 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
8944 case elfcpp::R_MIPS16_GPREL
:
8945 case elfcpp::R_MIPS_GOT_DISP
:
8946 case elfcpp::R_MIPS_LITERAL
:
8947 case elfcpp::R_MIPS_GOT_PAGE
:
8948 case elfcpp::R_MIPS_GOT_OFST
:
8949 case elfcpp::R_MIPS_TLS_GD
:
8950 case elfcpp::R_MIPS_TLS_LDM
:
8951 case elfcpp::R_MIPS_TLS_GOTTPREL
:
8954 // These relocations are not byte sized
8955 case elfcpp::R_MIPS_26
:
8956 case elfcpp::R_MIPS16_26
:
8959 case elfcpp::R_MIPS_COPY
:
8960 case elfcpp::R_MIPS_JUMP_SLOT
:
8961 object
->error(_("unexpected reloc %u in object file"), r_type
);
8965 object
->error(_("unsupported reloc %u in object file"), r_type
);
8970 // Scan the relocs during a relocatable link.
8972 template<int size
, bool big_endian
>
8974 Target_mips
<size
, big_endian
>::scan_relocatable_relocs(
8975 Symbol_table
* symtab
,
8977 Sized_relobj_file
<size
, big_endian
>* object
,
8978 unsigned int data_shndx
,
8979 unsigned int sh_type
,
8980 const unsigned char* prelocs
,
8982 Output_section
* output_section
,
8983 bool needs_special_offset_handling
,
8984 size_t local_symbol_count
,
8985 const unsigned char* plocal_symbols
,
8986 Relocatable_relocs
* rr
)
8988 if (sh_type
== elfcpp::SHT_REL
)
8990 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8992 typedef Mips_scan_relocatable_relocs
<big_endian
, Classify_reloc
>
8993 Scan_relocatable_relocs
;
8995 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_relocatable_relocs
>(
9003 needs_special_offset_handling
,
9008 else if (sh_type
== elfcpp::SHT_RELA
)
9010 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, 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
,
9032 // Scan the relocs for --emit-relocs.
9034 template<int size
, bool big_endian
>
9036 Target_mips
<size
, big_endian
>::emit_relocs_scan(
9037 Symbol_table
* symtab
,
9039 Sized_relobj_file
<size
, big_endian
>* object
,
9040 unsigned int data_shndx
,
9041 unsigned int sh_type
,
9042 const unsigned char* prelocs
,
9044 Output_section
* output_section
,
9045 bool needs_special_offset_handling
,
9046 size_t local_symbol_count
,
9047 const unsigned char* plocal_syms
,
9048 Relocatable_relocs
* rr
)
9050 if (sh_type
== elfcpp::SHT_REL
)
9052 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
9054 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
9055 Emit_relocs_strategy
;
9057 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
9065 needs_special_offset_handling
,
9070 else if (sh_type
== elfcpp::SHT_RELA
)
9072 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, 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
,
9094 // Emit relocations for a section.
9096 template<int size
, bool big_endian
>
9098 Target_mips
<size
, big_endian
>::relocate_relocs(
9099 const Relocate_info
<size
, big_endian
>* relinfo
,
9100 unsigned int sh_type
,
9101 const unsigned char* prelocs
,
9103 Output_section
* output_section
,
9104 typename
elfcpp::Elf_types
<size
>::Elf_Off
9105 offset_in_output_section
,
9106 unsigned char* view
,
9107 Mips_address view_address
,
9108 section_size_type view_size
,
9109 unsigned char* reloc_view
,
9110 section_size_type reloc_view_size
)
9112 if (sh_type
== elfcpp::SHT_REL
)
9114 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
9117 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
9122 offset_in_output_section
,
9129 else if (sh_type
== elfcpp::SHT_RELA
)
9131 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9134 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
9139 offset_in_output_section
,
9150 // Perform target-specific processing in a relocatable link. This is
9151 // only used if we use the relocation strategy RELOC_SPECIAL.
9153 template<int size
, bool big_endian
>
9155 Target_mips
<size
, big_endian
>::relocate_special_relocatable(
9156 const Relocate_info
<size
, big_endian
>* relinfo
,
9157 unsigned int sh_type
,
9158 const unsigned char* preloc_in
,
9160 Output_section
* output_section
,
9161 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
9162 unsigned char* view
,
9163 Mips_address view_address
,
9165 unsigned char* preloc_out
)
9167 // We can only handle REL type relocation sections.
9168 gold_assert(sh_type
== elfcpp::SHT_REL
);
9170 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
9172 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc_write
9175 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
9177 const Mips_address invalid_address
= static_cast<Mips_address
>(0) - 1;
9179 Mips_relobj
<size
, big_endian
>* object
=
9180 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
9181 const unsigned int local_count
= object
->local_symbol_count();
9183 Reltype
reloc(preloc_in
);
9184 Reltype_write
reloc_write(preloc_out
);
9186 elfcpp::Elf_types
<32>::Elf_WXword r_info
= reloc
.get_r_info();
9187 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
9188 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
9190 // Get the new symbol index.
9191 // We only use RELOC_SPECIAL strategy in local relocations.
9192 gold_assert(r_sym
< local_count
);
9194 // We are adjusting a section symbol. We need to find
9195 // the symbol table index of the section symbol for
9196 // the output section corresponding to input section
9197 // in which this symbol is defined.
9199 unsigned int shndx
= object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
9200 gold_assert(is_ordinary
);
9201 Output_section
* os
= object
->output_section(shndx
);
9202 gold_assert(os
!= NULL
);
9203 gold_assert(os
->needs_symtab_index());
9204 unsigned int new_symndx
= os
->symtab_index();
9206 // Get the new offset--the location in the output section where
9207 // this relocation should be applied.
9209 Mips_address offset
= reloc
.get_r_offset();
9210 Mips_address new_offset
;
9211 if (offset_in_output_section
!= invalid_address
)
9212 new_offset
= offset
+ offset_in_output_section
;
9215 section_offset_type sot_offset
=
9216 convert_types
<section_offset_type
, Mips_address
>(offset
);
9217 section_offset_type new_sot_offset
=
9218 output_section
->output_offset(object
, relinfo
->data_shndx
,
9220 gold_assert(new_sot_offset
!= -1);
9221 new_offset
= new_sot_offset
;
9224 // In an object file, r_offset is an offset within the section.
9225 // In an executable or dynamic object, generated by
9226 // --emit-relocs, r_offset is an absolute address.
9227 if (!parameters
->options().relocatable())
9229 new_offset
+= view_address
;
9230 if (offset_in_output_section
!= invalid_address
)
9231 new_offset
-= offset_in_output_section
;
9234 reloc_write
.put_r_offset(new_offset
);
9235 reloc_write
.put_r_info(elfcpp::elf_r_info
<32>(new_symndx
, r_type
));
9237 // Handle the reloc addend.
9238 // The relocation uses a section symbol in the input file.
9239 // We are adjusting it to use a section symbol in the output
9240 // file. The input section symbol refers to some address in
9241 // the input section. We need the relocation in the output
9242 // file to refer to that same address. This adjustment to
9243 // the addend is the same calculation we use for a simple
9244 // absolute relocation for the input section symbol.
9245 Valtype calculated_value
= 0;
9246 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
9248 unsigned char* paddend
= view
+ offset
;
9249 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
9252 case elfcpp::R_MIPS_26
:
9253 reloc_status
= Reloc_funcs::rel26(paddend
, object
, psymval
,
9254 offset_in_output_section
, true, 0, sh_type
== elfcpp::SHT_REL
, NULL
,
9255 false /*TODO(sasa): cross mode jump*/, r_type
, this->jal_to_bal(),
9256 false, &calculated_value
);
9263 // Report any errors.
9264 switch (reloc_status
)
9266 case Reloc_funcs::STATUS_OKAY
:
9268 case Reloc_funcs::STATUS_OVERFLOW
:
9269 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
9270 _("relocation overflow"));
9272 case Reloc_funcs::STATUS_BAD_RELOC
:
9273 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
9274 _("unexpected opcode while processing relocation"));
9281 // Optimize the TLS relocation type based on what we know about the
9282 // symbol. IS_FINAL is true if the final address of this symbol is
9283 // known at link time.
9285 template<int size
, bool big_endian
>
9286 tls::Tls_optimization
9287 Target_mips
<size
, big_endian
>::optimize_tls_reloc(bool, int)
9289 // FIXME: Currently we do not do any TLS optimization.
9290 return tls::TLSOPT_NONE
;
9293 // Scan a relocation for a local symbol.
9295 template<int size
, bool big_endian
>
9297 Target_mips
<size
, big_endian
>::Scan::local(
9298 Symbol_table
* symtab
,
9300 Target_mips
<size
, big_endian
>* target
,
9301 Sized_relobj_file
<size
, big_endian
>* object
,
9302 unsigned int data_shndx
,
9303 Output_section
* output_section
,
9304 const Relatype
* rela
,
9306 unsigned int rel_type
,
9307 unsigned int r_type
,
9308 const elfcpp::Sym
<size
, big_endian
>& lsym
,
9314 Mips_address r_offset
;
9316 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
9318 if (rel_type
== elfcpp::SHT_RELA
)
9320 r_offset
= rela
->get_r_offset();
9321 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
9323 r_addend
= rela
->get_r_addend();
9327 r_offset
= rel
->get_r_offset();
9328 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
9333 Mips_relobj
<size
, big_endian
>* mips_obj
=
9334 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
9336 if (mips_obj
->is_mips16_stub_section(data_shndx
))
9338 mips_obj
->get_mips16_stub_section(data_shndx
)
9339 ->new_local_reloc_found(r_type
, r_sym
);
9342 if (r_type
== elfcpp::R_MIPS_NONE
)
9343 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
9347 if (!mips16_call_reloc(r_type
)
9348 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
9349 // This reloc would need to refer to a MIPS16 hard-float stub, if
9350 // there is one. We ignore MIPS16 stub sections and .pdr section when
9351 // looking for relocs that would need to refer to MIPS16 stubs.
9352 mips_obj
->add_local_non_16bit_call(r_sym
);
9354 if (r_type
== elfcpp::R_MIPS16_26
9355 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
9356 mips_obj
->add_local_16bit_call(r_sym
);
9360 case elfcpp::R_MIPS_GOT16
:
9361 case elfcpp::R_MIPS_CALL16
:
9362 case elfcpp::R_MIPS_CALL_HI16
:
9363 case elfcpp::R_MIPS_CALL_LO16
:
9364 case elfcpp::R_MIPS_GOT_HI16
:
9365 case elfcpp::R_MIPS_GOT_LO16
:
9366 case elfcpp::R_MIPS_GOT_PAGE
:
9367 case elfcpp::R_MIPS_GOT_OFST
:
9368 case elfcpp::R_MIPS_GOT_DISP
:
9369 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9370 case elfcpp::R_MIPS_TLS_GD
:
9371 case elfcpp::R_MIPS_TLS_LDM
:
9372 case elfcpp::R_MIPS16_GOT16
:
9373 case elfcpp::R_MIPS16_CALL16
:
9374 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9375 case elfcpp::R_MIPS16_TLS_GD
:
9376 case elfcpp::R_MIPS16_TLS_LDM
:
9377 case elfcpp::R_MICROMIPS_GOT16
:
9378 case elfcpp::R_MICROMIPS_CALL16
:
9379 case elfcpp::R_MICROMIPS_CALL_HI16
:
9380 case elfcpp::R_MICROMIPS_CALL_LO16
:
9381 case elfcpp::R_MICROMIPS_GOT_HI16
:
9382 case elfcpp::R_MICROMIPS_GOT_LO16
:
9383 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9384 case elfcpp::R_MICROMIPS_GOT_OFST
:
9385 case elfcpp::R_MICROMIPS_GOT_DISP
:
9386 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9387 case elfcpp::R_MICROMIPS_TLS_GD
:
9388 case elfcpp::R_MICROMIPS_TLS_LDM
:
9389 case elfcpp::R_MIPS_EH
:
9390 // We need a GOT section.
9391 target
->got_section(symtab
, layout
);
9398 if (call_lo16_reloc(r_type
)
9399 || got_lo16_reloc(r_type
)
9400 || got_disp_reloc(r_type
)
9401 || eh_reloc(r_type
))
9403 // We may need a local GOT entry for this relocation. We
9404 // don't count R_MIPS_GOT_PAGE because we can estimate the
9405 // maximum number of pages needed by looking at the size of
9406 // the segment. Similar comments apply to R_MIPS*_GOT16 and
9407 // R_MIPS*_CALL16. We don't count R_MIPS_GOT_HI16, or
9408 // R_MIPS_CALL_HI16 because these are always followed by an
9409 // R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
9410 Mips_output_data_got
<size
, big_endian
>* got
=
9411 target
->got_section(symtab
, layout
);
9412 bool is_section_symbol
= lsym
.get_st_type() == elfcpp::STT_SECTION
;
9413 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
, -1U,
9419 case elfcpp::R_MIPS_CALL16
:
9420 case elfcpp::R_MIPS16_CALL16
:
9421 case elfcpp::R_MICROMIPS_CALL16
:
9422 gold_error(_("CALL16 reloc at 0x%lx not against global symbol "),
9423 (unsigned long)r_offset
);
9426 case elfcpp::R_MIPS_GOT_PAGE
:
9427 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9428 case elfcpp::R_MIPS16_GOT16
:
9429 case elfcpp::R_MIPS_GOT16
:
9430 case elfcpp::R_MIPS_GOT_HI16
:
9431 case elfcpp::R_MIPS_GOT_LO16
:
9432 case elfcpp::R_MICROMIPS_GOT16
:
9433 case elfcpp::R_MICROMIPS_GOT_HI16
:
9434 case elfcpp::R_MICROMIPS_GOT_LO16
:
9436 // This relocation needs a page entry in the GOT.
9437 // Get the section contents.
9438 section_size_type view_size
= 0;
9439 const unsigned char* view
= object
->section_contents(data_shndx
,
9443 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
9444 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
9447 if (rel_type
== elfcpp::SHT_REL
&& got16_reloc(r_type
))
9448 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
9449 object
, data_shndx
, r_type
, r_sym
, addend
));
9451 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
, addend
);
9455 case elfcpp::R_MIPS_HI16
:
9456 case elfcpp::R_MIPS16_HI16
:
9457 case elfcpp::R_MICROMIPS_HI16
:
9458 // Record the reloc so that we can check whether the corresponding LO16
9460 if (rel_type
== elfcpp::SHT_REL
)
9461 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
9462 object
, data_shndx
, r_type
, r_sym
, 0));
9465 case elfcpp::R_MIPS_LO16
:
9466 case elfcpp::R_MIPS16_LO16
:
9467 case elfcpp::R_MICROMIPS_LO16
:
9469 if (rel_type
!= elfcpp::SHT_REL
)
9472 // Find corresponding GOT16/HI16 relocation.
9474 // According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
9475 // be immediately following. However, for the IRIX6 ABI, the next
9476 // relocation may be a composed relocation consisting of several
9477 // relocations for the same address. In that case, the R_MIPS_LO16
9478 // relocation may occur as one of these. We permit a similar
9479 // extension in general, as that is useful for GCC.
9481 // In some cases GCC dead code elimination removes the LO16 but
9482 // keeps the corresponding HI16. This is strictly speaking a
9483 // violation of the ABI but not immediately harmful.
9485 typename
std::list
<got16_addend
<size
, big_endian
> >::iterator it
=
9486 target
->got16_addends_
.begin();
9487 while (it
!= target
->got16_addends_
.end())
9489 got16_addend
<size
, big_endian
> _got16_addend
= *it
;
9491 // TODO(sasa): Split got16_addends_ list into two lists - one for
9492 // GOT16 relocs and the other for HI16 relocs.
9494 // Report an error if we find HI16 or GOT16 reloc from the
9495 // previous section without the matching LO16 part.
9496 if (_got16_addend
.object
!= object
9497 || _got16_addend
.shndx
!= data_shndx
)
9499 gold_error("Can't find matching LO16 reloc");
9503 if (_got16_addend
.r_sym
!= r_sym
9504 || !is_matching_lo16_reloc(_got16_addend
.r_type
, r_type
))
9510 // We found a matching HI16 or GOT16 reloc for this LO16 reloc.
9511 // For GOT16, we need to calculate combined addend and record GOT page
9513 if (got16_reloc(_got16_addend
.r_type
))
9516 section_size_type view_size
= 0;
9517 const unsigned char* view
= object
->section_contents(data_shndx
,
9522 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
9523 int32_t addend
= Bits
<16>::sign_extend32(val
& 0xffff);
9525 addend
= (_got16_addend
.addend
<< 16) + addend
;
9526 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
,
9530 it
= target
->got16_addends_
.erase(it
);
9538 case elfcpp::R_MIPS_32
:
9539 case elfcpp::R_MIPS_REL32
:
9540 case elfcpp::R_MIPS_64
:
9542 if (parameters
->options().output_is_position_independent())
9544 // If building a shared library (or a position-independent
9545 // executable), we need to create a dynamic relocation for
9547 if (is_readonly_section(output_section
))
9549 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
9550 rel_dyn
->add_symbolless_local_addend(object
, r_sym
,
9551 elfcpp::R_MIPS_REL32
,
9552 output_section
, data_shndx
,
9558 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9559 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9560 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9561 case elfcpp::R_MIPS_TLS_LDM
:
9562 case elfcpp::R_MIPS16_TLS_LDM
:
9563 case elfcpp::R_MICROMIPS_TLS_LDM
:
9564 case elfcpp::R_MIPS_TLS_GD
:
9565 case elfcpp::R_MIPS16_TLS_GD
:
9566 case elfcpp::R_MICROMIPS_TLS_GD
:
9568 bool output_is_shared
= parameters
->options().shared();
9569 const tls::Tls_optimization optimized_type
9570 = Target_mips
<size
, big_endian
>::optimize_tls_reloc(
9571 !output_is_shared
, r_type
);
9574 case elfcpp::R_MIPS_TLS_GD
:
9575 case elfcpp::R_MIPS16_TLS_GD
:
9576 case elfcpp::R_MICROMIPS_TLS_GD
:
9577 if (optimized_type
== tls::TLSOPT_NONE
)
9579 // Create a pair of GOT entries for the module index and
9580 // dtv-relative offset.
9581 Mips_output_data_got
<size
, big_endian
>* got
=
9582 target
->got_section(symtab
, layout
);
9583 unsigned int shndx
= lsym
.get_st_shndx();
9585 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
9588 object
->error(_("local symbol %u has bad shndx %u"),
9592 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
9597 // FIXME: TLS optimization not supported yet.
9602 case elfcpp::R_MIPS_TLS_LDM
:
9603 case elfcpp::R_MIPS16_TLS_LDM
:
9604 case elfcpp::R_MICROMIPS_TLS_LDM
:
9605 if (optimized_type
== tls::TLSOPT_NONE
)
9607 // We always record LDM symbols as local with index 0.
9608 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
9614 // FIXME: TLS optimization not supported yet.
9618 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9619 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9620 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9621 layout
->set_has_static_tls();
9622 if (optimized_type
== tls::TLSOPT_NONE
)
9624 // Create a GOT entry for the tp-relative offset.
9625 Mips_output_data_got
<size
, big_endian
>* got
=
9626 target
->got_section(symtab
, layout
);
9627 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
9632 // FIXME: TLS optimization not supported yet.
9647 // Refuse some position-dependent relocations when creating a
9648 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
9649 // not PIC, but we can create dynamic relocations and the result
9650 // will be fine. Also do not refuse R_MIPS_LO16, which can be
9651 // combined with R_MIPS_GOT16.
9652 if (parameters
->options().shared())
9656 case elfcpp::R_MIPS16_HI16
:
9657 case elfcpp::R_MIPS_HI16
:
9658 case elfcpp::R_MICROMIPS_HI16
:
9659 // Don't refuse a high part relocation if it's against
9660 // no symbol (e.g. part of a compound relocation).
9666 case elfcpp::R_MIPS16_26
:
9667 case elfcpp::R_MIPS_26
:
9668 case elfcpp::R_MICROMIPS_26_S1
:
9669 gold_error(_("%s: relocation %u against `%s' can not be used when "
9670 "making a shared object; recompile with -fPIC"),
9671 object
->name().c_str(), r_type
, "a local symbol");
9678 template<int size
, bool big_endian
>
9680 Target_mips
<size
, big_endian
>::Scan::local(
9681 Symbol_table
* symtab
,
9683 Target_mips
<size
, big_endian
>* target
,
9684 Sized_relobj_file
<size
, big_endian
>* object
,
9685 unsigned int data_shndx
,
9686 Output_section
* output_section
,
9687 const Reltype
& reloc
,
9688 unsigned int r_type
,
9689 const elfcpp::Sym
<size
, big_endian
>& lsym
,
9702 (const Relatype
*) NULL
,
9706 lsym
, is_discarded
);
9710 template<int size
, bool big_endian
>
9712 Target_mips
<size
, big_endian
>::Scan::local(
9713 Symbol_table
* symtab
,
9715 Target_mips
<size
, big_endian
>* target
,
9716 Sized_relobj_file
<size
, big_endian
>* object
,
9717 unsigned int data_shndx
,
9718 Output_section
* output_section
,
9719 const Relatype
& reloc
,
9720 unsigned int r_type
,
9721 const elfcpp::Sym
<size
, big_endian
>& lsym
,
9735 (const Reltype
*) NULL
,
9738 lsym
, is_discarded
);
9741 // Scan a relocation for a global symbol.
9743 template<int size
, bool big_endian
>
9745 Target_mips
<size
, big_endian
>::Scan::global(
9746 Symbol_table
* symtab
,
9748 Target_mips
<size
, big_endian
>* target
,
9749 Sized_relobj_file
<size
, big_endian
>* object
,
9750 unsigned int data_shndx
,
9751 Output_section
* output_section
,
9752 const Relatype
* rela
,
9754 unsigned int rel_type
,
9755 unsigned int r_type
,
9758 Mips_address r_offset
;
9760 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
9762 if (rel_type
== elfcpp::SHT_RELA
)
9764 r_offset
= rela
->get_r_offset();
9765 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
9767 r_addend
= rela
->get_r_addend();
9771 r_offset
= rel
->get_r_offset();
9772 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
9777 Mips_relobj
<size
, big_endian
>* mips_obj
=
9778 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
9779 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
9781 if (mips_obj
->is_mips16_stub_section(data_shndx
))
9783 mips_obj
->get_mips16_stub_section(data_shndx
)
9784 ->new_global_reloc_found(r_type
, mips_sym
);
9787 if (r_type
== elfcpp::R_MIPS_NONE
)
9788 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
9792 if (!mips16_call_reloc(r_type
)
9793 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
9794 // This reloc would need to refer to a MIPS16 hard-float stub, if
9795 // there is one. We ignore MIPS16 stub sections and .pdr section when
9796 // looking for relocs that would need to refer to MIPS16 stubs.
9797 mips_sym
->set_need_fn_stub();
9799 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
9800 // section. We check here to avoid creating a dynamic reloc against
9801 // _GLOBAL_OFFSET_TABLE_.
9802 if (!target
->has_got_section()
9803 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9804 target
->got_section(symtab
, layout
);
9806 // We need PLT entries if there are static-only relocations against
9807 // an externally-defined function. This can technically occur for
9808 // shared libraries if there are branches to the symbol, although it
9809 // is unlikely that this will be used in practice due to the short
9810 // ranges involved. It can occur for any relative or absolute relocation
9811 // in executables; in that case, the PLT entry becomes the function's
9812 // canonical address.
9813 bool static_reloc
= false;
9815 // Set CAN_MAKE_DYNAMIC to true if we can convert this
9816 // relocation into a dynamic one.
9817 bool can_make_dynamic
= false;
9820 case elfcpp::R_MIPS_GOT16
:
9821 case elfcpp::R_MIPS_CALL16
:
9822 case elfcpp::R_MIPS_CALL_HI16
:
9823 case elfcpp::R_MIPS_CALL_LO16
:
9824 case elfcpp::R_MIPS_GOT_HI16
:
9825 case elfcpp::R_MIPS_GOT_LO16
:
9826 case elfcpp::R_MIPS_GOT_PAGE
:
9827 case elfcpp::R_MIPS_GOT_OFST
:
9828 case elfcpp::R_MIPS_GOT_DISP
:
9829 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9830 case elfcpp::R_MIPS_TLS_GD
:
9831 case elfcpp::R_MIPS_TLS_LDM
:
9832 case elfcpp::R_MIPS16_GOT16
:
9833 case elfcpp::R_MIPS16_CALL16
:
9834 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9835 case elfcpp::R_MIPS16_TLS_GD
:
9836 case elfcpp::R_MIPS16_TLS_LDM
:
9837 case elfcpp::R_MICROMIPS_GOT16
:
9838 case elfcpp::R_MICROMIPS_CALL16
:
9839 case elfcpp::R_MICROMIPS_CALL_HI16
:
9840 case elfcpp::R_MICROMIPS_CALL_LO16
:
9841 case elfcpp::R_MICROMIPS_GOT_HI16
:
9842 case elfcpp::R_MICROMIPS_GOT_LO16
:
9843 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9844 case elfcpp::R_MICROMIPS_GOT_OFST
:
9845 case elfcpp::R_MICROMIPS_GOT_DISP
:
9846 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9847 case elfcpp::R_MICROMIPS_TLS_GD
:
9848 case elfcpp::R_MICROMIPS_TLS_LDM
:
9849 case elfcpp::R_MIPS_EH
:
9850 // We need a GOT section.
9851 target
->got_section(symtab
, layout
);
9854 // This is just a hint; it can safely be ignored. Don't set
9855 // has_static_relocs for the corresponding symbol.
9856 case elfcpp::R_MIPS_JALR
:
9857 case elfcpp::R_MICROMIPS_JALR
:
9860 case elfcpp::R_MIPS_GPREL16
:
9861 case elfcpp::R_MIPS_GPREL32
:
9862 case elfcpp::R_MIPS16_GPREL
:
9863 case elfcpp::R_MICROMIPS_GPREL16
:
9865 // GP-relative relocations always resolve to a definition in a
9866 // regular input file, ignoring the one-definition rule. This is
9867 // important for the GP setup sequence in NewABI code, which
9868 // always resolves to a local function even if other relocations
9869 // against the symbol wouldn't.
9870 //constrain_symbol_p = FALSE;
9873 case elfcpp::R_MIPS_32
:
9874 case elfcpp::R_MIPS_REL32
:
9875 case elfcpp::R_MIPS_64
:
9876 if ((parameters
->options().shared()
9877 || (strcmp(gsym
->name(), "__gnu_local_gp") != 0
9878 && (!is_readonly_section(output_section
)
9879 || mips_obj
->is_pic())))
9880 && (output_section
->flags() & elfcpp::SHF_ALLOC
) != 0)
9882 if (r_type
!= elfcpp::R_MIPS_REL32
)
9883 mips_sym
->set_pointer_equality_needed();
9884 can_make_dynamic
= true;
9890 // Most static relocations require pointer equality, except
9892 mips_sym
->set_pointer_equality_needed();
9896 case elfcpp::R_MIPS_26
:
9897 case elfcpp::R_MIPS_PC16
:
9898 case elfcpp::R_MIPS16_26
:
9899 case elfcpp::R_MICROMIPS_26_S1
:
9900 case elfcpp::R_MICROMIPS_PC7_S1
:
9901 case elfcpp::R_MICROMIPS_PC10_S1
:
9902 case elfcpp::R_MICROMIPS_PC16_S1
:
9903 case elfcpp::R_MICROMIPS_PC23_S2
:
9904 static_reloc
= true;
9905 mips_sym
->set_has_static_relocs();
9909 // If there are call relocations against an externally-defined symbol,
9910 // see whether we can create a MIPS lazy-binding stub for it. We can
9911 // only do this if all references to the function are through call
9912 // relocations, and in that case, the traditional lazy-binding stubs
9913 // are much more efficient than PLT entries.
9916 case elfcpp::R_MIPS16_CALL16
:
9917 case elfcpp::R_MIPS_CALL16
:
9918 case elfcpp::R_MIPS_CALL_HI16
:
9919 case elfcpp::R_MIPS_CALL_LO16
:
9920 case elfcpp::R_MIPS_JALR
:
9921 case elfcpp::R_MICROMIPS_CALL16
:
9922 case elfcpp::R_MICROMIPS_CALL_HI16
:
9923 case elfcpp::R_MICROMIPS_CALL_LO16
:
9924 case elfcpp::R_MICROMIPS_JALR
:
9925 if (!mips_sym
->no_lazy_stub())
9927 if ((mips_sym
->needs_plt_entry() && mips_sym
->is_from_dynobj())
9928 // Calls from shared objects to undefined symbols of type
9929 // STT_NOTYPE need lazy-binding stub.
9930 || (mips_sym
->is_undefined() && parameters
->options().shared()))
9931 target
->mips_stubs_section(layout
)->make_entry(mips_sym
);
9936 // We must not create a stub for a symbol that has relocations
9937 // related to taking the function's address.
9938 mips_sym
->set_no_lazy_stub();
9939 target
->remove_lazy_stub_entry(mips_sym
);
9944 if (relocation_needs_la25_stub
<size
, big_endian
>(mips_obj
, r_type
,
9945 mips_sym
->is_mips16()))
9946 mips_sym
->set_has_nonpic_branches();
9948 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
9949 // and has a special meaning.
9950 bool gp_disp_against_hi16
= (!mips_obj
->is_newabi()
9951 && strcmp(gsym
->name(), "_gp_disp") == 0
9952 && (hi16_reloc(r_type
) || lo16_reloc(r_type
)));
9953 if (static_reloc
&& gsym
->needs_plt_entry())
9955 target
->make_plt_entry(symtab
, layout
, mips_sym
, r_type
);
9957 // Since this is not a PC-relative relocation, we may be
9958 // taking the address of a function. In that case we need to
9959 // set the entry in the dynamic symbol table to the address of
9961 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
9963 gsym
->set_needs_dynsym_value();
9964 // We distinguish between PLT entries and lazy-binding stubs by
9965 // giving the former an st_other value of STO_MIPS_PLT. Set the
9966 // flag if there are any relocations in the binary where pointer
9967 // equality matters.
9968 if (mips_sym
->pointer_equality_needed())
9969 mips_sym
->set_mips_plt();
9972 if ((static_reloc
|| can_make_dynamic
) && !gp_disp_against_hi16
)
9974 // Absolute addressing relocations.
9975 // Make a dynamic relocation if necessary.
9976 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
9978 if (gsym
->may_need_copy_reloc())
9980 target
->copy_reloc(symtab
, layout
, object
, data_shndx
,
9981 output_section
, gsym
, r_type
, r_offset
);
9983 else if (can_make_dynamic
)
9985 // Create .rel.dyn section.
9986 target
->rel_dyn_section(layout
);
9987 target
->dynamic_reloc(mips_sym
, elfcpp::R_MIPS_REL32
, mips_obj
,
9988 data_shndx
, output_section
, r_offset
);
9991 gold_error(_("non-dynamic relocations refer to dynamic symbol %s"),
9996 bool for_call
= false;
9999 case elfcpp::R_MIPS_CALL16
:
10000 case elfcpp::R_MIPS16_CALL16
:
10001 case elfcpp::R_MICROMIPS_CALL16
:
10002 case elfcpp::R_MIPS_CALL_HI16
:
10003 case elfcpp::R_MIPS_CALL_LO16
:
10004 case elfcpp::R_MICROMIPS_CALL_HI16
:
10005 case elfcpp::R_MICROMIPS_CALL_LO16
:
10009 case elfcpp::R_MIPS16_GOT16
:
10010 case elfcpp::R_MIPS_GOT16
:
10011 case elfcpp::R_MIPS_GOT_HI16
:
10012 case elfcpp::R_MIPS_GOT_LO16
:
10013 case elfcpp::R_MICROMIPS_GOT16
:
10014 case elfcpp::R_MICROMIPS_GOT_HI16
:
10015 case elfcpp::R_MICROMIPS_GOT_LO16
:
10016 case elfcpp::R_MIPS_GOT_DISP
:
10017 case elfcpp::R_MICROMIPS_GOT_DISP
:
10018 case elfcpp::R_MIPS_EH
:
10020 // The symbol requires a GOT entry.
10021 Mips_output_data_got
<size
, big_endian
>* got
=
10022 target
->got_section(symtab
, layout
);
10023 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10025 mips_sym
->set_global_got_area(GGA_NORMAL
);
10029 case elfcpp::R_MIPS_GOT_PAGE
:
10030 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10032 // This relocation needs a page entry in the GOT.
10033 // Get the section contents.
10034 section_size_type view_size
= 0;
10035 const unsigned char* view
=
10036 object
->section_contents(data_shndx
, &view_size
, false);
10039 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
10040 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
10042 Mips_output_data_got
<size
, big_endian
>* got
=
10043 target
->got_section(symtab
, layout
);
10044 got
->record_got_page_entry(mips_obj
, r_sym
, addend
);
10046 // If this is a global, overridable symbol, GOT_PAGE will
10047 // decay to GOT_DISP, so we'll need a GOT entry for it.
10048 bool def_regular
= (mips_sym
->source() == Symbol::FROM_OBJECT
10049 && !mips_sym
->object()->is_dynamic()
10050 && !mips_sym
->is_undefined());
10052 || (parameters
->options().output_is_position_independent()
10053 && !parameters
->options().Bsymbolic()
10054 && !mips_sym
->is_forced_local()))
10056 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10058 mips_sym
->set_global_got_area(GGA_NORMAL
);
10063 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10064 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10065 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10066 case elfcpp::R_MIPS_TLS_LDM
:
10067 case elfcpp::R_MIPS16_TLS_LDM
:
10068 case elfcpp::R_MICROMIPS_TLS_LDM
:
10069 case elfcpp::R_MIPS_TLS_GD
:
10070 case elfcpp::R_MIPS16_TLS_GD
:
10071 case elfcpp::R_MICROMIPS_TLS_GD
:
10073 const bool is_final
= gsym
->final_value_is_known();
10074 const tls::Tls_optimization optimized_type
=
10075 Target_mips
<size
, big_endian
>::optimize_tls_reloc(is_final
, r_type
);
10079 case elfcpp::R_MIPS_TLS_GD
:
10080 case elfcpp::R_MIPS16_TLS_GD
:
10081 case elfcpp::R_MICROMIPS_TLS_GD
:
10082 if (optimized_type
== tls::TLSOPT_NONE
)
10084 // Create a pair of GOT entries for the module index and
10085 // dtv-relative offset.
10086 Mips_output_data_got
<size
, big_endian
>* got
=
10087 target
->got_section(symtab
, layout
);
10088 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10093 // FIXME: TLS optimization not supported yet.
10094 gold_unreachable();
10098 case elfcpp::R_MIPS_TLS_LDM
:
10099 case elfcpp::R_MIPS16_TLS_LDM
:
10100 case elfcpp::R_MICROMIPS_TLS_LDM
:
10101 if (optimized_type
== tls::TLSOPT_NONE
)
10103 // We always record LDM symbols as local with index 0.
10104 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
10110 // FIXME: TLS optimization not supported yet.
10111 gold_unreachable();
10114 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10115 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10116 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10117 layout
->set_has_static_tls();
10118 if (optimized_type
== tls::TLSOPT_NONE
)
10120 // Create a GOT entry for the tp-relative offset.
10121 Mips_output_data_got
<size
, big_endian
>* got
=
10122 target
->got_section(symtab
, layout
);
10123 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10128 // FIXME: TLS optimization not supported yet.
10129 gold_unreachable();
10134 gold_unreachable();
10138 case elfcpp::R_MIPS_COPY
:
10139 case elfcpp::R_MIPS_JUMP_SLOT
:
10140 // These are relocations which should only be seen by the
10141 // dynamic linker, and should never be seen here.
10142 gold_error(_("%s: unexpected reloc %u in object file"),
10143 object
->name().c_str(), r_type
);
10150 // Refuse some position-dependent relocations when creating a
10151 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
10152 // not PIC, but we can create dynamic relocations and the result
10153 // will be fine. Also do not refuse R_MIPS_LO16, which can be
10154 // combined with R_MIPS_GOT16.
10155 if (parameters
->options().shared())
10159 case elfcpp::R_MIPS16_HI16
:
10160 case elfcpp::R_MIPS_HI16
:
10161 case elfcpp::R_MICROMIPS_HI16
:
10162 // Don't refuse a high part relocation if it's against
10163 // no symbol (e.g. part of a compound relocation).
10167 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
10168 // and has a special meaning.
10169 if (!mips_obj
->is_newabi() && strcmp(gsym
->name(), "_gp_disp") == 0)
10174 case elfcpp::R_MIPS16_26
:
10175 case elfcpp::R_MIPS_26
:
10176 case elfcpp::R_MICROMIPS_26_S1
:
10177 gold_error(_("%s: relocation %u against `%s' can not be used when "
10178 "making a shared object; recompile with -fPIC"),
10179 object
->name().c_str(), r_type
, gsym
->name());
10186 template<int size
, bool big_endian
>
10188 Target_mips
<size
, big_endian
>::Scan::global(
10189 Symbol_table
* symtab
,
10191 Target_mips
<size
, big_endian
>* target
,
10192 Sized_relobj_file
<size
, big_endian
>* object
,
10193 unsigned int data_shndx
,
10194 Output_section
* output_section
,
10195 const Relatype
& reloc
,
10196 unsigned int r_type
,
10207 (const Reltype
*) NULL
,
10213 template<int size
, bool big_endian
>
10215 Target_mips
<size
, big_endian
>::Scan::global(
10216 Symbol_table
* symtab
,
10218 Target_mips
<size
, big_endian
>* target
,
10219 Sized_relobj_file
<size
, big_endian
>* object
,
10220 unsigned int data_shndx
,
10221 Output_section
* output_section
,
10222 const Reltype
& reloc
,
10223 unsigned int r_type
,
10233 (const Relatype
*) NULL
,
10240 // Return whether a R_MIPS_32/R_MIPS64 relocation needs to be applied.
10241 // In cases where Scan::local() or Scan::global() has created
10242 // a dynamic relocation, the addend of the relocation is carried
10243 // in the data, and we must not apply the static relocation.
10245 template<int size
, bool big_endian
>
10247 Target_mips
<size
, big_endian
>::Relocate::should_apply_static_reloc(
10248 const Mips_symbol
<size
>* gsym
,
10249 unsigned int r_type
,
10250 Output_section
* output_section
,
10251 Target_mips
* target
)
10253 // If the output section is not allocated, then we didn't call
10254 // scan_relocs, we didn't create a dynamic reloc, and we must apply
10256 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
10263 // For global symbols, we use the same helper routines used in the
10265 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
))
10266 && !gsym
->may_need_copy_reloc())
10268 // We have generated dynamic reloc (R_MIPS_REL32).
10270 bool multi_got
= false;
10271 if (target
->has_got_section())
10272 multi_got
= target
->got_section()->multi_got();
10273 bool has_got_offset
;
10275 has_got_offset
= gsym
->has_got_offset(GOT_TYPE_STANDARD
);
10277 has_got_offset
= gsym
->global_gotoffset() != -1U;
10278 if (!has_got_offset
)
10281 // Apply the relocation only if the symbol is in the local got.
10282 // Do not apply the relocation if the symbol is in the global
10284 return symbol_references_local(gsym
, gsym
->has_dynsym_index());
10287 // We have not generated dynamic reloc.
10292 // Perform a relocation.
10294 template<int size
, bool big_endian
>
10296 Target_mips
<size
, big_endian
>::Relocate::relocate(
10297 const Relocate_info
<size
, big_endian
>* relinfo
,
10298 unsigned int rel_type
,
10299 Target_mips
* target
,
10300 Output_section
* output_section
,
10302 const unsigned char* preloc
,
10303 const Sized_symbol
<size
>* gsym
,
10304 const Symbol_value
<size
>* psymval
,
10305 unsigned char* view
,
10306 Mips_address address
,
10309 Mips_address r_offset
;
10310 unsigned int r_sym
;
10311 unsigned int r_type
;
10312 unsigned int r_type2
;
10313 unsigned int r_type3
;
10314 unsigned char r_ssym
;
10315 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
10317 if (rel_type
== elfcpp::SHT_RELA
)
10319 const Relatype
rela(preloc
);
10320 r_offset
= rela
.get_r_offset();
10321 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10323 r_type
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10325 r_type2
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10326 get_r_type2(&rela
);
10327 r_type3
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10328 get_r_type3(&rela
);
10329 r_ssym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10331 r_addend
= rela
.get_r_addend();
10335 const Reltype
rel(preloc
);
10336 r_offset
= rel
.get_r_offset();
10337 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
10339 r_type
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
10347 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
10348 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
10350 Mips_relobj
<size
, big_endian
>* object
=
10351 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
10353 bool target_is_16_bit_code
= false;
10354 bool target_is_micromips_code
= false;
10355 bool cross_mode_jump
;
10357 Symbol_value
<size
> symval
;
10359 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
10361 bool changed_symbol_value
= false;
10364 target_is_16_bit_code
= object
->local_symbol_is_mips16(r_sym
);
10365 target_is_micromips_code
= object
->local_symbol_is_micromips(r_sym
);
10366 if (target_is_16_bit_code
|| target_is_micromips_code
)
10368 // MIPS16/microMIPS text labels should be treated as odd.
10369 symval
.set_output_value(psymval
->value(object
, 1));
10371 changed_symbol_value
= true;
10376 target_is_16_bit_code
= mips_sym
->is_mips16();
10377 target_is_micromips_code
= mips_sym
->is_micromips();
10379 // If this is a mips16/microMIPS text symbol, add 1 to the value to make
10380 // it odd. This will cause something like .word SYM to come up with
10381 // the right value when it is loaded into the PC.
10383 if ((mips_sym
->is_mips16() || mips_sym
->is_micromips())
10384 && psymval
->value(object
, 0) != 0)
10386 symval
.set_output_value(psymval
->value(object
, 0) | 1);
10388 changed_symbol_value
= true;
10391 // Pick the value to use for symbols defined in shared objects.
10392 if (mips_sym
->use_plt_offset(Scan::get_reference_flags(r_type
))
10393 || mips_sym
->has_lazy_stub())
10395 Mips_address value
;
10396 if (!mips_sym
->has_lazy_stub())
10398 // Prefer a standard MIPS PLT entry.
10399 if (mips_sym
->has_mips_plt_offset())
10401 value
= target
->plt_section()->mips_entry_address(mips_sym
);
10402 target_is_micromips_code
= false;
10403 target_is_16_bit_code
= false;
10407 value
= (target
->plt_section()->comp_entry_address(mips_sym
)
10409 if (target
->is_output_micromips())
10410 target_is_micromips_code
= true;
10412 target_is_16_bit_code
= true;
10416 value
= target
->mips_stubs_section()->stub_address(mips_sym
);
10418 symval
.set_output_value(value
);
10423 // TRUE if the symbol referred to by this relocation is "_gp_disp".
10424 // Note that such a symbol must always be a global symbol.
10425 bool gp_disp
= (gsym
!= NULL
&& (strcmp(gsym
->name(), "_gp_disp") == 0)
10426 && !object
->is_newabi());
10428 // TRUE if the symbol referred to by this relocation is "__gnu_local_gp".
10429 // Note that such a symbol must always be a global symbol.
10430 bool gnu_local_gp
= gsym
&& (strcmp(gsym
->name(), "__gnu_local_gp") == 0);
10435 if (!hi16_reloc(r_type
) && !lo16_reloc(r_type
))
10436 gold_error_at_location(relinfo
, relnum
, r_offset
,
10437 _("relocations against _gp_disp are permitted only"
10438 " with R_MIPS_HI16 and R_MIPS_LO16 relocations."));
10440 else if (gnu_local_gp
)
10442 // __gnu_local_gp is _gp symbol.
10443 symval
.set_output_value(target
->adjusted_gp_value(object
));
10447 // If this is a reference to a 16-bit function with a stub, we need
10448 // to redirect the relocation to the stub unless:
10450 // (a) the relocation is for a MIPS16 JAL;
10452 // (b) the relocation is for a MIPS16 PIC call, and there are no
10453 // non-MIPS16 uses of the GOT slot; or
10455 // (c) the section allows direct references to MIPS16 functions.
10456 if (r_type
!= elfcpp::R_MIPS16_26
10457 && !parameters
->options().relocatable()
10458 && ((mips_sym
!= NULL
10459 && mips_sym
->has_mips16_fn_stub()
10460 && (r_type
!= elfcpp::R_MIPS16_CALL16
|| mips_sym
->need_fn_stub()))
10461 || (mips_sym
== NULL
10462 && object
->get_local_mips16_fn_stub(r_sym
) != NULL
))
10463 && !object
->section_allows_mips16_refs(relinfo
->data_shndx
))
10465 // This is a 32- or 64-bit call to a 16-bit function. We should
10466 // have already noticed that we were going to need the
10468 Mips_address value
;
10469 if (mips_sym
== NULL
)
10470 value
= object
->get_local_mips16_fn_stub(r_sym
)->output_address();
10473 gold_assert(mips_sym
->need_fn_stub());
10474 if (mips_sym
->has_la25_stub())
10475 value
= target
->la25_stub_section()->stub_address(mips_sym
);
10478 value
= mips_sym
->template
10479 get_mips16_fn_stub
<big_endian
>()->output_address();
10482 symval
.set_output_value(value
);
10484 changed_symbol_value
= true;
10486 // The target is 16-bit, but the stub isn't.
10487 target_is_16_bit_code
= false;
10489 // If this is a MIPS16 call with a stub, that is made through the PLT or
10490 // to a standard MIPS function, we need to redirect the call to the stub.
10491 // Note that we specifically exclude R_MIPS16_CALL16 from this behavior;
10492 // indirect calls should use an indirect stub instead.
10493 else if (r_type
== elfcpp::R_MIPS16_26
&& !parameters
->options().relocatable()
10494 && ((mips_sym
!= NULL
10495 && (mips_sym
->has_mips16_call_stub()
10496 || mips_sym
->has_mips16_call_fp_stub()))
10497 || (mips_sym
== NULL
10498 && object
->get_local_mips16_call_stub(r_sym
) != NULL
))
10499 && ((mips_sym
!= NULL
&& mips_sym
->has_plt_offset())
10500 || !target_is_16_bit_code
))
10502 Mips16_stub_section
<size
, big_endian
>* call_stub
;
10503 if (mips_sym
== NULL
)
10504 call_stub
= object
->get_local_mips16_call_stub(r_sym
);
10507 // If both call_stub and call_fp_stub are defined, we can figure
10508 // out which one to use by checking which one appears in the input
10510 if (mips_sym
->has_mips16_call_stub()
10511 && mips_sym
->has_mips16_call_fp_stub())
10514 for (unsigned int i
= 1; i
< object
->shnum(); ++i
)
10516 if (object
->is_mips16_call_fp_stub_section(i
))
10518 call_stub
= mips_sym
->template
10519 get_mips16_call_fp_stub
<big_endian
>();
10524 if (call_stub
== NULL
)
10526 mips_sym
->template get_mips16_call_stub
<big_endian
>();
10528 else if (mips_sym
->has_mips16_call_stub())
10529 call_stub
= mips_sym
->template get_mips16_call_stub
<big_endian
>();
10531 call_stub
= mips_sym
->template get_mips16_call_fp_stub
<big_endian
>();
10534 symval
.set_output_value(call_stub
->output_address());
10536 changed_symbol_value
= true;
10538 // If this is a direct call to a PIC function, redirect to the
10540 else if (mips_sym
!= NULL
10541 && mips_sym
->has_la25_stub()
10542 && relocation_needs_la25_stub
<size
, big_endian
>(
10543 object
, r_type
, target_is_16_bit_code
))
10545 Mips_address value
= target
->la25_stub_section()->stub_address(mips_sym
);
10546 if (mips_sym
->is_micromips())
10548 symval
.set_output_value(value
);
10551 // For direct MIPS16 and microMIPS calls make sure the compressed PLT
10552 // entry is used if a standard PLT entry has also been made.
10553 else if ((r_type
== elfcpp::R_MIPS16_26
10554 || r_type
== elfcpp::R_MICROMIPS_26_S1
)
10555 && !parameters
->options().relocatable()
10556 && mips_sym
!= NULL
10557 && mips_sym
->has_plt_offset()
10558 && mips_sym
->has_comp_plt_offset()
10559 && mips_sym
->has_mips_plt_offset())
10561 Mips_address value
= (target
->plt_section()->comp_entry_address(mips_sym
)
10563 symval
.set_output_value(value
);
10566 target_is_16_bit_code
= !target
->is_output_micromips();
10567 target_is_micromips_code
= target
->is_output_micromips();
10570 // Make sure MIPS16 and microMIPS are not used together.
10571 if ((r_type
== elfcpp::R_MIPS16_26
&& target_is_micromips_code
)
10572 || (micromips_branch_reloc(r_type
) && target_is_16_bit_code
))
10574 gold_error(_("MIPS16 and microMIPS functions cannot call each other"));
10577 // Calls from 16-bit code to 32-bit code and vice versa require the
10578 // mode change. However, we can ignore calls to undefined weak symbols,
10579 // which should never be executed at runtime. This exception is important
10580 // because the assembly writer may have "known" that any definition of the
10581 // symbol would be 16-bit code, and that direct jumps were therefore
10584 (!parameters
->options().relocatable()
10585 && !(gsym
!= NULL
&& gsym
->is_weak_undefined())
10586 && ((r_type
== elfcpp::R_MIPS16_26
&& !target_is_16_bit_code
)
10587 || (r_type
== elfcpp::R_MICROMIPS_26_S1
&& !target_is_micromips_code
)
10588 || ((r_type
== elfcpp::R_MIPS_26
|| r_type
== elfcpp::R_MIPS_JALR
)
10589 && (target_is_16_bit_code
|| target_is_micromips_code
))));
10591 bool local
= (mips_sym
== NULL
10592 || (mips_sym
->got_only_for_calls()
10593 ? symbol_calls_local(mips_sym
, mips_sym
->has_dynsym_index())
10594 : symbol_references_local(mips_sym
,
10595 mips_sym
->has_dynsym_index())));
10597 // Global R_MIPS_GOT_PAGE/R_MICROMIPS_GOT_PAGE relocations are equivalent
10598 // to R_MIPS_GOT_DISP/R_MICROMIPS_GOT_DISP. The addend is applied by the
10599 // corresponding R_MIPS_GOT_OFST/R_MICROMIPS_GOT_OFST.
10600 if (got_page_reloc(r_type
) && !local
)
10601 r_type
= (micromips_reloc(r_type
) ? elfcpp::R_MICROMIPS_GOT_DISP
10602 : elfcpp::R_MIPS_GOT_DISP
);
10604 unsigned int got_offset
= 0;
10607 bool calculate_only
= false;
10608 Valtype calculated_value
= 0;
10609 bool extract_addend
= rel_type
== elfcpp::SHT_REL
;
10610 unsigned int r_types
[3] = { r_type
, r_type2
, r_type3
};
10612 Reloc_funcs::mips_reloc_unshuffle(view
, r_type
, false);
10614 // For Mips64 N64 ABI, there may be up to three operations specified per
10615 // record, by the fields r_type, r_type2, and r_type3. The first operation
10616 // takes its addend from the relocation record. Each subsequent operation
10617 // takes as its addend the result of the previous operation.
10618 // The first operation in a record which references a symbol uses the symbol
10619 // implied by r_sym. The next operation in a record which references a symbol
10620 // uses the special symbol value given by the r_ssym field. A third operation
10621 // in a record which references a symbol will assume a NULL symbol,
10622 // i.e. value zero.
10625 // Check if a record references to a symbol.
10626 for (unsigned int i
= 0; i
< 3; ++i
)
10628 if (r_types
[i
] == elfcpp::R_MIPS_NONE
)
10632 // Check if the next relocation is for the same instruction.
10633 calculate_only
= i
== 2 ? false
10634 : r_types
[i
+1] != elfcpp::R_MIPS_NONE
;
10636 if (object
->is_n64())
10640 // Handle special symbol for r_type2 relocation type.
10644 symval
.set_output_value(0);
10647 symval
.set_output_value(target
->gp_value());
10650 symval
.set_output_value(object
->gp_value());
10653 symval
.set_output_value(address
);
10656 gold_unreachable();
10662 // For r_type3 symbol value is 0.
10663 symval
.set_output_value(0);
10667 bool update_got_entry
= false;
10668 switch (r_types
[i
])
10670 case elfcpp::R_MIPS_NONE
:
10672 case elfcpp::R_MIPS_16
:
10673 reloc_status
= Reloc_funcs::rel16(view
, object
, psymval
, r_addend
,
10674 extract_addend
, calculate_only
,
10675 &calculated_value
);
10678 case elfcpp::R_MIPS_32
:
10679 if (should_apply_static_reloc(mips_sym
, r_types
[i
], output_section
,
10681 reloc_status
= Reloc_funcs::rel32(view
, object
, psymval
, r_addend
,
10682 extract_addend
, calculate_only
,
10683 &calculated_value
);
10684 if (mips_sym
!= NULL
10685 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
10686 && mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
10688 // If mips_sym->has_mips16_fn_stub() is false, symbol value is
10689 // already updated by adding +1.
10690 if (mips_sym
->has_mips16_fn_stub())
10692 gold_assert(mips_sym
->need_fn_stub());
10693 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
10694 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
10696 symval
.set_output_value(fn_stub
->output_address());
10699 got_offset
= mips_sym
->global_gotoffset();
10700 update_got_entry
= true;
10704 case elfcpp::R_MIPS_64
:
10705 if (should_apply_static_reloc(mips_sym
, r_types
[i
], output_section
,
10707 reloc_status
= Reloc_funcs::rel64(view
, object
, psymval
, r_addend
,
10708 extract_addend
, calculate_only
,
10709 &calculated_value
, false);
10710 else if (target
->is_output_n64() && r_addend
!= 0)
10711 // Only apply the addend. The static relocation was RELA, but the
10712 // dynamic relocation is REL, so we need to apply the addend.
10713 reloc_status
= Reloc_funcs::rel64(view
, object
, psymval
, r_addend
,
10714 extract_addend
, calculate_only
,
10715 &calculated_value
, true);
10717 case elfcpp::R_MIPS_REL32
:
10718 gold_unreachable();
10720 case elfcpp::R_MIPS_PC32
:
10721 reloc_status
= Reloc_funcs::relpc32(view
, object
, psymval
, address
,
10722 r_addend
, extract_addend
,
10724 &calculated_value
);
10727 case elfcpp::R_MIPS16_26
:
10728 // The calculation for R_MIPS16_26 is just the same as for an
10729 // R_MIPS_26. It's only the storage of the relocated field into
10730 // the output file that's different. So, we just fall through to the
10731 // R_MIPS_26 case here.
10732 case elfcpp::R_MIPS_26
:
10733 case elfcpp::R_MICROMIPS_26_S1
:
10734 reloc_status
= Reloc_funcs::rel26(view
, object
, psymval
, address
,
10735 gsym
== NULL
, r_addend
, extract_addend
, gsym
, cross_mode_jump
,
10736 r_types
[i
], target
->jal_to_bal(), calculate_only
,
10737 &calculated_value
);
10740 case elfcpp::R_MIPS_HI16
:
10741 case elfcpp::R_MIPS16_HI16
:
10742 case elfcpp::R_MICROMIPS_HI16
:
10743 if (rel_type
== elfcpp::SHT_RELA
)
10744 reloc_status
= Reloc_funcs::do_relhi16(view
, object
, psymval
,
10746 gp_disp
, r_types
[i
],
10748 target
, calculate_only
,
10749 &calculated_value
);
10750 else if (rel_type
== elfcpp::SHT_REL
)
10751 reloc_status
= Reloc_funcs::relhi16(view
, object
, psymval
, r_addend
,
10752 address
, gp_disp
, r_types
[i
],
10753 r_sym
, extract_addend
);
10755 gold_unreachable();
10758 case elfcpp::R_MIPS_LO16
:
10759 case elfcpp::R_MIPS16_LO16
:
10760 case elfcpp::R_MICROMIPS_LO16
:
10761 case elfcpp::R_MICROMIPS_HI0_LO16
:
10762 reloc_status
= Reloc_funcs::rello16(target
, view
, object
, psymval
,
10763 r_addend
, extract_addend
, address
,
10764 gp_disp
, r_types
[i
], r_sym
,
10765 rel_type
, calculate_only
,
10766 &calculated_value
);
10769 case elfcpp::R_MIPS_LITERAL
:
10770 case elfcpp::R_MICROMIPS_LITERAL
:
10771 // Because we don't merge literal sections, we can handle this
10772 // just like R_MIPS_GPREL16. In the long run, we should merge
10773 // shared literals, and then we will need to additional work
10778 case elfcpp::R_MIPS_GPREL16
:
10779 case elfcpp::R_MIPS16_GPREL
:
10780 case elfcpp::R_MICROMIPS_GPREL7_S2
:
10781 case elfcpp::R_MICROMIPS_GPREL16
:
10782 reloc_status
= Reloc_funcs::relgprel(view
, object
, psymval
,
10783 target
->adjusted_gp_value(object
),
10784 r_addend
, extract_addend
,
10785 gsym
== NULL
, r_types
[i
],
10786 calculate_only
, &calculated_value
);
10789 case elfcpp::R_MIPS_PC16
:
10790 reloc_status
= Reloc_funcs::relpc16(view
, object
, psymval
, address
,
10791 r_addend
, extract_addend
,
10793 &calculated_value
);
10795 case elfcpp::R_MICROMIPS_PC7_S1
:
10796 reloc_status
= Reloc_funcs::relmicromips_pc7_s1(view
, object
, psymval
,
10800 &calculated_value
);
10802 case elfcpp::R_MICROMIPS_PC10_S1
:
10803 reloc_status
= Reloc_funcs::relmicromips_pc10_s1(view
, object
,
10805 r_addend
, extract_addend
,
10807 &calculated_value
);
10809 case elfcpp::R_MICROMIPS_PC16_S1
:
10810 reloc_status
= Reloc_funcs::relmicromips_pc16_s1(view
, object
,
10812 r_addend
, extract_addend
,
10814 &calculated_value
);
10816 case elfcpp::R_MIPS_GPREL32
:
10817 reloc_status
= Reloc_funcs::relgprel32(view
, object
, psymval
,
10818 target
->adjusted_gp_value(object
),
10819 r_addend
, extract_addend
,
10821 &calculated_value
);
10823 case elfcpp::R_MIPS_GOT_HI16
:
10824 case elfcpp::R_MIPS_CALL_HI16
:
10825 case elfcpp::R_MICROMIPS_GOT_HI16
:
10826 case elfcpp::R_MICROMIPS_CALL_HI16
:
10828 got_offset
= target
->got_section()->got_offset(gsym
,
10832 got_offset
= target
->got_section()->got_offset(r_sym
,
10835 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10836 reloc_status
= Reloc_funcs::relgot_hi16(view
, gp_offset
,
10838 &calculated_value
);
10839 update_got_entry
= changed_symbol_value
;
10842 case elfcpp::R_MIPS_GOT_LO16
:
10843 case elfcpp::R_MIPS_CALL_LO16
:
10844 case elfcpp::R_MICROMIPS_GOT_LO16
:
10845 case elfcpp::R_MICROMIPS_CALL_LO16
:
10847 got_offset
= target
->got_section()->got_offset(gsym
,
10851 got_offset
= target
->got_section()->got_offset(r_sym
,
10854 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10855 reloc_status
= Reloc_funcs::relgot_lo16(view
, gp_offset
,
10857 &calculated_value
);
10858 update_got_entry
= changed_symbol_value
;
10861 case elfcpp::R_MIPS_GOT_DISP
:
10862 case elfcpp::R_MICROMIPS_GOT_DISP
:
10863 case elfcpp::R_MIPS_EH
:
10865 got_offset
= target
->got_section()->got_offset(gsym
,
10869 got_offset
= target
->got_section()->got_offset(r_sym
,
10872 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10873 if (eh_reloc(r_types
[i
]))
10874 reloc_status
= Reloc_funcs::releh(view
, gp_offset
,
10876 &calculated_value
);
10878 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
10880 &calculated_value
);
10882 case elfcpp::R_MIPS_CALL16
:
10883 case elfcpp::R_MIPS16_CALL16
:
10884 case elfcpp::R_MICROMIPS_CALL16
:
10885 gold_assert(gsym
!= NULL
);
10886 got_offset
= target
->got_section()->got_offset(gsym
,
10889 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10890 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
10891 calculate_only
, &calculated_value
);
10892 // TODO(sasa): We should also initialize update_got_entry
10893 // in other place swhere relgot is called.
10894 update_got_entry
= changed_symbol_value
;
10897 case elfcpp::R_MIPS_GOT16
:
10898 case elfcpp::R_MIPS16_GOT16
:
10899 case elfcpp::R_MICROMIPS_GOT16
:
10902 got_offset
= target
->got_section()->got_offset(gsym
,
10905 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10906 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
10908 &calculated_value
);
10912 if (rel_type
== elfcpp::SHT_RELA
)
10913 reloc_status
= Reloc_funcs::do_relgot16_local(view
, object
,
10918 &calculated_value
);
10919 else if (rel_type
== elfcpp::SHT_REL
)
10920 reloc_status
= Reloc_funcs::relgot16_local(view
, object
,
10923 r_types
[i
], r_sym
);
10925 gold_unreachable();
10927 update_got_entry
= changed_symbol_value
;
10930 case elfcpp::R_MIPS_TLS_GD
:
10931 case elfcpp::R_MIPS16_TLS_GD
:
10932 case elfcpp::R_MICROMIPS_TLS_GD
:
10934 got_offset
= target
->got_section()->got_offset(gsym
,
10938 got_offset
= target
->got_section()->got_offset(r_sym
,
10941 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10942 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
10943 &calculated_value
);
10946 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10947 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10948 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10950 got_offset
= target
->got_section()->got_offset(gsym
,
10951 GOT_TYPE_TLS_OFFSET
,
10954 got_offset
= target
->got_section()->got_offset(r_sym
,
10955 GOT_TYPE_TLS_OFFSET
,
10957 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10958 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
10959 &calculated_value
);
10962 case elfcpp::R_MIPS_TLS_LDM
:
10963 case elfcpp::R_MIPS16_TLS_LDM
:
10964 case elfcpp::R_MICROMIPS_TLS_LDM
:
10965 // Relocate the field with the offset of the GOT entry for
10966 // the module index.
10967 got_offset
= target
->got_section()->tls_ldm_offset(object
);
10968 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10969 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
10970 &calculated_value
);
10973 case elfcpp::R_MIPS_GOT_PAGE
:
10974 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10975 reloc_status
= Reloc_funcs::relgotpage(target
, view
, object
, psymval
,
10976 r_addend
, extract_addend
,
10978 &calculated_value
);
10981 case elfcpp::R_MIPS_GOT_OFST
:
10982 case elfcpp::R_MICROMIPS_GOT_OFST
:
10983 reloc_status
= Reloc_funcs::relgotofst(target
, view
, object
, psymval
,
10984 r_addend
, extract_addend
,
10985 local
, calculate_only
,
10986 &calculated_value
);
10989 case elfcpp::R_MIPS_JALR
:
10990 case elfcpp::R_MICROMIPS_JALR
:
10991 // This relocation is only a hint. In some cases, we optimize
10992 // it into a bal instruction. But we don't try to optimize
10993 // when the symbol does not resolve locally.
10995 || symbol_calls_local(gsym
, gsym
->has_dynsym_index()))
10996 reloc_status
= Reloc_funcs::reljalr(view
, object
, psymval
, address
,
10997 r_addend
, extract_addend
,
10998 cross_mode_jump
, r_types
[i
],
10999 target
->jalr_to_bal(),
11002 &calculated_value
);
11005 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
11006 case elfcpp::R_MIPS16_TLS_DTPREL_HI16
:
11007 case elfcpp::R_MICROMIPS_TLS_DTPREL_HI16
:
11008 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
11009 elfcpp::DTP_OFFSET
, r_addend
,
11010 extract_addend
, calculate_only
,
11011 &calculated_value
);
11013 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
11014 case elfcpp::R_MIPS16_TLS_DTPREL_LO16
:
11015 case elfcpp::R_MICROMIPS_TLS_DTPREL_LO16
:
11016 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
11017 elfcpp::DTP_OFFSET
, r_addend
,
11018 extract_addend
, calculate_only
,
11019 &calculated_value
);
11021 case elfcpp::R_MIPS_TLS_DTPREL32
:
11022 case elfcpp::R_MIPS_TLS_DTPREL64
:
11023 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
11024 elfcpp::DTP_OFFSET
, r_addend
,
11025 extract_addend
, calculate_only
,
11026 &calculated_value
);
11028 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
11029 case elfcpp::R_MIPS16_TLS_TPREL_HI16
:
11030 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
11031 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
11032 elfcpp::TP_OFFSET
, r_addend
,
11033 extract_addend
, calculate_only
,
11034 &calculated_value
);
11036 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
11037 case elfcpp::R_MIPS16_TLS_TPREL_LO16
:
11038 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
11039 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
11040 elfcpp::TP_OFFSET
, r_addend
,
11041 extract_addend
, calculate_only
,
11042 &calculated_value
);
11044 case elfcpp::R_MIPS_TLS_TPREL32
:
11045 case elfcpp::R_MIPS_TLS_TPREL64
:
11046 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
11047 elfcpp::TP_OFFSET
, r_addend
,
11048 extract_addend
, calculate_only
,
11049 &calculated_value
);
11051 case elfcpp::R_MIPS_SUB
:
11052 case elfcpp::R_MICROMIPS_SUB
:
11053 reloc_status
= Reloc_funcs::relsub(view
, object
, psymval
, r_addend
,
11055 calculate_only
, &calculated_value
);
11058 gold_error_at_location(relinfo
, relnum
, r_offset
,
11059 _("unsupported reloc %u"), r_types
[i
]);
11063 if (update_got_entry
)
11065 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
11066 if (mips_sym
!= NULL
&& mips_sym
->get_applied_secondary_got_fixup())
11067 got
->update_got_entry(got
->get_primary_got_offset(mips_sym
),
11068 psymval
->value(object
, 0));
11070 got
->update_got_entry(got_offset
, psymval
->value(object
, 0));
11073 r_addend
= calculated_value
;
11076 bool jal_shuffle
= jal_reloc(r_type
) ? !parameters
->options().relocatable()
11078 Reloc_funcs::mips_reloc_shuffle(view
, r_type
, jal_shuffle
);
11080 // Report any errors.
11081 switch (reloc_status
)
11083 case Reloc_funcs::STATUS_OKAY
:
11085 case Reloc_funcs::STATUS_OVERFLOW
:
11086 gold_error_at_location(relinfo
, relnum
, r_offset
,
11087 _("relocation overflow"));
11089 case Reloc_funcs::STATUS_BAD_RELOC
:
11090 gold_error_at_location(relinfo
, relnum
, r_offset
,
11091 _("unexpected opcode while processing relocation"));
11094 gold_unreachable();
11100 // Get the Reference_flags for a particular relocation.
11102 template<int size
, bool big_endian
>
11104 Target_mips
<size
, big_endian
>::Scan::get_reference_flags(
11105 unsigned int r_type
)
11109 case elfcpp::R_MIPS_NONE
:
11110 // No symbol reference.
11113 case elfcpp::R_MIPS_16
:
11114 case elfcpp::R_MIPS_32
:
11115 case elfcpp::R_MIPS_64
:
11116 case elfcpp::R_MIPS_HI16
:
11117 case elfcpp::R_MIPS_LO16
:
11118 case elfcpp::R_MIPS16_HI16
:
11119 case elfcpp::R_MIPS16_LO16
:
11120 case elfcpp::R_MICROMIPS_HI16
:
11121 case elfcpp::R_MICROMIPS_LO16
:
11122 return Symbol::ABSOLUTE_REF
;
11124 case elfcpp::R_MIPS_26
:
11125 case elfcpp::R_MIPS16_26
:
11126 case elfcpp::R_MICROMIPS_26_S1
:
11127 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
11129 case elfcpp::R_MIPS_GPREL32
:
11130 case elfcpp::R_MIPS_GPREL16
:
11131 case elfcpp::R_MIPS_REL32
:
11132 case elfcpp::R_MIPS16_GPREL
:
11133 return Symbol::RELATIVE_REF
;
11135 case elfcpp::R_MIPS_PC16
:
11136 case elfcpp::R_MIPS_PC32
:
11137 case elfcpp::R_MIPS_JALR
:
11138 case elfcpp::R_MICROMIPS_JALR
:
11139 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
11141 case elfcpp::R_MIPS_GOT16
:
11142 case elfcpp::R_MIPS_CALL16
:
11143 case elfcpp::R_MIPS_GOT_DISP
:
11144 case elfcpp::R_MIPS_GOT_HI16
:
11145 case elfcpp::R_MIPS_GOT_LO16
:
11146 case elfcpp::R_MIPS_CALL_HI16
:
11147 case elfcpp::R_MIPS_CALL_LO16
:
11148 case elfcpp::R_MIPS_LITERAL
:
11149 case elfcpp::R_MIPS_GOT_PAGE
:
11150 case elfcpp::R_MIPS_GOT_OFST
:
11151 case elfcpp::R_MIPS16_GOT16
:
11152 case elfcpp::R_MIPS16_CALL16
:
11153 case elfcpp::R_MICROMIPS_GOT16
:
11154 case elfcpp::R_MICROMIPS_CALL16
:
11155 case elfcpp::R_MICROMIPS_GOT_HI16
:
11156 case elfcpp::R_MICROMIPS_GOT_LO16
:
11157 case elfcpp::R_MICROMIPS_CALL_HI16
:
11158 case elfcpp::R_MICROMIPS_CALL_LO16
:
11159 case elfcpp::R_MIPS_EH
:
11160 // Absolute in GOT.
11161 return Symbol::RELATIVE_REF
;
11163 case elfcpp::R_MIPS_TLS_DTPMOD32
:
11164 case elfcpp::R_MIPS_TLS_DTPREL32
:
11165 case elfcpp::R_MIPS_TLS_DTPMOD64
:
11166 case elfcpp::R_MIPS_TLS_DTPREL64
:
11167 case elfcpp::R_MIPS_TLS_GD
:
11168 case elfcpp::R_MIPS_TLS_LDM
:
11169 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
11170 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
11171 case elfcpp::R_MIPS_TLS_GOTTPREL
:
11172 case elfcpp::R_MIPS_TLS_TPREL32
:
11173 case elfcpp::R_MIPS_TLS_TPREL64
:
11174 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
11175 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
11176 case elfcpp::R_MIPS16_TLS_GD
:
11177 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
11178 case elfcpp::R_MICROMIPS_TLS_GD
:
11179 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
11180 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
11181 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
11182 return Symbol::TLS_REF
;
11184 case elfcpp::R_MIPS_COPY
:
11185 case elfcpp::R_MIPS_JUMP_SLOT
:
11187 gold_unreachable();
11188 // Not expected. We will give an error later.
11193 // Report an unsupported relocation against a local symbol.
11195 template<int size
, bool big_endian
>
11197 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_local(
11198 Sized_relobj_file
<size
, big_endian
>* object
,
11199 unsigned int r_type
)
11201 gold_error(_("%s: unsupported reloc %u against local symbol"),
11202 object
->name().c_str(), r_type
);
11205 // Report an unsupported relocation against a global symbol.
11207 template<int size
, bool big_endian
>
11209 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_global(
11210 Sized_relobj_file
<size
, big_endian
>* object
,
11211 unsigned int r_type
,
11214 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
11215 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
11218 // Return printable name for ABI.
11219 template<int size
, bool big_endian
>
11221 Target_mips
<size
, big_endian
>::elf_mips_abi_name(elfcpp::Elf_Word e_flags
)
11223 switch (e_flags
& elfcpp::EF_MIPS_ABI
)
11226 if ((e_flags
& elfcpp::EF_MIPS_ABI2
) != 0)
11228 else if (size
== 64)
11232 case elfcpp::E_MIPS_ABI_O32
:
11234 case elfcpp::E_MIPS_ABI_O64
:
11236 case elfcpp::E_MIPS_ABI_EABI32
:
11238 case elfcpp::E_MIPS_ABI_EABI64
:
11241 return "unknown abi";
11245 template<int size
, bool big_endian
>
11247 Target_mips
<size
, big_endian
>::elf_mips_mach_name(elfcpp::Elf_Word e_flags
)
11249 switch (e_flags
& elfcpp::EF_MIPS_MACH
)
11251 case elfcpp::E_MIPS_MACH_3900
:
11252 return "mips:3900";
11253 case elfcpp::E_MIPS_MACH_4010
:
11254 return "mips:4010";
11255 case elfcpp::E_MIPS_MACH_4100
:
11256 return "mips:4100";
11257 case elfcpp::E_MIPS_MACH_4111
:
11258 return "mips:4111";
11259 case elfcpp::E_MIPS_MACH_4120
:
11260 return "mips:4120";
11261 case elfcpp::E_MIPS_MACH_4650
:
11262 return "mips:4650";
11263 case elfcpp::E_MIPS_MACH_5400
:
11264 return "mips:5400";
11265 case elfcpp::E_MIPS_MACH_5500
:
11266 return "mips:5500";
11267 case elfcpp::E_MIPS_MACH_SB1
:
11269 case elfcpp::E_MIPS_MACH_9000
:
11270 return "mips:9000";
11271 case elfcpp::E_MIPS_MACH_LS2E
:
11272 return "mips:loongson-2e";
11273 case elfcpp::E_MIPS_MACH_LS2F
:
11274 return "mips:loongson-2f";
11275 case elfcpp::E_MIPS_MACH_LS3A
:
11276 return "mips:loongson-3a";
11277 case elfcpp::E_MIPS_MACH_OCTEON
:
11278 return "mips:octeon";
11279 case elfcpp::E_MIPS_MACH_OCTEON2
:
11280 return "mips:octeon2";
11281 case elfcpp::E_MIPS_MACH_XLR
:
11284 switch (e_flags
& elfcpp::EF_MIPS_ARCH
)
11287 case elfcpp::E_MIPS_ARCH_1
:
11288 return "mips:3000";
11290 case elfcpp::E_MIPS_ARCH_2
:
11291 return "mips:6000";
11293 case elfcpp::E_MIPS_ARCH_3
:
11294 return "mips:4000";
11296 case elfcpp::E_MIPS_ARCH_4
:
11297 return "mips:8000";
11299 case elfcpp::E_MIPS_ARCH_5
:
11300 return "mips:mips5";
11302 case elfcpp::E_MIPS_ARCH_32
:
11303 return "mips:isa32";
11305 case elfcpp::E_MIPS_ARCH_64
:
11306 return "mips:isa64";
11308 case elfcpp::E_MIPS_ARCH_32R2
:
11309 return "mips:isa32r2";
11311 case elfcpp::E_MIPS_ARCH_64R2
:
11312 return "mips:isa64r2";
11315 return "unknown CPU";
11318 template<int size
, bool big_endian
>
11319 const Target::Target_info Target_mips
<size
, big_endian
>::mips_info
=
11322 big_endian
, // is_big_endian
11323 elfcpp::EM_MIPS
, // machine_code
11324 true, // has_make_symbol
11325 false, // has_resolve
11326 false, // has_code_fill
11327 true, // is_default_stack_executable
11328 false, // can_icf_inline_merge_sections
11330 size
== 32 ? "/lib/ld.so.1" : "/lib64/ld.so.1", // dynamic_linker
11331 0x400000, // default_text_segment_address
11332 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
11333 4 * 1024, // common_pagesize (overridable by -z common-page-size)
11334 false, // isolate_execinstr
11335 0, // rosegment_gap
11336 elfcpp::SHN_UNDEF
, // small_common_shndx
11337 elfcpp::SHN_UNDEF
, // large_common_shndx
11338 0, // small_common_section_flags
11339 0, // large_common_section_flags
11340 NULL
, // attributes_section
11341 NULL
, // attributes_vendor
11342 "__start", // entry_symbol_name
11343 32, // hash_entry_size
11346 template<int size
, bool big_endian
>
11347 class Target_mips_nacl
: public Target_mips
<size
, big_endian
>
11351 : Target_mips
<size
, big_endian
>(&mips_nacl_info
)
11355 static const Target::Target_info mips_nacl_info
;
11358 template<int size
, bool big_endian
>
11359 const Target::Target_info Target_mips_nacl
<size
, big_endian
>::mips_nacl_info
=
11362 big_endian
, // is_big_endian
11363 elfcpp::EM_MIPS
, // machine_code
11364 true, // has_make_symbol
11365 false, // has_resolve
11366 false, // has_code_fill
11367 true, // is_default_stack_executable
11368 false, // can_icf_inline_merge_sections
11370 "/lib/ld.so.1", // dynamic_linker
11371 0x20000, // default_text_segment_address
11372 0x10000, // abi_pagesize (overridable by -z max-page-size)
11373 0x10000, // common_pagesize (overridable by -z common-page-size)
11374 true, // isolate_execinstr
11375 0x10000000, // rosegment_gap
11376 elfcpp::SHN_UNDEF
, // small_common_shndx
11377 elfcpp::SHN_UNDEF
, // large_common_shndx
11378 0, // small_common_section_flags
11379 0, // large_common_section_flags
11380 NULL
, // attributes_section
11381 NULL
, // attributes_vendor
11382 "_start", // entry_symbol_name
11383 32, // hash_entry_size
11386 // Target selector for Mips. Note this is never instantiated directly.
11387 // It's only used in Target_selector_mips_nacl, below.
11389 template<int size
, bool big_endian
>
11390 class Target_selector_mips
: public Target_selector
11393 Target_selector_mips()
11394 : Target_selector(elfcpp::EM_MIPS
, size
, big_endian
,
11396 (big_endian
? "elf64-tradbigmips" : "elf64-tradlittlemips") :
11397 (big_endian
? "elf32-tradbigmips" : "elf32-tradlittlemips")),
11399 (big_endian
? "elf64btsmip" : "elf64ltsmip") :
11400 (big_endian
? "elf32btsmip" : "elf32ltsmip")))
11403 Target
* do_instantiate_target()
11404 { return new Target_mips
<size
, big_endian
>(); }
11407 template<int size
, bool big_endian
>
11408 class Target_selector_mips_nacl
11409 : public Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
11410 Target_mips_nacl
<size
, big_endian
> >
11413 Target_selector_mips_nacl()
11414 : Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
11415 Target_mips_nacl
<size
, big_endian
> >(
11416 // NaCl currently supports only MIPS32 little-endian.
11417 "mipsel", "elf32-tradlittlemips-nacl", "elf32-tradlittlemips-nacl")
11421 Target_selector_mips_nacl
<32, true> target_selector_mips32
;
11422 Target_selector_mips_nacl
<32, false> target_selector_mips32el
;
11423 Target_selector_mips_nacl
<64, true> target_selector_mips64
;
11424 Target_selector_mips_nacl
<64, false> target_selector_mips64el
;
11426 } // End anonymous namespace.