1 // mips.cc -- mips target support for gold.
3 // Copyright (C) 2011-2017 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"
47 #include "attributes.h"
54 template<int size
, bool big_endian
>
55 class Mips_output_data_plt
;
57 template<int size
, bool big_endian
>
58 class Mips_output_data_got
;
60 template<int size
, bool big_endian
>
63 template<int size
, bool big_endian
>
64 class Mips_output_section_reginfo
;
66 template<int size
, bool big_endian
>
67 class Mips_output_section_options
;
69 template<int size
, bool big_endian
>
70 class Mips_output_data_la25_stub
;
72 template<int size
, bool big_endian
>
73 class Mips_output_data_mips_stubs
;
78 template<int size
, bool big_endian
>
81 template<int size
, bool big_endian
>
84 class Mips16_stub_section_base
;
86 template<int size
, bool big_endian
>
87 class Mips16_stub_section
;
89 // The ABI says that every symbol used by dynamic relocations must have
90 // a global GOT entry. Among other things, this provides the dynamic
91 // linker with a free, directly-indexed cache. The GOT can therefore
92 // contain symbols that are not referenced by GOT relocations themselves
93 // (in other words, it may have symbols that are not referenced by things
94 // like R_MIPS_GOT16 and R_MIPS_GOT_PAGE).
96 // GOT relocations are less likely to overflow if we put the associated
97 // GOT entries towards the beginning. We therefore divide the global
98 // GOT entries into two areas: "normal" and "reloc-only". Entries in
99 // the first area can be used for both dynamic relocations and GP-relative
100 // accesses, while those in the "reloc-only" area are for dynamic
103 // These GGA_* ("Global GOT Area") values are organised so that lower
104 // values are more general than higher values. Also, non-GGA_NONE
105 // values are ordered by the position of the area in the GOT.
114 // The types of GOT entries needed for this platform.
115 // These values are exposed to the ABI in an incremental link.
116 // Do not renumber existing values without changing the version
117 // number of the .gnu_incremental_inputs section.
120 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
121 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
122 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
124 // GOT entries for multi-GOT. We support up to 1024 GOTs in multi-GOT links.
125 GOT_TYPE_STANDARD_MULTIGOT
= 3,
126 GOT_TYPE_TLS_OFFSET_MULTIGOT
= GOT_TYPE_STANDARD_MULTIGOT
+ 1024,
127 GOT_TYPE_TLS_PAIR_MULTIGOT
= GOT_TYPE_TLS_OFFSET_MULTIGOT
+ 1024
130 // TLS type of GOT entry.
139 // Values found in the r_ssym field of a relocation entry.
140 enum Special_relocation_symbol
142 RSS_UNDEF
= 0, // None - value is zero.
143 RSS_GP
= 1, // Value of GP.
144 RSS_GP0
= 2, // Value of GP in object being relocated.
145 RSS_LOC
= 3 // Address of location being relocated.
148 // Whether the section is readonly.
150 is_readonly_section(Output_section
* output_section
)
152 elfcpp::Elf_Xword section_flags
= output_section
->flags();
153 elfcpp::Elf_Word section_type
= output_section
->type();
155 if (section_type
== elfcpp::SHT_NOBITS
)
158 if (section_flags
& elfcpp::SHF_WRITE
)
164 // Return TRUE if a relocation of type R_TYPE from OBJECT might
165 // require an la25 stub. See also local_pic_function, which determines
166 // whether the destination function ever requires a stub.
167 template<int size
, bool big_endian
>
169 relocation_needs_la25_stub(Mips_relobj
<size
, big_endian
>* object
,
170 unsigned int r_type
, bool target_is_16_bit_code
)
172 // We specifically ignore branches and jumps from EF_PIC objects,
173 // where the onus is on the compiler or programmer to perform any
174 // necessary initialization of $25. Sometimes such initialization
175 // is unnecessary; for example, -mno-shared functions do not use
176 // the incoming value of $25, and may therefore be called directly.
177 if (object
->is_pic())
182 case elfcpp::R_MIPS_26
:
183 case elfcpp::R_MIPS_PC16
:
184 case elfcpp::R_MIPS_PC21_S2
:
185 case elfcpp::R_MIPS_PC26_S2
:
186 case elfcpp::R_MICROMIPS_26_S1
:
187 case elfcpp::R_MICROMIPS_PC7_S1
:
188 case elfcpp::R_MICROMIPS_PC10_S1
:
189 case elfcpp::R_MICROMIPS_PC16_S1
:
190 case elfcpp::R_MICROMIPS_PC23_S2
:
193 case elfcpp::R_MIPS16_26
:
194 return !target_is_16_bit_code
;
201 // Return true if SYM is a locally-defined PIC function, in the sense
202 // that it or its fn_stub might need $25 to be valid on entry.
203 // Note that MIPS16 functions set up $gp using PC-relative instructions,
204 // so they themselves never need $25 to be valid. Only non-MIPS16
205 // entry points are of interest here.
206 template<int size
, bool big_endian
>
208 local_pic_function(Mips_symbol
<size
>* sym
)
210 bool def_regular
= (sym
->source() == Symbol::FROM_OBJECT
211 && !sym
->object()->is_dynamic()
212 && !sym
->is_undefined());
214 if (sym
->is_defined() && def_regular
)
216 Mips_relobj
<size
, big_endian
>* object
=
217 static_cast<Mips_relobj
<size
, big_endian
>*>(sym
->object());
219 if ((object
->is_pic() || sym
->is_pic())
220 && (!sym
->is_mips16()
221 || (sym
->has_mips16_fn_stub() && sym
->need_fn_stub())))
228 hi16_reloc(int r_type
)
230 return (r_type
== elfcpp::R_MIPS_HI16
231 || r_type
== elfcpp::R_MIPS16_HI16
232 || r_type
== elfcpp::R_MICROMIPS_HI16
233 || r_type
== elfcpp::R_MIPS_PCHI16
);
237 lo16_reloc(int r_type
)
239 return (r_type
== elfcpp::R_MIPS_LO16
240 || r_type
== elfcpp::R_MIPS16_LO16
241 || r_type
== elfcpp::R_MICROMIPS_LO16
242 || r_type
== elfcpp::R_MIPS_PCLO16
);
246 got16_reloc(unsigned int r_type
)
248 return (r_type
== elfcpp::R_MIPS_GOT16
249 || r_type
== elfcpp::R_MIPS16_GOT16
250 || r_type
== elfcpp::R_MICROMIPS_GOT16
);
254 call_lo16_reloc(unsigned int r_type
)
256 return (r_type
== elfcpp::R_MIPS_CALL_LO16
257 || r_type
== elfcpp::R_MICROMIPS_CALL_LO16
);
261 got_lo16_reloc(unsigned int r_type
)
263 return (r_type
== elfcpp::R_MIPS_GOT_LO16
264 || r_type
== elfcpp::R_MICROMIPS_GOT_LO16
);
268 eh_reloc(unsigned int r_type
)
270 return (r_type
== elfcpp::R_MIPS_EH
);
274 got_disp_reloc(unsigned int r_type
)
276 return (r_type
== elfcpp::R_MIPS_GOT_DISP
277 || r_type
== elfcpp::R_MICROMIPS_GOT_DISP
);
281 got_page_reloc(unsigned int r_type
)
283 return (r_type
== elfcpp::R_MIPS_GOT_PAGE
284 || r_type
== elfcpp::R_MICROMIPS_GOT_PAGE
);
288 tls_gd_reloc(unsigned int r_type
)
290 return (r_type
== elfcpp::R_MIPS_TLS_GD
291 || r_type
== elfcpp::R_MIPS16_TLS_GD
292 || r_type
== elfcpp::R_MICROMIPS_TLS_GD
);
296 tls_gottprel_reloc(unsigned int r_type
)
298 return (r_type
== elfcpp::R_MIPS_TLS_GOTTPREL
299 || r_type
== elfcpp::R_MIPS16_TLS_GOTTPREL
300 || r_type
== elfcpp::R_MICROMIPS_TLS_GOTTPREL
);
304 tls_ldm_reloc(unsigned int r_type
)
306 return (r_type
== elfcpp::R_MIPS_TLS_LDM
307 || r_type
== elfcpp::R_MIPS16_TLS_LDM
308 || r_type
== elfcpp::R_MICROMIPS_TLS_LDM
);
312 mips16_call_reloc(unsigned int r_type
)
314 return (r_type
== elfcpp::R_MIPS16_26
315 || r_type
== elfcpp::R_MIPS16_CALL16
);
319 jal_reloc(unsigned int r_type
)
321 return (r_type
== elfcpp::R_MIPS_26
322 || r_type
== elfcpp::R_MIPS16_26
323 || r_type
== elfcpp::R_MICROMIPS_26_S1
);
327 micromips_branch_reloc(unsigned int r_type
)
329 return (r_type
== elfcpp::R_MICROMIPS_26_S1
330 || r_type
== elfcpp::R_MICROMIPS_PC16_S1
331 || r_type
== elfcpp::R_MICROMIPS_PC10_S1
332 || r_type
== elfcpp::R_MICROMIPS_PC7_S1
);
335 // Check if R_TYPE is a MIPS16 reloc.
337 mips16_reloc(unsigned int r_type
)
341 case elfcpp::R_MIPS16_26
:
342 case elfcpp::R_MIPS16_GPREL
:
343 case elfcpp::R_MIPS16_GOT16
:
344 case elfcpp::R_MIPS16_CALL16
:
345 case elfcpp::R_MIPS16_HI16
:
346 case elfcpp::R_MIPS16_LO16
:
347 case elfcpp::R_MIPS16_TLS_GD
:
348 case elfcpp::R_MIPS16_TLS_LDM
:
349 case elfcpp::R_MIPS16_TLS_DTPREL_HI16
:
350 case elfcpp::R_MIPS16_TLS_DTPREL_LO16
:
351 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
352 case elfcpp::R_MIPS16_TLS_TPREL_HI16
:
353 case elfcpp::R_MIPS16_TLS_TPREL_LO16
:
361 // Check if R_TYPE is a microMIPS reloc.
363 micromips_reloc(unsigned int r_type
)
367 case elfcpp::R_MICROMIPS_26_S1
:
368 case elfcpp::R_MICROMIPS_HI16
:
369 case elfcpp::R_MICROMIPS_LO16
:
370 case elfcpp::R_MICROMIPS_GPREL16
:
371 case elfcpp::R_MICROMIPS_LITERAL
:
372 case elfcpp::R_MICROMIPS_GOT16
:
373 case elfcpp::R_MICROMIPS_PC7_S1
:
374 case elfcpp::R_MICROMIPS_PC10_S1
:
375 case elfcpp::R_MICROMIPS_PC16_S1
:
376 case elfcpp::R_MICROMIPS_CALL16
:
377 case elfcpp::R_MICROMIPS_GOT_DISP
:
378 case elfcpp::R_MICROMIPS_GOT_PAGE
:
379 case elfcpp::R_MICROMIPS_GOT_OFST
:
380 case elfcpp::R_MICROMIPS_GOT_HI16
:
381 case elfcpp::R_MICROMIPS_GOT_LO16
:
382 case elfcpp::R_MICROMIPS_SUB
:
383 case elfcpp::R_MICROMIPS_HIGHER
:
384 case elfcpp::R_MICROMIPS_HIGHEST
:
385 case elfcpp::R_MICROMIPS_CALL_HI16
:
386 case elfcpp::R_MICROMIPS_CALL_LO16
:
387 case elfcpp::R_MICROMIPS_SCN_DISP
:
388 case elfcpp::R_MICROMIPS_JALR
:
389 case elfcpp::R_MICROMIPS_HI0_LO16
:
390 case elfcpp::R_MICROMIPS_TLS_GD
:
391 case elfcpp::R_MICROMIPS_TLS_LDM
:
392 case elfcpp::R_MICROMIPS_TLS_DTPREL_HI16
:
393 case elfcpp::R_MICROMIPS_TLS_DTPREL_LO16
:
394 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
395 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
396 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
397 case elfcpp::R_MICROMIPS_GPREL7_S2
:
398 case elfcpp::R_MICROMIPS_PC23_S2
:
407 is_matching_lo16_reloc(unsigned int high_reloc
, unsigned int lo16_reloc
)
411 case elfcpp::R_MIPS_HI16
:
412 case elfcpp::R_MIPS_GOT16
:
413 return lo16_reloc
== elfcpp::R_MIPS_LO16
;
414 case elfcpp::R_MIPS_PCHI16
:
415 return lo16_reloc
== elfcpp::R_MIPS_PCLO16
;
416 case elfcpp::R_MIPS16_HI16
:
417 case elfcpp::R_MIPS16_GOT16
:
418 return lo16_reloc
== elfcpp::R_MIPS16_LO16
;
419 case elfcpp::R_MICROMIPS_HI16
:
420 case elfcpp::R_MICROMIPS_GOT16
:
421 return lo16_reloc
== elfcpp::R_MICROMIPS_LO16
;
427 // This class is used to hold information about one GOT entry.
428 // There are three types of entry:
430 // (1) a SYMBOL + OFFSET address, where SYMBOL is local to an input object
431 // (object != NULL, symndx >= 0, tls_type != GOT_TLS_LDM)
432 // (2) a SYMBOL address, where SYMBOL is not local to an input object
433 // (sym != NULL, symndx == -1)
434 // (3) a TLS LDM slot (there's only one of these per GOT.)
435 // (object != NULL, symndx == 0, tls_type == GOT_TLS_LDM)
437 template<int size
, bool big_endian
>
440 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
443 Mips_got_entry(Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
,
444 Mips_address addend
, unsigned char tls_type
,
445 unsigned int shndx
, bool is_section_symbol
)
446 : addend_(addend
), symndx_(symndx
), tls_type_(tls_type
),
447 is_section_symbol_(is_section_symbol
), shndx_(shndx
)
448 { this->d
.object
= object
; }
450 Mips_got_entry(Mips_symbol
<size
>* sym
, unsigned char tls_type
)
451 : addend_(0), symndx_(-1U), tls_type_(tls_type
),
452 is_section_symbol_(false), shndx_(-1U)
453 { this->d
.sym
= sym
; }
455 // Return whether this entry is for a local symbol.
457 is_for_local_symbol() const
458 { return this->symndx_
!= -1U; }
460 // Return whether this entry is for a global symbol.
462 is_for_global_symbol() const
463 { return this->symndx_
== -1U; }
465 // Return the hash of this entry.
469 if (this->tls_type_
== GOT_TLS_LDM
)
470 return this->symndx_
+ (1 << 18);
472 size_t name_hash_value
= gold::string_hash
<char>(
473 (this->symndx_
!= -1U)
474 ? this->d
.object
->name().c_str()
475 : this->d
.sym
->name());
476 size_t addend
= this->addend_
;
477 return name_hash_value
^ this->symndx_
^ addend
;
480 // Return whether this entry is equal to OTHER.
482 equals(Mips_got_entry
<size
, big_endian
>* other
) const
484 if (this->tls_type_
== GOT_TLS_LDM
)
487 return ((this->tls_type_
== other
->tls_type_
)
488 && (this->symndx_
== other
->symndx_
)
489 && ((this->symndx_
!= -1U)
490 ? (this->d
.object
== other
->d
.object
)
491 : (this->d
.sym
== other
->d
.sym
))
492 && (this->addend_
== other
->addend_
));
495 // Return input object that needs this GOT entry.
496 Mips_relobj
<size
, big_endian
>*
499 gold_assert(this->symndx_
!= -1U);
500 return this->d
.object
;
503 // Return local symbol index for local GOT entries.
507 gold_assert(this->symndx_
!= -1U);
508 return this->symndx_
;
511 // Return the relocation addend for local GOT entries.
514 { return this->addend_
; }
516 // Return global symbol for global GOT entries.
520 gold_assert(this->symndx_
== -1U);
524 // Return whether this is a TLS GOT entry.
527 { return this->tls_type_
!= GOT_TLS_NONE
; }
529 // Return TLS type of this GOT entry.
532 { return this->tls_type_
; }
534 // Return section index of the local symbol for local GOT entries.
537 { return this->shndx_
; }
539 // Return whether this is a STT_SECTION symbol.
541 is_section_symbol() const
542 { return this->is_section_symbol_
; }
546 Mips_address addend_
;
548 // The index of the symbol if we have a local symbol; -1 otherwise.
549 unsigned int symndx_
;
553 // The input object for local symbols that needs the GOT entry.
554 Mips_relobj
<size
, big_endian
>* object
;
555 // If symndx == -1, the global symbol corresponding to this GOT entry. The
556 // symbol's entry is in the local area if mips_sym->global_got_area is
557 // GGA_NONE, otherwise it is in the global area.
558 Mips_symbol
<size
>* sym
;
561 // The TLS type of this GOT entry. An LDM GOT entry will be a local
562 // symbol entry with r_symndx == 0.
563 unsigned char tls_type_
;
565 // Whether this is a STT_SECTION symbol.
566 bool is_section_symbol_
;
568 // For local GOT entries, section index of the local symbol.
572 // Hash for Mips_got_entry.
574 template<int size
, bool big_endian
>
575 class Mips_got_entry_hash
579 operator()(Mips_got_entry
<size
, big_endian
>* entry
) const
580 { return entry
->hash(); }
583 // Equality for Mips_got_entry.
585 template<int size
, bool big_endian
>
586 class Mips_got_entry_eq
590 operator()(Mips_got_entry
<size
, big_endian
>* e1
,
591 Mips_got_entry
<size
, big_endian
>* e2
) const
592 { return e1
->equals(e2
); }
595 // Hash for Mips_symbol.
598 class Mips_symbol_hash
602 operator()(Mips_symbol
<size
>* sym
) const
603 { return sym
->hash(); }
606 // Got_page_range. This class describes a range of addends: [MIN_ADDEND,
607 // MAX_ADDEND]. The instances form a non-overlapping list that is sorted by
608 // increasing MIN_ADDEND.
610 struct Got_page_range
613 : next(NULL
), min_addend(0), max_addend(0)
616 Got_page_range
* next
;
620 // Return the maximum number of GOT page entries required.
623 { return (this->max_addend
- this->min_addend
+ 0x1ffff) >> 16; }
626 // Got_page_entry. This class describes the range of addends that are applied
627 // to page relocations against a given symbol.
629 struct Got_page_entry
632 : object(NULL
), symndx(-1U), ranges(NULL
), num_pages(0)
635 Got_page_entry(Object
* object_
, unsigned int symndx_
)
636 : object(object_
), symndx(symndx_
), ranges(NULL
), num_pages(0)
639 // The input object that needs the GOT page entry.
641 // The index of the symbol, as stored in the relocation r_info.
643 // The ranges for this page entry.
644 Got_page_range
* ranges
;
645 // The maximum number of page entries needed for RANGES.
646 unsigned int num_pages
;
649 // Hash for Got_page_entry.
651 struct Got_page_entry_hash
654 operator()(Got_page_entry
* entry
) const
655 { return reinterpret_cast<uintptr_t>(entry
->object
) + entry
->symndx
; }
658 // Equality for Got_page_entry.
660 struct Got_page_entry_eq
663 operator()(Got_page_entry
* entry1
, Got_page_entry
* entry2
) const
665 return entry1
->object
== entry2
->object
&& entry1
->symndx
== entry2
->symndx
;
669 // This class is used to hold .got information when linking.
671 template<int size
, bool big_endian
>
674 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
675 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
677 typedef Unordered_map
<unsigned int, unsigned int> Got_page_offsets
;
679 // Unordered set of GOT entries.
680 typedef Unordered_set
<Mips_got_entry
<size
, big_endian
>*,
681 Mips_got_entry_hash
<size
, big_endian
>,
682 Mips_got_entry_eq
<size
, big_endian
> > Got_entry_set
;
684 // Unordered set of GOT page entries.
685 typedef Unordered_set
<Got_page_entry
*,
686 Got_page_entry_hash
, Got_page_entry_eq
> Got_page_entry_set
;
688 // Unordered set of global GOT entries.
689 typedef Unordered_set
<Mips_symbol
<size
>*, Mips_symbol_hash
<size
> >
690 Global_got_entry_set
;
694 : local_gotno_(0), page_gotno_(0), global_gotno_(0), reloc_only_gotno_(0),
695 tls_gotno_(0), tls_ldm_offset_(-1U), global_got_symbols_(),
696 got_entries_(), got_page_entries_(), got_page_offset_start_(0),
697 got_page_offset_next_(0), got_page_offsets_(), next_(NULL
), index_(-1U),
701 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
702 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
704 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
705 unsigned int symndx
, Mips_address addend
,
706 unsigned int r_type
, unsigned int shndx
,
707 bool is_section_symbol
);
709 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
710 // in OBJECT. FOR_CALL is true if the caller is only interested in
711 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
714 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
715 Mips_relobj
<size
, big_endian
>* object
,
716 unsigned int r_type
, bool dyn_reloc
, bool for_call
);
718 // Add ENTRY to master GOT and to OBJECT's GOT.
720 record_got_entry(Mips_got_entry
<size
, big_endian
>* entry
,
721 Mips_relobj
<size
, big_endian
>* object
);
723 // Record that OBJECT has a page relocation against symbol SYMNDX and
724 // that ADDEND is the addend for that relocation.
726 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
727 unsigned int symndx
, int addend
);
729 // Create all entries that should be in the local part of the GOT.
731 add_local_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
733 // Create GOT page entries.
735 add_page_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
737 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
739 add_global_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
740 unsigned int non_reloc_only_global_gotno
);
742 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
744 add_reloc_only_entries(Mips_output_data_got
<size
, big_endian
>* got
);
746 // Create TLS GOT entries.
748 add_tls_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
750 // Decide whether the symbol needs an entry in the global part of the primary
751 // GOT, setting global_got_area accordingly. Count the number of global
752 // symbols that are in the primary GOT only because they have dynamic
753 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
755 count_got_symbols(Symbol_table
* symtab
);
757 // Return the offset of GOT page entry for VALUE.
759 get_got_page_offset(Mips_address value
,
760 Mips_output_data_got
<size
, big_endian
>* got
);
762 // Count the number of GOT entries required.
766 // Count the number of GOT entries required by ENTRY. Accumulate the result.
768 count_got_entry(Mips_got_entry
<size
, big_endian
>* entry
);
770 // Add FROM's GOT entries.
772 add_got_entries(Mips_got_info
<size
, big_endian
>* from
);
774 // Add FROM's GOT page entries.
776 add_got_page_entries(Mips_got_info
<size
, big_endian
>* from
);
781 { return ((2 + this->local_gotno_
+ this->page_gotno_
+ this->global_gotno_
782 + this->tls_gotno_
) * size
/8);
785 // Return the number of local GOT entries.
788 { return this->local_gotno_
; }
790 // Return the maximum number of page GOT entries needed.
793 { return this->page_gotno_
; }
795 // Return the number of global GOT entries.
798 { return this->global_gotno_
; }
800 // Set the number of global GOT entries.
802 set_global_gotno(unsigned int global_gotno
)
803 { this->global_gotno_
= global_gotno
; }
805 // Return the number of GGA_RELOC_ONLY global GOT entries.
807 reloc_only_gotno() const
808 { return this->reloc_only_gotno_
; }
810 // Return the number of TLS GOT entries.
813 { return this->tls_gotno_
; }
815 // Return the GOT type for this GOT. Used for multi-GOT links only.
817 multigot_got_type(unsigned int got_type
) const
821 case GOT_TYPE_STANDARD
:
822 return GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
823 case GOT_TYPE_TLS_OFFSET
:
824 return GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
825 case GOT_TYPE_TLS_PAIR
:
826 return GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
832 // Remove lazy-binding stubs for global symbols in this GOT.
834 remove_lazy_stubs(Target_mips
<size
, big_endian
>* target
);
836 // Return offset of this GOT from the start of .got section.
839 { return this->offset_
; }
841 // Set offset of this GOT from the start of .got section.
843 set_offset(unsigned int offset
)
844 { this->offset_
= offset
; }
846 // Set index of this GOT in multi-GOT links.
848 set_index(unsigned int index
)
849 { this->index_
= index
; }
851 // Return next GOT in multi-GOT links.
852 Mips_got_info
<size
, big_endian
>*
854 { return this->next_
; }
856 // Set next GOT in multi-GOT links.
858 set_next(Mips_got_info
<size
, big_endian
>* next
)
859 { this->next_
= next
; }
861 // Return the offset of TLS LDM entry for this GOT.
863 tls_ldm_offset() const
864 { return this->tls_ldm_offset_
; }
866 // Set the offset of TLS LDM entry for this GOT.
868 set_tls_ldm_offset(unsigned int tls_ldm_offset
)
869 { this->tls_ldm_offset_
= tls_ldm_offset
; }
871 Global_got_entry_set
&
873 { return this->global_got_symbols_
; }
875 // Return the GOT_TLS_* type required by relocation type R_TYPE.
877 mips_elf_reloc_tls_type(unsigned int r_type
)
879 if (tls_gd_reloc(r_type
))
882 if (tls_ldm_reloc(r_type
))
885 if (tls_gottprel_reloc(r_type
))
891 // Return the number of GOT slots needed for GOT TLS type TYPE.
893 mips_tls_got_entries(unsigned int type
)
913 // The number of local GOT entries.
914 unsigned int local_gotno_
;
915 // The maximum number of page GOT entries needed.
916 unsigned int page_gotno_
;
917 // The number of global GOT entries.
918 unsigned int global_gotno_
;
919 // The number of global GOT entries that are in the GGA_RELOC_ONLY area.
920 unsigned int reloc_only_gotno_
;
921 // The number of TLS GOT entries.
922 unsigned int tls_gotno_
;
923 // The offset of TLS LDM entry for this GOT.
924 unsigned int tls_ldm_offset_
;
925 // All symbols that have global GOT entry.
926 Global_got_entry_set global_got_symbols_
;
927 // A hash table holding GOT entries.
928 Got_entry_set got_entries_
;
929 // A hash table of GOT page entries.
930 Got_page_entry_set got_page_entries_
;
931 // The offset of first GOT page entry for this GOT.
932 unsigned int got_page_offset_start_
;
933 // The offset of next available GOT page entry for this GOT.
934 unsigned int got_page_offset_next_
;
935 // A hash table that maps GOT page entry value to the GOT offset where
936 // the entry is located.
937 Got_page_offsets got_page_offsets_
;
938 // In multi-GOT links, a pointer to the next GOT.
939 Mips_got_info
<size
, big_endian
>* next_
;
940 // Index of this GOT in multi-GOT links.
942 // The offset of this GOT in multi-GOT links.
943 unsigned int offset_
;
946 // This is a helper class used during relocation scan. It records GOT16 addend.
948 template<int size
, bool big_endian
>
951 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
953 got16_addend(const Sized_relobj_file
<size
, big_endian
>* _object
,
954 unsigned int _shndx
, unsigned int _r_type
, unsigned int _r_sym
,
955 Mips_address _addend
)
956 : object(_object
), shndx(_shndx
), r_type(_r_type
), r_sym(_r_sym
),
960 const Sized_relobj_file
<size
, big_endian
>* object
;
967 // .MIPS.abiflags section content
969 template<bool big_endian
>
972 typedef typename
elfcpp::Swap
<8, big_endian
>::Valtype Valtype8
;
973 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype16
;
974 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
977 : version(0), isa_level(0), isa_rev(0), gpr_size(0), cpr1_size(0),
978 cpr2_size(0), fp_abi(0), isa_ext(0), ases(0), flags1(0), flags2(0)
981 // Version of flags structure.
983 // The level of the ISA: 1-5, 32, 64.
985 // The revision of ISA: 0 for MIPS V and below, 1-n otherwise.
987 // The size of general purpose registers.
989 // The size of co-processor 1 registers.
991 // The size of co-processor 2 registers.
993 // The floating-point ABI.
995 // Processor-specific extension.
997 // Mask of ASEs used.
999 // Mask of general flags.
1004 // Mips_symbol class. Holds additional symbol information needed for Mips.
1007 class Mips_symbol
: public Sized_symbol
<size
>
1011 : need_fn_stub_(false), has_nonpic_branches_(false), la25_stub_offset_(-1U),
1012 has_static_relocs_(false), no_lazy_stub_(false), lazy_stub_offset_(0),
1013 pointer_equality_needed_(false), global_got_area_(GGA_NONE
),
1014 global_gotoffset_(-1U), got_only_for_calls_(true), has_lazy_stub_(false),
1015 needs_mips_plt_(false), needs_comp_plt_(false), mips_plt_offset_(-1U),
1016 comp_plt_offset_(-1U), mips16_fn_stub_(NULL
), mips16_call_stub_(NULL
),
1017 mips16_call_fp_stub_(NULL
), applied_secondary_got_fixup_(false)
1020 // Return whether this is a MIPS16 symbol.
1024 // (st_other & STO_MIPS16) == STO_MIPS16
1025 return ((this->nonvis() & (elfcpp::STO_MIPS16
>> 2))
1026 == elfcpp::STO_MIPS16
>> 2);
1029 // Return whether this is a microMIPS symbol.
1031 is_micromips() const
1033 // (st_other & STO_MIPS_ISA) == STO_MICROMIPS
1034 return ((this->nonvis() & (elfcpp::STO_MIPS_ISA
>> 2))
1035 == elfcpp::STO_MICROMIPS
>> 2);
1038 // Return whether the symbol needs MIPS16 fn_stub.
1040 need_fn_stub() const
1041 { return this->need_fn_stub_
; }
1043 // Set that the symbol needs MIPS16 fn_stub.
1046 { this->need_fn_stub_
= true; }
1048 // Return whether this symbol is referenced by branch relocations from
1049 // any non-PIC input file.
1051 has_nonpic_branches() const
1052 { return this->has_nonpic_branches_
; }
1054 // Set that this symbol is referenced by branch relocations from
1055 // any non-PIC input file.
1057 set_has_nonpic_branches()
1058 { this->has_nonpic_branches_
= true; }
1060 // Return the offset of the la25 stub for this symbol from the start of the
1061 // la25 stub section.
1063 la25_stub_offset() const
1064 { return this->la25_stub_offset_
; }
1066 // Set the offset of the la25 stub for this symbol from the start of the
1067 // la25 stub section.
1069 set_la25_stub_offset(unsigned int offset
)
1070 { this->la25_stub_offset_
= offset
; }
1072 // Return whether the symbol has la25 stub. This is true if this symbol is
1073 // for a PIC function, and there are non-PIC branches and jumps to it.
1075 has_la25_stub() const
1076 { return this->la25_stub_offset_
!= -1U; }
1078 // Return whether there is a relocation against this symbol that must be
1079 // resolved by the static linker (that is, the relocation cannot possibly
1080 // be made dynamic).
1082 has_static_relocs() const
1083 { return this->has_static_relocs_
; }
1085 // Set that there is a relocation against this symbol that must be resolved
1086 // by the static linker (that is, the relocation cannot possibly be made
1089 set_has_static_relocs()
1090 { this->has_static_relocs_
= true; }
1092 // Return whether we must not create a lazy-binding stub for this symbol.
1094 no_lazy_stub() const
1095 { return this->no_lazy_stub_
; }
1097 // Set that we must not create a lazy-binding stub for this symbol.
1100 { this->no_lazy_stub_
= true; }
1102 // Return the offset of the lazy-binding stub for this symbol from the start
1103 // of .MIPS.stubs section.
1105 lazy_stub_offset() const
1106 { return this->lazy_stub_offset_
; }
1108 // Set the offset of the lazy-binding stub for this symbol from the start
1109 // of .MIPS.stubs section.
1111 set_lazy_stub_offset(unsigned int offset
)
1112 { this->lazy_stub_offset_
= offset
; }
1114 // Return whether there are any relocations for this symbol where
1115 // pointer equality matters.
1117 pointer_equality_needed() const
1118 { return this->pointer_equality_needed_
; }
1120 // Set that there are relocations for this symbol where pointer equality
1123 set_pointer_equality_needed()
1124 { this->pointer_equality_needed_
= true; }
1126 // Return global GOT area where this symbol in located.
1128 global_got_area() const
1129 { return this->global_got_area_
; }
1131 // Set global GOT area where this symbol in located.
1133 set_global_got_area(Global_got_area global_got_area
)
1134 { this->global_got_area_
= global_got_area
; }
1136 // Return the global GOT offset for this symbol. For multi-GOT links, this
1137 // returns the offset from the start of .got section to the first GOT entry
1138 // for the symbol. Note that in multi-GOT links the symbol can have entry
1139 // in more than one GOT.
1141 global_gotoffset() const
1142 { return this->global_gotoffset_
; }
1144 // Set the global GOT offset for this symbol. Note that in multi-GOT links
1145 // the symbol can have entry in more than one GOT. This method will set
1146 // the offset only if it is less than current offset.
1148 set_global_gotoffset(unsigned int offset
)
1150 if (this->global_gotoffset_
== -1U || offset
< this->global_gotoffset_
)
1151 this->global_gotoffset_
= offset
;
1154 // Return whether all GOT relocations for this symbol are for calls.
1156 got_only_for_calls() const
1157 { return this->got_only_for_calls_
; }
1159 // Set that there is a GOT relocation for this symbol that is not for call.
1161 set_got_not_only_for_calls()
1162 { this->got_only_for_calls_
= false; }
1164 // Return whether this is a PIC symbol.
1168 // (st_other & STO_MIPS_FLAGS) == STO_MIPS_PIC
1169 return ((this->nonvis() & (elfcpp::STO_MIPS_FLAGS
>> 2))
1170 == (elfcpp::STO_MIPS_PIC
>> 2));
1173 // Set the flag in st_other field that marks this symbol as PIC.
1177 if (this->is_mips16())
1178 // (st_other & ~(STO_MIPS16 | STO_MIPS_FLAGS)) | STO_MIPS_PIC
1179 this->set_nonvis((this->nonvis()
1180 & ~((elfcpp::STO_MIPS16
>> 2)
1181 | (elfcpp::STO_MIPS_FLAGS
>> 2)))
1182 | (elfcpp::STO_MIPS_PIC
>> 2));
1184 // (other & ~STO_MIPS_FLAGS) | STO_MIPS_PIC
1185 this->set_nonvis((this->nonvis() & ~(elfcpp::STO_MIPS_FLAGS
>> 2))
1186 | (elfcpp::STO_MIPS_PIC
>> 2));
1189 // Set the flag in st_other field that marks this symbol as PLT.
1193 if (this->is_mips16())
1194 // (st_other & (STO_MIPS16 | ~STO_MIPS_FLAGS)) | STO_MIPS_PLT
1195 this->set_nonvis((this->nonvis()
1196 & ((elfcpp::STO_MIPS16
>> 2)
1197 | ~(elfcpp::STO_MIPS_FLAGS
>> 2)))
1198 | (elfcpp::STO_MIPS_PLT
>> 2));
1201 // (st_other & ~STO_MIPS_FLAGS) | STO_MIPS_PLT
1202 this->set_nonvis((this->nonvis() & ~(elfcpp::STO_MIPS_FLAGS
>> 2))
1203 | (elfcpp::STO_MIPS_PLT
>> 2));
1206 // Downcast a base pointer to a Mips_symbol pointer.
1207 static Mips_symbol
<size
>*
1208 as_mips_sym(Symbol
* sym
)
1209 { return static_cast<Mips_symbol
<size
>*>(sym
); }
1211 // Downcast a base pointer to a Mips_symbol pointer.
1212 static const Mips_symbol
<size
>*
1213 as_mips_sym(const Symbol
* sym
)
1214 { return static_cast<const Mips_symbol
<size
>*>(sym
); }
1216 // Return whether the symbol has lazy-binding stub.
1218 has_lazy_stub() const
1219 { return this->has_lazy_stub_
; }
1221 // Set whether the symbol has lazy-binding stub.
1223 set_has_lazy_stub(bool has_lazy_stub
)
1224 { this->has_lazy_stub_
= has_lazy_stub
; }
1226 // Return whether the symbol needs a standard PLT entry.
1228 needs_mips_plt() const
1229 { return this->needs_mips_plt_
; }
1231 // Set whether the symbol needs a standard PLT entry.
1233 set_needs_mips_plt(bool needs_mips_plt
)
1234 { this->needs_mips_plt_
= needs_mips_plt
; }
1236 // Return whether the symbol needs a compressed (MIPS16 or microMIPS) PLT
1239 needs_comp_plt() const
1240 { return this->needs_comp_plt_
; }
1242 // Set whether the symbol needs a compressed (MIPS16 or microMIPS) PLT entry.
1244 set_needs_comp_plt(bool needs_comp_plt
)
1245 { this->needs_comp_plt_
= needs_comp_plt
; }
1247 // Return standard PLT entry offset, or -1 if none.
1249 mips_plt_offset() const
1250 { return this->mips_plt_offset_
; }
1252 // Set standard PLT entry offset.
1254 set_mips_plt_offset(unsigned int mips_plt_offset
)
1255 { this->mips_plt_offset_
= mips_plt_offset
; }
1257 // Return whether the symbol has standard PLT entry.
1259 has_mips_plt_offset() const
1260 { return this->mips_plt_offset_
!= -1U; }
1262 // Return compressed (MIPS16 or microMIPS) PLT entry offset, or -1 if none.
1264 comp_plt_offset() const
1265 { return this->comp_plt_offset_
; }
1267 // Set compressed (MIPS16 or microMIPS) PLT entry offset.
1269 set_comp_plt_offset(unsigned int comp_plt_offset
)
1270 { this->comp_plt_offset_
= comp_plt_offset
; }
1272 // Return whether the symbol has compressed (MIPS16 or microMIPS) PLT entry.
1274 has_comp_plt_offset() const
1275 { return this->comp_plt_offset_
!= -1U; }
1277 // Return MIPS16 fn stub for a symbol.
1278 template<bool big_endian
>
1279 Mips16_stub_section
<size
, big_endian
>*
1280 get_mips16_fn_stub() const
1282 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(mips16_fn_stub_
);
1285 // Set MIPS16 fn stub for a symbol.
1287 set_mips16_fn_stub(Mips16_stub_section_base
* stub
)
1288 { this->mips16_fn_stub_
= stub
; }
1290 // Return whether symbol has MIPS16 fn stub.
1292 has_mips16_fn_stub() const
1293 { return this->mips16_fn_stub_
!= NULL
; }
1295 // Return MIPS16 call stub for a symbol.
1296 template<bool big_endian
>
1297 Mips16_stub_section
<size
, big_endian
>*
1298 get_mips16_call_stub() const
1300 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(
1304 // Set MIPS16 call stub for a symbol.
1306 set_mips16_call_stub(Mips16_stub_section_base
* stub
)
1307 { this->mips16_call_stub_
= stub
; }
1309 // Return whether symbol has MIPS16 call stub.
1311 has_mips16_call_stub() const
1312 { return this->mips16_call_stub_
!= NULL
; }
1314 // Return MIPS16 call_fp stub for a symbol.
1315 template<bool big_endian
>
1316 Mips16_stub_section
<size
, big_endian
>*
1317 get_mips16_call_fp_stub() const
1319 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(
1320 mips16_call_fp_stub_
);
1323 // Set MIPS16 call_fp stub for a symbol.
1325 set_mips16_call_fp_stub(Mips16_stub_section_base
* stub
)
1326 { this->mips16_call_fp_stub_
= stub
; }
1328 // Return whether symbol has MIPS16 call_fp stub.
1330 has_mips16_call_fp_stub() const
1331 { return this->mips16_call_fp_stub_
!= NULL
; }
1334 get_applied_secondary_got_fixup() const
1335 { return applied_secondary_got_fixup_
; }
1338 set_applied_secondary_got_fixup()
1339 { this->applied_secondary_got_fixup_
= true; }
1341 // Return the hash of this symbol.
1345 return gold::string_hash
<char>(this->name());
1349 // Whether the symbol needs MIPS16 fn_stub. This is true if this symbol
1350 // appears in any relocs other than a 16 bit call.
1353 // True if this symbol is referenced by branch relocations from
1354 // any non-PIC input file. This is used to determine whether an
1355 // la25 stub is required.
1356 bool has_nonpic_branches_
;
1358 // The offset of the la25 stub for this symbol from the start of the
1359 // la25 stub section.
1360 unsigned int la25_stub_offset_
;
1362 // True if there is a relocation against this symbol that must be
1363 // resolved by the static linker (that is, the relocation cannot
1364 // possibly be made dynamic).
1365 bool has_static_relocs_
;
1367 // Whether we must not create a lazy-binding stub for this symbol.
1368 // This is true if the symbol has relocations related to taking the
1369 // function's address.
1372 // The offset of the lazy-binding stub for this symbol from the start of
1373 // .MIPS.stubs section.
1374 unsigned int lazy_stub_offset_
;
1376 // True if there are any relocations for this symbol where pointer equality
1378 bool pointer_equality_needed_
;
1380 // Global GOT area where this symbol in located, or GGA_NONE if symbol is not
1381 // in the global part of the GOT.
1382 Global_got_area global_got_area_
;
1384 // The global GOT offset for this symbol. For multi-GOT links, this is offset
1385 // from the start of .got section to the first GOT entry for the symbol.
1386 // Note that in multi-GOT links the symbol can have entry in more than one GOT.
1387 unsigned int global_gotoffset_
;
1389 // Whether all GOT relocations for this symbol are for calls.
1390 bool got_only_for_calls_
;
1391 // Whether the symbol has lazy-binding stub.
1392 bool has_lazy_stub_
;
1393 // Whether the symbol needs a standard PLT entry.
1394 bool needs_mips_plt_
;
1395 // Whether the symbol needs a compressed (MIPS16 or microMIPS) PLT entry.
1396 bool needs_comp_plt_
;
1397 // Standard PLT entry offset, or -1 if none.
1398 unsigned int mips_plt_offset_
;
1399 // Compressed (MIPS16 or microMIPS) PLT entry offset, or -1 if none.
1400 unsigned int comp_plt_offset_
;
1401 // MIPS16 fn stub for a symbol.
1402 Mips16_stub_section_base
* mips16_fn_stub_
;
1403 // MIPS16 call stub for a symbol.
1404 Mips16_stub_section_base
* mips16_call_stub_
;
1405 // MIPS16 call_fp stub for a symbol.
1406 Mips16_stub_section_base
* mips16_call_fp_stub_
;
1408 bool applied_secondary_got_fixup_
;
1411 // Mips16_stub_section class.
1413 // The mips16 compiler uses a couple of special sections to handle
1414 // floating point arguments.
1416 // Section names that look like .mips16.fn.FNNAME contain stubs that
1417 // copy floating point arguments from the fp regs to the gp regs and
1418 // then jump to FNNAME. If any 32 bit function calls FNNAME, the
1419 // call should be redirected to the stub instead. If no 32 bit
1420 // function calls FNNAME, the stub should be discarded. We need to
1421 // consider any reference to the function, not just a call, because
1422 // if the address of the function is taken we will need the stub,
1423 // since the address might be passed to a 32 bit function.
1425 // Section names that look like .mips16.call.FNNAME contain stubs
1426 // that copy floating point arguments from the gp regs to the fp
1427 // regs and then jump to FNNAME. If FNNAME is a 32 bit function,
1428 // then any 16 bit function that calls FNNAME should be redirected
1429 // to the stub instead. If FNNAME is not a 32 bit function, the
1430 // stub should be discarded.
1432 // .mips16.call.fp.FNNAME sections are similar, but contain stubs
1433 // which call FNNAME and then copy the return value from the fp regs
1434 // to the gp regs. These stubs store the return address in $18 while
1435 // calling FNNAME; any function which might call one of these stubs
1436 // must arrange to save $18 around the call. (This case is not
1437 // needed for 32 bit functions that call 16 bit functions, because
1438 // 16 bit functions always return floating point values in both
1439 // $f0/$f1 and $2/$3.)
1441 // Note that in all cases FNNAME might be defined statically.
1442 // Therefore, FNNAME is not used literally. Instead, the relocation
1443 // information will indicate which symbol the section is for.
1445 // We record any stubs that we find in the symbol table.
1447 // TODO(sasa): All mips16 stub sections should be emitted in the .text section.
1449 class Mips16_stub_section_base
{ };
1451 template<int size
, bool big_endian
>
1452 class Mips16_stub_section
: public Mips16_stub_section_base
1454 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1457 Mips16_stub_section(Mips_relobj
<size
, big_endian
>* object
, unsigned int shndx
)
1458 : object_(object
), shndx_(shndx
), r_sym_(0), gsym_(NULL
),
1459 found_r_mips_none_(false)
1461 gold_assert(object
->is_mips16_fn_stub_section(shndx
)
1462 || object
->is_mips16_call_stub_section(shndx
)
1463 || object
->is_mips16_call_fp_stub_section(shndx
));
1466 // Return the object of this stub section.
1467 Mips_relobj
<size
, big_endian
>*
1469 { return this->object_
; }
1471 // Return the size of a section.
1473 section_size() const
1474 { return this->object_
->section_size(this->shndx_
); }
1476 // Return section index of this stub section.
1479 { return this->shndx_
; }
1481 // Return symbol index, if stub is for a local function.
1484 { return this->r_sym_
; }
1486 // Return symbol, if stub is for a global function.
1489 { return this->gsym_
; }
1491 // Return whether stub is for a local function.
1493 is_for_local_function() const
1494 { return this->gsym_
== NULL
; }
1496 // This method is called when a new relocation R_TYPE for local symbol R_SYM
1497 // is found in the stub section. Try to find stub target.
1499 new_local_reloc_found(unsigned int r_type
, unsigned int r_sym
)
1501 // To find target symbol for this stub, trust the first R_MIPS_NONE
1502 // relocation, if any. Otherwise trust the first relocation, whatever
1504 if (this->found_r_mips_none_
)
1506 if (r_type
== elfcpp::R_MIPS_NONE
)
1508 this->r_sym_
= r_sym
;
1510 this->found_r_mips_none_
= true;
1512 else if (!is_target_found())
1513 this->r_sym_
= r_sym
;
1516 // This method is called when a new relocation R_TYPE for global symbol GSYM
1517 // is found in the stub section. Try to find stub target.
1519 new_global_reloc_found(unsigned int r_type
, Mips_symbol
<size
>* gsym
)
1521 // To find target symbol for this stub, trust the first R_MIPS_NONE
1522 // relocation, if any. Otherwise trust the first relocation, whatever
1524 if (this->found_r_mips_none_
)
1526 if (r_type
== elfcpp::R_MIPS_NONE
)
1530 this->found_r_mips_none_
= true;
1532 else if (!is_target_found())
1536 // Return whether we found the stub target.
1538 is_target_found() const
1539 { return this->r_sym_
!= 0 || this->gsym_
!= NULL
; }
1541 // Return whether this is a fn stub.
1544 { return this->object_
->is_mips16_fn_stub_section(this->shndx_
); }
1546 // Return whether this is a call stub.
1548 is_call_stub() const
1549 { return this->object_
->is_mips16_call_stub_section(this->shndx_
); }
1551 // Return whether this is a call_fp stub.
1553 is_call_fp_stub() const
1554 { return this->object_
->is_mips16_call_fp_stub_section(this->shndx_
); }
1556 // Return the output address.
1558 output_address() const
1560 return (this->object_
->output_section(this->shndx_
)->address()
1561 + this->object_
->output_section_offset(this->shndx_
));
1565 // The object of this stub section.
1566 Mips_relobj
<size
, big_endian
>* object_
;
1567 // The section index of this stub section.
1568 unsigned int shndx_
;
1569 // The symbol index, if stub is for a local function.
1570 unsigned int r_sym_
;
1571 // The symbol, if stub is for a global function.
1572 Mips_symbol
<size
>* gsym_
;
1573 // True if we found R_MIPS_NONE relocation in this stub.
1574 bool found_r_mips_none_
;
1577 // Mips_relobj class.
1579 template<int size
, bool big_endian
>
1580 class Mips_relobj
: public Sized_relobj_file
<size
, big_endian
>
1582 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1583 typedef std::map
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>
1584 Mips16_stubs_int_map
;
1585 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1588 Mips_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
1589 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1590 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
1591 processor_specific_flags_(0), local_symbol_is_mips16_(),
1592 local_symbol_is_micromips_(), mips16_stub_sections_(),
1593 local_non_16bit_calls_(), local_16bit_calls_(), local_mips16_fn_stubs_(),
1594 local_mips16_call_stubs_(), gp_(0), has_reginfo_section_(false),
1595 got_info_(NULL
), section_is_mips16_fn_stub_(),
1596 section_is_mips16_call_stub_(), section_is_mips16_call_fp_stub_(),
1597 pdr_shndx_(-1U), attributes_section_data_(NULL
), abiflags_(NULL
),
1598 gprmask_(0), cprmask1_(0), cprmask2_(0), cprmask3_(0), cprmask4_(0)
1600 this->is_pic_
= (ehdr
.get_e_flags() & elfcpp::EF_MIPS_PIC
) != 0;
1601 this->is_n32_
= elfcpp::abi_n32(ehdr
.get_e_flags());
1605 { delete this->attributes_section_data_
; }
1607 // Downcast a base pointer to a Mips_relobj pointer. This is
1608 // not type-safe but we only use Mips_relobj not the base class.
1609 static Mips_relobj
<size
, big_endian
>*
1610 as_mips_relobj(Relobj
* relobj
)
1611 { return static_cast<Mips_relobj
<size
, big_endian
>*>(relobj
); }
1613 // Downcast a base pointer to a Mips_relobj pointer. This is
1614 // not type-safe but we only use Mips_relobj not the base class.
1615 static const Mips_relobj
<size
, big_endian
>*
1616 as_mips_relobj(const Relobj
* relobj
)
1617 { return static_cast<const Mips_relobj
<size
, big_endian
>*>(relobj
); }
1619 // Processor-specific flags in ELF file header. This is valid only after
1622 processor_specific_flags() const
1623 { return this->processor_specific_flags_
; }
1625 // Whether a local symbol is MIPS16 symbol. R_SYM is the symbol table
1626 // index. This is only valid after do_count_local_symbol is called.
1628 local_symbol_is_mips16(unsigned int r_sym
) const
1630 gold_assert(r_sym
< this->local_symbol_is_mips16_
.size());
1631 return this->local_symbol_is_mips16_
[r_sym
];
1634 // Whether a local symbol is microMIPS symbol. R_SYM is the symbol table
1635 // index. This is only valid after do_count_local_symbol is called.
1637 local_symbol_is_micromips(unsigned int r_sym
) const
1639 gold_assert(r_sym
< this->local_symbol_is_micromips_
.size());
1640 return this->local_symbol_is_micromips_
[r_sym
];
1643 // Get or create MIPS16 stub section.
1644 Mips16_stub_section
<size
, big_endian
>*
1645 get_mips16_stub_section(unsigned int shndx
)
1647 typename
Mips16_stubs_int_map::const_iterator it
=
1648 this->mips16_stub_sections_
.find(shndx
);
1649 if (it
!= this->mips16_stub_sections_
.end())
1650 return (*it
).second
;
1652 Mips16_stub_section
<size
, big_endian
>* stub_section
=
1653 new Mips16_stub_section
<size
, big_endian
>(this, shndx
);
1654 this->mips16_stub_sections_
.insert(
1655 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1656 stub_section
->shndx(), stub_section
));
1657 return stub_section
;
1660 // Return MIPS16 fn stub section for local symbol R_SYM, or NULL if this
1661 // object doesn't have fn stub for R_SYM.
1662 Mips16_stub_section
<size
, big_endian
>*
1663 get_local_mips16_fn_stub(unsigned int r_sym
) const
1665 typename
Mips16_stubs_int_map::const_iterator it
=
1666 this->local_mips16_fn_stubs_
.find(r_sym
);
1667 if (it
!= this->local_mips16_fn_stubs_
.end())
1668 return (*it
).second
;
1672 // Record that this object has MIPS16 fn stub for local symbol. This method
1673 // is only called if we decided not to discard the stub.
1675 add_local_mips16_fn_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1677 gold_assert(stub
->is_for_local_function());
1678 unsigned int r_sym
= stub
->r_sym();
1679 this->local_mips16_fn_stubs_
.insert(
1680 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1684 // Return MIPS16 call stub section for local symbol R_SYM, or NULL if this
1685 // object doesn't have call stub for R_SYM.
1686 Mips16_stub_section
<size
, big_endian
>*
1687 get_local_mips16_call_stub(unsigned int r_sym
) const
1689 typename
Mips16_stubs_int_map::const_iterator it
=
1690 this->local_mips16_call_stubs_
.find(r_sym
);
1691 if (it
!= this->local_mips16_call_stubs_
.end())
1692 return (*it
).second
;
1696 // Record that this object has MIPS16 call stub for local symbol. This method
1697 // is only called if we decided not to discard the stub.
1699 add_local_mips16_call_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1701 gold_assert(stub
->is_for_local_function());
1702 unsigned int r_sym
= stub
->r_sym();
1703 this->local_mips16_call_stubs_
.insert(
1704 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1708 // Record that we found "non 16-bit" call relocation against local symbol
1709 // SYMNDX. This reloc would need to refer to a MIPS16 fn stub, if there
1712 add_local_non_16bit_call(unsigned int symndx
)
1713 { this->local_non_16bit_calls_
.insert(symndx
); }
1715 // Return true if there is any "non 16-bit" call relocation against local
1716 // symbol SYMNDX in this object.
1718 has_local_non_16bit_call_relocs(unsigned int symndx
)
1720 return (this->local_non_16bit_calls_
.find(symndx
)
1721 != this->local_non_16bit_calls_
.end());
1724 // Record that we found 16-bit call relocation R_MIPS16_26 against local
1725 // symbol SYMNDX. Local MIPS16 call or call_fp stubs will only be needed
1726 // if there is some R_MIPS16_26 relocation that refers to the stub symbol.
1728 add_local_16bit_call(unsigned int symndx
)
1729 { this->local_16bit_calls_
.insert(symndx
); }
1731 // Return true if there is any 16-bit call relocation R_MIPS16_26 against local
1732 // symbol SYMNDX in this object.
1734 has_local_16bit_call_relocs(unsigned int symndx
)
1736 return (this->local_16bit_calls_
.find(symndx
)
1737 != this->local_16bit_calls_
.end());
1740 // Get gp value that was used to create this object.
1743 { return this->gp_
; }
1745 // Return whether the object is a PIC object.
1748 { return this->is_pic_
; }
1750 // Return whether the object uses N32 ABI.
1753 { return this->is_n32_
; }
1755 // Return whether the object uses N64 ABI.
1758 { return size
== 64; }
1760 // Return whether the object uses NewABI conventions.
1763 { return this->is_n32() || this->is_n64(); }
1765 // Return Mips_got_info for this object.
1766 Mips_got_info
<size
, big_endian
>*
1767 get_got_info() const
1768 { return this->got_info_
; }
1770 // Return Mips_got_info for this object. Create new info if it doesn't exist.
1771 Mips_got_info
<size
, big_endian
>*
1772 get_or_create_got_info()
1774 if (!this->got_info_
)
1775 this->got_info_
= new Mips_got_info
<size
, big_endian
>();
1776 return this->got_info_
;
1779 // Set Mips_got_info for this object.
1781 set_got_info(Mips_got_info
<size
, big_endian
>* got_info
)
1782 { this->got_info_
= got_info
; }
1784 // Whether a section SHDNX is a MIPS16 stub section. This is only valid
1785 // after do_read_symbols is called.
1787 is_mips16_stub_section(unsigned int shndx
)
1789 return (is_mips16_fn_stub_section(shndx
)
1790 || is_mips16_call_stub_section(shndx
)
1791 || is_mips16_call_fp_stub_section(shndx
));
1794 // Return TRUE if relocations in section SHNDX can refer directly to a
1795 // MIPS16 function rather than to a hard-float stub. This is only valid
1796 // after do_read_symbols is called.
1798 section_allows_mips16_refs(unsigned int shndx
)
1800 return (this->is_mips16_stub_section(shndx
) || shndx
== this->pdr_shndx_
);
1803 // Whether a section SHDNX is a MIPS16 fn stub section. This is only valid
1804 // after do_read_symbols is called.
1806 is_mips16_fn_stub_section(unsigned int shndx
)
1808 gold_assert(shndx
< this->section_is_mips16_fn_stub_
.size());
1809 return this->section_is_mips16_fn_stub_
[shndx
];
1812 // Whether a section SHDNX is a MIPS16 call stub section. This is only valid
1813 // after do_read_symbols is called.
1815 is_mips16_call_stub_section(unsigned int shndx
)
1817 gold_assert(shndx
< this->section_is_mips16_call_stub_
.size());
1818 return this->section_is_mips16_call_stub_
[shndx
];
1821 // Whether a section SHDNX is a MIPS16 call_fp stub section. This is only
1822 // valid after do_read_symbols is called.
1824 is_mips16_call_fp_stub_section(unsigned int shndx
)
1826 gold_assert(shndx
< this->section_is_mips16_call_fp_stub_
.size());
1827 return this->section_is_mips16_call_fp_stub_
[shndx
];
1830 // Discard MIPS16 stub secions that are not needed.
1832 discard_mips16_stub_sections(Symbol_table
* symtab
);
1834 // Return whether there is a .reginfo section.
1836 has_reginfo_section() const
1837 { return this->has_reginfo_section_
; }
1839 // Return gprmask from the .reginfo section of this object.
1842 { return this->gprmask_
; }
1844 // Return cprmask1 from the .reginfo section of this object.
1847 { return this->cprmask1_
; }
1849 // Return cprmask2 from the .reginfo section of this object.
1852 { return this->cprmask2_
; }
1854 // Return cprmask3 from the .reginfo section of this object.
1857 { return this->cprmask3_
; }
1859 // Return cprmask4 from the .reginfo section of this object.
1862 { return this->cprmask4_
; }
1864 // This is the contents of the .MIPS.abiflags section if there is one.
1865 Mips_abiflags
<big_endian
>*
1867 { return this->abiflags_
; }
1869 // This is the contents of the .gnu.attribute section if there is one.
1870 const Attributes_section_data
*
1871 attributes_section_data() const
1872 { return this->attributes_section_data_
; }
1875 // Count the local symbols.
1877 do_count_local_symbols(Stringpool_template
<char>*,
1878 Stringpool_template
<char>*);
1880 // Read the symbol information.
1882 do_read_symbols(Read_symbols_data
* sd
);
1885 // The name of the options section.
1886 const char* mips_elf_options_section_name()
1887 { return this->is_newabi() ? ".MIPS.options" : ".options"; }
1889 // processor-specific flags in ELF file header.
1890 elfcpp::Elf_Word processor_specific_flags_
;
1892 // Bit vector to tell if a local symbol is a MIPS16 symbol or not.
1893 // This is only valid after do_count_local_symbol is called.
1894 std::vector
<bool> local_symbol_is_mips16_
;
1896 // Bit vector to tell if a local symbol is a microMIPS symbol or not.
1897 // This is only valid after do_count_local_symbol is called.
1898 std::vector
<bool> local_symbol_is_micromips_
;
1900 // Map from section index to the MIPS16 stub for that section. This contains
1901 // all stubs found in this object.
1902 Mips16_stubs_int_map mips16_stub_sections_
;
1904 // Local symbols that have "non 16-bit" call relocation. This relocation
1905 // would need to refer to a MIPS16 fn stub, if there is one.
1906 std::set
<unsigned int> local_non_16bit_calls_
;
1908 // Local symbols that have 16-bit call relocation R_MIPS16_26. Local MIPS16
1909 // call or call_fp stubs will only be needed if there is some R_MIPS16_26
1910 // relocation that refers to the stub symbol.
1911 std::set
<unsigned int> local_16bit_calls_
;
1913 // Map from local symbol index to the MIPS16 fn stub for that symbol.
1914 // This contains only the stubs that we decided not to discard.
1915 Mips16_stubs_int_map local_mips16_fn_stubs_
;
1917 // Map from local symbol index to the MIPS16 call stub for that symbol.
1918 // This contains only the stubs that we decided not to discard.
1919 Mips16_stubs_int_map local_mips16_call_stubs_
;
1921 // gp value that was used to create this object.
1923 // Whether the object is a PIC object.
1925 // Whether the object uses N32 ABI.
1927 // Whether the object contains a .reginfo section.
1928 bool has_reginfo_section_
: 1;
1929 // The Mips_got_info for this object.
1930 Mips_got_info
<size
, big_endian
>* got_info_
;
1932 // Bit vector to tell if a section is a MIPS16 fn stub section or not.
1933 // This is only valid after do_read_symbols is called.
1934 std::vector
<bool> section_is_mips16_fn_stub_
;
1936 // Bit vector to tell if a section is a MIPS16 call stub section or not.
1937 // This is only valid after do_read_symbols is called.
1938 std::vector
<bool> section_is_mips16_call_stub_
;
1940 // Bit vector to tell if a section is a MIPS16 call_fp stub section or not.
1941 // This is only valid after do_read_symbols is called.
1942 std::vector
<bool> section_is_mips16_call_fp_stub_
;
1944 // .pdr section index.
1945 unsigned int pdr_shndx_
;
1947 // Object attributes if there is a .gnu.attributes section or NULL.
1948 Attributes_section_data
* attributes_section_data_
;
1950 // Object abiflags if there is a .MIPS.abiflags section or NULL.
1951 Mips_abiflags
<big_endian
>* abiflags_
;
1953 // gprmask from the .reginfo section of this object.
1955 // cprmask1 from the .reginfo section of this object.
1957 // cprmask2 from the .reginfo section of this object.
1959 // cprmask3 from the .reginfo section of this object.
1961 // cprmask4 from the .reginfo section of this object.
1965 // Mips_output_data_got class.
1967 template<int size
, bool big_endian
>
1968 class Mips_output_data_got
: public Output_data_got
<size
, big_endian
>
1970 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1971 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
1973 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1976 Mips_output_data_got(Target_mips
<size
, big_endian
>* target
,
1977 Symbol_table
* symtab
, Layout
* layout
)
1978 : Output_data_got
<size
, big_endian
>(), target_(target
),
1979 symbol_table_(symtab
), layout_(layout
), static_relocs_(), got_view_(NULL
),
1980 first_global_got_dynsym_index_(-1U), primary_got_(NULL
),
1981 secondary_got_relocs_()
1983 this->master_got_info_
= new Mips_got_info
<size
, big_endian
>();
1984 this->set_addralign(16);
1987 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
1988 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
1990 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
1991 unsigned int symndx
, Mips_address addend
,
1992 unsigned int r_type
, unsigned int shndx
,
1993 bool is_section_symbol
)
1995 this->master_got_info_
->record_local_got_symbol(object
, symndx
, addend
,
2000 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
2001 // in OBJECT. FOR_CALL is true if the caller is only interested in
2002 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
2005 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
2006 Mips_relobj
<size
, big_endian
>* object
,
2007 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
2009 this->master_got_info_
->record_global_got_symbol(mips_sym
, object
, r_type
,
2010 dyn_reloc
, for_call
);
2013 // Record that OBJECT has a page relocation against symbol SYMNDX and
2014 // that ADDEND is the addend for that relocation.
2016 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
2017 unsigned int symndx
, int addend
)
2018 { this->master_got_info_
->record_got_page_entry(object
, symndx
, addend
); }
2020 // Add a static entry for the GOT entry at OFFSET. GSYM is a global
2021 // symbol and R_TYPE is the code of a dynamic relocation that needs to be
2022 // applied in a static link.
2024 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
2025 Mips_symbol
<size
>* gsym
)
2026 { this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, gsym
)); }
2028 // Add a static reloc for the GOT entry at OFFSET. RELOBJ is an object
2029 // defining a local symbol with INDEX. R_TYPE is the code of a dynamic
2030 // relocation that needs to be applied in a static link.
2032 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
2033 Sized_relobj_file
<size
, big_endian
>* relobj
,
2036 this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, relobj
,
2040 // Record that global symbol GSYM has R_TYPE dynamic relocation in the
2041 // secondary GOT at OFFSET.
2043 add_secondary_got_reloc(unsigned int got_offset
, unsigned int r_type
,
2044 Mips_symbol
<size
>* gsym
)
2046 this->secondary_got_relocs_
.push_back(Static_reloc(got_offset
,
2050 // Update GOT entry at OFFSET with VALUE.
2052 update_got_entry(unsigned int offset
, Mips_address value
)
2054 elfcpp::Swap
<size
, big_endian
>::writeval(this->got_view_
+ offset
, value
);
2057 // Return the number of entries in local part of the GOT. This includes
2058 // local entries, page entries and 2 reserved entries.
2060 get_local_gotno() const
2062 if (!this->multi_got())
2064 return (2 + this->master_got_info_
->local_gotno()
2065 + this->master_got_info_
->page_gotno());
2068 return 2 + this->primary_got_
->local_gotno() + this->primary_got_
->page_gotno();
2071 // Return dynamic symbol table index of the first symbol with global GOT
2074 first_global_got_dynsym_index() const
2075 { return this->first_global_got_dynsym_index_
; }
2077 // Set dynamic symbol table index of the first symbol with global GOT entry.
2079 set_first_global_got_dynsym_index(unsigned int index
)
2080 { this->first_global_got_dynsym_index_
= index
; }
2082 // Lay out the GOT. Add local, global and TLS entries. If GOT is
2083 // larger than 64K, create multi-GOT.
2085 lay_out_got(Layout
* layout
, Symbol_table
* symtab
,
2086 const Input_objects
* input_objects
);
2088 // Create multi-GOT. For every GOT, add local, global and TLS entries.
2090 lay_out_multi_got(Layout
* layout
, const Input_objects
* input_objects
);
2092 // Attempt to merge GOTs of different input objects.
2094 merge_gots(const Input_objects
* input_objects
);
2096 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
2097 // this would lead to overflow, true if they were merged successfully.
2099 merge_got_with(Mips_got_info
<size
, big_endian
>* from
,
2100 Mips_relobj
<size
, big_endian
>* object
,
2101 Mips_got_info
<size
, big_endian
>* to
);
2103 // Return the offset of GOT page entry for VALUE. For multi-GOT links,
2104 // use OBJECT's GOT.
2106 get_got_page_offset(Mips_address value
,
2107 const Mips_relobj
<size
, big_endian
>* object
)
2109 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2110 ? this->master_got_info_
2111 : object
->get_got_info());
2112 gold_assert(g
!= NULL
);
2113 return g
->get_got_page_offset(value
, this);
2116 // Return the GOT offset of type GOT_TYPE of the global symbol
2117 // GSYM. For multi-GOT links, use OBJECT's GOT.
2118 unsigned int got_offset(const Symbol
* gsym
, unsigned int got_type
,
2119 Mips_relobj
<size
, big_endian
>* object
) const
2121 if (!this->multi_got())
2122 return gsym
->got_offset(got_type
);
2125 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
2126 gold_assert(g
!= NULL
);
2127 return gsym
->got_offset(g
->multigot_got_type(got_type
));
2131 // Return the GOT offset of type GOT_TYPE of the local symbol
2134 got_offset(unsigned int symndx
, unsigned int got_type
,
2135 Sized_relobj_file
<size
, big_endian
>* object
,
2136 uint64_t addend
) const
2137 { return object
->local_got_offset(symndx
, got_type
, addend
); }
2139 // Return the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2141 tls_ldm_offset(Mips_relobj
<size
, big_endian
>* object
) const
2143 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2144 ? this->master_got_info_
2145 : object
->get_got_info());
2146 gold_assert(g
!= NULL
);
2147 return g
->tls_ldm_offset();
2150 // Set the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2152 set_tls_ldm_offset(unsigned int tls_ldm_offset
,
2153 Mips_relobj
<size
, big_endian
>* object
)
2155 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2156 ? this->master_got_info_
2157 : object
->get_got_info());
2158 gold_assert(g
!= NULL
);
2159 g
->set_tls_ldm_offset(tls_ldm_offset
);
2162 // Return true for multi-GOT links.
2165 { return this->primary_got_
!= NULL
; }
2167 // Return the offset of OBJECT's GOT from the start of .got section.
2169 get_got_offset(const Mips_relobj
<size
, big_endian
>* object
)
2171 if (!this->multi_got())
2175 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
2176 return g
!= NULL
? g
->offset() : 0;
2180 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
2182 add_reloc_only_entries()
2183 { this->master_got_info_
->add_reloc_only_entries(this); }
2185 // Return offset of the primary GOT's entry for global symbol.
2187 get_primary_got_offset(const Mips_symbol
<size
>* sym
) const
2189 gold_assert(sym
->global_got_area() != GGA_NONE
);
2190 return (this->get_local_gotno() + sym
->dynsym_index()
2191 - this->first_global_got_dynsym_index()) * size
/8;
2194 // For the entry at offset GOT_OFFSET, return its offset from the gp.
2195 // Input argument GOT_OFFSET is always global offset from the start of
2196 // .got section, for both single and multi-GOT links.
2197 // For single GOT links, this returns GOT_OFFSET - 0x7FF0. For multi-GOT
2198 // links, the return value is object_got_offset - 0x7FF0, where
2199 // object_got_offset is offset in the OBJECT's GOT.
2201 gp_offset(unsigned int got_offset
,
2202 const Mips_relobj
<size
, big_endian
>* object
) const
2204 return (this->address() + got_offset
2205 - this->target_
->adjusted_gp_value(object
));
2209 // Write out the GOT table.
2211 do_write(Output_file
*);
2215 // This class represent dynamic relocations that need to be applied by
2216 // gold because we are using TLS relocations in a static link.
2220 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2221 Mips_symbol
<size
>* gsym
)
2222 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(true)
2223 { this->u_
.global
.symbol
= gsym
; }
2225 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2226 Sized_relobj_file
<size
, big_endian
>* relobj
, unsigned int index
)
2227 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(false)
2229 this->u_
.local
.relobj
= relobj
;
2230 this->u_
.local
.index
= index
;
2233 // Return the GOT offset.
2236 { return this->got_offset_
; }
2241 { return this->r_type_
; }
2243 // Whether the symbol is global or not.
2245 symbol_is_global() const
2246 { return this->symbol_is_global_
; }
2248 // For a relocation against a global symbol, the global symbol.
2252 gold_assert(this->symbol_is_global_
);
2253 return this->u_
.global
.symbol
;
2256 // For a relocation against a local symbol, the defining object.
2257 Sized_relobj_file
<size
, big_endian
>*
2260 gold_assert(!this->symbol_is_global_
);
2261 return this->u_
.local
.relobj
;
2264 // For a relocation against a local symbol, the local symbol index.
2268 gold_assert(!this->symbol_is_global_
);
2269 return this->u_
.local
.index
;
2273 // GOT offset of the entry to which this relocation is applied.
2274 unsigned int got_offset_
;
2275 // Type of relocation.
2276 unsigned int r_type_
;
2277 // Whether this relocation is against a global symbol.
2278 bool symbol_is_global_
;
2279 // A global or local symbol.
2284 // For a global symbol, the symbol itself.
2285 Mips_symbol
<size
>* symbol
;
2289 // For a local symbol, the object defining object.
2290 Sized_relobj_file
<size
, big_endian
>* relobj
;
2291 // For a local symbol, the symbol index.
2298 Target_mips
<size
, big_endian
>* target_
;
2299 // The symbol table.
2300 Symbol_table
* symbol_table_
;
2303 // Static relocs to be applied to the GOT.
2304 std::vector
<Static_reloc
> static_relocs_
;
2305 // .got section view.
2306 unsigned char* got_view_
;
2307 // The dynamic symbol table index of the first symbol with global GOT entry.
2308 unsigned int first_global_got_dynsym_index_
;
2309 // The master GOT information.
2310 Mips_got_info
<size
, big_endian
>* master_got_info_
;
2311 // The primary GOT information.
2312 Mips_got_info
<size
, big_endian
>* primary_got_
;
2313 // Secondary GOT fixups.
2314 std::vector
<Static_reloc
> secondary_got_relocs_
;
2317 // A class to handle LA25 stubs - non-PIC interface to a PIC function. There are
2318 // two ways of creating these interfaces. The first is to add:
2320 // lui $25,%hi(func)
2322 // addiu $25,$25,%lo(func)
2324 // to a separate trampoline section. The second is to add:
2326 // lui $25,%hi(func)
2327 // addiu $25,$25,%lo(func)
2329 // immediately before a PIC function "func", but only if a function is at the
2330 // beginning of the section, and the section is not too heavily aligned (i.e we
2331 // would need to add no more than 2 nops before the stub.)
2333 // We only create stubs of the first type.
2335 template<int size
, bool big_endian
>
2336 class Mips_output_data_la25_stub
: public Output_section_data
2338 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2341 Mips_output_data_la25_stub()
2342 : Output_section_data(size
== 32 ? 4 : 8), symbols_()
2345 // Create LA25 stub for a symbol.
2347 create_la25_stub(Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
2348 Mips_symbol
<size
>* gsym
);
2350 // Return output address of a stub.
2352 stub_address(const Mips_symbol
<size
>* sym
) const
2354 gold_assert(sym
->has_la25_stub());
2355 return this->address() + sym
->la25_stub_offset();
2360 do_adjust_output_section(Output_section
* os
)
2361 { os
->set_entsize(0); }
2364 // Template for standard LA25 stub.
2365 static const uint32_t la25_stub_entry
[];
2366 // Template for microMIPS LA25 stub.
2367 static const uint32_t la25_stub_micromips_entry
[];
2369 // Set the final size.
2371 set_final_data_size()
2372 { this->set_data_size(this->symbols_
.size() * 16); }
2374 // Create a symbol for SYM stub's value and size, to help make the
2375 // disassembly easier to read.
2377 create_stub_symbol(Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
2378 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
);
2380 // Write to a map file.
2382 do_print_to_mapfile(Mapfile
* mapfile
) const
2383 { mapfile
->print_output_data(this, _(".LA25.stubs")); }
2385 // Write out the LA25 stub section.
2387 do_write(Output_file
*);
2389 // Symbols that have LA25 stubs.
2390 std::vector
<Mips_symbol
<size
>*> symbols_
;
2393 // MIPS-specific relocation writer.
2395 template<int sh_type
, bool dynamic
, int size
, bool big_endian
>
2396 struct Mips_output_reloc_writer
;
2398 template<int sh_type
, bool dynamic
, bool big_endian
>
2399 struct Mips_output_reloc_writer
<sh_type
, dynamic
, 32, big_endian
>
2401 typedef Output_reloc
<sh_type
, dynamic
, 32, big_endian
> Output_reloc_type
;
2402 typedef std::vector
<Output_reloc_type
> Relocs
;
2405 write(typename
Relocs::const_iterator p
, unsigned char* pov
)
2409 template<int sh_type
, bool dynamic
, bool big_endian
>
2410 struct Mips_output_reloc_writer
<sh_type
, dynamic
, 64, big_endian
>
2412 typedef Output_reloc
<sh_type
, dynamic
, 64, big_endian
> Output_reloc_type
;
2413 typedef std::vector
<Output_reloc_type
> Relocs
;
2416 write(typename
Relocs::const_iterator p
, unsigned char* pov
)
2418 elfcpp::Mips64_rel_write
<big_endian
> orel(pov
);
2419 orel
.put_r_offset(p
->get_address());
2420 orel
.put_r_sym(p
->get_symbol_index());
2421 orel
.put_r_ssym(RSS_UNDEF
);
2422 orel
.put_r_type(p
->type());
2423 if (p
->type() == elfcpp::R_MIPS_REL32
)
2424 orel
.put_r_type2(elfcpp::R_MIPS_64
);
2426 orel
.put_r_type2(elfcpp::R_MIPS_NONE
);
2427 orel
.put_r_type3(elfcpp::R_MIPS_NONE
);
2431 template<int sh_type
, bool dynamic
, int size
, bool big_endian
>
2432 class Mips_output_data_reloc
: public Output_data_reloc
<sh_type
, dynamic
,
2436 Mips_output_data_reloc(bool sort_relocs
)
2437 : Output_data_reloc
<sh_type
, dynamic
, size
, big_endian
>(sort_relocs
)
2441 // Write out the data.
2443 do_write(Output_file
* of
)
2445 typedef Mips_output_reloc_writer
<sh_type
, dynamic
, size
,
2447 this->template do_write_generic
<Writer
>(of
);
2452 // A class to handle the PLT data.
2454 template<int size
, bool big_endian
>
2455 class Mips_output_data_plt
: public Output_section_data
2457 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2458 typedef Mips_output_data_reloc
<elfcpp::SHT_REL
, true,
2459 size
, big_endian
> Reloc_section
;
2462 // Create the PLT section. The ordinary .got section is an argument,
2463 // since we need to refer to the start.
2464 Mips_output_data_plt(Layout
* layout
, Output_data_space
* got_plt
,
2465 Target_mips
<size
, big_endian
>* target
)
2466 : Output_section_data(size
== 32 ? 4 : 8), got_plt_(got_plt
), symbols_(),
2467 plt_mips_offset_(0), plt_comp_offset_(0), plt_header_size_(0),
2470 this->rel_
= new Reloc_section(false);
2471 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
2472 elfcpp::SHF_ALLOC
, this->rel_
,
2473 ORDER_DYNAMIC_PLT_RELOCS
, false);
2476 // Add an entry to the PLT for a symbol referenced by r_type relocation.
2478 add_entry(Mips_symbol
<size
>* gsym
, unsigned int r_type
);
2480 // Return the .rel.plt section data.
2483 { return this->rel_
; }
2485 // Return the number of PLT entries.
2488 { return this->symbols_
.size(); }
2490 // Return the offset of the first non-reserved PLT entry.
2492 first_plt_entry_offset() const
2493 { return sizeof(plt0_entry_o32
); }
2495 // Return the size of a PLT entry.
2497 plt_entry_size() const
2498 { return sizeof(plt_entry
); }
2500 // Set final PLT offsets. For each symbol, determine whether standard or
2501 // compressed (MIPS16 or microMIPS) PLT entry is used.
2505 // Return the offset of the first standard PLT entry.
2507 first_mips_plt_offset() const
2508 { return this->plt_header_size_
; }
2510 // Return the offset of the first compressed PLT entry.
2512 first_comp_plt_offset() const
2513 { return this->plt_header_size_
+ this->plt_mips_offset_
; }
2515 // Return whether there are any standard PLT entries.
2517 has_standard_entries() const
2518 { return this->plt_mips_offset_
> 0; }
2520 // Return the output address of standard PLT entry.
2522 mips_entry_address(const Mips_symbol
<size
>* sym
) const
2524 gold_assert (sym
->has_mips_plt_offset());
2525 return (this->address() + this->first_mips_plt_offset()
2526 + sym
->mips_plt_offset());
2529 // Return the output address of compressed (MIPS16 or microMIPS) PLT entry.
2531 comp_entry_address(const Mips_symbol
<size
>* sym
) const
2533 gold_assert (sym
->has_comp_plt_offset());
2534 return (this->address() + this->first_comp_plt_offset()
2535 + sym
->comp_plt_offset());
2540 do_adjust_output_section(Output_section
* os
)
2541 { os
->set_entsize(0); }
2543 // Write to a map file.
2545 do_print_to_mapfile(Mapfile
* mapfile
) const
2546 { mapfile
->print_output_data(this, _(".plt")); }
2549 // Template for the first PLT entry.
2550 static const uint32_t plt0_entry_o32
[];
2551 static const uint32_t plt0_entry_n32
[];
2552 static const uint32_t plt0_entry_n64
[];
2553 static const uint32_t plt0_entry_micromips_o32
[];
2554 static const uint32_t plt0_entry_micromips32_o32
[];
2556 // Template for subsequent PLT entries.
2557 static const uint32_t plt_entry
[];
2558 static const uint32_t plt_entry_r6
[];
2559 static const uint32_t plt_entry_mips16_o32
[];
2560 static const uint32_t plt_entry_micromips_o32
[];
2561 static const uint32_t plt_entry_micromips32_o32
[];
2563 // Set the final size.
2565 set_final_data_size()
2567 this->set_data_size(this->plt_header_size_
+ this->plt_mips_offset_
2568 + this->plt_comp_offset_
);
2571 // Write out the PLT data.
2573 do_write(Output_file
*);
2575 // Return whether the plt header contains microMIPS code. For the sake of
2576 // cache alignment always use a standard header whenever any standard entries
2577 // are present even if microMIPS entries are present as well. This also lets
2578 // the microMIPS header rely on the value of $v0 only set by microMIPS
2579 // entries, for a small size reduction.
2581 is_plt_header_compressed() const
2583 gold_assert(this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0);
2584 return this->target_
->is_output_micromips() && this->plt_mips_offset_
== 0;
2587 // Return the size of the PLT header.
2589 get_plt_header_size() const
2591 if (this->target_
->is_output_n64())
2592 return 4 * sizeof(plt0_entry_n64
) / sizeof(plt0_entry_n64
[0]);
2593 else if (this->target_
->is_output_n32())
2594 return 4 * sizeof(plt0_entry_n32
) / sizeof(plt0_entry_n32
[0]);
2595 else if (!this->is_plt_header_compressed())
2596 return 4 * sizeof(plt0_entry_o32
) / sizeof(plt0_entry_o32
[0]);
2597 else if (this->target_
->use_32bit_micromips_instructions())
2598 return (2 * sizeof(plt0_entry_micromips32_o32
)
2599 / sizeof(plt0_entry_micromips32_o32
[0]));
2601 return (2 * sizeof(plt0_entry_micromips_o32
)
2602 / sizeof(plt0_entry_micromips_o32
[0]));
2605 // Return the PLT header entry.
2607 get_plt_header_entry() const
2609 if (this->target_
->is_output_n64())
2610 return plt0_entry_n64
;
2611 else if (this->target_
->is_output_n32())
2612 return plt0_entry_n32
;
2613 else if (!this->is_plt_header_compressed())
2614 return plt0_entry_o32
;
2615 else if (this->target_
->use_32bit_micromips_instructions())
2616 return plt0_entry_micromips32_o32
;
2618 return plt0_entry_micromips_o32
;
2621 // Return the size of the standard PLT entry.
2623 standard_plt_entry_size() const
2624 { return 4 * sizeof(plt_entry
) / sizeof(plt_entry
[0]); }
2626 // Return the size of the compressed PLT entry.
2628 compressed_plt_entry_size() const
2630 gold_assert(!this->target_
->is_output_newabi());
2632 if (!this->target_
->is_output_micromips())
2633 return (2 * sizeof(plt_entry_mips16_o32
)
2634 / sizeof(plt_entry_mips16_o32
[0]));
2635 else if (this->target_
->use_32bit_micromips_instructions())
2636 return (2 * sizeof(plt_entry_micromips32_o32
)
2637 / sizeof(plt_entry_micromips32_o32
[0]));
2639 return (2 * sizeof(plt_entry_micromips_o32
)
2640 / sizeof(plt_entry_micromips_o32
[0]));
2643 // The reloc section.
2644 Reloc_section
* rel_
;
2645 // The .got.plt section.
2646 Output_data_space
* got_plt_
;
2647 // Symbols that have PLT entry.
2648 std::vector
<Mips_symbol
<size
>*> symbols_
;
2649 // The offset of the next standard PLT entry to create.
2650 unsigned int plt_mips_offset_
;
2651 // The offset of the next compressed PLT entry to create.
2652 unsigned int plt_comp_offset_
;
2653 // The size of the PLT header in bytes.
2654 unsigned int plt_header_size_
;
2656 Target_mips
<size
, big_endian
>* target_
;
2659 // A class to handle the .MIPS.stubs data.
2661 template<int size
, bool big_endian
>
2662 class Mips_output_data_mips_stubs
: public Output_section_data
2664 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2666 // Unordered set of .MIPS.stubs entries.
2667 typedef Unordered_set
<Mips_symbol
<size
>*, Mips_symbol_hash
<size
> >
2668 Mips_stubs_entry_set
;
2671 Mips_output_data_mips_stubs(Target_mips
<size
, big_endian
>* target
)
2672 : Output_section_data(size
== 32 ? 4 : 8), symbols_(), dynsym_count_(-1U),
2673 stub_offsets_are_set_(false), target_(target
)
2676 // Create entry for a symbol.
2678 make_entry(Mips_symbol
<size
>*);
2680 // Remove entry for a symbol.
2682 remove_entry(Mips_symbol
<size
>* gsym
);
2684 // Set stub offsets for symbols. This method expects that the number of
2685 // entries in dynamic symbol table is set.
2687 set_lazy_stub_offsets();
2690 set_needs_dynsym_value();
2692 // Set the number of entries in dynamic symbol table.
2694 set_dynsym_count(unsigned int dynsym_count
)
2695 { this->dynsym_count_
= dynsym_count
; }
2697 // Return maximum size of the stub, ie. the stub size if the dynamic symbol
2698 // count is greater than 0x10000. If the dynamic symbol count is less than
2699 // 0x10000, the stub will be 4 bytes smaller.
2700 // There's no disadvantage from using microMIPS code here, so for the sake of
2701 // pure-microMIPS binaries we prefer it whenever there's any microMIPS code in
2702 // output produced at all. This has a benefit of stubs being shorter by
2703 // 4 bytes each too, unless in the insn32 mode.
2705 stub_max_size() const
2707 if (!this->target_
->is_output_micromips()
2708 || this->target_
->use_32bit_micromips_instructions())
2714 // Return the size of the stub. This method expects that the final dynsym
2719 gold_assert(this->dynsym_count_
!= -1U);
2720 if (this->dynsym_count_
> 0x10000)
2721 return this->stub_max_size();
2723 return this->stub_max_size() - 4;
2726 // Return output address of a stub.
2728 stub_address(const Mips_symbol
<size
>* sym
) const
2730 gold_assert(sym
->has_lazy_stub());
2731 return this->address() + sym
->lazy_stub_offset();
2736 do_adjust_output_section(Output_section
* os
)
2737 { os
->set_entsize(0); }
2739 // Write to a map file.
2741 do_print_to_mapfile(Mapfile
* mapfile
) const
2742 { mapfile
->print_output_data(this, _(".MIPS.stubs")); }
2745 static const uint32_t lazy_stub_normal_1
[];
2746 static const uint32_t lazy_stub_normal_1_n64
[];
2747 static const uint32_t lazy_stub_normal_2
[];
2748 static const uint32_t lazy_stub_normal_2_n64
[];
2749 static const uint32_t lazy_stub_big
[];
2750 static const uint32_t lazy_stub_big_n64
[];
2752 static const uint32_t lazy_stub_micromips_normal_1
[];
2753 static const uint32_t lazy_stub_micromips_normal_1_n64
[];
2754 static const uint32_t lazy_stub_micromips_normal_2
[];
2755 static const uint32_t lazy_stub_micromips_normal_2_n64
[];
2756 static const uint32_t lazy_stub_micromips_big
[];
2757 static const uint32_t lazy_stub_micromips_big_n64
[];
2759 static const uint32_t lazy_stub_micromips32_normal_1
[];
2760 static const uint32_t lazy_stub_micromips32_normal_1_n64
[];
2761 static const uint32_t lazy_stub_micromips32_normal_2
[];
2762 static const uint32_t lazy_stub_micromips32_normal_2_n64
[];
2763 static const uint32_t lazy_stub_micromips32_big
[];
2764 static const uint32_t lazy_stub_micromips32_big_n64
[];
2766 // Set the final size.
2768 set_final_data_size()
2769 { this->set_data_size(this->symbols_
.size() * this->stub_max_size()); }
2771 // Write out the .MIPS.stubs data.
2773 do_write(Output_file
*);
2775 // .MIPS.stubs symbols
2776 Mips_stubs_entry_set symbols_
;
2777 // Number of entries in dynamic symbol table.
2778 unsigned int dynsym_count_
;
2779 // Whether the stub offsets are set.
2780 bool stub_offsets_are_set_
;
2782 Target_mips
<size
, big_endian
>* target_
;
2785 // This class handles Mips .reginfo output section.
2787 template<int size
, bool big_endian
>
2788 class Mips_output_section_reginfo
: public Output_section_data
2790 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
2793 Mips_output_section_reginfo(Target_mips
<size
, big_endian
>* target
,
2794 Valtype gprmask
, Valtype cprmask1
,
2795 Valtype cprmask2
, Valtype cprmask3
,
2797 : Output_section_data(24, 4, true), target_(target
),
2798 gprmask_(gprmask
), cprmask1_(cprmask1
), cprmask2_(cprmask2
),
2799 cprmask3_(cprmask3
), cprmask4_(cprmask4
)
2803 // Write to a map file.
2805 do_print_to_mapfile(Mapfile
* mapfile
) const
2806 { mapfile
->print_output_data(this, _(".reginfo")); }
2808 // Write out reginfo section.
2810 do_write(Output_file
* of
);
2813 Target_mips
<size
, big_endian
>* target_
;
2815 // gprmask of the output .reginfo section.
2817 // cprmask1 of the output .reginfo section.
2819 // cprmask2 of the output .reginfo section.
2821 // cprmask3 of the output .reginfo section.
2823 // cprmask4 of the output .reginfo section.
2827 // This class handles .MIPS.options output section.
2829 template<int size
, bool big_endian
>
2830 class Mips_output_section_options
: public Output_section
2833 Mips_output_section_options(const char* name
, elfcpp::Elf_Word type
,
2834 elfcpp::Elf_Xword flags
,
2835 Target_mips
<size
, big_endian
>* target
)
2836 : Output_section(name
, type
, flags
), target_(target
)
2838 // After the input sections are written, we only need to update
2839 // ri_gp_value field of ODK_REGINFO entries.
2840 this->set_after_input_sections();
2844 // Write out option section.
2846 do_write(Output_file
* of
);
2849 Target_mips
<size
, big_endian
>* target_
;
2852 // This class handles .MIPS.abiflags output section.
2854 template<int size
, bool big_endian
>
2855 class Mips_output_section_abiflags
: public Output_section_data
2858 Mips_output_section_abiflags(const Mips_abiflags
<big_endian
>& abiflags
)
2859 : Output_section_data(24, 8, true), abiflags_(abiflags
)
2863 // Write to a map file.
2865 do_print_to_mapfile(Mapfile
* mapfile
) const
2866 { mapfile
->print_output_data(this, _(".MIPS.abiflags")); }
2869 do_write(Output_file
* of
);
2872 const Mips_abiflags
<big_endian
>& abiflags_
;
2875 // The MIPS target has relocation types which default handling of relocatable
2876 // relocation cannot process. So we have to extend the default code.
2878 template<bool big_endian
, typename Classify_reloc
>
2879 class Mips_scan_relocatable_relocs
:
2880 public Default_scan_relocatable_relocs
<Classify_reloc
>
2883 // Return the strategy to use for a local symbol which is a section
2884 // symbol, given the relocation type.
2885 inline Relocatable_relocs::Reloc_strategy
2886 local_section_strategy(unsigned int r_type
, Relobj
* object
)
2888 if (Classify_reloc::sh_type
== elfcpp::SHT_RELA
)
2889 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
2894 case elfcpp::R_MIPS_26
:
2895 return Relocatable_relocs::RELOC_SPECIAL
;
2898 return Default_scan_relocatable_relocs
<Classify_reloc
>::
2899 local_section_strategy(r_type
, object
);
2905 // Mips_copy_relocs class. The only difference from the base class is the
2906 // method emit_mips, which should be called instead of Copy_reloc_entry::emit.
2907 // Mips cannot convert all relocation types to dynamic relocs. If a reloc
2908 // cannot be made dynamic, a COPY reloc is emitted.
2910 template<int sh_type
, int size
, bool big_endian
>
2911 class Mips_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
2915 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_MIPS_COPY
)
2918 // Emit any saved relocations which turn out to be needed. This is
2919 // called after all the relocs have been scanned.
2921 emit_mips(Output_data_reloc
<sh_type
, true, size
, big_endian
>*,
2922 Symbol_table
*, Layout
*, Target_mips
<size
, big_endian
>*);
2925 typedef typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
2928 // Emit this reloc if appropriate. This is called after we have
2929 // scanned all the relocations, so we know whether we emitted a
2930 // COPY relocation for SYM_.
2932 emit_entry(Copy_reloc_entry
& entry
,
2933 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
2934 Symbol_table
* symtab
, Layout
* layout
,
2935 Target_mips
<size
, big_endian
>* target
);
2939 // Return true if the symbol SYM should be considered to resolve local
2940 // to the current module, and false otherwise. The logic is taken from
2941 // GNU ld's method _bfd_elf_symbol_refs_local_p.
2943 symbol_refs_local(const Symbol
* sym
, bool has_dynsym_entry
,
2944 bool local_protected
)
2946 // If it's a local sym, of course we resolve locally.
2950 // STV_HIDDEN or STV_INTERNAL ones must be local.
2951 if (sym
->visibility() == elfcpp::STV_HIDDEN
2952 || sym
->visibility() == elfcpp::STV_INTERNAL
)
2955 // If we don't have a definition in a regular file, then we can't
2956 // resolve locally. The sym is either undefined or dynamic.
2957 if (sym
->is_from_dynobj() || sym
->is_undefined())
2960 // Forced local symbols resolve locally.
2961 if (sym
->is_forced_local())
2964 // As do non-dynamic symbols.
2965 if (!has_dynsym_entry
)
2968 // At this point, we know the symbol is defined and dynamic. In an
2969 // executable it must resolve locally, likewise when building symbolic
2970 // shared libraries.
2971 if (parameters
->options().output_is_executable()
2972 || parameters
->options().Bsymbolic())
2975 // Now deal with defined dynamic symbols in shared libraries. Ones
2976 // with default visibility might not resolve locally.
2977 if (sym
->visibility() == elfcpp::STV_DEFAULT
)
2980 // STV_PROTECTED non-function symbols are local.
2981 if (sym
->type() != elfcpp::STT_FUNC
)
2984 // Function pointer equality tests may require that STV_PROTECTED
2985 // symbols be treated as dynamic symbols. If the address of a
2986 // function not defined in an executable is set to that function's
2987 // plt entry in the executable, then the address of the function in
2988 // a shared library must also be the plt entry in the executable.
2989 return local_protected
;
2992 // Return TRUE if references to this symbol always reference the symbol in this
2995 symbol_references_local(const Symbol
* sym
, bool has_dynsym_entry
)
2997 return symbol_refs_local(sym
, has_dynsym_entry
, false);
3000 // Return TRUE if calls to this symbol always call the version in this object.
3002 symbol_calls_local(const Symbol
* sym
, bool has_dynsym_entry
)
3004 return symbol_refs_local(sym
, has_dynsym_entry
, true);
3007 // Compare GOT offsets of two symbols.
3009 template<int size
, bool big_endian
>
3011 got_offset_compare(Symbol
* sym1
, Symbol
* sym2
)
3013 Mips_symbol
<size
>* mips_sym1
= Mips_symbol
<size
>::as_mips_sym(sym1
);
3014 Mips_symbol
<size
>* mips_sym2
= Mips_symbol
<size
>::as_mips_sym(sym2
);
3015 unsigned int area1
= mips_sym1
->global_got_area();
3016 unsigned int area2
= mips_sym2
->global_got_area();
3017 gold_assert(area1
!= GGA_NONE
&& area1
!= GGA_NONE
);
3019 // GGA_NORMAL entries always come before GGA_RELOC_ONLY.
3021 return area1
< area2
;
3023 return mips_sym1
->global_gotoffset() < mips_sym2
->global_gotoffset();
3026 // This method divides dynamic symbols into symbols that have GOT entry, and
3027 // symbols that don't have GOT entry. It also sorts symbols with the GOT entry.
3028 // Mips ABI requires that symbols with the GOT entry must be at the end of
3029 // dynamic symbol table, and the order in dynamic symbol table must match the
3032 template<int size
, bool big_endian
>
3034 reorder_dyn_symbols(std::vector
<Symbol
*>* dyn_symbols
,
3035 std::vector
<Symbol
*>* non_got_symbols
,
3036 std::vector
<Symbol
*>* got_symbols
)
3038 for (std::vector
<Symbol
*>::iterator p
= dyn_symbols
->begin();
3039 p
!= dyn_symbols
->end();
3042 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(*p
);
3043 if (mips_sym
->global_got_area() == GGA_NORMAL
3044 || mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
3045 got_symbols
->push_back(mips_sym
);
3047 non_got_symbols
->push_back(mips_sym
);
3050 std::sort(got_symbols
->begin(), got_symbols
->end(),
3051 got_offset_compare
<size
, big_endian
>);
3054 // Functor class for processing the global symbol table.
3056 template<int size
, bool big_endian
>
3057 class Symbol_visitor_check_symbols
3060 Symbol_visitor_check_symbols(Target_mips
<size
, big_endian
>* target
,
3061 Layout
* layout
, Symbol_table
* symtab
)
3062 : target_(target
), layout_(layout
), symtab_(symtab
)
3066 operator()(Sized_symbol
<size
>* sym
)
3068 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
3069 if (local_pic_function
<size
, big_endian
>(mips_sym
))
3071 // SYM is a function that might need $25 to be valid on entry.
3072 // If we're creating a non-PIC relocatable object, mark SYM as
3073 // being PIC. If we're creating a non-relocatable object with
3074 // non-PIC branches and jumps to SYM, make sure that SYM has an la25
3076 if (parameters
->options().relocatable())
3078 if (!parameters
->options().output_is_position_independent())
3079 mips_sym
->set_pic();
3081 else if (mips_sym
->has_nonpic_branches())
3083 this->target_
->la25_stub_section(layout_
)
3084 ->create_la25_stub(this->symtab_
, this->target_
, mips_sym
);
3090 Target_mips
<size
, big_endian
>* target_
;
3092 Symbol_table
* symtab_
;
3095 // Relocation types, parameterized by SHT_REL vs. SHT_RELA, size,
3096 // and endianness. The relocation format for MIPS-64 is non-standard.
3098 template<int sh_type
, int size
, bool big_endian
>
3099 struct Mips_reloc_types
;
3101 template<bool big_endian
>
3102 struct Mips_reloc_types
<elfcpp::SHT_REL
, 32, big_endian
>
3104 typedef typename
elfcpp::Rel
<32, big_endian
> Reloc
;
3105 typedef typename
elfcpp::Rel_write
<32, big_endian
> Reloc_write
;
3107 static typename
elfcpp::Elf_types
<32>::Elf_Swxword
3108 get_r_addend(const Reloc
*)
3112 set_reloc_addend(Reloc_write
*,
3113 typename
elfcpp::Elf_types
<32>::Elf_Swxword
)
3114 { gold_unreachable(); }
3117 template<bool big_endian
>
3118 struct Mips_reloc_types
<elfcpp::SHT_RELA
, 32, big_endian
>
3120 typedef typename
elfcpp::Rela
<32, big_endian
> Reloc
;
3121 typedef typename
elfcpp::Rela_write
<32, big_endian
> Reloc_write
;
3123 static typename
elfcpp::Elf_types
<32>::Elf_Swxword
3124 get_r_addend(const Reloc
* reloc
)
3125 { return reloc
->get_r_addend(); }
3128 set_reloc_addend(Reloc_write
* p
,
3129 typename
elfcpp::Elf_types
<32>::Elf_Swxword val
)
3130 { p
->put_r_addend(val
); }
3133 template<bool big_endian
>
3134 struct Mips_reloc_types
<elfcpp::SHT_REL
, 64, big_endian
>
3136 typedef typename
elfcpp::Mips64_rel
<big_endian
> Reloc
;
3137 typedef typename
elfcpp::Mips64_rel_write
<big_endian
> Reloc_write
;
3139 static typename
elfcpp::Elf_types
<64>::Elf_Swxword
3140 get_r_addend(const Reloc
*)
3144 set_reloc_addend(Reloc_write
*,
3145 typename
elfcpp::Elf_types
<64>::Elf_Swxword
)
3146 { gold_unreachable(); }
3149 template<bool big_endian
>
3150 struct Mips_reloc_types
<elfcpp::SHT_RELA
, 64, big_endian
>
3152 typedef typename
elfcpp::Mips64_rela
<big_endian
> Reloc
;
3153 typedef typename
elfcpp::Mips64_rela_write
<big_endian
> Reloc_write
;
3155 static typename
elfcpp::Elf_types
<64>::Elf_Swxword
3156 get_r_addend(const Reloc
* reloc
)
3157 { return reloc
->get_r_addend(); }
3160 set_reloc_addend(Reloc_write
* p
,
3161 typename
elfcpp::Elf_types
<64>::Elf_Swxword val
)
3162 { p
->put_r_addend(val
); }
3165 // Forward declaration.
3167 mips_get_size_for_reloc(unsigned int, Relobj
*);
3169 // A class for inquiring about properties of a relocation,
3170 // used while scanning relocs during a relocatable link and
3171 // garbage collection.
3173 template<int sh_type_
, int size
, bool big_endian
>
3174 class Mips_classify_reloc
;
3176 template<int sh_type_
, bool big_endian
>
3177 class Mips_classify_reloc
<sh_type_
, 32, big_endian
> :
3178 public gold::Default_classify_reloc
<sh_type_
, 32, big_endian
>
3181 typedef typename Mips_reloc_types
<sh_type_
, 32, big_endian
>::Reloc
3183 typedef typename Mips_reloc_types
<sh_type_
, 32, big_endian
>::Reloc_write
3186 // Return the symbol referred to by the relocation.
3187 static inline unsigned int
3188 get_r_sym(const Reltype
* reloc
)
3189 { return elfcpp::elf_r_sym
<32>(reloc
->get_r_info()); }
3191 // Return the type of the relocation.
3192 static inline unsigned int
3193 get_r_type(const Reltype
* reloc
)
3194 { return elfcpp::elf_r_type
<32>(reloc
->get_r_info()); }
3196 static inline unsigned int
3197 get_r_type2(const Reltype
*)
3200 static inline unsigned int
3201 get_r_type3(const Reltype
*)
3204 static inline unsigned int
3205 get_r_ssym(const Reltype
*)
3208 // Return the explicit addend of the relocation (return 0 for SHT_REL).
3209 static inline unsigned int
3210 get_r_addend(const Reltype
* reloc
)
3212 if (sh_type_
== elfcpp::SHT_REL
)
3214 return Mips_reloc_types
<sh_type_
, 32, big_endian
>::get_r_addend(reloc
);
3217 // Write the r_info field to a new reloc, using the r_info field from
3218 // the original reloc, replacing the r_sym field with R_SYM.
3220 put_r_info(Reltype_write
* new_reloc
, Reltype
* reloc
, unsigned int r_sym
)
3222 unsigned int r_type
= elfcpp::elf_r_type
<32>(reloc
->get_r_info());
3223 new_reloc
->put_r_info(elfcpp::elf_r_info
<32>(r_sym
, r_type
));
3226 // Write the r_addend field to a new reloc.
3228 put_r_addend(Reltype_write
* to
,
3229 typename
elfcpp::Elf_types
<32>::Elf_Swxword addend
)
3230 { Mips_reloc_types
<sh_type_
, 32, big_endian
>::set_reloc_addend(to
, addend
); }
3232 // Return the size of the addend of the relocation (only used for SHT_REL).
3234 get_size_for_reloc(unsigned int r_type
, Relobj
* obj
)
3235 { return mips_get_size_for_reloc(r_type
, obj
); }
3238 template<int sh_type_
, bool big_endian
>
3239 class Mips_classify_reloc
<sh_type_
, 64, big_endian
> :
3240 public gold::Default_classify_reloc
<sh_type_
, 64, big_endian
>
3243 typedef typename Mips_reloc_types
<sh_type_
, 64, big_endian
>::Reloc
3245 typedef typename Mips_reloc_types
<sh_type_
, 64, big_endian
>::Reloc_write
3248 // Return the symbol referred to by the relocation.
3249 static inline unsigned int
3250 get_r_sym(const Reltype
* reloc
)
3251 { return reloc
->get_r_sym(); }
3253 // Return the r_type of the relocation.
3254 static inline unsigned int
3255 get_r_type(const Reltype
* reloc
)
3256 { return reloc
->get_r_type(); }
3258 // Return the r_type2 of the relocation.
3259 static inline unsigned int
3260 get_r_type2(const Reltype
* reloc
)
3261 { return reloc
->get_r_type2(); }
3263 // Return the r_type3 of the relocation.
3264 static inline unsigned int
3265 get_r_type3(const Reltype
* reloc
)
3266 { return reloc
->get_r_type3(); }
3268 // Return the special symbol of the relocation.
3269 static inline unsigned int
3270 get_r_ssym(const Reltype
* reloc
)
3271 { return reloc
->get_r_ssym(); }
3273 // Return the explicit addend of the relocation (return 0 for SHT_REL).
3274 static inline typename
elfcpp::Elf_types
<64>::Elf_Swxword
3275 get_r_addend(const Reltype
* reloc
)
3277 if (sh_type_
== elfcpp::SHT_REL
)
3279 return Mips_reloc_types
<sh_type_
, 64, big_endian
>::get_r_addend(reloc
);
3282 // Write the r_info field to a new reloc, using the r_info field from
3283 // the original reloc, replacing the r_sym field with R_SYM.
3285 put_r_info(Reltype_write
* new_reloc
, Reltype
* reloc
, unsigned int r_sym
)
3287 new_reloc
->put_r_sym(r_sym
);
3288 new_reloc
->put_r_ssym(reloc
->get_r_ssym());
3289 new_reloc
->put_r_type3(reloc
->get_r_type3());
3290 new_reloc
->put_r_type2(reloc
->get_r_type2());
3291 new_reloc
->put_r_type(reloc
->get_r_type());
3294 // Write the r_addend field to a new reloc.
3296 put_r_addend(Reltype_write
* to
,
3297 typename
elfcpp::Elf_types
<64>::Elf_Swxword addend
)
3298 { Mips_reloc_types
<sh_type_
, 64, big_endian
>::set_reloc_addend(to
, addend
); }
3300 // Return the size of the addend of the relocation (only used for SHT_REL).
3302 get_size_for_reloc(unsigned int r_type
, Relobj
* obj
)
3303 { return mips_get_size_for_reloc(r_type
, obj
); }
3306 template<int size
, bool big_endian
>
3307 class Target_mips
: public Sized_target
<size
, big_endian
>
3309 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
3310 typedef Mips_output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
3312 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
3313 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
3314 typedef typename Mips_reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
3316 typedef typename Mips_reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
3320 Target_mips(const Target::Target_info
* info
= &mips_info
)
3321 : Sized_target
<size
, big_endian
>(info
), got_(NULL
), gp_(NULL
), plt_(NULL
),
3322 got_plt_(NULL
), rel_dyn_(NULL
), rld_map_(NULL
), copy_relocs_(),
3323 dyn_relocs_(), la25_stub_(NULL
), mips_mach_extensions_(),
3324 mips_stubs_(NULL
), attributes_section_data_(NULL
), abiflags_(NULL
),
3325 mach_(0), layout_(NULL
), got16_addends_(), has_abiflags_section_(false),
3326 entry_symbol_is_compressed_(false), insn32_(false)
3328 this->add_machine_extensions();
3331 // The offset of $gp from the beginning of the .got section.
3332 static const unsigned int MIPS_GP_OFFSET
= 0x7ff0;
3334 // The maximum size of the GOT for it to be addressable using 16-bit
3335 // offsets from $gp.
3336 static const unsigned int MIPS_GOT_MAX_SIZE
= MIPS_GP_OFFSET
+ 0x7fff;
3338 // Make a new symbol table entry for the Mips target.
3340 make_symbol(const char*, elfcpp::STT
, Object
*, unsigned int, uint64_t)
3341 { return new Mips_symbol
<size
>(); }
3343 // Process the relocations to determine unreferenced sections for
3344 // garbage collection.
3346 gc_process_relocs(Symbol_table
* symtab
,
3348 Sized_relobj_file
<size
, big_endian
>* object
,
3349 unsigned int data_shndx
,
3350 unsigned int sh_type
,
3351 const unsigned char* prelocs
,
3353 Output_section
* output_section
,
3354 bool needs_special_offset_handling
,
3355 size_t local_symbol_count
,
3356 const unsigned char* plocal_symbols
);
3358 // Scan the relocations to look for symbol adjustments.
3360 scan_relocs(Symbol_table
* symtab
,
3362 Sized_relobj_file
<size
, big_endian
>* object
,
3363 unsigned int data_shndx
,
3364 unsigned int sh_type
,
3365 const unsigned char* prelocs
,
3367 Output_section
* output_section
,
3368 bool needs_special_offset_handling
,
3369 size_t local_symbol_count
,
3370 const unsigned char* plocal_symbols
);
3372 // Finalize the sections.
3374 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
3376 // Relocate a section.
3378 relocate_section(const Relocate_info
<size
, big_endian
>*,
3379 unsigned int sh_type
,
3380 const unsigned char* prelocs
,
3382 Output_section
* output_section
,
3383 bool needs_special_offset_handling
,
3384 unsigned char* view
,
3385 Mips_address view_address
,
3386 section_size_type view_size
,
3387 const Reloc_symbol_changes
*);
3389 // Scan the relocs during a relocatable link.
3391 scan_relocatable_relocs(Symbol_table
* symtab
,
3393 Sized_relobj_file
<size
, big_endian
>* object
,
3394 unsigned int data_shndx
,
3395 unsigned int sh_type
,
3396 const unsigned char* prelocs
,
3398 Output_section
* output_section
,
3399 bool needs_special_offset_handling
,
3400 size_t local_symbol_count
,
3401 const unsigned char* plocal_symbols
,
3402 Relocatable_relocs
*);
3404 // Scan the relocs for --emit-relocs.
3406 emit_relocs_scan(Symbol_table
* symtab
,
3408 Sized_relobj_file
<size
, big_endian
>* object
,
3409 unsigned int data_shndx
,
3410 unsigned int sh_type
,
3411 const unsigned char* prelocs
,
3413 Output_section
* output_section
,
3414 bool needs_special_offset_handling
,
3415 size_t local_symbol_count
,
3416 const unsigned char* plocal_syms
,
3417 Relocatable_relocs
* rr
);
3419 // Emit relocations for a section.
3421 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
3422 unsigned int sh_type
,
3423 const unsigned char* prelocs
,
3425 Output_section
* output_section
,
3426 typename
elfcpp::Elf_types
<size
>::Elf_Off
3427 offset_in_output_section
,
3428 unsigned char* view
,
3429 Mips_address view_address
,
3430 section_size_type view_size
,
3431 unsigned char* reloc_view
,
3432 section_size_type reloc_view_size
);
3434 // Perform target-specific processing in a relocatable link. This is
3435 // only used if we use the relocation strategy RELOC_SPECIAL.
3437 relocate_special_relocatable(const Relocate_info
<size
, big_endian
>* relinfo
,
3438 unsigned int sh_type
,
3439 const unsigned char* preloc_in
,
3441 Output_section
* output_section
,
3442 typename
elfcpp::Elf_types
<size
>::Elf_Off
3443 offset_in_output_section
,
3444 unsigned char* view
,
3445 Mips_address view_address
,
3446 section_size_type view_size
,
3447 unsigned char* preloc_out
);
3449 // Return whether SYM is defined by the ABI.
3451 do_is_defined_by_abi(const Symbol
* sym
) const
3453 return ((strcmp(sym
->name(), "__gnu_local_gp") == 0)
3454 || (strcmp(sym
->name(), "_gp_disp") == 0)
3455 || (strcmp(sym
->name(), "___tls_get_addr") == 0));
3458 // Return the number of entries in the GOT.
3460 got_entry_count() const
3462 if (!this->has_got_section())
3464 return this->got_size() / (size
/8);
3467 // Return the number of entries in the PLT.
3469 plt_entry_count() const
3471 if (this->plt_
== NULL
)
3473 return this->plt_
->entry_count();
3476 // Return the offset of the first non-reserved PLT entry.
3478 first_plt_entry_offset() const
3479 { return this->plt_
->first_plt_entry_offset(); }
3481 // Return the size of each PLT entry.
3483 plt_entry_size() const
3484 { return this->plt_
->plt_entry_size(); }
3486 // Get the GOT section, creating it if necessary.
3487 Mips_output_data_got
<size
, big_endian
>*
3488 got_section(Symbol_table
*, Layout
*);
3490 // Get the GOT section.
3491 Mips_output_data_got
<size
, big_endian
>*
3494 gold_assert(this->got_
!= NULL
);
3498 // Get the .MIPS.stubs section, creating it if necessary.
3499 Mips_output_data_mips_stubs
<size
, big_endian
>*
3500 mips_stubs_section(Layout
* layout
);
3502 // Get the .MIPS.stubs section.
3503 Mips_output_data_mips_stubs
<size
, big_endian
>*
3504 mips_stubs_section() const
3506 gold_assert(this->mips_stubs_
!= NULL
);
3507 return this->mips_stubs_
;
3510 // Get the LA25 stub section, creating it if necessary.
3511 Mips_output_data_la25_stub
<size
, big_endian
>*
3512 la25_stub_section(Layout
*);
3514 // Get the LA25 stub section.
3515 Mips_output_data_la25_stub
<size
, big_endian
>*
3518 gold_assert(this->la25_stub_
!= NULL
);
3519 return this->la25_stub_
;
3522 // Get gp value. It has the value of .got + 0x7FF0.
3526 if (this->gp_
!= NULL
)
3527 return this->gp_
->value();
3531 // Get gp value. It has the value of .got + 0x7FF0. Adjust it for
3532 // multi-GOT links so that OBJECT's GOT + 0x7FF0 is returned.
3534 adjusted_gp_value(const Mips_relobj
<size
, big_endian
>* object
)
3536 if (this->gp_
== NULL
)
3539 bool multi_got
= false;
3540 if (this->has_got_section())
3541 multi_got
= this->got_section()->multi_got();
3543 return this->gp_
->value();
3545 return this->gp_
->value() + this->got_section()->get_got_offset(object
);
3548 // Get the dynamic reloc section, creating it if necessary.
3550 rel_dyn_section(Layout
*);
3553 do_has_custom_set_dynsym_indexes() const
3556 // Don't emit input .reginfo/.MIPS.abiflags sections to
3557 // output .reginfo/.MIPS.abiflags.
3559 do_should_include_section(elfcpp::Elf_Word sh_type
) const
3561 return ((sh_type
!= elfcpp::SHT_MIPS_REGINFO
)
3562 && (sh_type
!= elfcpp::SHT_MIPS_ABIFLAGS
));
3565 // Set the dynamic symbol indexes. INDEX is the index of the first
3566 // global dynamic symbol. Pointers to the symbols are stored into the
3567 // vector SYMS. The names are added to DYNPOOL. This returns an
3568 // updated dynamic symbol index.
3570 do_set_dynsym_indexes(std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
3571 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
3572 Versions
* versions
, Symbol_table
* symtab
) const;
3574 // Remove .MIPS.stubs entry for a symbol.
3576 remove_lazy_stub_entry(Mips_symbol
<size
>* sym
)
3578 if (this->mips_stubs_
!= NULL
)
3579 this->mips_stubs_
->remove_entry(sym
);
3582 // The value to write into got[1] for SVR4 targets, to identify it is
3583 // a GNU object. The dynamic linker can then use got[1] to store the
3586 mips_elf_gnu_got1_mask()
3588 if (this->is_output_n64())
3589 return (uint64_t)1 << 63;
3594 // Whether the output has microMIPS code. This is valid only after
3595 // merge_obj_e_flags() is called.
3597 is_output_micromips() const
3599 gold_assert(this->are_processor_specific_flags_set());
3600 return elfcpp::is_micromips(this->processor_specific_flags());
3603 // Whether the output uses N32 ABI. This is valid only after
3604 // merge_obj_e_flags() is called.
3606 is_output_n32() const
3608 gold_assert(this->are_processor_specific_flags_set());
3609 return elfcpp::abi_n32(this->processor_specific_flags());
3612 // Whether the output uses R6 ISA. This is valid only after
3613 // merge_obj_e_flags() is called.
3615 is_output_r6() const
3617 gold_assert(this->are_processor_specific_flags_set());
3618 return elfcpp::r6_isa(this->processor_specific_flags());
3621 // Whether the output uses N64 ABI.
3623 is_output_n64() const
3624 { return size
== 64; }
3626 // Whether the output uses NEWABI. This is valid only after
3627 // merge_obj_e_flags() is called.
3629 is_output_newabi() const
3630 { return this->is_output_n32() || this->is_output_n64(); }
3632 // Whether we can only use 32-bit microMIPS instructions.
3634 use_32bit_micromips_instructions() const
3635 { return this->insn32_
; }
3637 // Return the r_sym field from a relocation.
3639 get_r_sym(const unsigned char* preloc
) const
3641 // Since REL and RELA relocs share the same structure through
3642 // the r_info field, we can just use REL here.
3643 Reltype
rel(preloc
);
3644 return Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
3649 // Return the value to use for a dynamic symbol which requires special
3650 // treatment. This is how we support equality comparisons of function
3651 // pointers across shared library boundaries, as described in the
3652 // processor specific ABI supplement.
3654 do_dynsym_value(const Symbol
* gsym
) const;
3656 // Make an ELF object.
3658 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
3659 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
);
3662 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
3663 const elfcpp::Ehdr
<size
, !big_endian
>&)
3664 { gold_unreachable(); }
3666 // Make an output section.
3668 do_make_output_section(const char* name
, elfcpp::Elf_Word type
,
3669 elfcpp::Elf_Xword flags
)
3671 if (type
== elfcpp::SHT_MIPS_OPTIONS
)
3672 return new Mips_output_section_options
<size
, big_endian
>(name
, type
,
3675 return new Output_section(name
, type
, flags
);
3678 // Adjust ELF file header.
3680 do_adjust_elf_header(unsigned char* view
, int len
);
3682 // Get the custom dynamic tag value.
3684 do_dynamic_tag_custom_value(elfcpp::DT
) const;
3686 // Adjust the value written to the dynamic symbol table.
3688 do_adjust_dyn_symbol(const Symbol
* sym
, unsigned char* view
) const
3690 elfcpp::Sym
<size
, big_endian
> isym(view
);
3691 elfcpp::Sym_write
<size
, big_endian
> osym(view
);
3692 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
3694 // Keep dynamic compressed symbols odd. This allows the dynamic linker
3695 // to treat compressed symbols like any other.
3696 Mips_address value
= isym
.get_st_value();
3697 if (mips_sym
->is_mips16() && value
!= 0)
3699 if (!mips_sym
->has_mips16_fn_stub())
3703 // If we have a MIPS16 function with a stub, the dynamic symbol
3704 // must refer to the stub, since only the stub uses the standard
3705 // calling conventions. Stub contains MIPS32 code, so don't add +1
3708 // There is a code which does this in the method
3709 // Target_mips::do_dynsym_value, but that code will only be
3710 // executed if the symbol is from dynobj.
3711 // TODO(sasa): GNU ld also changes the value in non-dynamic symbol
3714 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
3715 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
3716 value
= fn_stub
->output_address();
3717 osym
.put_st_size(fn_stub
->section_size());
3720 osym
.put_st_value(value
);
3721 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(),
3722 mips_sym
->nonvis() - (elfcpp::STO_MIPS16
>> 2)));
3724 else if ((mips_sym
->is_micromips()
3725 // Stubs are always microMIPS if there is any microMIPS code in
3727 || (this->is_output_micromips() && mips_sym
->has_lazy_stub()))
3730 osym
.put_st_value(value
| 1);
3731 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(),
3732 mips_sym
->nonvis() - (elfcpp::STO_MICROMIPS
>> 2)));
3737 // The class which scans relocations.
3745 get_reference_flags(unsigned int r_type
);
3748 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3749 Sized_relobj_file
<size
, big_endian
>* object
,
3750 unsigned int data_shndx
,
3751 Output_section
* output_section
,
3752 const Reltype
& reloc
, unsigned int r_type
,
3753 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3757 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3758 Sized_relobj_file
<size
, big_endian
>* object
,
3759 unsigned int data_shndx
,
3760 Output_section
* output_section
,
3761 const Relatype
& reloc
, unsigned int r_type
,
3762 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3766 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3767 Sized_relobj_file
<size
, big_endian
>* object
,
3768 unsigned int data_shndx
,
3769 Output_section
* output_section
,
3770 const Relatype
* rela
,
3772 unsigned int rel_type
,
3773 unsigned int r_type
,
3774 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3778 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3779 Sized_relobj_file
<size
, big_endian
>* object
,
3780 unsigned int data_shndx
,
3781 Output_section
* output_section
,
3782 const Reltype
& reloc
, unsigned int r_type
,
3786 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3787 Sized_relobj_file
<size
, big_endian
>* object
,
3788 unsigned int data_shndx
,
3789 Output_section
* output_section
,
3790 const Relatype
& reloc
, unsigned int r_type
,
3794 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3795 Sized_relobj_file
<size
, big_endian
>* object
,
3796 unsigned int data_shndx
,
3797 Output_section
* output_section
,
3798 const Relatype
* rela
,
3800 unsigned int rel_type
,
3801 unsigned int r_type
,
3805 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
*,
3807 Sized_relobj_file
<size
, big_endian
>*,
3812 const elfcpp::Sym
<size
, big_endian
>&)
3816 global_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3818 Sized_relobj_file
<size
, big_endian
>*,
3822 unsigned int, Symbol
*)
3826 local_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3828 Sized_relobj_file
<size
, big_endian
>*,
3833 const elfcpp::Sym
<size
, big_endian
>&)
3837 global_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3839 Sized_relobj_file
<size
, big_endian
>*,
3843 unsigned int, Symbol
*)
3847 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
3848 unsigned int r_type
);
3851 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
3852 unsigned int r_type
, Symbol
*);
3855 // The class which implements relocation.
3865 // Return whether a R_MIPS_32/R_MIPS_64 relocation needs to be applied.
3867 should_apply_static_reloc(const Mips_symbol
<size
>* gsym
,
3868 unsigned int r_type
,
3869 Output_section
* output_section
,
3870 Target_mips
* target
);
3872 // Do a relocation. Return false if the caller should not issue
3873 // any warnings about this relocation.
3875 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
3876 Target_mips
*, Output_section
*, size_t, const unsigned char*,
3877 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
3878 unsigned char*, Mips_address
, section_size_type
);
3881 // This POD class holds the dynamic relocations that should be emitted instead
3882 // of R_MIPS_32, R_MIPS_REL32 and R_MIPS_64 relocations. We will emit these
3883 // relocations if it turns out that the symbol does not have static
3888 Dyn_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
3889 Mips_relobj
<size
, big_endian
>* relobj
, unsigned int shndx
,
3890 Output_section
* output_section
, Mips_address r_offset
)
3891 : sym_(sym
), r_type_(r_type
), relobj_(relobj
),
3892 shndx_(shndx
), output_section_(output_section
),
3896 // Emit this reloc if appropriate. This is called after we have
3897 // scanned all the relocations, so we know whether the symbol has
3898 // static relocations.
3900 emit(Reloc_section
* rel_dyn
, Mips_output_data_got
<size
, big_endian
>* got
,
3901 Symbol_table
* symtab
)
3903 if (!this->sym_
->has_static_relocs())
3905 got
->record_global_got_symbol(this->sym_
, this->relobj_
,
3906 this->r_type_
, true, false);
3907 if (!symbol_references_local(this->sym_
,
3908 this->sym_
->should_add_dynsym_entry(symtab
)))
3909 rel_dyn
->add_global(this->sym_
, this->r_type_
,
3910 this->output_section_
, this->relobj_
,
3911 this->shndx_
, this->r_offset_
);
3913 rel_dyn
->add_symbolless_global_addend(this->sym_
, this->r_type_
,
3914 this->output_section_
, this->relobj_
,
3915 this->shndx_
, this->r_offset_
);
3920 Mips_symbol
<size
>* sym_
;
3921 unsigned int r_type_
;
3922 Mips_relobj
<size
, big_endian
>* relobj_
;
3923 unsigned int shndx_
;
3924 Output_section
* output_section_
;
3925 Mips_address r_offset_
;
3928 // Adjust TLS relocation type based on the options and whether this
3929 // is a local symbol.
3930 static tls::Tls_optimization
3931 optimize_tls_reloc(bool is_final
, int r_type
);
3933 // Return whether there is a GOT section.
3935 has_got_section() const
3936 { return this->got_
!= NULL
; }
3938 // Check whether the given ELF header flags describe a 32-bit binary.
3940 mips_32bit_flags(elfcpp::Elf_Word
);
3943 mach_mips3000
= 3000,
3944 mach_mips3900
= 3900,
3945 mach_mips4000
= 4000,
3946 mach_mips4010
= 4010,
3947 mach_mips4100
= 4100,
3948 mach_mips4111
= 4111,
3949 mach_mips4120
= 4120,
3950 mach_mips4300
= 4300,
3951 mach_mips4400
= 4400,
3952 mach_mips4600
= 4600,
3953 mach_mips4650
= 4650,
3954 mach_mips5000
= 5000,
3955 mach_mips5400
= 5400,
3956 mach_mips5500
= 5500,
3957 mach_mips5900
= 5900,
3958 mach_mips6000
= 6000,
3959 mach_mips7000
= 7000,
3960 mach_mips8000
= 8000,
3961 mach_mips9000
= 9000,
3962 mach_mips10000
= 10000,
3963 mach_mips12000
= 12000,
3964 mach_mips14000
= 14000,
3965 mach_mips16000
= 16000,
3968 mach_mips_loongson_2e
= 3001,
3969 mach_mips_loongson_2f
= 3002,
3970 mach_mips_loongson_3a
= 3003,
3971 mach_mips_sb1
= 12310201, // octal 'SB', 01
3972 mach_mips_octeon
= 6501,
3973 mach_mips_octeonp
= 6601,
3974 mach_mips_octeon2
= 6502,
3975 mach_mips_octeon3
= 6503,
3976 mach_mips_xlr
= 887682, // decimal 'XLR'
3977 mach_mipsisa32
= 32,
3978 mach_mipsisa32r2
= 33,
3979 mach_mipsisa32r3
= 34,
3980 mach_mipsisa32r5
= 36,
3981 mach_mipsisa32r6
= 37,
3982 mach_mipsisa64
= 64,
3983 mach_mipsisa64r2
= 65,
3984 mach_mipsisa64r3
= 66,
3985 mach_mipsisa64r5
= 68,
3986 mach_mipsisa64r6
= 69,
3987 mach_mips_micromips
= 96
3990 // Return the MACH for a MIPS e_flags value.
3992 elf_mips_mach(elfcpp::Elf_Word
);
3994 // Return the MACH for each .MIPS.abiflags ISA Extension.
3996 mips_isa_ext_mach(unsigned int);
3998 // Return the .MIPS.abiflags value representing each ISA Extension.
4000 mips_isa_ext(unsigned int);
4002 // Update the isa_level, isa_rev, isa_ext fields of abiflags.
4004 update_abiflags_isa(const std::string
&, elfcpp::Elf_Word
,
4005 Mips_abiflags
<big_endian
>*);
4007 // Infer the content of the ABI flags based on the elf header.
4009 infer_abiflags(Mips_relobj
<size
, big_endian
>*, Mips_abiflags
<big_endian
>*);
4011 // Create abiflags from elf header or from .MIPS.abiflags section.
4013 create_abiflags(Mips_relobj
<size
, big_endian
>*, Mips_abiflags
<big_endian
>*);
4015 // Return the meaning of fp_abi, or "unknown" if not known.
4021 select_fp_abi(const std::string
&, int, int);
4023 // Merge attributes from input object.
4025 merge_obj_attributes(const std::string
&, const Attributes_section_data
*);
4027 // Merge abiflags from input object.
4029 merge_obj_abiflags(const std::string
&, Mips_abiflags
<big_endian
>*);
4031 // Check whether machine EXTENSION is an extension of machine BASE.
4033 mips_mach_extends(unsigned int, unsigned int);
4035 // Merge file header flags from input object.
4037 merge_obj_e_flags(const std::string
&, elfcpp::Elf_Word
);
4039 // Encode ISA level and revision as a single value.
4041 level_rev(unsigned char isa_level
, unsigned char isa_rev
) const
4042 { return (isa_level
<< 3) | isa_rev
; }
4044 // True if we are linking for CPUs that are faster if JAL is converted to BAL.
4049 // True if we are linking for CPUs that are faster if JALR is converted to
4050 // BAL. This should be safe for all architectures. We enable this predicate
4056 // True if we are linking for CPUs that are faster if JR is converted to B.
4057 // This should be safe for all architectures. We enable this predicate for
4063 // Return the size of the GOT section.
4067 gold_assert(this->got_
!= NULL
);
4068 return this->got_
->data_size();
4071 // Create a PLT entry for a global symbol referenced by r_type relocation.
4073 make_plt_entry(Symbol_table
*, Layout
*, Mips_symbol
<size
>*,
4074 unsigned int r_type
);
4076 // Get the PLT section.
4077 Mips_output_data_plt
<size
, big_endian
>*
4080 gold_assert(this->plt_
!= NULL
);
4084 // Get the GOT PLT section.
4085 const Mips_output_data_plt
<size
, big_endian
>*
4086 got_plt_section() const
4088 gold_assert(this->got_plt_
!= NULL
);
4089 return this->got_plt_
;
4092 // Copy a relocation against a global symbol.
4094 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
4095 Sized_relobj_file
<size
, big_endian
>* object
,
4096 unsigned int shndx
, Output_section
* output_section
,
4097 Symbol
* sym
, unsigned int r_type
, Mips_address r_offset
)
4099 this->copy_relocs_
.copy_reloc(symtab
, layout
,
4100 symtab
->get_sized_symbol
<size
>(sym
),
4101 object
, shndx
, output_section
,
4102 r_type
, r_offset
, 0,
4103 this->rel_dyn_section(layout
));
4107 dynamic_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
4108 Mips_relobj
<size
, big_endian
>* relobj
,
4109 unsigned int shndx
, Output_section
* output_section
,
4110 Mips_address r_offset
)
4112 this->dyn_relocs_
.push_back(Dyn_reloc(sym
, r_type
, relobj
, shndx
,
4113 output_section
, r_offset
));
4116 // Calculate value of _gp symbol.
4118 set_gp(Layout
*, Symbol_table
*);
4121 elf_mips_abi_name(elfcpp::Elf_Word e_flags
);
4123 elf_mips_mach_name(elfcpp::Elf_Word e_flags
);
4125 // Adds entries that describe how machines relate to one another. The entries
4126 // are ordered topologically with MIPS I extensions listed last. First
4127 // element is extension, second element is base.
4129 add_machine_extensions()
4131 // MIPS64r2 extensions.
4132 this->add_extension(mach_mips_octeon3
, mach_mips_octeon2
);
4133 this->add_extension(mach_mips_octeon2
, mach_mips_octeonp
);
4134 this->add_extension(mach_mips_octeonp
, mach_mips_octeon
);
4135 this->add_extension(mach_mips_octeon
, mach_mipsisa64r2
);
4136 this->add_extension(mach_mips_loongson_3a
, mach_mipsisa64r2
);
4138 // MIPS64 extensions.
4139 this->add_extension(mach_mipsisa64r2
, mach_mipsisa64
);
4140 this->add_extension(mach_mips_sb1
, mach_mipsisa64
);
4141 this->add_extension(mach_mips_xlr
, mach_mipsisa64
);
4143 // MIPS V extensions.
4144 this->add_extension(mach_mipsisa64
, mach_mips5
);
4146 // R10000 extensions.
4147 this->add_extension(mach_mips12000
, mach_mips10000
);
4148 this->add_extension(mach_mips14000
, mach_mips10000
);
4149 this->add_extension(mach_mips16000
, mach_mips10000
);
4151 // R5000 extensions. Note: the vr5500 ISA is an extension of the core
4152 // vr5400 ISA, but doesn't include the multimedia stuff. It seems
4153 // better to allow vr5400 and vr5500 code to be merged anyway, since
4154 // many libraries will just use the core ISA. Perhaps we could add
4155 // some sort of ASE flag if this ever proves a problem.
4156 this->add_extension(mach_mips5500
, mach_mips5400
);
4157 this->add_extension(mach_mips5400
, mach_mips5000
);
4159 // MIPS IV extensions.
4160 this->add_extension(mach_mips5
, mach_mips8000
);
4161 this->add_extension(mach_mips10000
, mach_mips8000
);
4162 this->add_extension(mach_mips5000
, mach_mips8000
);
4163 this->add_extension(mach_mips7000
, mach_mips8000
);
4164 this->add_extension(mach_mips9000
, mach_mips8000
);
4166 // VR4100 extensions.
4167 this->add_extension(mach_mips4120
, mach_mips4100
);
4168 this->add_extension(mach_mips4111
, mach_mips4100
);
4170 // MIPS III extensions.
4171 this->add_extension(mach_mips_loongson_2e
, mach_mips4000
);
4172 this->add_extension(mach_mips_loongson_2f
, mach_mips4000
);
4173 this->add_extension(mach_mips8000
, mach_mips4000
);
4174 this->add_extension(mach_mips4650
, mach_mips4000
);
4175 this->add_extension(mach_mips4600
, mach_mips4000
);
4176 this->add_extension(mach_mips4400
, mach_mips4000
);
4177 this->add_extension(mach_mips4300
, mach_mips4000
);
4178 this->add_extension(mach_mips4100
, mach_mips4000
);
4179 this->add_extension(mach_mips4010
, mach_mips4000
);
4180 this->add_extension(mach_mips5900
, mach_mips4000
);
4182 // MIPS32 extensions.
4183 this->add_extension(mach_mipsisa32r2
, mach_mipsisa32
);
4185 // MIPS II extensions.
4186 this->add_extension(mach_mips4000
, mach_mips6000
);
4187 this->add_extension(mach_mipsisa32
, mach_mips6000
);
4189 // MIPS I extensions.
4190 this->add_extension(mach_mips6000
, mach_mips3000
);
4191 this->add_extension(mach_mips3900
, mach_mips3000
);
4194 // Add value to MIPS extenstions.
4196 add_extension(unsigned int base
, unsigned int extension
)
4198 std::pair
<unsigned int, unsigned int> ext(base
, extension
);
4199 this->mips_mach_extensions_
.push_back(ext
);
4202 // Return the number of entries in the .dynsym section.
4203 unsigned int get_dt_mips_symtabno() const
4205 return ((unsigned int)(this->layout_
->dynsym_section()->data_size()
4206 / elfcpp::Elf_sizes
<size
>::sym_size
));
4207 // TODO(sasa): Entry size is MIPS_ELF_SYM_SIZE.
4210 // Information about this specific target which we pass to the
4211 // general Target structure.
4212 static const Target::Target_info mips_info
;
4214 Mips_output_data_got
<size
, big_endian
>* got_
;
4215 // gp symbol. It has the value of .got + 0x7FF0.
4216 Sized_symbol
<size
>* gp_
;
4218 Mips_output_data_plt
<size
, big_endian
>* plt_
;
4219 // The GOT PLT section.
4220 Output_data_space
* got_plt_
;
4221 // The dynamic reloc section.
4222 Reloc_section
* rel_dyn_
;
4223 // The .rld_map section.
4224 Output_data_zero_fill
* rld_map_
;
4225 // Relocs saved to avoid a COPY reloc.
4226 Mips_copy_relocs
<elfcpp::SHT_REL
, size
, big_endian
> copy_relocs_
;
4228 // A list of dyn relocs to be saved.
4229 std::vector
<Dyn_reloc
> dyn_relocs_
;
4231 // The LA25 stub section.
4232 Mips_output_data_la25_stub
<size
, big_endian
>* la25_stub_
;
4233 // Architecture extensions.
4234 std::vector
<std::pair
<unsigned int, unsigned int> > mips_mach_extensions_
;
4236 Mips_output_data_mips_stubs
<size
, big_endian
>* mips_stubs_
;
4238 // Attributes section data in output.
4239 Attributes_section_data
* attributes_section_data_
;
4240 // .MIPS.abiflags section data in output.
4241 Mips_abiflags
<big_endian
>* abiflags_
;
4246 typename
std::list
<got16_addend
<size
, big_endian
> > got16_addends_
;
4248 // Whether there is an input .MIPS.abiflags section.
4249 bool has_abiflags_section_
;
4251 // Whether the entry symbol is mips16 or micromips.
4252 bool entry_symbol_is_compressed_
;
4254 // Whether we can use only 32-bit microMIPS instructions.
4255 // TODO(sasa): This should be a linker option.
4259 // Helper structure for R_MIPS*_HI16/LO16 and R_MIPS*_GOT16/LO16 relocations.
4260 // It records high part of the relocation pair.
4262 template<int size
, bool big_endian
>
4265 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
4267 reloc_high(unsigned char* _view
, const Mips_relobj
<size
, big_endian
>* _object
,
4268 const Symbol_value
<size
>* _psymval
, Mips_address _addend
,
4269 unsigned int _r_type
, unsigned int _r_sym
, bool _extract_addend
,
4270 Mips_address _address
= 0, bool _gp_disp
= false)
4271 : view(_view
), object(_object
), psymval(_psymval
), addend(_addend
),
4272 r_type(_r_type
), r_sym(_r_sym
), extract_addend(_extract_addend
),
4273 address(_address
), gp_disp(_gp_disp
)
4276 unsigned char* view
;
4277 const Mips_relobj
<size
, big_endian
>* object
;
4278 const Symbol_value
<size
>* psymval
;
4279 Mips_address addend
;
4280 unsigned int r_type
;
4282 bool extract_addend
;
4283 Mips_address address
;
4287 template<int size
, bool big_endian
>
4288 class Mips_relocate_functions
: public Relocate_functions
<size
, big_endian
>
4290 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
4291 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
4292 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype16
;
4293 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
4294 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype64
;
4299 STATUS_OKAY
, // No error during relocation.
4300 STATUS_OVERFLOW
, // Relocation overflow.
4301 STATUS_BAD_RELOC
, // Relocation cannot be applied.
4302 STATUS_PCREL_UNALIGNED
// Unaligned PC-relative relocation.
4306 typedef Relocate_functions
<size
, big_endian
> Base
;
4307 typedef Mips_relocate_functions
<size
, big_endian
> This
;
4309 static typename
std::list
<reloc_high
<size
, big_endian
> > hi16_relocs
;
4310 static typename
std::list
<reloc_high
<size
, big_endian
> > got16_relocs
;
4311 static typename
std::list
<reloc_high
<size
, big_endian
> > pchi16_relocs
;
4313 template<int valsize
>
4314 static inline typename
This::Status
4315 check_overflow(Valtype value
)
4318 return (Bits
<valsize
>::has_overflow32(value
)
4319 ? This::STATUS_OVERFLOW
4320 : This::STATUS_OKAY
);
4322 return (Bits
<valsize
>::has_overflow(value
)
4323 ? This::STATUS_OVERFLOW
4324 : This::STATUS_OKAY
);
4328 should_shuffle_micromips_reloc(unsigned int r_type
)
4330 return (micromips_reloc(r_type
)
4331 && r_type
!= elfcpp::R_MICROMIPS_PC7_S1
4332 && r_type
!= elfcpp::R_MICROMIPS_PC10_S1
);
4336 // R_MIPS16_26 is used for the mips16 jal and jalx instructions.
4337 // Most mips16 instructions are 16 bits, but these instructions
4340 // The format of these instructions is:
4342 // +--------------+--------------------------------+
4343 // | JALX | X| Imm 20:16 | Imm 25:21 |
4344 // +--------------+--------------------------------+
4345 // | Immediate 15:0 |
4346 // +-----------------------------------------------+
4348 // JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
4349 // Note that the immediate value in the first word is swapped.
4351 // When producing a relocatable object file, R_MIPS16_26 is
4352 // handled mostly like R_MIPS_26. In particular, the addend is
4353 // stored as a straight 26-bit value in a 32-bit instruction.
4354 // (gas makes life simpler for itself by never adjusting a
4355 // R_MIPS16_26 reloc to be against a section, so the addend is
4356 // always zero). However, the 32 bit instruction is stored as 2
4357 // 16-bit values, rather than a single 32-bit value. In a
4358 // big-endian file, the result is the same; in a little-endian
4359 // file, the two 16-bit halves of the 32 bit value are swapped.
4360 // This is so that a disassembler can recognize the jal
4363 // When doing a final link, R_MIPS16_26 is treated as a 32 bit
4364 // instruction stored as two 16-bit values. The addend A is the
4365 // contents of the targ26 field. The calculation is the same as
4366 // R_MIPS_26. When storing the calculated value, reorder the
4367 // immediate value as shown above, and don't forget to store the
4368 // value as two 16-bit values.
4370 // To put it in MIPS ABI terms, the relocation field is T-targ26-16,
4374 // +--------+----------------------+
4378 // +--------+----------------------+
4381 // +----------+------+-------------+
4383 // | sub1 | | sub2 |
4384 // |0 9|10 15|16 31|
4385 // +----------+--------------------+
4386 // where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
4387 // ((sub1 << 16) | sub2)).
4389 // When producing a relocatable object file, the calculation is
4390 // (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
4391 // When producing a fully linked file, the calculation is
4392 // let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
4393 // ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
4395 // The table below lists the other MIPS16 instruction relocations.
4396 // Each one is calculated in the same way as the non-MIPS16 relocation
4397 // given on the right, but using the extended MIPS16 layout of 16-bit
4398 // immediate fields:
4400 // R_MIPS16_GPREL R_MIPS_GPREL16
4401 // R_MIPS16_GOT16 R_MIPS_GOT16
4402 // R_MIPS16_CALL16 R_MIPS_CALL16
4403 // R_MIPS16_HI16 R_MIPS_HI16
4404 // R_MIPS16_LO16 R_MIPS_LO16
4406 // A typical instruction will have a format like this:
4408 // +--------------+--------------------------------+
4409 // | EXTEND | Imm 10:5 | Imm 15:11 |
4410 // +--------------+--------------------------------+
4411 // | Major | rx | ry | Imm 4:0 |
4412 // +--------------+--------------------------------+
4414 // EXTEND is the five bit value 11110. Major is the instruction
4417 // All we need to do here is shuffle the bits appropriately.
4418 // As above, the two 16-bit halves must be swapped on a
4419 // little-endian system.
4421 // Similar to MIPS16, the two 16-bit halves in microMIPS must be swapped
4422 // on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1
4423 // and R_MICROMIPS_PC10_S1 relocs that apply to 16-bit instructions.
4426 mips_reloc_unshuffle(unsigned char* view
, unsigned int r_type
,
4429 if (!mips16_reloc(r_type
)
4430 && !should_shuffle_micromips_reloc(r_type
))
4433 // Pick up the first and second halfwords of the instruction.
4434 Valtype16 first
= elfcpp::Swap
<16, big_endian
>::readval(view
);
4435 Valtype16 second
= elfcpp::Swap
<16, big_endian
>::readval(view
+ 2);
4438 if (micromips_reloc(r_type
)
4439 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
4440 val
= first
<< 16 | second
;
4441 else if (r_type
!= elfcpp::R_MIPS16_26
)
4442 val
= (((first
& 0xf800) << 16) | ((second
& 0xffe0) << 11)
4443 | ((first
& 0x1f) << 11) | (first
& 0x7e0) | (second
& 0x1f));
4445 val
= (((first
& 0xfc00) << 16) | ((first
& 0x3e0) << 11)
4446 | ((first
& 0x1f) << 21) | second
);
4448 elfcpp::Swap
<32, big_endian
>::writeval(view
, val
);
4452 mips_reloc_shuffle(unsigned char* view
, unsigned int r_type
, bool jal_shuffle
)
4454 if (!mips16_reloc(r_type
)
4455 && !should_shuffle_micromips_reloc(r_type
))
4458 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4459 Valtype16 first
, second
;
4461 if (micromips_reloc(r_type
)
4462 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
4464 second
= val
& 0xffff;
4467 else if (r_type
!= elfcpp::R_MIPS16_26
)
4469 second
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
4470 first
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
4474 second
= val
& 0xffff;
4475 first
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
4476 | ((val
>> 21) & 0x1f);
4479 elfcpp::Swap
<16, big_endian
>::writeval(view
+ 2, second
);
4480 elfcpp::Swap
<16, big_endian
>::writeval(view
, first
);
4483 // R_MIPS_16: S + sign-extend(A)
4484 static inline typename
This::Status
4485 rel16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4486 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4487 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
4489 Valtype16
* wv
= reinterpret_cast<Valtype16
*>(view
);
4490 Valtype16 val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
4492 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
)
4495 Valtype x
= psymval
->value(object
, addend
);
4496 val
= Bits
<16>::bit_select32(val
, x
, 0xffffU
);
4500 *calculated_value
= x
;
4501 return This::STATUS_OKAY
;
4504 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
4506 return check_overflow
<16>(x
);
4510 static inline typename
This::Status
4511 rel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4512 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4513 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
4515 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4516 Valtype addend
= (extract_addend
4517 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
4519 Valtype x
= psymval
->value(object
, addend
);
4522 *calculated_value
= x
;
4524 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4526 return This::STATUS_OKAY
;
4529 // R_MIPS_JALR, R_MICROMIPS_JALR
4530 static inline typename
This::Status
4531 reljalr(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4532 const Symbol_value
<size
>* psymval
, Mips_address address
,
4533 Mips_address addend_a
, bool extract_addend
, bool cross_mode_jump
,
4534 unsigned int r_type
, bool jalr_to_bal
, bool jr_to_b
,
4535 bool calculate_only
, Valtype
* calculated_value
)
4537 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4538 Valtype addend
= extract_addend
? 0 : addend_a
;
4539 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4541 // Try converting J(AL)R to B(AL), if the target is in range.
4542 if (r_type
== elfcpp::R_MIPS_JALR
4544 && ((jalr_to_bal
&& val
== 0x0320f809) // jalr t9
4545 || (jr_to_b
&& val
== 0x03200008))) // jr t9
4547 int offset
= psymval
->value(object
, addend
) - (address
+ 4);
4548 if (!Bits
<18>::has_overflow32(offset
))
4550 if (val
== 0x03200008) // jr t9
4551 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4553 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4558 *calculated_value
= val
;
4560 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4562 return This::STATUS_OKAY
;
4565 // R_MIPS_PC32: S + A - P
4566 static inline typename
This::Status
4567 relpc32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4568 const Symbol_value
<size
>* psymval
, Mips_address address
,
4569 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4570 Valtype
* calculated_value
)
4572 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4573 Valtype addend
= (extract_addend
4574 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
4576 Valtype x
= psymval
->value(object
, addend
) - address
;
4579 *calculated_value
= x
;
4581 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4583 return This::STATUS_OKAY
;
4586 // R_MIPS_26, R_MIPS16_26, R_MICROMIPS_26_S1
4587 static inline typename
This::Status
4588 rel26(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4589 const Symbol_value
<size
>* psymval
, Mips_address address
,
4590 bool local
, Mips_address addend_a
, bool extract_addend
,
4591 const Symbol
* gsym
, bool cross_mode_jump
, unsigned int r_type
,
4592 bool jal_to_bal
, bool calculate_only
, Valtype
* calculated_value
)
4594 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4595 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4600 if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4601 addend
= (val
& 0x03ffffff) << 1;
4603 addend
= (val
& 0x03ffffff) << 2;
4608 // Make sure the target of JALX is word-aligned. Bit 0 must be
4609 // the correct ISA mode selector and bit 1 must be 0.
4610 if (!calculate_only
&& cross_mode_jump
4611 && (psymval
->value(object
, 0) & 3) != (r_type
== elfcpp::R_MIPS_26
))
4613 gold_warning(_("JALX to a non-word-aligned address"));
4614 return This::STATUS_BAD_RELOC
;
4617 // Shift is 2, unusually, for microMIPS JALX.
4618 unsigned int shift
=
4619 (!cross_mode_jump
&& r_type
== elfcpp::R_MICROMIPS_26_S1
) ? 1 : 2;
4623 x
= addend
| ((address
+ 4) & (0xfc000000 << shift
));
4627 x
= Bits
<27>::sign_extend32(addend
);
4629 x
= Bits
<28>::sign_extend32(addend
);
4631 x
= psymval
->value(object
, x
) >> shift
;
4633 if (!calculate_only
&& !local
&& !gsym
->is_weak_undefined()
4634 && ((x
>> 26) != ((address
+ 4) >> (26 + shift
))))
4635 return This::STATUS_OVERFLOW
;
4637 val
= Bits
<32>::bit_select32(val
, x
, 0x03ffffff);
4639 // If required, turn JAL into JALX.
4640 if (cross_mode_jump
)
4643 Valtype32 opcode
= val
>> 26;
4644 Valtype32 jalx_opcode
;
4646 // Check to see if the opcode is already JAL or JALX.
4647 if (r_type
== elfcpp::R_MIPS16_26
)
4649 ok
= (opcode
== 0x6) || (opcode
== 0x7);
4652 else if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4654 ok
= (opcode
== 0x3d) || (opcode
== 0x3c);
4659 ok
= (opcode
== 0x3) || (opcode
== 0x1d);
4663 // If the opcode is not JAL or JALX, there's a problem. We cannot
4664 // convert J or JALS to JALX.
4665 if (!calculate_only
&& !ok
)
4667 gold_error(_("Unsupported jump between ISA modes; consider "
4668 "recompiling with interlinking enabled."));
4669 return This::STATUS_BAD_RELOC
;
4672 // Make this the JALX opcode.
4673 val
= (val
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
4676 // Try converting JAL to BAL, if the target is in range.
4677 if (!parameters
->options().relocatable()
4680 && r_type
== elfcpp::R_MIPS_26
4681 && (val
>> 26) == 0x3))) // jal addr
4683 Valtype32 dest
= (x
<< 2) | (((address
+ 4) >> 28) << 28);
4684 int offset
= dest
- (address
+ 4);
4685 if (!Bits
<18>::has_overflow32(offset
))
4687 if (val
== 0x03200008) // jr t9
4688 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4690 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4695 *calculated_value
= val
;
4697 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4699 return This::STATUS_OKAY
;
4703 static inline typename
This::Status
4704 relpc16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4705 const Symbol_value
<size
>* psymval
, Mips_address address
,
4706 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4707 Valtype
* calculated_value
)
4709 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4710 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4712 Valtype addend
= (extract_addend
4713 ? Bits
<18>::sign_extend32((val
& 0xffff) << 2)
4716 Valtype x
= psymval
->value(object
, addend
) - address
;
4717 val
= Bits
<16>::bit_select32(val
, x
>> 2, 0xffff);
4721 *calculated_value
= x
>> 2;
4722 return This::STATUS_OKAY
;
4725 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4727 if (psymval
->value(object
, addend
) & 3)
4728 return This::STATUS_PCREL_UNALIGNED
;
4730 return check_overflow
<18>(x
);
4734 static inline typename
This::Status
4735 relpc21(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4736 const Symbol_value
<size
>* psymval
, Mips_address address
,
4737 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4738 Valtype
* calculated_value
)
4740 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4741 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4743 Valtype addend
= (extract_addend
4744 ? Bits
<23>::sign_extend32((val
& 0x1fffff) << 2)
4747 Valtype x
= psymval
->value(object
, addend
) - address
;
4748 val
= Bits
<21>::bit_select32(val
, x
>> 2, 0x1fffff);
4752 *calculated_value
= x
>> 2;
4753 return This::STATUS_OKAY
;
4756 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4758 if (psymval
->value(object
, addend
) & 3)
4759 return This::STATUS_PCREL_UNALIGNED
;
4761 return check_overflow
<23>(x
);
4765 static inline typename
This::Status
4766 relpc26(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4767 const Symbol_value
<size
>* psymval
, Mips_address address
,
4768 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4769 Valtype
* calculated_value
)
4771 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4772 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4774 Valtype addend
= (extract_addend
4775 ? Bits
<28>::sign_extend32((val
& 0x3ffffff) << 2)
4778 Valtype x
= psymval
->value(object
, addend
) - address
;
4779 val
= Bits
<26>::bit_select32(val
, x
>> 2, 0x3ffffff);
4783 *calculated_value
= x
>> 2;
4784 return This::STATUS_OKAY
;
4787 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4789 if (psymval
->value(object
, addend
) & 3)
4790 return This::STATUS_PCREL_UNALIGNED
;
4792 return check_overflow
<28>(x
);
4796 static inline typename
This::Status
4797 relpc18(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4798 const Symbol_value
<size
>* psymval
, Mips_address address
,
4799 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4800 Valtype
* calculated_value
)
4802 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4803 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4805 Valtype addend
= (extract_addend
4806 ? Bits
<21>::sign_extend32((val
& 0x3ffff) << 3)
4809 Valtype x
= psymval
->value(object
, addend
) - ((address
| 7) ^ 7);
4810 val
= Bits
<18>::bit_select32(val
, x
>> 3, 0x3ffff);
4814 *calculated_value
= x
>> 3;
4815 return This::STATUS_OKAY
;
4818 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4820 if (psymval
->value(object
, addend
) & 7)
4821 return This::STATUS_PCREL_UNALIGNED
;
4823 return check_overflow
<21>(x
);
4827 static inline typename
This::Status
4828 relpc19(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4829 const Symbol_value
<size
>* psymval
, Mips_address address
,
4830 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4831 Valtype
* calculated_value
)
4833 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4834 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4836 Valtype addend
= (extract_addend
4837 ? Bits
<21>::sign_extend32((val
& 0x7ffff) << 2)
4840 Valtype x
= psymval
->value(object
, addend
) - address
;
4841 val
= Bits
<19>::bit_select32(val
, x
>> 2, 0x7ffff);
4845 *calculated_value
= x
>> 2;
4846 return This::STATUS_OKAY
;
4849 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4851 if (psymval
->value(object
, addend
) & 3)
4852 return This::STATUS_PCREL_UNALIGNED
;
4854 return check_overflow
<21>(x
);
4858 static inline typename
This::Status
4859 relpchi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4860 const Symbol_value
<size
>* psymval
, Mips_address addend
,
4861 Mips_address address
, unsigned int r_sym
, bool extract_addend
)
4863 // Record the relocation. It will be resolved when we find pclo16 part.
4864 pchi16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
4865 addend
, 0, r_sym
, extract_addend
, address
));
4866 return This::STATUS_OKAY
;
4870 static inline typename
This::Status
4871 do_relpchi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4872 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
4873 Mips_address address
, bool extract_addend
, Valtype32 addend_lo
,
4874 bool calculate_only
, Valtype
* calculated_value
)
4876 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4877 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4879 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
4882 Valtype value
= psymval
->value(object
, addend
) - address
;
4883 Valtype x
= ((value
+ 0x8000) >> 16) & 0xffff;
4884 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4887 *calculated_value
= x
;
4889 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4891 return This::STATUS_OKAY
;
4895 static inline typename
This::Status
4896 relpclo16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4897 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4898 bool extract_addend
, Mips_address address
, unsigned int r_sym
,
4899 unsigned int rel_type
, bool calculate_only
,
4900 Valtype
* calculated_value
)
4902 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4903 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4905 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
4908 if (rel_type
== elfcpp::SHT_REL
)
4910 // Resolve pending R_MIPS_PCHI16 relocations.
4911 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it
=
4912 pchi16_relocs
.begin();
4913 while (it
!= pchi16_relocs
.end())
4915 reloc_high
<size
, big_endian
> pchi16
= *it
;
4916 if (pchi16
.r_sym
== r_sym
)
4918 do_relpchi16(pchi16
.view
, pchi16
.object
, pchi16
.psymval
,
4919 pchi16
.addend
, pchi16
.address
,
4920 pchi16
.extract_addend
, addend
, calculate_only
,
4922 it
= pchi16_relocs
.erase(it
);
4929 // Resolve R_MIPS_PCLO16 relocation.
4930 Valtype x
= psymval
->value(object
, addend
) - address
;
4931 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4934 *calculated_value
= x
;
4936 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4938 return This::STATUS_OKAY
;
4941 // R_MICROMIPS_PC7_S1
4942 static inline typename
This::Status
4943 relmicromips_pc7_s1(unsigned char* view
,
4944 const Mips_relobj
<size
, big_endian
>* object
,
4945 const Symbol_value
<size
>* psymval
, Mips_address address
,
4946 Mips_address addend_a
, bool extract_addend
,
4947 bool calculate_only
, Valtype
* calculated_value
)
4949 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4950 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4952 Valtype addend
= extract_addend
? Bits
<8>::sign_extend32((val
& 0x7f) << 1)
4955 Valtype x
= psymval
->value(object
, addend
) - address
;
4956 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x7f);
4960 *calculated_value
= x
>> 1;
4961 return This::STATUS_OKAY
;
4964 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4966 return check_overflow
<8>(x
);
4969 // R_MICROMIPS_PC10_S1
4970 static inline typename
This::Status
4971 relmicromips_pc10_s1(unsigned char* view
,
4972 const Mips_relobj
<size
, big_endian
>* object
,
4973 const Symbol_value
<size
>* psymval
, Mips_address address
,
4974 Mips_address addend_a
, bool extract_addend
,
4975 bool calculate_only
, Valtype
* calculated_value
)
4977 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4978 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4980 Valtype addend
= (extract_addend
4981 ? Bits
<11>::sign_extend32((val
& 0x3ff) << 1)
4984 Valtype x
= psymval
->value(object
, addend
) - address
;
4985 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x3ff);
4989 *calculated_value
= x
>> 1;
4990 return This::STATUS_OKAY
;
4993 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4995 return check_overflow
<11>(x
);
4998 // R_MICROMIPS_PC16_S1
4999 static inline typename
This::Status
5000 relmicromips_pc16_s1(unsigned char* view
,
5001 const Mips_relobj
<size
, big_endian
>* object
,
5002 const Symbol_value
<size
>* psymval
, Mips_address address
,
5003 Mips_address addend_a
, bool extract_addend
,
5004 bool calculate_only
, Valtype
* calculated_value
)
5006 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5007 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5009 Valtype addend
= (extract_addend
5010 ? Bits
<17>::sign_extend32((val
& 0xffff) << 1)
5013 Valtype x
= psymval
->value(object
, addend
) - address
;
5014 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0xffff);
5018 *calculated_value
= x
>> 1;
5019 return This::STATUS_OKAY
;
5022 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5024 return check_overflow
<17>(x
);
5027 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
5028 static inline typename
This::Status
5029 relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5030 const Symbol_value
<size
>* psymval
, Mips_address addend
,
5031 Mips_address address
, bool gp_disp
, unsigned int r_type
,
5032 unsigned int r_sym
, bool extract_addend
)
5034 // Record the relocation. It will be resolved when we find lo16 part.
5035 hi16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
5036 addend
, r_type
, r_sym
, extract_addend
, address
,
5038 return This::STATUS_OKAY
;
5041 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
5042 static inline typename
This::Status
5043 do_relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5044 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
5045 Mips_address address
, bool is_gp_disp
, unsigned int r_type
,
5046 bool extract_addend
, Valtype32 addend_lo
,
5047 Target_mips
<size
, big_endian
>* target
, bool calculate_only
,
5048 Valtype
* calculated_value
)
5050 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5051 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5053 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
5058 value
= psymval
->value(object
, addend
);
5061 // For MIPS16 ABI code we generate this sequence
5062 // 0: li $v0,%hi(_gp_disp)
5063 // 4: addiupc $v1,%lo(_gp_disp)
5067 // So the offsets of hi and lo relocs are the same, but the
5068 // base $pc is that used by the ADDIUPC instruction at $t9 + 4.
5069 // ADDIUPC clears the low two bits of the instruction address,
5070 // so the base is ($t9 + 4) & ~3.
5072 if (r_type
== elfcpp::R_MIPS16_HI16
)
5073 gp_disp
= (target
->adjusted_gp_value(object
)
5074 - ((address
+ 4) & ~0x3));
5075 // The microMIPS .cpload sequence uses the same assembly
5076 // instructions as the traditional psABI version, but the
5077 // incoming $t9 has the low bit set.
5078 else if (r_type
== elfcpp::R_MICROMIPS_HI16
)
5079 gp_disp
= target
->adjusted_gp_value(object
) - address
- 1;
5081 gp_disp
= target
->adjusted_gp_value(object
) - address
;
5082 value
= gp_disp
+ addend
;
5084 Valtype x
= ((value
+ 0x8000) >> 16) & 0xffff;
5085 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5089 *calculated_value
= x
;
5090 return This::STATUS_OKAY
;
5093 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5095 return (is_gp_disp
? check_overflow
<16>(x
)
5096 : This::STATUS_OKAY
);
5099 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
5100 static inline typename
This::Status
5101 relgot16_local(unsigned char* view
,
5102 const Mips_relobj
<size
, big_endian
>* object
,
5103 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5104 bool extract_addend
, unsigned int r_type
, unsigned int r_sym
)
5106 // Record the relocation. It will be resolved when we find lo16 part.
5107 got16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
5108 addend_a
, r_type
, r_sym
, extract_addend
));
5109 return This::STATUS_OKAY
;
5112 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
5113 static inline typename
This::Status
5114 do_relgot16_local(unsigned char* view
,
5115 const Mips_relobj
<size
, big_endian
>* object
,
5116 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
5117 bool extract_addend
, Valtype32 addend_lo
,
5118 Target_mips
<size
, big_endian
>* target
, bool calculate_only
,
5119 Valtype
* calculated_value
)
5121 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5122 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5124 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
5127 // Find GOT page entry.
5128 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000) >> 16)
5131 unsigned int got_offset
=
5132 target
->got_section()->get_got_page_offset(value
, object
);
5134 // Resolve the relocation.
5135 Valtype x
= target
->got_section()->gp_offset(got_offset
, object
);
5136 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5140 *calculated_value
= x
;
5141 return This::STATUS_OKAY
;
5144 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5146 return check_overflow
<16>(x
);
5149 // R_MIPS_LO16, R_MIPS16_LO16, R_MICROMIPS_LO16, R_MICROMIPS_HI0_LO16
5150 static inline typename
This::Status
5151 rello16(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
5152 const Mips_relobj
<size
, big_endian
>* object
,
5153 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5154 bool extract_addend
, Mips_address address
, bool is_gp_disp
,
5155 unsigned int r_type
, unsigned int r_sym
, unsigned int rel_type
,
5156 bool calculate_only
, Valtype
* calculated_value
)
5158 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5159 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5161 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
5164 if (rel_type
== elfcpp::SHT_REL
)
5166 typename
This::Status reloc_status
= This::STATUS_OKAY
;
5167 // Resolve pending R_MIPS_HI16 relocations.
5168 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it
=
5169 hi16_relocs
.begin();
5170 while (it
!= hi16_relocs
.end())
5172 reloc_high
<size
, big_endian
> hi16
= *it
;
5173 if (hi16
.r_sym
== r_sym
5174 && is_matching_lo16_reloc(hi16
.r_type
, r_type
))
5176 mips_reloc_unshuffle(hi16
.view
, hi16
.r_type
, false);
5177 reloc_status
= do_relhi16(hi16
.view
, hi16
.object
, hi16
.psymval
,
5178 hi16
.addend
, hi16
.address
, hi16
.gp_disp
,
5179 hi16
.r_type
, hi16
.extract_addend
, addend
,
5180 target
, calculate_only
, calculated_value
);
5181 mips_reloc_shuffle(hi16
.view
, hi16
.r_type
, false);
5182 if (reloc_status
== This::STATUS_OVERFLOW
)
5183 return This::STATUS_OVERFLOW
;
5184 it
= hi16_relocs
.erase(it
);
5190 // Resolve pending local R_MIPS_GOT16 relocations.
5191 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it2
=
5192 got16_relocs
.begin();
5193 while (it2
!= got16_relocs
.end())
5195 reloc_high
<size
, big_endian
> got16
= *it2
;
5196 if (got16
.r_sym
== r_sym
5197 && is_matching_lo16_reloc(got16
.r_type
, r_type
))
5199 mips_reloc_unshuffle(got16
.view
, got16
.r_type
, false);
5201 reloc_status
= do_relgot16_local(got16
.view
, got16
.object
,
5202 got16
.psymval
, got16
.addend
,
5203 got16
.extract_addend
, addend
, target
,
5204 calculate_only
, calculated_value
);
5206 mips_reloc_shuffle(got16
.view
, got16
.r_type
, false);
5207 if (reloc_status
== This::STATUS_OVERFLOW
)
5208 return This::STATUS_OVERFLOW
;
5209 it2
= got16_relocs
.erase(it2
);
5216 // Resolve R_MIPS_LO16 relocation.
5219 x
= psymval
->value(object
, addend
);
5222 // See the comment for R_MIPS16_HI16 above for the reason
5223 // for this conditional.
5225 if (r_type
== elfcpp::R_MIPS16_LO16
)
5226 gp_disp
= target
->adjusted_gp_value(object
) - (address
& ~0x3);
5227 else if (r_type
== elfcpp::R_MICROMIPS_LO16
5228 || r_type
== elfcpp::R_MICROMIPS_HI0_LO16
)
5229 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 3;
5231 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 4;
5232 // The MIPS ABI requires checking the R_MIPS_LO16 relocation
5233 // for overflow. Relocations against _gp_disp are normally
5234 // generated from the .cpload pseudo-op. It generates code
5235 // that normally looks like this:
5237 // lui $gp,%hi(_gp_disp)
5238 // addiu $gp,$gp,%lo(_gp_disp)
5241 // Here $t9 holds the address of the function being called,
5242 // as required by the MIPS ELF ABI. The R_MIPS_LO16
5243 // relocation can easily overflow in this situation, but the
5244 // R_MIPS_HI16 relocation will handle the overflow.
5245 // Therefore, we consider this a bug in the MIPS ABI, and do
5246 // not check for overflow here.
5247 x
= gp_disp
+ addend
;
5249 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5252 *calculated_value
= x
;
5254 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5256 return This::STATUS_OKAY
;
5259 // R_MIPS_CALL16, R_MIPS16_CALL16, R_MICROMIPS_CALL16
5260 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
5261 // R_MIPS_TLS_GD, R_MIPS16_TLS_GD, R_MICROMIPS_TLS_GD
5262 // R_MIPS_TLS_GOTTPREL, R_MIPS16_TLS_GOTTPREL, R_MICROMIPS_TLS_GOTTPREL
5263 // R_MIPS_TLS_LDM, R_MIPS16_TLS_LDM, R_MICROMIPS_TLS_LDM
5264 // R_MIPS_GOT_DISP, R_MICROMIPS_GOT_DISP
5265 static inline typename
This::Status
5266 relgot(unsigned char* view
, int gp_offset
, bool calculate_only
,
5267 Valtype
* calculated_value
)
5269 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5270 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5271 Valtype x
= gp_offset
;
5272 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5276 *calculated_value
= x
;
5277 return This::STATUS_OKAY
;
5280 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5282 return check_overflow
<16>(x
);
5286 static inline typename
This::Status
5287 releh(unsigned char* view
, int gp_offset
, bool calculate_only
,
5288 Valtype
* calculated_value
)
5290 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5291 Valtype x
= gp_offset
;
5295 *calculated_value
= x
;
5296 return This::STATUS_OKAY
;
5299 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5301 return check_overflow
<32>(x
);
5304 // R_MIPS_GOT_PAGE, R_MICROMIPS_GOT_PAGE
5305 static inline typename
This::Status
5306 relgotpage(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
5307 const Mips_relobj
<size
, big_endian
>* object
,
5308 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5309 bool extract_addend
, bool calculate_only
,
5310 Valtype
* calculated_value
)
5312 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5313 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
5314 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5316 // Find a GOT page entry that points to within 32KB of symbol + addend.
5317 Mips_address value
= (psymval
->value(object
, addend
) + 0x8000) & ~0xffff;
5318 unsigned int got_offset
=
5319 target
->got_section()->get_got_page_offset(value
, object
);
5321 Valtype x
= target
->got_section()->gp_offset(got_offset
, object
);
5322 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5326 *calculated_value
= x
;
5327 return This::STATUS_OKAY
;
5330 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5332 return check_overflow
<16>(x
);
5335 // R_MIPS_GOT_OFST, R_MICROMIPS_GOT_OFST
5336 static inline typename
This::Status
5337 relgotofst(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
5338 const Mips_relobj
<size
, big_endian
>* object
,
5339 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5340 bool extract_addend
, bool local
, bool calculate_only
,
5341 Valtype
* calculated_value
)
5343 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5344 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
5345 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5347 // For a local symbol, find a GOT page entry that points to within 32KB of
5348 // symbol + addend. Relocation value is the offset of the GOT page entry's
5349 // value from symbol + addend.
5350 // For a global symbol, relocation value is addend.
5354 // Find GOT page entry.
5355 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000)
5357 target
->got_section()->get_got_page_offset(value
, object
);
5359 x
= psymval
->value(object
, addend
) - value
;
5363 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5367 *calculated_value
= x
;
5368 return This::STATUS_OKAY
;
5371 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5373 return check_overflow
<16>(x
);
5376 // R_MIPS_GOT_HI16, R_MIPS_CALL_HI16,
5377 // R_MICROMIPS_GOT_HI16, R_MICROMIPS_CALL_HI16
5378 static inline typename
This::Status
5379 relgot_hi16(unsigned char* view
, int gp_offset
, bool calculate_only
,
5380 Valtype
* calculated_value
)
5382 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5383 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5384 Valtype x
= gp_offset
;
5385 x
= ((x
+ 0x8000) >> 16) & 0xffff;
5386 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5389 *calculated_value
= x
;
5391 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5393 return This::STATUS_OKAY
;
5396 // R_MIPS_GOT_LO16, R_MIPS_CALL_LO16,
5397 // R_MICROMIPS_GOT_LO16, R_MICROMIPS_CALL_LO16
5398 static inline typename
This::Status
5399 relgot_lo16(unsigned char* view
, int gp_offset
, bool calculate_only
,
5400 Valtype
* calculated_value
)
5402 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5403 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5404 Valtype x
= gp_offset
;
5405 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5408 *calculated_value
= x
;
5410 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5412 return This::STATUS_OKAY
;
5415 // R_MIPS_GPREL16, R_MIPS16_GPREL, R_MIPS_LITERAL, R_MICROMIPS_LITERAL
5416 // R_MICROMIPS_GPREL7_S2, R_MICROMIPS_GPREL16
5417 static inline typename
This::Status
5418 relgprel(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5419 const Symbol_value
<size
>* psymval
, Mips_address gp
,
5420 Mips_address addend_a
, bool extract_addend
, bool local
,
5421 unsigned int r_type
, bool calculate_only
,
5422 Valtype
* calculated_value
)
5424 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5425 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5430 if (r_type
== elfcpp::R_MICROMIPS_GPREL7_S2
)
5431 addend
= (val
& 0x7f) << 2;
5433 addend
= val
& 0xffff;
5434 // Only sign-extend the addend if it was extracted from the
5435 // instruction. If the addend was separate, leave it alone,
5436 // otherwise we may lose significant bits.
5437 addend
= Bits
<16>::sign_extend32(addend
);
5442 Valtype x
= psymval
->value(object
, addend
) - gp
;
5444 // If the symbol was local, any earlier relocatable links will
5445 // have adjusted its addend with the gp offset, so compensate
5446 // for that now. Don't do it for symbols forced local in this
5447 // link, though, since they won't have had the gp offset applied
5450 x
+= object
->gp_value();
5452 if (r_type
== elfcpp::R_MICROMIPS_GPREL7_S2
)
5453 val
= Bits
<32>::bit_select32(val
, x
, 0x7f);
5455 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5459 *calculated_value
= x
;
5460 return This::STATUS_OKAY
;
5463 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5465 if (check_overflow
<16>(x
) == This::STATUS_OVERFLOW
)
5467 gold_error(_("small-data section exceeds 64KB; lower small-data size "
5468 "limit (see option -G)"));
5469 return This::STATUS_OVERFLOW
;
5471 return This::STATUS_OKAY
;
5475 static inline typename
This::Status
5476 relgprel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5477 const Symbol_value
<size
>* psymval
, Mips_address gp
,
5478 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5479 Valtype
* calculated_value
)
5481 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5482 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5483 Valtype addend
= extract_addend
? val
: addend_a
;
5485 // R_MIPS_GPREL32 relocations are defined for local symbols only.
5486 Valtype x
= psymval
->value(object
, addend
) + object
->gp_value() - gp
;
5489 *calculated_value
= x
;
5491 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5493 return This::STATUS_OKAY
;
5496 // R_MIPS_TLS_TPREL_HI16, R_MIPS16_TLS_TPREL_HI16, R_MICROMIPS_TLS_TPREL_HI16
5497 // R_MIPS_TLS_DTPREL_HI16, R_MIPS16_TLS_DTPREL_HI16,
5498 // R_MICROMIPS_TLS_DTPREL_HI16
5499 static inline typename
This::Status
5500 tlsrelhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5501 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5502 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5503 Valtype
* calculated_value
)
5505 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5506 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5507 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5509 // tls symbol values are relative to tls_segment()->vaddr()
5510 Valtype x
= ((psymval
->value(object
, addend
) - tp_offset
) + 0x8000) >> 16;
5511 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5514 *calculated_value
= x
;
5516 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5518 return This::STATUS_OKAY
;
5521 // R_MIPS_TLS_TPREL_LO16, R_MIPS16_TLS_TPREL_LO16, R_MICROMIPS_TLS_TPREL_LO16,
5522 // R_MIPS_TLS_DTPREL_LO16, R_MIPS16_TLS_DTPREL_LO16,
5523 // R_MICROMIPS_TLS_DTPREL_LO16,
5524 static inline typename
This::Status
5525 tlsrello16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5526 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5527 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5528 Valtype
* calculated_value
)
5530 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5531 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5532 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5534 // tls symbol values are relative to tls_segment()->vaddr()
5535 Valtype x
= psymval
->value(object
, addend
) - tp_offset
;
5536 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5539 *calculated_value
= x
;
5541 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5543 return This::STATUS_OKAY
;
5546 // R_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL64,
5547 // R_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL64
5548 static inline typename
This::Status
5549 tlsrel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5550 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5551 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5552 Valtype
* calculated_value
)
5554 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5555 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5556 Valtype addend
= extract_addend
? val
: addend_a
;
5558 // tls symbol values are relative to tls_segment()->vaddr()
5559 Valtype x
= psymval
->value(object
, addend
) - tp_offset
;
5562 *calculated_value
= x
;
5564 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5566 return This::STATUS_OKAY
;
5569 // R_MIPS_SUB, R_MICROMIPS_SUB
5570 static inline typename
This::Status
5571 relsub(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5572 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5573 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
5575 Valtype64
* wv
= reinterpret_cast<Valtype64
*>(view
);
5576 Valtype64 addend
= (extract_addend
5577 ? elfcpp::Swap
<64, big_endian
>::readval(wv
)
5580 Valtype64 x
= psymval
->value(object
, -addend
);
5582 *calculated_value
= x
;
5584 elfcpp::Swap
<64, big_endian
>::writeval(wv
, x
);
5586 return This::STATUS_OKAY
;
5590 static inline typename
This::Status
5591 rel64(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5592 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5593 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
,
5594 bool apply_addend_only
)
5596 Valtype64
* wv
= reinterpret_cast<Valtype64
*>(view
);
5597 Valtype64 addend
= (extract_addend
5598 ? elfcpp::Swap
<64, big_endian
>::readval(wv
)
5601 Valtype64 x
= psymval
->value(object
, addend
);
5603 *calculated_value
= x
;
5606 if (apply_addend_only
)
5608 elfcpp::Swap
<64, big_endian
>::writeval(wv
, x
);
5611 return This::STATUS_OKAY
;
5614 // R_MIPS_HIGHER, R_MICROMIPS_HIGHER
5615 static inline typename
This::Status
5616 relhigher(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5617 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5618 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
5620 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5621 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5622 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
5625 Valtype x
= psymval
->value(object
, addend
);
5626 x
= ((x
+ (uint64_t) 0x80008000) >> 32) & 0xffff;
5627 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5630 *calculated_value
= x
;
5632 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5634 return This::STATUS_OKAY
;
5637 // R_MIPS_HIGHEST, R_MICROMIPS_HIGHEST
5638 static inline typename
This::Status
5639 relhighest(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5640 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5641 bool extract_addend
, bool calculate_only
,
5642 Valtype
* calculated_value
)
5644 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5645 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5646 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
5649 Valtype x
= psymval
->value(object
, addend
);
5650 x
= ((x
+ (uint64_t) 0x800080008000) >> 48) & 0xffff;
5651 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5654 *calculated_value
= x
;
5656 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5658 return This::STATUS_OKAY
;
5662 template<int size
, bool big_endian
>
5663 typename
std::list
<reloc_high
<size
, big_endian
> >
5664 Mips_relocate_functions
<size
, big_endian
>::hi16_relocs
;
5666 template<int size
, bool big_endian
>
5667 typename
std::list
<reloc_high
<size
, big_endian
> >
5668 Mips_relocate_functions
<size
, big_endian
>::got16_relocs
;
5670 template<int size
, bool big_endian
>
5671 typename
std::list
<reloc_high
<size
, big_endian
> >
5672 Mips_relocate_functions
<size
, big_endian
>::pchi16_relocs
;
5674 // Mips_got_info methods.
5676 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
5677 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
5679 template<int size
, bool big_endian
>
5681 Mips_got_info
<size
, big_endian
>::record_local_got_symbol(
5682 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
,
5683 Mips_address addend
, unsigned int r_type
, unsigned int shndx
,
5684 bool is_section_symbol
)
5686 Mips_got_entry
<size
, big_endian
>* entry
=
5687 new Mips_got_entry
<size
, big_endian
>(object
, symndx
, addend
,
5688 mips_elf_reloc_tls_type(r_type
),
5689 shndx
, is_section_symbol
);
5690 this->record_got_entry(entry
, object
);
5693 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
5694 // in OBJECT. FOR_CALL is true if the caller is only interested in
5695 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
5698 template<int size
, bool big_endian
>
5700 Mips_got_info
<size
, big_endian
>::record_global_got_symbol(
5701 Mips_symbol
<size
>* mips_sym
, Mips_relobj
<size
, big_endian
>* object
,
5702 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
5705 mips_sym
->set_got_not_only_for_calls();
5707 // A global symbol in the GOT must also be in the dynamic symbol table.
5708 if (!mips_sym
->needs_dynsym_entry() && !mips_sym
->is_forced_local())
5710 switch (mips_sym
->visibility())
5712 case elfcpp::STV_INTERNAL
:
5713 case elfcpp::STV_HIDDEN
:
5714 mips_sym
->set_is_forced_local();
5717 mips_sym
->set_needs_dynsym_entry();
5722 unsigned char tls_type
= mips_elf_reloc_tls_type(r_type
);
5723 if (tls_type
== GOT_TLS_NONE
)
5724 this->global_got_symbols_
.insert(mips_sym
);
5728 if (mips_sym
->global_got_area() == GGA_NONE
)
5729 mips_sym
->set_global_got_area(GGA_RELOC_ONLY
);
5733 Mips_got_entry
<size
, big_endian
>* entry
=
5734 new Mips_got_entry
<size
, big_endian
>(mips_sym
, tls_type
);
5736 this->record_got_entry(entry
, object
);
5739 // Add ENTRY to master GOT and to OBJECT's GOT.
5741 template<int size
, bool big_endian
>
5743 Mips_got_info
<size
, big_endian
>::record_got_entry(
5744 Mips_got_entry
<size
, big_endian
>* entry
,
5745 Mips_relobj
<size
, big_endian
>* object
)
5747 this->got_entries_
.insert(entry
);
5749 // Create the GOT entry for the OBJECT's GOT.
5750 Mips_got_info
<size
, big_endian
>* g
= object
->get_or_create_got_info();
5751 Mips_got_entry
<size
, big_endian
>* entry2
=
5752 new Mips_got_entry
<size
, big_endian
>(*entry
);
5754 g
->got_entries_
.insert(entry2
);
5757 // Record that OBJECT has a page relocation against symbol SYMNDX and
5758 // that ADDEND is the addend for that relocation.
5759 // This function creates an upper bound on the number of GOT slots
5760 // required; no attempt is made to combine references to non-overridable
5761 // global symbols across multiple input files.
5763 template<int size
, bool big_endian
>
5765 Mips_got_info
<size
, big_endian
>::record_got_page_entry(
5766 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
, int addend
)
5768 struct Got_page_range
**range_ptr
, *range
;
5769 int old_pages
, new_pages
;
5771 // Find the Got_page_entry for this symbol.
5772 Got_page_entry
* entry
= new Got_page_entry(object
, symndx
);
5773 typename
Got_page_entry_set::iterator it
=
5774 this->got_page_entries_
.find(entry
);
5775 if (it
!= this->got_page_entries_
.end())
5778 this->got_page_entries_
.insert(entry
);
5780 // Add the same entry to the OBJECT's GOT.
5781 Got_page_entry
* entry2
= NULL
;
5782 Mips_got_info
<size
, big_endian
>* g2
= object
->get_or_create_got_info();
5783 if (g2
->got_page_entries_
.find(entry
) == g2
->got_page_entries_
.end())
5785 entry2
= new Got_page_entry(*entry
);
5786 g2
->got_page_entries_
.insert(entry2
);
5789 // Skip over ranges whose maximum extent cannot share a page entry
5791 range_ptr
= &entry
->ranges
;
5792 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
5793 range_ptr
= &(*range_ptr
)->next
;
5795 // If we scanned to the end of the list, or found a range whose
5796 // minimum extent cannot share a page entry with ADDEND, create
5797 // a new singleton range.
5799 if (!range
|| addend
< range
->min_addend
- 0xffff)
5801 range
= new Got_page_range();
5802 range
->next
= *range_ptr
;
5803 range
->min_addend
= addend
;
5804 range
->max_addend
= addend
;
5809 ++entry2
->num_pages
;
5810 ++this->page_gotno_
;
5815 // Remember how many pages the old range contributed.
5816 old_pages
= range
->get_max_pages();
5818 // Update the ranges.
5819 if (addend
< range
->min_addend
)
5820 range
->min_addend
= addend
;
5821 else if (addend
> range
->max_addend
)
5823 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
5825 old_pages
+= range
->next
->get_max_pages();
5826 range
->max_addend
= range
->next
->max_addend
;
5827 range
->next
= range
->next
->next
;
5830 range
->max_addend
= addend
;
5833 // Record any change in the total estimate.
5834 new_pages
= range
->get_max_pages();
5835 if (old_pages
!= new_pages
)
5837 entry
->num_pages
+= new_pages
- old_pages
;
5839 entry2
->num_pages
+= new_pages
- old_pages
;
5840 this->page_gotno_
+= new_pages
- old_pages
;
5841 g2
->page_gotno_
+= new_pages
- old_pages
;
5845 // Create all entries that should be in the local part of the GOT.
5847 template<int size
, bool big_endian
>
5849 Mips_got_info
<size
, big_endian
>::add_local_entries(
5850 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5852 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5853 // First two GOT entries are reserved. The first entry will be filled at
5854 // runtime. The second entry will be used by some runtime loaders.
5855 got
->add_constant(0);
5856 got
->add_constant(target
->mips_elf_gnu_got1_mask());
5858 for (typename
Got_entry_set::iterator
5859 p
= this->got_entries_
.begin();
5860 p
!= this->got_entries_
.end();
5863 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5864 if (entry
->is_for_local_symbol() && !entry
->is_tls_entry())
5866 got
->add_local(entry
->object(), entry
->symndx(),
5867 GOT_TYPE_STANDARD
, entry
->addend());
5868 unsigned int got_offset
= entry
->object()->local_got_offset(
5869 entry
->symndx(), GOT_TYPE_STANDARD
, entry
->addend());
5870 if (got
->multi_got() && this->index_
> 0
5871 && parameters
->options().output_is_position_independent())
5873 if (!entry
->is_section_symbol())
5874 target
->rel_dyn_section(layout
)->add_local(entry
->object(),
5875 entry
->symndx(), elfcpp::R_MIPS_REL32
, got
, got_offset
);
5877 target
->rel_dyn_section(layout
)->add_symbolless_local_addend(
5878 entry
->object(), entry
->symndx(), elfcpp::R_MIPS_REL32
,
5884 this->add_page_entries(target
, layout
);
5886 // Add global entries that should be in the local area.
5887 for (typename
Got_entry_set::iterator
5888 p
= this->got_entries_
.begin();
5889 p
!= this->got_entries_
.end();
5892 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5893 if (!entry
->is_for_global_symbol())
5896 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5897 if (mips_sym
->global_got_area() == GGA_NONE
&& !entry
->is_tls_entry())
5899 unsigned int got_type
;
5900 if (!got
->multi_got())
5901 got_type
= GOT_TYPE_STANDARD
;
5903 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
5904 if (got
->add_global(mips_sym
, got_type
))
5906 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5907 if (got
->multi_got() && this->index_
> 0
5908 && parameters
->options().output_is_position_independent())
5909 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
5910 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
5911 mips_sym
->got_offset(got_type
));
5917 // Create GOT page entries.
5919 template<int size
, bool big_endian
>
5921 Mips_got_info
<size
, big_endian
>::add_page_entries(
5922 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5924 if (this->page_gotno_
== 0)
5927 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5928 this->got_page_offset_start_
= got
->add_constant(0);
5929 if (got
->multi_got() && this->index_
> 0
5930 && parameters
->options().output_is_position_independent())
5931 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
5932 this->got_page_offset_start_
);
5933 int num_entries
= this->page_gotno_
;
5934 unsigned int prev_offset
= this->got_page_offset_start_
;
5935 while (--num_entries
> 0)
5937 unsigned int next_offset
= got
->add_constant(0);
5938 if (got
->multi_got() && this->index_
> 0
5939 && parameters
->options().output_is_position_independent())
5940 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
5942 gold_assert(next_offset
== prev_offset
+ size
/8);
5943 prev_offset
= next_offset
;
5945 this->got_page_offset_next_
= this->got_page_offset_start_
;
5948 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
5950 template<int size
, bool big_endian
>
5952 Mips_got_info
<size
, big_endian
>::add_global_entries(
5953 Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
5954 unsigned int non_reloc_only_global_gotno
)
5956 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5957 // Add GGA_NORMAL entries.
5958 unsigned int count
= 0;
5959 for (typename
Got_entry_set::iterator
5960 p
= this->got_entries_
.begin();
5961 p
!= this->got_entries_
.end();
5964 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5965 if (!entry
->is_for_global_symbol())
5968 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5969 if (mips_sym
->global_got_area() != GGA_NORMAL
)
5972 unsigned int got_type
;
5973 if (!got
->multi_got())
5974 got_type
= GOT_TYPE_STANDARD
;
5976 // In multi-GOT links, global symbol can be in both primary and
5977 // secondary GOT(s). By creating custom GOT type
5978 // (GOT_TYPE_STANDARD_MULTIGOT + got_index) we ensure that symbol
5979 // is added to secondary GOT(s).
5980 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
5981 if (!got
->add_global(mips_sym
, got_type
))
5984 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5985 if (got
->multi_got() && this->index_
== 0)
5987 if (got
->multi_got() && this->index_
> 0)
5989 if (parameters
->options().output_is_position_independent()
5990 || (!parameters
->doing_static_link()
5991 && mips_sym
->is_from_dynobj() && !mips_sym
->is_undefined()))
5993 target
->rel_dyn_section(layout
)->add_global(
5994 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
5995 mips_sym
->got_offset(got_type
));
5996 got
->add_secondary_got_reloc(mips_sym
->got_offset(got_type
),
5997 elfcpp::R_MIPS_REL32
, mips_sym
);
6002 if (!got
->multi_got() || this->index_
== 0)
6004 if (got
->multi_got())
6006 // We need to allocate space in the primary GOT for GGA_NORMAL entries
6007 // of secondary GOTs, to ensure that GOT offsets of GGA_RELOC_ONLY
6008 // entries correspond to dynamic symbol indexes.
6009 while (count
< non_reloc_only_global_gotno
)
6011 got
->add_constant(0);
6016 // Add GGA_RELOC_ONLY entries.
6017 got
->add_reloc_only_entries();
6021 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
6023 template<int size
, bool big_endian
>
6025 Mips_got_info
<size
, big_endian
>::add_reloc_only_entries(
6026 Mips_output_data_got
<size
, big_endian
>* got
)
6028 for (typename
Global_got_entry_set::iterator
6029 p
= this->global_got_symbols_
.begin();
6030 p
!= this->global_got_symbols_
.end();
6033 Mips_symbol
<size
>* mips_sym
= *p
;
6034 if (mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
6036 unsigned int got_type
;
6037 if (!got
->multi_got())
6038 got_type
= GOT_TYPE_STANDARD
;
6040 got_type
= GOT_TYPE_STANDARD_MULTIGOT
;
6041 if (got
->add_global(mips_sym
, got_type
))
6042 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
6047 // Create TLS GOT entries.
6049 template<int size
, bool big_endian
>
6051 Mips_got_info
<size
, big_endian
>::add_tls_entries(
6052 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
6054 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
6055 // Add local tls entries.
6056 for (typename
Got_entry_set::iterator
6057 p
= this->got_entries_
.begin();
6058 p
!= this->got_entries_
.end();
6061 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
6062 if (!entry
->is_tls_entry() || !entry
->is_for_local_symbol())
6065 if (entry
->tls_type() == GOT_TLS_GD
)
6067 unsigned int got_type
= GOT_TYPE_TLS_PAIR
;
6068 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
6069 : elfcpp::R_MIPS_TLS_DTPMOD64
);
6070 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
6071 : elfcpp::R_MIPS_TLS_DTPREL64
);
6073 if (!parameters
->doing_static_link())
6075 got
->add_local_pair_with_rel(entry
->object(), entry
->symndx(),
6076 entry
->shndx(), got_type
,
6077 target
->rel_dyn_section(layout
),
6078 r_type1
, entry
->addend());
6079 unsigned int got_offset
=
6080 entry
->object()->local_got_offset(entry
->symndx(), got_type
,
6082 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
6083 entry
->object(), entry
->symndx());
6087 // We are doing a static link. Mark it as belong to module 1,
6089 unsigned int got_offset
= got
->add_constant(1);
6090 entry
->object()->set_local_got_offset(entry
->symndx(), got_type
,
6093 got
->add_constant(0);
6094 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
6095 entry
->object(), entry
->symndx());
6098 else if (entry
->tls_type() == GOT_TLS_IE
)
6100 unsigned int got_type
= GOT_TYPE_TLS_OFFSET
;
6101 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
6102 : elfcpp::R_MIPS_TLS_TPREL64
);
6103 if (!parameters
->doing_static_link())
6104 got
->add_local_with_rel(entry
->object(), entry
->symndx(), got_type
,
6105 target
->rel_dyn_section(layout
), r_type
,
6109 got
->add_local(entry
->object(), entry
->symndx(), got_type
,
6111 unsigned int got_offset
=
6112 entry
->object()->local_got_offset(entry
->symndx(), got_type
,
6114 got
->add_static_reloc(got_offset
, r_type
, entry
->object(),
6118 else if (entry
->tls_type() == GOT_TLS_LDM
)
6120 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
6121 : elfcpp::R_MIPS_TLS_DTPMOD64
);
6122 unsigned int got_offset
;
6123 if (!parameters
->doing_static_link())
6125 got_offset
= got
->add_constant(0);
6126 target
->rel_dyn_section(layout
)->add_local(
6127 entry
->object(), 0, r_type
, got
, got_offset
);
6130 // We are doing a static link. Just mark it as belong to module 1,
6132 got_offset
= got
->add_constant(1);
6134 got
->add_constant(0);
6135 got
->set_tls_ldm_offset(got_offset
, entry
->object());
6141 // Add global tls entries.
6142 for (typename
Got_entry_set::iterator
6143 p
= this->got_entries_
.begin();
6144 p
!= this->got_entries_
.end();
6147 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
6148 if (!entry
->is_tls_entry() || !entry
->is_for_global_symbol())
6151 Mips_symbol
<size
>* mips_sym
= entry
->sym();
6152 if (entry
->tls_type() == GOT_TLS_GD
)
6154 unsigned int got_type
;
6155 if (!got
->multi_got())
6156 got_type
= GOT_TYPE_TLS_PAIR
;
6158 got_type
= GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
6159 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
6160 : elfcpp::R_MIPS_TLS_DTPMOD64
);
6161 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
6162 : elfcpp::R_MIPS_TLS_DTPREL64
);
6163 if (!parameters
->doing_static_link())
6164 got
->add_global_pair_with_rel(mips_sym
, got_type
,
6165 target
->rel_dyn_section(layout
), r_type1
, r_type2
);
6168 // Add a GOT pair for for R_MIPS_TLS_GD. The creates a pair of
6169 // GOT entries. The first one is initialized to be 1, which is the
6170 // module index for the main executable and the second one 0. A
6171 // reloc of the type R_MIPS_TLS_DTPREL32/64 will be created for
6172 // the second GOT entry and will be applied by gold.
6173 unsigned int got_offset
= got
->add_constant(1);
6174 mips_sym
->set_got_offset(got_type
, got_offset
);
6175 got
->add_constant(0);
6176 got
->add_static_reloc(got_offset
+ size
/8, r_type2
, mips_sym
);
6179 else if (entry
->tls_type() == GOT_TLS_IE
)
6181 unsigned int got_type
;
6182 if (!got
->multi_got())
6183 got_type
= GOT_TYPE_TLS_OFFSET
;
6185 got_type
= GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
6186 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
6187 : elfcpp::R_MIPS_TLS_TPREL64
);
6188 if (!parameters
->doing_static_link())
6189 got
->add_global_with_rel(mips_sym
, got_type
,
6190 target
->rel_dyn_section(layout
), r_type
);
6193 got
->add_global(mips_sym
, got_type
);
6194 unsigned int got_offset
= mips_sym
->got_offset(got_type
);
6195 got
->add_static_reloc(got_offset
, r_type
, mips_sym
);
6203 // Decide whether the symbol needs an entry in the global part of the primary
6204 // GOT, setting global_got_area accordingly. Count the number of global
6205 // symbols that are in the primary GOT only because they have dynamic
6206 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
6208 template<int size
, bool big_endian
>
6210 Mips_got_info
<size
, big_endian
>::count_got_symbols(Symbol_table
* symtab
)
6212 for (typename
Global_got_entry_set::iterator
6213 p
= this->global_got_symbols_
.begin();
6214 p
!= this->global_got_symbols_
.end();
6217 Mips_symbol
<size
>* sym
= *p
;
6218 // Make a final decision about whether the symbol belongs in the
6219 // local or global GOT. Symbols that bind locally can (and in the
6220 // case of forced-local symbols, must) live in the local GOT.
6221 // Those that are aren't in the dynamic symbol table must also
6222 // live in the local GOT.
6224 if (!sym
->should_add_dynsym_entry(symtab
)
6225 || (sym
->got_only_for_calls()
6226 ? symbol_calls_local(sym
, sym
->should_add_dynsym_entry(symtab
))
6227 : symbol_references_local(sym
,
6228 sym
->should_add_dynsym_entry(symtab
))))
6229 // The symbol belongs in the local GOT. We no longer need this
6230 // entry if it was only used for relocations; those relocations
6231 // will be against the null or section symbol instead.
6232 sym
->set_global_got_area(GGA_NONE
);
6233 else if (sym
->global_got_area() == GGA_RELOC_ONLY
)
6235 ++this->reloc_only_gotno_
;
6236 ++this->global_gotno_
;
6241 // Return the offset of GOT page entry for VALUE. Initialize the entry with
6242 // VALUE if it is not initialized.
6244 template<int size
, bool big_endian
>
6246 Mips_got_info
<size
, big_endian
>::get_got_page_offset(Mips_address value
,
6247 Mips_output_data_got
<size
, big_endian
>* got
)
6249 typename
Got_page_offsets::iterator it
= this->got_page_offsets_
.find(value
);
6250 if (it
!= this->got_page_offsets_
.end())
6253 gold_assert(this->got_page_offset_next_
< this->got_page_offset_start_
6254 + (size
/8) * this->page_gotno_
);
6256 unsigned int got_offset
= this->got_page_offset_next_
;
6257 this->got_page_offsets_
[value
] = got_offset
;
6258 this->got_page_offset_next_
+= size
/8;
6259 got
->update_got_entry(got_offset
, value
);
6263 // Remove lazy-binding stubs for global symbols in this GOT.
6265 template<int size
, bool big_endian
>
6267 Mips_got_info
<size
, big_endian
>::remove_lazy_stubs(
6268 Target_mips
<size
, big_endian
>* target
)
6270 for (typename
Got_entry_set::iterator
6271 p
= this->got_entries_
.begin();
6272 p
!= this->got_entries_
.end();
6275 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
6276 if (entry
->is_for_global_symbol())
6277 target
->remove_lazy_stub_entry(entry
->sym());
6281 // Count the number of GOT entries required.
6283 template<int size
, bool big_endian
>
6285 Mips_got_info
<size
, big_endian
>::count_got_entries()
6287 for (typename
Got_entry_set::iterator
6288 p
= this->got_entries_
.begin();
6289 p
!= this->got_entries_
.end();
6292 this->count_got_entry(*p
);
6296 // Count the number of GOT entries required by ENTRY. Accumulate the result.
6298 template<int size
, bool big_endian
>
6300 Mips_got_info
<size
, big_endian
>::count_got_entry(
6301 Mips_got_entry
<size
, big_endian
>* entry
)
6303 if (entry
->is_tls_entry())
6304 this->tls_gotno_
+= mips_tls_got_entries(entry
->tls_type());
6305 else if (entry
->is_for_local_symbol()
6306 || entry
->sym()->global_got_area() == GGA_NONE
)
6307 ++this->local_gotno_
;
6309 ++this->global_gotno_
;
6312 // Add FROM's GOT entries.
6314 template<int size
, bool big_endian
>
6316 Mips_got_info
<size
, big_endian
>::add_got_entries(
6317 Mips_got_info
<size
, big_endian
>* from
)
6319 for (typename
Got_entry_set::iterator
6320 p
= from
->got_entries_
.begin();
6321 p
!= from
->got_entries_
.end();
6324 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
6325 if (this->got_entries_
.find(entry
) == this->got_entries_
.end())
6327 Mips_got_entry
<size
, big_endian
>* entry2
=
6328 new Mips_got_entry
<size
, big_endian
>(*entry
);
6329 this->got_entries_
.insert(entry2
);
6330 this->count_got_entry(entry
);
6335 // Add FROM's GOT page entries.
6337 template<int size
, bool big_endian
>
6339 Mips_got_info
<size
, big_endian
>::add_got_page_entries(
6340 Mips_got_info
<size
, big_endian
>* from
)
6342 for (typename
Got_page_entry_set::iterator
6343 p
= from
->got_page_entries_
.begin();
6344 p
!= from
->got_page_entries_
.end();
6347 Got_page_entry
* entry
= *p
;
6348 if (this->got_page_entries_
.find(entry
) == this->got_page_entries_
.end())
6350 Got_page_entry
* entry2
= new Got_page_entry(*entry
);
6351 this->got_page_entries_
.insert(entry2
);
6352 this->page_gotno_
+= entry
->num_pages
;
6357 // Mips_output_data_got methods.
6359 // Lay out the GOT. Add local, global and TLS entries. If GOT is
6360 // larger than 64K, create multi-GOT.
6362 template<int size
, bool big_endian
>
6364 Mips_output_data_got
<size
, big_endian
>::lay_out_got(Layout
* layout
,
6365 Symbol_table
* symtab
, const Input_objects
* input_objects
)
6367 // Decide which symbols need to go in the global part of the GOT and
6368 // count the number of reloc-only GOT symbols.
6369 this->master_got_info_
->count_got_symbols(symtab
);
6371 // Count the number of GOT entries.
6372 this->master_got_info_
->count_got_entries();
6374 unsigned int got_size
= this->master_got_info_
->got_size();
6375 if (got_size
> Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
)
6376 this->lay_out_multi_got(layout
, input_objects
);
6379 // Record that all objects use single GOT.
6380 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
6381 p
!= input_objects
->relobj_end();
6384 Mips_relobj
<size
, big_endian
>* object
=
6385 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
6386 if (object
->get_got_info() != NULL
)
6387 object
->set_got_info(this->master_got_info_
);
6390 this->master_got_info_
->add_local_entries(this->target_
, layout
);
6391 this->master_got_info_
->add_global_entries(this->target_
, layout
,
6393 this->master_got_info_
->add_tls_entries(this->target_
, layout
);
6397 // Create multi-GOT. For every GOT, add local, global and TLS entries.
6399 template<int size
, bool big_endian
>
6401 Mips_output_data_got
<size
, big_endian
>::lay_out_multi_got(Layout
* layout
,
6402 const Input_objects
* input_objects
)
6404 // Try to merge the GOTs of input objects together, as long as they
6405 // don't seem to exceed the maximum GOT size, choosing one of them
6406 // to be the primary GOT.
6407 this->merge_gots(input_objects
);
6409 // Every symbol that is referenced in a dynamic relocation must be
6410 // present in the primary GOT.
6411 this->primary_got_
->set_global_gotno(this->master_got_info_
->global_gotno());
6415 unsigned int offset
= 0;
6416 Mips_got_info
<size
, big_endian
>* g
= this->primary_got_
;
6420 g
->set_offset(offset
);
6422 g
->add_local_entries(this->target_
, layout
);
6424 g
->add_global_entries(this->target_
, layout
,
6425 (this->master_got_info_
->global_gotno()
6426 - this->master_got_info_
->reloc_only_gotno()));
6428 g
->add_global_entries(this->target_
, layout
, /*not used*/-1U);
6429 g
->add_tls_entries(this->target_
, layout
);
6431 // Forbid global symbols in every non-primary GOT from having
6432 // lazy-binding stubs.
6434 g
->remove_lazy_stubs(this->target_
);
6437 offset
+= g
->got_size();
6443 // Attempt to merge GOTs of different input objects. Try to use as much as
6444 // possible of the primary GOT, since it doesn't require explicit dynamic
6445 // relocations, but don't use objects that would reference global symbols
6446 // out of the addressable range. Failing the primary GOT, attempt to merge
6447 // with the current GOT, or finish the current GOT and then make make the new
6450 template<int size
, bool big_endian
>
6452 Mips_output_data_got
<size
, big_endian
>::merge_gots(
6453 const Input_objects
* input_objects
)
6455 gold_assert(this->primary_got_
== NULL
);
6456 Mips_got_info
<size
, big_endian
>* current
= NULL
;
6458 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
6459 p
!= input_objects
->relobj_end();
6462 Mips_relobj
<size
, big_endian
>* object
=
6463 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
6465 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
6469 g
->count_got_entries();
6471 // Work out the number of page, local and TLS entries.
6472 unsigned int estimate
= this->master_got_info_
->page_gotno();
6473 if (estimate
> g
->page_gotno())
6474 estimate
= g
->page_gotno();
6475 estimate
+= g
->local_gotno() + g
->tls_gotno();
6477 // We place TLS GOT entries after both locals and globals. The globals
6478 // for the primary GOT may overflow the normal GOT size limit, so be
6479 // sure not to merge a GOT which requires TLS with the primary GOT in that
6480 // case. This doesn't affect non-primary GOTs.
6481 estimate
+= (g
->tls_gotno() > 0 ? this->master_got_info_
->global_gotno()
6482 : g
->global_gotno());
6484 unsigned int max_count
=
6485 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
6486 if (estimate
<= max_count
)
6488 // If we don't have a primary GOT, use it as
6489 // a starting point for the primary GOT.
6490 if (!this->primary_got_
)
6492 this->primary_got_
= g
;
6496 // Try merging with the primary GOT.
6497 if (this->merge_got_with(g
, object
, this->primary_got_
))
6501 // If we can merge with the last-created GOT, do it.
6502 if (current
&& this->merge_got_with(g
, object
, current
))
6505 // Well, we couldn't merge, so create a new GOT. Don't check if it
6506 // fits; if it turns out that it doesn't, we'll get relocation
6507 // overflows anyway.
6508 g
->set_next(current
);
6512 // If we do not find any suitable primary GOT, create an empty one.
6513 if (this->primary_got_
== NULL
)
6514 this->primary_got_
= new Mips_got_info
<size
, big_endian
>();
6516 // Link primary GOT with secondary GOTs.
6517 this->primary_got_
->set_next(current
);
6520 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
6521 // this would lead to overflow, true if they were merged successfully.
6523 template<int size
, bool big_endian
>
6525 Mips_output_data_got
<size
, big_endian
>::merge_got_with(
6526 Mips_got_info
<size
, big_endian
>* from
,
6527 Mips_relobj
<size
, big_endian
>* object
,
6528 Mips_got_info
<size
, big_endian
>* to
)
6530 // Work out how many page entries we would need for the combined GOT.
6531 unsigned int estimate
= this->master_got_info_
->page_gotno();
6532 if (estimate
>= from
->page_gotno() + to
->page_gotno())
6533 estimate
= from
->page_gotno() + to
->page_gotno();
6535 // Conservatively estimate how many local and TLS entries would be needed.
6536 estimate
+= from
->local_gotno() + to
->local_gotno();
6537 estimate
+= from
->tls_gotno() + to
->tls_gotno();
6539 // If we're merging with the primary got, any TLS relocations will
6540 // come after the full set of global entries. Otherwise estimate those
6541 // conservatively as well.
6542 if (to
== this->primary_got_
&& (from
->tls_gotno() + to
->tls_gotno()) > 0)
6543 estimate
+= this->master_got_info_
->global_gotno();
6545 estimate
+= from
->global_gotno() + to
->global_gotno();
6547 // Bail out if the combined GOT might be too big.
6548 unsigned int max_count
=
6549 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
6550 if (estimate
> max_count
)
6553 // Transfer the object's GOT information from FROM to TO.
6554 to
->add_got_entries(from
);
6555 to
->add_got_page_entries(from
);
6557 // Record that OBJECT should use output GOT TO.
6558 object
->set_got_info(to
);
6563 // Write out the GOT.
6565 template<int size
, bool big_endian
>
6567 Mips_output_data_got
<size
, big_endian
>::do_write(Output_file
* of
)
6569 typedef Unordered_set
<Mips_symbol
<size
>*, Mips_symbol_hash
<size
> >
6570 Mips_stubs_entry_set
;
6572 // Call parent to write out GOT.
6573 Output_data_got
<size
, big_endian
>::do_write(of
);
6575 const off_t offset
= this->offset();
6576 const section_size_type oview_size
=
6577 convert_to_section_size_type(this->data_size());
6578 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6580 // Needed for fixing values of .got section.
6581 this->got_view_
= oview
;
6583 // Write lazy stub addresses.
6584 for (typename
Mips_stubs_entry_set::iterator
6585 p
= this->master_got_info_
->global_got_symbols().begin();
6586 p
!= this->master_got_info_
->global_got_symbols().end();
6589 Mips_symbol
<size
>* mips_sym
= *p
;
6590 if (mips_sym
->has_lazy_stub())
6592 Valtype
* wv
= reinterpret_cast<Valtype
*>(
6593 oview
+ this->get_primary_got_offset(mips_sym
));
6595 this->target_
->mips_stubs_section()->stub_address(mips_sym
);
6596 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
6600 // Add +1 to GGA_NONE nonzero MIPS16 and microMIPS entries.
6601 for (typename
Mips_stubs_entry_set::iterator
6602 p
= this->master_got_info_
->global_got_symbols().begin();
6603 p
!= this->master_got_info_
->global_got_symbols().end();
6606 Mips_symbol
<size
>* mips_sym
= *p
;
6607 if (!this->multi_got()
6608 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
6609 && mips_sym
->global_got_area() == GGA_NONE
6610 && mips_sym
->has_got_offset(GOT_TYPE_STANDARD
))
6612 Valtype
* wv
= reinterpret_cast<Valtype
*>(
6613 oview
+ mips_sym
->got_offset(GOT_TYPE_STANDARD
));
6614 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv
);
6618 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
6623 if (!this->secondary_got_relocs_
.empty())
6625 // Fixup for the secondary GOT R_MIPS_REL32 relocs. For global
6626 // secondary GOT entries with non-zero initial value copy the value
6627 // to the corresponding primary GOT entry, and set the secondary GOT
6629 // TODO(sasa): This is workaround. It needs to be investigated further.
6631 for (size_t i
= 0; i
< this->secondary_got_relocs_
.size(); ++i
)
6633 Static_reloc
& reloc(this->secondary_got_relocs_
[i
]);
6634 if (reloc
.symbol_is_global())
6636 Mips_symbol
<size
>* gsym
= reloc
.symbol();
6637 gold_assert(gsym
!= NULL
);
6639 unsigned got_offset
= reloc
.got_offset();
6640 gold_assert(got_offset
< oview_size
);
6642 // Find primary GOT entry.
6643 Valtype
* wv_prim
= reinterpret_cast<Valtype
*>(
6644 oview
+ this->get_primary_got_offset(gsym
));
6646 // Find secondary GOT entry.
6647 Valtype
* wv_sec
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6649 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv_sec
);
6652 elfcpp::Swap
<size
, big_endian
>::writeval(wv_prim
, value
);
6653 elfcpp::Swap
<size
, big_endian
>::writeval(wv_sec
, 0);
6654 gsym
->set_applied_secondary_got_fixup();
6659 of
->write_output_view(offset
, oview_size
, oview
);
6662 // We are done if there is no fix up.
6663 if (this->static_relocs_
.empty())
6666 Output_segment
* tls_segment
= this->layout_
->tls_segment();
6667 gold_assert(tls_segment
!= NULL
);
6669 for (size_t i
= 0; i
< this->static_relocs_
.size(); ++i
)
6671 Static_reloc
& reloc(this->static_relocs_
[i
]);
6674 if (!reloc
.symbol_is_global())
6676 Sized_relobj_file
<size
, big_endian
>* object
= reloc
.relobj();
6677 const Symbol_value
<size
>* psymval
=
6678 object
->local_symbol(reloc
.index());
6680 // We are doing static linking. Issue an error and skip this
6681 // relocation if the symbol is undefined or in a discarded_section.
6683 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
6684 if ((shndx
== elfcpp::SHN_UNDEF
)
6686 && shndx
!= elfcpp::SHN_UNDEF
6687 && !object
->is_section_included(shndx
)
6688 && !this->symbol_table_
->is_section_folded(object
, shndx
)))
6690 gold_error(_("undefined or discarded local symbol %u from "
6691 " object %s in GOT"),
6692 reloc
.index(), reloc
.relobj()->name().c_str());
6696 value
= psymval
->value(object
, 0);
6700 const Mips_symbol
<size
>* gsym
= reloc
.symbol();
6701 gold_assert(gsym
!= NULL
);
6703 // We are doing static linking. Issue an error and skip this
6704 // relocation if the symbol is undefined or in a discarded_section
6705 // unless it is a weakly_undefined symbol.
6706 if ((gsym
->is_defined_in_discarded_section() || gsym
->is_undefined())
6707 && !gsym
->is_weak_undefined())
6709 gold_error(_("undefined or discarded symbol %s in GOT"),
6714 if (!gsym
->is_weak_undefined())
6715 value
= gsym
->value();
6720 unsigned got_offset
= reloc
.got_offset();
6721 gold_assert(got_offset
< oview_size
);
6723 Valtype
* wv
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6726 switch (reloc
.r_type())
6728 case elfcpp::R_MIPS_TLS_DTPMOD32
:
6729 case elfcpp::R_MIPS_TLS_DTPMOD64
:
6732 case elfcpp::R_MIPS_TLS_DTPREL32
:
6733 case elfcpp::R_MIPS_TLS_DTPREL64
:
6734 x
= value
- elfcpp::DTP_OFFSET
;
6736 case elfcpp::R_MIPS_TLS_TPREL32
:
6737 case elfcpp::R_MIPS_TLS_TPREL64
:
6738 x
= value
- elfcpp::TP_OFFSET
;
6745 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, x
);
6748 of
->write_output_view(offset
, oview_size
, oview
);
6751 // Mips_relobj methods.
6753 // Count the local symbols. The Mips backend needs to know if a symbol
6754 // is a MIPS16 or microMIPS function or not. For global symbols, it is easy
6755 // because the Symbol object keeps the ELF symbol type and st_other field.
6756 // For local symbol it is harder because we cannot access this information.
6757 // So we override the do_count_local_symbol in parent and scan local symbols to
6758 // mark MIPS16 and microMIPS functions. This is not the most efficient way but
6759 // I do not want to slow down other ports by calling a per symbol target hook
6760 // inside Sized_relobj_file<size, big_endian>::do_count_local_symbols.
6762 template<int size
, bool big_endian
>
6764 Mips_relobj
<size
, big_endian
>::do_count_local_symbols(
6765 Stringpool_template
<char>* pool
,
6766 Stringpool_template
<char>* dynpool
)
6768 // Ask parent to count the local symbols.
6769 Sized_relobj_file
<size
, big_endian
>::do_count_local_symbols(pool
, dynpool
);
6770 const unsigned int loccount
= this->local_symbol_count();
6774 // Initialize the mips16 and micromips function bit-vector.
6775 this->local_symbol_is_mips16_
.resize(loccount
, false);
6776 this->local_symbol_is_micromips_
.resize(loccount
, false);
6778 // Read the symbol table section header.
6779 const unsigned int symtab_shndx
= this->symtab_shndx();
6780 elfcpp::Shdr
<size
, big_endian
>
6781 symtabshdr(this, this->elf_file()->section_header(symtab_shndx
));
6782 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
6784 // Read the local symbols.
6785 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
6786 gold_assert(loccount
== symtabshdr
.get_sh_info());
6787 off_t locsize
= loccount
* sym_size
;
6788 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
6789 locsize
, true, true);
6791 // Loop over the local symbols and mark any MIPS16 or microMIPS local symbols.
6793 // Skip the first dummy symbol.
6795 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
6797 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
6798 unsigned char st_other
= sym
.get_st_other();
6799 this->local_symbol_is_mips16_
[i
] = elfcpp::elf_st_is_mips16(st_other
);
6800 this->local_symbol_is_micromips_
[i
] =
6801 elfcpp::elf_st_is_micromips(st_other
);
6805 // Read the symbol information.
6807 template<int size
, bool big_endian
>
6809 Mips_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
6811 // Call parent class to read symbol information.
6812 this->base_read_symbols(sd
);
6814 // Read processor-specific flags in ELF file header.
6815 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
6816 elfcpp::Elf_sizes
<size
>::ehdr_size
,
6818 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
6819 this->processor_specific_flags_
= ehdr
.get_e_flags();
6821 // Get the section names.
6822 const unsigned char* pnamesu
= sd
->section_names
->data();
6823 const char* pnames
= reinterpret_cast<const char*>(pnamesu
);
6825 // Initialize the mips16 stub section bit-vectors.
6826 this->section_is_mips16_fn_stub_
.resize(this->shnum(), false);
6827 this->section_is_mips16_call_stub_
.resize(this->shnum(), false);
6828 this->section_is_mips16_call_fp_stub_
.resize(this->shnum(), false);
6830 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
6831 const unsigned char* pshdrs
= sd
->section_headers
->data();
6832 const unsigned char* ps
= pshdrs
+ shdr_size
;
6833 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
6835 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
6837 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_REGINFO
)
6839 this->has_reginfo_section_
= true;
6840 // Read the gp value that was used to create this object. We need the
6841 // gp value while processing relocs. The .reginfo section is not used
6842 // in the 64-bit MIPS ELF ABI.
6843 section_offset_type section_offset
= shdr
.get_sh_offset();
6844 section_size_type section_size
=
6845 convert_to_section_size_type(shdr
.get_sh_size());
6846 const unsigned char* view
=
6847 this->get_view(section_offset
, section_size
, true, false);
6849 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 20);
6851 // Read the rest of .reginfo.
6852 this->gprmask_
= elfcpp::Swap
<size
, big_endian
>::readval(view
);
6853 this->cprmask1_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 4);
6854 this->cprmask2_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 8);
6855 this->cprmask3_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 12);
6856 this->cprmask4_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 16);
6859 if (shdr
.get_sh_type() == elfcpp::SHT_GNU_ATTRIBUTES
)
6861 gold_assert(this->attributes_section_data_
== NULL
);
6862 section_offset_type section_offset
= shdr
.get_sh_offset();
6863 section_size_type section_size
=
6864 convert_to_section_size_type(shdr
.get_sh_size());
6865 const unsigned char* view
=
6866 this->get_view(section_offset
, section_size
, true, false);
6867 this->attributes_section_data_
=
6868 new Attributes_section_data(view
, section_size
);
6871 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_ABIFLAGS
)
6873 gold_assert(this->abiflags_
== NULL
);
6874 section_offset_type section_offset
= shdr
.get_sh_offset();
6875 section_size_type section_size
=
6876 convert_to_section_size_type(shdr
.get_sh_size());
6877 const unsigned char* view
=
6878 this->get_view(section_offset
, section_size
, true, false);
6879 this->abiflags_
= new Mips_abiflags
<big_endian
>();
6881 this->abiflags_
->version
=
6882 elfcpp::Swap
<16, big_endian
>::readval(view
);
6883 if (this->abiflags_
->version
!= 0)
6885 gold_error(_("%s: .MIPS.abiflags section has "
6886 "unsupported version %u"),
6887 this->name().c_str(),
6888 this->abiflags_
->version
);
6891 this->abiflags_
->isa_level
=
6892 elfcpp::Swap
<8, big_endian
>::readval(view
+ 2);
6893 this->abiflags_
->isa_rev
=
6894 elfcpp::Swap
<8, big_endian
>::readval(view
+ 3);
6895 this->abiflags_
->gpr_size
=
6896 elfcpp::Swap
<8, big_endian
>::readval(view
+ 4);
6897 this->abiflags_
->cpr1_size
=
6898 elfcpp::Swap
<8, big_endian
>::readval(view
+ 5);
6899 this->abiflags_
->cpr2_size
=
6900 elfcpp::Swap
<8, big_endian
>::readval(view
+ 6);
6901 this->abiflags_
->fp_abi
=
6902 elfcpp::Swap
<8, big_endian
>::readval(view
+ 7);
6903 this->abiflags_
->isa_ext
=
6904 elfcpp::Swap
<32, big_endian
>::readval(view
+ 8);
6905 this->abiflags_
->ases
=
6906 elfcpp::Swap
<32, big_endian
>::readval(view
+ 12);
6907 this->abiflags_
->flags1
=
6908 elfcpp::Swap
<32, big_endian
>::readval(view
+ 16);
6909 this->abiflags_
->flags2
=
6910 elfcpp::Swap
<32, big_endian
>::readval(view
+ 20);
6913 // In the 64-bit ABI, .MIPS.options section holds register information.
6914 // A SHT_MIPS_OPTIONS section contains a series of options, each of which
6915 // starts with this header:
6919 // // Type of option.
6920 // unsigned char kind[1];
6921 // // Size of option descriptor, including header.
6922 // unsigned char size[1];
6923 // // Section index of affected section, or 0 for global option.
6924 // unsigned char section[2];
6925 // // Information specific to this kind of option.
6926 // unsigned char info[4];
6929 // For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and set
6930 // the gp value based on what we find. We may see both SHT_MIPS_REGINFO
6931 // and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case, they should agree.
6933 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_OPTIONS
)
6935 section_offset_type section_offset
= shdr
.get_sh_offset();
6936 section_size_type section_size
=
6937 convert_to_section_size_type(shdr
.get_sh_size());
6938 const unsigned char* view
=
6939 this->get_view(section_offset
, section_size
, true, false);
6940 const unsigned char* end
= view
+ section_size
;
6942 while (view
+ 8 <= end
)
6944 unsigned char kind
= elfcpp::Swap
<8, big_endian
>::readval(view
);
6945 unsigned char sz
= elfcpp::Swap
<8, big_endian
>::readval(view
+ 1);
6948 gold_error(_("%s: Warning: bad `%s' option size %u smaller "
6950 this->name().c_str(),
6951 this->mips_elf_options_section_name(), sz
);
6955 if (this->is_n64() && kind
== elfcpp::ODK_REGINFO
)
6957 // In the 64 bit ABI, an ODK_REGINFO option is the following
6958 // structure. The info field of the options header is not
6963 // // Mask of general purpose registers used.
6964 // unsigned char ri_gprmask[4];
6966 // unsigned char ri_pad[4];
6967 // // Mask of co-processor registers used.
6968 // unsigned char ri_cprmask[4][4];
6969 // // GP register value for this object file.
6970 // unsigned char ri_gp_value[8];
6973 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
6976 else if (kind
== elfcpp::ODK_REGINFO
)
6978 // In the 32 bit ABI, an ODK_REGINFO option is the following
6979 // structure. The info field of the options header is not
6980 // used. The same structure is used in .reginfo section.
6984 // unsigned char ri_gprmask[4];
6985 // unsigned char ri_cprmask[4][4];
6986 // unsigned char ri_gp_value[4];
6989 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
6996 const char* name
= pnames
+ shdr
.get_sh_name();
6997 this->section_is_mips16_fn_stub_
[i
] = is_prefix_of(".mips16.fn", name
);
6998 this->section_is_mips16_call_stub_
[i
] =
6999 is_prefix_of(".mips16.call.", name
);
7000 this->section_is_mips16_call_fp_stub_
[i
] =
7001 is_prefix_of(".mips16.call.fp.", name
);
7003 if (strcmp(name
, ".pdr") == 0)
7005 gold_assert(this->pdr_shndx_
== -1U);
7006 this->pdr_shndx_
= i
;
7011 // Discard MIPS16 stub secions that are not needed.
7013 template<int size
, bool big_endian
>
7015 Mips_relobj
<size
, big_endian
>::discard_mips16_stub_sections(Symbol_table
* symtab
)
7017 for (typename
Mips16_stubs_int_map::const_iterator
7018 it
= this->mips16_stub_sections_
.begin();
7019 it
!= this->mips16_stub_sections_
.end(); ++it
)
7021 Mips16_stub_section
<size
, big_endian
>* stub_section
= it
->second
;
7022 if (!stub_section
->is_target_found())
7024 gold_error(_("no relocation found in mips16 stub section '%s'"),
7025 stub_section
->object()
7026 ->section_name(stub_section
->shndx()).c_str());
7029 bool discard
= false;
7030 if (stub_section
->is_for_local_function())
7032 if (stub_section
->is_fn_stub())
7034 // This stub is for a local symbol. This stub will only
7035 // be needed if there is some relocation in this object,
7036 // other than a 16 bit function call, which refers to this
7038 if (!this->has_local_non_16bit_call_relocs(stub_section
->r_sym()))
7041 this->add_local_mips16_fn_stub(stub_section
);
7045 // This stub is for a local symbol. This stub will only
7046 // be needed if there is some relocation (R_MIPS16_26) in
7047 // this object that refers to this symbol.
7048 gold_assert(stub_section
->is_call_stub()
7049 || stub_section
->is_call_fp_stub());
7050 if (!this->has_local_16bit_call_relocs(stub_section
->r_sym()))
7053 this->add_local_mips16_call_stub(stub_section
);
7058 Mips_symbol
<size
>* gsym
= stub_section
->gsym();
7059 if (stub_section
->is_fn_stub())
7061 if (gsym
->has_mips16_fn_stub())
7062 // We already have a stub for this function.
7066 gsym
->set_mips16_fn_stub(stub_section
);
7067 if (gsym
->should_add_dynsym_entry(symtab
))
7069 // If we have a MIPS16 function with a stub, the
7070 // dynamic symbol must refer to the stub, since only
7071 // the stub uses the standard calling conventions.
7072 gsym
->set_need_fn_stub();
7073 if (gsym
->is_from_dynobj())
7074 gsym
->set_needs_dynsym_value();
7077 if (!gsym
->need_fn_stub())
7080 else if (stub_section
->is_call_stub())
7082 if (gsym
->is_mips16())
7083 // We don't need the call_stub; this is a 16 bit
7084 // function, so calls from other 16 bit functions are
7087 else if (gsym
->has_mips16_call_stub())
7088 // We already have a stub for this function.
7091 gsym
->set_mips16_call_stub(stub_section
);
7095 gold_assert(stub_section
->is_call_fp_stub());
7096 if (gsym
->is_mips16())
7097 // We don't need the call_stub; this is a 16 bit
7098 // function, so calls from other 16 bit functions are
7101 else if (gsym
->has_mips16_call_fp_stub())
7102 // We already have a stub for this function.
7105 gsym
->set_mips16_call_fp_stub(stub_section
);
7109 this->set_output_section(stub_section
->shndx(), NULL
);
7113 // Mips_output_data_la25_stub methods.
7115 // Template for standard LA25 stub.
7116 template<int size
, bool big_endian
>
7118 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_entry
[] =
7120 0x3c190000, // lui $25,%hi(func)
7121 0x08000000, // j func
7122 0x27390000, // add $25,$25,%lo(func)
7126 // Template for microMIPS LA25 stub.
7127 template<int size
, bool big_endian
>
7129 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_micromips_entry
[] =
7131 0x41b9, 0x0000, // lui t9,%hi(func)
7132 0xd400, 0x0000, // j func
7133 0x3339, 0x0000, // addiu t9,t9,%lo(func)
7134 0x0000, 0x0000 // nop
7137 // Create la25 stub for a symbol.
7139 template<int size
, bool big_endian
>
7141 Mips_output_data_la25_stub
<size
, big_endian
>::create_la25_stub(
7142 Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
7143 Mips_symbol
<size
>* gsym
)
7145 if (!gsym
->has_la25_stub())
7147 gsym
->set_la25_stub_offset(this->symbols_
.size() * 16);
7148 this->symbols_
.push_back(gsym
);
7149 this->create_stub_symbol(gsym
, symtab
, target
, 16);
7153 // Create a symbol for SYM stub's value and size, to help make the disassembly
7156 template<int size
, bool big_endian
>
7158 Mips_output_data_la25_stub
<size
, big_endian
>::create_stub_symbol(
7159 Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
7160 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
)
7162 std::string
name(".pic.");
7163 name
+= sym
->name();
7165 unsigned int offset
= sym
->la25_stub_offset();
7166 if (sym
->is_micromips())
7169 // Make it a local function.
7170 Symbol
* new_sym
= symtab
->define_in_output_data(name
.c_str(), NULL
,
7171 Symbol_table::PREDEFINED
,
7172 target
->la25_stub_section(),
7173 offset
, symsize
, elfcpp::STT_FUNC
,
7175 elfcpp::STV_DEFAULT
, 0,
7177 new_sym
->set_is_forced_local();
7180 // Write out la25 stubs. This uses the hand-coded instructions above,
7181 // and adjusts them as needed.
7183 template<int size
, bool big_endian
>
7185 Mips_output_data_la25_stub
<size
, big_endian
>::do_write(Output_file
* of
)
7187 const off_t offset
= this->offset();
7188 const section_size_type oview_size
=
7189 convert_to_section_size_type(this->data_size());
7190 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
7192 for (typename
std::vector
<Mips_symbol
<size
>*>::iterator
7193 p
= this->symbols_
.begin();
7194 p
!= this->symbols_
.end();
7197 Mips_symbol
<size
>* sym
= *p
;
7198 unsigned char* pov
= oview
+ sym
->la25_stub_offset();
7200 Mips_address target
= sym
->value();
7201 if (!sym
->is_micromips())
7203 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7204 la25_stub_entry
[0] | (((target
+ 0x8000) >> 16) & 0xffff));
7205 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7206 la25_stub_entry
[1] | ((target
>> 2) & 0x3ffffff));
7207 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
7208 la25_stub_entry
[2] | (target
& 0xffff));
7209 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12, la25_stub_entry
[3]);
7214 // First stub instruction. Paste high 16-bits of the target.
7215 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
7216 la25_stub_micromips_entry
[0]);
7217 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7218 ((target
+ 0x8000) >> 16) & 0xffff);
7219 // Second stub instruction. Paste low 26-bits of the target, shifted
7221 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
7222 la25_stub_micromips_entry
[2] | ((target
>> 17) & 0x3ff));
7223 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
7224 la25_stub_micromips_entry
[3] | ((target
>> 1) & 0xffff));
7225 // Third stub instruction. Paste low 16-bits of the target.
7226 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8,
7227 la25_stub_micromips_entry
[4]);
7228 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, target
& 0xffff);
7229 // Fourth stub instruction.
7230 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 12,
7231 la25_stub_micromips_entry
[6]);
7232 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 14,
7233 la25_stub_micromips_entry
[7]);
7237 of
->write_output_view(offset
, oview_size
, oview
);
7240 // Mips_output_data_plt methods.
7242 // The format of the first PLT entry in an O32 executable.
7243 template<int size
, bool big_endian
>
7244 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_o32
[] =
7246 0x3c1c0000, // lui $28, %hi(&GOTPLT[0])
7247 0x8f990000, // lw $25, %lo(&GOTPLT[0])($28)
7248 0x279c0000, // addiu $28, $28, %lo(&GOTPLT[0])
7249 0x031cc023, // subu $24, $24, $28
7250 0x03e07825, // or $15, $31, zero
7251 0x0018c082, // srl $24, $24, 2
7252 0x0320f809, // jalr $25
7253 0x2718fffe // subu $24, $24, 2
7256 // The format of the first PLT entry in an N32 executable. Different
7257 // because gp ($28) is not available; we use t2 ($14) instead.
7258 template<int size
, bool big_endian
>
7259 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n32
[] =
7261 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
7262 0x8dd90000, // lw $25, %lo(&GOTPLT[0])($14)
7263 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
7264 0x030ec023, // subu $24, $24, $14
7265 0x03e07825, // or $15, $31, zero
7266 0x0018c082, // srl $24, $24, 2
7267 0x0320f809, // jalr $25
7268 0x2718fffe // subu $24, $24, 2
7271 // The format of the first PLT entry in an N64 executable. Different
7272 // from N32 because of the increased size of GOT entries.
7273 template<int size
, bool big_endian
>
7274 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n64
[] =
7276 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
7277 0xddd90000, // ld $25, %lo(&GOTPLT[0])($14)
7278 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
7279 0x030ec023, // subu $24, $24, $14
7280 0x03e07825, // or $15, $31, zero
7281 0x0018c0c2, // srl $24, $24, 3
7282 0x0320f809, // jalr $25
7283 0x2718fffe // subu $24, $24, 2
7286 // The format of the microMIPS first PLT entry in an O32 executable.
7287 // We rely on v0 ($2) rather than t8 ($24) to contain the address
7288 // of the GOTPLT entry handled, so this stub may only be used when
7289 // all the subsequent PLT entries are microMIPS code too.
7291 // The trailing NOP is for alignment and correct disassembly only.
7292 template<int size
, bool big_endian
>
7293 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
7294 plt0_entry_micromips_o32
[] =
7296 0x7980, 0x0000, // addiupc $3, (&GOTPLT[0]) - .
7297 0xff23, 0x0000, // lw $25, 0($3)
7298 0x0535, // subu $2, $2, $3
7299 0x2525, // srl $2, $2, 2
7300 0x3302, 0xfffe, // subu $24, $2, 2
7301 0x0dff, // move $15, $31
7302 0x45f9, // jalrs $25
7303 0x0f83, // move $28, $3
7307 // The format of the microMIPS first PLT entry in an O32 executable
7308 // in the insn32 mode.
7309 template<int size
, bool big_endian
>
7310 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
7311 plt0_entry_micromips32_o32
[] =
7313 0x41bc, 0x0000, // lui $28, %hi(&GOTPLT[0])
7314 0xff3c, 0x0000, // lw $25, %lo(&GOTPLT[0])($28)
7315 0x339c, 0x0000, // addiu $28, $28, %lo(&GOTPLT[0])
7316 0x0398, 0xc1d0, // subu $24, $24, $28
7317 0x001f, 0x7a90, // or $15, $31, zero
7318 0x0318, 0x1040, // srl $24, $24, 2
7319 0x03f9, 0x0f3c, // jalr $25
7320 0x3318, 0xfffe // subu $24, $24, 2
7323 // The format of subsequent standard entries in the PLT.
7324 template<int size
, bool big_endian
>
7325 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry
[] =
7327 0x3c0f0000, // lui $15, %hi(.got.plt entry)
7328 0x01f90000, // l[wd] $25, %lo(.got.plt entry)($15)
7329 0x03200008, // jr $25
7330 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
7333 // The format of subsequent R6 PLT entries.
7334 template<int size
, bool big_endian
>
7335 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry_r6
[] =
7337 0x3c0f0000, // lui $15, %hi(.got.plt entry)
7338 0x01f90000, // l[wd] $25, %lo(.got.plt entry)($15)
7339 0x03200009, // jr $25
7340 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
7343 // The format of subsequent MIPS16 o32 PLT entries. We use v1 ($3) as a
7344 // temporary because t8 ($24) and t9 ($25) are not directly addressable.
7345 // Note that this differs from the GNU ld which uses both v0 ($2) and v1 ($3).
7346 // We cannot use v0 because MIPS16 call stubs from the CS toolchain expect
7347 // target function address in register v0.
7348 template<int size
, bool big_endian
>
7349 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry_mips16_o32
[] =
7351 0xb303, // lw $3, 12($pc)
7352 0x651b, // move $24, $3
7353 0x9b60, // lw $3, 0($3)
7355 0x653b, // move $25, $3
7357 0x0000, 0x0000 // .word (.got.plt entry)
7360 // The format of subsequent microMIPS o32 PLT entries. We use v0 ($2)
7361 // as a temporary because t8 ($24) is not addressable with ADDIUPC.
7362 template<int size
, bool big_endian
>
7363 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
7364 plt_entry_micromips_o32
[] =
7366 0x7900, 0x0000, // addiupc $2, (.got.plt entry) - .
7367 0xff22, 0x0000, // lw $25, 0($2)
7369 0x0f02 // move $24, $2
7372 // The format of subsequent microMIPS o32 PLT entries in the insn32 mode.
7373 template<int size
, bool big_endian
>
7374 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
7375 plt_entry_micromips32_o32
[] =
7377 0x41af, 0x0000, // lui $15, %hi(.got.plt entry)
7378 0xff2f, 0x0000, // lw $25, %lo(.got.plt entry)($15)
7379 0x0019, 0x0f3c, // jr $25
7380 0x330f, 0x0000 // addiu $24, $15, %lo(.got.plt entry)
7383 // Add an entry to the PLT for a symbol referenced by r_type relocation.
7385 template<int size
, bool big_endian
>
7387 Mips_output_data_plt
<size
, big_endian
>::add_entry(Mips_symbol
<size
>* gsym
,
7388 unsigned int r_type
)
7390 gold_assert(!gsym
->has_plt_offset());
7392 // Final PLT offset for a symbol will be set in method set_plt_offsets().
7393 gsym
->set_plt_offset(this->entry_count() * sizeof(plt_entry
)
7394 + sizeof(plt0_entry_o32
));
7395 this->symbols_
.push_back(gsym
);
7397 // Record whether the relocation requires a standard MIPS
7398 // or a compressed code entry.
7399 if (jal_reloc(r_type
))
7401 if (r_type
== elfcpp::R_MIPS_26
)
7402 gsym
->set_needs_mips_plt(true);
7404 gsym
->set_needs_comp_plt(true);
7407 section_offset_type got_offset
= this->got_plt_
->current_data_size();
7409 // Every PLT entry needs a GOT entry which points back to the PLT
7410 // entry (this will be changed by the dynamic linker, normally
7411 // lazily when the function is called).
7412 this->got_plt_
->set_current_data_size(got_offset
+ size
/8);
7414 gsym
->set_needs_dynsym_entry();
7415 this->rel_
->add_global(gsym
, elfcpp::R_MIPS_JUMP_SLOT
, this->got_plt_
,
7419 // Set final PLT offsets. For each symbol, determine whether standard or
7420 // compressed (MIPS16 or microMIPS) PLT entry is used.
7422 template<int size
, bool big_endian
>
7424 Mips_output_data_plt
<size
, big_endian
>::set_plt_offsets()
7426 // The sizes of individual PLT entries.
7427 unsigned int plt_mips_entry_size
= this->standard_plt_entry_size();
7428 unsigned int plt_comp_entry_size
= (!this->target_
->is_output_newabi()
7429 ? this->compressed_plt_entry_size() : 0);
7431 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
7432 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
7434 Mips_symbol
<size
>* mips_sym
= *p
;
7436 // There are no defined MIPS16 or microMIPS PLT entries for n32 or n64,
7437 // so always use a standard entry there.
7439 // If the symbol has a MIPS16 call stub and gets a PLT entry, then
7440 // all MIPS16 calls will go via that stub, and there is no benefit
7441 // to having a MIPS16 entry. And in the case of call_stub a
7442 // standard entry actually has to be used as the stub ends with a J
7444 if (this->target_
->is_output_newabi()
7445 || mips_sym
->has_mips16_call_stub()
7446 || mips_sym
->has_mips16_call_fp_stub())
7448 mips_sym
->set_needs_mips_plt(true);
7449 mips_sym
->set_needs_comp_plt(false);
7452 // Otherwise, if there are no direct calls to the function, we
7453 // have a free choice of whether to use standard or compressed
7454 // entries. Prefer microMIPS entries if the object is known to
7455 // contain microMIPS code, so that it becomes possible to create
7456 // pure microMIPS binaries. Prefer standard entries otherwise,
7457 // because MIPS16 ones are no smaller and are usually slower.
7458 if (!mips_sym
->needs_mips_plt() && !mips_sym
->needs_comp_plt())
7460 if (this->target_
->is_output_micromips())
7461 mips_sym
->set_needs_comp_plt(true);
7463 mips_sym
->set_needs_mips_plt(true);
7466 if (mips_sym
->needs_mips_plt())
7468 mips_sym
->set_mips_plt_offset(this->plt_mips_offset_
);
7469 this->plt_mips_offset_
+= plt_mips_entry_size
;
7471 if (mips_sym
->needs_comp_plt())
7473 mips_sym
->set_comp_plt_offset(this->plt_comp_offset_
);
7474 this->plt_comp_offset_
+= plt_comp_entry_size
;
7478 // Figure out the size of the PLT header if we know that we are using it.
7479 if (this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0)
7480 this->plt_header_size_
= this->get_plt_header_size();
7483 // Write out the PLT. This uses the hand-coded instructions above,
7484 // and adjusts them as needed.
7486 template<int size
, bool big_endian
>
7488 Mips_output_data_plt
<size
, big_endian
>::do_write(Output_file
* of
)
7490 const off_t offset
= this->offset();
7491 const section_size_type oview_size
=
7492 convert_to_section_size_type(this->data_size());
7493 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
7495 const off_t gotplt_file_offset
= this->got_plt_
->offset();
7496 const section_size_type gotplt_size
=
7497 convert_to_section_size_type(this->got_plt_
->data_size());
7498 unsigned char* const gotplt_view
= of
->get_output_view(gotplt_file_offset
,
7500 unsigned char* pov
= oview
;
7502 Mips_address plt_address
= this->address();
7504 // Calculate the address of .got.plt.
7505 Mips_address gotplt_addr
= this->got_plt_
->address();
7506 Mips_address gotplt_addr_high
= ((gotplt_addr
+ 0x8000) >> 16) & 0xffff;
7507 Mips_address gotplt_addr_low
= gotplt_addr
& 0xffff;
7509 // The PLT sequence is not safe for N64 if .got.plt's address can
7510 // not be loaded in two instructions.
7511 gold_assert((gotplt_addr
& ~(Mips_address
) 0x7fffffff) == 0
7512 || ~(gotplt_addr
| 0x7fffffff) == 0);
7514 // Write the PLT header.
7515 const uint32_t* plt0_entry
= this->get_plt_header_entry();
7516 if (plt0_entry
== plt0_entry_micromips_o32
)
7518 // Write microMIPS PLT header.
7519 gold_assert(gotplt_addr
% 4 == 0);
7521 Mips_address gotpc_offset
= gotplt_addr
- ((plt_address
| 3) ^ 3);
7523 // ADDIUPC has a span of +/-16MB, check we're in range.
7524 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
7526 gold_error(_(".got.plt offset of %ld from .plt beyond the range of "
7527 "ADDIUPC"), (long)gotpc_offset
);
7531 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
7532 plt0_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
7533 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7534 (gotpc_offset
>> 2) & 0xffff);
7536 for (unsigned int i
= 2;
7537 i
< (sizeof(plt0_entry_micromips_o32
)
7538 / sizeof(plt0_entry_micromips_o32
[0]));
7541 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7545 else if (plt0_entry
== plt0_entry_micromips32_o32
)
7547 // Write microMIPS PLT header in insn32 mode.
7548 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[0]);
7549 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, gotplt_addr_high
);
7550 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, plt0_entry
[2]);
7551 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, gotplt_addr_low
);
7552 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8, plt0_entry
[4]);
7553 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, gotplt_addr_low
);
7555 for (unsigned int i
= 6;
7556 i
< (sizeof(plt0_entry_micromips32_o32
)
7557 / sizeof(plt0_entry_micromips32_o32
[0]));
7560 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7566 // Write standard PLT header.
7567 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7568 plt0_entry
[0] | gotplt_addr_high
);
7569 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7570 plt0_entry
[1] | gotplt_addr_low
);
7571 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
7572 plt0_entry
[2] | gotplt_addr_low
);
7574 for (int i
= 3; i
< 8; i
++)
7576 elfcpp::Swap
<32, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7582 unsigned char* gotplt_pov
= gotplt_view
;
7583 unsigned int got_entry_size
= size
/8; // TODO(sasa): MIPS_ELF_GOT_SIZE
7585 // The first two entries in .got.plt are reserved.
7586 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
, 0);
7587 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
+ got_entry_size
, 0);
7589 unsigned int gotplt_offset
= 2 * got_entry_size
;
7590 gotplt_pov
+= 2 * got_entry_size
;
7592 // Calculate the address of the PLT header.
7593 Mips_address header_address
= (plt_address
7594 + (this->is_plt_header_compressed() ? 1 : 0));
7596 // Initialize compressed PLT area view.
7597 unsigned char* pov2
= pov
+ this->plt_mips_offset_
;
7599 // Write the PLT entries.
7600 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
7601 p
= this->symbols_
.begin();
7602 p
!= this->symbols_
.end();
7603 ++p
, gotplt_pov
+= got_entry_size
, gotplt_offset
+= got_entry_size
)
7605 Mips_symbol
<size
>* mips_sym
= *p
;
7607 // Calculate the address of the .got.plt entry.
7608 uint32_t gotplt_entry_addr
= (gotplt_addr
+ gotplt_offset
);
7609 uint32_t gotplt_entry_addr_hi
= (((gotplt_entry_addr
+ 0x8000) >> 16)
7611 uint32_t gotplt_entry_addr_lo
= gotplt_entry_addr
& 0xffff;
7613 // Initially point the .got.plt entry at the PLT header.
7614 if (this->target_
->is_output_n64())
7615 elfcpp::Swap
<64, big_endian
>::writeval(gotplt_pov
, header_address
);
7617 elfcpp::Swap
<32, big_endian
>::writeval(gotplt_pov
, header_address
);
7619 // Now handle the PLT itself. First the standard entry.
7620 if (mips_sym
->has_mips_plt_offset())
7622 // Pick the load opcode (LW or LD).
7623 uint64_t load
= this->target_
->is_output_n64() ? 0xdc000000
7626 const uint32_t* entry
= this->target_
->is_output_r6() ? plt_entry_r6
7629 // Fill in the PLT entry itself.
7630 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7631 entry
[0] | gotplt_entry_addr_hi
);
7632 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7633 entry
[1] | gotplt_entry_addr_lo
| load
);
7634 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8, entry
[2]);
7635 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12,
7636 entry
[3] | gotplt_entry_addr_lo
);
7640 // Now the compressed entry. They come after any standard ones.
7641 if (mips_sym
->has_comp_plt_offset())
7643 if (!this->target_
->is_output_micromips())
7645 // Write MIPS16 PLT entry.
7646 const uint32_t* plt_entry
= plt_entry_mips16_o32
;
7648 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
7649 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2, plt_entry
[1]);
7650 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7651 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
7652 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7653 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7654 elfcpp::Swap
<32, big_endian
>::writeval(pov2
+ 12,
7658 else if (this->target_
->use_32bit_micromips_instructions())
7660 // Write microMIPS PLT entry in insn32 mode.
7661 const uint32_t* plt_entry
= plt_entry_micromips32_o32
;
7663 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
7664 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2,
7665 gotplt_entry_addr_hi
);
7666 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7667 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6,
7668 gotplt_entry_addr_lo
);
7669 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7670 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7671 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 12, plt_entry
[6]);
7672 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 14,
7673 gotplt_entry_addr_lo
);
7678 // Write microMIPS PLT entry.
7679 const uint32_t* plt_entry
= plt_entry_micromips_o32
;
7681 gold_assert(gotplt_entry_addr
% 4 == 0);
7683 Mips_address loc_address
= plt_address
+ pov2
- oview
;
7684 int gotpc_offset
= gotplt_entry_addr
- ((loc_address
| 3) ^ 3);
7686 // ADDIUPC has a span of +/-16MB, check we're in range.
7687 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
7689 gold_error(_(".got.plt offset of %ld from .plt beyond the "
7690 "range of ADDIUPC"), (long)gotpc_offset
);
7694 elfcpp::Swap
<16, big_endian
>::writeval(pov2
,
7695 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
7696 elfcpp::Swap
<16, big_endian
>::writeval(
7697 pov2
+ 2, (gotpc_offset
>> 2) & 0xffff);
7698 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7699 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
7700 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7701 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7707 // Check the number of bytes written for standard entries.
7708 gold_assert(static_cast<section_size_type
>(
7709 pov
- oview
- this->plt_header_size_
) == this->plt_mips_offset_
);
7710 // Check the number of bytes written for compressed entries.
7711 gold_assert((static_cast<section_size_type
>(pov2
- pov
)
7712 == this->plt_comp_offset_
));
7713 // Check the total number of bytes written.
7714 gold_assert(static_cast<section_size_type
>(pov2
- oview
) == oview_size
);
7716 gold_assert(static_cast<section_size_type
>(gotplt_pov
- gotplt_view
)
7719 of
->write_output_view(offset
, oview_size
, oview
);
7720 of
->write_output_view(gotplt_file_offset
, gotplt_size
, gotplt_view
);
7723 // Mips_output_data_mips_stubs methods.
7725 // The format of the lazy binding stub when dynamic symbol count is less than
7726 // 64K, dynamic symbol index is less than 32K, and ABI is not N64.
7727 template<int size
, bool big_endian
>
7729 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1
[4] =
7731 0x8f998010, // lw t9,0x8010(gp)
7732 0x03e07825, // or t7,ra,zero
7733 0x0320f809, // jalr t9,ra
7734 0x24180000 // addiu t8,zero,DYN_INDEX sign extended
7737 // The format of the lazy binding stub when dynamic symbol count is less than
7738 // 64K, dynamic symbol index is less than 32K, and ABI is N64.
7739 template<int size
, bool big_endian
>
7741 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1_n64
[4] =
7743 0xdf998010, // ld t9,0x8010(gp)
7744 0x03e07825, // or t7,ra,zero
7745 0x0320f809, // jalr t9,ra
7746 0x64180000 // daddiu t8,zero,DYN_INDEX sign extended
7749 // The format of the lazy binding stub when dynamic symbol count is less than
7750 // 64K, dynamic symbol index is between 32K and 64K, and ABI is not N64.
7751 template<int size
, bool big_endian
>
7753 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2
[4] =
7755 0x8f998010, // lw t9,0x8010(gp)
7756 0x03e07825, // or t7,ra,zero
7757 0x0320f809, // jalr t9,ra
7758 0x34180000 // ori t8,zero,DYN_INDEX unsigned
7761 // The format of the lazy binding stub when dynamic symbol count is less than
7762 // 64K, dynamic symbol index is between 32K and 64K, and ABI is N64.
7763 template<int size
, bool big_endian
>
7765 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2_n64
[4] =
7767 0xdf998010, // ld t9,0x8010(gp)
7768 0x03e07825, // or t7,ra,zero
7769 0x0320f809, // jalr t9,ra
7770 0x34180000 // ori t8,zero,DYN_INDEX unsigned
7773 // The format of the lazy binding stub when dynamic symbol count is greater than
7774 // 64K, and ABI is not N64.
7775 template<int size
, bool big_endian
>
7776 const uint32_t Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big
[5] =
7778 0x8f998010, // lw t9,0x8010(gp)
7779 0x03e07825, // or t7,ra,zero
7780 0x3c180000, // lui t8,DYN_INDEX
7781 0x0320f809, // jalr t9,ra
7782 0x37180000 // ori t8,t8,DYN_INDEX
7785 // The format of the lazy binding stub when dynamic symbol count is greater than
7786 // 64K, and ABI is N64.
7787 template<int size
, bool big_endian
>
7789 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big_n64
[5] =
7791 0xdf998010, // ld t9,0x8010(gp)
7792 0x03e07825, // or t7,ra,zero
7793 0x3c180000, // lui t8,DYN_INDEX
7794 0x0320f809, // jalr t9,ra
7795 0x37180000 // ori t8,t8,DYN_INDEX
7800 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7801 // less than 64K, dynamic symbol index is less than 32K, and ABI is not N64.
7802 template<int size
, bool big_endian
>
7804 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_1
[] =
7806 0xff3c, 0x8010, // lw t9,0x8010(gp)
7807 0x0dff, // move t7,ra
7809 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
7812 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7813 // less than 64K, dynamic symbol index is less than 32K, and ABI is N64.
7814 template<int size
, bool big_endian
>
7816 Mips_output_data_mips_stubs
<size
, big_endian
>::
7817 lazy_stub_micromips_normal_1_n64
[] =
7819 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7820 0x0dff, // move t7,ra
7822 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
7825 // The format of the microMIPS lazy binding stub when dynamic symbol
7826 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7827 // and ABI is not N64.
7828 template<int size
, bool big_endian
>
7830 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_2
[] =
7832 0xff3c, 0x8010, // lw t9,0x8010(gp)
7833 0x0dff, // move t7,ra
7835 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7838 // The format of the microMIPS lazy binding stub when dynamic symbol
7839 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7841 template<int size
, bool big_endian
>
7843 Mips_output_data_mips_stubs
<size
, big_endian
>::
7844 lazy_stub_micromips_normal_2_n64
[] =
7846 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7847 0x0dff, // move t7,ra
7849 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7852 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7853 // greater than 64K, and ABI is not N64.
7854 template<int size
, bool big_endian
>
7856 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big
[] =
7858 0xff3c, 0x8010, // lw t9,0x8010(gp)
7859 0x0dff, // move t7,ra
7860 0x41b8, 0x0000, // lui t8,DYN_INDEX
7862 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7865 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7866 // greater than 64K, and ABI is N64.
7867 template<int size
, bool big_endian
>
7869 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big_n64
[] =
7871 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7872 0x0dff, // move t7,ra
7873 0x41b8, 0x0000, // lui t8,DYN_INDEX
7875 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7878 // 32-bit microMIPS stubs.
7880 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7881 // less than 64K, dynamic symbol index is less than 32K, ABI is not N64, and we
7882 // can use only 32-bit instructions.
7883 template<int size
, bool big_endian
>
7885 Mips_output_data_mips_stubs
<size
, big_endian
>::
7886 lazy_stub_micromips32_normal_1
[] =
7888 0xff3c, 0x8010, // lw t9,0x8010(gp)
7889 0x001f, 0x7a90, // or t7,ra,zero
7890 0x03f9, 0x0f3c, // jalr ra,t9
7891 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
7894 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7895 // less than 64K, dynamic symbol index is less than 32K, ABI is N64, and we can
7896 // use only 32-bit instructions.
7897 template<int size
, bool big_endian
>
7899 Mips_output_data_mips_stubs
<size
, big_endian
>::
7900 lazy_stub_micromips32_normal_1_n64
[] =
7902 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7903 0x001f, 0x7a90, // or t7,ra,zero
7904 0x03f9, 0x0f3c, // jalr ra,t9
7905 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
7908 // The format of the microMIPS lazy binding stub when dynamic symbol
7909 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7910 // ABI is not N64, and we can use only 32-bit instructions.
7911 template<int size
, bool big_endian
>
7913 Mips_output_data_mips_stubs
<size
, big_endian
>::
7914 lazy_stub_micromips32_normal_2
[] =
7916 0xff3c, 0x8010, // lw t9,0x8010(gp)
7917 0x001f, 0x7a90, // or t7,ra,zero
7918 0x03f9, 0x0f3c, // jalr ra,t9
7919 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7922 // The format of the microMIPS lazy binding stub when dynamic symbol
7923 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7924 // ABI is N64, and we can use only 32-bit instructions.
7925 template<int size
, bool big_endian
>
7927 Mips_output_data_mips_stubs
<size
, big_endian
>::
7928 lazy_stub_micromips32_normal_2_n64
[] =
7930 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7931 0x001f, 0x7a90, // or t7,ra,zero
7932 0x03f9, 0x0f3c, // jalr ra,t9
7933 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7936 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7937 // greater than 64K, ABI is not N64, and we can use only 32-bit instructions.
7938 template<int size
, bool big_endian
>
7940 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big
[] =
7942 0xff3c, 0x8010, // lw t9,0x8010(gp)
7943 0x001f, 0x7a90, // or t7,ra,zero
7944 0x41b8, 0x0000, // lui t8,DYN_INDEX
7945 0x03f9, 0x0f3c, // jalr ra,t9
7946 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7949 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7950 // greater than 64K, ABI is N64, and we can use only 32-bit instructions.
7951 template<int size
, bool big_endian
>
7953 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big_n64
[] =
7955 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7956 0x001f, 0x7a90, // or t7,ra,zero
7957 0x41b8, 0x0000, // lui t8,DYN_INDEX
7958 0x03f9, 0x0f3c, // jalr ra,t9
7959 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7962 // Create entry for a symbol.
7964 template<int size
, bool big_endian
>
7966 Mips_output_data_mips_stubs
<size
, big_endian
>::make_entry(
7967 Mips_symbol
<size
>* gsym
)
7969 if (!gsym
->has_lazy_stub() && !gsym
->has_plt_offset())
7971 this->symbols_
.insert(gsym
);
7972 gsym
->set_has_lazy_stub(true);
7976 // Remove entry for a symbol.
7978 template<int size
, bool big_endian
>
7980 Mips_output_data_mips_stubs
<size
, big_endian
>::remove_entry(
7981 Mips_symbol
<size
>* gsym
)
7983 if (gsym
->has_lazy_stub())
7985 this->symbols_
.erase(gsym
);
7986 gsym
->set_has_lazy_stub(false);
7990 // Set stub offsets for symbols. This method expects that the number of
7991 // entries in dynamic symbol table is set.
7993 template<int size
, bool big_endian
>
7995 Mips_output_data_mips_stubs
<size
, big_endian
>::set_lazy_stub_offsets()
7997 gold_assert(this->dynsym_count_
!= -1U);
7999 if (this->stub_offsets_are_set_
)
8002 unsigned int stub_size
= this->stub_size();
8003 unsigned int offset
= 0;
8004 for (typename
Mips_stubs_entry_set::const_iterator
8005 p
= this->symbols_
.begin();
8006 p
!= this->symbols_
.end();
8007 ++p
, offset
+= stub_size
)
8009 Mips_symbol
<size
>* mips_sym
= *p
;
8010 mips_sym
->set_lazy_stub_offset(offset
);
8012 this->stub_offsets_are_set_
= true;
8015 template<int size
, bool big_endian
>
8017 Mips_output_data_mips_stubs
<size
, big_endian
>::set_needs_dynsym_value()
8019 for (typename
Mips_stubs_entry_set::const_iterator
8020 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
8022 Mips_symbol
<size
>* sym
= *p
;
8023 if (sym
->is_from_dynobj())
8024 sym
->set_needs_dynsym_value();
8028 // Write out the .MIPS.stubs. This uses the hand-coded instructions and
8029 // adjusts them as needed.
8031 template<int size
, bool big_endian
>
8033 Mips_output_data_mips_stubs
<size
, big_endian
>::do_write(Output_file
* of
)
8035 const off_t offset
= this->offset();
8036 const section_size_type oview_size
=
8037 convert_to_section_size_type(this->data_size());
8038 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
8040 bool big_stub
= this->dynsym_count_
> 0x10000;
8042 unsigned char* pov
= oview
;
8043 for (typename
Mips_stubs_entry_set::const_iterator
8044 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
8046 Mips_symbol
<size
>* sym
= *p
;
8047 const uint32_t* lazy_stub
;
8048 bool n64
= this->target_
->is_output_n64();
8050 if (!this->target_
->is_output_micromips())
8052 // Write standard (non-microMIPS) stub.
8055 if (sym
->dynsym_index() & ~0x7fff)
8056 // Dynsym index is between 32K and 64K.
8057 lazy_stub
= n64
? lazy_stub_normal_2_n64
: lazy_stub_normal_2
;
8059 // Dynsym index is less than 32K.
8060 lazy_stub
= n64
? lazy_stub_normal_1_n64
: lazy_stub_normal_1
;
8063 lazy_stub
= n64
? lazy_stub_big_n64
: lazy_stub_big
;
8066 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8067 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 1]);
8073 // LUI instruction of the big stub. Paste high 16 bits of the
8075 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
8076 lazy_stub
[i
] | ((sym
->dynsym_index() >> 16) & 0x7fff));
8080 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8081 // Last stub instruction. Paste low 16 bits of the dynsym index.
8082 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
8083 lazy_stub
[i
+ 1] | (sym
->dynsym_index() & 0xffff));
8086 else if (this->target_
->use_32bit_micromips_instructions())
8088 // Write microMIPS stub in insn32 mode.
8091 if (sym
->dynsym_index() & ~0x7fff)
8092 // Dynsym index is between 32K and 64K.
8093 lazy_stub
= n64
? lazy_stub_micromips32_normal_2_n64
8094 : lazy_stub_micromips32_normal_2
;
8096 // Dynsym index is less than 32K.
8097 lazy_stub
= n64
? lazy_stub_micromips32_normal_1_n64
8098 : lazy_stub_micromips32_normal_1
;
8101 lazy_stub
= n64
? lazy_stub_micromips32_big_n64
8102 : lazy_stub_micromips32_big
;
8105 // First stub instruction. We emit 32-bit microMIPS instructions by
8106 // emitting two 16-bit parts because on microMIPS the 16-bit part of
8107 // the instruction where the opcode is must always come first, for
8108 // both little and big endian.
8109 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8110 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
8111 // Second stub instruction.
8112 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
8113 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, lazy_stub
[i
+ 3]);
8118 // LUI instruction of the big stub. Paste high 16 bits of the
8120 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8121 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
8122 (sym
->dynsym_index() >> 16) & 0x7fff);
8126 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8127 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
8128 // Last stub instruction. Paste low 16 bits of the dynsym index.
8129 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
8130 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
8131 sym
->dynsym_index() & 0xffff);
8136 // Write microMIPS stub.
8139 if (sym
->dynsym_index() & ~0x7fff)
8140 // Dynsym index is between 32K and 64K.
8141 lazy_stub
= n64
? lazy_stub_micromips_normal_2_n64
8142 : lazy_stub_micromips_normal_2
;
8144 // Dynsym index is less than 32K.
8145 lazy_stub
= n64
? lazy_stub_micromips_normal_1_n64
8146 : lazy_stub_micromips_normal_1
;
8149 lazy_stub
= n64
? lazy_stub_micromips_big_n64
8150 : lazy_stub_micromips_big
;
8153 // First stub instruction. We emit 32-bit microMIPS instructions by
8154 // emitting two 16-bit parts because on microMIPS the 16-bit part of
8155 // the instruction where the opcode is must always come first, for
8156 // both little and big endian.
8157 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8158 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
8159 // Second stub instruction.
8160 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
8165 // LUI instruction of the big stub. Paste high 16 bits of the
8167 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8168 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
8169 (sym
->dynsym_index() >> 16) & 0x7fff);
8173 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8174 // Last stub instruction. Paste low 16 bits of the dynsym index.
8175 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
8176 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
8177 sym
->dynsym_index() & 0xffff);
8182 // We always allocate 20 bytes for every stub, because final dynsym count is
8183 // not known in method do_finalize_sections. There are 4 unused bytes per
8184 // stub if final dynsym count is less than 0x10000.
8185 unsigned int used
= pov
- oview
;
8186 unsigned int unused
= big_stub
? 0 : this->symbols_
.size() * 4;
8187 gold_assert(static_cast<section_size_type
>(used
+ unused
) == oview_size
);
8189 // Fill the unused space with zeroes.
8190 // TODO(sasa): Can we strip unused bytes during the relaxation?
8192 memset(pov
, 0, unused
);
8194 of
->write_output_view(offset
, oview_size
, oview
);
8197 // Mips_output_section_reginfo methods.
8199 template<int size
, bool big_endian
>
8201 Mips_output_section_reginfo
<size
, big_endian
>::do_write(Output_file
* of
)
8203 off_t offset
= this->offset();
8204 off_t data_size
= this->data_size();
8206 unsigned char* view
= of
->get_output_view(offset
, data_size
);
8207 elfcpp::Swap
<size
, big_endian
>::writeval(view
, this->gprmask_
);
8208 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 4, this->cprmask1_
);
8209 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 8, this->cprmask2_
);
8210 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 12, this->cprmask3_
);
8211 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 16, this->cprmask4_
);
8212 // Write the gp value.
8213 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 20,
8214 this->target_
->gp_value());
8216 of
->write_output_view(offset
, data_size
, view
);
8219 // Mips_output_section_options methods.
8221 template<int size
, bool big_endian
>
8223 Mips_output_section_options
<size
, big_endian
>::do_write(Output_file
* of
)
8225 off_t offset
= this->offset();
8226 const section_size_type oview_size
=
8227 convert_to_section_size_type(this->data_size());
8228 unsigned char* view
= of
->get_output_view(offset
, oview_size
);
8229 const unsigned char* end
= view
+ oview_size
;
8231 while (view
+ 8 <= end
)
8233 unsigned char kind
= elfcpp::Swap
<8, big_endian
>::readval(view
);
8234 unsigned char sz
= elfcpp::Swap
<8, big_endian
>::readval(view
+ 1);
8237 gold_error(_("Warning: bad `%s' option size %u smaller "
8238 "than its header in output section"),
8243 // Only update ri_gp_value (GP register value) field of ODK_REGINFO entry.
8244 if (this->target_
->is_output_n64() && kind
== elfcpp::ODK_REGINFO
)
8245 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 32,
8246 this->target_
->gp_value());
8247 else if (kind
== elfcpp::ODK_REGINFO
)
8248 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 28,
8249 this->target_
->gp_value());
8254 of
->write_output_view(offset
, oview_size
, view
);
8257 // Mips_output_section_abiflags methods.
8259 template<int size
, bool big_endian
>
8261 Mips_output_section_abiflags
<size
, big_endian
>::do_write(Output_file
* of
)
8263 off_t offset
= this->offset();
8264 off_t data_size
= this->data_size();
8266 unsigned char* view
= of
->get_output_view(offset
, data_size
);
8267 elfcpp::Swap
<16, big_endian
>::writeval(view
, this->abiflags_
.version
);
8268 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 2, this->abiflags_
.isa_level
);
8269 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 3, this->abiflags_
.isa_rev
);
8270 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 4, this->abiflags_
.gpr_size
);
8271 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 5, this->abiflags_
.cpr1_size
);
8272 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 6, this->abiflags_
.cpr2_size
);
8273 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 7, this->abiflags_
.fp_abi
);
8274 elfcpp::Swap
<32, big_endian
>::writeval(view
+ 8, this->abiflags_
.isa_ext
);
8275 elfcpp::Swap
<32, big_endian
>::writeval(view
+ 12, this->abiflags_
.ases
);
8276 elfcpp::Swap
<32, big_endian
>::writeval(view
+ 16, this->abiflags_
.flags1
);
8277 elfcpp::Swap
<32, big_endian
>::writeval(view
+ 20, this->abiflags_
.flags2
);
8279 of
->write_output_view(offset
, data_size
, view
);
8282 // Mips_copy_relocs methods.
8284 // Emit any saved relocs.
8286 template<int sh_type
, int size
, bool big_endian
>
8288 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_mips(
8289 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
8290 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
8292 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
8293 Copy_reloc_entries::iterator p
= this->entries_
.begin();
8294 p
!= this->entries_
.end();
8296 emit_entry(*p
, reloc_section
, symtab
, layout
, target
);
8298 // We no longer need the saved information.
8299 this->entries_
.clear();
8302 // Emit the reloc if appropriate.
8304 template<int sh_type
, int size
, bool big_endian
>
8306 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_entry(
8307 Copy_reloc_entry
& entry
,
8308 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
8309 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
8311 // If the symbol is no longer defined in a dynamic object, then we
8312 // emitted a COPY relocation, and we do not want to emit this
8313 // dynamic relocation.
8314 if (!entry
.sym_
->is_from_dynobj())
8317 bool can_make_dynamic
= (entry
.reloc_type_
== elfcpp::R_MIPS_32
8318 || entry
.reloc_type_
== elfcpp::R_MIPS_REL32
8319 || entry
.reloc_type_
== elfcpp::R_MIPS_64
);
8321 Mips_symbol
<size
>* sym
= Mips_symbol
<size
>::as_mips_sym(entry
.sym_
);
8322 if (can_make_dynamic
&& !sym
->has_static_relocs())
8324 Mips_relobj
<size
, big_endian
>* object
=
8325 Mips_relobj
<size
, big_endian
>::as_mips_relobj(entry
.relobj_
);
8326 target
->got_section(symtab
, layout
)->record_global_got_symbol(
8327 sym
, object
, entry
.reloc_type_
, true, false);
8328 if (!symbol_references_local(sym
, sym
->should_add_dynsym_entry(symtab
)))
8329 target
->rel_dyn_section(layout
)->add_global(sym
, elfcpp::R_MIPS_REL32
,
8330 entry
.output_section_
, entry
.relobj_
, entry
.shndx_
, entry
.address_
);
8332 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
8333 sym
, elfcpp::R_MIPS_REL32
, entry
.output_section_
, entry
.relobj_
,
8334 entry
.shndx_
, entry
.address_
);
8337 this->make_copy_reloc(symtab
, layout
,
8338 static_cast<Sized_symbol
<size
>*>(entry
.sym_
),
8343 // Target_mips methods.
8345 // Return the value to use for a dynamic symbol which requires special
8346 // treatment. This is how we support equality comparisons of function
8347 // pointers across shared library boundaries, as described in the
8348 // processor specific ABI supplement.
8350 template<int size
, bool big_endian
>
8352 Target_mips
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
8355 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
8357 if (!mips_sym
->has_lazy_stub())
8359 if (mips_sym
->has_plt_offset())
8361 // We distinguish between PLT entries and lazy-binding stubs by
8362 // giving the former an st_other value of STO_MIPS_PLT. Set the
8363 // value to the stub address if there are any relocations in the
8364 // binary where pointer equality matters.
8365 if (mips_sym
->pointer_equality_needed())
8367 // Prefer a standard MIPS PLT entry.
8368 if (mips_sym
->has_mips_plt_offset())
8369 value
= this->plt_section()->mips_entry_address(mips_sym
);
8371 value
= this->plt_section()->comp_entry_address(mips_sym
) + 1;
8379 // First, set stub offsets for symbols. This method expects that the
8380 // number of entries in dynamic symbol table is set.
8381 this->mips_stubs_section()->set_lazy_stub_offsets();
8383 // The run-time linker uses the st_value field of the symbol
8384 // to reset the global offset table entry for this external
8385 // to its stub address when unlinking a shared object.
8386 value
= this->mips_stubs_section()->stub_address(mips_sym
);
8389 if (mips_sym
->has_mips16_fn_stub())
8391 // If we have a MIPS16 function with a stub, the dynamic symbol must
8392 // refer to the stub, since only the stub uses the standard calling
8394 value
= mips_sym
->template
8395 get_mips16_fn_stub
<big_endian
>()->output_address();
8401 // Get the dynamic reloc section, creating it if necessary. It's always
8402 // .rel.dyn, even for MIPS64.
8404 template<int size
, bool big_endian
>
8405 typename Target_mips
<size
, big_endian
>::Reloc_section
*
8406 Target_mips
<size
, big_endian
>::rel_dyn_section(Layout
* layout
)
8408 if (this->rel_dyn_
== NULL
)
8410 gold_assert(layout
!= NULL
);
8411 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
8412 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
8413 elfcpp::SHF_ALLOC
, this->rel_dyn_
,
8414 ORDER_DYNAMIC_RELOCS
, false);
8416 // First entry in .rel.dyn has to be null.
8417 // This is hack - we define dummy output data and set its address to 0,
8418 // and define absolute R_MIPS_NONE relocation with offset 0 against it.
8419 // This ensures that the entry is null.
8420 Output_data
* od
= new Output_data_zero_fill(0, 0);
8422 this->rel_dyn_
->add_absolute(elfcpp::R_MIPS_NONE
, od
, 0);
8424 return this->rel_dyn_
;
8427 // Get the GOT section, creating it if necessary.
8429 template<int size
, bool big_endian
>
8430 Mips_output_data_got
<size
, big_endian
>*
8431 Target_mips
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
8434 if (this->got_
== NULL
)
8436 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
8438 this->got_
= new Mips_output_data_got
<size
, big_endian
>(this, symtab
,
8440 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
8441 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
|
8442 elfcpp::SHF_MIPS_GPREL
),
8443 this->got_
, ORDER_DATA
, false);
8445 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
8446 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
8447 Symbol_table::PREDEFINED
,
8449 0, 0, elfcpp::STT_OBJECT
,
8451 elfcpp::STV_HIDDEN
, 0,
8458 // Calculate value of _gp symbol.
8460 template<int size
, bool big_endian
>
8462 Target_mips
<size
, big_endian
>::set_gp(Layout
* layout
, Symbol_table
* symtab
)
8464 gold_assert(this->gp_
== NULL
);
8466 Sized_symbol
<size
>* gp
=
8467 static_cast<Sized_symbol
<size
>*>(symtab
->lookup("_gp"));
8469 // Set _gp symbol if the linker script hasn't created it.
8470 if (gp
== NULL
|| gp
->source() != Symbol::IS_CONSTANT
)
8472 // If there is no .got section, gp should be based on .sdata.
8473 Output_data
* gp_section
= (this->got_
!= NULL
8474 ? this->got_
->output_section()
8475 : layout
->find_output_section(".sdata"));
8477 if (gp_section
!= NULL
)
8478 gp
= static_cast<Sized_symbol
<size
>*>(symtab
->define_in_output_data(
8479 "_gp", NULL
, Symbol_table::PREDEFINED
,
8480 gp_section
, MIPS_GP_OFFSET
, 0,
8483 elfcpp::STV_DEFAULT
,
8490 // Set the dynamic symbol indexes. INDEX is the index of the first
8491 // global dynamic symbol. Pointers to the symbols are stored into the
8492 // vector SYMS. The names are added to DYNPOOL. This returns an
8493 // updated dynamic symbol index.
8495 template<int size
, bool big_endian
>
8497 Target_mips
<size
, big_endian
>::do_set_dynsym_indexes(
8498 std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
8499 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
8500 Versions
* versions
, Symbol_table
* symtab
) const
8502 std::vector
<Symbol
*> non_got_symbols
;
8503 std::vector
<Symbol
*> got_symbols
;
8505 reorder_dyn_symbols
<size
, big_endian
>(dyn_symbols
, &non_got_symbols
,
8508 for (std::vector
<Symbol
*>::iterator p
= non_got_symbols
.begin();
8509 p
!= non_got_symbols
.end();
8514 // Note that SYM may already have a dynamic symbol index, since
8515 // some symbols appear more than once in the symbol table, with
8516 // and without a version.
8518 if (!sym
->has_dynsym_index())
8520 sym
->set_dynsym_index(index
);
8522 syms
->push_back(sym
);
8523 dynpool
->add(sym
->name(), false, NULL
);
8525 // Record any version information.
8526 if (sym
->version() != NULL
)
8527 versions
->record_version(symtab
, dynpool
, sym
);
8529 // If the symbol is defined in a dynamic object and is
8530 // referenced in a regular object, then mark the dynamic
8531 // object as needed. This is used to implement --as-needed.
8532 if (sym
->is_from_dynobj() && sym
->in_reg())
8533 sym
->object()->set_is_needed();
8537 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
8538 p
!= got_symbols
.end();
8542 if (!sym
->has_dynsym_index())
8544 // Record any version information.
8545 if (sym
->version() != NULL
)
8546 versions
->record_version(symtab
, dynpool
, sym
);
8550 index
= versions
->finalize(symtab
, index
, syms
);
8552 int got_sym_count
= 0;
8553 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
8554 p
!= got_symbols
.end();
8559 if (!sym
->has_dynsym_index())
8562 sym
->set_dynsym_index(index
);
8564 syms
->push_back(sym
);
8565 dynpool
->add(sym
->name(), false, NULL
);
8567 // If the symbol is defined in a dynamic object and is
8568 // referenced in a regular object, then mark the dynamic
8569 // object as needed. This is used to implement --as-needed.
8570 if (sym
->is_from_dynobj() && sym
->in_reg())
8571 sym
->object()->set_is_needed();
8575 // Set index of the first symbol that has .got entry.
8576 this->got_
->set_first_global_got_dynsym_index(
8577 got_sym_count
> 0 ? index
- got_sym_count
: -1U);
8579 if (this->mips_stubs_
!= NULL
)
8580 this->mips_stubs_
->set_dynsym_count(index
);
8585 // Create a PLT entry for a global symbol referenced by r_type relocation.
8587 template<int size
, bool big_endian
>
8589 Target_mips
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
8591 Mips_symbol
<size
>* gsym
,
8592 unsigned int r_type
)
8594 if (gsym
->has_lazy_stub() || gsym
->has_plt_offset())
8597 if (this->plt_
== NULL
)
8599 // Create the GOT section first.
8600 this->got_section(symtab
, layout
);
8602 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
8603 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
8604 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
8605 this->got_plt_
, ORDER_DATA
, false);
8607 // The first two entries are reserved.
8608 this->got_plt_
->set_current_data_size(2 * size
/8);
8610 this->plt_
= new Mips_output_data_plt
<size
, big_endian
>(layout
,
8613 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
8615 | elfcpp::SHF_EXECINSTR
),
8616 this->plt_
, ORDER_PLT
, false);
8618 // Make the sh_info field of .rel.plt point to .plt.
8619 Output_section
* rel_plt_os
= this->plt_
->rel_plt()->output_section();
8620 rel_plt_os
->set_info_section(this->plt_
->output_section());
8623 this->plt_
->add_entry(gsym
, r_type
);
8627 // Get the .MIPS.stubs section, creating it if necessary.
8629 template<int size
, bool big_endian
>
8630 Mips_output_data_mips_stubs
<size
, big_endian
>*
8631 Target_mips
<size
, big_endian
>::mips_stubs_section(Layout
* layout
)
8633 if (this->mips_stubs_
== NULL
)
8636 new Mips_output_data_mips_stubs
<size
, big_endian
>(this);
8637 layout
->add_output_section_data(".MIPS.stubs", elfcpp::SHT_PROGBITS
,
8639 | elfcpp::SHF_EXECINSTR
),
8640 this->mips_stubs_
, ORDER_PLT
, false);
8642 return this->mips_stubs_
;
8645 // Get the LA25 stub section, creating it if necessary.
8647 template<int size
, bool big_endian
>
8648 Mips_output_data_la25_stub
<size
, big_endian
>*
8649 Target_mips
<size
, big_endian
>::la25_stub_section(Layout
* layout
)
8651 if (this->la25_stub_
== NULL
)
8653 this->la25_stub_
= new Mips_output_data_la25_stub
<size
, big_endian
>();
8654 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
8656 | elfcpp::SHF_EXECINSTR
),
8657 this->la25_stub_
, ORDER_TEXT
, false);
8659 return this->la25_stub_
;
8662 // Process the relocations to determine unreferenced sections for
8663 // garbage collection.
8665 template<int size
, bool big_endian
>
8667 Target_mips
<size
, big_endian
>::gc_process_relocs(
8668 Symbol_table
* symtab
,
8670 Sized_relobj_file
<size
, big_endian
>* object
,
8671 unsigned int data_shndx
,
8672 unsigned int sh_type
,
8673 const unsigned char* prelocs
,
8675 Output_section
* output_section
,
8676 bool needs_special_offset_handling
,
8677 size_t local_symbol_count
,
8678 const unsigned char* plocal_symbols
)
8680 typedef Target_mips
<size
, big_endian
> Mips
;
8682 if (sh_type
== elfcpp::SHT_REL
)
8684 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8687 gold::gc_process_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8696 needs_special_offset_handling
,
8700 else if (sh_type
== elfcpp::SHT_RELA
)
8702 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8705 gold::gc_process_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8714 needs_special_offset_handling
,
8722 // Scan relocations for a section.
8724 template<int size
, bool big_endian
>
8726 Target_mips
<size
, big_endian
>::scan_relocs(
8727 Symbol_table
* symtab
,
8729 Sized_relobj_file
<size
, big_endian
>* object
,
8730 unsigned int data_shndx
,
8731 unsigned int sh_type
,
8732 const unsigned char* prelocs
,
8734 Output_section
* output_section
,
8735 bool needs_special_offset_handling
,
8736 size_t local_symbol_count
,
8737 const unsigned char* plocal_symbols
)
8739 typedef Target_mips
<size
, big_endian
> Mips
;
8741 if (sh_type
== elfcpp::SHT_REL
)
8743 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8746 gold::scan_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8755 needs_special_offset_handling
,
8759 else if (sh_type
== elfcpp::SHT_RELA
)
8761 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8764 gold::scan_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8773 needs_special_offset_handling
,
8779 template<int size
, bool big_endian
>
8781 Target_mips
<size
, big_endian
>::mips_32bit_flags(elfcpp::Elf_Word flags
)
8783 return ((flags
& elfcpp::EF_MIPS_32BITMODE
) != 0
8784 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_O32
8785 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_EABI32
8786 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_1
8787 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_2
8788 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32
8789 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32R2
8790 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32R6
);
8793 // Return the MACH for a MIPS e_flags value.
8794 template<int size
, bool big_endian
>
8796 Target_mips
<size
, big_endian
>::elf_mips_mach(elfcpp::Elf_Word flags
)
8798 switch (flags
& elfcpp::EF_MIPS_MACH
)
8800 case elfcpp::E_MIPS_MACH_3900
:
8801 return mach_mips3900
;
8803 case elfcpp::E_MIPS_MACH_4010
:
8804 return mach_mips4010
;
8806 case elfcpp::E_MIPS_MACH_4100
:
8807 return mach_mips4100
;
8809 case elfcpp::E_MIPS_MACH_4111
:
8810 return mach_mips4111
;
8812 case elfcpp::E_MIPS_MACH_4120
:
8813 return mach_mips4120
;
8815 case elfcpp::E_MIPS_MACH_4650
:
8816 return mach_mips4650
;
8818 case elfcpp::E_MIPS_MACH_5400
:
8819 return mach_mips5400
;
8821 case elfcpp::E_MIPS_MACH_5500
:
8822 return mach_mips5500
;
8824 case elfcpp::E_MIPS_MACH_5900
:
8825 return mach_mips5900
;
8827 case elfcpp::E_MIPS_MACH_9000
:
8828 return mach_mips9000
;
8830 case elfcpp::E_MIPS_MACH_SB1
:
8831 return mach_mips_sb1
;
8833 case elfcpp::E_MIPS_MACH_LS2E
:
8834 return mach_mips_loongson_2e
;
8836 case elfcpp::E_MIPS_MACH_LS2F
:
8837 return mach_mips_loongson_2f
;
8839 case elfcpp::E_MIPS_MACH_LS3A
:
8840 return mach_mips_loongson_3a
;
8842 case elfcpp::E_MIPS_MACH_OCTEON3
:
8843 return mach_mips_octeon3
;
8845 case elfcpp::E_MIPS_MACH_OCTEON2
:
8846 return mach_mips_octeon2
;
8848 case elfcpp::E_MIPS_MACH_OCTEON
:
8849 return mach_mips_octeon
;
8851 case elfcpp::E_MIPS_MACH_XLR
:
8852 return mach_mips_xlr
;
8855 switch (flags
& elfcpp::EF_MIPS_ARCH
)
8858 case elfcpp::E_MIPS_ARCH_1
:
8859 return mach_mips3000
;
8861 case elfcpp::E_MIPS_ARCH_2
:
8862 return mach_mips6000
;
8864 case elfcpp::E_MIPS_ARCH_3
:
8865 return mach_mips4000
;
8867 case elfcpp::E_MIPS_ARCH_4
:
8868 return mach_mips8000
;
8870 case elfcpp::E_MIPS_ARCH_5
:
8873 case elfcpp::E_MIPS_ARCH_32
:
8874 return mach_mipsisa32
;
8876 case elfcpp::E_MIPS_ARCH_64
:
8877 return mach_mipsisa64
;
8879 case elfcpp::E_MIPS_ARCH_32R2
:
8880 return mach_mipsisa32r2
;
8882 case elfcpp::E_MIPS_ARCH_32R6
:
8883 return mach_mipsisa32r6
;
8885 case elfcpp::E_MIPS_ARCH_64R2
:
8886 return mach_mipsisa64r2
;
8888 case elfcpp::E_MIPS_ARCH_64R6
:
8889 return mach_mipsisa64r6
;
8896 // Return the MACH for each .MIPS.abiflags ISA Extension.
8898 template<int size
, bool big_endian
>
8900 Target_mips
<size
, big_endian
>::mips_isa_ext_mach(unsigned int isa_ext
)
8904 case elfcpp::AFL_EXT_3900
:
8905 return mach_mips3900
;
8907 case elfcpp::AFL_EXT_4010
:
8908 return mach_mips4010
;
8910 case elfcpp::AFL_EXT_4100
:
8911 return mach_mips4100
;
8913 case elfcpp::AFL_EXT_4111
:
8914 return mach_mips4111
;
8916 case elfcpp::AFL_EXT_4120
:
8917 return mach_mips4120
;
8919 case elfcpp::AFL_EXT_4650
:
8920 return mach_mips4650
;
8922 case elfcpp::AFL_EXT_5400
:
8923 return mach_mips5400
;
8925 case elfcpp::AFL_EXT_5500
:
8926 return mach_mips5500
;
8928 case elfcpp::AFL_EXT_5900
:
8929 return mach_mips5900
;
8931 case elfcpp::AFL_EXT_10000
:
8932 return mach_mips10000
;
8934 case elfcpp::AFL_EXT_LOONGSON_2E
:
8935 return mach_mips_loongson_2e
;
8937 case elfcpp::AFL_EXT_LOONGSON_2F
:
8938 return mach_mips_loongson_2f
;
8940 case elfcpp::AFL_EXT_LOONGSON_3A
:
8941 return mach_mips_loongson_3a
;
8943 case elfcpp::AFL_EXT_SB1
:
8944 return mach_mips_sb1
;
8946 case elfcpp::AFL_EXT_OCTEON
:
8947 return mach_mips_octeon
;
8949 case elfcpp::AFL_EXT_OCTEONP
:
8950 return mach_mips_octeonp
;
8952 case elfcpp::AFL_EXT_OCTEON2
:
8953 return mach_mips_octeon2
;
8955 case elfcpp::AFL_EXT_XLR
:
8956 return mach_mips_xlr
;
8959 return mach_mips3000
;
8963 // Return the .MIPS.abiflags value representing each ISA Extension.
8965 template<int size
, bool big_endian
>
8967 Target_mips
<size
, big_endian
>::mips_isa_ext(unsigned int mips_mach
)
8972 return elfcpp::AFL_EXT_3900
;
8975 return elfcpp::AFL_EXT_4010
;
8978 return elfcpp::AFL_EXT_4100
;
8981 return elfcpp::AFL_EXT_4111
;
8984 return elfcpp::AFL_EXT_4120
;
8987 return elfcpp::AFL_EXT_4650
;
8990 return elfcpp::AFL_EXT_5400
;
8993 return elfcpp::AFL_EXT_5500
;
8996 return elfcpp::AFL_EXT_5900
;
8998 case mach_mips10000
:
8999 return elfcpp::AFL_EXT_10000
;
9001 case mach_mips_loongson_2e
:
9002 return elfcpp::AFL_EXT_LOONGSON_2E
;
9004 case mach_mips_loongson_2f
:
9005 return elfcpp::AFL_EXT_LOONGSON_2F
;
9007 case mach_mips_loongson_3a
:
9008 return elfcpp::AFL_EXT_LOONGSON_3A
;
9011 return elfcpp::AFL_EXT_SB1
;
9013 case mach_mips_octeon
:
9014 return elfcpp::AFL_EXT_OCTEON
;
9016 case mach_mips_octeonp
:
9017 return elfcpp::AFL_EXT_OCTEONP
;
9019 case mach_mips_octeon3
:
9020 return elfcpp::AFL_EXT_OCTEON3
;
9022 case mach_mips_octeon2
:
9023 return elfcpp::AFL_EXT_OCTEON2
;
9026 return elfcpp::AFL_EXT_XLR
;
9033 // Update the isa_level, isa_rev, isa_ext fields of abiflags.
9035 template<int size
, bool big_endian
>
9037 Target_mips
<size
, big_endian
>::update_abiflags_isa(const std::string
& name
,
9038 elfcpp::Elf_Word e_flags
, Mips_abiflags
<big_endian
>* abiflags
)
9041 switch (e_flags
& elfcpp::EF_MIPS_ARCH
)
9043 case elfcpp::E_MIPS_ARCH_1
:
9044 new_isa
= this->level_rev(1, 0);
9046 case elfcpp::E_MIPS_ARCH_2
:
9047 new_isa
= this->level_rev(2, 0);
9049 case elfcpp::E_MIPS_ARCH_3
:
9050 new_isa
= this->level_rev(3, 0);
9052 case elfcpp::E_MIPS_ARCH_4
:
9053 new_isa
= this->level_rev(4, 0);
9055 case elfcpp::E_MIPS_ARCH_5
:
9056 new_isa
= this->level_rev(5, 0);
9058 case elfcpp::E_MIPS_ARCH_32
:
9059 new_isa
= this->level_rev(32, 1);
9061 case elfcpp::E_MIPS_ARCH_32R2
:
9062 new_isa
= this->level_rev(32, 2);
9064 case elfcpp::E_MIPS_ARCH_32R6
:
9065 new_isa
= this->level_rev(32, 6);
9067 case elfcpp::E_MIPS_ARCH_64
:
9068 new_isa
= this->level_rev(64, 1);
9070 case elfcpp::E_MIPS_ARCH_64R2
:
9071 new_isa
= this->level_rev(64, 2);
9073 case elfcpp::E_MIPS_ARCH_64R6
:
9074 new_isa
= this->level_rev(64, 6);
9077 gold_error(_("%s: Unknown architecture %s"), name
.c_str(),
9078 this->elf_mips_mach_name(e_flags
));
9081 if (new_isa
> this->level_rev(abiflags
->isa_level
, abiflags
->isa_rev
))
9083 // Decode a single value into level and revision.
9084 abiflags
->isa_level
= new_isa
>> 3;
9085 abiflags
->isa_rev
= new_isa
& 0x7;
9088 // Update the isa_ext if needed.
9089 if (this->mips_mach_extends(this->mips_isa_ext_mach(abiflags
->isa_ext
),
9090 this->elf_mips_mach(e_flags
)))
9091 abiflags
->isa_ext
= this->mips_isa_ext(this->elf_mips_mach(e_flags
));
9094 // Infer the content of the ABI flags based on the elf header.
9096 template<int size
, bool big_endian
>
9098 Target_mips
<size
, big_endian
>::infer_abiflags(
9099 Mips_relobj
<size
, big_endian
>* relobj
, Mips_abiflags
<big_endian
>* abiflags
)
9101 const Attributes_section_data
* pasd
= relobj
->attributes_section_data();
9102 int attr_fp_abi
= elfcpp::Val_GNU_MIPS_ABI_FP_ANY
;
9103 elfcpp::Elf_Word e_flags
= relobj
->processor_specific_flags();
9105 this->update_abiflags_isa(relobj
->name(), e_flags
, abiflags
);
9108 // Read fp_abi from the .gnu.attribute section.
9109 const Object_attribute
* attr
=
9110 pasd
->known_attributes(Object_attribute::OBJ_ATTR_GNU
);
9111 attr_fp_abi
= attr
[elfcpp::Tag_GNU_MIPS_ABI_FP
].int_value();
9114 abiflags
->fp_abi
= attr_fp_abi
;
9115 abiflags
->cpr1_size
= elfcpp::AFL_REG_NONE
;
9116 abiflags
->cpr2_size
= elfcpp::AFL_REG_NONE
;
9117 abiflags
->gpr_size
= this->mips_32bit_flags(e_flags
) ? elfcpp::AFL_REG_32
9118 : elfcpp::AFL_REG_64
;
9120 if (abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_SINGLE
9121 || abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_XX
9122 || (abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
9123 && abiflags
->gpr_size
== elfcpp::AFL_REG_32
))
9124 abiflags
->cpr1_size
= elfcpp::AFL_REG_32
;
9125 else if (abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
9126 || abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_64
9127 || abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
)
9128 abiflags
->cpr1_size
= elfcpp::AFL_REG_64
;
9130 if (e_flags
& elfcpp::EF_MIPS_ARCH_ASE_MDMX
)
9131 abiflags
->ases
|= elfcpp::AFL_ASE_MDMX
;
9132 if (e_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
)
9133 abiflags
->ases
|= elfcpp::AFL_ASE_MIPS16
;
9134 if (e_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
)
9135 abiflags
->ases
|= elfcpp::AFL_ASE_MICROMIPS
;
9137 if (abiflags
->fp_abi
!= elfcpp::Val_GNU_MIPS_ABI_FP_ANY
9138 && abiflags
->fp_abi
!= elfcpp::Val_GNU_MIPS_ABI_FP_SOFT
9139 && abiflags
->fp_abi
!= elfcpp::Val_GNU_MIPS_ABI_FP_64A
9140 && abiflags
->isa_level
>= 32
9141 && abiflags
->isa_ext
!= elfcpp::AFL_EXT_LOONGSON_3A
)
9142 abiflags
->flags1
|= elfcpp::AFL_FLAGS1_ODDSPREG
;
9145 // Create abiflags from elf header or from .MIPS.abiflags section.
9147 template<int size
, bool big_endian
>
9149 Target_mips
<size
, big_endian
>::create_abiflags(
9150 Mips_relobj
<size
, big_endian
>* relobj
,
9151 Mips_abiflags
<big_endian
>* abiflags
)
9153 Mips_abiflags
<big_endian
>* sec_abiflags
= relobj
->abiflags();
9154 Mips_abiflags
<big_endian
> header_abiflags
;
9156 this->infer_abiflags(relobj
, &header_abiflags
);
9158 if (sec_abiflags
== NULL
)
9160 // If there is no input .MIPS.abiflags section, use abiflags created
9162 *abiflags
= header_abiflags
;
9166 this->has_abiflags_section_
= true;
9168 // It is not possible to infer the correct ISA revision for R3 or R5
9169 // so drop down to R2 for the checks.
9170 unsigned char isa_rev
= sec_abiflags
->isa_rev
;
9171 if (isa_rev
== 3 || isa_rev
== 5)
9174 // Check compatibility between abiflags created from elf header
9175 // and abiflags from .MIPS.abiflags section in this object file.
9176 if (this->level_rev(sec_abiflags
->isa_level
, isa_rev
)
9177 < this->level_rev(header_abiflags
.isa_level
, header_abiflags
.isa_rev
))
9178 gold_warning(_("%s: Inconsistent ISA between e_flags and .MIPS.abiflags"),
9179 relobj
->name().c_str());
9180 if (header_abiflags
.fp_abi
!= elfcpp::Val_GNU_MIPS_ABI_FP_ANY
9181 && sec_abiflags
->fp_abi
!= header_abiflags
.fp_abi
)
9182 gold_warning(_("%s: Inconsistent FP ABI between .gnu.attributes and "
9183 ".MIPS.abiflags"), relobj
->name().c_str());
9184 if ((sec_abiflags
->ases
& header_abiflags
.ases
) != header_abiflags
.ases
)
9185 gold_warning(_("%s: Inconsistent ASEs between e_flags and .MIPS.abiflags"),
9186 relobj
->name().c_str());
9187 // The isa_ext is allowed to be an extension of what can be inferred
9189 if (!this->mips_mach_extends(this->mips_isa_ext_mach(header_abiflags
.isa_ext
),
9190 this->mips_isa_ext_mach(sec_abiflags
->isa_ext
)))
9191 gold_warning(_("%s: Inconsistent ISA extensions between e_flags and "
9192 ".MIPS.abiflags"), relobj
->name().c_str());
9193 if (sec_abiflags
->flags2
!= 0)
9194 gold_warning(_("%s: Unexpected flag in the flags2 field of "
9195 ".MIPS.abiflags (0x%x)"), relobj
->name().c_str(),
9196 sec_abiflags
->flags2
);
9197 // Use abiflags from .MIPS.abiflags section.
9198 *abiflags
= *sec_abiflags
;
9201 // Return the meaning of fp_abi, or "unknown" if not known.
9203 template<int size
, bool big_endian
>
9205 Target_mips
<size
, big_endian
>::fp_abi_string(int fp
)
9209 case elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
:
9210 return "-mdouble-float";
9211 case elfcpp::Val_GNU_MIPS_ABI_FP_SINGLE
:
9212 return "-msingle-float";
9213 case elfcpp::Val_GNU_MIPS_ABI_FP_SOFT
:
9214 return "-msoft-float";
9215 case elfcpp::Val_GNU_MIPS_ABI_FP_OLD_64
:
9216 return _("-mips32r2 -mfp64 (12 callee-saved)");
9217 case elfcpp::Val_GNU_MIPS_ABI_FP_XX
:
9219 case elfcpp::Val_GNU_MIPS_ABI_FP_64
:
9220 return "-mgp32 -mfp64";
9221 case elfcpp::Val_GNU_MIPS_ABI_FP_64A
:
9222 return "-mgp32 -mfp64 -mno-odd-spreg";
9230 template<int size
, bool big_endian
>
9232 Target_mips
<size
, big_endian
>::select_fp_abi(const std::string
& name
, int in_fp
,
9235 if (in_fp
== out_fp
)
9238 if (out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_ANY
)
9240 else if (out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_XX
9241 && (in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
9242 || in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64
9243 || in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
))
9245 else if (in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_XX
9246 && (out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
9247 || out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64
9248 || out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
))
9249 return out_fp
; // Keep the current setting.
9250 else if (out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
9251 && in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64
)
9253 else if (in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
9254 && out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64
)
9255 return out_fp
; // Keep the current setting.
9256 else if (in_fp
!= elfcpp::Val_GNU_MIPS_ABI_FP_ANY
)
9257 gold_warning(_("%s: FP ABI %s is incompatible with %s"), name
.c_str(),
9258 fp_abi_string(in_fp
), fp_abi_string(out_fp
));
9262 // Merge attributes from input object.
9264 template<int size
, bool big_endian
>
9266 Target_mips
<size
, big_endian
>::merge_obj_attributes(const std::string
& name
,
9267 const Attributes_section_data
* pasd
)
9269 // Return if there is no attributes section data.
9273 // If output has no object attributes, just copy.
9274 if (this->attributes_section_data_
== NULL
)
9276 this->attributes_section_data_
= new Attributes_section_data(*pasd
);
9280 Object_attribute
* out_attr
= this->attributes_section_data_
->known_attributes(
9281 Object_attribute::OBJ_ATTR_GNU
);
9283 out_attr
[elfcpp::Tag_GNU_MIPS_ABI_FP
].set_type(1);
9284 out_attr
[elfcpp::Tag_GNU_MIPS_ABI_FP
].set_int_value(this->abiflags_
->fp_abi
);
9286 // Merge Tag_compatibility attributes and any common GNU ones.
9287 this->attributes_section_data_
->merge(name
.c_str(), pasd
);
9290 // Merge abiflags from input object.
9292 template<int size
, bool big_endian
>
9294 Target_mips
<size
, big_endian
>::merge_obj_abiflags(const std::string
& name
,
9295 Mips_abiflags
<big_endian
>* in_abiflags
)
9297 // If output has no abiflags, just copy.
9298 if (this->abiflags_
== NULL
)
9300 this->abiflags_
= new Mips_abiflags
<big_endian
>(*in_abiflags
);
9304 this->abiflags_
->fp_abi
= this->select_fp_abi(name
, in_abiflags
->fp_abi
,
9305 this->abiflags_
->fp_abi
);
9308 this->abiflags_
->isa_level
= std::max(this->abiflags_
->isa_level
,
9309 in_abiflags
->isa_level
);
9310 this->abiflags_
->isa_rev
= std::max(this->abiflags_
->isa_rev
,
9311 in_abiflags
->isa_rev
);
9312 this->abiflags_
->gpr_size
= std::max(this->abiflags_
->gpr_size
,
9313 in_abiflags
->gpr_size
);
9314 this->abiflags_
->cpr1_size
= std::max(this->abiflags_
->cpr1_size
,
9315 in_abiflags
->cpr1_size
);
9316 this->abiflags_
->cpr2_size
= std::max(this->abiflags_
->cpr2_size
,
9317 in_abiflags
->cpr2_size
);
9318 this->abiflags_
->ases
|= in_abiflags
->ases
;
9319 this->abiflags_
->flags1
|= in_abiflags
->flags1
;
9322 // Check whether machine EXTENSION is an extension of machine BASE.
9323 template<int size
, bool big_endian
>
9325 Target_mips
<size
, big_endian
>::mips_mach_extends(unsigned int base
,
9326 unsigned int extension
)
9328 if (extension
== base
)
9331 if ((base
== mach_mipsisa32
)
9332 && this->mips_mach_extends(mach_mipsisa64
, extension
))
9335 if ((base
== mach_mipsisa32r2
)
9336 && this->mips_mach_extends(mach_mipsisa64r2
, extension
))
9339 for (unsigned int i
= 0; i
< this->mips_mach_extensions_
.size(); ++i
)
9340 if (extension
== this->mips_mach_extensions_
[i
].first
)
9342 extension
= this->mips_mach_extensions_
[i
].second
;
9343 if (extension
== base
)
9350 // Merge file header flags from input object.
9352 template<int size
, bool big_endian
>
9354 Target_mips
<size
, big_endian
>::merge_obj_e_flags(const std::string
& name
,
9355 elfcpp::Elf_Word in_flags
)
9357 // If flags are not set yet, just copy them.
9358 if (!this->are_processor_specific_flags_set())
9360 this->set_processor_specific_flags(in_flags
);
9361 this->mach_
= this->elf_mips_mach(in_flags
);
9365 elfcpp::Elf_Word new_flags
= in_flags
;
9366 elfcpp::Elf_Word old_flags
= this->processor_specific_flags();
9367 elfcpp::Elf_Word merged_flags
= this->processor_specific_flags();
9368 merged_flags
|= new_flags
& elfcpp::EF_MIPS_NOREORDER
;
9370 // Check flag compatibility.
9371 new_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
9372 old_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
9374 // Some IRIX 6 BSD-compatibility objects have this bit set. It
9375 // doesn't seem to matter.
9376 new_flags
&= ~elfcpp::EF_MIPS_XGOT
;
9377 old_flags
&= ~elfcpp::EF_MIPS_XGOT
;
9379 // MIPSpro generates ucode info in n64 objects. Again, we should
9380 // just be able to ignore this.
9381 new_flags
&= ~elfcpp::EF_MIPS_UCODE
;
9382 old_flags
&= ~elfcpp::EF_MIPS_UCODE
;
9384 if (new_flags
== old_flags
)
9386 this->set_processor_specific_flags(merged_flags
);
9390 if (((new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0)
9391 != ((old_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0))
9392 gold_warning(_("%s: linking abicalls files with non-abicalls files"),
9395 if (new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
))
9396 merged_flags
|= elfcpp::EF_MIPS_CPIC
;
9397 if (!(new_flags
& elfcpp::EF_MIPS_PIC
))
9398 merged_flags
&= ~elfcpp::EF_MIPS_PIC
;
9400 new_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
9401 old_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
9403 // Compare the ISAs.
9404 if (mips_32bit_flags(old_flags
) != mips_32bit_flags(new_flags
))
9405 gold_error(_("%s: linking 32-bit code with 64-bit code"), name
.c_str());
9406 else if (!this->mips_mach_extends(this->elf_mips_mach(in_flags
), this->mach_
))
9408 // Output ISA isn't the same as, or an extension of, input ISA.
9409 if (this->mips_mach_extends(this->mach_
, this->elf_mips_mach(in_flags
)))
9411 // Copy the architecture info from input object to output. Also copy
9412 // the 32-bit flag (if set) so that we continue to recognise
9413 // output as a 32-bit binary.
9414 this->mach_
= this->elf_mips_mach(in_flags
);
9415 merged_flags
&= ~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
);
9416 merged_flags
|= (new_flags
& (elfcpp::EF_MIPS_ARCH
9417 | elfcpp::EF_MIPS_MACH
| elfcpp::EF_MIPS_32BITMODE
));
9419 // Update the ABI flags isa_level, isa_rev, isa_ext fields.
9420 this->update_abiflags_isa(name
, merged_flags
, this->abiflags_
);
9422 // Copy across the ABI flags if output doesn't use them
9423 // and if that was what caused us to treat input object as 32-bit.
9424 if ((old_flags
& elfcpp::EF_MIPS_ABI
) == 0
9425 && this->mips_32bit_flags(new_flags
)
9426 && !this->mips_32bit_flags(new_flags
& ~elfcpp::EF_MIPS_ABI
))
9427 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ABI
;
9430 // The ISAs aren't compatible.
9431 gold_error(_("%s: linking %s module with previous %s modules"),
9432 name
.c_str(), this->elf_mips_mach_name(in_flags
),
9433 this->elf_mips_mach_name(merged_flags
));
9436 new_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
9437 | elfcpp::EF_MIPS_32BITMODE
));
9438 old_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
9439 | elfcpp::EF_MIPS_32BITMODE
));
9442 if ((new_flags
& elfcpp::EF_MIPS_ABI
) != (old_flags
& elfcpp::EF_MIPS_ABI
))
9444 // Only error if both are set (to different values).
9445 if ((new_flags
& elfcpp::EF_MIPS_ABI
)
9446 && (old_flags
& elfcpp::EF_MIPS_ABI
))
9447 gold_error(_("%s: ABI mismatch: linking %s module with "
9448 "previous %s modules"), name
.c_str(),
9449 this->elf_mips_abi_name(in_flags
),
9450 this->elf_mips_abi_name(merged_flags
));
9452 new_flags
&= ~elfcpp::EF_MIPS_ABI
;
9453 old_flags
&= ~elfcpp::EF_MIPS_ABI
;
9456 // Compare ASEs. Forbid linking MIPS16 and microMIPS ASE modules together
9457 // and allow arbitrary mixing of the remaining ASEs (retain the union).
9458 if ((new_flags
& elfcpp::EF_MIPS_ARCH_ASE
)
9459 != (old_flags
& elfcpp::EF_MIPS_ARCH_ASE
))
9461 int old_micro
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
9462 int new_micro
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
9463 int old_m16
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
9464 int new_m16
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
9465 int micro_mis
= old_m16
&& new_micro
;
9466 int m16_mis
= old_micro
&& new_m16
;
9468 if (m16_mis
|| micro_mis
)
9469 gold_error(_("%s: ASE mismatch: linking %s module with "
9470 "previous %s modules"), name
.c_str(),
9471 m16_mis
? "MIPS16" : "microMIPS",
9472 m16_mis
? "microMIPS" : "MIPS16");
9474 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ARCH_ASE
;
9476 new_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
9477 old_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
9480 // Compare NaN encodings.
9481 if ((new_flags
& elfcpp::EF_MIPS_NAN2008
) != (old_flags
& elfcpp::EF_MIPS_NAN2008
))
9483 gold_error(_("%s: linking %s module with previous %s modules"),
9485 (new_flags
& elfcpp::EF_MIPS_NAN2008
9486 ? "-mnan=2008" : "-mnan=legacy"),
9487 (old_flags
& elfcpp::EF_MIPS_NAN2008
9488 ? "-mnan=2008" : "-mnan=legacy"));
9490 new_flags
&= ~elfcpp::EF_MIPS_NAN2008
;
9491 old_flags
&= ~elfcpp::EF_MIPS_NAN2008
;
9494 // Compare FP64 state.
9495 if ((new_flags
& elfcpp::EF_MIPS_FP64
) != (old_flags
& elfcpp::EF_MIPS_FP64
))
9497 gold_error(_("%s: linking %s module with previous %s modules"),
9499 (new_flags
& elfcpp::EF_MIPS_FP64
9500 ? "-mfp64" : "-mfp32"),
9501 (old_flags
& elfcpp::EF_MIPS_FP64
9502 ? "-mfp64" : "-mfp32"));
9504 new_flags
&= ~elfcpp::EF_MIPS_FP64
;
9505 old_flags
&= ~elfcpp::EF_MIPS_FP64
;
9508 // Warn about any other mismatches.
9509 if (new_flags
!= old_flags
)
9510 gold_error(_("%s: uses different e_flags (0x%x) fields than previous "
9511 "modules (0x%x)"), name
.c_str(), new_flags
, old_flags
);
9513 this->set_processor_specific_flags(merged_flags
);
9516 // Adjust ELF file header.
9518 template<int size
, bool big_endian
>
9520 Target_mips
<size
, big_endian
>::do_adjust_elf_header(
9521 unsigned char* view
,
9524 gold_assert(len
== elfcpp::Elf_sizes
<size
>::ehdr_size
);
9526 elfcpp::Ehdr
<size
, big_endian
> ehdr(view
);
9527 unsigned char e_ident
[elfcpp::EI_NIDENT
];
9528 elfcpp::Elf_Word flags
= this->processor_specific_flags();
9529 memcpy(e_ident
, ehdr
.get_e_ident(), elfcpp::EI_NIDENT
);
9531 unsigned char ei_abiversion
= 0;
9532 elfcpp::Elf_Half type
= ehdr
.get_e_type();
9533 if (type
== elfcpp::ET_EXEC
9534 && parameters
->options().copyreloc()
9535 && (flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
))
9536 == elfcpp::EF_MIPS_CPIC
)
9539 if (this->abiflags_
!= NULL
9540 && (this->abiflags_
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_64
9541 || this->abiflags_
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
))
9544 e_ident
[elfcpp::EI_ABIVERSION
] = ei_abiversion
;
9545 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
9546 oehdr
.put_e_ident(e_ident
);
9548 if (this->entry_symbol_is_compressed_
)
9549 oehdr
.put_e_entry(ehdr
.get_e_entry() + 1);
9552 // do_make_elf_object to override the same function in the base class.
9553 // We need to use a target-specific sub-class of
9554 // Sized_relobj_file<size, big_endian> to store Mips specific information.
9555 // Hence we need to have our own ELF object creation.
9557 template<int size
, bool big_endian
>
9559 Target_mips
<size
, big_endian
>::do_make_elf_object(
9560 const std::string
& name
,
9561 Input_file
* input_file
,
9562 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
9564 int et
= ehdr
.get_e_type();
9565 // ET_EXEC files are valid input for --just-symbols/-R,
9566 // and we treat them as relocatable objects.
9567 if (et
== elfcpp::ET_REL
9568 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
9570 Mips_relobj
<size
, big_endian
>* obj
=
9571 new Mips_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
9575 else if (et
== elfcpp::ET_DYN
)
9577 // TODO(sasa): Should we create Mips_dynobj?
9578 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
9582 gold_error(_("%s: unsupported ELF file type %d"),
9588 // Finalize the sections.
9590 template <int size
, bool big_endian
>
9592 Target_mips
<size
, big_endian
>::do_finalize_sections(Layout
* layout
,
9593 const Input_objects
* input_objects
,
9594 Symbol_table
* symtab
)
9596 // Add +1 to MIPS16 and microMIPS init_ and _fini symbols so that DT_INIT and
9597 // DT_FINI have correct values.
9598 Mips_symbol
<size
>* init
= static_cast<Mips_symbol
<size
>*>(
9599 symtab
->lookup(parameters
->options().init()));
9600 if (init
!= NULL
&& (init
->is_mips16() || init
->is_micromips()))
9601 init
->set_value(init
->value() | 1);
9602 Mips_symbol
<size
>* fini
= static_cast<Mips_symbol
<size
>*>(
9603 symtab
->lookup(parameters
->options().fini()));
9604 if (fini
!= NULL
&& (fini
->is_mips16() || fini
->is_micromips()))
9605 fini
->set_value(fini
->value() | 1);
9607 // Check whether the entry symbol is mips16 or micromips. This is needed to
9608 // adjust entry address in ELF header.
9609 Mips_symbol
<size
>* entry
=
9610 static_cast<Mips_symbol
<size
>*>(symtab
->lookup(this->entry_symbol_name()));
9611 this->entry_symbol_is_compressed_
= (entry
!= NULL
&& (entry
->is_mips16()
9612 || entry
->is_micromips()));
9614 if (!parameters
->doing_static_link()
9615 && (strcmp(parameters
->options().hash_style(), "gnu") == 0
9616 || strcmp(parameters
->options().hash_style(), "both") == 0))
9618 // .gnu.hash and the MIPS ABI require .dynsym to be sorted in different
9619 // ways. .gnu.hash needs symbols to be grouped by hash code whereas the
9620 // MIPS ABI requires a mapping between the GOT and the symbol table.
9621 gold_error(".gnu.hash is incompatible with the MIPS ABI");
9624 // Check whether the final section that was scanned has HI16 or GOT16
9625 // relocations without the corresponding LO16 part.
9626 if (this->got16_addends_
.size() > 0)
9627 gold_error("Can't find matching LO16 reloc");
9629 // Check for any mips16 stub sections that we can discard.
9630 if (!parameters
->options().relocatable())
9632 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9633 p
!= input_objects
->relobj_end();
9636 Mips_relobj
<size
, big_endian
>* object
=
9637 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
9638 object
->discard_mips16_stub_sections(symtab
);
9642 Valtype gprmask
= 0;
9643 Valtype cprmask1
= 0;
9644 Valtype cprmask2
= 0;
9645 Valtype cprmask3
= 0;
9646 Valtype cprmask4
= 0;
9647 bool has_reginfo_section
= false;
9649 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9650 p
!= input_objects
->relobj_end();
9653 Mips_relobj
<size
, big_endian
>* relobj
=
9654 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
9656 // Merge .reginfo contents of input objects.
9657 if (relobj
->has_reginfo_section())
9659 has_reginfo_section
= true;
9660 gprmask
|= relobj
->gprmask();
9661 cprmask1
|= relobj
->cprmask1();
9662 cprmask2
|= relobj
->cprmask2();
9663 cprmask3
|= relobj
->cprmask3();
9664 cprmask4
|= relobj
->cprmask4();
9667 Input_file::Format format
= relobj
->input_file()->format();
9668 if (format
!= Input_file::FORMAT_ELF
)
9671 // If all input sections will be discarded, don't use this object
9672 // file for merging processor specific flags.
9673 bool should_merge_processor_specific_flags
= false;
9675 for (unsigned int i
= 1; i
< relobj
->shnum(); ++i
)
9676 if (relobj
->output_section(i
) != NULL
)
9678 should_merge_processor_specific_flags
= true;
9682 if (!should_merge_processor_specific_flags
)
9685 // Merge processor specific flags.
9686 Mips_abiflags
<big_endian
> in_abiflags
;
9688 this->create_abiflags(relobj
, &in_abiflags
);
9689 this->merge_obj_e_flags(relobj
->name(),
9690 relobj
->processor_specific_flags());
9691 this->merge_obj_abiflags(relobj
->name(), &in_abiflags
);
9692 this->merge_obj_attributes(relobj
->name(),
9693 relobj
->attributes_section_data());
9696 // Create a .gnu.attributes section if we have merged any attributes
9698 if (this->attributes_section_data_
!= NULL
)
9700 Output_attributes_section_data
* attributes_section
=
9701 new Output_attributes_section_data(*this->attributes_section_data_
);
9702 layout
->add_output_section_data(".gnu.attributes",
9703 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
9704 attributes_section
, ORDER_INVALID
, false);
9707 // Create .MIPS.abiflags output section if there is an input section.
9708 if (this->has_abiflags_section_
)
9710 Mips_output_section_abiflags
<size
, big_endian
>* abiflags_section
=
9711 new Mips_output_section_abiflags
<size
, big_endian
>(*this->abiflags_
);
9713 Output_section
* os
=
9714 layout
->add_output_section_data(".MIPS.abiflags",
9715 elfcpp::SHT_MIPS_ABIFLAGS
,
9717 abiflags_section
, ORDER_INVALID
, false);
9719 if (!parameters
->options().relocatable() && os
!= NULL
)
9721 Output_segment
* abiflags_segment
=
9722 layout
->make_output_segment(elfcpp::PT_MIPS_ABIFLAGS
, elfcpp::PF_R
);
9723 abiflags_segment
->add_output_section_to_nonload(os
, elfcpp::PF_R
);
9727 if (has_reginfo_section
&& !parameters
->options().gc_sections())
9729 // Create .reginfo output section.
9730 Mips_output_section_reginfo
<size
, big_endian
>* reginfo_section
=
9731 new Mips_output_section_reginfo
<size
, big_endian
>(this, gprmask
,
9733 cprmask3
, cprmask4
);
9735 Output_section
* os
=
9736 layout
->add_output_section_data(".reginfo", elfcpp::SHT_MIPS_REGINFO
,
9737 elfcpp::SHF_ALLOC
, reginfo_section
,
9738 ORDER_INVALID
, false);
9740 if (!parameters
->options().relocatable() && os
!= NULL
)
9742 Output_segment
* reginfo_segment
=
9743 layout
->make_output_segment(elfcpp::PT_MIPS_REGINFO
,
9745 reginfo_segment
->add_output_section_to_nonload(os
, elfcpp::PF_R
);
9749 if (this->plt_
!= NULL
)
9751 // Set final PLT offsets for symbols.
9752 this->plt_section()->set_plt_offsets();
9754 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
9755 // Set STO_MICROMIPS flag if the output has microMIPS code, but only if
9756 // there are no standard PLT entries present.
9757 unsigned char nonvis
= 0;
9758 if (this->is_output_micromips()
9759 && !this->plt_section()->has_standard_entries())
9760 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
9761 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
9762 Symbol_table::PREDEFINED
,
9764 0, 0, elfcpp::STT_FUNC
,
9766 elfcpp::STV_DEFAULT
, nonvis
,
9770 if (this->mips_stubs_
!= NULL
)
9772 // Define _MIPS_STUBS_ at the start of the .MIPS.stubs section.
9773 unsigned char nonvis
= 0;
9774 if (this->is_output_micromips())
9775 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
9776 symtab
->define_in_output_data("_MIPS_STUBS_", NULL
,
9777 Symbol_table::PREDEFINED
,
9779 0, 0, elfcpp::STT_FUNC
,
9781 elfcpp::STV_DEFAULT
, nonvis
,
9785 if (!parameters
->options().relocatable() && !parameters
->doing_static_link())
9786 // In case there is no .got section, create one.
9787 this->got_section(symtab
, layout
);
9789 // Emit any relocs we saved in an attempt to avoid generating COPY
9791 if (this->copy_relocs_
.any_saved_relocs())
9792 this->copy_relocs_
.emit_mips(this->rel_dyn_section(layout
), symtab
, layout
,
9796 this->set_gp(layout
, symtab
);
9798 // Emit dynamic relocs.
9799 for (typename
std::vector
<Dyn_reloc
>::iterator p
= this->dyn_relocs_
.begin();
9800 p
!= this->dyn_relocs_
.end();
9802 p
->emit(this->rel_dyn_section(layout
), this->got_section(), symtab
);
9804 if (this->has_got_section())
9805 this->got_section()->lay_out_got(layout
, symtab
, input_objects
);
9807 if (this->mips_stubs_
!= NULL
)
9808 this->mips_stubs_
->set_needs_dynsym_value();
9810 // Check for functions that might need $25 to be valid on entry.
9811 // TODO(sasa): Can we do this without iterating over all symbols?
9812 typedef Symbol_visitor_check_symbols
<size
, big_endian
> Symbol_visitor
;
9813 symtab
->for_all_symbols
<size
, Symbol_visitor
>(Symbol_visitor(this, layout
,
9816 // Add NULL segment.
9817 if (!parameters
->options().relocatable())
9818 layout
->make_output_segment(elfcpp::PT_NULL
, 0);
9820 // Fill in some more dynamic tags.
9821 // TODO(sasa): Add more dynamic tags.
9822 const Reloc_section
* rel_plt
= (this->plt_
== NULL
9823 ? NULL
: this->plt_
->rel_plt());
9824 layout
->add_target_dynamic_tags(true, this->got_
, rel_plt
,
9825 this->rel_dyn_
, true, false);
9827 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
9829 && !parameters
->options().relocatable()
9830 && !parameters
->doing_static_link())
9833 // This element holds a 32-bit version id for the Runtime
9834 // Linker Interface. This will start at integer value 1.
9836 odyn
->add_constant(elfcpp::DT_MIPS_RLD_VERSION
, d_val
);
9839 d_val
= elfcpp::RHF_NOTPOT
;
9840 odyn
->add_constant(elfcpp::DT_MIPS_FLAGS
, d_val
);
9842 // Save layout for using when emitting custom dynamic tags.
9843 this->layout_
= layout
;
9845 // This member holds the base address of the segment.
9846 odyn
->add_custom(elfcpp::DT_MIPS_BASE_ADDRESS
);
9848 // This member holds the number of entries in the .dynsym section.
9849 odyn
->add_custom(elfcpp::DT_MIPS_SYMTABNO
);
9851 // This member holds the index of the first dynamic symbol
9852 // table entry that corresponds to an entry in the global offset table.
9853 odyn
->add_custom(elfcpp::DT_MIPS_GOTSYM
);
9855 // This member holds the number of local GOT entries.
9856 odyn
->add_constant(elfcpp::DT_MIPS_LOCAL_GOTNO
,
9857 this->got_
->get_local_gotno());
9859 if (this->plt_
!= NULL
)
9860 // DT_MIPS_PLTGOT dynamic tag
9861 odyn
->add_section_address(elfcpp::DT_MIPS_PLTGOT
, this->got_plt_
);
9863 if (!parameters
->options().shared())
9865 this->rld_map_
= new Output_data_zero_fill(size
/ 8, size
/ 8);
9867 layout
->add_output_section_data(".rld_map", elfcpp::SHT_PROGBITS
,
9868 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
9869 this->rld_map_
, ORDER_INVALID
, false);
9871 // __RLD_MAP will be filled in by the runtime loader to contain
9872 // a pointer to the _r_debug structure.
9873 Symbol
* rld_map
= symtab
->define_in_output_data("__RLD_MAP", NULL
,
9874 Symbol_table::PREDEFINED
,
9876 0, 0, elfcpp::STT_OBJECT
,
9878 elfcpp::STV_DEFAULT
, 0,
9881 if (!rld_map
->is_forced_local())
9882 rld_map
->set_needs_dynsym_entry();
9884 if (!parameters
->options().pie())
9885 // This member holds the absolute address of the debug pointer.
9886 odyn
->add_section_address(elfcpp::DT_MIPS_RLD_MAP
, this->rld_map_
);
9888 // This member holds the offset to the debug pointer,
9889 // relative to the address of the tag.
9890 odyn
->add_custom(elfcpp::DT_MIPS_RLD_MAP_REL
);
9895 // Get the custom dynamic tag value.
9896 template<int size
, bool big_endian
>
9898 Target_mips
<size
, big_endian
>::do_dynamic_tag_custom_value(elfcpp::DT tag
) const
9902 case elfcpp::DT_MIPS_BASE_ADDRESS
:
9904 // The base address of the segment.
9905 // At this point, the segment list has been sorted into final order,
9906 // so just return vaddr of the first readable PT_LOAD segment.
9907 Output_segment
* seg
=
9908 this->layout_
->find_output_segment(elfcpp::PT_LOAD
, elfcpp::PF_R
, 0);
9909 gold_assert(seg
!= NULL
);
9910 return seg
->vaddr();
9913 case elfcpp::DT_MIPS_SYMTABNO
:
9914 // The number of entries in the .dynsym section.
9915 return this->get_dt_mips_symtabno();
9917 case elfcpp::DT_MIPS_GOTSYM
:
9919 // The index of the first dynamic symbol table entry that corresponds
9920 // to an entry in the GOT.
9921 if (this->got_
->first_global_got_dynsym_index() != -1U)
9922 return this->got_
->first_global_got_dynsym_index();
9924 // In case if we don't have global GOT symbols we default to setting
9925 // DT_MIPS_GOTSYM to the same value as DT_MIPS_SYMTABNO.
9926 return this->get_dt_mips_symtabno();
9929 case elfcpp::DT_MIPS_RLD_MAP_REL
:
9931 // The MIPS_RLD_MAP_REL tag stores the offset to the debug pointer,
9932 // relative to the address of the tag.
9933 Output_data_dynamic
* const odyn
= this->layout_
->dynamic_data();
9934 unsigned int entry_offset
=
9935 odyn
->get_entry_offset(elfcpp::DT_MIPS_RLD_MAP_REL
);
9936 gold_assert(entry_offset
!= -1U);
9937 return this->rld_map_
->address() - (odyn
->address() + entry_offset
);
9940 gold_error(_("Unknown dynamic tag 0x%x"), (unsigned int)tag
);
9943 return (unsigned int)-1;
9946 // Relocate section data.
9948 template<int size
, bool big_endian
>
9950 Target_mips
<size
, big_endian
>::relocate_section(
9951 const Relocate_info
<size
, big_endian
>* relinfo
,
9952 unsigned int sh_type
,
9953 const unsigned char* prelocs
,
9955 Output_section
* output_section
,
9956 bool needs_special_offset_handling
,
9957 unsigned char* view
,
9958 Mips_address address
,
9959 section_size_type view_size
,
9960 const Reloc_symbol_changes
* reloc_symbol_changes
)
9962 typedef Target_mips
<size
, big_endian
> Mips
;
9963 typedef typename Target_mips
<size
, big_endian
>::Relocate Mips_relocate
;
9965 if (sh_type
== elfcpp::SHT_REL
)
9967 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
9970 gold::relocate_section
<size
, big_endian
, Mips
, Mips_relocate
,
9971 gold::Default_comdat_behavior
, Classify_reloc
>(
9977 needs_special_offset_handling
,
9981 reloc_symbol_changes
);
9983 else if (sh_type
== elfcpp::SHT_RELA
)
9985 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9988 gold::relocate_section
<size
, big_endian
, Mips
, Mips_relocate
,
9989 gold::Default_comdat_behavior
, Classify_reloc
>(
9995 needs_special_offset_handling
,
9999 reloc_symbol_changes
);
10003 // Return the size of a relocation while scanning during a relocatable
10007 mips_get_size_for_reloc(unsigned int r_type
, Relobj
* object
)
10011 case elfcpp::R_MIPS_NONE
:
10012 case elfcpp::R_MIPS_TLS_DTPMOD64
:
10013 case elfcpp::R_MIPS_TLS_DTPREL64
:
10014 case elfcpp::R_MIPS_TLS_TPREL64
:
10017 case elfcpp::R_MIPS_32
:
10018 case elfcpp::R_MIPS_TLS_DTPMOD32
:
10019 case elfcpp::R_MIPS_TLS_DTPREL32
:
10020 case elfcpp::R_MIPS_TLS_TPREL32
:
10021 case elfcpp::R_MIPS_REL32
:
10022 case elfcpp::R_MIPS_PC32
:
10023 case elfcpp::R_MIPS_GPREL32
:
10024 case elfcpp::R_MIPS_JALR
:
10025 case elfcpp::R_MIPS_EH
:
10028 case elfcpp::R_MIPS_16
:
10029 case elfcpp::R_MIPS_HI16
:
10030 case elfcpp::R_MIPS_LO16
:
10031 case elfcpp::R_MIPS_HIGHER
:
10032 case elfcpp::R_MIPS_HIGHEST
:
10033 case elfcpp::R_MIPS_GPREL16
:
10034 case elfcpp::R_MIPS16_HI16
:
10035 case elfcpp::R_MIPS16_LO16
:
10036 case elfcpp::R_MIPS_PC16
:
10037 case elfcpp::R_MIPS_PCHI16
:
10038 case elfcpp::R_MIPS_PCLO16
:
10039 case elfcpp::R_MIPS_GOT16
:
10040 case elfcpp::R_MIPS16_GOT16
:
10041 case elfcpp::R_MIPS_CALL16
:
10042 case elfcpp::R_MIPS16_CALL16
:
10043 case elfcpp::R_MIPS_GOT_HI16
:
10044 case elfcpp::R_MIPS_CALL_HI16
:
10045 case elfcpp::R_MIPS_GOT_LO16
:
10046 case elfcpp::R_MIPS_CALL_LO16
:
10047 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
10048 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
10049 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
10050 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
10051 case elfcpp::R_MIPS16_GPREL
:
10052 case elfcpp::R_MIPS_GOT_DISP
:
10053 case elfcpp::R_MIPS_LITERAL
:
10054 case elfcpp::R_MIPS_GOT_PAGE
:
10055 case elfcpp::R_MIPS_GOT_OFST
:
10056 case elfcpp::R_MIPS_TLS_GD
:
10057 case elfcpp::R_MIPS_TLS_LDM
:
10058 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10061 // These relocations are not byte sized
10062 case elfcpp::R_MIPS_26
:
10063 case elfcpp::R_MIPS16_26
:
10064 case elfcpp::R_MIPS_PC21_S2
:
10065 case elfcpp::R_MIPS_PC26_S2
:
10066 case elfcpp::R_MIPS_PC18_S3
:
10067 case elfcpp::R_MIPS_PC19_S2
:
10070 case elfcpp::R_MIPS_COPY
:
10071 case elfcpp::R_MIPS_JUMP_SLOT
:
10072 object
->error(_("unexpected reloc %u in object file"), r_type
);
10076 object
->error(_("unsupported reloc %u in object file"), r_type
);
10081 // Scan the relocs during a relocatable link.
10083 template<int size
, bool big_endian
>
10085 Target_mips
<size
, big_endian
>::scan_relocatable_relocs(
10086 Symbol_table
* symtab
,
10088 Sized_relobj_file
<size
, big_endian
>* object
,
10089 unsigned int data_shndx
,
10090 unsigned int sh_type
,
10091 const unsigned char* prelocs
,
10092 size_t reloc_count
,
10093 Output_section
* output_section
,
10094 bool needs_special_offset_handling
,
10095 size_t local_symbol_count
,
10096 const unsigned char* plocal_symbols
,
10097 Relocatable_relocs
* rr
)
10099 if (sh_type
== elfcpp::SHT_REL
)
10101 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
10103 typedef Mips_scan_relocatable_relocs
<big_endian
, Classify_reloc
>
10104 Scan_relocatable_relocs
;
10106 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_relocatable_relocs
>(
10114 needs_special_offset_handling
,
10115 local_symbol_count
,
10119 else if (sh_type
== elfcpp::SHT_RELA
)
10121 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
10123 typedef Mips_scan_relocatable_relocs
<big_endian
, Classify_reloc
>
10124 Scan_relocatable_relocs
;
10126 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_relocatable_relocs
>(
10134 needs_special_offset_handling
,
10135 local_symbol_count
,
10140 gold_unreachable();
10143 // Scan the relocs for --emit-relocs.
10145 template<int size
, bool big_endian
>
10147 Target_mips
<size
, big_endian
>::emit_relocs_scan(
10148 Symbol_table
* symtab
,
10150 Sized_relobj_file
<size
, big_endian
>* object
,
10151 unsigned int data_shndx
,
10152 unsigned int sh_type
,
10153 const unsigned char* prelocs
,
10154 size_t reloc_count
,
10155 Output_section
* output_section
,
10156 bool needs_special_offset_handling
,
10157 size_t local_symbol_count
,
10158 const unsigned char* plocal_syms
,
10159 Relocatable_relocs
* rr
)
10161 if (sh_type
== elfcpp::SHT_REL
)
10163 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
10165 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
10166 Emit_relocs_strategy
;
10168 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
10176 needs_special_offset_handling
,
10177 local_symbol_count
,
10181 else if (sh_type
== elfcpp::SHT_RELA
)
10183 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
10185 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
10186 Emit_relocs_strategy
;
10188 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
10196 needs_special_offset_handling
,
10197 local_symbol_count
,
10202 gold_unreachable();
10205 // Emit relocations for a section.
10207 template<int size
, bool big_endian
>
10209 Target_mips
<size
, big_endian
>::relocate_relocs(
10210 const Relocate_info
<size
, big_endian
>* relinfo
,
10211 unsigned int sh_type
,
10212 const unsigned char* prelocs
,
10213 size_t reloc_count
,
10214 Output_section
* output_section
,
10215 typename
elfcpp::Elf_types
<size
>::Elf_Off
10216 offset_in_output_section
,
10217 unsigned char* view
,
10218 Mips_address view_address
,
10219 section_size_type view_size
,
10220 unsigned char* reloc_view
,
10221 section_size_type reloc_view_size
)
10223 if (sh_type
== elfcpp::SHT_REL
)
10225 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
10228 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
10233 offset_in_output_section
,
10240 else if (sh_type
== elfcpp::SHT_RELA
)
10242 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
10245 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
10250 offset_in_output_section
,
10258 gold_unreachable();
10261 // Perform target-specific processing in a relocatable link. This is
10262 // only used if we use the relocation strategy RELOC_SPECIAL.
10264 template<int size
, bool big_endian
>
10266 Target_mips
<size
, big_endian
>::relocate_special_relocatable(
10267 const Relocate_info
<size
, big_endian
>* relinfo
,
10268 unsigned int sh_type
,
10269 const unsigned char* preloc_in
,
10271 Output_section
* output_section
,
10272 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
10273 unsigned char* view
,
10274 Mips_address view_address
,
10276 unsigned char* preloc_out
)
10278 // We can only handle REL type relocation sections.
10279 gold_assert(sh_type
== elfcpp::SHT_REL
);
10281 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
10283 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc_write
10286 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
10288 const Mips_address invalid_address
= static_cast<Mips_address
>(0) - 1;
10290 Mips_relobj
<size
, big_endian
>* object
=
10291 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
10292 const unsigned int local_count
= object
->local_symbol_count();
10294 Reltype
reloc(preloc_in
);
10295 Reltype_write
reloc_write(preloc_out
);
10297 elfcpp::Elf_types
<32>::Elf_WXword r_info
= reloc
.get_r_info();
10298 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
10299 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
10301 // Get the new symbol index.
10302 // We only use RELOC_SPECIAL strategy in local relocations.
10303 gold_assert(r_sym
< local_count
);
10305 // We are adjusting a section symbol. We need to find
10306 // the symbol table index of the section symbol for
10307 // the output section corresponding to input section
10308 // in which this symbol is defined.
10310 unsigned int shndx
= object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
10311 gold_assert(is_ordinary
);
10312 Output_section
* os
= object
->output_section(shndx
);
10313 gold_assert(os
!= NULL
);
10314 gold_assert(os
->needs_symtab_index());
10315 unsigned int new_symndx
= os
->symtab_index();
10317 // Get the new offset--the location in the output section where
10318 // this relocation should be applied.
10320 Mips_address offset
= reloc
.get_r_offset();
10321 Mips_address new_offset
;
10322 if (offset_in_output_section
!= invalid_address
)
10323 new_offset
= offset
+ offset_in_output_section
;
10326 section_offset_type sot_offset
=
10327 convert_types
<section_offset_type
, Mips_address
>(offset
);
10328 section_offset_type new_sot_offset
=
10329 output_section
->output_offset(object
, relinfo
->data_shndx
,
10331 gold_assert(new_sot_offset
!= -1);
10332 new_offset
= new_sot_offset
;
10335 // In an object file, r_offset is an offset within the section.
10336 // In an executable or dynamic object, generated by
10337 // --emit-relocs, r_offset is an absolute address.
10338 if (!parameters
->options().relocatable())
10340 new_offset
+= view_address
;
10341 if (offset_in_output_section
!= invalid_address
)
10342 new_offset
-= offset_in_output_section
;
10345 reloc_write
.put_r_offset(new_offset
);
10346 reloc_write
.put_r_info(elfcpp::elf_r_info
<32>(new_symndx
, r_type
));
10348 // Handle the reloc addend.
10349 // The relocation uses a section symbol in the input file.
10350 // We are adjusting it to use a section symbol in the output
10351 // file. The input section symbol refers to some address in
10352 // the input section. We need the relocation in the output
10353 // file to refer to that same address. This adjustment to
10354 // the addend is the same calculation we use for a simple
10355 // absolute relocation for the input section symbol.
10356 Valtype calculated_value
= 0;
10357 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
10359 unsigned char* paddend
= view
+ offset
;
10360 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
10363 case elfcpp::R_MIPS_26
:
10364 reloc_status
= Reloc_funcs::rel26(paddend
, object
, psymval
,
10365 offset_in_output_section
, true, 0, sh_type
== elfcpp::SHT_REL
, NULL
,
10366 false /*TODO(sasa): cross mode jump*/, r_type
, this->jal_to_bal(),
10367 false, &calculated_value
);
10371 gold_unreachable();
10374 // Report any errors.
10375 switch (reloc_status
)
10377 case Reloc_funcs::STATUS_OKAY
:
10379 case Reloc_funcs::STATUS_OVERFLOW
:
10380 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
10381 _("relocation overflow: "
10382 "%u against local symbol %u in %s"),
10383 r_type
, r_sym
, object
->name().c_str());
10385 case Reloc_funcs::STATUS_BAD_RELOC
:
10386 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
10387 _("unexpected opcode while processing relocation"));
10390 gold_unreachable();
10394 // Optimize the TLS relocation type based on what we know about the
10395 // symbol. IS_FINAL is true if the final address of this symbol is
10396 // known at link time.
10398 template<int size
, bool big_endian
>
10399 tls::Tls_optimization
10400 Target_mips
<size
, big_endian
>::optimize_tls_reloc(bool, int)
10402 // FIXME: Currently we do not do any TLS optimization.
10403 return tls::TLSOPT_NONE
;
10406 // Scan a relocation for a local symbol.
10408 template<int size
, bool big_endian
>
10410 Target_mips
<size
, big_endian
>::Scan::local(
10411 Symbol_table
* symtab
,
10413 Target_mips
<size
, big_endian
>* target
,
10414 Sized_relobj_file
<size
, big_endian
>* object
,
10415 unsigned int data_shndx
,
10416 Output_section
* output_section
,
10417 const Relatype
* rela
,
10418 const Reltype
* rel
,
10419 unsigned int rel_type
,
10420 unsigned int r_type
,
10421 const elfcpp::Sym
<size
, big_endian
>& lsym
,
10427 Mips_address r_offset
;
10428 unsigned int r_sym
;
10429 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
10431 if (rel_type
== elfcpp::SHT_RELA
)
10433 r_offset
= rela
->get_r_offset();
10434 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10436 r_addend
= rela
->get_r_addend();
10440 r_offset
= rel
->get_r_offset();
10441 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
10446 Mips_relobj
<size
, big_endian
>* mips_obj
=
10447 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
10449 if (mips_obj
->is_mips16_stub_section(data_shndx
))
10451 mips_obj
->get_mips16_stub_section(data_shndx
)
10452 ->new_local_reloc_found(r_type
, r_sym
);
10455 if (r_type
== elfcpp::R_MIPS_NONE
)
10456 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
10460 if (!mips16_call_reloc(r_type
)
10461 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
10462 // This reloc would need to refer to a MIPS16 hard-float stub, if
10463 // there is one. We ignore MIPS16 stub sections and .pdr section when
10464 // looking for relocs that would need to refer to MIPS16 stubs.
10465 mips_obj
->add_local_non_16bit_call(r_sym
);
10467 if (r_type
== elfcpp::R_MIPS16_26
10468 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
10469 mips_obj
->add_local_16bit_call(r_sym
);
10473 case elfcpp::R_MIPS_GOT16
:
10474 case elfcpp::R_MIPS_CALL16
:
10475 case elfcpp::R_MIPS_CALL_HI16
:
10476 case elfcpp::R_MIPS_CALL_LO16
:
10477 case elfcpp::R_MIPS_GOT_HI16
:
10478 case elfcpp::R_MIPS_GOT_LO16
:
10479 case elfcpp::R_MIPS_GOT_PAGE
:
10480 case elfcpp::R_MIPS_GOT_OFST
:
10481 case elfcpp::R_MIPS_GOT_DISP
:
10482 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10483 case elfcpp::R_MIPS_TLS_GD
:
10484 case elfcpp::R_MIPS_TLS_LDM
:
10485 case elfcpp::R_MIPS16_GOT16
:
10486 case elfcpp::R_MIPS16_CALL16
:
10487 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10488 case elfcpp::R_MIPS16_TLS_GD
:
10489 case elfcpp::R_MIPS16_TLS_LDM
:
10490 case elfcpp::R_MICROMIPS_GOT16
:
10491 case elfcpp::R_MICROMIPS_CALL16
:
10492 case elfcpp::R_MICROMIPS_CALL_HI16
:
10493 case elfcpp::R_MICROMIPS_CALL_LO16
:
10494 case elfcpp::R_MICROMIPS_GOT_HI16
:
10495 case elfcpp::R_MICROMIPS_GOT_LO16
:
10496 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10497 case elfcpp::R_MICROMIPS_GOT_OFST
:
10498 case elfcpp::R_MICROMIPS_GOT_DISP
:
10499 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10500 case elfcpp::R_MICROMIPS_TLS_GD
:
10501 case elfcpp::R_MICROMIPS_TLS_LDM
:
10502 case elfcpp::R_MIPS_EH
:
10503 // We need a GOT section.
10504 target
->got_section(symtab
, layout
);
10511 if (call_lo16_reloc(r_type
)
10512 || got_lo16_reloc(r_type
)
10513 || got_disp_reloc(r_type
)
10514 || eh_reloc(r_type
))
10516 // We may need a local GOT entry for this relocation. We
10517 // don't count R_MIPS_GOT_PAGE because we can estimate the
10518 // maximum number of pages needed by looking at the size of
10519 // the segment. Similar comments apply to R_MIPS*_GOT16 and
10520 // R_MIPS*_CALL16. We don't count R_MIPS_GOT_HI16, or
10521 // R_MIPS_CALL_HI16 because these are always followed by an
10522 // R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
10523 Mips_output_data_got
<size
, big_endian
>* got
=
10524 target
->got_section(symtab
, layout
);
10525 bool is_section_symbol
= lsym
.get_st_type() == elfcpp::STT_SECTION
;
10526 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
, -1U,
10527 is_section_symbol
);
10532 case elfcpp::R_MIPS_CALL16
:
10533 case elfcpp::R_MIPS16_CALL16
:
10534 case elfcpp::R_MICROMIPS_CALL16
:
10535 gold_error(_("CALL16 reloc at 0x%lx not against global symbol "),
10536 (unsigned long)r_offset
);
10539 case elfcpp::R_MIPS_GOT_PAGE
:
10540 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10541 case elfcpp::R_MIPS16_GOT16
:
10542 case elfcpp::R_MIPS_GOT16
:
10543 case elfcpp::R_MIPS_GOT_HI16
:
10544 case elfcpp::R_MIPS_GOT_LO16
:
10545 case elfcpp::R_MICROMIPS_GOT16
:
10546 case elfcpp::R_MICROMIPS_GOT_HI16
:
10547 case elfcpp::R_MICROMIPS_GOT_LO16
:
10549 // This relocation needs a page entry in the GOT.
10550 // Get the section contents.
10551 section_size_type view_size
= 0;
10552 const unsigned char* view
= object
->section_contents(data_shndx
,
10553 &view_size
, false);
10556 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
10557 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
10560 if (rel_type
== elfcpp::SHT_REL
&& got16_reloc(r_type
))
10561 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
10562 object
, data_shndx
, r_type
, r_sym
, addend
));
10564 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
, addend
);
10568 case elfcpp::R_MIPS_HI16
:
10569 case elfcpp::R_MIPS_PCHI16
:
10570 case elfcpp::R_MIPS16_HI16
:
10571 case elfcpp::R_MICROMIPS_HI16
:
10572 // Record the reloc so that we can check whether the corresponding LO16
10574 if (rel_type
== elfcpp::SHT_REL
)
10575 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
10576 object
, data_shndx
, r_type
, r_sym
, 0));
10579 case elfcpp::R_MIPS_LO16
:
10580 case elfcpp::R_MIPS_PCLO16
:
10581 case elfcpp::R_MIPS16_LO16
:
10582 case elfcpp::R_MICROMIPS_LO16
:
10584 if (rel_type
!= elfcpp::SHT_REL
)
10587 // Find corresponding GOT16/HI16 relocation.
10589 // According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
10590 // be immediately following. However, for the IRIX6 ABI, the next
10591 // relocation may be a composed relocation consisting of several
10592 // relocations for the same address. In that case, the R_MIPS_LO16
10593 // relocation may occur as one of these. We permit a similar
10594 // extension in general, as that is useful for GCC.
10596 // In some cases GCC dead code elimination removes the LO16 but
10597 // keeps the corresponding HI16. This is strictly speaking a
10598 // violation of the ABI but not immediately harmful.
10600 typename
std::list
<got16_addend
<size
, big_endian
> >::iterator it
=
10601 target
->got16_addends_
.begin();
10602 while (it
!= target
->got16_addends_
.end())
10604 got16_addend
<size
, big_endian
> _got16_addend
= *it
;
10606 // TODO(sasa): Split got16_addends_ list into two lists - one for
10607 // GOT16 relocs and the other for HI16 relocs.
10609 // Report an error if we find HI16 or GOT16 reloc from the
10610 // previous section without the matching LO16 part.
10611 if (_got16_addend
.object
!= object
10612 || _got16_addend
.shndx
!= data_shndx
)
10614 gold_error("Can't find matching LO16 reloc");
10618 if (_got16_addend
.r_sym
!= r_sym
10619 || !is_matching_lo16_reloc(_got16_addend
.r_type
, r_type
))
10625 // We found a matching HI16 or GOT16 reloc for this LO16 reloc.
10626 // For GOT16, we need to calculate combined addend and record GOT page
10628 if (got16_reloc(_got16_addend
.r_type
))
10631 section_size_type view_size
= 0;
10632 const unsigned char* view
= object
->section_contents(data_shndx
,
10637 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
10638 int32_t addend
= Bits
<16>::sign_extend32(val
& 0xffff);
10640 addend
= (_got16_addend
.addend
<< 16) + addend
;
10641 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
,
10645 it
= target
->got16_addends_
.erase(it
);
10653 case elfcpp::R_MIPS_32
:
10654 case elfcpp::R_MIPS_REL32
:
10655 case elfcpp::R_MIPS_64
:
10657 if (parameters
->options().output_is_position_independent())
10659 // If building a shared library (or a position-independent
10660 // executable), we need to create a dynamic relocation for
10662 if (is_readonly_section(output_section
))
10664 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
10665 rel_dyn
->add_symbolless_local_addend(object
, r_sym
,
10666 elfcpp::R_MIPS_REL32
,
10667 output_section
, data_shndx
,
10673 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10674 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10675 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10676 case elfcpp::R_MIPS_TLS_LDM
:
10677 case elfcpp::R_MIPS16_TLS_LDM
:
10678 case elfcpp::R_MICROMIPS_TLS_LDM
:
10679 case elfcpp::R_MIPS_TLS_GD
:
10680 case elfcpp::R_MIPS16_TLS_GD
:
10681 case elfcpp::R_MICROMIPS_TLS_GD
:
10683 bool output_is_shared
= parameters
->options().shared();
10684 const tls::Tls_optimization optimized_type
10685 = Target_mips
<size
, big_endian
>::optimize_tls_reloc(
10686 !output_is_shared
, r_type
);
10689 case elfcpp::R_MIPS_TLS_GD
:
10690 case elfcpp::R_MIPS16_TLS_GD
:
10691 case elfcpp::R_MICROMIPS_TLS_GD
:
10692 if (optimized_type
== tls::TLSOPT_NONE
)
10694 // Create a pair of GOT entries for the module index and
10695 // dtv-relative offset.
10696 Mips_output_data_got
<size
, big_endian
>* got
=
10697 target
->got_section(symtab
, layout
);
10698 unsigned int shndx
= lsym
.get_st_shndx();
10700 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
10703 object
->error(_("local symbol %u has bad shndx %u"),
10707 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
10712 // FIXME: TLS optimization not supported yet.
10713 gold_unreachable();
10717 case elfcpp::R_MIPS_TLS_LDM
:
10718 case elfcpp::R_MIPS16_TLS_LDM
:
10719 case elfcpp::R_MICROMIPS_TLS_LDM
:
10720 if (optimized_type
== tls::TLSOPT_NONE
)
10722 // We always record LDM symbols as local with index 0.
10723 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
10729 // FIXME: TLS optimization not supported yet.
10730 gold_unreachable();
10733 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10734 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10735 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10736 layout
->set_has_static_tls();
10737 if (optimized_type
== tls::TLSOPT_NONE
)
10739 // Create a GOT entry for the tp-relative offset.
10740 Mips_output_data_got
<size
, big_endian
>* got
=
10741 target
->got_section(symtab
, layout
);
10742 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
10747 // FIXME: TLS optimization not supported yet.
10748 gold_unreachable();
10753 gold_unreachable();
10762 // Refuse some position-dependent relocations when creating a
10763 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
10764 // not PIC, but we can create dynamic relocations and the result
10765 // will be fine. Also do not refuse R_MIPS_LO16, which can be
10766 // combined with R_MIPS_GOT16.
10767 if (parameters
->options().shared())
10771 case elfcpp::R_MIPS16_HI16
:
10772 case elfcpp::R_MIPS_HI16
:
10773 case elfcpp::R_MIPS_HIGHER
:
10774 case elfcpp::R_MIPS_HIGHEST
:
10775 case elfcpp::R_MICROMIPS_HI16
:
10776 case elfcpp::R_MICROMIPS_HIGHER
:
10777 case elfcpp::R_MICROMIPS_HIGHEST
:
10778 // Don't refuse a high part relocation if it's against
10779 // no symbol (e.g. part of a compound relocation).
10784 case elfcpp::R_MIPS16_26
:
10785 case elfcpp::R_MIPS_26
:
10786 case elfcpp::R_MICROMIPS_26_S1
:
10787 gold_error(_("%s: relocation %u against `%s' can not be used when "
10788 "making a shared object; recompile with -fPIC"),
10789 object
->name().c_str(), r_type
, "a local symbol");
10796 template<int size
, bool big_endian
>
10798 Target_mips
<size
, big_endian
>::Scan::local(
10799 Symbol_table
* symtab
,
10801 Target_mips
<size
, big_endian
>* target
,
10802 Sized_relobj_file
<size
, big_endian
>* object
,
10803 unsigned int data_shndx
,
10804 Output_section
* output_section
,
10805 const Reltype
& reloc
,
10806 unsigned int r_type
,
10807 const elfcpp::Sym
<size
, big_endian
>& lsym
,
10820 (const Relatype
*) NULL
,
10824 lsym
, is_discarded
);
10828 template<int size
, bool big_endian
>
10830 Target_mips
<size
, big_endian
>::Scan::local(
10831 Symbol_table
* symtab
,
10833 Target_mips
<size
, big_endian
>* target
,
10834 Sized_relobj_file
<size
, big_endian
>* object
,
10835 unsigned int data_shndx
,
10836 Output_section
* output_section
,
10837 const Relatype
& reloc
,
10838 unsigned int r_type
,
10839 const elfcpp::Sym
<size
, big_endian
>& lsym
,
10853 (const Reltype
*) NULL
,
10856 lsym
, is_discarded
);
10859 // Scan a relocation for a global symbol.
10861 template<int size
, bool big_endian
>
10863 Target_mips
<size
, big_endian
>::Scan::global(
10864 Symbol_table
* symtab
,
10866 Target_mips
<size
, big_endian
>* target
,
10867 Sized_relobj_file
<size
, big_endian
>* object
,
10868 unsigned int data_shndx
,
10869 Output_section
* output_section
,
10870 const Relatype
* rela
,
10871 const Reltype
* rel
,
10872 unsigned int rel_type
,
10873 unsigned int r_type
,
10876 Mips_address r_offset
;
10877 unsigned int r_sym
;
10878 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
10880 if (rel_type
== elfcpp::SHT_RELA
)
10882 r_offset
= rela
->get_r_offset();
10883 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10885 r_addend
= rela
->get_r_addend();
10889 r_offset
= rel
->get_r_offset();
10890 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
10895 Mips_relobj
<size
, big_endian
>* mips_obj
=
10896 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
10897 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
10899 if (mips_obj
->is_mips16_stub_section(data_shndx
))
10901 mips_obj
->get_mips16_stub_section(data_shndx
)
10902 ->new_global_reloc_found(r_type
, mips_sym
);
10905 if (r_type
== elfcpp::R_MIPS_NONE
)
10906 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
10910 if (!mips16_call_reloc(r_type
)
10911 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
10912 // This reloc would need to refer to a MIPS16 hard-float stub, if
10913 // there is one. We ignore MIPS16 stub sections and .pdr section when
10914 // looking for relocs that would need to refer to MIPS16 stubs.
10915 mips_sym
->set_need_fn_stub();
10917 // We need PLT entries if there are static-only relocations against
10918 // an externally-defined function. This can technically occur for
10919 // shared libraries if there are branches to the symbol, although it
10920 // is unlikely that this will be used in practice due to the short
10921 // ranges involved. It can occur for any relative or absolute relocation
10922 // in executables; in that case, the PLT entry becomes the function's
10923 // canonical address.
10924 bool static_reloc
= false;
10926 // Set CAN_MAKE_DYNAMIC to true if we can convert this
10927 // relocation into a dynamic one.
10928 bool can_make_dynamic
= false;
10931 case elfcpp::R_MIPS_GOT16
:
10932 case elfcpp::R_MIPS_CALL16
:
10933 case elfcpp::R_MIPS_CALL_HI16
:
10934 case elfcpp::R_MIPS_CALL_LO16
:
10935 case elfcpp::R_MIPS_GOT_HI16
:
10936 case elfcpp::R_MIPS_GOT_LO16
:
10937 case elfcpp::R_MIPS_GOT_PAGE
:
10938 case elfcpp::R_MIPS_GOT_OFST
:
10939 case elfcpp::R_MIPS_GOT_DISP
:
10940 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10941 case elfcpp::R_MIPS_TLS_GD
:
10942 case elfcpp::R_MIPS_TLS_LDM
:
10943 case elfcpp::R_MIPS16_GOT16
:
10944 case elfcpp::R_MIPS16_CALL16
:
10945 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10946 case elfcpp::R_MIPS16_TLS_GD
:
10947 case elfcpp::R_MIPS16_TLS_LDM
:
10948 case elfcpp::R_MICROMIPS_GOT16
:
10949 case elfcpp::R_MICROMIPS_CALL16
:
10950 case elfcpp::R_MICROMIPS_CALL_HI16
:
10951 case elfcpp::R_MICROMIPS_CALL_LO16
:
10952 case elfcpp::R_MICROMIPS_GOT_HI16
:
10953 case elfcpp::R_MICROMIPS_GOT_LO16
:
10954 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10955 case elfcpp::R_MICROMIPS_GOT_OFST
:
10956 case elfcpp::R_MICROMIPS_GOT_DISP
:
10957 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10958 case elfcpp::R_MICROMIPS_TLS_GD
:
10959 case elfcpp::R_MICROMIPS_TLS_LDM
:
10960 case elfcpp::R_MIPS_EH
:
10961 // We need a GOT section.
10962 target
->got_section(symtab
, layout
);
10965 // This is just a hint; it can safely be ignored. Don't set
10966 // has_static_relocs for the corresponding symbol.
10967 case elfcpp::R_MIPS_JALR
:
10968 case elfcpp::R_MICROMIPS_JALR
:
10971 case elfcpp::R_MIPS_GPREL16
:
10972 case elfcpp::R_MIPS_GPREL32
:
10973 case elfcpp::R_MIPS16_GPREL
:
10974 case elfcpp::R_MICROMIPS_GPREL16
:
10976 // GP-relative relocations always resolve to a definition in a
10977 // regular input file, ignoring the one-definition rule. This is
10978 // important for the GP setup sequence in NewABI code, which
10979 // always resolves to a local function even if other relocations
10980 // against the symbol wouldn't.
10981 //constrain_symbol_p = FALSE;
10984 case elfcpp::R_MIPS_32
:
10985 case elfcpp::R_MIPS_REL32
:
10986 case elfcpp::R_MIPS_64
:
10987 if ((parameters
->options().shared()
10988 || (strcmp(gsym
->name(), "__gnu_local_gp") != 0
10989 && (!is_readonly_section(output_section
)
10990 || mips_obj
->is_pic())))
10991 && (output_section
->flags() & elfcpp::SHF_ALLOC
) != 0)
10993 if (r_type
!= elfcpp::R_MIPS_REL32
)
10994 mips_sym
->set_pointer_equality_needed();
10995 can_make_dynamic
= true;
11001 // Most static relocations require pointer equality, except
11003 mips_sym
->set_pointer_equality_needed();
11006 case elfcpp::R_MIPS_26
:
11007 case elfcpp::R_MIPS_PC16
:
11008 case elfcpp::R_MIPS_PC21_S2
:
11009 case elfcpp::R_MIPS_PC26_S2
:
11010 case elfcpp::R_MIPS16_26
:
11011 case elfcpp::R_MICROMIPS_26_S1
:
11012 case elfcpp::R_MICROMIPS_PC7_S1
:
11013 case elfcpp::R_MICROMIPS_PC10_S1
:
11014 case elfcpp::R_MICROMIPS_PC16_S1
:
11015 case elfcpp::R_MICROMIPS_PC23_S2
:
11016 static_reloc
= true;
11017 mips_sym
->set_has_static_relocs();
11021 // If there are call relocations against an externally-defined symbol,
11022 // see whether we can create a MIPS lazy-binding stub for it. We can
11023 // only do this if all references to the function are through call
11024 // relocations, and in that case, the traditional lazy-binding stubs
11025 // are much more efficient than PLT entries.
11028 case elfcpp::R_MIPS16_CALL16
:
11029 case elfcpp::R_MIPS_CALL16
:
11030 case elfcpp::R_MIPS_CALL_HI16
:
11031 case elfcpp::R_MIPS_CALL_LO16
:
11032 case elfcpp::R_MIPS_JALR
:
11033 case elfcpp::R_MICROMIPS_CALL16
:
11034 case elfcpp::R_MICROMIPS_CALL_HI16
:
11035 case elfcpp::R_MICROMIPS_CALL_LO16
:
11036 case elfcpp::R_MICROMIPS_JALR
:
11037 if (!mips_sym
->no_lazy_stub())
11039 if ((mips_sym
->needs_plt_entry() && mips_sym
->is_from_dynobj())
11040 // Calls from shared objects to undefined symbols of type
11041 // STT_NOTYPE need lazy-binding stub.
11042 || (mips_sym
->is_undefined() && parameters
->options().shared()))
11043 target
->mips_stubs_section(layout
)->make_entry(mips_sym
);
11048 // We must not create a stub for a symbol that has relocations
11049 // related to taking the function's address.
11050 mips_sym
->set_no_lazy_stub();
11051 target
->remove_lazy_stub_entry(mips_sym
);
11056 if (relocation_needs_la25_stub
<size
, big_endian
>(mips_obj
, r_type
,
11057 mips_sym
->is_mips16()))
11058 mips_sym
->set_has_nonpic_branches();
11060 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
11061 // and has a special meaning.
11062 bool gp_disp_against_hi16
= (!mips_obj
->is_newabi()
11063 && strcmp(gsym
->name(), "_gp_disp") == 0
11064 && (hi16_reloc(r_type
) || lo16_reloc(r_type
)));
11065 if (static_reloc
&& gsym
->needs_plt_entry())
11067 target
->make_plt_entry(symtab
, layout
, mips_sym
, r_type
);
11069 // Since this is not a PC-relative relocation, we may be
11070 // taking the address of a function. In that case we need to
11071 // set the entry in the dynamic symbol table to the address of
11073 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
11075 gsym
->set_needs_dynsym_value();
11076 // We distinguish between PLT entries and lazy-binding stubs by
11077 // giving the former an st_other value of STO_MIPS_PLT. Set the
11078 // flag if there are any relocations in the binary where pointer
11079 // equality matters.
11080 if (mips_sym
->pointer_equality_needed())
11081 mips_sym
->set_mips_plt();
11084 if ((static_reloc
|| can_make_dynamic
) && !gp_disp_against_hi16
)
11086 // Absolute addressing relocations.
11087 // Make a dynamic relocation if necessary.
11088 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
11090 if (gsym
->may_need_copy_reloc())
11092 target
->copy_reloc(symtab
, layout
, object
, data_shndx
,
11093 output_section
, gsym
, r_type
, r_offset
);
11095 else if (can_make_dynamic
)
11097 // Create .rel.dyn section.
11098 target
->rel_dyn_section(layout
);
11099 target
->dynamic_reloc(mips_sym
, elfcpp::R_MIPS_REL32
, mips_obj
,
11100 data_shndx
, output_section
, r_offset
);
11103 gold_error(_("non-dynamic relocations refer to dynamic symbol %s"),
11108 bool for_call
= false;
11111 case elfcpp::R_MIPS_CALL16
:
11112 case elfcpp::R_MIPS16_CALL16
:
11113 case elfcpp::R_MICROMIPS_CALL16
:
11114 case elfcpp::R_MIPS_CALL_HI16
:
11115 case elfcpp::R_MIPS_CALL_LO16
:
11116 case elfcpp::R_MICROMIPS_CALL_HI16
:
11117 case elfcpp::R_MICROMIPS_CALL_LO16
:
11121 case elfcpp::R_MIPS16_GOT16
:
11122 case elfcpp::R_MIPS_GOT16
:
11123 case elfcpp::R_MIPS_GOT_HI16
:
11124 case elfcpp::R_MIPS_GOT_LO16
:
11125 case elfcpp::R_MICROMIPS_GOT16
:
11126 case elfcpp::R_MICROMIPS_GOT_HI16
:
11127 case elfcpp::R_MICROMIPS_GOT_LO16
:
11128 case elfcpp::R_MIPS_GOT_DISP
:
11129 case elfcpp::R_MICROMIPS_GOT_DISP
:
11130 case elfcpp::R_MIPS_EH
:
11132 // The symbol requires a GOT entry.
11133 Mips_output_data_got
<size
, big_endian
>* got
=
11134 target
->got_section(symtab
, layout
);
11135 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
11137 mips_sym
->set_global_got_area(GGA_NORMAL
);
11141 case elfcpp::R_MIPS_GOT_PAGE
:
11142 case elfcpp::R_MICROMIPS_GOT_PAGE
:
11144 // This relocation needs a page entry in the GOT.
11145 // Get the section contents.
11146 section_size_type view_size
= 0;
11147 const unsigned char* view
=
11148 object
->section_contents(data_shndx
, &view_size
, false);
11151 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
11152 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
11154 Mips_output_data_got
<size
, big_endian
>* got
=
11155 target
->got_section(symtab
, layout
);
11156 got
->record_got_page_entry(mips_obj
, r_sym
, addend
);
11158 // If this is a global, overridable symbol, GOT_PAGE will
11159 // decay to GOT_DISP, so we'll need a GOT entry for it.
11160 bool def_regular
= (mips_sym
->source() == Symbol::FROM_OBJECT
11161 && !mips_sym
->object()->is_dynamic()
11162 && !mips_sym
->is_undefined());
11164 || (parameters
->options().output_is_position_independent()
11165 && !parameters
->options().Bsymbolic()
11166 && !mips_sym
->is_forced_local()))
11168 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
11170 mips_sym
->set_global_got_area(GGA_NORMAL
);
11175 case elfcpp::R_MIPS_TLS_GOTTPREL
:
11176 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
11177 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
11178 case elfcpp::R_MIPS_TLS_LDM
:
11179 case elfcpp::R_MIPS16_TLS_LDM
:
11180 case elfcpp::R_MICROMIPS_TLS_LDM
:
11181 case elfcpp::R_MIPS_TLS_GD
:
11182 case elfcpp::R_MIPS16_TLS_GD
:
11183 case elfcpp::R_MICROMIPS_TLS_GD
:
11185 const bool is_final
= gsym
->final_value_is_known();
11186 const tls::Tls_optimization optimized_type
=
11187 Target_mips
<size
, big_endian
>::optimize_tls_reloc(is_final
, r_type
);
11191 case elfcpp::R_MIPS_TLS_GD
:
11192 case elfcpp::R_MIPS16_TLS_GD
:
11193 case elfcpp::R_MICROMIPS_TLS_GD
:
11194 if (optimized_type
== tls::TLSOPT_NONE
)
11196 // Create a pair of GOT entries for the module index and
11197 // dtv-relative offset.
11198 Mips_output_data_got
<size
, big_endian
>* got
=
11199 target
->got_section(symtab
, layout
);
11200 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
11205 // FIXME: TLS optimization not supported yet.
11206 gold_unreachable();
11210 case elfcpp::R_MIPS_TLS_LDM
:
11211 case elfcpp::R_MIPS16_TLS_LDM
:
11212 case elfcpp::R_MICROMIPS_TLS_LDM
:
11213 if (optimized_type
== tls::TLSOPT_NONE
)
11215 // We always record LDM symbols as local with index 0.
11216 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
11222 // FIXME: TLS optimization not supported yet.
11223 gold_unreachable();
11226 case elfcpp::R_MIPS_TLS_GOTTPREL
:
11227 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
11228 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
11229 layout
->set_has_static_tls();
11230 if (optimized_type
== tls::TLSOPT_NONE
)
11232 // Create a GOT entry for the tp-relative offset.
11233 Mips_output_data_got
<size
, big_endian
>* got
=
11234 target
->got_section(symtab
, layout
);
11235 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
11240 // FIXME: TLS optimization not supported yet.
11241 gold_unreachable();
11246 gold_unreachable();
11250 case elfcpp::R_MIPS_COPY
:
11251 case elfcpp::R_MIPS_JUMP_SLOT
:
11252 // These are relocations which should only be seen by the
11253 // dynamic linker, and should never be seen here.
11254 gold_error(_("%s: unexpected reloc %u in object file"),
11255 object
->name().c_str(), r_type
);
11262 // Refuse some position-dependent relocations when creating a
11263 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
11264 // not PIC, but we can create dynamic relocations and the result
11265 // will be fine. Also do not refuse R_MIPS_LO16, which can be
11266 // combined with R_MIPS_GOT16.
11267 if (parameters
->options().shared())
11271 case elfcpp::R_MIPS16_HI16
:
11272 case elfcpp::R_MIPS_HI16
:
11273 case elfcpp::R_MIPS_HIGHER
:
11274 case elfcpp::R_MIPS_HIGHEST
:
11275 case elfcpp::R_MICROMIPS_HI16
:
11276 case elfcpp::R_MICROMIPS_HIGHER
:
11277 case elfcpp::R_MICROMIPS_HIGHEST
:
11278 // Don't refuse a high part relocation if it's against
11279 // no symbol (e.g. part of a compound relocation).
11283 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
11284 // and has a special meaning.
11285 if (!mips_obj
->is_newabi() && strcmp(gsym
->name(), "_gp_disp") == 0)
11289 case elfcpp::R_MIPS16_26
:
11290 case elfcpp::R_MIPS_26
:
11291 case elfcpp::R_MICROMIPS_26_S1
:
11292 gold_error(_("%s: relocation %u against `%s' can not be used when "
11293 "making a shared object; recompile with -fPIC"),
11294 object
->name().c_str(), r_type
, gsym
->name());
11301 template<int size
, bool big_endian
>
11303 Target_mips
<size
, big_endian
>::Scan::global(
11304 Symbol_table
* symtab
,
11306 Target_mips
<size
, big_endian
>* target
,
11307 Sized_relobj_file
<size
, big_endian
>* object
,
11308 unsigned int data_shndx
,
11309 Output_section
* output_section
,
11310 const Relatype
& reloc
,
11311 unsigned int r_type
,
11322 (const Reltype
*) NULL
,
11328 template<int size
, bool big_endian
>
11330 Target_mips
<size
, big_endian
>::Scan::global(
11331 Symbol_table
* symtab
,
11333 Target_mips
<size
, big_endian
>* target
,
11334 Sized_relobj_file
<size
, big_endian
>* object
,
11335 unsigned int data_shndx
,
11336 Output_section
* output_section
,
11337 const Reltype
& reloc
,
11338 unsigned int r_type
,
11348 (const Relatype
*) NULL
,
11355 // Return whether a R_MIPS_32/R_MIPS64 relocation needs to be applied.
11356 // In cases where Scan::local() or Scan::global() has created
11357 // a dynamic relocation, the addend of the relocation is carried
11358 // in the data, and we must not apply the static relocation.
11360 template<int size
, bool big_endian
>
11362 Target_mips
<size
, big_endian
>::Relocate::should_apply_static_reloc(
11363 const Mips_symbol
<size
>* gsym
,
11364 unsigned int r_type
,
11365 Output_section
* output_section
,
11366 Target_mips
* target
)
11368 // If the output section is not allocated, then we didn't call
11369 // scan_relocs, we didn't create a dynamic reloc, and we must apply
11371 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
11378 // For global symbols, we use the same helper routines used in the
11380 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
))
11381 && !gsym
->may_need_copy_reloc())
11383 // We have generated dynamic reloc (R_MIPS_REL32).
11385 bool multi_got
= false;
11386 if (target
->has_got_section())
11387 multi_got
= target
->got_section()->multi_got();
11388 bool has_got_offset
;
11390 has_got_offset
= gsym
->has_got_offset(GOT_TYPE_STANDARD
);
11392 has_got_offset
= gsym
->global_gotoffset() != -1U;
11393 if (!has_got_offset
)
11396 // Apply the relocation only if the symbol is in the local got.
11397 // Do not apply the relocation if the symbol is in the global
11399 return symbol_references_local(gsym
, gsym
->has_dynsym_index());
11402 // We have not generated dynamic reloc.
11407 // Perform a relocation.
11409 template<int size
, bool big_endian
>
11411 Target_mips
<size
, big_endian
>::Relocate::relocate(
11412 const Relocate_info
<size
, big_endian
>* relinfo
,
11413 unsigned int rel_type
,
11414 Target_mips
* target
,
11415 Output_section
* output_section
,
11417 const unsigned char* preloc
,
11418 const Sized_symbol
<size
>* gsym
,
11419 const Symbol_value
<size
>* psymval
,
11420 unsigned char* view
,
11421 Mips_address address
,
11424 Mips_address r_offset
;
11425 unsigned int r_sym
;
11426 unsigned int r_type
;
11427 unsigned int r_type2
;
11428 unsigned int r_type3
;
11429 unsigned char r_ssym
;
11430 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
11432 if (rel_type
== elfcpp::SHT_RELA
)
11434 const Relatype
rela(preloc
);
11435 r_offset
= rela
.get_r_offset();
11436 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11438 r_type
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11440 r_type2
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11441 get_r_type2(&rela
);
11442 r_type3
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11443 get_r_type3(&rela
);
11444 r_ssym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11446 r_addend
= rela
.get_r_addend();
11450 const Reltype
rel(preloc
);
11451 r_offset
= rel
.get_r_offset();
11452 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
11454 r_type
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
11462 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
11463 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
11465 Mips_relobj
<size
, big_endian
>* object
=
11466 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
11468 bool target_is_16_bit_code
= false;
11469 bool target_is_micromips_code
= false;
11470 bool cross_mode_jump
;
11472 Symbol_value
<size
> symval
;
11474 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
11476 bool changed_symbol_value
= false;
11479 target_is_16_bit_code
= object
->local_symbol_is_mips16(r_sym
);
11480 target_is_micromips_code
= object
->local_symbol_is_micromips(r_sym
);
11481 if (target_is_16_bit_code
|| target_is_micromips_code
)
11483 // MIPS16/microMIPS text labels should be treated as odd.
11484 symval
.set_output_value(psymval
->value(object
, 1));
11486 changed_symbol_value
= true;
11491 target_is_16_bit_code
= mips_sym
->is_mips16();
11492 target_is_micromips_code
= mips_sym
->is_micromips();
11494 // If this is a mips16/microMIPS text symbol, add 1 to the value to make
11495 // it odd. This will cause something like .word SYM to come up with
11496 // the right value when it is loaded into the PC.
11498 if ((mips_sym
->is_mips16() || mips_sym
->is_micromips())
11499 && psymval
->value(object
, 0) != 0)
11501 symval
.set_output_value(psymval
->value(object
, 0) | 1);
11503 changed_symbol_value
= true;
11506 // Pick the value to use for symbols defined in shared objects.
11507 if (mips_sym
->use_plt_offset(Scan::get_reference_flags(r_type
))
11508 || mips_sym
->has_lazy_stub())
11510 Mips_address value
;
11511 if (!mips_sym
->has_lazy_stub())
11513 // Prefer a standard MIPS PLT entry.
11514 if (mips_sym
->has_mips_plt_offset())
11516 value
= target
->plt_section()->mips_entry_address(mips_sym
);
11517 target_is_micromips_code
= false;
11518 target_is_16_bit_code
= false;
11522 value
= (target
->plt_section()->comp_entry_address(mips_sym
)
11524 if (target
->is_output_micromips())
11525 target_is_micromips_code
= true;
11527 target_is_16_bit_code
= true;
11531 value
= target
->mips_stubs_section()->stub_address(mips_sym
);
11533 symval
.set_output_value(value
);
11538 // TRUE if the symbol referred to by this relocation is "_gp_disp".
11539 // Note that such a symbol must always be a global symbol.
11540 bool gp_disp
= (gsym
!= NULL
&& (strcmp(gsym
->name(), "_gp_disp") == 0)
11541 && !object
->is_newabi());
11543 // TRUE if the symbol referred to by this relocation is "__gnu_local_gp".
11544 // Note that such a symbol must always be a global symbol.
11545 bool gnu_local_gp
= gsym
&& (strcmp(gsym
->name(), "__gnu_local_gp") == 0);
11550 if (!hi16_reloc(r_type
) && !lo16_reloc(r_type
))
11551 gold_error_at_location(relinfo
, relnum
, r_offset
,
11552 _("relocations against _gp_disp are permitted only"
11553 " with R_MIPS_HI16 and R_MIPS_LO16 relocations."));
11555 else if (gnu_local_gp
)
11557 // __gnu_local_gp is _gp symbol.
11558 symval
.set_output_value(target
->adjusted_gp_value(object
));
11562 // If this is a reference to a 16-bit function with a stub, we need
11563 // to redirect the relocation to the stub unless:
11565 // (a) the relocation is for a MIPS16 JAL;
11567 // (b) the relocation is for a MIPS16 PIC call, and there are no
11568 // non-MIPS16 uses of the GOT slot; or
11570 // (c) the section allows direct references to MIPS16 functions.
11571 if (r_type
!= elfcpp::R_MIPS16_26
11572 && ((mips_sym
!= NULL
11573 && mips_sym
->has_mips16_fn_stub()
11574 && (r_type
!= elfcpp::R_MIPS16_CALL16
|| mips_sym
->need_fn_stub()))
11575 || (mips_sym
== NULL
11576 && object
->get_local_mips16_fn_stub(r_sym
) != NULL
))
11577 && !object
->section_allows_mips16_refs(relinfo
->data_shndx
))
11579 // This is a 32- or 64-bit call to a 16-bit function. We should
11580 // have already noticed that we were going to need the
11582 Mips_address value
;
11583 if (mips_sym
== NULL
)
11584 value
= object
->get_local_mips16_fn_stub(r_sym
)->output_address();
11587 gold_assert(mips_sym
->need_fn_stub());
11588 if (mips_sym
->has_la25_stub())
11589 value
= target
->la25_stub_section()->stub_address(mips_sym
);
11592 value
= mips_sym
->template
11593 get_mips16_fn_stub
<big_endian
>()->output_address();
11596 symval
.set_output_value(value
);
11598 changed_symbol_value
= true;
11600 // The target is 16-bit, but the stub isn't.
11601 target_is_16_bit_code
= false;
11603 // If this is a MIPS16 call with a stub, that is made through the PLT or
11604 // to a standard MIPS function, we need to redirect the call to the stub.
11605 // Note that we specifically exclude R_MIPS16_CALL16 from this behavior;
11606 // indirect calls should use an indirect stub instead.
11607 else if (r_type
== elfcpp::R_MIPS16_26
11608 && ((mips_sym
!= NULL
11609 && (mips_sym
->has_mips16_call_stub()
11610 || mips_sym
->has_mips16_call_fp_stub()))
11611 || (mips_sym
== NULL
11612 && object
->get_local_mips16_call_stub(r_sym
) != NULL
))
11613 && ((mips_sym
!= NULL
&& mips_sym
->has_plt_offset())
11614 || !target_is_16_bit_code
))
11616 Mips16_stub_section
<size
, big_endian
>* call_stub
;
11617 if (mips_sym
== NULL
)
11618 call_stub
= object
->get_local_mips16_call_stub(r_sym
);
11621 // If both call_stub and call_fp_stub are defined, we can figure
11622 // out which one to use by checking which one appears in the input
11624 if (mips_sym
->has_mips16_call_stub()
11625 && mips_sym
->has_mips16_call_fp_stub())
11628 for (unsigned int i
= 1; i
< object
->shnum(); ++i
)
11630 if (object
->is_mips16_call_fp_stub_section(i
))
11632 call_stub
= mips_sym
->template
11633 get_mips16_call_fp_stub
<big_endian
>();
11638 if (call_stub
== NULL
)
11640 mips_sym
->template get_mips16_call_stub
<big_endian
>();
11642 else if (mips_sym
->has_mips16_call_stub())
11643 call_stub
= mips_sym
->template get_mips16_call_stub
<big_endian
>();
11645 call_stub
= mips_sym
->template get_mips16_call_fp_stub
<big_endian
>();
11648 symval
.set_output_value(call_stub
->output_address());
11650 changed_symbol_value
= true;
11652 // If this is a direct call to a PIC function, redirect to the
11654 else if (mips_sym
!= NULL
11655 && mips_sym
->has_la25_stub()
11656 && relocation_needs_la25_stub
<size
, big_endian
>(
11657 object
, r_type
, target_is_16_bit_code
))
11659 Mips_address value
= target
->la25_stub_section()->stub_address(mips_sym
);
11660 if (mips_sym
->is_micromips())
11662 symval
.set_output_value(value
);
11665 // For direct MIPS16 and microMIPS calls make sure the compressed PLT
11666 // entry is used if a standard PLT entry has also been made.
11667 else if ((r_type
== elfcpp::R_MIPS16_26
11668 || r_type
== elfcpp::R_MICROMIPS_26_S1
)
11669 && mips_sym
!= NULL
11670 && mips_sym
->has_plt_offset()
11671 && mips_sym
->has_comp_plt_offset()
11672 && mips_sym
->has_mips_plt_offset())
11674 Mips_address value
= (target
->plt_section()->comp_entry_address(mips_sym
)
11676 symval
.set_output_value(value
);
11679 target_is_16_bit_code
= !target
->is_output_micromips();
11680 target_is_micromips_code
= target
->is_output_micromips();
11683 // Make sure MIPS16 and microMIPS are not used together.
11684 if ((r_type
== elfcpp::R_MIPS16_26
&& target_is_micromips_code
)
11685 || (micromips_branch_reloc(r_type
) && target_is_16_bit_code
))
11687 gold_error(_("MIPS16 and microMIPS functions cannot call each other"));
11690 // Calls from 16-bit code to 32-bit code and vice versa require the
11691 // mode change. However, we can ignore calls to undefined weak symbols,
11692 // which should never be executed at runtime. This exception is important
11693 // because the assembly writer may have "known" that any definition of the
11694 // symbol would be 16-bit code, and that direct jumps were therefore
11697 (!(gsym
!= NULL
&& gsym
->is_weak_undefined())
11698 && ((r_type
== elfcpp::R_MIPS16_26
&& !target_is_16_bit_code
)
11699 || (r_type
== elfcpp::R_MICROMIPS_26_S1
&& !target_is_micromips_code
)
11700 || ((r_type
== elfcpp::R_MIPS_26
|| r_type
== elfcpp::R_MIPS_JALR
)
11701 && (target_is_16_bit_code
|| target_is_micromips_code
))));
11703 bool local
= (mips_sym
== NULL
11704 || (mips_sym
->got_only_for_calls()
11705 ? symbol_calls_local(mips_sym
, mips_sym
->has_dynsym_index())
11706 : symbol_references_local(mips_sym
,
11707 mips_sym
->has_dynsym_index())));
11709 // Global R_MIPS_GOT_PAGE/R_MICROMIPS_GOT_PAGE relocations are equivalent
11710 // to R_MIPS_GOT_DISP/R_MICROMIPS_GOT_DISP. The addend is applied by the
11711 // corresponding R_MIPS_GOT_OFST/R_MICROMIPS_GOT_OFST.
11712 if (got_page_reloc(r_type
) && !local
)
11713 r_type
= (micromips_reloc(r_type
) ? elfcpp::R_MICROMIPS_GOT_DISP
11714 : elfcpp::R_MIPS_GOT_DISP
);
11716 unsigned int got_offset
= 0;
11719 bool calculate_only
= false;
11720 Valtype calculated_value
= 0;
11721 bool extract_addend
= rel_type
== elfcpp::SHT_REL
;
11722 unsigned int r_types
[3] = { r_type
, r_type2
, r_type3
};
11724 Reloc_funcs::mips_reloc_unshuffle(view
, r_type
, false);
11726 // For Mips64 N64 ABI, there may be up to three operations specified per
11727 // record, by the fields r_type, r_type2, and r_type3. The first operation
11728 // takes its addend from the relocation record. Each subsequent operation
11729 // takes as its addend the result of the previous operation.
11730 // The first operation in a record which references a symbol uses the symbol
11731 // implied by r_sym. The next operation in a record which references a symbol
11732 // uses the special symbol value given by the r_ssym field. A third operation
11733 // in a record which references a symbol will assume a NULL symbol,
11734 // i.e. value zero.
11737 // Check if a record references to a symbol.
11738 for (unsigned int i
= 0; i
< 3; ++i
)
11740 if (r_types
[i
] == elfcpp::R_MIPS_NONE
)
11744 // Check if the next relocation is for the same instruction.
11745 calculate_only
= i
== 2 ? false
11746 : r_types
[i
+1] != elfcpp::R_MIPS_NONE
;
11748 if (object
->is_n64())
11752 // Handle special symbol for r_type2 relocation type.
11756 symval
.set_output_value(0);
11759 symval
.set_output_value(target
->gp_value());
11762 symval
.set_output_value(object
->gp_value());
11765 symval
.set_output_value(address
);
11768 gold_unreachable();
11774 // For r_type3 symbol value is 0.
11775 symval
.set_output_value(0);
11779 bool update_got_entry
= false;
11780 switch (r_types
[i
])
11782 case elfcpp::R_MIPS_NONE
:
11784 case elfcpp::R_MIPS_16
:
11785 reloc_status
= Reloc_funcs::rel16(view
, object
, psymval
, r_addend
,
11786 extract_addend
, calculate_only
,
11787 &calculated_value
);
11790 case elfcpp::R_MIPS_32
:
11791 if (should_apply_static_reloc(mips_sym
, r_types
[i
], output_section
,
11793 reloc_status
= Reloc_funcs::rel32(view
, object
, psymval
, r_addend
,
11794 extract_addend
, calculate_only
,
11795 &calculated_value
);
11796 if (mips_sym
!= NULL
11797 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
11798 && mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
11800 // If mips_sym->has_mips16_fn_stub() is false, symbol value is
11801 // already updated by adding +1.
11802 if (mips_sym
->has_mips16_fn_stub())
11804 gold_assert(mips_sym
->need_fn_stub());
11805 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
11806 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
11808 symval
.set_output_value(fn_stub
->output_address());
11811 got_offset
= mips_sym
->global_gotoffset();
11812 update_got_entry
= true;
11816 case elfcpp::R_MIPS_64
:
11817 if (should_apply_static_reloc(mips_sym
, r_types
[i
], output_section
,
11819 reloc_status
= Reloc_funcs::rel64(view
, object
, psymval
, r_addend
,
11820 extract_addend
, calculate_only
,
11821 &calculated_value
, false);
11822 else if (target
->is_output_n64() && r_addend
!= 0)
11823 // Only apply the addend. The static relocation was RELA, but the
11824 // dynamic relocation is REL, so we need to apply the addend.
11825 reloc_status
= Reloc_funcs::rel64(view
, object
, psymval
, r_addend
,
11826 extract_addend
, calculate_only
,
11827 &calculated_value
, true);
11829 case elfcpp::R_MIPS_REL32
:
11830 gold_unreachable();
11832 case elfcpp::R_MIPS_PC32
:
11833 reloc_status
= Reloc_funcs::relpc32(view
, object
, psymval
, address
,
11834 r_addend
, extract_addend
,
11836 &calculated_value
);
11839 case elfcpp::R_MIPS16_26
:
11840 // The calculation for R_MIPS16_26 is just the same as for an
11841 // R_MIPS_26. It's only the storage of the relocated field into
11842 // the output file that's different. So, we just fall through to the
11843 // R_MIPS_26 case here.
11844 case elfcpp::R_MIPS_26
:
11845 case elfcpp::R_MICROMIPS_26_S1
:
11846 reloc_status
= Reloc_funcs::rel26(view
, object
, psymval
, address
,
11847 gsym
== NULL
, r_addend
, extract_addend
, gsym
, cross_mode_jump
,
11848 r_types
[i
], target
->jal_to_bal(), calculate_only
,
11849 &calculated_value
);
11852 case elfcpp::R_MIPS_HI16
:
11853 case elfcpp::R_MIPS16_HI16
:
11854 case elfcpp::R_MICROMIPS_HI16
:
11855 if (rel_type
== elfcpp::SHT_RELA
)
11856 reloc_status
= Reloc_funcs::do_relhi16(view
, object
, psymval
,
11858 gp_disp
, r_types
[i
],
11860 target
, calculate_only
,
11861 &calculated_value
);
11862 else if (rel_type
== elfcpp::SHT_REL
)
11863 reloc_status
= Reloc_funcs::relhi16(view
, object
, psymval
, r_addend
,
11864 address
, gp_disp
, r_types
[i
],
11865 r_sym
, extract_addend
);
11867 gold_unreachable();
11870 case elfcpp::R_MIPS_LO16
:
11871 case elfcpp::R_MIPS16_LO16
:
11872 case elfcpp::R_MICROMIPS_LO16
:
11873 case elfcpp::R_MICROMIPS_HI0_LO16
:
11874 reloc_status
= Reloc_funcs::rello16(target
, view
, object
, psymval
,
11875 r_addend
, extract_addend
, address
,
11876 gp_disp
, r_types
[i
], r_sym
,
11877 rel_type
, calculate_only
,
11878 &calculated_value
);
11881 case elfcpp::R_MIPS_LITERAL
:
11882 case elfcpp::R_MICROMIPS_LITERAL
:
11883 // Because we don't merge literal sections, we can handle this
11884 // just like R_MIPS_GPREL16. In the long run, we should merge
11885 // shared literals, and then we will need to additional work
11890 case elfcpp::R_MIPS_GPREL16
:
11891 case elfcpp::R_MIPS16_GPREL
:
11892 case elfcpp::R_MICROMIPS_GPREL7_S2
:
11893 case elfcpp::R_MICROMIPS_GPREL16
:
11894 reloc_status
= Reloc_funcs::relgprel(view
, object
, psymval
,
11895 target
->adjusted_gp_value(object
),
11896 r_addend
, extract_addend
,
11897 gsym
== NULL
, r_types
[i
],
11898 calculate_only
, &calculated_value
);
11901 case elfcpp::R_MIPS_PC16
:
11902 reloc_status
= Reloc_funcs::relpc16(view
, object
, psymval
, address
,
11903 r_addend
, extract_addend
,
11905 &calculated_value
);
11908 case elfcpp::R_MIPS_PC21_S2
:
11909 reloc_status
= Reloc_funcs::relpc21(view
, object
, psymval
, address
,
11910 r_addend
, extract_addend
,
11912 &calculated_value
);
11915 case elfcpp::R_MIPS_PC26_S2
:
11916 reloc_status
= Reloc_funcs::relpc26(view
, object
, psymval
, address
,
11917 r_addend
, extract_addend
,
11919 &calculated_value
);
11922 case elfcpp::R_MIPS_PC18_S3
:
11923 reloc_status
= Reloc_funcs::relpc18(view
, object
, psymval
, address
,
11924 r_addend
, extract_addend
,
11926 &calculated_value
);
11929 case elfcpp::R_MIPS_PC19_S2
:
11930 reloc_status
= Reloc_funcs::relpc19(view
, object
, psymval
, address
,
11931 r_addend
, extract_addend
,
11933 &calculated_value
);
11936 case elfcpp::R_MIPS_PCHI16
:
11937 if (rel_type
== elfcpp::SHT_RELA
)
11938 reloc_status
= Reloc_funcs::do_relpchi16(view
, object
, psymval
,
11942 &calculated_value
);
11943 else if (rel_type
== elfcpp::SHT_REL
)
11944 reloc_status
= Reloc_funcs::relpchi16(view
, object
, psymval
,
11945 r_addend
, address
, r_sym
,
11948 gold_unreachable();
11951 case elfcpp::R_MIPS_PCLO16
:
11952 reloc_status
= Reloc_funcs::relpclo16(view
, object
, psymval
, r_addend
,
11953 extract_addend
, address
, r_sym
,
11954 rel_type
, calculate_only
,
11955 &calculated_value
);
11957 case elfcpp::R_MICROMIPS_PC7_S1
:
11958 reloc_status
= Reloc_funcs::relmicromips_pc7_s1(view
, object
, psymval
,
11962 &calculated_value
);
11964 case elfcpp::R_MICROMIPS_PC10_S1
:
11965 reloc_status
= Reloc_funcs::relmicromips_pc10_s1(view
, object
,
11967 r_addend
, extract_addend
,
11969 &calculated_value
);
11971 case elfcpp::R_MICROMIPS_PC16_S1
:
11972 reloc_status
= Reloc_funcs::relmicromips_pc16_s1(view
, object
,
11974 r_addend
, extract_addend
,
11976 &calculated_value
);
11978 case elfcpp::R_MIPS_GPREL32
:
11979 reloc_status
= Reloc_funcs::relgprel32(view
, object
, psymval
,
11980 target
->adjusted_gp_value(object
),
11981 r_addend
, extract_addend
,
11983 &calculated_value
);
11985 case elfcpp::R_MIPS_GOT_HI16
:
11986 case elfcpp::R_MIPS_CALL_HI16
:
11987 case elfcpp::R_MICROMIPS_GOT_HI16
:
11988 case elfcpp::R_MICROMIPS_CALL_HI16
:
11990 got_offset
= target
->got_section()->got_offset(gsym
,
11994 got_offset
= target
->got_section()->got_offset(r_sym
,
11997 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
11998 reloc_status
= Reloc_funcs::relgot_hi16(view
, gp_offset
,
12000 &calculated_value
);
12001 update_got_entry
= changed_symbol_value
;
12004 case elfcpp::R_MIPS_GOT_LO16
:
12005 case elfcpp::R_MIPS_CALL_LO16
:
12006 case elfcpp::R_MICROMIPS_GOT_LO16
:
12007 case elfcpp::R_MICROMIPS_CALL_LO16
:
12009 got_offset
= target
->got_section()->got_offset(gsym
,
12013 got_offset
= target
->got_section()->got_offset(r_sym
,
12016 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12017 reloc_status
= Reloc_funcs::relgot_lo16(view
, gp_offset
,
12019 &calculated_value
);
12020 update_got_entry
= changed_symbol_value
;
12023 case elfcpp::R_MIPS_GOT_DISP
:
12024 case elfcpp::R_MICROMIPS_GOT_DISP
:
12025 case elfcpp::R_MIPS_EH
:
12027 got_offset
= target
->got_section()->got_offset(gsym
,
12031 got_offset
= target
->got_section()->got_offset(r_sym
,
12034 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12035 if (eh_reloc(r_types
[i
]))
12036 reloc_status
= Reloc_funcs::releh(view
, gp_offset
,
12038 &calculated_value
);
12040 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12042 &calculated_value
);
12044 case elfcpp::R_MIPS_CALL16
:
12045 case elfcpp::R_MIPS16_CALL16
:
12046 case elfcpp::R_MICROMIPS_CALL16
:
12047 gold_assert(gsym
!= NULL
);
12048 got_offset
= target
->got_section()->got_offset(gsym
,
12051 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12052 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12053 calculate_only
, &calculated_value
);
12054 // TODO(sasa): We should also initialize update_got_entry
12055 // in other place swhere relgot is called.
12056 update_got_entry
= changed_symbol_value
;
12059 case elfcpp::R_MIPS_GOT16
:
12060 case elfcpp::R_MIPS16_GOT16
:
12061 case elfcpp::R_MICROMIPS_GOT16
:
12064 got_offset
= target
->got_section()->got_offset(gsym
,
12067 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12068 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12070 &calculated_value
);
12074 if (rel_type
== elfcpp::SHT_RELA
)
12075 reloc_status
= Reloc_funcs::do_relgot16_local(view
, object
,
12080 &calculated_value
);
12081 else if (rel_type
== elfcpp::SHT_REL
)
12082 reloc_status
= Reloc_funcs::relgot16_local(view
, object
,
12085 r_types
[i
], r_sym
);
12087 gold_unreachable();
12089 update_got_entry
= changed_symbol_value
;
12092 case elfcpp::R_MIPS_TLS_GD
:
12093 case elfcpp::R_MIPS16_TLS_GD
:
12094 case elfcpp::R_MICROMIPS_TLS_GD
:
12096 got_offset
= target
->got_section()->got_offset(gsym
,
12100 got_offset
= target
->got_section()->got_offset(r_sym
,
12103 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12104 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
12105 &calculated_value
);
12108 case elfcpp::R_MIPS_TLS_GOTTPREL
:
12109 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
12110 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
12112 got_offset
= target
->got_section()->got_offset(gsym
,
12113 GOT_TYPE_TLS_OFFSET
,
12116 got_offset
= target
->got_section()->got_offset(r_sym
,
12117 GOT_TYPE_TLS_OFFSET
,
12119 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12120 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
12121 &calculated_value
);
12124 case elfcpp::R_MIPS_TLS_LDM
:
12125 case elfcpp::R_MIPS16_TLS_LDM
:
12126 case elfcpp::R_MICROMIPS_TLS_LDM
:
12127 // Relocate the field with the offset of the GOT entry for
12128 // the module index.
12129 got_offset
= target
->got_section()->tls_ldm_offset(object
);
12130 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12131 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
12132 &calculated_value
);
12135 case elfcpp::R_MIPS_GOT_PAGE
:
12136 case elfcpp::R_MICROMIPS_GOT_PAGE
:
12137 reloc_status
= Reloc_funcs::relgotpage(target
, view
, object
, psymval
,
12138 r_addend
, extract_addend
,
12140 &calculated_value
);
12143 case elfcpp::R_MIPS_GOT_OFST
:
12144 case elfcpp::R_MICROMIPS_GOT_OFST
:
12145 reloc_status
= Reloc_funcs::relgotofst(target
, view
, object
, psymval
,
12146 r_addend
, extract_addend
,
12147 local
, calculate_only
,
12148 &calculated_value
);
12151 case elfcpp::R_MIPS_JALR
:
12152 case elfcpp::R_MICROMIPS_JALR
:
12153 // This relocation is only a hint. In some cases, we optimize
12154 // it into a bal instruction. But we don't try to optimize
12155 // when the symbol does not resolve locally.
12157 || symbol_calls_local(gsym
, gsym
->has_dynsym_index()))
12158 reloc_status
= Reloc_funcs::reljalr(view
, object
, psymval
, address
,
12159 r_addend
, extract_addend
,
12160 cross_mode_jump
, r_types
[i
],
12161 target
->jalr_to_bal(),
12164 &calculated_value
);
12167 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
12168 case elfcpp::R_MIPS16_TLS_DTPREL_HI16
:
12169 case elfcpp::R_MICROMIPS_TLS_DTPREL_HI16
:
12170 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
12171 elfcpp::DTP_OFFSET
, r_addend
,
12172 extract_addend
, calculate_only
,
12173 &calculated_value
);
12175 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
12176 case elfcpp::R_MIPS16_TLS_DTPREL_LO16
:
12177 case elfcpp::R_MICROMIPS_TLS_DTPREL_LO16
:
12178 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
12179 elfcpp::DTP_OFFSET
, r_addend
,
12180 extract_addend
, calculate_only
,
12181 &calculated_value
);
12183 case elfcpp::R_MIPS_TLS_DTPREL32
:
12184 case elfcpp::R_MIPS_TLS_DTPREL64
:
12185 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
12186 elfcpp::DTP_OFFSET
, r_addend
,
12187 extract_addend
, calculate_only
,
12188 &calculated_value
);
12190 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
12191 case elfcpp::R_MIPS16_TLS_TPREL_HI16
:
12192 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
12193 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
12194 elfcpp::TP_OFFSET
, r_addend
,
12195 extract_addend
, calculate_only
,
12196 &calculated_value
);
12198 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
12199 case elfcpp::R_MIPS16_TLS_TPREL_LO16
:
12200 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
12201 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
12202 elfcpp::TP_OFFSET
, r_addend
,
12203 extract_addend
, calculate_only
,
12204 &calculated_value
);
12206 case elfcpp::R_MIPS_TLS_TPREL32
:
12207 case elfcpp::R_MIPS_TLS_TPREL64
:
12208 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
12209 elfcpp::TP_OFFSET
, r_addend
,
12210 extract_addend
, calculate_only
,
12211 &calculated_value
);
12213 case elfcpp::R_MIPS_SUB
:
12214 case elfcpp::R_MICROMIPS_SUB
:
12215 reloc_status
= Reloc_funcs::relsub(view
, object
, psymval
, r_addend
,
12217 calculate_only
, &calculated_value
);
12219 case elfcpp::R_MIPS_HIGHER
:
12220 case elfcpp::R_MICROMIPS_HIGHER
:
12221 reloc_status
= Reloc_funcs::relhigher(view
, object
, psymval
, r_addend
,
12222 extract_addend
, calculate_only
,
12223 &calculated_value
);
12225 case elfcpp::R_MIPS_HIGHEST
:
12226 case elfcpp::R_MICROMIPS_HIGHEST
:
12227 reloc_status
= Reloc_funcs::relhighest(view
, object
, psymval
,
12228 r_addend
, extract_addend
,
12230 &calculated_value
);
12233 gold_error_at_location(relinfo
, relnum
, r_offset
,
12234 _("unsupported reloc %u"), r_types
[i
]);
12238 if (update_got_entry
)
12240 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
12241 if (mips_sym
!= NULL
&& mips_sym
->get_applied_secondary_got_fixup())
12242 got
->update_got_entry(got
->get_primary_got_offset(mips_sym
),
12243 psymval
->value(object
, 0));
12245 got
->update_got_entry(got_offset
, psymval
->value(object
, 0));
12248 r_addend
= calculated_value
;
12251 bool jal_shuffle
= jal_reloc(r_type
);
12252 Reloc_funcs::mips_reloc_shuffle(view
, r_type
, jal_shuffle
);
12254 // Report any errors.
12255 switch (reloc_status
)
12257 case Reloc_funcs::STATUS_OKAY
:
12259 case Reloc_funcs::STATUS_OVERFLOW
:
12261 gold_error_at_location(relinfo
, relnum
, r_offset
,
12262 _("relocation overflow: "
12263 "%u against local symbol %u in %s"),
12264 r_type
, r_sym
, object
->name().c_str());
12265 else if (gsym
->is_defined() && gsym
->source() == Symbol::FROM_OBJECT
)
12266 gold_error_at_location(relinfo
, relnum
, r_offset
,
12267 _("relocation overflow: "
12268 "%u against '%s' defined in %s"),
12269 r_type
, gsym
->demangled_name().c_str(),
12270 gsym
->object()->name().c_str());
12272 gold_error_at_location(relinfo
, relnum
, r_offset
,
12273 _("relocation overflow: %u against '%s'"),
12274 r_type
, gsym
->demangled_name().c_str());
12276 case Reloc_funcs::STATUS_BAD_RELOC
:
12277 gold_error_at_location(relinfo
, relnum
, r_offset
,
12278 _("unexpected opcode while processing relocation"));
12280 case Reloc_funcs::STATUS_PCREL_UNALIGNED
:
12281 gold_error_at_location(relinfo
, relnum
, r_offset
,
12282 _("unaligned PC-relative relocation"));
12285 gold_unreachable();
12291 // Get the Reference_flags for a particular relocation.
12293 template<int size
, bool big_endian
>
12295 Target_mips
<size
, big_endian
>::Scan::get_reference_flags(
12296 unsigned int r_type
)
12300 case elfcpp::R_MIPS_NONE
:
12301 // No symbol reference.
12304 case elfcpp::R_MIPS_16
:
12305 case elfcpp::R_MIPS_32
:
12306 case elfcpp::R_MIPS_64
:
12307 case elfcpp::R_MIPS_HI16
:
12308 case elfcpp::R_MIPS_LO16
:
12309 case elfcpp::R_MIPS_HIGHER
:
12310 case elfcpp::R_MIPS_HIGHEST
:
12311 case elfcpp::R_MIPS16_HI16
:
12312 case elfcpp::R_MIPS16_LO16
:
12313 case elfcpp::R_MICROMIPS_HI16
:
12314 case elfcpp::R_MICROMIPS_LO16
:
12315 case elfcpp::R_MICROMIPS_HIGHER
:
12316 case elfcpp::R_MICROMIPS_HIGHEST
:
12317 return Symbol::ABSOLUTE_REF
;
12319 case elfcpp::R_MIPS_26
:
12320 case elfcpp::R_MIPS16_26
:
12321 case elfcpp::R_MICROMIPS_26_S1
:
12322 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
12324 case elfcpp::R_MIPS_PC18_S3
:
12325 case elfcpp::R_MIPS_PC19_S2
:
12326 case elfcpp::R_MIPS_PCHI16
:
12327 case elfcpp::R_MIPS_PCLO16
:
12328 case elfcpp::R_MIPS_GPREL32
:
12329 case elfcpp::R_MIPS_GPREL16
:
12330 case elfcpp::R_MIPS_REL32
:
12331 case elfcpp::R_MIPS16_GPREL
:
12332 return Symbol::RELATIVE_REF
;
12334 case elfcpp::R_MIPS_PC16
:
12335 case elfcpp::R_MIPS_PC32
:
12336 case elfcpp::R_MIPS_PC21_S2
:
12337 case elfcpp::R_MIPS_PC26_S2
:
12338 case elfcpp::R_MIPS_JALR
:
12339 case elfcpp::R_MICROMIPS_JALR
:
12340 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
12342 case elfcpp::R_MIPS_GOT16
:
12343 case elfcpp::R_MIPS_CALL16
:
12344 case elfcpp::R_MIPS_GOT_DISP
:
12345 case elfcpp::R_MIPS_GOT_HI16
:
12346 case elfcpp::R_MIPS_GOT_LO16
:
12347 case elfcpp::R_MIPS_CALL_HI16
:
12348 case elfcpp::R_MIPS_CALL_LO16
:
12349 case elfcpp::R_MIPS_LITERAL
:
12350 case elfcpp::R_MIPS_GOT_PAGE
:
12351 case elfcpp::R_MIPS_GOT_OFST
:
12352 case elfcpp::R_MIPS16_GOT16
:
12353 case elfcpp::R_MIPS16_CALL16
:
12354 case elfcpp::R_MICROMIPS_GOT16
:
12355 case elfcpp::R_MICROMIPS_CALL16
:
12356 case elfcpp::R_MICROMIPS_GOT_HI16
:
12357 case elfcpp::R_MICROMIPS_GOT_LO16
:
12358 case elfcpp::R_MICROMIPS_CALL_HI16
:
12359 case elfcpp::R_MICROMIPS_CALL_LO16
:
12360 case elfcpp::R_MIPS_EH
:
12361 // Absolute in GOT.
12362 return Symbol::RELATIVE_REF
;
12364 case elfcpp::R_MIPS_TLS_DTPMOD32
:
12365 case elfcpp::R_MIPS_TLS_DTPREL32
:
12366 case elfcpp::R_MIPS_TLS_DTPMOD64
:
12367 case elfcpp::R_MIPS_TLS_DTPREL64
:
12368 case elfcpp::R_MIPS_TLS_GD
:
12369 case elfcpp::R_MIPS_TLS_LDM
:
12370 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
12371 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
12372 case elfcpp::R_MIPS_TLS_GOTTPREL
:
12373 case elfcpp::R_MIPS_TLS_TPREL32
:
12374 case elfcpp::R_MIPS_TLS_TPREL64
:
12375 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
12376 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
12377 case elfcpp::R_MIPS16_TLS_GD
:
12378 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
12379 case elfcpp::R_MICROMIPS_TLS_GD
:
12380 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
12381 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
12382 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
12383 return Symbol::TLS_REF
;
12385 case elfcpp::R_MIPS_COPY
:
12386 case elfcpp::R_MIPS_JUMP_SLOT
:
12388 // Not expected. We will give an error later.
12393 // Report an unsupported relocation against a local symbol.
12395 template<int size
, bool big_endian
>
12397 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_local(
12398 Sized_relobj_file
<size
, big_endian
>* object
,
12399 unsigned int r_type
)
12401 gold_error(_("%s: unsupported reloc %u against local symbol"),
12402 object
->name().c_str(), r_type
);
12405 // Report an unsupported relocation against a global symbol.
12407 template<int size
, bool big_endian
>
12409 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_global(
12410 Sized_relobj_file
<size
, big_endian
>* object
,
12411 unsigned int r_type
,
12414 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
12415 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
12418 // Return printable name for ABI.
12419 template<int size
, bool big_endian
>
12421 Target_mips
<size
, big_endian
>::elf_mips_abi_name(elfcpp::Elf_Word e_flags
)
12423 switch (e_flags
& elfcpp::EF_MIPS_ABI
)
12426 if ((e_flags
& elfcpp::EF_MIPS_ABI2
) != 0)
12428 else if (size
== 64)
12432 case elfcpp::E_MIPS_ABI_O32
:
12434 case elfcpp::E_MIPS_ABI_O64
:
12436 case elfcpp::E_MIPS_ABI_EABI32
:
12438 case elfcpp::E_MIPS_ABI_EABI64
:
12441 return "unknown abi";
12445 template<int size
, bool big_endian
>
12447 Target_mips
<size
, big_endian
>::elf_mips_mach_name(elfcpp::Elf_Word e_flags
)
12449 switch (e_flags
& elfcpp::EF_MIPS_MACH
)
12451 case elfcpp::E_MIPS_MACH_3900
:
12452 return "mips:3900";
12453 case elfcpp::E_MIPS_MACH_4010
:
12454 return "mips:4010";
12455 case elfcpp::E_MIPS_MACH_4100
:
12456 return "mips:4100";
12457 case elfcpp::E_MIPS_MACH_4111
:
12458 return "mips:4111";
12459 case elfcpp::E_MIPS_MACH_4120
:
12460 return "mips:4120";
12461 case elfcpp::E_MIPS_MACH_4650
:
12462 return "mips:4650";
12463 case elfcpp::E_MIPS_MACH_5400
:
12464 return "mips:5400";
12465 case elfcpp::E_MIPS_MACH_5500
:
12466 return "mips:5500";
12467 case elfcpp::E_MIPS_MACH_5900
:
12468 return "mips:5900";
12469 case elfcpp::E_MIPS_MACH_SB1
:
12471 case elfcpp::E_MIPS_MACH_9000
:
12472 return "mips:9000";
12473 case elfcpp::E_MIPS_MACH_LS2E
:
12474 return "mips:loongson_2e";
12475 case elfcpp::E_MIPS_MACH_LS2F
:
12476 return "mips:loongson_2f";
12477 case elfcpp::E_MIPS_MACH_LS3A
:
12478 return "mips:loongson_3a";
12479 case elfcpp::E_MIPS_MACH_OCTEON
:
12480 return "mips:octeon";
12481 case elfcpp::E_MIPS_MACH_OCTEON2
:
12482 return "mips:octeon2";
12483 case elfcpp::E_MIPS_MACH_OCTEON3
:
12484 return "mips:octeon3";
12485 case elfcpp::E_MIPS_MACH_XLR
:
12488 switch (e_flags
& elfcpp::EF_MIPS_ARCH
)
12491 case elfcpp::E_MIPS_ARCH_1
:
12492 return "mips:3000";
12494 case elfcpp::E_MIPS_ARCH_2
:
12495 return "mips:6000";
12497 case elfcpp::E_MIPS_ARCH_3
:
12498 return "mips:4000";
12500 case elfcpp::E_MIPS_ARCH_4
:
12501 return "mips:8000";
12503 case elfcpp::E_MIPS_ARCH_5
:
12504 return "mips:mips5";
12506 case elfcpp::E_MIPS_ARCH_32
:
12507 return "mips:isa32";
12509 case elfcpp::E_MIPS_ARCH_64
:
12510 return "mips:isa64";
12512 case elfcpp::E_MIPS_ARCH_32R2
:
12513 return "mips:isa32r2";
12515 case elfcpp::E_MIPS_ARCH_32R6
:
12516 return "mips:isa32r6";
12518 case elfcpp::E_MIPS_ARCH_64R2
:
12519 return "mips:isa64r2";
12521 case elfcpp::E_MIPS_ARCH_64R6
:
12522 return "mips:isa64r6";
12525 return "unknown CPU";
12528 template<int size
, bool big_endian
>
12529 const Target::Target_info Target_mips
<size
, big_endian
>::mips_info
=
12532 big_endian
, // is_big_endian
12533 elfcpp::EM_MIPS
, // machine_code
12534 true, // has_make_symbol
12535 false, // has_resolve
12536 false, // has_code_fill
12537 true, // is_default_stack_executable
12538 false, // can_icf_inline_merge_sections
12540 size
== 32 ? "/lib/ld.so.1" : "/lib64/ld.so.1", // dynamic_linker
12541 0x400000, // default_text_segment_address
12542 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
12543 4 * 1024, // common_pagesize (overridable by -z common-page-size)
12544 false, // isolate_execinstr
12545 0, // rosegment_gap
12546 elfcpp::SHN_UNDEF
, // small_common_shndx
12547 elfcpp::SHN_UNDEF
, // large_common_shndx
12548 0, // small_common_section_flags
12549 0, // large_common_section_flags
12550 NULL
, // attributes_section
12551 NULL
, // attributes_vendor
12552 "__start", // entry_symbol_name
12553 32, // hash_entry_size
12556 template<int size
, bool big_endian
>
12557 class Target_mips_nacl
: public Target_mips
<size
, big_endian
>
12561 : Target_mips
<size
, big_endian
>(&mips_nacl_info
)
12565 static const Target::Target_info mips_nacl_info
;
12568 template<int size
, bool big_endian
>
12569 const Target::Target_info Target_mips_nacl
<size
, big_endian
>::mips_nacl_info
=
12572 big_endian
, // is_big_endian
12573 elfcpp::EM_MIPS
, // machine_code
12574 true, // has_make_symbol
12575 false, // has_resolve
12576 false, // has_code_fill
12577 true, // is_default_stack_executable
12578 false, // can_icf_inline_merge_sections
12580 "/lib/ld.so.1", // dynamic_linker
12581 0x20000, // default_text_segment_address
12582 0x10000, // abi_pagesize (overridable by -z max-page-size)
12583 0x10000, // common_pagesize (overridable by -z common-page-size)
12584 true, // isolate_execinstr
12585 0x10000000, // rosegment_gap
12586 elfcpp::SHN_UNDEF
, // small_common_shndx
12587 elfcpp::SHN_UNDEF
, // large_common_shndx
12588 0, // small_common_section_flags
12589 0, // large_common_section_flags
12590 NULL
, // attributes_section
12591 NULL
, // attributes_vendor
12592 "_start", // entry_symbol_name
12593 32, // hash_entry_size
12596 // Target selector for Mips. Note this is never instantiated directly.
12597 // It's only used in Target_selector_mips_nacl, below.
12599 template<int size
, bool big_endian
>
12600 class Target_selector_mips
: public Target_selector
12603 Target_selector_mips()
12604 : Target_selector(elfcpp::EM_MIPS
, size
, big_endian
,
12606 (big_endian
? "elf64-tradbigmips" : "elf64-tradlittlemips") :
12607 (big_endian
? "elf32-tradbigmips" : "elf32-tradlittlemips")),
12609 (big_endian
? "elf64btsmip" : "elf64ltsmip") :
12610 (big_endian
? "elf32btsmip" : "elf32ltsmip")))
12613 Target
* do_instantiate_target()
12614 { return new Target_mips
<size
, big_endian
>(); }
12617 template<int size
, bool big_endian
>
12618 class Target_selector_mips_nacl
12619 : public Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
12620 Target_mips_nacl
<size
, big_endian
> >
12623 Target_selector_mips_nacl()
12624 : Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
12625 Target_mips_nacl
<size
, big_endian
> >(
12626 // NaCl currently supports only MIPS32 little-endian.
12627 "mipsel", "elf32-tradlittlemips-nacl", "elf32-tradlittlemips-nacl")
12631 Target_selector_mips_nacl
<32, true> target_selector_mips32
;
12632 Target_selector_mips_nacl
<32, false> target_selector_mips32el
;
12633 Target_selector_mips_nacl
<64, true> target_selector_mips64
;
12634 Target_selector_mips_nacl
<64, false> target_selector_mips64el
;
12636 } // End anonymous namespace.