1 // mips.cc -- mips target support for gold.
3 // Copyright (C) 2011-2018 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
<< 16);
480 // Return whether this entry is equal to OTHER.
482 equals(Mips_got_entry
<size
, big_endian
>* other
) const
484 if (this->symndx_
!= other
->symndx_
485 || this->tls_type_
!= other
->tls_type_
)
488 if (this->tls_type_
== GOT_TLS_LDM
)
491 return (((this->symndx_
!= -1U)
492 ? (this->d
.object
== other
->d
.object
)
493 : (this->d
.sym
== other
->d
.sym
))
494 && (this->addend_
== other
->addend_
));
497 // Return input object that needs this GOT entry.
498 Mips_relobj
<size
, big_endian
>*
501 gold_assert(this->symndx_
!= -1U);
502 return this->d
.object
;
505 // Return local symbol index for local GOT entries.
509 gold_assert(this->symndx_
!= -1U);
510 return this->symndx_
;
513 // Return the relocation addend for local GOT entries.
516 { return this->addend_
; }
518 // Return global symbol for global GOT entries.
522 gold_assert(this->symndx_
== -1U);
526 // Return whether this is a TLS GOT entry.
529 { return this->tls_type_
!= GOT_TLS_NONE
; }
531 // Return TLS type of this GOT entry.
534 { return this->tls_type_
; }
536 // Return section index of the local symbol for local GOT entries.
539 { return this->shndx_
; }
541 // Return whether this is a STT_SECTION symbol.
543 is_section_symbol() const
544 { return this->is_section_symbol_
; }
548 Mips_address addend_
;
550 // The index of the symbol if we have a local symbol; -1 otherwise.
551 unsigned int symndx_
;
555 // The input object for local symbols that needs the GOT entry.
556 Mips_relobj
<size
, big_endian
>* object
;
557 // If symndx == -1, the global symbol corresponding to this GOT entry. The
558 // symbol's entry is in the local area if mips_sym->global_got_area is
559 // GGA_NONE, otherwise it is in the global area.
560 Mips_symbol
<size
>* sym
;
563 // The TLS type of this GOT entry. An LDM GOT entry will be a local
564 // symbol entry with r_symndx == 0.
565 unsigned char tls_type_
;
567 // Whether this is a STT_SECTION symbol.
568 bool is_section_symbol_
;
570 // For local GOT entries, section index of the local symbol.
574 // Hash for Mips_got_entry.
576 template<int size
, bool big_endian
>
577 class Mips_got_entry_hash
581 operator()(Mips_got_entry
<size
, big_endian
>* entry
) const
582 { return entry
->hash(); }
585 // Equality for Mips_got_entry.
587 template<int size
, bool big_endian
>
588 class Mips_got_entry_eq
592 operator()(Mips_got_entry
<size
, big_endian
>* e1
,
593 Mips_got_entry
<size
, big_endian
>* e2
) const
594 { return e1
->equals(e2
); }
597 // Hash for Mips_symbol.
600 class Mips_symbol_hash
604 operator()(Mips_symbol
<size
>* sym
) const
605 { return sym
->hash(); }
608 // Got_page_range. This class describes a range of addends: [MIN_ADDEND,
609 // MAX_ADDEND]. The instances form a non-overlapping list that is sorted by
610 // increasing MIN_ADDEND.
612 struct Got_page_range
615 : next(NULL
), min_addend(0), max_addend(0)
618 Got_page_range
* next
;
622 // Return the maximum number of GOT page entries required.
625 { return (this->max_addend
- this->min_addend
+ 0x1ffff) >> 16; }
628 // Got_page_entry. This class describes the range of addends that are applied
629 // to page relocations against a given symbol.
631 struct Got_page_entry
634 : object(NULL
), symndx(-1U), ranges(NULL
), num_pages(0)
637 Got_page_entry(Object
* object_
, unsigned int symndx_
)
638 : object(object_
), symndx(symndx_
), ranges(NULL
), num_pages(0)
641 // The input object that needs the GOT page entry.
643 // The index of the symbol, as stored in the relocation r_info.
645 // The ranges for this page entry.
646 Got_page_range
* ranges
;
647 // The maximum number of page entries needed for RANGES.
648 unsigned int num_pages
;
651 // Hash for Got_page_entry.
653 struct Got_page_entry_hash
656 operator()(Got_page_entry
* entry
) const
657 { return reinterpret_cast<uintptr_t>(entry
->object
) + entry
->symndx
; }
660 // Equality for Got_page_entry.
662 struct Got_page_entry_eq
665 operator()(Got_page_entry
* entry1
, Got_page_entry
* entry2
) const
667 return entry1
->object
== entry2
->object
&& entry1
->symndx
== entry2
->symndx
;
671 // This class is used to hold .got information when linking.
673 template<int size
, bool big_endian
>
676 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
677 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
679 typedef Unordered_map
<unsigned int, unsigned int> Got_page_offsets
;
681 // Unordered set of GOT entries.
682 typedef Unordered_set
<Mips_got_entry
<size
, big_endian
>*,
683 Mips_got_entry_hash
<size
, big_endian
>,
684 Mips_got_entry_eq
<size
, big_endian
> > Got_entry_set
;
686 // Unordered set of GOT page entries.
687 typedef Unordered_set
<Got_page_entry
*,
688 Got_page_entry_hash
, Got_page_entry_eq
> Got_page_entry_set
;
690 // Unordered set of global GOT entries.
691 typedef Unordered_set
<Mips_symbol
<size
>*, Mips_symbol_hash
<size
> >
692 Global_got_entry_set
;
696 : local_gotno_(0), page_gotno_(0), global_gotno_(0), reloc_only_gotno_(0),
697 tls_gotno_(0), tls_ldm_offset_(-1U), global_got_symbols_(),
698 got_entries_(), got_page_entries_(), got_page_offset_start_(0),
699 got_page_offset_next_(0), got_page_offsets_(), next_(NULL
), index_(-1U),
703 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
704 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
706 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
707 unsigned int symndx
, Mips_address addend
,
708 unsigned int r_type
, unsigned int shndx
,
709 bool is_section_symbol
);
711 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
712 // in OBJECT. FOR_CALL is true if the caller is only interested in
713 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
716 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
717 Mips_relobj
<size
, big_endian
>* object
,
718 unsigned int r_type
, bool dyn_reloc
, bool for_call
);
720 // Add ENTRY to master GOT and to OBJECT's GOT.
722 record_got_entry(Mips_got_entry
<size
, big_endian
>* entry
,
723 Mips_relobj
<size
, big_endian
>* object
);
725 // Record that OBJECT has a page relocation against symbol SYMNDX and
726 // that ADDEND is the addend for that relocation.
728 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
729 unsigned int symndx
, int addend
);
731 // Create all entries that should be in the local part of the GOT.
733 add_local_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
735 // Create GOT page entries.
737 add_page_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
739 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
741 add_global_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
742 unsigned int non_reloc_only_global_gotno
);
744 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
746 add_reloc_only_entries(Mips_output_data_got
<size
, big_endian
>* got
);
748 // Create TLS GOT entries.
750 add_tls_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
752 // Decide whether the symbol needs an entry in the global part of the primary
753 // GOT, setting global_got_area accordingly. Count the number of global
754 // symbols that are in the primary GOT only because they have dynamic
755 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
757 count_got_symbols(Symbol_table
* symtab
);
759 // Return the offset of GOT page entry for VALUE.
761 get_got_page_offset(Mips_address value
,
762 Mips_output_data_got
<size
, big_endian
>* got
);
764 // Count the number of GOT entries required.
768 // Count the number of GOT entries required by ENTRY. Accumulate the result.
770 count_got_entry(Mips_got_entry
<size
, big_endian
>* entry
);
772 // Add FROM's GOT entries.
774 add_got_entries(Mips_got_info
<size
, big_endian
>* from
);
776 // Add FROM's GOT page entries.
778 add_got_page_entries(Mips_got_info
<size
, big_endian
>* from
);
783 { return ((2 + this->local_gotno_
+ this->page_gotno_
+ this->global_gotno_
784 + this->tls_gotno_
) * size
/8);
787 // Return the number of local GOT entries.
790 { return this->local_gotno_
; }
792 // Return the maximum number of page GOT entries needed.
795 { return this->page_gotno_
; }
797 // Return the number of global GOT entries.
800 { return this->global_gotno_
; }
802 // Set the number of global GOT entries.
804 set_global_gotno(unsigned int global_gotno
)
805 { this->global_gotno_
= global_gotno
; }
807 // Return the number of GGA_RELOC_ONLY global GOT entries.
809 reloc_only_gotno() const
810 { return this->reloc_only_gotno_
; }
812 // Return the number of TLS GOT entries.
815 { return this->tls_gotno_
; }
817 // Return the GOT type for this GOT. Used for multi-GOT links only.
819 multigot_got_type(unsigned int got_type
) const
823 case GOT_TYPE_STANDARD
:
824 return GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
825 case GOT_TYPE_TLS_OFFSET
:
826 return GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
827 case GOT_TYPE_TLS_PAIR
:
828 return GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
834 // Remove lazy-binding stubs for global symbols in this GOT.
836 remove_lazy_stubs(Target_mips
<size
, big_endian
>* target
);
838 // Return offset of this GOT from the start of .got section.
841 { return this->offset_
; }
843 // Set offset of this GOT from the start of .got section.
845 set_offset(unsigned int offset
)
846 { this->offset_
= offset
; }
848 // Set index of this GOT in multi-GOT links.
850 set_index(unsigned int index
)
851 { this->index_
= index
; }
853 // Return next GOT in multi-GOT links.
854 Mips_got_info
<size
, big_endian
>*
856 { return this->next_
; }
858 // Set next GOT in multi-GOT links.
860 set_next(Mips_got_info
<size
, big_endian
>* next
)
861 { this->next_
= next
; }
863 // Return the offset of TLS LDM entry for this GOT.
865 tls_ldm_offset() const
866 { return this->tls_ldm_offset_
; }
868 // Set the offset of TLS LDM entry for this GOT.
870 set_tls_ldm_offset(unsigned int tls_ldm_offset
)
871 { this->tls_ldm_offset_
= tls_ldm_offset
; }
873 Global_got_entry_set
&
875 { return this->global_got_symbols_
; }
877 // Return the GOT_TLS_* type required by relocation type R_TYPE.
879 mips_elf_reloc_tls_type(unsigned int r_type
)
881 if (tls_gd_reloc(r_type
))
884 if (tls_ldm_reloc(r_type
))
887 if (tls_gottprel_reloc(r_type
))
893 // Return the number of GOT slots needed for GOT TLS type TYPE.
895 mips_tls_got_entries(unsigned int type
)
915 // The number of local GOT entries.
916 unsigned int local_gotno_
;
917 // The maximum number of page GOT entries needed.
918 unsigned int page_gotno_
;
919 // The number of global GOT entries.
920 unsigned int global_gotno_
;
921 // The number of global GOT entries that are in the GGA_RELOC_ONLY area.
922 unsigned int reloc_only_gotno_
;
923 // The number of TLS GOT entries.
924 unsigned int tls_gotno_
;
925 // The offset of TLS LDM entry for this GOT.
926 unsigned int tls_ldm_offset_
;
927 // All symbols that have global GOT entry.
928 Global_got_entry_set global_got_symbols_
;
929 // A hash table holding GOT entries.
930 Got_entry_set got_entries_
;
931 // A hash table of GOT page entries.
932 Got_page_entry_set got_page_entries_
;
933 // The offset of first GOT page entry for this GOT.
934 unsigned int got_page_offset_start_
;
935 // The offset of next available GOT page entry for this GOT.
936 unsigned int got_page_offset_next_
;
937 // A hash table that maps GOT page entry value to the GOT offset where
938 // the entry is located.
939 Got_page_offsets got_page_offsets_
;
940 // In multi-GOT links, a pointer to the next GOT.
941 Mips_got_info
<size
, big_endian
>* next_
;
942 // Index of this GOT in multi-GOT links.
944 // The offset of this GOT in multi-GOT links.
945 unsigned int offset_
;
948 // This is a helper class used during relocation scan. It records GOT16 addend.
950 template<int size
, bool big_endian
>
953 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
955 got16_addend(const Sized_relobj_file
<size
, big_endian
>* _object
,
956 unsigned int _shndx
, unsigned int _r_type
, unsigned int _r_sym
,
957 Mips_address _addend
)
958 : object(_object
), shndx(_shndx
), r_type(_r_type
), r_sym(_r_sym
),
962 const Sized_relobj_file
<size
, big_endian
>* object
;
969 // .MIPS.abiflags section content
971 template<bool big_endian
>
974 typedef typename
elfcpp::Swap
<8, big_endian
>::Valtype Valtype8
;
975 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype16
;
976 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
979 : version(0), isa_level(0), isa_rev(0), gpr_size(0), cpr1_size(0),
980 cpr2_size(0), fp_abi(0), isa_ext(0), ases(0), flags1(0), flags2(0)
983 // Version of flags structure.
985 // The level of the ISA: 1-5, 32, 64.
987 // The revision of ISA: 0 for MIPS V and below, 1-n otherwise.
989 // The size of general purpose registers.
991 // The size of co-processor 1 registers.
993 // The size of co-processor 2 registers.
995 // The floating-point ABI.
997 // Processor-specific extension.
999 // Mask of ASEs used.
1001 // Mask of general flags.
1006 // Mips_symbol class. Holds additional symbol information needed for Mips.
1009 class Mips_symbol
: public Sized_symbol
<size
>
1013 : need_fn_stub_(false), has_nonpic_branches_(false), la25_stub_offset_(-1U),
1014 has_static_relocs_(false), no_lazy_stub_(false), lazy_stub_offset_(0),
1015 pointer_equality_needed_(false), global_got_area_(GGA_NONE
),
1016 global_gotoffset_(-1U), got_only_for_calls_(true), has_lazy_stub_(false),
1017 needs_mips_plt_(false), needs_comp_plt_(false), mips_plt_offset_(-1U),
1018 comp_plt_offset_(-1U), mips16_fn_stub_(NULL
), mips16_call_stub_(NULL
),
1019 mips16_call_fp_stub_(NULL
), applied_secondary_got_fixup_(false)
1022 // Return whether this is a MIPS16 symbol.
1026 // (st_other & STO_MIPS16) == STO_MIPS16
1027 return ((this->nonvis() & (elfcpp::STO_MIPS16
>> 2))
1028 == elfcpp::STO_MIPS16
>> 2);
1031 // Return whether this is a microMIPS symbol.
1033 is_micromips() const
1035 // (st_other & STO_MIPS_ISA) == STO_MICROMIPS
1036 return ((this->nonvis() & (elfcpp::STO_MIPS_ISA
>> 2))
1037 == elfcpp::STO_MICROMIPS
>> 2);
1040 // Return whether the symbol needs MIPS16 fn_stub.
1042 need_fn_stub() const
1043 { return this->need_fn_stub_
; }
1045 // Set that the symbol needs MIPS16 fn_stub.
1048 { this->need_fn_stub_
= true; }
1050 // Return whether this symbol is referenced by branch relocations from
1051 // any non-PIC input file.
1053 has_nonpic_branches() const
1054 { return this->has_nonpic_branches_
; }
1056 // Set that this symbol is referenced by branch relocations from
1057 // any non-PIC input file.
1059 set_has_nonpic_branches()
1060 { this->has_nonpic_branches_
= true; }
1062 // Return the offset of the la25 stub for this symbol from the start of the
1063 // la25 stub section.
1065 la25_stub_offset() const
1066 { return this->la25_stub_offset_
; }
1068 // Set the offset of the la25 stub for this symbol from the start of the
1069 // la25 stub section.
1071 set_la25_stub_offset(unsigned int offset
)
1072 { this->la25_stub_offset_
= offset
; }
1074 // Return whether the symbol has la25 stub. This is true if this symbol is
1075 // for a PIC function, and there are non-PIC branches and jumps to it.
1077 has_la25_stub() const
1078 { return this->la25_stub_offset_
!= -1U; }
1080 // Return whether there is a relocation against this symbol that must be
1081 // resolved by the static linker (that is, the relocation cannot possibly
1082 // be made dynamic).
1084 has_static_relocs() const
1085 { return this->has_static_relocs_
; }
1087 // Set that there is a relocation against this symbol that must be resolved
1088 // by the static linker (that is, the relocation cannot possibly be made
1091 set_has_static_relocs()
1092 { this->has_static_relocs_
= true; }
1094 // Return whether we must not create a lazy-binding stub for this symbol.
1096 no_lazy_stub() const
1097 { return this->no_lazy_stub_
; }
1099 // Set that we must not create a lazy-binding stub for this symbol.
1102 { this->no_lazy_stub_
= true; }
1104 // Return the offset of the lazy-binding stub for this symbol from the start
1105 // of .MIPS.stubs section.
1107 lazy_stub_offset() const
1108 { return this->lazy_stub_offset_
; }
1110 // Set the offset of the lazy-binding stub for this symbol from the start
1111 // of .MIPS.stubs section.
1113 set_lazy_stub_offset(unsigned int offset
)
1114 { this->lazy_stub_offset_
= offset
; }
1116 // Return whether there are any relocations for this symbol where
1117 // pointer equality matters.
1119 pointer_equality_needed() const
1120 { return this->pointer_equality_needed_
; }
1122 // Set that there are relocations for this symbol where pointer equality
1125 set_pointer_equality_needed()
1126 { this->pointer_equality_needed_
= true; }
1128 // Return global GOT area where this symbol in located.
1130 global_got_area() const
1131 { return this->global_got_area_
; }
1133 // Set global GOT area where this symbol in located.
1135 set_global_got_area(Global_got_area global_got_area
)
1136 { this->global_got_area_
= global_got_area
; }
1138 // Return the global GOT offset for this symbol. For multi-GOT links, this
1139 // returns the offset from the start of .got section to the first GOT entry
1140 // for the symbol. Note that in multi-GOT links the symbol can have entry
1141 // in more than one GOT.
1143 global_gotoffset() const
1144 { return this->global_gotoffset_
; }
1146 // Set the global GOT offset for this symbol. Note that in multi-GOT links
1147 // the symbol can have entry in more than one GOT. This method will set
1148 // the offset only if it is less than current offset.
1150 set_global_gotoffset(unsigned int offset
)
1152 if (this->global_gotoffset_
== -1U || offset
< this->global_gotoffset_
)
1153 this->global_gotoffset_
= offset
;
1156 // Return whether all GOT relocations for this symbol are for calls.
1158 got_only_for_calls() const
1159 { return this->got_only_for_calls_
; }
1161 // Set that there is a GOT relocation for this symbol that is not for call.
1163 set_got_not_only_for_calls()
1164 { this->got_only_for_calls_
= false; }
1166 // Return whether this is a PIC symbol.
1170 // (st_other & STO_MIPS_FLAGS) == STO_MIPS_PIC
1171 return ((this->nonvis() & (elfcpp::STO_MIPS_FLAGS
>> 2))
1172 == (elfcpp::STO_MIPS_PIC
>> 2));
1175 // Set the flag in st_other field that marks this symbol as PIC.
1179 if (this->is_mips16())
1180 // (st_other & ~(STO_MIPS16 | STO_MIPS_FLAGS)) | STO_MIPS_PIC
1181 this->set_nonvis((this->nonvis()
1182 & ~((elfcpp::STO_MIPS16
>> 2)
1183 | (elfcpp::STO_MIPS_FLAGS
>> 2)))
1184 | (elfcpp::STO_MIPS_PIC
>> 2));
1186 // (other & ~STO_MIPS_FLAGS) | STO_MIPS_PIC
1187 this->set_nonvis((this->nonvis() & ~(elfcpp::STO_MIPS_FLAGS
>> 2))
1188 | (elfcpp::STO_MIPS_PIC
>> 2));
1191 // Set the flag in st_other field that marks this symbol as PLT.
1195 if (this->is_mips16())
1196 // (st_other & (STO_MIPS16 | ~STO_MIPS_FLAGS)) | STO_MIPS_PLT
1197 this->set_nonvis((this->nonvis()
1198 & ((elfcpp::STO_MIPS16
>> 2)
1199 | ~(elfcpp::STO_MIPS_FLAGS
>> 2)))
1200 | (elfcpp::STO_MIPS_PLT
>> 2));
1203 // (st_other & ~STO_MIPS_FLAGS) | STO_MIPS_PLT
1204 this->set_nonvis((this->nonvis() & ~(elfcpp::STO_MIPS_FLAGS
>> 2))
1205 | (elfcpp::STO_MIPS_PLT
>> 2));
1208 // Downcast a base pointer to a Mips_symbol pointer.
1209 static Mips_symbol
<size
>*
1210 as_mips_sym(Symbol
* sym
)
1211 { return static_cast<Mips_symbol
<size
>*>(sym
); }
1213 // Downcast a base pointer to a Mips_symbol pointer.
1214 static const Mips_symbol
<size
>*
1215 as_mips_sym(const Symbol
* sym
)
1216 { return static_cast<const Mips_symbol
<size
>*>(sym
); }
1218 // Return whether the symbol has lazy-binding stub.
1220 has_lazy_stub() const
1221 { return this->has_lazy_stub_
; }
1223 // Set whether the symbol has lazy-binding stub.
1225 set_has_lazy_stub(bool has_lazy_stub
)
1226 { this->has_lazy_stub_
= has_lazy_stub
; }
1228 // Return whether the symbol needs a standard PLT entry.
1230 needs_mips_plt() const
1231 { return this->needs_mips_plt_
; }
1233 // Set whether the symbol needs a standard PLT entry.
1235 set_needs_mips_plt(bool needs_mips_plt
)
1236 { this->needs_mips_plt_
= needs_mips_plt
; }
1238 // Return whether the symbol needs a compressed (MIPS16 or microMIPS) PLT
1241 needs_comp_plt() const
1242 { return this->needs_comp_plt_
; }
1244 // Set whether the symbol needs a compressed (MIPS16 or microMIPS) PLT entry.
1246 set_needs_comp_plt(bool needs_comp_plt
)
1247 { this->needs_comp_plt_
= needs_comp_plt
; }
1249 // Return standard PLT entry offset, or -1 if none.
1251 mips_plt_offset() const
1252 { return this->mips_plt_offset_
; }
1254 // Set standard PLT entry offset.
1256 set_mips_plt_offset(unsigned int mips_plt_offset
)
1257 { this->mips_plt_offset_
= mips_plt_offset
; }
1259 // Return whether the symbol has standard PLT entry.
1261 has_mips_plt_offset() const
1262 { return this->mips_plt_offset_
!= -1U; }
1264 // Return compressed (MIPS16 or microMIPS) PLT entry offset, or -1 if none.
1266 comp_plt_offset() const
1267 { return this->comp_plt_offset_
; }
1269 // Set compressed (MIPS16 or microMIPS) PLT entry offset.
1271 set_comp_plt_offset(unsigned int comp_plt_offset
)
1272 { this->comp_plt_offset_
= comp_plt_offset
; }
1274 // Return whether the symbol has compressed (MIPS16 or microMIPS) PLT entry.
1276 has_comp_plt_offset() const
1277 { return this->comp_plt_offset_
!= -1U; }
1279 // Return MIPS16 fn stub for a symbol.
1280 template<bool big_endian
>
1281 Mips16_stub_section
<size
, big_endian
>*
1282 get_mips16_fn_stub() const
1284 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(mips16_fn_stub_
);
1287 // Set MIPS16 fn stub for a symbol.
1289 set_mips16_fn_stub(Mips16_stub_section_base
* stub
)
1290 { this->mips16_fn_stub_
= stub
; }
1292 // Return whether symbol has MIPS16 fn stub.
1294 has_mips16_fn_stub() const
1295 { return this->mips16_fn_stub_
!= NULL
; }
1297 // Return MIPS16 call stub for a symbol.
1298 template<bool big_endian
>
1299 Mips16_stub_section
<size
, big_endian
>*
1300 get_mips16_call_stub() const
1302 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(
1306 // Set MIPS16 call stub for a symbol.
1308 set_mips16_call_stub(Mips16_stub_section_base
* stub
)
1309 { this->mips16_call_stub_
= stub
; }
1311 // Return whether symbol has MIPS16 call stub.
1313 has_mips16_call_stub() const
1314 { return this->mips16_call_stub_
!= NULL
; }
1316 // Return MIPS16 call_fp stub for a symbol.
1317 template<bool big_endian
>
1318 Mips16_stub_section
<size
, big_endian
>*
1319 get_mips16_call_fp_stub() const
1321 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(
1322 mips16_call_fp_stub_
);
1325 // Set MIPS16 call_fp stub for a symbol.
1327 set_mips16_call_fp_stub(Mips16_stub_section_base
* stub
)
1328 { this->mips16_call_fp_stub_
= stub
; }
1330 // Return whether symbol has MIPS16 call_fp stub.
1332 has_mips16_call_fp_stub() const
1333 { return this->mips16_call_fp_stub_
!= NULL
; }
1336 get_applied_secondary_got_fixup() const
1337 { return applied_secondary_got_fixup_
; }
1340 set_applied_secondary_got_fixup()
1341 { this->applied_secondary_got_fixup_
= true; }
1343 // Return the hash of this symbol.
1347 return gold::string_hash
<char>(this->name());
1351 // Whether the symbol needs MIPS16 fn_stub. This is true if this symbol
1352 // appears in any relocs other than a 16 bit call.
1355 // True if this symbol is referenced by branch relocations from
1356 // any non-PIC input file. This is used to determine whether an
1357 // la25 stub is required.
1358 bool has_nonpic_branches_
;
1360 // The offset of the la25 stub for this symbol from the start of the
1361 // la25 stub section.
1362 unsigned int la25_stub_offset_
;
1364 // True if there is a relocation against this symbol that must be
1365 // resolved by the static linker (that is, the relocation cannot
1366 // possibly be made dynamic).
1367 bool has_static_relocs_
;
1369 // Whether we must not create a lazy-binding stub for this symbol.
1370 // This is true if the symbol has relocations related to taking the
1371 // function's address.
1374 // The offset of the lazy-binding stub for this symbol from the start of
1375 // .MIPS.stubs section.
1376 unsigned int lazy_stub_offset_
;
1378 // True if there are any relocations for this symbol where pointer equality
1380 bool pointer_equality_needed_
;
1382 // Global GOT area where this symbol in located, or GGA_NONE if symbol is not
1383 // in the global part of the GOT.
1384 Global_got_area global_got_area_
;
1386 // The global GOT offset for this symbol. For multi-GOT links, this is offset
1387 // from the start of .got section to the first GOT entry for the symbol.
1388 // Note that in multi-GOT links the symbol can have entry in more than one GOT.
1389 unsigned int global_gotoffset_
;
1391 // Whether all GOT relocations for this symbol are for calls.
1392 bool got_only_for_calls_
;
1393 // Whether the symbol has lazy-binding stub.
1394 bool has_lazy_stub_
;
1395 // Whether the symbol needs a standard PLT entry.
1396 bool needs_mips_plt_
;
1397 // Whether the symbol needs a compressed (MIPS16 or microMIPS) PLT entry.
1398 bool needs_comp_plt_
;
1399 // Standard PLT entry offset, or -1 if none.
1400 unsigned int mips_plt_offset_
;
1401 // Compressed (MIPS16 or microMIPS) PLT entry offset, or -1 if none.
1402 unsigned int comp_plt_offset_
;
1403 // MIPS16 fn stub for a symbol.
1404 Mips16_stub_section_base
* mips16_fn_stub_
;
1405 // MIPS16 call stub for a symbol.
1406 Mips16_stub_section_base
* mips16_call_stub_
;
1407 // MIPS16 call_fp stub for a symbol.
1408 Mips16_stub_section_base
* mips16_call_fp_stub_
;
1410 bool applied_secondary_got_fixup_
;
1413 // Mips16_stub_section class.
1415 // The mips16 compiler uses a couple of special sections to handle
1416 // floating point arguments.
1418 // Section names that look like .mips16.fn.FNNAME contain stubs that
1419 // copy floating point arguments from the fp regs to the gp regs and
1420 // then jump to FNNAME. If any 32 bit function calls FNNAME, the
1421 // call should be redirected to the stub instead. If no 32 bit
1422 // function calls FNNAME, the stub should be discarded. We need to
1423 // consider any reference to the function, not just a call, because
1424 // if the address of the function is taken we will need the stub,
1425 // since the address might be passed to a 32 bit function.
1427 // Section names that look like .mips16.call.FNNAME contain stubs
1428 // that copy floating point arguments from the gp regs to the fp
1429 // regs and then jump to FNNAME. If FNNAME is a 32 bit function,
1430 // then any 16 bit function that calls FNNAME should be redirected
1431 // to the stub instead. If FNNAME is not a 32 bit function, the
1432 // stub should be discarded.
1434 // .mips16.call.fp.FNNAME sections are similar, but contain stubs
1435 // which call FNNAME and then copy the return value from the fp regs
1436 // to the gp regs. These stubs store the return address in $18 while
1437 // calling FNNAME; any function which might call one of these stubs
1438 // must arrange to save $18 around the call. (This case is not
1439 // needed for 32 bit functions that call 16 bit functions, because
1440 // 16 bit functions always return floating point values in both
1441 // $f0/$f1 and $2/$3.)
1443 // Note that in all cases FNNAME might be defined statically.
1444 // Therefore, FNNAME is not used literally. Instead, the relocation
1445 // information will indicate which symbol the section is for.
1447 // We record any stubs that we find in the symbol table.
1449 // TODO(sasa): All mips16 stub sections should be emitted in the .text section.
1451 class Mips16_stub_section_base
{ };
1453 template<int size
, bool big_endian
>
1454 class Mips16_stub_section
: public Mips16_stub_section_base
1456 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1459 Mips16_stub_section(Mips_relobj
<size
, big_endian
>* object
, unsigned int shndx
)
1460 : object_(object
), shndx_(shndx
), r_sym_(0), gsym_(NULL
),
1461 found_r_mips_none_(false)
1463 gold_assert(object
->is_mips16_fn_stub_section(shndx
)
1464 || object
->is_mips16_call_stub_section(shndx
)
1465 || object
->is_mips16_call_fp_stub_section(shndx
));
1468 // Return the object of this stub section.
1469 Mips_relobj
<size
, big_endian
>*
1471 { return this->object_
; }
1473 // Return the size of a section.
1475 section_size() const
1476 { return this->object_
->section_size(this->shndx_
); }
1478 // Return section index of this stub section.
1481 { return this->shndx_
; }
1483 // Return symbol index, if stub is for a local function.
1486 { return this->r_sym_
; }
1488 // Return symbol, if stub is for a global function.
1491 { return this->gsym_
; }
1493 // Return whether stub is for a local function.
1495 is_for_local_function() const
1496 { return this->gsym_
== NULL
; }
1498 // This method is called when a new relocation R_TYPE for local symbol R_SYM
1499 // is found in the stub section. Try to find stub target.
1501 new_local_reloc_found(unsigned int r_type
, unsigned int r_sym
)
1503 // To find target symbol for this stub, trust the first R_MIPS_NONE
1504 // relocation, if any. Otherwise trust the first relocation, whatever
1506 if (this->found_r_mips_none_
)
1508 if (r_type
== elfcpp::R_MIPS_NONE
)
1510 this->r_sym_
= r_sym
;
1512 this->found_r_mips_none_
= true;
1514 else if (!is_target_found())
1515 this->r_sym_
= r_sym
;
1518 // This method is called when a new relocation R_TYPE for global symbol GSYM
1519 // is found in the stub section. Try to find stub target.
1521 new_global_reloc_found(unsigned int r_type
, Mips_symbol
<size
>* gsym
)
1523 // To find target symbol for this stub, trust the first R_MIPS_NONE
1524 // relocation, if any. Otherwise trust the first relocation, whatever
1526 if (this->found_r_mips_none_
)
1528 if (r_type
== elfcpp::R_MIPS_NONE
)
1532 this->found_r_mips_none_
= true;
1534 else if (!is_target_found())
1538 // Return whether we found the stub target.
1540 is_target_found() const
1541 { return this->r_sym_
!= 0 || this->gsym_
!= NULL
; }
1543 // Return whether this is a fn stub.
1546 { return this->object_
->is_mips16_fn_stub_section(this->shndx_
); }
1548 // Return whether this is a call stub.
1550 is_call_stub() const
1551 { return this->object_
->is_mips16_call_stub_section(this->shndx_
); }
1553 // Return whether this is a call_fp stub.
1555 is_call_fp_stub() const
1556 { return this->object_
->is_mips16_call_fp_stub_section(this->shndx_
); }
1558 // Return the output address.
1560 output_address() const
1562 return (this->object_
->output_section(this->shndx_
)->address()
1563 + this->object_
->output_section_offset(this->shndx_
));
1567 // The object of this stub section.
1568 Mips_relobj
<size
, big_endian
>* object_
;
1569 // The section index of this stub section.
1570 unsigned int shndx_
;
1571 // The symbol index, if stub is for a local function.
1572 unsigned int r_sym_
;
1573 // The symbol, if stub is for a global function.
1574 Mips_symbol
<size
>* gsym_
;
1575 // True if we found R_MIPS_NONE relocation in this stub.
1576 bool found_r_mips_none_
;
1579 // Mips_relobj class.
1581 template<int size
, bool big_endian
>
1582 class Mips_relobj
: public Sized_relobj_file
<size
, big_endian
>
1584 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1585 typedef std::map
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>
1586 Mips16_stubs_int_map
;
1587 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1590 Mips_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
1591 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1592 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
1593 processor_specific_flags_(0), local_symbol_is_mips16_(),
1594 local_symbol_is_micromips_(), mips16_stub_sections_(),
1595 local_non_16bit_calls_(), local_16bit_calls_(), local_mips16_fn_stubs_(),
1596 local_mips16_call_stubs_(), gp_(0), has_reginfo_section_(false),
1597 merge_processor_specific_data_(true), got_info_(NULL
),
1598 section_is_mips16_fn_stub_(), section_is_mips16_call_stub_(),
1599 section_is_mips16_call_fp_stub_(), pdr_shndx_(-1U),
1600 attributes_section_data_(NULL
), abiflags_(NULL
), gprmask_(0),
1601 cprmask1_(0), cprmask2_(0), cprmask3_(0), cprmask4_(0)
1603 this->is_pic_
= (ehdr
.get_e_flags() & elfcpp::EF_MIPS_PIC
) != 0;
1604 this->is_n32_
= elfcpp::abi_n32(ehdr
.get_e_flags());
1608 { delete this->attributes_section_data_
; }
1610 // Downcast a base pointer to a Mips_relobj pointer. This is
1611 // not type-safe but we only use Mips_relobj not the base class.
1612 static Mips_relobj
<size
, big_endian
>*
1613 as_mips_relobj(Relobj
* relobj
)
1614 { return static_cast<Mips_relobj
<size
, big_endian
>*>(relobj
); }
1616 // Downcast a base pointer to a Mips_relobj pointer. This is
1617 // not type-safe but we only use Mips_relobj not the base class.
1618 static const Mips_relobj
<size
, big_endian
>*
1619 as_mips_relobj(const Relobj
* relobj
)
1620 { return static_cast<const Mips_relobj
<size
, big_endian
>*>(relobj
); }
1622 // Processor-specific flags in ELF file header. This is valid only after
1625 processor_specific_flags() const
1626 { return this->processor_specific_flags_
; }
1628 // Whether a local symbol is MIPS16 symbol. R_SYM is the symbol table
1629 // index. This is only valid after do_count_local_symbol is called.
1631 local_symbol_is_mips16(unsigned int r_sym
) const
1633 gold_assert(r_sym
< this->local_symbol_is_mips16_
.size());
1634 return this->local_symbol_is_mips16_
[r_sym
];
1637 // Whether a local symbol is microMIPS symbol. R_SYM is the symbol table
1638 // index. This is only valid after do_count_local_symbol is called.
1640 local_symbol_is_micromips(unsigned int r_sym
) const
1642 gold_assert(r_sym
< this->local_symbol_is_micromips_
.size());
1643 return this->local_symbol_is_micromips_
[r_sym
];
1646 // Get or create MIPS16 stub section.
1647 Mips16_stub_section
<size
, big_endian
>*
1648 get_mips16_stub_section(unsigned int shndx
)
1650 typename
Mips16_stubs_int_map::const_iterator it
=
1651 this->mips16_stub_sections_
.find(shndx
);
1652 if (it
!= this->mips16_stub_sections_
.end())
1653 return (*it
).second
;
1655 Mips16_stub_section
<size
, big_endian
>* stub_section
=
1656 new Mips16_stub_section
<size
, big_endian
>(this, shndx
);
1657 this->mips16_stub_sections_
.insert(
1658 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1659 stub_section
->shndx(), stub_section
));
1660 return stub_section
;
1663 // Return MIPS16 fn stub section for local symbol R_SYM, or NULL if this
1664 // object doesn't have fn stub for R_SYM.
1665 Mips16_stub_section
<size
, big_endian
>*
1666 get_local_mips16_fn_stub(unsigned int r_sym
) const
1668 typename
Mips16_stubs_int_map::const_iterator it
=
1669 this->local_mips16_fn_stubs_
.find(r_sym
);
1670 if (it
!= this->local_mips16_fn_stubs_
.end())
1671 return (*it
).second
;
1675 // Record that this object has MIPS16 fn stub for local symbol. This method
1676 // is only called if we decided not to discard the stub.
1678 add_local_mips16_fn_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1680 gold_assert(stub
->is_for_local_function());
1681 unsigned int r_sym
= stub
->r_sym();
1682 this->local_mips16_fn_stubs_
.insert(
1683 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1687 // Return MIPS16 call stub section for local symbol R_SYM, or NULL if this
1688 // object doesn't have call stub for R_SYM.
1689 Mips16_stub_section
<size
, big_endian
>*
1690 get_local_mips16_call_stub(unsigned int r_sym
) const
1692 typename
Mips16_stubs_int_map::const_iterator it
=
1693 this->local_mips16_call_stubs_
.find(r_sym
);
1694 if (it
!= this->local_mips16_call_stubs_
.end())
1695 return (*it
).second
;
1699 // Record that this object has MIPS16 call stub for local symbol. This method
1700 // is only called if we decided not to discard the stub.
1702 add_local_mips16_call_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1704 gold_assert(stub
->is_for_local_function());
1705 unsigned int r_sym
= stub
->r_sym();
1706 this->local_mips16_call_stubs_
.insert(
1707 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1711 // Record that we found "non 16-bit" call relocation against local symbol
1712 // SYMNDX. This reloc would need to refer to a MIPS16 fn stub, if there
1715 add_local_non_16bit_call(unsigned int symndx
)
1716 { this->local_non_16bit_calls_
.insert(symndx
); }
1718 // Return true if there is any "non 16-bit" call relocation against local
1719 // symbol SYMNDX in this object.
1721 has_local_non_16bit_call_relocs(unsigned int symndx
)
1723 return (this->local_non_16bit_calls_
.find(symndx
)
1724 != this->local_non_16bit_calls_
.end());
1727 // Record that we found 16-bit call relocation R_MIPS16_26 against local
1728 // symbol SYMNDX. Local MIPS16 call or call_fp stubs will only be needed
1729 // if there is some R_MIPS16_26 relocation that refers to the stub symbol.
1731 add_local_16bit_call(unsigned int symndx
)
1732 { this->local_16bit_calls_
.insert(symndx
); }
1734 // Return true if there is any 16-bit call relocation R_MIPS16_26 against local
1735 // symbol SYMNDX in this object.
1737 has_local_16bit_call_relocs(unsigned int symndx
)
1739 return (this->local_16bit_calls_
.find(symndx
)
1740 != this->local_16bit_calls_
.end());
1743 // Get gp value that was used to create this object.
1746 { return this->gp_
; }
1748 // Return whether the object is a PIC object.
1751 { return this->is_pic_
; }
1753 // Return whether the object uses N32 ABI.
1756 { return this->is_n32_
; }
1758 // Return whether the object uses N64 ABI.
1761 { return size
== 64; }
1763 // Return whether the object uses NewABI conventions.
1766 { return this->is_n32() || this->is_n64(); }
1768 // Return Mips_got_info for this object.
1769 Mips_got_info
<size
, big_endian
>*
1770 get_got_info() const
1771 { return this->got_info_
; }
1773 // Return Mips_got_info for this object. Create new info if it doesn't exist.
1774 Mips_got_info
<size
, big_endian
>*
1775 get_or_create_got_info()
1777 if (!this->got_info_
)
1778 this->got_info_
= new Mips_got_info
<size
, big_endian
>();
1779 return this->got_info_
;
1782 // Set Mips_got_info for this object.
1784 set_got_info(Mips_got_info
<size
, big_endian
>* got_info
)
1785 { this->got_info_
= got_info
; }
1787 // Whether a section SHDNX is a MIPS16 stub section. This is only valid
1788 // after do_read_symbols is called.
1790 is_mips16_stub_section(unsigned int shndx
)
1792 return (is_mips16_fn_stub_section(shndx
)
1793 || is_mips16_call_stub_section(shndx
)
1794 || is_mips16_call_fp_stub_section(shndx
));
1797 // Return TRUE if relocations in section SHNDX can refer directly to a
1798 // MIPS16 function rather than to a hard-float stub. This is only valid
1799 // after do_read_symbols is called.
1801 section_allows_mips16_refs(unsigned int shndx
)
1803 return (this->is_mips16_stub_section(shndx
) || shndx
== this->pdr_shndx_
);
1806 // Whether a section SHDNX is a MIPS16 fn stub section. This is only valid
1807 // after do_read_symbols is called.
1809 is_mips16_fn_stub_section(unsigned int shndx
)
1811 gold_assert(shndx
< this->section_is_mips16_fn_stub_
.size());
1812 return this->section_is_mips16_fn_stub_
[shndx
];
1815 // Whether a section SHDNX is a MIPS16 call stub section. This is only valid
1816 // after do_read_symbols is called.
1818 is_mips16_call_stub_section(unsigned int shndx
)
1820 gold_assert(shndx
< this->section_is_mips16_call_stub_
.size());
1821 return this->section_is_mips16_call_stub_
[shndx
];
1824 // Whether a section SHDNX is a MIPS16 call_fp stub section. This is only
1825 // valid after do_read_symbols is called.
1827 is_mips16_call_fp_stub_section(unsigned int shndx
)
1829 gold_assert(shndx
< this->section_is_mips16_call_fp_stub_
.size());
1830 return this->section_is_mips16_call_fp_stub_
[shndx
];
1833 // Discard MIPS16 stub secions that are not needed.
1835 discard_mips16_stub_sections(Symbol_table
* symtab
);
1837 // Return whether there is a .reginfo section.
1839 has_reginfo_section() const
1840 { return this->has_reginfo_section_
; }
1842 // Return whether we want to merge processor-specific data.
1844 merge_processor_specific_data() const
1845 { return this->merge_processor_specific_data_
; }
1847 // Return gprmask from the .reginfo section of this object.
1850 { return this->gprmask_
; }
1852 // Return cprmask1 from the .reginfo section of this object.
1855 { return this->cprmask1_
; }
1857 // Return cprmask2 from the .reginfo section of this object.
1860 { return this->cprmask2_
; }
1862 // Return cprmask3 from the .reginfo section of this object.
1865 { return this->cprmask3_
; }
1867 // Return cprmask4 from the .reginfo section of this object.
1870 { return this->cprmask4_
; }
1872 // This is the contents of the .MIPS.abiflags section if there is one.
1873 Mips_abiflags
<big_endian
>*
1875 { return this->abiflags_
; }
1877 // This is the contents of the .gnu.attribute section if there is one.
1878 const Attributes_section_data
*
1879 attributes_section_data() const
1880 { return this->attributes_section_data_
; }
1883 // Count the local symbols.
1885 do_count_local_symbols(Stringpool_template
<char>*,
1886 Stringpool_template
<char>*);
1888 // Read the symbol information.
1890 do_read_symbols(Read_symbols_data
* sd
);
1893 // The name of the options section.
1894 const char* mips_elf_options_section_name()
1895 { return this->is_newabi() ? ".MIPS.options" : ".options"; }
1897 // processor-specific flags in ELF file header.
1898 elfcpp::Elf_Word processor_specific_flags_
;
1900 // Bit vector to tell if a local symbol is a MIPS16 symbol or not.
1901 // This is only valid after do_count_local_symbol is called.
1902 std::vector
<bool> local_symbol_is_mips16_
;
1904 // Bit vector to tell if a local symbol is a microMIPS symbol or not.
1905 // This is only valid after do_count_local_symbol is called.
1906 std::vector
<bool> local_symbol_is_micromips_
;
1908 // Map from section index to the MIPS16 stub for that section. This contains
1909 // all stubs found in this object.
1910 Mips16_stubs_int_map mips16_stub_sections_
;
1912 // Local symbols that have "non 16-bit" call relocation. This relocation
1913 // would need to refer to a MIPS16 fn stub, if there is one.
1914 std::set
<unsigned int> local_non_16bit_calls_
;
1916 // Local symbols that have 16-bit call relocation R_MIPS16_26. Local MIPS16
1917 // call or call_fp stubs will only be needed if there is some R_MIPS16_26
1918 // relocation that refers to the stub symbol.
1919 std::set
<unsigned int> local_16bit_calls_
;
1921 // Map from local symbol index to the MIPS16 fn stub for that symbol.
1922 // This contains only the stubs that we decided not to discard.
1923 Mips16_stubs_int_map local_mips16_fn_stubs_
;
1925 // Map from local symbol index to the MIPS16 call stub for that symbol.
1926 // This contains only the stubs that we decided not to discard.
1927 Mips16_stubs_int_map local_mips16_call_stubs_
;
1929 // gp value that was used to create this object.
1931 // Whether the object is a PIC object.
1933 // Whether the object uses N32 ABI.
1935 // Whether the object contains a .reginfo section.
1936 bool has_reginfo_section_
: 1;
1937 // Whether we merge processor-specific data of this object to output.
1938 bool merge_processor_specific_data_
: 1;
1939 // The Mips_got_info for this object.
1940 Mips_got_info
<size
, big_endian
>* got_info_
;
1942 // Bit vector to tell if a section is a MIPS16 fn stub section or not.
1943 // This is only valid after do_read_symbols is called.
1944 std::vector
<bool> section_is_mips16_fn_stub_
;
1946 // Bit vector to tell if a section is a MIPS16 call stub section or not.
1947 // This is only valid after do_read_symbols is called.
1948 std::vector
<bool> section_is_mips16_call_stub_
;
1950 // Bit vector to tell if a section is a MIPS16 call_fp stub section or not.
1951 // This is only valid after do_read_symbols is called.
1952 std::vector
<bool> section_is_mips16_call_fp_stub_
;
1954 // .pdr section index.
1955 unsigned int pdr_shndx_
;
1957 // Object attributes if there is a .gnu.attributes section or NULL.
1958 Attributes_section_data
* attributes_section_data_
;
1960 // Object abiflags if there is a .MIPS.abiflags section or NULL.
1961 Mips_abiflags
<big_endian
>* abiflags_
;
1963 // gprmask from the .reginfo section of this object.
1965 // cprmask1 from the .reginfo section of this object.
1967 // cprmask2 from the .reginfo section of this object.
1969 // cprmask3 from the .reginfo section of this object.
1971 // cprmask4 from the .reginfo section of this object.
1975 // Mips_output_data_got class.
1977 template<int size
, bool big_endian
>
1978 class Mips_output_data_got
: public Output_data_got
<size
, big_endian
>
1980 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1981 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
1983 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1986 Mips_output_data_got(Target_mips
<size
, big_endian
>* target
,
1987 Symbol_table
* symtab
, Layout
* layout
)
1988 : Output_data_got
<size
, big_endian
>(), target_(target
),
1989 symbol_table_(symtab
), layout_(layout
), static_relocs_(), got_view_(NULL
),
1990 first_global_got_dynsym_index_(-1U), primary_got_(NULL
),
1991 secondary_got_relocs_()
1993 this->master_got_info_
= new Mips_got_info
<size
, big_endian
>();
1994 this->set_addralign(16);
1997 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
1998 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
2000 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
2001 unsigned int symndx
, Mips_address addend
,
2002 unsigned int r_type
, unsigned int shndx
,
2003 bool is_section_symbol
)
2005 this->master_got_info_
->record_local_got_symbol(object
, symndx
, addend
,
2010 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
2011 // in OBJECT. FOR_CALL is true if the caller is only interested in
2012 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
2015 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
2016 Mips_relobj
<size
, big_endian
>* object
,
2017 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
2019 this->master_got_info_
->record_global_got_symbol(mips_sym
, object
, r_type
,
2020 dyn_reloc
, for_call
);
2023 // Record that OBJECT has a page relocation against symbol SYMNDX and
2024 // that ADDEND is the addend for that relocation.
2026 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
2027 unsigned int symndx
, int addend
)
2028 { this->master_got_info_
->record_got_page_entry(object
, symndx
, addend
); }
2030 // Add a static entry for the GOT entry at OFFSET. GSYM is a global
2031 // symbol and R_TYPE is the code of a dynamic relocation that needs to be
2032 // applied in a static link.
2034 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
2035 Mips_symbol
<size
>* gsym
)
2036 { this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, gsym
)); }
2038 // Add a static reloc for the GOT entry at OFFSET. RELOBJ is an object
2039 // defining a local symbol with INDEX. R_TYPE is the code of a dynamic
2040 // relocation that needs to be applied in a static link.
2042 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
2043 Sized_relobj_file
<size
, big_endian
>* relobj
,
2046 this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, relobj
,
2050 // Record that global symbol GSYM has R_TYPE dynamic relocation in the
2051 // secondary GOT at OFFSET.
2053 add_secondary_got_reloc(unsigned int got_offset
, unsigned int r_type
,
2054 Mips_symbol
<size
>* gsym
)
2056 this->secondary_got_relocs_
.push_back(Static_reloc(got_offset
,
2060 // Update GOT entry at OFFSET with VALUE.
2062 update_got_entry(unsigned int offset
, Mips_address value
)
2064 elfcpp::Swap
<size
, big_endian
>::writeval(this->got_view_
+ offset
, value
);
2067 // Return the number of entries in local part of the GOT. This includes
2068 // local entries, page entries and 2 reserved entries.
2070 get_local_gotno() const
2072 if (!this->multi_got())
2074 return (2 + this->master_got_info_
->local_gotno()
2075 + this->master_got_info_
->page_gotno());
2078 return 2 + this->primary_got_
->local_gotno() + this->primary_got_
->page_gotno();
2081 // Return dynamic symbol table index of the first symbol with global GOT
2084 first_global_got_dynsym_index() const
2085 { return this->first_global_got_dynsym_index_
; }
2087 // Set dynamic symbol table index of the first symbol with global GOT entry.
2089 set_first_global_got_dynsym_index(unsigned int index
)
2090 { this->first_global_got_dynsym_index_
= index
; }
2092 // Lay out the GOT. Add local, global and TLS entries. If GOT is
2093 // larger than 64K, create multi-GOT.
2095 lay_out_got(Layout
* layout
, Symbol_table
* symtab
,
2096 const Input_objects
* input_objects
);
2098 // Create multi-GOT. For every GOT, add local, global and TLS entries.
2100 lay_out_multi_got(Layout
* layout
, const Input_objects
* input_objects
);
2102 // Attempt to merge GOTs of different input objects.
2104 merge_gots(const Input_objects
* input_objects
);
2106 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
2107 // this would lead to overflow, true if they were merged successfully.
2109 merge_got_with(Mips_got_info
<size
, big_endian
>* from
,
2110 Mips_relobj
<size
, big_endian
>* object
,
2111 Mips_got_info
<size
, big_endian
>* to
);
2113 // Return the offset of GOT page entry for VALUE. For multi-GOT links,
2114 // use OBJECT's GOT.
2116 get_got_page_offset(Mips_address value
,
2117 const Mips_relobj
<size
, big_endian
>* object
)
2119 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2120 ? this->master_got_info_
2121 : object
->get_got_info());
2122 gold_assert(g
!= NULL
);
2123 return g
->get_got_page_offset(value
, this);
2126 // Return the GOT offset of type GOT_TYPE of the global symbol
2127 // GSYM. For multi-GOT links, use OBJECT's GOT.
2128 unsigned int got_offset(const Symbol
* gsym
, unsigned int got_type
,
2129 Mips_relobj
<size
, big_endian
>* object
) const
2131 if (!this->multi_got())
2132 return gsym
->got_offset(got_type
);
2135 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
2136 gold_assert(g
!= NULL
);
2137 return gsym
->got_offset(g
->multigot_got_type(got_type
));
2141 // Return the GOT offset of type GOT_TYPE of the local symbol
2144 got_offset(unsigned int symndx
, unsigned int got_type
,
2145 Sized_relobj_file
<size
, big_endian
>* object
,
2146 uint64_t addend
) const
2147 { return object
->local_got_offset(symndx
, got_type
, addend
); }
2149 // Return the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2151 tls_ldm_offset(Mips_relobj
<size
, big_endian
>* object
) const
2153 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2154 ? this->master_got_info_
2155 : object
->get_got_info());
2156 gold_assert(g
!= NULL
);
2157 return g
->tls_ldm_offset();
2160 // Set the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2162 set_tls_ldm_offset(unsigned int tls_ldm_offset
,
2163 Mips_relobj
<size
, big_endian
>* object
)
2165 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2166 ? this->master_got_info_
2167 : object
->get_got_info());
2168 gold_assert(g
!= NULL
);
2169 g
->set_tls_ldm_offset(tls_ldm_offset
);
2172 // Return true for multi-GOT links.
2175 { return this->primary_got_
!= NULL
; }
2177 // Return the offset of OBJECT's GOT from the start of .got section.
2179 get_got_offset(const Mips_relobj
<size
, big_endian
>* object
)
2181 if (!this->multi_got())
2185 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
2186 return g
!= NULL
? g
->offset() : 0;
2190 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
2192 add_reloc_only_entries()
2193 { this->master_got_info_
->add_reloc_only_entries(this); }
2195 // Return offset of the primary GOT's entry for global symbol.
2197 get_primary_got_offset(const Mips_symbol
<size
>* sym
) const
2199 gold_assert(sym
->global_got_area() != GGA_NONE
);
2200 return (this->get_local_gotno() + sym
->dynsym_index()
2201 - this->first_global_got_dynsym_index()) * size
/8;
2204 // For the entry at offset GOT_OFFSET, return its offset from the gp.
2205 // Input argument GOT_OFFSET is always global offset from the start of
2206 // .got section, for both single and multi-GOT links.
2207 // For single GOT links, this returns GOT_OFFSET - 0x7FF0. For multi-GOT
2208 // links, the return value is object_got_offset - 0x7FF0, where
2209 // object_got_offset is offset in the OBJECT's GOT.
2211 gp_offset(unsigned int got_offset
,
2212 const Mips_relobj
<size
, big_endian
>* object
) const
2214 return (this->address() + got_offset
2215 - this->target_
->adjusted_gp_value(object
));
2219 // Write out the GOT table.
2221 do_write(Output_file
*);
2225 // This class represent dynamic relocations that need to be applied by
2226 // gold because we are using TLS relocations in a static link.
2230 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2231 Mips_symbol
<size
>* gsym
)
2232 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(true)
2233 { this->u_
.global
.symbol
= gsym
; }
2235 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2236 Sized_relobj_file
<size
, big_endian
>* relobj
, unsigned int index
)
2237 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(false)
2239 this->u_
.local
.relobj
= relobj
;
2240 this->u_
.local
.index
= index
;
2243 // Return the GOT offset.
2246 { return this->got_offset_
; }
2251 { return this->r_type_
; }
2253 // Whether the symbol is global or not.
2255 symbol_is_global() const
2256 { return this->symbol_is_global_
; }
2258 // For a relocation against a global symbol, the global symbol.
2262 gold_assert(this->symbol_is_global_
);
2263 return this->u_
.global
.symbol
;
2266 // For a relocation against a local symbol, the defining object.
2267 Sized_relobj_file
<size
, big_endian
>*
2270 gold_assert(!this->symbol_is_global_
);
2271 return this->u_
.local
.relobj
;
2274 // For a relocation against a local symbol, the local symbol index.
2278 gold_assert(!this->symbol_is_global_
);
2279 return this->u_
.local
.index
;
2283 // GOT offset of the entry to which this relocation is applied.
2284 unsigned int got_offset_
;
2285 // Type of relocation.
2286 unsigned int r_type_
;
2287 // Whether this relocation is against a global symbol.
2288 bool symbol_is_global_
;
2289 // A global or local symbol.
2294 // For a global symbol, the symbol itself.
2295 Mips_symbol
<size
>* symbol
;
2299 // For a local symbol, the object defining object.
2300 Sized_relobj_file
<size
, big_endian
>* relobj
;
2301 // For a local symbol, the symbol index.
2308 Target_mips
<size
, big_endian
>* target_
;
2309 // The symbol table.
2310 Symbol_table
* symbol_table_
;
2313 // Static relocs to be applied to the GOT.
2314 std::vector
<Static_reloc
> static_relocs_
;
2315 // .got section view.
2316 unsigned char* got_view_
;
2317 // The dynamic symbol table index of the first symbol with global GOT entry.
2318 unsigned int first_global_got_dynsym_index_
;
2319 // The master GOT information.
2320 Mips_got_info
<size
, big_endian
>* master_got_info_
;
2321 // The primary GOT information.
2322 Mips_got_info
<size
, big_endian
>* primary_got_
;
2323 // Secondary GOT fixups.
2324 std::vector
<Static_reloc
> secondary_got_relocs_
;
2327 // A class to handle LA25 stubs - non-PIC interface to a PIC function. There are
2328 // two ways of creating these interfaces. The first is to add:
2330 // lui $25,%hi(func)
2332 // addiu $25,$25,%lo(func)
2334 // to a separate trampoline section. The second is to add:
2336 // lui $25,%hi(func)
2337 // addiu $25,$25,%lo(func)
2339 // immediately before a PIC function "func", but only if a function is at the
2340 // beginning of the section, and the section is not too heavily aligned (i.e we
2341 // would need to add no more than 2 nops before the stub.)
2343 // We only create stubs of the first type.
2345 template<int size
, bool big_endian
>
2346 class Mips_output_data_la25_stub
: public Output_section_data
2348 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2351 Mips_output_data_la25_stub()
2352 : Output_section_data(size
== 32 ? 4 : 8), symbols_()
2355 // Create LA25 stub for a symbol.
2357 create_la25_stub(Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
2358 Mips_symbol
<size
>* gsym
);
2360 // Return output address of a stub.
2362 stub_address(const Mips_symbol
<size
>* sym
) const
2364 gold_assert(sym
->has_la25_stub());
2365 return this->address() + sym
->la25_stub_offset();
2370 do_adjust_output_section(Output_section
* os
)
2371 { os
->set_entsize(0); }
2374 // Template for standard LA25 stub.
2375 static const uint32_t la25_stub_entry
[];
2376 // Template for microMIPS LA25 stub.
2377 static const uint32_t la25_stub_micromips_entry
[];
2379 // Set the final size.
2381 set_final_data_size()
2382 { this->set_data_size(this->symbols_
.size() * 16); }
2384 // Create a symbol for SYM stub's value and size, to help make the
2385 // disassembly easier to read.
2387 create_stub_symbol(Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
2388 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
);
2390 // Write to a map file.
2392 do_print_to_mapfile(Mapfile
* mapfile
) const
2393 { mapfile
->print_output_data(this, _(".LA25.stubs")); }
2395 // Write out the LA25 stub section.
2397 do_write(Output_file
*);
2399 // Symbols that have LA25 stubs.
2400 std::vector
<Mips_symbol
<size
>*> symbols_
;
2403 // MIPS-specific relocation writer.
2405 template<int sh_type
, bool dynamic
, int size
, bool big_endian
>
2406 struct Mips_output_reloc_writer
;
2408 template<int sh_type
, bool dynamic
, bool big_endian
>
2409 struct Mips_output_reloc_writer
<sh_type
, dynamic
, 32, big_endian
>
2411 typedef Output_reloc
<sh_type
, dynamic
, 32, big_endian
> Output_reloc_type
;
2412 typedef std::vector
<Output_reloc_type
> Relocs
;
2415 write(typename
Relocs::const_iterator p
, unsigned char* pov
)
2419 template<int sh_type
, bool dynamic
, bool big_endian
>
2420 struct Mips_output_reloc_writer
<sh_type
, dynamic
, 64, big_endian
>
2422 typedef Output_reloc
<sh_type
, dynamic
, 64, big_endian
> Output_reloc_type
;
2423 typedef std::vector
<Output_reloc_type
> Relocs
;
2426 write(typename
Relocs::const_iterator p
, unsigned char* pov
)
2428 elfcpp::Mips64_rel_write
<big_endian
> orel(pov
);
2429 orel
.put_r_offset(p
->get_address());
2430 orel
.put_r_sym(p
->get_symbol_index());
2431 orel
.put_r_ssym(RSS_UNDEF
);
2432 orel
.put_r_type(p
->type());
2433 if (p
->type() == elfcpp::R_MIPS_REL32
)
2434 orel
.put_r_type2(elfcpp::R_MIPS_64
);
2436 orel
.put_r_type2(elfcpp::R_MIPS_NONE
);
2437 orel
.put_r_type3(elfcpp::R_MIPS_NONE
);
2441 template<int sh_type
, bool dynamic
, int size
, bool big_endian
>
2442 class Mips_output_data_reloc
: public Output_data_reloc
<sh_type
, dynamic
,
2446 Mips_output_data_reloc(bool sort_relocs
)
2447 : Output_data_reloc
<sh_type
, dynamic
, size
, big_endian
>(sort_relocs
)
2451 // Write out the data.
2453 do_write(Output_file
* of
)
2455 typedef Mips_output_reloc_writer
<sh_type
, dynamic
, size
,
2457 this->template do_write_generic
<Writer
>(of
);
2462 // A class to handle the PLT data.
2464 template<int size
, bool big_endian
>
2465 class Mips_output_data_plt
: public Output_section_data
2467 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2468 typedef Mips_output_data_reloc
<elfcpp::SHT_REL
, true,
2469 size
, big_endian
> Reloc_section
;
2472 // Create the PLT section. The ordinary .got section is an argument,
2473 // since we need to refer to the start.
2474 Mips_output_data_plt(Layout
* layout
, Output_data_space
* got_plt
,
2475 Target_mips
<size
, big_endian
>* target
)
2476 : Output_section_data(size
== 32 ? 4 : 8), got_plt_(got_plt
), symbols_(),
2477 plt_mips_offset_(0), plt_comp_offset_(0), plt_header_size_(0),
2480 this->rel_
= new Reloc_section(false);
2481 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
2482 elfcpp::SHF_ALLOC
, this->rel_
,
2483 ORDER_DYNAMIC_PLT_RELOCS
, false);
2486 // Add an entry to the PLT for a symbol referenced by r_type relocation.
2488 add_entry(Mips_symbol
<size
>* gsym
, unsigned int r_type
);
2490 // Return the .rel.plt section data.
2493 { return this->rel_
; }
2495 // Return the number of PLT entries.
2498 { return this->symbols_
.size(); }
2500 // Return the offset of the first non-reserved PLT entry.
2502 first_plt_entry_offset() const
2503 { return sizeof(plt0_entry_o32
); }
2505 // Return the size of a PLT entry.
2507 plt_entry_size() const
2508 { return sizeof(plt_entry
); }
2510 // Set final PLT offsets. For each symbol, determine whether standard or
2511 // compressed (MIPS16 or microMIPS) PLT entry is used.
2515 // Return the offset of the first standard PLT entry.
2517 first_mips_plt_offset() const
2518 { return this->plt_header_size_
; }
2520 // Return the offset of the first compressed PLT entry.
2522 first_comp_plt_offset() const
2523 { return this->plt_header_size_
+ this->plt_mips_offset_
; }
2525 // Return whether there are any standard PLT entries.
2527 has_standard_entries() const
2528 { return this->plt_mips_offset_
> 0; }
2530 // Return the output address of standard PLT entry.
2532 mips_entry_address(const Mips_symbol
<size
>* sym
) const
2534 gold_assert (sym
->has_mips_plt_offset());
2535 return (this->address() + this->first_mips_plt_offset()
2536 + sym
->mips_plt_offset());
2539 // Return the output address of compressed (MIPS16 or microMIPS) PLT entry.
2541 comp_entry_address(const Mips_symbol
<size
>* sym
) const
2543 gold_assert (sym
->has_comp_plt_offset());
2544 return (this->address() + this->first_comp_plt_offset()
2545 + sym
->comp_plt_offset());
2550 do_adjust_output_section(Output_section
* os
)
2551 { os
->set_entsize(0); }
2553 // Write to a map file.
2555 do_print_to_mapfile(Mapfile
* mapfile
) const
2556 { mapfile
->print_output_data(this, _(".plt")); }
2559 // Template for the first PLT entry.
2560 static const uint32_t plt0_entry_o32
[];
2561 static const uint32_t plt0_entry_n32
[];
2562 static const uint32_t plt0_entry_n64
[];
2563 static const uint32_t plt0_entry_micromips_o32
[];
2564 static const uint32_t plt0_entry_micromips32_o32
[];
2566 // Template for subsequent PLT entries.
2567 static const uint32_t plt_entry
[];
2568 static const uint32_t plt_entry_r6
[];
2569 static const uint32_t plt_entry_mips16_o32
[];
2570 static const uint32_t plt_entry_micromips_o32
[];
2571 static const uint32_t plt_entry_micromips32_o32
[];
2573 // Set the final size.
2575 set_final_data_size()
2577 this->set_data_size(this->plt_header_size_
+ this->plt_mips_offset_
2578 + this->plt_comp_offset_
);
2581 // Write out the PLT data.
2583 do_write(Output_file
*);
2585 // Return whether the plt header contains microMIPS code. For the sake of
2586 // cache alignment always use a standard header whenever any standard entries
2587 // are present even if microMIPS entries are present as well. This also lets
2588 // the microMIPS header rely on the value of $v0 only set by microMIPS
2589 // entries, for a small size reduction.
2591 is_plt_header_compressed() const
2593 gold_assert(this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0);
2594 return this->target_
->is_output_micromips() && this->plt_mips_offset_
== 0;
2597 // Return the size of the PLT header.
2599 get_plt_header_size() const
2601 if (this->target_
->is_output_n64())
2602 return 4 * sizeof(plt0_entry_n64
) / sizeof(plt0_entry_n64
[0]);
2603 else if (this->target_
->is_output_n32())
2604 return 4 * sizeof(plt0_entry_n32
) / sizeof(plt0_entry_n32
[0]);
2605 else if (!this->is_plt_header_compressed())
2606 return 4 * sizeof(plt0_entry_o32
) / sizeof(plt0_entry_o32
[0]);
2607 else if (this->target_
->use_32bit_micromips_instructions())
2608 return (2 * sizeof(plt0_entry_micromips32_o32
)
2609 / sizeof(plt0_entry_micromips32_o32
[0]));
2611 return (2 * sizeof(plt0_entry_micromips_o32
)
2612 / sizeof(plt0_entry_micromips_o32
[0]));
2615 // Return the PLT header entry.
2617 get_plt_header_entry() const
2619 if (this->target_
->is_output_n64())
2620 return plt0_entry_n64
;
2621 else if (this->target_
->is_output_n32())
2622 return plt0_entry_n32
;
2623 else if (!this->is_plt_header_compressed())
2624 return plt0_entry_o32
;
2625 else if (this->target_
->use_32bit_micromips_instructions())
2626 return plt0_entry_micromips32_o32
;
2628 return plt0_entry_micromips_o32
;
2631 // Return the size of the standard PLT entry.
2633 standard_plt_entry_size() const
2634 { return 4 * sizeof(plt_entry
) / sizeof(plt_entry
[0]); }
2636 // Return the size of the compressed PLT entry.
2638 compressed_plt_entry_size() const
2640 gold_assert(!this->target_
->is_output_newabi());
2642 if (!this->target_
->is_output_micromips())
2643 return (2 * sizeof(plt_entry_mips16_o32
)
2644 / sizeof(plt_entry_mips16_o32
[0]));
2645 else if (this->target_
->use_32bit_micromips_instructions())
2646 return (2 * sizeof(plt_entry_micromips32_o32
)
2647 / sizeof(plt_entry_micromips32_o32
[0]));
2649 return (2 * sizeof(plt_entry_micromips_o32
)
2650 / sizeof(plt_entry_micromips_o32
[0]));
2653 // The reloc section.
2654 Reloc_section
* rel_
;
2655 // The .got.plt section.
2656 Output_data_space
* got_plt_
;
2657 // Symbols that have PLT entry.
2658 std::vector
<Mips_symbol
<size
>*> symbols_
;
2659 // The offset of the next standard PLT entry to create.
2660 unsigned int plt_mips_offset_
;
2661 // The offset of the next compressed PLT entry to create.
2662 unsigned int plt_comp_offset_
;
2663 // The size of the PLT header in bytes.
2664 unsigned int plt_header_size_
;
2666 Target_mips
<size
, big_endian
>* target_
;
2669 // A class to handle the .MIPS.stubs data.
2671 template<int size
, bool big_endian
>
2672 class Mips_output_data_mips_stubs
: public Output_section_data
2674 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2676 // Unordered set of .MIPS.stubs entries.
2677 typedef Unordered_set
<Mips_symbol
<size
>*, Mips_symbol_hash
<size
> >
2678 Mips_stubs_entry_set
;
2681 Mips_output_data_mips_stubs(Target_mips
<size
, big_endian
>* target
)
2682 : Output_section_data(size
== 32 ? 4 : 8), symbols_(), dynsym_count_(-1U),
2683 stub_offsets_are_set_(false), target_(target
)
2686 // Create entry for a symbol.
2688 make_entry(Mips_symbol
<size
>*);
2690 // Remove entry for a symbol.
2692 remove_entry(Mips_symbol
<size
>* gsym
);
2694 // Set stub offsets for symbols. This method expects that the number of
2695 // entries in dynamic symbol table is set.
2697 set_lazy_stub_offsets();
2700 set_needs_dynsym_value();
2702 // Set the number of entries in dynamic symbol table.
2704 set_dynsym_count(unsigned int dynsym_count
)
2705 { this->dynsym_count_
= dynsym_count
; }
2707 // Return maximum size of the stub, ie. the stub size if the dynamic symbol
2708 // count is greater than 0x10000. If the dynamic symbol count is less than
2709 // 0x10000, the stub will be 4 bytes smaller.
2710 // There's no disadvantage from using microMIPS code here, so for the sake of
2711 // pure-microMIPS binaries we prefer it whenever there's any microMIPS code in
2712 // output produced at all. This has a benefit of stubs being shorter by
2713 // 4 bytes each too, unless in the insn32 mode.
2715 stub_max_size() const
2717 if (!this->target_
->is_output_micromips()
2718 || this->target_
->use_32bit_micromips_instructions())
2724 // Return the size of the stub. This method expects that the final dynsym
2729 gold_assert(this->dynsym_count_
!= -1U);
2730 if (this->dynsym_count_
> 0x10000)
2731 return this->stub_max_size();
2733 return this->stub_max_size() - 4;
2736 // Return output address of a stub.
2738 stub_address(const Mips_symbol
<size
>* sym
) const
2740 gold_assert(sym
->has_lazy_stub());
2741 return this->address() + sym
->lazy_stub_offset();
2746 do_adjust_output_section(Output_section
* os
)
2747 { os
->set_entsize(0); }
2749 // Write to a map file.
2751 do_print_to_mapfile(Mapfile
* mapfile
) const
2752 { mapfile
->print_output_data(this, _(".MIPS.stubs")); }
2755 static const uint32_t lazy_stub_normal_1
[];
2756 static const uint32_t lazy_stub_normal_1_n64
[];
2757 static const uint32_t lazy_stub_normal_2
[];
2758 static const uint32_t lazy_stub_normal_2_n64
[];
2759 static const uint32_t lazy_stub_big
[];
2760 static const uint32_t lazy_stub_big_n64
[];
2762 static const uint32_t lazy_stub_micromips_normal_1
[];
2763 static const uint32_t lazy_stub_micromips_normal_1_n64
[];
2764 static const uint32_t lazy_stub_micromips_normal_2
[];
2765 static const uint32_t lazy_stub_micromips_normal_2_n64
[];
2766 static const uint32_t lazy_stub_micromips_big
[];
2767 static const uint32_t lazy_stub_micromips_big_n64
[];
2769 static const uint32_t lazy_stub_micromips32_normal_1
[];
2770 static const uint32_t lazy_stub_micromips32_normal_1_n64
[];
2771 static const uint32_t lazy_stub_micromips32_normal_2
[];
2772 static const uint32_t lazy_stub_micromips32_normal_2_n64
[];
2773 static const uint32_t lazy_stub_micromips32_big
[];
2774 static const uint32_t lazy_stub_micromips32_big_n64
[];
2776 // Set the final size.
2778 set_final_data_size()
2779 { this->set_data_size(this->symbols_
.size() * this->stub_max_size()); }
2781 // Write out the .MIPS.stubs data.
2783 do_write(Output_file
*);
2785 // .MIPS.stubs symbols
2786 Mips_stubs_entry_set symbols_
;
2787 // Number of entries in dynamic symbol table.
2788 unsigned int dynsym_count_
;
2789 // Whether the stub offsets are set.
2790 bool stub_offsets_are_set_
;
2792 Target_mips
<size
, big_endian
>* target_
;
2795 // This class handles Mips .reginfo output section.
2797 template<int size
, bool big_endian
>
2798 class Mips_output_section_reginfo
: public Output_section_data
2800 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
2803 Mips_output_section_reginfo(Target_mips
<size
, big_endian
>* target
,
2804 Valtype gprmask
, Valtype cprmask1
,
2805 Valtype cprmask2
, Valtype cprmask3
,
2807 : Output_section_data(24, 4, true), target_(target
),
2808 gprmask_(gprmask
), cprmask1_(cprmask1
), cprmask2_(cprmask2
),
2809 cprmask3_(cprmask3
), cprmask4_(cprmask4
)
2813 // Write to a map file.
2815 do_print_to_mapfile(Mapfile
* mapfile
) const
2816 { mapfile
->print_output_data(this, _(".reginfo")); }
2818 // Write out reginfo section.
2820 do_write(Output_file
* of
);
2823 Target_mips
<size
, big_endian
>* target_
;
2825 // gprmask of the output .reginfo section.
2827 // cprmask1 of the output .reginfo section.
2829 // cprmask2 of the output .reginfo section.
2831 // cprmask3 of the output .reginfo section.
2833 // cprmask4 of the output .reginfo section.
2837 // This class handles .MIPS.options output section.
2839 template<int size
, bool big_endian
>
2840 class Mips_output_section_options
: public Output_section
2843 Mips_output_section_options(const char* name
, elfcpp::Elf_Word type
,
2844 elfcpp::Elf_Xword flags
,
2845 Target_mips
<size
, big_endian
>* target
)
2846 : Output_section(name
, type
, flags
), target_(target
)
2848 // After the input sections are written, we only need to update
2849 // ri_gp_value field of ODK_REGINFO entries.
2850 this->set_after_input_sections();
2854 // Write out option section.
2856 do_write(Output_file
* of
);
2859 Target_mips
<size
, big_endian
>* target_
;
2862 // This class handles .MIPS.abiflags output section.
2864 template<int size
, bool big_endian
>
2865 class Mips_output_section_abiflags
: public Output_section_data
2868 Mips_output_section_abiflags(const Mips_abiflags
<big_endian
>& abiflags
)
2869 : Output_section_data(24, 8, true), abiflags_(abiflags
)
2873 // Write to a map file.
2875 do_print_to_mapfile(Mapfile
* mapfile
) const
2876 { mapfile
->print_output_data(this, _(".MIPS.abiflags")); }
2879 do_write(Output_file
* of
);
2882 const Mips_abiflags
<big_endian
>& abiflags_
;
2885 // The MIPS target has relocation types which default handling of relocatable
2886 // relocation cannot process. So we have to extend the default code.
2888 template<bool big_endian
, typename Classify_reloc
>
2889 class Mips_scan_relocatable_relocs
:
2890 public Default_scan_relocatable_relocs
<Classify_reloc
>
2893 // Return the strategy to use for a local symbol which is a section
2894 // symbol, given the relocation type.
2895 inline Relocatable_relocs::Reloc_strategy
2896 local_section_strategy(unsigned int r_type
, Relobj
* object
)
2898 if (Classify_reloc::sh_type
== elfcpp::SHT_RELA
)
2899 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
2904 case elfcpp::R_MIPS_26
:
2905 return Relocatable_relocs::RELOC_SPECIAL
;
2908 return Default_scan_relocatable_relocs
<Classify_reloc
>::
2909 local_section_strategy(r_type
, object
);
2915 // Mips_copy_relocs class. The only difference from the base class is the
2916 // method emit_mips, which should be called instead of Copy_reloc_entry::emit.
2917 // Mips cannot convert all relocation types to dynamic relocs. If a reloc
2918 // cannot be made dynamic, a COPY reloc is emitted.
2920 template<int sh_type
, int size
, bool big_endian
>
2921 class Mips_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
2925 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_MIPS_COPY
)
2928 // Emit any saved relocations which turn out to be needed. This is
2929 // called after all the relocs have been scanned.
2931 emit_mips(Output_data_reloc
<sh_type
, true, size
, big_endian
>*,
2932 Symbol_table
*, Layout
*, Target_mips
<size
, big_endian
>*);
2935 typedef typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
2938 // Emit this reloc if appropriate. This is called after we have
2939 // scanned all the relocations, so we know whether we emitted a
2940 // COPY relocation for SYM_.
2942 emit_entry(Copy_reloc_entry
& entry
,
2943 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
2944 Symbol_table
* symtab
, Layout
* layout
,
2945 Target_mips
<size
, big_endian
>* target
);
2949 // Return true if the symbol SYM should be considered to resolve local
2950 // to the current module, and false otherwise. The logic is taken from
2951 // GNU ld's method _bfd_elf_symbol_refs_local_p.
2953 symbol_refs_local(const Symbol
* sym
, bool has_dynsym_entry
,
2954 bool local_protected
)
2956 // If it's a local sym, of course we resolve locally.
2960 // STV_HIDDEN or STV_INTERNAL ones must be local.
2961 if (sym
->visibility() == elfcpp::STV_HIDDEN
2962 || sym
->visibility() == elfcpp::STV_INTERNAL
)
2965 // If we don't have a definition in a regular file, then we can't
2966 // resolve locally. The sym is either undefined or dynamic.
2967 if (sym
->is_from_dynobj() || sym
->is_undefined())
2970 // Forced local symbols resolve locally.
2971 if (sym
->is_forced_local())
2974 // As do non-dynamic symbols.
2975 if (!has_dynsym_entry
)
2978 // At this point, we know the symbol is defined and dynamic. In an
2979 // executable it must resolve locally, likewise when building symbolic
2980 // shared libraries.
2981 if (parameters
->options().output_is_executable()
2982 || parameters
->options().Bsymbolic())
2985 // Now deal with defined dynamic symbols in shared libraries. Ones
2986 // with default visibility might not resolve locally.
2987 if (sym
->visibility() == elfcpp::STV_DEFAULT
)
2990 // STV_PROTECTED non-function symbols are local.
2991 if (sym
->type() != elfcpp::STT_FUNC
)
2994 // Function pointer equality tests may require that STV_PROTECTED
2995 // symbols be treated as dynamic symbols. If the address of a
2996 // function not defined in an executable is set to that function's
2997 // plt entry in the executable, then the address of the function in
2998 // a shared library must also be the plt entry in the executable.
2999 return local_protected
;
3002 // Return TRUE if references to this symbol always reference the symbol in this
3005 symbol_references_local(const Symbol
* sym
, bool has_dynsym_entry
)
3007 return symbol_refs_local(sym
, has_dynsym_entry
, false);
3010 // Return TRUE if calls to this symbol always call the version in this object.
3012 symbol_calls_local(const Symbol
* sym
, bool has_dynsym_entry
)
3014 return symbol_refs_local(sym
, has_dynsym_entry
, true);
3017 // Compare GOT offsets of two symbols.
3019 template<int size
, bool big_endian
>
3021 got_offset_compare(Symbol
* sym1
, Symbol
* sym2
)
3023 Mips_symbol
<size
>* mips_sym1
= Mips_symbol
<size
>::as_mips_sym(sym1
);
3024 Mips_symbol
<size
>* mips_sym2
= Mips_symbol
<size
>::as_mips_sym(sym2
);
3025 unsigned int area1
= mips_sym1
->global_got_area();
3026 unsigned int area2
= mips_sym2
->global_got_area();
3027 gold_assert(area1
!= GGA_NONE
&& area1
!= GGA_NONE
);
3029 // GGA_NORMAL entries always come before GGA_RELOC_ONLY.
3031 return area1
< area2
;
3033 return mips_sym1
->global_gotoffset() < mips_sym2
->global_gotoffset();
3036 // This method divides dynamic symbols into symbols that have GOT entry, and
3037 // symbols that don't have GOT entry. It also sorts symbols with the GOT entry.
3038 // Mips ABI requires that symbols with the GOT entry must be at the end of
3039 // dynamic symbol table, and the order in dynamic symbol table must match the
3042 template<int size
, bool big_endian
>
3044 reorder_dyn_symbols(std::vector
<Symbol
*>* dyn_symbols
,
3045 std::vector
<Symbol
*>* non_got_symbols
,
3046 std::vector
<Symbol
*>* got_symbols
)
3048 for (std::vector
<Symbol
*>::iterator p
= dyn_symbols
->begin();
3049 p
!= dyn_symbols
->end();
3052 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(*p
);
3053 if (mips_sym
->global_got_area() == GGA_NORMAL
3054 || mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
3055 got_symbols
->push_back(mips_sym
);
3057 non_got_symbols
->push_back(mips_sym
);
3060 std::sort(got_symbols
->begin(), got_symbols
->end(),
3061 got_offset_compare
<size
, big_endian
>);
3064 // Functor class for processing the global symbol table.
3066 template<int size
, bool big_endian
>
3067 class Symbol_visitor_check_symbols
3070 Symbol_visitor_check_symbols(Target_mips
<size
, big_endian
>* target
,
3071 Layout
* layout
, Symbol_table
* symtab
)
3072 : target_(target
), layout_(layout
), symtab_(symtab
)
3076 operator()(Sized_symbol
<size
>* sym
)
3078 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
3079 if (local_pic_function
<size
, big_endian
>(mips_sym
))
3081 // SYM is a function that might need $25 to be valid on entry.
3082 // If we're creating a non-PIC relocatable object, mark SYM as
3083 // being PIC. If we're creating a non-relocatable object with
3084 // non-PIC branches and jumps to SYM, make sure that SYM has an la25
3086 if (parameters
->options().relocatable())
3088 if (!parameters
->options().output_is_position_independent())
3089 mips_sym
->set_pic();
3091 else if (mips_sym
->has_nonpic_branches())
3093 this->target_
->la25_stub_section(layout_
)
3094 ->create_la25_stub(this->symtab_
, this->target_
, mips_sym
);
3100 Target_mips
<size
, big_endian
>* target_
;
3102 Symbol_table
* symtab_
;
3105 // Relocation types, parameterized by SHT_REL vs. SHT_RELA, size,
3106 // and endianness. The relocation format for MIPS-64 is non-standard.
3108 template<int sh_type
, int size
, bool big_endian
>
3109 struct Mips_reloc_types
;
3111 template<bool big_endian
>
3112 struct Mips_reloc_types
<elfcpp::SHT_REL
, 32, big_endian
>
3114 typedef typename
elfcpp::Rel
<32, big_endian
> Reloc
;
3115 typedef typename
elfcpp::Rel_write
<32, big_endian
> Reloc_write
;
3117 static typename
elfcpp::Elf_types
<32>::Elf_Swxword
3118 get_r_addend(const Reloc
*)
3122 set_reloc_addend(Reloc_write
*,
3123 typename
elfcpp::Elf_types
<32>::Elf_Swxword
)
3124 { gold_unreachable(); }
3127 template<bool big_endian
>
3128 struct Mips_reloc_types
<elfcpp::SHT_RELA
, 32, big_endian
>
3130 typedef typename
elfcpp::Rela
<32, big_endian
> Reloc
;
3131 typedef typename
elfcpp::Rela_write
<32, big_endian
> Reloc_write
;
3133 static typename
elfcpp::Elf_types
<32>::Elf_Swxword
3134 get_r_addend(const Reloc
* reloc
)
3135 { return reloc
->get_r_addend(); }
3138 set_reloc_addend(Reloc_write
* p
,
3139 typename
elfcpp::Elf_types
<32>::Elf_Swxword val
)
3140 { p
->put_r_addend(val
); }
3143 template<bool big_endian
>
3144 struct Mips_reloc_types
<elfcpp::SHT_REL
, 64, big_endian
>
3146 typedef typename
elfcpp::Mips64_rel
<big_endian
> Reloc
;
3147 typedef typename
elfcpp::Mips64_rel_write
<big_endian
> Reloc_write
;
3149 static typename
elfcpp::Elf_types
<64>::Elf_Swxword
3150 get_r_addend(const Reloc
*)
3154 set_reloc_addend(Reloc_write
*,
3155 typename
elfcpp::Elf_types
<64>::Elf_Swxword
)
3156 { gold_unreachable(); }
3159 template<bool big_endian
>
3160 struct Mips_reloc_types
<elfcpp::SHT_RELA
, 64, big_endian
>
3162 typedef typename
elfcpp::Mips64_rela
<big_endian
> Reloc
;
3163 typedef typename
elfcpp::Mips64_rela_write
<big_endian
> Reloc_write
;
3165 static typename
elfcpp::Elf_types
<64>::Elf_Swxword
3166 get_r_addend(const Reloc
* reloc
)
3167 { return reloc
->get_r_addend(); }
3170 set_reloc_addend(Reloc_write
* p
,
3171 typename
elfcpp::Elf_types
<64>::Elf_Swxword val
)
3172 { p
->put_r_addend(val
); }
3175 // Forward declaration.
3177 mips_get_size_for_reloc(unsigned int, Relobj
*);
3179 // A class for inquiring about properties of a relocation,
3180 // used while scanning relocs during a relocatable link and
3181 // garbage collection.
3183 template<int sh_type_
, int size
, bool big_endian
>
3184 class Mips_classify_reloc
;
3186 template<int sh_type_
, bool big_endian
>
3187 class Mips_classify_reloc
<sh_type_
, 32, big_endian
> :
3188 public gold::Default_classify_reloc
<sh_type_
, 32, big_endian
>
3191 typedef typename Mips_reloc_types
<sh_type_
, 32, big_endian
>::Reloc
3193 typedef typename Mips_reloc_types
<sh_type_
, 32, big_endian
>::Reloc_write
3196 // Return the symbol referred to by the relocation.
3197 static inline unsigned int
3198 get_r_sym(const Reltype
* reloc
)
3199 { return elfcpp::elf_r_sym
<32>(reloc
->get_r_info()); }
3201 // Return the type of the relocation.
3202 static inline unsigned int
3203 get_r_type(const Reltype
* reloc
)
3204 { return elfcpp::elf_r_type
<32>(reloc
->get_r_info()); }
3206 static inline unsigned int
3207 get_r_type2(const Reltype
*)
3210 static inline unsigned int
3211 get_r_type3(const Reltype
*)
3214 static inline unsigned int
3215 get_r_ssym(const Reltype
*)
3218 // Return the explicit addend of the relocation (return 0 for SHT_REL).
3219 static inline unsigned int
3220 get_r_addend(const Reltype
* reloc
)
3222 if (sh_type_
== elfcpp::SHT_REL
)
3224 return Mips_reloc_types
<sh_type_
, 32, big_endian
>::get_r_addend(reloc
);
3227 // Write the r_info field to a new reloc, using the r_info field from
3228 // the original reloc, replacing the r_sym field with R_SYM.
3230 put_r_info(Reltype_write
* new_reloc
, Reltype
* reloc
, unsigned int r_sym
)
3232 unsigned int r_type
= elfcpp::elf_r_type
<32>(reloc
->get_r_info());
3233 new_reloc
->put_r_info(elfcpp::elf_r_info
<32>(r_sym
, r_type
));
3236 // Write the r_addend field to a new reloc.
3238 put_r_addend(Reltype_write
* to
,
3239 typename
elfcpp::Elf_types
<32>::Elf_Swxword addend
)
3240 { Mips_reloc_types
<sh_type_
, 32, big_endian
>::set_reloc_addend(to
, addend
); }
3242 // Return the size of the addend of the relocation (only used for SHT_REL).
3244 get_size_for_reloc(unsigned int r_type
, Relobj
* obj
)
3245 { return mips_get_size_for_reloc(r_type
, obj
); }
3248 template<int sh_type_
, bool big_endian
>
3249 class Mips_classify_reloc
<sh_type_
, 64, big_endian
> :
3250 public gold::Default_classify_reloc
<sh_type_
, 64, big_endian
>
3253 typedef typename Mips_reloc_types
<sh_type_
, 64, big_endian
>::Reloc
3255 typedef typename Mips_reloc_types
<sh_type_
, 64, big_endian
>::Reloc_write
3258 // Return the symbol referred to by the relocation.
3259 static inline unsigned int
3260 get_r_sym(const Reltype
* reloc
)
3261 { return reloc
->get_r_sym(); }
3263 // Return the r_type of the relocation.
3264 static inline unsigned int
3265 get_r_type(const Reltype
* reloc
)
3266 { return reloc
->get_r_type(); }
3268 // Return the r_type2 of the relocation.
3269 static inline unsigned int
3270 get_r_type2(const Reltype
* reloc
)
3271 { return reloc
->get_r_type2(); }
3273 // Return the r_type3 of the relocation.
3274 static inline unsigned int
3275 get_r_type3(const Reltype
* reloc
)
3276 { return reloc
->get_r_type3(); }
3278 // Return the special symbol of the relocation.
3279 static inline unsigned int
3280 get_r_ssym(const Reltype
* reloc
)
3281 { return reloc
->get_r_ssym(); }
3283 // Return the explicit addend of the relocation (return 0 for SHT_REL).
3284 static inline typename
elfcpp::Elf_types
<64>::Elf_Swxword
3285 get_r_addend(const Reltype
* reloc
)
3287 if (sh_type_
== elfcpp::SHT_REL
)
3289 return Mips_reloc_types
<sh_type_
, 64, big_endian
>::get_r_addend(reloc
);
3292 // Write the r_info field to a new reloc, using the r_info field from
3293 // the original reloc, replacing the r_sym field with R_SYM.
3295 put_r_info(Reltype_write
* new_reloc
, Reltype
* reloc
, unsigned int r_sym
)
3297 new_reloc
->put_r_sym(r_sym
);
3298 new_reloc
->put_r_ssym(reloc
->get_r_ssym());
3299 new_reloc
->put_r_type3(reloc
->get_r_type3());
3300 new_reloc
->put_r_type2(reloc
->get_r_type2());
3301 new_reloc
->put_r_type(reloc
->get_r_type());
3304 // Write the r_addend field to a new reloc.
3306 put_r_addend(Reltype_write
* to
,
3307 typename
elfcpp::Elf_types
<64>::Elf_Swxword addend
)
3308 { Mips_reloc_types
<sh_type_
, 64, big_endian
>::set_reloc_addend(to
, addend
); }
3310 // Return the size of the addend of the relocation (only used for SHT_REL).
3312 get_size_for_reloc(unsigned int r_type
, Relobj
* obj
)
3313 { return mips_get_size_for_reloc(r_type
, obj
); }
3316 template<int size
, bool big_endian
>
3317 class Target_mips
: public Sized_target
<size
, big_endian
>
3319 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
3320 typedef Mips_output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
3322 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
3323 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
3324 typedef typename Mips_reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
3326 typedef typename Mips_reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
3330 Target_mips(const Target::Target_info
* info
= &mips_info
)
3331 : Sized_target
<size
, big_endian
>(info
), got_(NULL
), gp_(NULL
), plt_(NULL
),
3332 got_plt_(NULL
), rel_dyn_(NULL
), rld_map_(NULL
), copy_relocs_(),
3333 dyn_relocs_(), la25_stub_(NULL
), mips_mach_extensions_(),
3334 mips_stubs_(NULL
), attributes_section_data_(NULL
), abiflags_(NULL
),
3335 mach_(0), layout_(NULL
), got16_addends_(), has_abiflags_section_(false),
3336 entry_symbol_is_compressed_(false), insn32_(false)
3338 this->add_machine_extensions();
3341 // The offset of $gp from the beginning of the .got section.
3342 static const unsigned int MIPS_GP_OFFSET
= 0x7ff0;
3344 // The maximum size of the GOT for it to be addressable using 16-bit
3345 // offsets from $gp.
3346 static const unsigned int MIPS_GOT_MAX_SIZE
= MIPS_GP_OFFSET
+ 0x7fff;
3348 // Make a new symbol table entry for the Mips target.
3350 make_symbol(const char*, elfcpp::STT
, Object
*, unsigned int, uint64_t)
3351 { return new Mips_symbol
<size
>(); }
3353 // Process the relocations to determine unreferenced sections for
3354 // garbage collection.
3356 gc_process_relocs(Symbol_table
* symtab
,
3358 Sized_relobj_file
<size
, big_endian
>* object
,
3359 unsigned int data_shndx
,
3360 unsigned int sh_type
,
3361 const unsigned char* prelocs
,
3363 Output_section
* output_section
,
3364 bool needs_special_offset_handling
,
3365 size_t local_symbol_count
,
3366 const unsigned char* plocal_symbols
);
3368 // Scan the relocations to look for symbol adjustments.
3370 scan_relocs(Symbol_table
* symtab
,
3372 Sized_relobj_file
<size
, big_endian
>* object
,
3373 unsigned int data_shndx
,
3374 unsigned int sh_type
,
3375 const unsigned char* prelocs
,
3377 Output_section
* output_section
,
3378 bool needs_special_offset_handling
,
3379 size_t local_symbol_count
,
3380 const unsigned char* plocal_symbols
);
3382 // Finalize the sections.
3384 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
3386 // Relocate a section.
3388 relocate_section(const Relocate_info
<size
, big_endian
>*,
3389 unsigned int sh_type
,
3390 const unsigned char* prelocs
,
3392 Output_section
* output_section
,
3393 bool needs_special_offset_handling
,
3394 unsigned char* view
,
3395 Mips_address view_address
,
3396 section_size_type view_size
,
3397 const Reloc_symbol_changes
*);
3399 // Scan the relocs during a relocatable link.
3401 scan_relocatable_relocs(Symbol_table
* symtab
,
3403 Sized_relobj_file
<size
, big_endian
>* object
,
3404 unsigned int data_shndx
,
3405 unsigned int sh_type
,
3406 const unsigned char* prelocs
,
3408 Output_section
* output_section
,
3409 bool needs_special_offset_handling
,
3410 size_t local_symbol_count
,
3411 const unsigned char* plocal_symbols
,
3412 Relocatable_relocs
*);
3414 // Scan the relocs for --emit-relocs.
3416 emit_relocs_scan(Symbol_table
* symtab
,
3418 Sized_relobj_file
<size
, big_endian
>* object
,
3419 unsigned int data_shndx
,
3420 unsigned int sh_type
,
3421 const unsigned char* prelocs
,
3423 Output_section
* output_section
,
3424 bool needs_special_offset_handling
,
3425 size_t local_symbol_count
,
3426 const unsigned char* plocal_syms
,
3427 Relocatable_relocs
* rr
);
3429 // Emit relocations for a section.
3431 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
3432 unsigned int sh_type
,
3433 const unsigned char* prelocs
,
3435 Output_section
* output_section
,
3436 typename
elfcpp::Elf_types
<size
>::Elf_Off
3437 offset_in_output_section
,
3438 unsigned char* view
,
3439 Mips_address view_address
,
3440 section_size_type view_size
,
3441 unsigned char* reloc_view
,
3442 section_size_type reloc_view_size
);
3444 // Perform target-specific processing in a relocatable link. This is
3445 // only used if we use the relocation strategy RELOC_SPECIAL.
3447 relocate_special_relocatable(const Relocate_info
<size
, big_endian
>* relinfo
,
3448 unsigned int sh_type
,
3449 const unsigned char* preloc_in
,
3451 Output_section
* output_section
,
3452 typename
elfcpp::Elf_types
<size
>::Elf_Off
3453 offset_in_output_section
,
3454 unsigned char* view
,
3455 Mips_address view_address
,
3456 section_size_type view_size
,
3457 unsigned char* preloc_out
);
3459 // Return whether SYM is defined by the ABI.
3461 do_is_defined_by_abi(const Symbol
* sym
) const
3463 return ((strcmp(sym
->name(), "__gnu_local_gp") == 0)
3464 || (strcmp(sym
->name(), "_gp_disp") == 0)
3465 || (strcmp(sym
->name(), "___tls_get_addr") == 0));
3468 // Return the number of entries in the GOT.
3470 got_entry_count() const
3472 if (!this->has_got_section())
3474 return this->got_size() / (size
/8);
3477 // Return the number of entries in the PLT.
3479 plt_entry_count() const
3481 if (this->plt_
== NULL
)
3483 return this->plt_
->entry_count();
3486 // Return the offset of the first non-reserved PLT entry.
3488 first_plt_entry_offset() const
3489 { return this->plt_
->first_plt_entry_offset(); }
3491 // Return the size of each PLT entry.
3493 plt_entry_size() const
3494 { return this->plt_
->plt_entry_size(); }
3496 // Get the GOT section, creating it if necessary.
3497 Mips_output_data_got
<size
, big_endian
>*
3498 got_section(Symbol_table
*, Layout
*);
3500 // Get the GOT section.
3501 Mips_output_data_got
<size
, big_endian
>*
3504 gold_assert(this->got_
!= NULL
);
3508 // Get the .MIPS.stubs section, creating it if necessary.
3509 Mips_output_data_mips_stubs
<size
, big_endian
>*
3510 mips_stubs_section(Layout
* layout
);
3512 // Get the .MIPS.stubs section.
3513 Mips_output_data_mips_stubs
<size
, big_endian
>*
3514 mips_stubs_section() const
3516 gold_assert(this->mips_stubs_
!= NULL
);
3517 return this->mips_stubs_
;
3520 // Get the LA25 stub section, creating it if necessary.
3521 Mips_output_data_la25_stub
<size
, big_endian
>*
3522 la25_stub_section(Layout
*);
3524 // Get the LA25 stub section.
3525 Mips_output_data_la25_stub
<size
, big_endian
>*
3528 gold_assert(this->la25_stub_
!= NULL
);
3529 return this->la25_stub_
;
3532 // Get gp value. It has the value of .got + 0x7FF0.
3536 if (this->gp_
!= NULL
)
3537 return this->gp_
->value();
3541 // Get gp value. It has the value of .got + 0x7FF0. Adjust it for
3542 // multi-GOT links so that OBJECT's GOT + 0x7FF0 is returned.
3544 adjusted_gp_value(const Mips_relobj
<size
, big_endian
>* object
)
3546 if (this->gp_
== NULL
)
3549 bool multi_got
= false;
3550 if (this->has_got_section())
3551 multi_got
= this->got_section()->multi_got();
3553 return this->gp_
->value();
3555 return this->gp_
->value() + this->got_section()->get_got_offset(object
);
3558 // Get the dynamic reloc section, creating it if necessary.
3560 rel_dyn_section(Layout
*);
3563 do_has_custom_set_dynsym_indexes() const
3566 // Don't emit input .reginfo/.MIPS.abiflags sections to
3567 // output .reginfo/.MIPS.abiflags.
3569 do_should_include_section(elfcpp::Elf_Word sh_type
) const
3571 return ((sh_type
!= elfcpp::SHT_MIPS_REGINFO
)
3572 && (sh_type
!= elfcpp::SHT_MIPS_ABIFLAGS
));
3575 // Set the dynamic symbol indexes. INDEX is the index of the first
3576 // global dynamic symbol. Pointers to the symbols are stored into the
3577 // vector SYMS. The names are added to DYNPOOL. This returns an
3578 // updated dynamic symbol index.
3580 do_set_dynsym_indexes(std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
3581 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
3582 Versions
* versions
, Symbol_table
* symtab
) const;
3584 // Remove .MIPS.stubs entry for a symbol.
3586 remove_lazy_stub_entry(Mips_symbol
<size
>* sym
)
3588 if (this->mips_stubs_
!= NULL
)
3589 this->mips_stubs_
->remove_entry(sym
);
3592 // The value to write into got[1] for SVR4 targets, to identify it is
3593 // a GNU object. The dynamic linker can then use got[1] to store the
3596 mips_elf_gnu_got1_mask()
3598 if (this->is_output_n64())
3599 return (uint64_t)1 << 63;
3604 // Whether the output has microMIPS code. This is valid only after
3605 // merge_obj_e_flags() is called.
3607 is_output_micromips() const
3609 gold_assert(this->are_processor_specific_flags_set());
3610 return elfcpp::is_micromips(this->processor_specific_flags());
3613 // Whether the output uses N32 ABI. This is valid only after
3614 // merge_obj_e_flags() is called.
3616 is_output_n32() const
3618 gold_assert(this->are_processor_specific_flags_set());
3619 return elfcpp::abi_n32(this->processor_specific_flags());
3622 // Whether the output uses R6 ISA. This is valid only after
3623 // merge_obj_e_flags() is called.
3625 is_output_r6() const
3627 gold_assert(this->are_processor_specific_flags_set());
3628 return elfcpp::r6_isa(this->processor_specific_flags());
3631 // Whether the output uses N64 ABI.
3633 is_output_n64() const
3634 { return size
== 64; }
3636 // Whether the output uses NEWABI. This is valid only after
3637 // merge_obj_e_flags() is called.
3639 is_output_newabi() const
3640 { return this->is_output_n32() || this->is_output_n64(); }
3642 // Whether we can only use 32-bit microMIPS instructions.
3644 use_32bit_micromips_instructions() const
3645 { return this->insn32_
; }
3647 // Return the r_sym field from a relocation.
3649 get_r_sym(const unsigned char* preloc
) const
3651 // Since REL and RELA relocs share the same structure through
3652 // the r_info field, we can just use REL here.
3653 Reltype
rel(preloc
);
3654 return Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
3659 // Return the value to use for a dynamic symbol which requires special
3660 // treatment. This is how we support equality comparisons of function
3661 // pointers across shared library boundaries, as described in the
3662 // processor specific ABI supplement.
3664 do_dynsym_value(const Symbol
* gsym
) const;
3666 // Make an ELF object.
3668 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
3669 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
);
3672 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
3673 const elfcpp::Ehdr
<size
, !big_endian
>&)
3674 { gold_unreachable(); }
3676 // Make an output section.
3678 do_make_output_section(const char* name
, elfcpp::Elf_Word type
,
3679 elfcpp::Elf_Xword flags
)
3681 if (type
== elfcpp::SHT_MIPS_OPTIONS
)
3682 return new Mips_output_section_options
<size
, big_endian
>(name
, type
,
3685 return new Output_section(name
, type
, flags
);
3688 // Adjust ELF file header.
3690 do_adjust_elf_header(unsigned char* view
, int len
);
3692 // Get the custom dynamic tag value.
3694 do_dynamic_tag_custom_value(elfcpp::DT
) const;
3696 // Adjust the value written to the dynamic symbol table.
3698 do_adjust_dyn_symbol(const Symbol
* sym
, unsigned char* view
) const
3700 elfcpp::Sym
<size
, big_endian
> isym(view
);
3701 elfcpp::Sym_write
<size
, big_endian
> osym(view
);
3702 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
3704 // Keep dynamic compressed symbols odd. This allows the dynamic linker
3705 // to treat compressed symbols like any other.
3706 Mips_address value
= isym
.get_st_value();
3707 if (mips_sym
->is_mips16() && value
!= 0)
3709 if (!mips_sym
->has_mips16_fn_stub())
3713 // If we have a MIPS16 function with a stub, the dynamic symbol
3714 // must refer to the stub, since only the stub uses the standard
3715 // calling conventions. Stub contains MIPS32 code, so don't add +1
3718 // There is a code which does this in the method
3719 // Target_mips::do_dynsym_value, but that code will only be
3720 // executed if the symbol is from dynobj.
3721 // TODO(sasa): GNU ld also changes the value in non-dynamic symbol
3724 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
3725 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
3726 value
= fn_stub
->output_address();
3727 osym
.put_st_size(fn_stub
->section_size());
3730 osym
.put_st_value(value
);
3731 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(),
3732 mips_sym
->nonvis() - (elfcpp::STO_MIPS16
>> 2)));
3734 else if ((mips_sym
->is_micromips()
3735 // Stubs are always microMIPS if there is any microMIPS code in
3737 || (this->is_output_micromips() && mips_sym
->has_lazy_stub()))
3740 osym
.put_st_value(value
| 1);
3741 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(),
3742 mips_sym
->nonvis() - (elfcpp::STO_MICROMIPS
>> 2)));
3747 // The class which scans relocations.
3755 get_reference_flags(unsigned int r_type
);
3758 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3759 Sized_relobj_file
<size
, big_endian
>* object
,
3760 unsigned int data_shndx
,
3761 Output_section
* output_section
,
3762 const Reltype
& reloc
, unsigned int r_type
,
3763 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3767 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3768 Sized_relobj_file
<size
, big_endian
>* object
,
3769 unsigned int data_shndx
,
3770 Output_section
* output_section
,
3771 const Relatype
& reloc
, unsigned int r_type
,
3772 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3776 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3777 Sized_relobj_file
<size
, big_endian
>* object
,
3778 unsigned int data_shndx
,
3779 Output_section
* output_section
,
3780 const Relatype
* rela
,
3782 unsigned int rel_type
,
3783 unsigned int r_type
,
3784 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3788 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3789 Sized_relobj_file
<size
, big_endian
>* object
,
3790 unsigned int data_shndx
,
3791 Output_section
* output_section
,
3792 const Reltype
& reloc
, unsigned int r_type
,
3796 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3797 Sized_relobj_file
<size
, big_endian
>* object
,
3798 unsigned int data_shndx
,
3799 Output_section
* output_section
,
3800 const Relatype
& reloc
, unsigned int r_type
,
3804 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3805 Sized_relobj_file
<size
, big_endian
>* object
,
3806 unsigned int data_shndx
,
3807 Output_section
* output_section
,
3808 const Relatype
* rela
,
3810 unsigned int rel_type
,
3811 unsigned int r_type
,
3815 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
*,
3817 Sized_relobj_file
<size
, big_endian
>*,
3822 const elfcpp::Sym
<size
, big_endian
>&)
3826 global_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3828 Sized_relobj_file
<size
, big_endian
>*,
3832 unsigned int, Symbol
*)
3836 local_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3838 Sized_relobj_file
<size
, big_endian
>*,
3843 const elfcpp::Sym
<size
, big_endian
>&)
3847 global_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3849 Sized_relobj_file
<size
, big_endian
>*,
3853 unsigned int, Symbol
*)
3857 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
3858 unsigned int r_type
);
3861 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
3862 unsigned int r_type
, Symbol
*);
3865 // The class which implements relocation.
3870 : calculated_value_(0), calculate_only_(false)
3876 // Return whether a R_MIPS_32/R_MIPS_64 relocation needs to be applied.
3878 should_apply_static_reloc(const Mips_symbol
<size
>* gsym
,
3879 unsigned int r_type
,
3880 Output_section
* output_section
,
3881 Target_mips
* target
);
3883 // Do a relocation. Return false if the caller should not issue
3884 // any warnings about this relocation.
3886 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
3887 Target_mips
*, Output_section
*, size_t, const unsigned char*,
3888 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
3889 unsigned char*, Mips_address
, section_size_type
);
3892 // Result of the relocation.
3893 Valtype calculated_value_
;
3894 // Whether we have to calculate relocation instead of applying it.
3895 bool calculate_only_
;
3898 // This POD class holds the dynamic relocations that should be emitted instead
3899 // of R_MIPS_32, R_MIPS_REL32 and R_MIPS_64 relocations. We will emit these
3900 // relocations if it turns out that the symbol does not have static
3905 Dyn_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
3906 Mips_relobj
<size
, big_endian
>* relobj
, unsigned int shndx
,
3907 Output_section
* output_section
, Mips_address r_offset
)
3908 : sym_(sym
), r_type_(r_type
), relobj_(relobj
),
3909 shndx_(shndx
), output_section_(output_section
),
3913 // Emit this reloc if appropriate. This is called after we have
3914 // scanned all the relocations, so we know whether the symbol has
3915 // static relocations.
3917 emit(Reloc_section
* rel_dyn
, Mips_output_data_got
<size
, big_endian
>* got
,
3918 Symbol_table
* symtab
)
3920 if (!this->sym_
->has_static_relocs())
3922 got
->record_global_got_symbol(this->sym_
, this->relobj_
,
3923 this->r_type_
, true, false);
3924 if (!symbol_references_local(this->sym_
,
3925 this->sym_
->should_add_dynsym_entry(symtab
)))
3926 rel_dyn
->add_global(this->sym_
, this->r_type_
,
3927 this->output_section_
, this->relobj_
,
3928 this->shndx_
, this->r_offset_
);
3930 rel_dyn
->add_symbolless_global_addend(this->sym_
, this->r_type_
,
3931 this->output_section_
, this->relobj_
,
3932 this->shndx_
, this->r_offset_
);
3937 Mips_symbol
<size
>* sym_
;
3938 unsigned int r_type_
;
3939 Mips_relobj
<size
, big_endian
>* relobj_
;
3940 unsigned int shndx_
;
3941 Output_section
* output_section_
;
3942 Mips_address r_offset_
;
3945 // Adjust TLS relocation type based on the options and whether this
3946 // is a local symbol.
3947 static tls::Tls_optimization
3948 optimize_tls_reloc(bool is_final
, int r_type
);
3950 // Return whether there is a GOT section.
3952 has_got_section() const
3953 { return this->got_
!= NULL
; }
3955 // Check whether the given ELF header flags describe a 32-bit binary.
3957 mips_32bit_flags(elfcpp::Elf_Word
);
3960 mach_mips3000
= 3000,
3961 mach_mips3900
= 3900,
3962 mach_mips4000
= 4000,
3963 mach_mips4010
= 4010,
3964 mach_mips4100
= 4100,
3965 mach_mips4111
= 4111,
3966 mach_mips4120
= 4120,
3967 mach_mips4300
= 4300,
3968 mach_mips4400
= 4400,
3969 mach_mips4600
= 4600,
3970 mach_mips4650
= 4650,
3971 mach_mips5000
= 5000,
3972 mach_mips5400
= 5400,
3973 mach_mips5500
= 5500,
3974 mach_mips5900
= 5900,
3975 mach_mips6000
= 6000,
3976 mach_mips7000
= 7000,
3977 mach_mips8000
= 8000,
3978 mach_mips9000
= 9000,
3979 mach_mips10000
= 10000,
3980 mach_mips12000
= 12000,
3981 mach_mips14000
= 14000,
3982 mach_mips16000
= 16000,
3985 mach_mips_loongson_2e
= 3001,
3986 mach_mips_loongson_2f
= 3002,
3987 mach_mips_loongson_3a
= 3003,
3988 mach_mips_sb1
= 12310201, // octal 'SB', 01
3989 mach_mips_octeon
= 6501,
3990 mach_mips_octeonp
= 6601,
3991 mach_mips_octeon2
= 6502,
3992 mach_mips_octeon3
= 6503,
3993 mach_mips_xlr
= 887682, // decimal 'XLR'
3994 mach_mipsisa32
= 32,
3995 mach_mipsisa32r2
= 33,
3996 mach_mipsisa32r3
= 34,
3997 mach_mipsisa32r5
= 36,
3998 mach_mipsisa32r6
= 37,
3999 mach_mipsisa64
= 64,
4000 mach_mipsisa64r2
= 65,
4001 mach_mipsisa64r3
= 66,
4002 mach_mipsisa64r5
= 68,
4003 mach_mipsisa64r6
= 69,
4004 mach_mips_micromips
= 96
4007 // Return the MACH for a MIPS e_flags value.
4009 elf_mips_mach(elfcpp::Elf_Word
);
4011 // Return the MACH for each .MIPS.abiflags ISA Extension.
4013 mips_isa_ext_mach(unsigned int);
4015 // Return the .MIPS.abiflags value representing each ISA Extension.
4017 mips_isa_ext(unsigned int);
4019 // Update the isa_level, isa_rev, isa_ext fields of abiflags.
4021 update_abiflags_isa(const std::string
&, elfcpp::Elf_Word
,
4022 Mips_abiflags
<big_endian
>*);
4024 // Infer the content of the ABI flags based on the elf header.
4026 infer_abiflags(Mips_relobj
<size
, big_endian
>*, Mips_abiflags
<big_endian
>*);
4028 // Create abiflags from elf header or from .MIPS.abiflags section.
4030 create_abiflags(Mips_relobj
<size
, big_endian
>*, Mips_abiflags
<big_endian
>*);
4032 // Return the meaning of fp_abi, or "unknown" if not known.
4038 select_fp_abi(const std::string
&, int, int);
4040 // Merge attributes from input object.
4042 merge_obj_attributes(const std::string
&, const Attributes_section_data
*);
4044 // Merge abiflags from input object.
4046 merge_obj_abiflags(const std::string
&, Mips_abiflags
<big_endian
>*);
4048 // Check whether machine EXTENSION is an extension of machine BASE.
4050 mips_mach_extends(unsigned int, unsigned int);
4052 // Merge file header flags from input object.
4054 merge_obj_e_flags(const std::string
&, elfcpp::Elf_Word
);
4056 // Encode ISA level and revision as a single value.
4058 level_rev(unsigned char isa_level
, unsigned char isa_rev
) const
4059 { return (isa_level
<< 3) | isa_rev
; }
4061 // True if we are linking for CPUs that are faster if JAL is converted to BAL.
4066 // True if we are linking for CPUs that are faster if JALR is converted to
4067 // BAL. This should be safe for all architectures. We enable this predicate
4073 // True if we are linking for CPUs that are faster if JR is converted to B.
4074 // This should be safe for all architectures. We enable this predicate for
4080 // Return the size of the GOT section.
4084 gold_assert(this->got_
!= NULL
);
4085 return this->got_
->data_size();
4088 // Create a PLT entry for a global symbol referenced by r_type relocation.
4090 make_plt_entry(Symbol_table
*, Layout
*, Mips_symbol
<size
>*,
4091 unsigned int r_type
);
4093 // Get the PLT section.
4094 Mips_output_data_plt
<size
, big_endian
>*
4097 gold_assert(this->plt_
!= NULL
);
4101 // Get the GOT PLT section.
4102 const Mips_output_data_plt
<size
, big_endian
>*
4103 got_plt_section() const
4105 gold_assert(this->got_plt_
!= NULL
);
4106 return this->got_plt_
;
4109 // Copy a relocation against a global symbol.
4111 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
4112 Sized_relobj_file
<size
, big_endian
>* object
,
4113 unsigned int shndx
, Output_section
* output_section
,
4114 Symbol
* sym
, unsigned int r_type
, Mips_address r_offset
)
4116 this->copy_relocs_
.copy_reloc(symtab
, layout
,
4117 symtab
->get_sized_symbol
<size
>(sym
),
4118 object
, shndx
, output_section
,
4119 r_type
, r_offset
, 0,
4120 this->rel_dyn_section(layout
));
4124 dynamic_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
4125 Mips_relobj
<size
, big_endian
>* relobj
,
4126 unsigned int shndx
, Output_section
* output_section
,
4127 Mips_address r_offset
)
4129 this->dyn_relocs_
.push_back(Dyn_reloc(sym
, r_type
, relobj
, shndx
,
4130 output_section
, r_offset
));
4133 // Calculate value of _gp symbol.
4135 set_gp(Layout
*, Symbol_table
*);
4138 elf_mips_abi_name(elfcpp::Elf_Word e_flags
);
4140 elf_mips_mach_name(elfcpp::Elf_Word e_flags
);
4142 // Adds entries that describe how machines relate to one another. The entries
4143 // are ordered topologically with MIPS I extensions listed last. First
4144 // element is extension, second element is base.
4146 add_machine_extensions()
4148 // MIPS64r2 extensions.
4149 this->add_extension(mach_mips_octeon3
, mach_mips_octeon2
);
4150 this->add_extension(mach_mips_octeon2
, mach_mips_octeonp
);
4151 this->add_extension(mach_mips_octeonp
, mach_mips_octeon
);
4152 this->add_extension(mach_mips_octeon
, mach_mipsisa64r2
);
4153 this->add_extension(mach_mips_loongson_3a
, mach_mipsisa64r2
);
4155 // MIPS64 extensions.
4156 this->add_extension(mach_mipsisa64r2
, mach_mipsisa64
);
4157 this->add_extension(mach_mips_sb1
, mach_mipsisa64
);
4158 this->add_extension(mach_mips_xlr
, mach_mipsisa64
);
4160 // MIPS V extensions.
4161 this->add_extension(mach_mipsisa64
, mach_mips5
);
4163 // R10000 extensions.
4164 this->add_extension(mach_mips12000
, mach_mips10000
);
4165 this->add_extension(mach_mips14000
, mach_mips10000
);
4166 this->add_extension(mach_mips16000
, mach_mips10000
);
4168 // R5000 extensions. Note: the vr5500 ISA is an extension of the core
4169 // vr5400 ISA, but doesn't include the multimedia stuff. It seems
4170 // better to allow vr5400 and vr5500 code to be merged anyway, since
4171 // many libraries will just use the core ISA. Perhaps we could add
4172 // some sort of ASE flag if this ever proves a problem.
4173 this->add_extension(mach_mips5500
, mach_mips5400
);
4174 this->add_extension(mach_mips5400
, mach_mips5000
);
4176 // MIPS IV extensions.
4177 this->add_extension(mach_mips5
, mach_mips8000
);
4178 this->add_extension(mach_mips10000
, mach_mips8000
);
4179 this->add_extension(mach_mips5000
, mach_mips8000
);
4180 this->add_extension(mach_mips7000
, mach_mips8000
);
4181 this->add_extension(mach_mips9000
, mach_mips8000
);
4183 // VR4100 extensions.
4184 this->add_extension(mach_mips4120
, mach_mips4100
);
4185 this->add_extension(mach_mips4111
, mach_mips4100
);
4187 // MIPS III extensions.
4188 this->add_extension(mach_mips_loongson_2e
, mach_mips4000
);
4189 this->add_extension(mach_mips_loongson_2f
, mach_mips4000
);
4190 this->add_extension(mach_mips8000
, mach_mips4000
);
4191 this->add_extension(mach_mips4650
, mach_mips4000
);
4192 this->add_extension(mach_mips4600
, mach_mips4000
);
4193 this->add_extension(mach_mips4400
, mach_mips4000
);
4194 this->add_extension(mach_mips4300
, mach_mips4000
);
4195 this->add_extension(mach_mips4100
, mach_mips4000
);
4196 this->add_extension(mach_mips4010
, mach_mips4000
);
4197 this->add_extension(mach_mips5900
, mach_mips4000
);
4199 // MIPS32 extensions.
4200 this->add_extension(mach_mipsisa32r2
, mach_mipsisa32
);
4202 // MIPS II extensions.
4203 this->add_extension(mach_mips4000
, mach_mips6000
);
4204 this->add_extension(mach_mipsisa32
, mach_mips6000
);
4206 // MIPS I extensions.
4207 this->add_extension(mach_mips6000
, mach_mips3000
);
4208 this->add_extension(mach_mips3900
, mach_mips3000
);
4211 // Add value to MIPS extenstions.
4213 add_extension(unsigned int base
, unsigned int extension
)
4215 std::pair
<unsigned int, unsigned int> ext(base
, extension
);
4216 this->mips_mach_extensions_
.push_back(ext
);
4219 // Return the number of entries in the .dynsym section.
4220 unsigned int get_dt_mips_symtabno() const
4222 return ((unsigned int)(this->layout_
->dynsym_section()->data_size()
4223 / elfcpp::Elf_sizes
<size
>::sym_size
));
4224 // TODO(sasa): Entry size is MIPS_ELF_SYM_SIZE.
4227 // Information about this specific target which we pass to the
4228 // general Target structure.
4229 static const Target::Target_info mips_info
;
4231 Mips_output_data_got
<size
, big_endian
>* got_
;
4232 // gp symbol. It has the value of .got + 0x7FF0.
4233 Sized_symbol
<size
>* gp_
;
4235 Mips_output_data_plt
<size
, big_endian
>* plt_
;
4236 // The GOT PLT section.
4237 Output_data_space
* got_plt_
;
4238 // The dynamic reloc section.
4239 Reloc_section
* rel_dyn_
;
4240 // The .rld_map section.
4241 Output_data_zero_fill
* rld_map_
;
4242 // Relocs saved to avoid a COPY reloc.
4243 Mips_copy_relocs
<elfcpp::SHT_REL
, size
, big_endian
> copy_relocs_
;
4245 // A list of dyn relocs to be saved.
4246 std::vector
<Dyn_reloc
> dyn_relocs_
;
4248 // The LA25 stub section.
4249 Mips_output_data_la25_stub
<size
, big_endian
>* la25_stub_
;
4250 // Architecture extensions.
4251 std::vector
<std::pair
<unsigned int, unsigned int> > mips_mach_extensions_
;
4253 Mips_output_data_mips_stubs
<size
, big_endian
>* mips_stubs_
;
4255 // Attributes section data in output.
4256 Attributes_section_data
* attributes_section_data_
;
4257 // .MIPS.abiflags section data in output.
4258 Mips_abiflags
<big_endian
>* abiflags_
;
4263 typename
std::list
<got16_addend
<size
, big_endian
> > got16_addends_
;
4265 // Whether there is an input .MIPS.abiflags section.
4266 bool has_abiflags_section_
;
4268 // Whether the entry symbol is mips16 or micromips.
4269 bool entry_symbol_is_compressed_
;
4271 // Whether we can use only 32-bit microMIPS instructions.
4272 // TODO(sasa): This should be a linker option.
4276 // Helper structure for R_MIPS*_HI16/LO16 and R_MIPS*_GOT16/LO16 relocations.
4277 // It records high part of the relocation pair.
4279 template<int size
, bool big_endian
>
4282 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
4284 reloc_high(unsigned char* _view
, const Mips_relobj
<size
, big_endian
>* _object
,
4285 const Symbol_value
<size
>* _psymval
, Mips_address _addend
,
4286 unsigned int _r_type
, unsigned int _r_sym
, bool _extract_addend
,
4287 Mips_address _address
= 0, bool _gp_disp
= false)
4288 : view(_view
), object(_object
), psymval(_psymval
), addend(_addend
),
4289 r_type(_r_type
), r_sym(_r_sym
), extract_addend(_extract_addend
),
4290 address(_address
), gp_disp(_gp_disp
)
4293 unsigned char* view
;
4294 const Mips_relobj
<size
, big_endian
>* object
;
4295 const Symbol_value
<size
>* psymval
;
4296 Mips_address addend
;
4297 unsigned int r_type
;
4299 bool extract_addend
;
4300 Mips_address address
;
4304 template<int size
, bool big_endian
>
4305 class Mips_relocate_functions
: public Relocate_functions
<size
, big_endian
>
4307 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
4308 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
4309 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype16
;
4310 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
4311 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype64
;
4316 STATUS_OKAY
, // No error during relocation.
4317 STATUS_OVERFLOW
, // Relocation overflow.
4318 STATUS_BAD_RELOC
, // Relocation cannot be applied.
4319 STATUS_PCREL_UNALIGNED
// Unaligned PC-relative relocation.
4323 typedef Relocate_functions
<size
, big_endian
> Base
;
4324 typedef Mips_relocate_functions
<size
, big_endian
> This
;
4326 static typename
std::list
<reloc_high
<size
, big_endian
> > hi16_relocs
;
4327 static typename
std::list
<reloc_high
<size
, big_endian
> > got16_relocs
;
4328 static typename
std::list
<reloc_high
<size
, big_endian
> > pchi16_relocs
;
4330 template<int valsize
>
4331 static inline typename
This::Status
4332 check_overflow(Valtype value
)
4335 return (Bits
<valsize
>::has_overflow32(value
)
4336 ? This::STATUS_OVERFLOW
4337 : This::STATUS_OKAY
);
4339 return (Bits
<valsize
>::has_overflow(value
)
4340 ? This::STATUS_OVERFLOW
4341 : This::STATUS_OKAY
);
4345 should_shuffle_micromips_reloc(unsigned int r_type
)
4347 return (micromips_reloc(r_type
)
4348 && r_type
!= elfcpp::R_MICROMIPS_PC7_S1
4349 && r_type
!= elfcpp::R_MICROMIPS_PC10_S1
);
4353 // R_MIPS16_26 is used for the mips16 jal and jalx instructions.
4354 // Most mips16 instructions are 16 bits, but these instructions
4357 // The format of these instructions is:
4359 // +--------------+--------------------------------+
4360 // | JALX | X| Imm 20:16 | Imm 25:21 |
4361 // +--------------+--------------------------------+
4362 // | Immediate 15:0 |
4363 // +-----------------------------------------------+
4365 // JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
4366 // Note that the immediate value in the first word is swapped.
4368 // When producing a relocatable object file, R_MIPS16_26 is
4369 // handled mostly like R_MIPS_26. In particular, the addend is
4370 // stored as a straight 26-bit value in a 32-bit instruction.
4371 // (gas makes life simpler for itself by never adjusting a
4372 // R_MIPS16_26 reloc to be against a section, so the addend is
4373 // always zero). However, the 32 bit instruction is stored as 2
4374 // 16-bit values, rather than a single 32-bit value. In a
4375 // big-endian file, the result is the same; in a little-endian
4376 // file, the two 16-bit halves of the 32 bit value are swapped.
4377 // This is so that a disassembler can recognize the jal
4380 // When doing a final link, R_MIPS16_26 is treated as a 32 bit
4381 // instruction stored as two 16-bit values. The addend A is the
4382 // contents of the targ26 field. The calculation is the same as
4383 // R_MIPS_26. When storing the calculated value, reorder the
4384 // immediate value as shown above, and don't forget to store the
4385 // value as two 16-bit values.
4387 // To put it in MIPS ABI terms, the relocation field is T-targ26-16,
4391 // +--------+----------------------+
4395 // +--------+----------------------+
4398 // +----------+------+-------------+
4400 // | sub1 | | sub2 |
4401 // |0 9|10 15|16 31|
4402 // +----------+--------------------+
4403 // where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
4404 // ((sub1 << 16) | sub2)).
4406 // When producing a relocatable object file, the calculation is
4407 // (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
4408 // When producing a fully linked file, the calculation is
4409 // let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
4410 // ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
4412 // The table below lists the other MIPS16 instruction relocations.
4413 // Each one is calculated in the same way as the non-MIPS16 relocation
4414 // given on the right, but using the extended MIPS16 layout of 16-bit
4415 // immediate fields:
4417 // R_MIPS16_GPREL R_MIPS_GPREL16
4418 // R_MIPS16_GOT16 R_MIPS_GOT16
4419 // R_MIPS16_CALL16 R_MIPS_CALL16
4420 // R_MIPS16_HI16 R_MIPS_HI16
4421 // R_MIPS16_LO16 R_MIPS_LO16
4423 // A typical instruction will have a format like this:
4425 // +--------------+--------------------------------+
4426 // | EXTEND | Imm 10:5 | Imm 15:11 |
4427 // +--------------+--------------------------------+
4428 // | Major | rx | ry | Imm 4:0 |
4429 // +--------------+--------------------------------+
4431 // EXTEND is the five bit value 11110. Major is the instruction
4434 // All we need to do here is shuffle the bits appropriately.
4435 // As above, the two 16-bit halves must be swapped on a
4436 // little-endian system.
4438 // Similar to MIPS16, the two 16-bit halves in microMIPS must be swapped
4439 // on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1
4440 // and R_MICROMIPS_PC10_S1 relocs that apply to 16-bit instructions.
4443 mips_reloc_unshuffle(unsigned char* view
, unsigned int r_type
,
4446 if (!mips16_reloc(r_type
)
4447 && !should_shuffle_micromips_reloc(r_type
))
4450 // Pick up the first and second halfwords of the instruction.
4451 Valtype16 first
= elfcpp::Swap
<16, big_endian
>::readval(view
);
4452 Valtype16 second
= elfcpp::Swap
<16, big_endian
>::readval(view
+ 2);
4455 if (micromips_reloc(r_type
)
4456 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
4457 val
= first
<< 16 | second
;
4458 else if (r_type
!= elfcpp::R_MIPS16_26
)
4459 val
= (((first
& 0xf800) << 16) | ((second
& 0xffe0) << 11)
4460 | ((first
& 0x1f) << 11) | (first
& 0x7e0) | (second
& 0x1f));
4462 val
= (((first
& 0xfc00) << 16) | ((first
& 0x3e0) << 11)
4463 | ((first
& 0x1f) << 21) | second
);
4465 elfcpp::Swap
<32, big_endian
>::writeval(view
, val
);
4469 mips_reloc_shuffle(unsigned char* view
, unsigned int r_type
, bool jal_shuffle
)
4471 if (!mips16_reloc(r_type
)
4472 && !should_shuffle_micromips_reloc(r_type
))
4475 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4476 Valtype16 first
, second
;
4478 if (micromips_reloc(r_type
)
4479 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
4481 second
= val
& 0xffff;
4484 else if (r_type
!= elfcpp::R_MIPS16_26
)
4486 second
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
4487 first
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
4491 second
= val
& 0xffff;
4492 first
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
4493 | ((val
>> 21) & 0x1f);
4496 elfcpp::Swap
<16, big_endian
>::writeval(view
+ 2, second
);
4497 elfcpp::Swap
<16, big_endian
>::writeval(view
, first
);
4500 // R_MIPS_16: S + sign-extend(A)
4501 static inline typename
This::Status
4502 rel16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4503 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4504 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
4506 Valtype16
* wv
= reinterpret_cast<Valtype16
*>(view
);
4507 Valtype16 val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
4509 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
)
4512 Valtype x
= psymval
->value(object
, addend
);
4513 val
= Bits
<16>::bit_select32(val
, x
, 0xffffU
);
4517 *calculated_value
= x
;
4518 return This::STATUS_OKAY
;
4521 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
4523 return check_overflow
<16>(x
);
4527 static inline typename
This::Status
4528 rel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4529 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4530 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
4532 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4533 Valtype addend
= (extract_addend
4534 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
4536 Valtype x
= psymval
->value(object
, addend
);
4539 *calculated_value
= x
;
4541 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4543 return This::STATUS_OKAY
;
4546 // R_MIPS_JALR, R_MICROMIPS_JALR
4547 static inline typename
This::Status
4548 reljalr(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4549 const Symbol_value
<size
>* psymval
, Mips_address address
,
4550 Mips_address addend_a
, bool extract_addend
, bool cross_mode_jump
,
4551 unsigned int r_type
, bool jalr_to_bal
, bool jr_to_b
,
4552 bool calculate_only
, Valtype
* calculated_value
)
4554 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4555 Valtype addend
= extract_addend
? 0 : addend_a
;
4556 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4558 // Try converting J(AL)R to B(AL), if the target is in range.
4559 if (r_type
== elfcpp::R_MIPS_JALR
4561 && ((jalr_to_bal
&& val
== 0x0320f809) // jalr t9
4562 || (jr_to_b
&& val
== 0x03200008))) // jr t9
4564 int offset
= psymval
->value(object
, addend
) - (address
+ 4);
4565 if (!Bits
<18>::has_overflow32(offset
))
4567 if (val
== 0x03200008) // jr t9
4568 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4570 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4575 *calculated_value
= val
;
4577 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4579 return This::STATUS_OKAY
;
4582 // R_MIPS_PC32: S + A - P
4583 static inline typename
This::Status
4584 relpc32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4585 const Symbol_value
<size
>* psymval
, Mips_address address
,
4586 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4587 Valtype
* calculated_value
)
4589 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4590 Valtype addend
= (extract_addend
4591 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
4593 Valtype x
= psymval
->value(object
, addend
) - address
;
4596 *calculated_value
= x
;
4598 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4600 return This::STATUS_OKAY
;
4603 // R_MIPS_26, R_MIPS16_26, R_MICROMIPS_26_S1
4604 static inline typename
This::Status
4605 rel26(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4606 const Symbol_value
<size
>* psymval
, Mips_address address
,
4607 bool local
, Mips_address addend_a
, bool extract_addend
,
4608 const Symbol
* gsym
, bool cross_mode_jump
, unsigned int r_type
,
4609 bool jal_to_bal
, bool calculate_only
, Valtype
* calculated_value
)
4611 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4612 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4617 if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4618 addend
= (val
& 0x03ffffff) << 1;
4620 addend
= (val
& 0x03ffffff) << 2;
4625 // Make sure the target of JALX is word-aligned. Bit 0 must be
4626 // the correct ISA mode selector and bit 1 must be 0.
4627 if (!calculate_only
&& cross_mode_jump
4628 && (psymval
->value(object
, 0) & 3) != (r_type
== elfcpp::R_MIPS_26
))
4630 gold_warning(_("JALX to a non-word-aligned address"));
4631 return This::STATUS_BAD_RELOC
;
4634 // Shift is 2, unusually, for microMIPS JALX.
4635 unsigned int shift
=
4636 (!cross_mode_jump
&& r_type
== elfcpp::R_MICROMIPS_26_S1
) ? 1 : 2;
4640 x
= addend
| ((address
+ 4) & (0xfc000000 << shift
));
4644 x
= Bits
<27>::sign_extend32(addend
);
4646 x
= Bits
<28>::sign_extend32(addend
);
4648 x
= psymval
->value(object
, x
) >> shift
;
4650 if (!calculate_only
&& !local
&& !gsym
->is_weak_undefined()
4651 && ((x
>> 26) != ((address
+ 4) >> (26 + shift
))))
4652 return This::STATUS_OVERFLOW
;
4654 val
= Bits
<32>::bit_select32(val
, x
, 0x03ffffff);
4656 // If required, turn JAL into JALX.
4657 if (cross_mode_jump
)
4660 Valtype32 opcode
= val
>> 26;
4661 Valtype32 jalx_opcode
;
4663 // Check to see if the opcode is already JAL or JALX.
4664 if (r_type
== elfcpp::R_MIPS16_26
)
4666 ok
= (opcode
== 0x6) || (opcode
== 0x7);
4669 else if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4671 ok
= (opcode
== 0x3d) || (opcode
== 0x3c);
4676 ok
= (opcode
== 0x3) || (opcode
== 0x1d);
4680 // If the opcode is not JAL or JALX, there's a problem. We cannot
4681 // convert J or JALS to JALX.
4682 if (!calculate_only
&& !ok
)
4684 gold_error(_("Unsupported jump between ISA modes; consider "
4685 "recompiling with interlinking enabled."));
4686 return This::STATUS_BAD_RELOC
;
4689 // Make this the JALX opcode.
4690 val
= (val
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
4693 // Try converting JAL to BAL, if the target is in range.
4694 if (!parameters
->options().relocatable()
4697 && r_type
== elfcpp::R_MIPS_26
4698 && (val
>> 26) == 0x3))) // jal addr
4700 Valtype32 dest
= (x
<< 2) | (((address
+ 4) >> 28) << 28);
4701 int offset
= dest
- (address
+ 4);
4702 if (!Bits
<18>::has_overflow32(offset
))
4704 if (val
== 0x03200008) // jr t9
4705 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4707 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4712 *calculated_value
= val
;
4714 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4716 return This::STATUS_OKAY
;
4720 static inline typename
This::Status
4721 relpc16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4722 const Symbol_value
<size
>* psymval
, Mips_address address
,
4723 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4724 Valtype
* calculated_value
)
4726 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4727 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4729 Valtype addend
= (extract_addend
4730 ? Bits
<18>::sign_extend32((val
& 0xffff) << 2)
4733 Valtype x
= psymval
->value(object
, addend
) - address
;
4734 val
= Bits
<16>::bit_select32(val
, x
>> 2, 0xffff);
4738 *calculated_value
= x
>> 2;
4739 return This::STATUS_OKAY
;
4742 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4744 if (psymval
->value(object
, addend
) & 3)
4745 return This::STATUS_PCREL_UNALIGNED
;
4747 return check_overflow
<18>(x
);
4751 static inline typename
This::Status
4752 relpc21(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4753 const Symbol_value
<size
>* psymval
, Mips_address address
,
4754 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4755 Valtype
* calculated_value
)
4757 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4758 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4760 Valtype addend
= (extract_addend
4761 ? Bits
<23>::sign_extend32((val
& 0x1fffff) << 2)
4764 Valtype x
= psymval
->value(object
, addend
) - address
;
4765 val
= Bits
<21>::bit_select32(val
, x
>> 2, 0x1fffff);
4769 *calculated_value
= x
>> 2;
4770 return This::STATUS_OKAY
;
4773 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4775 if (psymval
->value(object
, addend
) & 3)
4776 return This::STATUS_PCREL_UNALIGNED
;
4778 return check_overflow
<23>(x
);
4782 static inline typename
This::Status
4783 relpc26(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4784 const Symbol_value
<size
>* psymval
, Mips_address address
,
4785 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4786 Valtype
* calculated_value
)
4788 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4789 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4791 Valtype addend
= (extract_addend
4792 ? Bits
<28>::sign_extend32((val
& 0x3ffffff) << 2)
4795 Valtype x
= psymval
->value(object
, addend
) - address
;
4796 val
= Bits
<26>::bit_select32(val
, x
>> 2, 0x3ffffff);
4800 *calculated_value
= x
>> 2;
4801 return This::STATUS_OKAY
;
4804 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4806 if (psymval
->value(object
, addend
) & 3)
4807 return This::STATUS_PCREL_UNALIGNED
;
4809 return check_overflow
<28>(x
);
4813 static inline typename
This::Status
4814 relpc18(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4815 const Symbol_value
<size
>* psymval
, Mips_address address
,
4816 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4817 Valtype
* calculated_value
)
4819 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4820 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4822 Valtype addend
= (extract_addend
4823 ? Bits
<21>::sign_extend32((val
& 0x3ffff) << 3)
4826 Valtype x
= psymval
->value(object
, addend
) - ((address
| 7) ^ 7);
4827 val
= Bits
<18>::bit_select32(val
, x
>> 3, 0x3ffff);
4831 *calculated_value
= x
>> 3;
4832 return This::STATUS_OKAY
;
4835 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4837 if (psymval
->value(object
, addend
) & 7)
4838 return This::STATUS_PCREL_UNALIGNED
;
4840 return check_overflow
<21>(x
);
4844 static inline typename
This::Status
4845 relpc19(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4846 const Symbol_value
<size
>* psymval
, Mips_address address
,
4847 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4848 Valtype
* calculated_value
)
4850 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4851 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4853 Valtype addend
= (extract_addend
4854 ? Bits
<21>::sign_extend32((val
& 0x7ffff) << 2)
4857 Valtype x
= psymval
->value(object
, addend
) - address
;
4858 val
= Bits
<19>::bit_select32(val
, x
>> 2, 0x7ffff);
4862 *calculated_value
= x
>> 2;
4863 return This::STATUS_OKAY
;
4866 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4868 if (psymval
->value(object
, addend
) & 3)
4869 return This::STATUS_PCREL_UNALIGNED
;
4871 return check_overflow
<21>(x
);
4875 static inline typename
This::Status
4876 relpchi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4877 const Symbol_value
<size
>* psymval
, Mips_address addend
,
4878 Mips_address address
, unsigned int r_sym
, bool extract_addend
)
4880 // Record the relocation. It will be resolved when we find pclo16 part.
4881 pchi16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
4882 addend
, 0, r_sym
, extract_addend
, address
));
4883 return This::STATUS_OKAY
;
4887 static inline typename
This::Status
4888 do_relpchi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4889 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
4890 Mips_address address
, bool extract_addend
, Valtype32 addend_lo
,
4891 bool calculate_only
, Valtype
* calculated_value
)
4893 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4894 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4896 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
4899 Valtype value
= psymval
->value(object
, addend
) - address
;
4900 Valtype x
= ((value
+ 0x8000) >> 16) & 0xffff;
4901 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4904 *calculated_value
= x
;
4906 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4908 return This::STATUS_OKAY
;
4912 static inline typename
This::Status
4913 relpclo16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4914 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4915 bool extract_addend
, Mips_address address
, unsigned int r_sym
,
4916 unsigned int rel_type
, bool calculate_only
,
4917 Valtype
* calculated_value
)
4919 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4920 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4922 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
4925 if (rel_type
== elfcpp::SHT_REL
)
4927 // Resolve pending R_MIPS_PCHI16 relocations.
4928 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it
=
4929 pchi16_relocs
.begin();
4930 while (it
!= pchi16_relocs
.end())
4932 reloc_high
<size
, big_endian
> pchi16
= *it
;
4933 if (pchi16
.r_sym
== r_sym
)
4935 do_relpchi16(pchi16
.view
, pchi16
.object
, pchi16
.psymval
,
4936 pchi16
.addend
, pchi16
.address
,
4937 pchi16
.extract_addend
, addend
, calculate_only
,
4939 it
= pchi16_relocs
.erase(it
);
4946 // Resolve R_MIPS_PCLO16 relocation.
4947 Valtype x
= psymval
->value(object
, addend
) - address
;
4948 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4951 *calculated_value
= x
;
4953 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4955 return This::STATUS_OKAY
;
4958 // R_MICROMIPS_PC7_S1
4959 static inline typename
This::Status
4960 relmicromips_pc7_s1(unsigned char* view
,
4961 const Mips_relobj
<size
, big_endian
>* object
,
4962 const Symbol_value
<size
>* psymval
, Mips_address address
,
4963 Mips_address addend_a
, bool extract_addend
,
4964 bool calculate_only
, Valtype
* calculated_value
)
4966 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4967 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4969 Valtype addend
= extract_addend
? Bits
<8>::sign_extend32((val
& 0x7f) << 1)
4972 Valtype x
= psymval
->value(object
, addend
) - address
;
4973 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x7f);
4977 *calculated_value
= x
>> 1;
4978 return This::STATUS_OKAY
;
4981 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4983 return check_overflow
<8>(x
);
4986 // R_MICROMIPS_PC10_S1
4987 static inline typename
This::Status
4988 relmicromips_pc10_s1(unsigned char* view
,
4989 const Mips_relobj
<size
, big_endian
>* object
,
4990 const Symbol_value
<size
>* psymval
, Mips_address address
,
4991 Mips_address addend_a
, bool extract_addend
,
4992 bool calculate_only
, Valtype
* calculated_value
)
4994 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4995 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4997 Valtype addend
= (extract_addend
4998 ? Bits
<11>::sign_extend32((val
& 0x3ff) << 1)
5001 Valtype x
= psymval
->value(object
, addend
) - address
;
5002 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x3ff);
5006 *calculated_value
= x
>> 1;
5007 return This::STATUS_OKAY
;
5010 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5012 return check_overflow
<11>(x
);
5015 // R_MICROMIPS_PC16_S1
5016 static inline typename
This::Status
5017 relmicromips_pc16_s1(unsigned char* view
,
5018 const Mips_relobj
<size
, big_endian
>* object
,
5019 const Symbol_value
<size
>* psymval
, Mips_address address
,
5020 Mips_address addend_a
, bool extract_addend
,
5021 bool calculate_only
, Valtype
* calculated_value
)
5023 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5024 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5026 Valtype addend
= (extract_addend
5027 ? Bits
<17>::sign_extend32((val
& 0xffff) << 1)
5030 Valtype x
= psymval
->value(object
, addend
) - address
;
5031 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0xffff);
5035 *calculated_value
= x
>> 1;
5036 return This::STATUS_OKAY
;
5039 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5041 return check_overflow
<17>(x
);
5044 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
5045 static inline typename
This::Status
5046 relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5047 const Symbol_value
<size
>* psymval
, Mips_address addend
,
5048 Mips_address address
, bool gp_disp
, unsigned int r_type
,
5049 unsigned int r_sym
, bool extract_addend
)
5051 // Record the relocation. It will be resolved when we find lo16 part.
5052 hi16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
5053 addend
, r_type
, r_sym
, extract_addend
, address
,
5055 return This::STATUS_OKAY
;
5058 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
5059 static inline typename
This::Status
5060 do_relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5061 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
5062 Mips_address address
, bool is_gp_disp
, unsigned int r_type
,
5063 bool extract_addend
, Valtype32 addend_lo
,
5064 Target_mips
<size
, big_endian
>* target
, bool calculate_only
,
5065 Valtype
* calculated_value
)
5067 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5068 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5070 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
5075 value
= psymval
->value(object
, addend
);
5078 // For MIPS16 ABI code we generate this sequence
5079 // 0: li $v0,%hi(_gp_disp)
5080 // 4: addiupc $v1,%lo(_gp_disp)
5084 // So the offsets of hi and lo relocs are the same, but the
5085 // base $pc is that used by the ADDIUPC instruction at $t9 + 4.
5086 // ADDIUPC clears the low two bits of the instruction address,
5087 // so the base is ($t9 + 4) & ~3.
5089 if (r_type
== elfcpp::R_MIPS16_HI16
)
5090 gp_disp
= (target
->adjusted_gp_value(object
)
5091 - ((address
+ 4) & ~0x3));
5092 // The microMIPS .cpload sequence uses the same assembly
5093 // instructions as the traditional psABI version, but the
5094 // incoming $t9 has the low bit set.
5095 else if (r_type
== elfcpp::R_MICROMIPS_HI16
)
5096 gp_disp
= target
->adjusted_gp_value(object
) - address
- 1;
5098 gp_disp
= target
->adjusted_gp_value(object
) - address
;
5099 value
= gp_disp
+ addend
;
5101 Valtype x
= ((value
+ 0x8000) >> 16) & 0xffff;
5102 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5106 *calculated_value
= x
;
5107 return This::STATUS_OKAY
;
5110 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5112 return (is_gp_disp
? check_overflow
<16>(x
)
5113 : This::STATUS_OKAY
);
5116 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
5117 static inline typename
This::Status
5118 relgot16_local(unsigned char* view
,
5119 const Mips_relobj
<size
, big_endian
>* object
,
5120 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5121 bool extract_addend
, unsigned int r_type
, unsigned int r_sym
)
5123 // Record the relocation. It will be resolved when we find lo16 part.
5124 got16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
5125 addend_a
, r_type
, r_sym
, extract_addend
));
5126 return This::STATUS_OKAY
;
5129 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
5130 static inline typename
This::Status
5131 do_relgot16_local(unsigned char* view
,
5132 const Mips_relobj
<size
, big_endian
>* object
,
5133 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
5134 bool extract_addend
, Valtype32 addend_lo
,
5135 Target_mips
<size
, big_endian
>* target
, bool calculate_only
,
5136 Valtype
* calculated_value
)
5138 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5139 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5141 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
5144 // Find GOT page entry.
5145 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000) >> 16)
5148 unsigned int got_offset
=
5149 target
->got_section()->get_got_page_offset(value
, object
);
5151 // Resolve the relocation.
5152 Valtype x
= target
->got_section()->gp_offset(got_offset
, object
);
5153 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5157 *calculated_value
= x
;
5158 return This::STATUS_OKAY
;
5161 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5163 return check_overflow
<16>(x
);
5166 // R_MIPS_LO16, R_MIPS16_LO16, R_MICROMIPS_LO16, R_MICROMIPS_HI0_LO16
5167 static inline typename
This::Status
5168 rello16(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
5169 const Mips_relobj
<size
, big_endian
>* object
,
5170 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5171 bool extract_addend
, Mips_address address
, bool is_gp_disp
,
5172 unsigned int r_type
, unsigned int r_sym
, unsigned int rel_type
,
5173 bool calculate_only
, Valtype
* calculated_value
)
5175 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5176 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5178 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
5181 if (rel_type
== elfcpp::SHT_REL
)
5183 typename
This::Status reloc_status
= This::STATUS_OKAY
;
5184 // Resolve pending R_MIPS_HI16 relocations.
5185 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it
=
5186 hi16_relocs
.begin();
5187 while (it
!= hi16_relocs
.end())
5189 reloc_high
<size
, big_endian
> hi16
= *it
;
5190 if (hi16
.r_sym
== r_sym
5191 && is_matching_lo16_reloc(hi16
.r_type
, r_type
))
5193 mips_reloc_unshuffle(hi16
.view
, hi16
.r_type
, false);
5194 reloc_status
= do_relhi16(hi16
.view
, hi16
.object
, hi16
.psymval
,
5195 hi16
.addend
, hi16
.address
, hi16
.gp_disp
,
5196 hi16
.r_type
, hi16
.extract_addend
, addend
,
5197 target
, calculate_only
, calculated_value
);
5198 mips_reloc_shuffle(hi16
.view
, hi16
.r_type
, false);
5199 if (reloc_status
== This::STATUS_OVERFLOW
)
5200 return This::STATUS_OVERFLOW
;
5201 it
= hi16_relocs
.erase(it
);
5207 // Resolve pending local R_MIPS_GOT16 relocations.
5208 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it2
=
5209 got16_relocs
.begin();
5210 while (it2
!= got16_relocs
.end())
5212 reloc_high
<size
, big_endian
> got16
= *it2
;
5213 if (got16
.r_sym
== r_sym
5214 && is_matching_lo16_reloc(got16
.r_type
, r_type
))
5216 mips_reloc_unshuffle(got16
.view
, got16
.r_type
, false);
5218 reloc_status
= do_relgot16_local(got16
.view
, got16
.object
,
5219 got16
.psymval
, got16
.addend
,
5220 got16
.extract_addend
, addend
, target
,
5221 calculate_only
, calculated_value
);
5223 mips_reloc_shuffle(got16
.view
, got16
.r_type
, false);
5224 if (reloc_status
== This::STATUS_OVERFLOW
)
5225 return This::STATUS_OVERFLOW
;
5226 it2
= got16_relocs
.erase(it2
);
5233 // Resolve R_MIPS_LO16 relocation.
5236 x
= psymval
->value(object
, addend
);
5239 // See the comment for R_MIPS16_HI16 above for the reason
5240 // for this conditional.
5242 if (r_type
== elfcpp::R_MIPS16_LO16
)
5243 gp_disp
= target
->adjusted_gp_value(object
) - (address
& ~0x3);
5244 else if (r_type
== elfcpp::R_MICROMIPS_LO16
5245 || r_type
== elfcpp::R_MICROMIPS_HI0_LO16
)
5246 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 3;
5248 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 4;
5249 // The MIPS ABI requires checking the R_MIPS_LO16 relocation
5250 // for overflow. Relocations against _gp_disp are normally
5251 // generated from the .cpload pseudo-op. It generates code
5252 // that normally looks like this:
5254 // lui $gp,%hi(_gp_disp)
5255 // addiu $gp,$gp,%lo(_gp_disp)
5258 // Here $t9 holds the address of the function being called,
5259 // as required by the MIPS ELF ABI. The R_MIPS_LO16
5260 // relocation can easily overflow in this situation, but the
5261 // R_MIPS_HI16 relocation will handle the overflow.
5262 // Therefore, we consider this a bug in the MIPS ABI, and do
5263 // not check for overflow here.
5264 x
= gp_disp
+ addend
;
5266 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5269 *calculated_value
= x
;
5271 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5273 return This::STATUS_OKAY
;
5276 // R_MIPS_CALL16, R_MIPS16_CALL16, R_MICROMIPS_CALL16
5277 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
5278 // R_MIPS_TLS_GD, R_MIPS16_TLS_GD, R_MICROMIPS_TLS_GD
5279 // R_MIPS_TLS_GOTTPREL, R_MIPS16_TLS_GOTTPREL, R_MICROMIPS_TLS_GOTTPREL
5280 // R_MIPS_TLS_LDM, R_MIPS16_TLS_LDM, R_MICROMIPS_TLS_LDM
5281 // R_MIPS_GOT_DISP, R_MICROMIPS_GOT_DISP
5282 static inline typename
This::Status
5283 relgot(unsigned char* view
, int gp_offset
, bool calculate_only
,
5284 Valtype
* calculated_value
)
5286 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5287 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5288 Valtype x
= gp_offset
;
5289 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5293 *calculated_value
= x
;
5294 return This::STATUS_OKAY
;
5297 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5299 return check_overflow
<16>(x
);
5303 static inline typename
This::Status
5304 releh(unsigned char* view
, int gp_offset
, bool calculate_only
,
5305 Valtype
* calculated_value
)
5307 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5308 Valtype x
= gp_offset
;
5312 *calculated_value
= x
;
5313 return This::STATUS_OKAY
;
5316 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5318 return check_overflow
<32>(x
);
5321 // R_MIPS_GOT_PAGE, R_MICROMIPS_GOT_PAGE
5322 static inline typename
This::Status
5323 relgotpage(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
5324 const Mips_relobj
<size
, big_endian
>* object
,
5325 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5326 bool extract_addend
, bool calculate_only
,
5327 Valtype
* calculated_value
)
5329 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5330 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
5331 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5333 // Find a GOT page entry that points to within 32KB of symbol + addend.
5334 Mips_address value
= (psymval
->value(object
, addend
) + 0x8000) & ~0xffff;
5335 unsigned int got_offset
=
5336 target
->got_section()->get_got_page_offset(value
, object
);
5338 Valtype x
= target
->got_section()->gp_offset(got_offset
, object
);
5339 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5343 *calculated_value
= x
;
5344 return This::STATUS_OKAY
;
5347 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5349 return check_overflow
<16>(x
);
5352 // R_MIPS_GOT_OFST, R_MICROMIPS_GOT_OFST
5353 static inline typename
This::Status
5354 relgotofst(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
5355 const Mips_relobj
<size
, big_endian
>* object
,
5356 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5357 bool extract_addend
, bool local
, bool calculate_only
,
5358 Valtype
* calculated_value
)
5360 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5361 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
5362 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5364 // For a local symbol, find a GOT page entry that points to within 32KB of
5365 // symbol + addend. Relocation value is the offset of the GOT page entry's
5366 // value from symbol + addend.
5367 // For a global symbol, relocation value is addend.
5371 // Find GOT page entry.
5372 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000)
5374 target
->got_section()->get_got_page_offset(value
, object
);
5376 x
= psymval
->value(object
, addend
) - value
;
5380 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5384 *calculated_value
= x
;
5385 return This::STATUS_OKAY
;
5388 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5390 return check_overflow
<16>(x
);
5393 // R_MIPS_GOT_HI16, R_MIPS_CALL_HI16,
5394 // R_MICROMIPS_GOT_HI16, R_MICROMIPS_CALL_HI16
5395 static inline typename
This::Status
5396 relgot_hi16(unsigned char* view
, int gp_offset
, bool calculate_only
,
5397 Valtype
* calculated_value
)
5399 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5400 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5401 Valtype x
= gp_offset
;
5402 x
= ((x
+ 0x8000) >> 16) & 0xffff;
5403 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5406 *calculated_value
= x
;
5408 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5410 return This::STATUS_OKAY
;
5413 // R_MIPS_GOT_LO16, R_MIPS_CALL_LO16,
5414 // R_MICROMIPS_GOT_LO16, R_MICROMIPS_CALL_LO16
5415 static inline typename
This::Status
5416 relgot_lo16(unsigned char* view
, int gp_offset
, bool calculate_only
,
5417 Valtype
* calculated_value
)
5419 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5420 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5421 Valtype x
= gp_offset
;
5422 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5425 *calculated_value
= x
;
5427 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5429 return This::STATUS_OKAY
;
5432 // R_MIPS_GPREL16, R_MIPS16_GPREL, R_MIPS_LITERAL, R_MICROMIPS_LITERAL
5433 // R_MICROMIPS_GPREL7_S2, R_MICROMIPS_GPREL16
5434 static inline typename
This::Status
5435 relgprel(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5436 const Symbol_value
<size
>* psymval
, Mips_address gp
,
5437 Mips_address addend_a
, bool extract_addend
, bool local
,
5438 unsigned int r_type
, bool calculate_only
,
5439 Valtype
* calculated_value
)
5441 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5442 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5447 if (r_type
== elfcpp::R_MICROMIPS_GPREL7_S2
)
5448 addend
= (val
& 0x7f) << 2;
5450 addend
= val
& 0xffff;
5451 // Only sign-extend the addend if it was extracted from the
5452 // instruction. If the addend was separate, leave it alone,
5453 // otherwise we may lose significant bits.
5454 addend
= Bits
<16>::sign_extend32(addend
);
5459 Valtype x
= psymval
->value(object
, addend
) - gp
;
5461 // If the symbol was local, any earlier relocatable links will
5462 // have adjusted its addend with the gp offset, so compensate
5463 // for that now. Don't do it for symbols forced local in this
5464 // link, though, since they won't have had the gp offset applied
5467 x
+= object
->gp_value();
5469 if (r_type
== elfcpp::R_MICROMIPS_GPREL7_S2
)
5470 val
= Bits
<32>::bit_select32(val
, x
, 0x7f);
5472 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5476 *calculated_value
= x
;
5477 return This::STATUS_OKAY
;
5480 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5482 if (check_overflow
<16>(x
) == This::STATUS_OVERFLOW
)
5484 gold_error(_("small-data section exceeds 64KB; lower small-data size "
5485 "limit (see option -G)"));
5486 return This::STATUS_OVERFLOW
;
5488 return This::STATUS_OKAY
;
5492 static inline typename
This::Status
5493 relgprel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5494 const Symbol_value
<size
>* psymval
, Mips_address gp
,
5495 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5496 Valtype
* calculated_value
)
5498 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5499 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5500 Valtype addend
= extract_addend
? val
: addend_a
;
5502 // R_MIPS_GPREL32 relocations are defined for local symbols only.
5503 Valtype x
= psymval
->value(object
, addend
) + object
->gp_value() - gp
;
5506 *calculated_value
= x
;
5508 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5510 return This::STATUS_OKAY
;
5513 // R_MIPS_TLS_TPREL_HI16, R_MIPS16_TLS_TPREL_HI16, R_MICROMIPS_TLS_TPREL_HI16
5514 // R_MIPS_TLS_DTPREL_HI16, R_MIPS16_TLS_DTPREL_HI16,
5515 // R_MICROMIPS_TLS_DTPREL_HI16
5516 static inline typename
This::Status
5517 tlsrelhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5518 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5519 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5520 Valtype
* calculated_value
)
5522 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5523 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5524 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5526 // tls symbol values are relative to tls_segment()->vaddr()
5527 Valtype x
= ((psymval
->value(object
, addend
) - tp_offset
) + 0x8000) >> 16;
5528 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5531 *calculated_value
= x
;
5533 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5535 return This::STATUS_OKAY
;
5538 // R_MIPS_TLS_TPREL_LO16, R_MIPS16_TLS_TPREL_LO16, R_MICROMIPS_TLS_TPREL_LO16,
5539 // R_MIPS_TLS_DTPREL_LO16, R_MIPS16_TLS_DTPREL_LO16,
5540 // R_MICROMIPS_TLS_DTPREL_LO16,
5541 static inline typename
This::Status
5542 tlsrello16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5543 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5544 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5545 Valtype
* calculated_value
)
5547 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5548 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5549 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5551 // tls symbol values are relative to tls_segment()->vaddr()
5552 Valtype x
= psymval
->value(object
, addend
) - tp_offset
;
5553 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5556 *calculated_value
= x
;
5558 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5560 return This::STATUS_OKAY
;
5563 // R_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL64,
5564 // R_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL64
5565 static inline typename
This::Status
5566 tlsrel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5567 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5568 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5569 Valtype
* calculated_value
)
5571 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5572 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5573 Valtype addend
= extract_addend
? val
: addend_a
;
5575 // tls symbol values are relative to tls_segment()->vaddr()
5576 Valtype x
= psymval
->value(object
, addend
) - tp_offset
;
5579 *calculated_value
= x
;
5581 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5583 return This::STATUS_OKAY
;
5586 // R_MIPS_SUB, R_MICROMIPS_SUB
5587 static inline typename
This::Status
5588 relsub(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5589 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5590 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
5592 Valtype64
* wv
= reinterpret_cast<Valtype64
*>(view
);
5593 Valtype64 addend
= (extract_addend
5594 ? elfcpp::Swap
<64, big_endian
>::readval(wv
)
5597 Valtype64 x
= psymval
->value(object
, -addend
);
5599 *calculated_value
= x
;
5601 elfcpp::Swap
<64, big_endian
>::writeval(wv
, x
);
5603 return This::STATUS_OKAY
;
5607 static inline typename
This::Status
5608 rel64(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5609 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5610 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
,
5611 bool apply_addend_only
)
5613 Valtype64
* wv
= reinterpret_cast<Valtype64
*>(view
);
5614 Valtype64 addend
= (extract_addend
5615 ? elfcpp::Swap
<64, big_endian
>::readval(wv
)
5618 Valtype64 x
= psymval
->value(object
, addend
);
5620 *calculated_value
= x
;
5623 if (apply_addend_only
)
5625 elfcpp::Swap
<64, big_endian
>::writeval(wv
, x
);
5628 return This::STATUS_OKAY
;
5631 // R_MIPS_HIGHER, R_MICROMIPS_HIGHER
5632 static inline typename
This::Status
5633 relhigher(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5634 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5635 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
5637 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5638 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5639 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
5642 Valtype x
= psymval
->value(object
, addend
);
5643 x
= ((x
+ (uint64_t) 0x80008000) >> 32) & 0xffff;
5644 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5647 *calculated_value
= x
;
5649 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5651 return This::STATUS_OKAY
;
5654 // R_MIPS_HIGHEST, R_MICROMIPS_HIGHEST
5655 static inline typename
This::Status
5656 relhighest(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5657 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5658 bool extract_addend
, bool calculate_only
,
5659 Valtype
* calculated_value
)
5661 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5662 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5663 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
5666 Valtype x
= psymval
->value(object
, addend
);
5667 x
= ((x
+ (uint64_t) 0x800080008000llu
) >> 48) & 0xffff;
5668 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5671 *calculated_value
= x
;
5673 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5675 return This::STATUS_OKAY
;
5679 template<int size
, bool big_endian
>
5680 typename
std::list
<reloc_high
<size
, big_endian
> >
5681 Mips_relocate_functions
<size
, big_endian
>::hi16_relocs
;
5683 template<int size
, bool big_endian
>
5684 typename
std::list
<reloc_high
<size
, big_endian
> >
5685 Mips_relocate_functions
<size
, big_endian
>::got16_relocs
;
5687 template<int size
, bool big_endian
>
5688 typename
std::list
<reloc_high
<size
, big_endian
> >
5689 Mips_relocate_functions
<size
, big_endian
>::pchi16_relocs
;
5691 // Mips_got_info methods.
5693 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
5694 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
5696 template<int size
, bool big_endian
>
5698 Mips_got_info
<size
, big_endian
>::record_local_got_symbol(
5699 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
,
5700 Mips_address addend
, unsigned int r_type
, unsigned int shndx
,
5701 bool is_section_symbol
)
5703 Mips_got_entry
<size
, big_endian
>* entry
=
5704 new Mips_got_entry
<size
, big_endian
>(object
, symndx
, addend
,
5705 mips_elf_reloc_tls_type(r_type
),
5706 shndx
, is_section_symbol
);
5707 this->record_got_entry(entry
, object
);
5710 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
5711 // in OBJECT. FOR_CALL is true if the caller is only interested in
5712 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
5715 template<int size
, bool big_endian
>
5717 Mips_got_info
<size
, big_endian
>::record_global_got_symbol(
5718 Mips_symbol
<size
>* mips_sym
, Mips_relobj
<size
, big_endian
>* object
,
5719 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
5722 mips_sym
->set_got_not_only_for_calls();
5724 // A global symbol in the GOT must also be in the dynamic symbol table.
5725 if (!mips_sym
->needs_dynsym_entry() && !mips_sym
->is_forced_local())
5727 switch (mips_sym
->visibility())
5729 case elfcpp::STV_INTERNAL
:
5730 case elfcpp::STV_HIDDEN
:
5731 mips_sym
->set_is_forced_local();
5734 mips_sym
->set_needs_dynsym_entry();
5739 unsigned char tls_type
= mips_elf_reloc_tls_type(r_type
);
5740 if (tls_type
== GOT_TLS_NONE
)
5741 this->global_got_symbols_
.insert(mips_sym
);
5745 if (mips_sym
->global_got_area() == GGA_NONE
)
5746 mips_sym
->set_global_got_area(GGA_RELOC_ONLY
);
5750 Mips_got_entry
<size
, big_endian
>* entry
=
5751 new Mips_got_entry
<size
, big_endian
>(mips_sym
, tls_type
);
5753 this->record_got_entry(entry
, object
);
5756 // Add ENTRY to master GOT and to OBJECT's GOT.
5758 template<int size
, bool big_endian
>
5760 Mips_got_info
<size
, big_endian
>::record_got_entry(
5761 Mips_got_entry
<size
, big_endian
>* entry
,
5762 Mips_relobj
<size
, big_endian
>* object
)
5764 this->got_entries_
.insert(entry
);
5766 // Create the GOT entry for the OBJECT's GOT.
5767 Mips_got_info
<size
, big_endian
>* g
= object
->get_or_create_got_info();
5768 Mips_got_entry
<size
, big_endian
>* entry2
=
5769 new Mips_got_entry
<size
, big_endian
>(*entry
);
5771 g
->got_entries_
.insert(entry2
);
5774 // Record that OBJECT has a page relocation against symbol SYMNDX and
5775 // that ADDEND is the addend for that relocation.
5776 // This function creates an upper bound on the number of GOT slots
5777 // required; no attempt is made to combine references to non-overridable
5778 // global symbols across multiple input files.
5780 template<int size
, bool big_endian
>
5782 Mips_got_info
<size
, big_endian
>::record_got_page_entry(
5783 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
, int addend
)
5785 struct Got_page_range
**range_ptr
, *range
;
5786 int old_pages
, new_pages
;
5788 // Find the Got_page_entry for this symbol.
5789 Got_page_entry
* entry
= new Got_page_entry(object
, symndx
);
5790 typename
Got_page_entry_set::iterator it
=
5791 this->got_page_entries_
.find(entry
);
5792 if (it
!= this->got_page_entries_
.end())
5795 this->got_page_entries_
.insert(entry
);
5797 // Add the same entry to the OBJECT's GOT.
5798 Got_page_entry
* entry2
= new Got_page_entry(*entry
);
5799 Mips_got_info
<size
, big_endian
>* g2
= object
->get_or_create_got_info();
5800 typename
Got_page_entry_set::iterator it2
=
5801 g2
->got_page_entries_
.find(entry
);
5802 if (it2
!= g2
->got_page_entries_
.end())
5805 g2
->got_page_entries_
.insert(entry2
);
5807 // Skip over ranges whose maximum extent cannot share a page entry
5809 range_ptr
= &entry
->ranges
;
5810 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
5811 range_ptr
= &(*range_ptr
)->next
;
5813 // If we scanned to the end of the list, or found a range whose
5814 // minimum extent cannot share a page entry with ADDEND, create
5815 // a new singleton range.
5817 if (!range
|| addend
< range
->min_addend
- 0xffff)
5819 range
= new Got_page_range();
5820 range
->next
= *range_ptr
;
5821 range
->min_addend
= addend
;
5822 range
->max_addend
= addend
;
5826 ++entry2
->num_pages
;
5827 ++this->page_gotno_
;
5832 // Remember how many pages the old range contributed.
5833 old_pages
= range
->get_max_pages();
5835 // Update the ranges.
5836 if (addend
< range
->min_addend
)
5837 range
->min_addend
= addend
;
5838 else if (addend
> range
->max_addend
)
5840 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
5842 old_pages
+= range
->next
->get_max_pages();
5843 range
->max_addend
= range
->next
->max_addend
;
5844 range
->next
= range
->next
->next
;
5847 range
->max_addend
= addend
;
5850 // Record any change in the total estimate.
5851 new_pages
= range
->get_max_pages();
5852 if (old_pages
!= new_pages
)
5854 entry
->num_pages
+= new_pages
- old_pages
;
5855 entry2
->num_pages
+= new_pages
- old_pages
;
5856 this->page_gotno_
+= new_pages
- old_pages
;
5857 g2
->page_gotno_
+= new_pages
- old_pages
;
5861 // Create all entries that should be in the local part of the GOT.
5863 template<int size
, bool big_endian
>
5865 Mips_got_info
<size
, big_endian
>::add_local_entries(
5866 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5868 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5869 // First two GOT entries are reserved. The first entry will be filled at
5870 // runtime. The second entry will be used by some runtime loaders.
5871 got
->add_constant(0);
5872 got
->add_constant(target
->mips_elf_gnu_got1_mask());
5874 for (typename
Got_entry_set::iterator
5875 p
= this->got_entries_
.begin();
5876 p
!= this->got_entries_
.end();
5879 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5880 if (entry
->is_for_local_symbol() && !entry
->is_tls_entry())
5882 got
->add_local(entry
->object(), entry
->symndx(),
5883 GOT_TYPE_STANDARD
, entry
->addend());
5884 unsigned int got_offset
= entry
->object()->local_got_offset(
5885 entry
->symndx(), GOT_TYPE_STANDARD
, entry
->addend());
5886 if (got
->multi_got() && this->index_
> 0
5887 && parameters
->options().output_is_position_independent())
5889 if (!entry
->is_section_symbol())
5890 target
->rel_dyn_section(layout
)->add_local(entry
->object(),
5891 entry
->symndx(), elfcpp::R_MIPS_REL32
, got
, got_offset
);
5893 target
->rel_dyn_section(layout
)->add_symbolless_local_addend(
5894 entry
->object(), entry
->symndx(), elfcpp::R_MIPS_REL32
,
5900 this->add_page_entries(target
, layout
);
5902 // Add global entries that should be in the local area.
5903 for (typename
Got_entry_set::iterator
5904 p
= this->got_entries_
.begin();
5905 p
!= this->got_entries_
.end();
5908 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5909 if (!entry
->is_for_global_symbol())
5912 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5913 if (mips_sym
->global_got_area() == GGA_NONE
&& !entry
->is_tls_entry())
5915 unsigned int got_type
;
5916 if (!got
->multi_got())
5917 got_type
= GOT_TYPE_STANDARD
;
5919 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
5920 if (got
->add_global(mips_sym
, got_type
))
5922 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5923 if (got
->multi_got() && this->index_
> 0
5924 && parameters
->options().output_is_position_independent())
5925 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
5926 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
5927 mips_sym
->got_offset(got_type
));
5933 // Create GOT page entries.
5935 template<int size
, bool big_endian
>
5937 Mips_got_info
<size
, big_endian
>::add_page_entries(
5938 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5940 if (this->page_gotno_
== 0)
5943 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5944 this->got_page_offset_start_
= got
->add_constant(0);
5945 if (got
->multi_got() && this->index_
> 0
5946 && parameters
->options().output_is_position_independent())
5947 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
5948 this->got_page_offset_start_
);
5949 int num_entries
= this->page_gotno_
;
5950 unsigned int prev_offset
= this->got_page_offset_start_
;
5951 while (--num_entries
> 0)
5953 unsigned int next_offset
= got
->add_constant(0);
5954 if (got
->multi_got() && this->index_
> 0
5955 && parameters
->options().output_is_position_independent())
5956 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
5958 gold_assert(next_offset
== prev_offset
+ size
/8);
5959 prev_offset
= next_offset
;
5961 this->got_page_offset_next_
= this->got_page_offset_start_
;
5964 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
5966 template<int size
, bool big_endian
>
5968 Mips_got_info
<size
, big_endian
>::add_global_entries(
5969 Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
5970 unsigned int non_reloc_only_global_gotno
)
5972 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5973 // Add GGA_NORMAL entries.
5974 unsigned int count
= 0;
5975 for (typename
Got_entry_set::iterator
5976 p
= this->got_entries_
.begin();
5977 p
!= this->got_entries_
.end();
5980 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5981 if (!entry
->is_for_global_symbol())
5984 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5985 if (mips_sym
->global_got_area() != GGA_NORMAL
)
5988 unsigned int got_type
;
5989 if (!got
->multi_got())
5990 got_type
= GOT_TYPE_STANDARD
;
5992 // In multi-GOT links, global symbol can be in both primary and
5993 // secondary GOT(s). By creating custom GOT type
5994 // (GOT_TYPE_STANDARD_MULTIGOT + got_index) we ensure that symbol
5995 // is added to secondary GOT(s).
5996 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
5997 if (!got
->add_global(mips_sym
, got_type
))
6000 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
6001 if (got
->multi_got() && this->index_
== 0)
6003 if (got
->multi_got() && this->index_
> 0)
6005 if (parameters
->options().output_is_position_independent()
6006 || (!parameters
->doing_static_link()
6007 && mips_sym
->is_from_dynobj() && !mips_sym
->is_undefined()))
6009 target
->rel_dyn_section(layout
)->add_global(
6010 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
6011 mips_sym
->got_offset(got_type
));
6012 got
->add_secondary_got_reloc(mips_sym
->got_offset(got_type
),
6013 elfcpp::R_MIPS_REL32
, mips_sym
);
6018 if (!got
->multi_got() || this->index_
== 0)
6020 if (got
->multi_got())
6022 // We need to allocate space in the primary GOT for GGA_NORMAL entries
6023 // of secondary GOTs, to ensure that GOT offsets of GGA_RELOC_ONLY
6024 // entries correspond to dynamic symbol indexes.
6025 while (count
< non_reloc_only_global_gotno
)
6027 got
->add_constant(0);
6032 // Add GGA_RELOC_ONLY entries.
6033 got
->add_reloc_only_entries();
6037 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
6039 template<int size
, bool big_endian
>
6041 Mips_got_info
<size
, big_endian
>::add_reloc_only_entries(
6042 Mips_output_data_got
<size
, big_endian
>* got
)
6044 for (typename
Global_got_entry_set::iterator
6045 p
= this->global_got_symbols_
.begin();
6046 p
!= this->global_got_symbols_
.end();
6049 Mips_symbol
<size
>* mips_sym
= *p
;
6050 if (mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
6052 unsigned int got_type
;
6053 if (!got
->multi_got())
6054 got_type
= GOT_TYPE_STANDARD
;
6056 got_type
= GOT_TYPE_STANDARD_MULTIGOT
;
6057 if (got
->add_global(mips_sym
, got_type
))
6058 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
6063 // Create TLS GOT entries.
6065 template<int size
, bool big_endian
>
6067 Mips_got_info
<size
, big_endian
>::add_tls_entries(
6068 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
6070 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
6071 // Add local tls entries.
6072 for (typename
Got_entry_set::iterator
6073 p
= this->got_entries_
.begin();
6074 p
!= this->got_entries_
.end();
6077 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
6078 if (!entry
->is_tls_entry() || !entry
->is_for_local_symbol())
6081 if (entry
->tls_type() == GOT_TLS_GD
)
6083 unsigned int got_type
= GOT_TYPE_TLS_PAIR
;
6084 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
6085 : elfcpp::R_MIPS_TLS_DTPMOD64
);
6086 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
6087 : elfcpp::R_MIPS_TLS_DTPREL64
);
6089 if (!parameters
->doing_static_link())
6091 got
->add_local_pair_with_rel(entry
->object(), entry
->symndx(),
6092 entry
->shndx(), got_type
,
6093 target
->rel_dyn_section(layout
),
6094 r_type1
, entry
->addend());
6095 unsigned int got_offset
=
6096 entry
->object()->local_got_offset(entry
->symndx(), got_type
,
6098 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
6099 entry
->object(), entry
->symndx());
6103 // We are doing a static link. Mark it as belong to module 1,
6105 unsigned int got_offset
= got
->add_constant(1);
6106 entry
->object()->set_local_got_offset(entry
->symndx(), got_type
,
6109 got
->add_constant(0);
6110 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
6111 entry
->object(), entry
->symndx());
6114 else if (entry
->tls_type() == GOT_TLS_IE
)
6116 unsigned int got_type
= GOT_TYPE_TLS_OFFSET
;
6117 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
6118 : elfcpp::R_MIPS_TLS_TPREL64
);
6119 if (!parameters
->doing_static_link())
6120 got
->add_local_with_rel(entry
->object(), entry
->symndx(), got_type
,
6121 target
->rel_dyn_section(layout
), r_type
,
6125 got
->add_local(entry
->object(), entry
->symndx(), got_type
,
6127 unsigned int got_offset
=
6128 entry
->object()->local_got_offset(entry
->symndx(), got_type
,
6130 got
->add_static_reloc(got_offset
, r_type
, entry
->object(),
6134 else if (entry
->tls_type() == GOT_TLS_LDM
)
6136 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
6137 : elfcpp::R_MIPS_TLS_DTPMOD64
);
6138 unsigned int got_offset
;
6139 if (!parameters
->doing_static_link())
6141 got_offset
= got
->add_constant(0);
6142 target
->rel_dyn_section(layout
)->add_local(
6143 entry
->object(), 0, r_type
, got
, got_offset
);
6146 // We are doing a static link. Just mark it as belong to module 1,
6148 got_offset
= got
->add_constant(1);
6150 got
->add_constant(0);
6151 got
->set_tls_ldm_offset(got_offset
, entry
->object());
6157 // Add global tls entries.
6158 for (typename
Got_entry_set::iterator
6159 p
= this->got_entries_
.begin();
6160 p
!= this->got_entries_
.end();
6163 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
6164 if (!entry
->is_tls_entry() || !entry
->is_for_global_symbol())
6167 Mips_symbol
<size
>* mips_sym
= entry
->sym();
6168 if (entry
->tls_type() == GOT_TLS_GD
)
6170 unsigned int got_type
;
6171 if (!got
->multi_got())
6172 got_type
= GOT_TYPE_TLS_PAIR
;
6174 got_type
= GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
6175 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
6176 : elfcpp::R_MIPS_TLS_DTPMOD64
);
6177 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
6178 : elfcpp::R_MIPS_TLS_DTPREL64
);
6179 if (!parameters
->doing_static_link())
6180 got
->add_global_pair_with_rel(mips_sym
, got_type
,
6181 target
->rel_dyn_section(layout
), r_type1
, r_type2
);
6184 // Add a GOT pair for for R_MIPS_TLS_GD. The creates a pair of
6185 // GOT entries. The first one is initialized to be 1, which is the
6186 // module index for the main executable and the second one 0. A
6187 // reloc of the type R_MIPS_TLS_DTPREL32/64 will be created for
6188 // the second GOT entry and will be applied by gold.
6189 unsigned int got_offset
= got
->add_constant(1);
6190 mips_sym
->set_got_offset(got_type
, got_offset
);
6191 got
->add_constant(0);
6192 got
->add_static_reloc(got_offset
+ size
/8, r_type2
, mips_sym
);
6195 else if (entry
->tls_type() == GOT_TLS_IE
)
6197 unsigned int got_type
;
6198 if (!got
->multi_got())
6199 got_type
= GOT_TYPE_TLS_OFFSET
;
6201 got_type
= GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
6202 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
6203 : elfcpp::R_MIPS_TLS_TPREL64
);
6204 if (!parameters
->doing_static_link())
6205 got
->add_global_with_rel(mips_sym
, got_type
,
6206 target
->rel_dyn_section(layout
), r_type
);
6209 got
->add_global(mips_sym
, got_type
);
6210 unsigned int got_offset
= mips_sym
->got_offset(got_type
);
6211 got
->add_static_reloc(got_offset
, r_type
, mips_sym
);
6219 // Decide whether the symbol needs an entry in the global part of the primary
6220 // GOT, setting global_got_area accordingly. Count the number of global
6221 // symbols that are in the primary GOT only because they have dynamic
6222 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
6224 template<int size
, bool big_endian
>
6226 Mips_got_info
<size
, big_endian
>::count_got_symbols(Symbol_table
* symtab
)
6228 for (typename
Global_got_entry_set::iterator
6229 p
= this->global_got_symbols_
.begin();
6230 p
!= this->global_got_symbols_
.end();
6233 Mips_symbol
<size
>* sym
= *p
;
6234 // Make a final decision about whether the symbol belongs in the
6235 // local or global GOT. Symbols that bind locally can (and in the
6236 // case of forced-local symbols, must) live in the local GOT.
6237 // Those that are aren't in the dynamic symbol table must also
6238 // live in the local GOT.
6240 if (!sym
->should_add_dynsym_entry(symtab
)
6241 || (sym
->got_only_for_calls()
6242 ? symbol_calls_local(sym
, sym
->should_add_dynsym_entry(symtab
))
6243 : symbol_references_local(sym
,
6244 sym
->should_add_dynsym_entry(symtab
))))
6245 // The symbol belongs in the local GOT. We no longer need this
6246 // entry if it was only used for relocations; those relocations
6247 // will be against the null or section symbol instead.
6248 sym
->set_global_got_area(GGA_NONE
);
6249 else if (sym
->global_got_area() == GGA_RELOC_ONLY
)
6251 ++this->reloc_only_gotno_
;
6252 ++this->global_gotno_
;
6257 // Return the offset of GOT page entry for VALUE. Initialize the entry with
6258 // VALUE if it is not initialized.
6260 template<int size
, bool big_endian
>
6262 Mips_got_info
<size
, big_endian
>::get_got_page_offset(Mips_address value
,
6263 Mips_output_data_got
<size
, big_endian
>* got
)
6265 typename
Got_page_offsets::iterator it
= this->got_page_offsets_
.find(value
);
6266 if (it
!= this->got_page_offsets_
.end())
6269 gold_assert(this->got_page_offset_next_
< this->got_page_offset_start_
6270 + (size
/8) * this->page_gotno_
);
6272 unsigned int got_offset
= this->got_page_offset_next_
;
6273 this->got_page_offsets_
[value
] = got_offset
;
6274 this->got_page_offset_next_
+= size
/8;
6275 got
->update_got_entry(got_offset
, value
);
6279 // Remove lazy-binding stubs for global symbols in this GOT.
6281 template<int size
, bool big_endian
>
6283 Mips_got_info
<size
, big_endian
>::remove_lazy_stubs(
6284 Target_mips
<size
, big_endian
>* target
)
6286 for (typename
Got_entry_set::iterator
6287 p
= this->got_entries_
.begin();
6288 p
!= this->got_entries_
.end();
6291 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
6292 if (entry
->is_for_global_symbol())
6293 target
->remove_lazy_stub_entry(entry
->sym());
6297 // Count the number of GOT entries required.
6299 template<int size
, bool big_endian
>
6301 Mips_got_info
<size
, big_endian
>::count_got_entries()
6303 for (typename
Got_entry_set::iterator
6304 p
= this->got_entries_
.begin();
6305 p
!= this->got_entries_
.end();
6308 this->count_got_entry(*p
);
6312 // Count the number of GOT entries required by ENTRY. Accumulate the result.
6314 template<int size
, bool big_endian
>
6316 Mips_got_info
<size
, big_endian
>::count_got_entry(
6317 Mips_got_entry
<size
, big_endian
>* entry
)
6319 if (entry
->is_tls_entry())
6320 this->tls_gotno_
+= mips_tls_got_entries(entry
->tls_type());
6321 else if (entry
->is_for_local_symbol()
6322 || entry
->sym()->global_got_area() == GGA_NONE
)
6323 ++this->local_gotno_
;
6325 ++this->global_gotno_
;
6328 // Add FROM's GOT entries.
6330 template<int size
, bool big_endian
>
6332 Mips_got_info
<size
, big_endian
>::add_got_entries(
6333 Mips_got_info
<size
, big_endian
>* from
)
6335 for (typename
Got_entry_set::iterator
6336 p
= from
->got_entries_
.begin();
6337 p
!= from
->got_entries_
.end();
6340 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
6341 if (this->got_entries_
.find(entry
) == this->got_entries_
.end())
6343 Mips_got_entry
<size
, big_endian
>* entry2
=
6344 new Mips_got_entry
<size
, big_endian
>(*entry
);
6345 this->got_entries_
.insert(entry2
);
6346 this->count_got_entry(entry
);
6351 // Add FROM's GOT page entries.
6353 template<int size
, bool big_endian
>
6355 Mips_got_info
<size
, big_endian
>::add_got_page_entries(
6356 Mips_got_info
<size
, big_endian
>* from
)
6358 for (typename
Got_page_entry_set::iterator
6359 p
= from
->got_page_entries_
.begin();
6360 p
!= from
->got_page_entries_
.end();
6363 Got_page_entry
* entry
= *p
;
6364 if (this->got_page_entries_
.find(entry
) == this->got_page_entries_
.end())
6366 Got_page_entry
* entry2
= new Got_page_entry(*entry
);
6367 this->got_page_entries_
.insert(entry2
);
6368 this->page_gotno_
+= entry
->num_pages
;
6373 // Mips_output_data_got methods.
6375 // Lay out the GOT. Add local, global and TLS entries. If GOT is
6376 // larger than 64K, create multi-GOT.
6378 template<int size
, bool big_endian
>
6380 Mips_output_data_got
<size
, big_endian
>::lay_out_got(Layout
* layout
,
6381 Symbol_table
* symtab
, const Input_objects
* input_objects
)
6383 // Decide which symbols need to go in the global part of the GOT and
6384 // count the number of reloc-only GOT symbols.
6385 this->master_got_info_
->count_got_symbols(symtab
);
6387 // Count the number of GOT entries.
6388 this->master_got_info_
->count_got_entries();
6390 unsigned int got_size
= this->master_got_info_
->got_size();
6391 if (got_size
> Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
)
6392 this->lay_out_multi_got(layout
, input_objects
);
6395 // Record that all objects use single GOT.
6396 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
6397 p
!= input_objects
->relobj_end();
6400 Mips_relobj
<size
, big_endian
>* object
=
6401 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
6402 if (object
->get_got_info() != NULL
)
6403 object
->set_got_info(this->master_got_info_
);
6406 this->master_got_info_
->add_local_entries(this->target_
, layout
);
6407 this->master_got_info_
->add_global_entries(this->target_
, layout
,
6409 this->master_got_info_
->add_tls_entries(this->target_
, layout
);
6413 // Create multi-GOT. For every GOT, add local, global and TLS entries.
6415 template<int size
, bool big_endian
>
6417 Mips_output_data_got
<size
, big_endian
>::lay_out_multi_got(Layout
* layout
,
6418 const Input_objects
* input_objects
)
6420 // Try to merge the GOTs of input objects together, as long as they
6421 // don't seem to exceed the maximum GOT size, choosing one of them
6422 // to be the primary GOT.
6423 this->merge_gots(input_objects
);
6425 // Every symbol that is referenced in a dynamic relocation must be
6426 // present in the primary GOT.
6427 this->primary_got_
->set_global_gotno(this->master_got_info_
->global_gotno());
6431 unsigned int offset
= 0;
6432 Mips_got_info
<size
, big_endian
>* g
= this->primary_got_
;
6436 g
->set_offset(offset
);
6438 g
->add_local_entries(this->target_
, layout
);
6440 g
->add_global_entries(this->target_
, layout
,
6441 (this->master_got_info_
->global_gotno()
6442 - this->master_got_info_
->reloc_only_gotno()));
6444 g
->add_global_entries(this->target_
, layout
, /*not used*/-1U);
6445 g
->add_tls_entries(this->target_
, layout
);
6447 // Forbid global symbols in every non-primary GOT from having
6448 // lazy-binding stubs.
6450 g
->remove_lazy_stubs(this->target_
);
6453 offset
+= g
->got_size();
6459 // Attempt to merge GOTs of different input objects. Try to use as much as
6460 // possible of the primary GOT, since it doesn't require explicit dynamic
6461 // relocations, but don't use objects that would reference global symbols
6462 // out of the addressable range. Failing the primary GOT, attempt to merge
6463 // with the current GOT, or finish the current GOT and then make make the new
6466 template<int size
, bool big_endian
>
6468 Mips_output_data_got
<size
, big_endian
>::merge_gots(
6469 const Input_objects
* input_objects
)
6471 gold_assert(this->primary_got_
== NULL
);
6472 Mips_got_info
<size
, big_endian
>* current
= NULL
;
6474 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
6475 p
!= input_objects
->relobj_end();
6478 Mips_relobj
<size
, big_endian
>* object
=
6479 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
6481 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
6485 g
->count_got_entries();
6487 // Work out the number of page, local and TLS entries.
6488 unsigned int estimate
= this->master_got_info_
->page_gotno();
6489 if (estimate
> g
->page_gotno())
6490 estimate
= g
->page_gotno();
6491 estimate
+= g
->local_gotno() + g
->tls_gotno();
6493 // We place TLS GOT entries after both locals and globals. The globals
6494 // for the primary GOT may overflow the normal GOT size limit, so be
6495 // sure not to merge a GOT which requires TLS with the primary GOT in that
6496 // case. This doesn't affect non-primary GOTs.
6497 estimate
+= (g
->tls_gotno() > 0 ? this->master_got_info_
->global_gotno()
6498 : g
->global_gotno());
6500 unsigned int max_count
=
6501 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
6502 if (estimate
<= max_count
)
6504 // If we don't have a primary GOT, use it as
6505 // a starting point for the primary GOT.
6506 if (!this->primary_got_
)
6508 this->primary_got_
= g
;
6512 // Try merging with the primary GOT.
6513 if (this->merge_got_with(g
, object
, this->primary_got_
))
6517 // If we can merge with the last-created GOT, do it.
6518 if (current
&& this->merge_got_with(g
, object
, current
))
6521 // Well, we couldn't merge, so create a new GOT. Don't check if it
6522 // fits; if it turns out that it doesn't, we'll get relocation
6523 // overflows anyway.
6524 g
->set_next(current
);
6528 // If we do not find any suitable primary GOT, create an empty one.
6529 if (this->primary_got_
== NULL
)
6530 this->primary_got_
= new Mips_got_info
<size
, big_endian
>();
6532 // Link primary GOT with secondary GOTs.
6533 this->primary_got_
->set_next(current
);
6536 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
6537 // this would lead to overflow, true if they were merged successfully.
6539 template<int size
, bool big_endian
>
6541 Mips_output_data_got
<size
, big_endian
>::merge_got_with(
6542 Mips_got_info
<size
, big_endian
>* from
,
6543 Mips_relobj
<size
, big_endian
>* object
,
6544 Mips_got_info
<size
, big_endian
>* to
)
6546 // Work out how many page entries we would need for the combined GOT.
6547 unsigned int estimate
= this->master_got_info_
->page_gotno();
6548 if (estimate
>= from
->page_gotno() + to
->page_gotno())
6549 estimate
= from
->page_gotno() + to
->page_gotno();
6551 // Conservatively estimate how many local and TLS entries would be needed.
6552 estimate
+= from
->local_gotno() + to
->local_gotno();
6553 estimate
+= from
->tls_gotno() + to
->tls_gotno();
6555 // If we're merging with the primary got, any TLS relocations will
6556 // come after the full set of global entries. Otherwise estimate those
6557 // conservatively as well.
6558 if (to
== this->primary_got_
&& (from
->tls_gotno() + to
->tls_gotno()) > 0)
6559 estimate
+= this->master_got_info_
->global_gotno();
6561 estimate
+= from
->global_gotno() + to
->global_gotno();
6563 // Bail out if the combined GOT might be too big.
6564 unsigned int max_count
=
6565 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
6566 if (estimate
> max_count
)
6569 // Transfer the object's GOT information from FROM to TO.
6570 to
->add_got_entries(from
);
6571 to
->add_got_page_entries(from
);
6573 // Record that OBJECT should use output GOT TO.
6574 object
->set_got_info(to
);
6579 // Write out the GOT.
6581 template<int size
, bool big_endian
>
6583 Mips_output_data_got
<size
, big_endian
>::do_write(Output_file
* of
)
6585 typedef Unordered_set
<Mips_symbol
<size
>*, Mips_symbol_hash
<size
> >
6586 Mips_stubs_entry_set
;
6588 // Call parent to write out GOT.
6589 Output_data_got
<size
, big_endian
>::do_write(of
);
6591 const off_t offset
= this->offset();
6592 const section_size_type oview_size
=
6593 convert_to_section_size_type(this->data_size());
6594 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6596 // Needed for fixing values of .got section.
6597 this->got_view_
= oview
;
6599 // Write lazy stub addresses.
6600 for (typename
Mips_stubs_entry_set::iterator
6601 p
= this->master_got_info_
->global_got_symbols().begin();
6602 p
!= this->master_got_info_
->global_got_symbols().end();
6605 Mips_symbol
<size
>* mips_sym
= *p
;
6606 if (mips_sym
->has_lazy_stub())
6608 Valtype
* wv
= reinterpret_cast<Valtype
*>(
6609 oview
+ this->get_primary_got_offset(mips_sym
));
6611 this->target_
->mips_stubs_section()->stub_address(mips_sym
);
6612 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
6616 // Add +1 to GGA_NONE nonzero MIPS16 and microMIPS entries.
6617 for (typename
Mips_stubs_entry_set::iterator
6618 p
= this->master_got_info_
->global_got_symbols().begin();
6619 p
!= this->master_got_info_
->global_got_symbols().end();
6622 Mips_symbol
<size
>* mips_sym
= *p
;
6623 if (!this->multi_got()
6624 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
6625 && mips_sym
->global_got_area() == GGA_NONE
6626 && mips_sym
->has_got_offset(GOT_TYPE_STANDARD
))
6628 Valtype
* wv
= reinterpret_cast<Valtype
*>(
6629 oview
+ mips_sym
->got_offset(GOT_TYPE_STANDARD
));
6630 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv
);
6634 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
6639 if (!this->secondary_got_relocs_
.empty())
6641 // Fixup for the secondary GOT R_MIPS_REL32 relocs. For global
6642 // secondary GOT entries with non-zero initial value copy the value
6643 // to the corresponding primary GOT entry, and set the secondary GOT
6645 // TODO(sasa): This is workaround. It needs to be investigated further.
6647 for (size_t i
= 0; i
< this->secondary_got_relocs_
.size(); ++i
)
6649 Static_reloc
& reloc(this->secondary_got_relocs_
[i
]);
6650 if (reloc
.symbol_is_global())
6652 Mips_symbol
<size
>* gsym
= reloc
.symbol();
6653 gold_assert(gsym
!= NULL
);
6655 unsigned got_offset
= reloc
.got_offset();
6656 gold_assert(got_offset
< oview_size
);
6658 // Find primary GOT entry.
6659 Valtype
* wv_prim
= reinterpret_cast<Valtype
*>(
6660 oview
+ this->get_primary_got_offset(gsym
));
6662 // Find secondary GOT entry.
6663 Valtype
* wv_sec
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6665 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv_sec
);
6668 elfcpp::Swap
<size
, big_endian
>::writeval(wv_prim
, value
);
6669 elfcpp::Swap
<size
, big_endian
>::writeval(wv_sec
, 0);
6670 gsym
->set_applied_secondary_got_fixup();
6675 of
->write_output_view(offset
, oview_size
, oview
);
6678 // We are done if there is no fix up.
6679 if (this->static_relocs_
.empty())
6682 Output_segment
* tls_segment
= this->layout_
->tls_segment();
6683 gold_assert(tls_segment
!= NULL
);
6685 for (size_t i
= 0; i
< this->static_relocs_
.size(); ++i
)
6687 Static_reloc
& reloc(this->static_relocs_
[i
]);
6690 if (!reloc
.symbol_is_global())
6692 Sized_relobj_file
<size
, big_endian
>* object
= reloc
.relobj();
6693 const Symbol_value
<size
>* psymval
=
6694 object
->local_symbol(reloc
.index());
6696 // We are doing static linking. Issue an error and skip this
6697 // relocation if the symbol is undefined or in a discarded_section.
6699 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
6700 if ((shndx
== elfcpp::SHN_UNDEF
)
6702 && shndx
!= elfcpp::SHN_UNDEF
6703 && !object
->is_section_included(shndx
)
6704 && !this->symbol_table_
->is_section_folded(object
, shndx
)))
6706 gold_error(_("undefined or discarded local symbol %u from "
6707 " object %s in GOT"),
6708 reloc
.index(), reloc
.relobj()->name().c_str());
6712 value
= psymval
->value(object
, 0);
6716 const Mips_symbol
<size
>* gsym
= reloc
.symbol();
6717 gold_assert(gsym
!= NULL
);
6719 // We are doing static linking. Issue an error and skip this
6720 // relocation if the symbol is undefined or in a discarded_section
6721 // unless it is a weakly_undefined symbol.
6722 if ((gsym
->is_defined_in_discarded_section() || gsym
->is_undefined())
6723 && !gsym
->is_weak_undefined())
6725 gold_error(_("undefined or discarded symbol %s in GOT"),
6730 if (!gsym
->is_weak_undefined())
6731 value
= gsym
->value();
6736 unsigned got_offset
= reloc
.got_offset();
6737 gold_assert(got_offset
< oview_size
);
6739 Valtype
* wv
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6742 switch (reloc
.r_type())
6744 case elfcpp::R_MIPS_TLS_DTPMOD32
:
6745 case elfcpp::R_MIPS_TLS_DTPMOD64
:
6748 case elfcpp::R_MIPS_TLS_DTPREL32
:
6749 case elfcpp::R_MIPS_TLS_DTPREL64
:
6750 x
= value
- elfcpp::DTP_OFFSET
;
6752 case elfcpp::R_MIPS_TLS_TPREL32
:
6753 case elfcpp::R_MIPS_TLS_TPREL64
:
6754 x
= value
- elfcpp::TP_OFFSET
;
6761 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, x
);
6764 of
->write_output_view(offset
, oview_size
, oview
);
6767 // Mips_relobj methods.
6769 // Count the local symbols. The Mips backend needs to know if a symbol
6770 // is a MIPS16 or microMIPS function or not. For global symbols, it is easy
6771 // because the Symbol object keeps the ELF symbol type and st_other field.
6772 // For local symbol it is harder because we cannot access this information.
6773 // So we override the do_count_local_symbol in parent and scan local symbols to
6774 // mark MIPS16 and microMIPS functions. This is not the most efficient way but
6775 // I do not want to slow down other ports by calling a per symbol target hook
6776 // inside Sized_relobj_file<size, big_endian>::do_count_local_symbols.
6778 template<int size
, bool big_endian
>
6780 Mips_relobj
<size
, big_endian
>::do_count_local_symbols(
6781 Stringpool_template
<char>* pool
,
6782 Stringpool_template
<char>* dynpool
)
6784 // Ask parent to count the local symbols.
6785 Sized_relobj_file
<size
, big_endian
>::do_count_local_symbols(pool
, dynpool
);
6786 const unsigned int loccount
= this->local_symbol_count();
6790 // Initialize the mips16 and micromips function bit-vector.
6791 this->local_symbol_is_mips16_
.resize(loccount
, false);
6792 this->local_symbol_is_micromips_
.resize(loccount
, false);
6794 // Read the symbol table section header.
6795 const unsigned int symtab_shndx
= this->symtab_shndx();
6796 elfcpp::Shdr
<size
, big_endian
>
6797 symtabshdr(this, this->elf_file()->section_header(symtab_shndx
));
6798 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
6800 // Read the local symbols.
6801 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
6802 gold_assert(loccount
== symtabshdr
.get_sh_info());
6803 off_t locsize
= loccount
* sym_size
;
6804 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
6805 locsize
, true, true);
6807 // Loop over the local symbols and mark any MIPS16 or microMIPS local symbols.
6809 // Skip the first dummy symbol.
6811 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
6813 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
6814 unsigned char st_other
= sym
.get_st_other();
6815 this->local_symbol_is_mips16_
[i
] = elfcpp::elf_st_is_mips16(st_other
);
6816 this->local_symbol_is_micromips_
[i
] =
6817 elfcpp::elf_st_is_micromips(st_other
);
6821 // Read the symbol information.
6823 template<int size
, bool big_endian
>
6825 Mips_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
6827 // Call parent class to read symbol information.
6828 this->base_read_symbols(sd
);
6830 // If this input file is a binary file, it has no processor
6832 Input_file::Format format
= this->input_file()->format();
6833 if (format
!= Input_file::FORMAT_ELF
)
6835 gold_assert(format
== Input_file::FORMAT_BINARY
);
6836 this->merge_processor_specific_data_
= false;
6840 // Read processor-specific flags in ELF file header.
6841 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
6842 elfcpp::Elf_sizes
<size
>::ehdr_size
,
6844 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
6845 this->processor_specific_flags_
= ehdr
.get_e_flags();
6847 // Get the section names.
6848 const unsigned char* pnamesu
= sd
->section_names
->data();
6849 const char* pnames
= reinterpret_cast<const char*>(pnamesu
);
6851 // Initialize the mips16 stub section bit-vectors.
6852 this->section_is_mips16_fn_stub_
.resize(this->shnum(), false);
6853 this->section_is_mips16_call_stub_
.resize(this->shnum(), false);
6854 this->section_is_mips16_call_fp_stub_
.resize(this->shnum(), false);
6856 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
6857 const unsigned char* pshdrs
= sd
->section_headers
->data();
6858 const unsigned char* ps
= pshdrs
+ shdr_size
;
6859 bool must_merge_processor_specific_data
= false;
6860 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
6862 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
6864 // Sometimes an object has no contents except the section name string
6865 // table and an empty symbol table with the undefined symbol. We
6866 // don't want to merge processor-specific data from such an object.
6867 if (shdr
.get_sh_type() == elfcpp::SHT_SYMTAB
)
6869 // Symbol table is not empty.
6870 const typename
elfcpp::Elf_types
<size
>::Elf_WXword sym_size
=
6871 elfcpp::Elf_sizes
<size
>::sym_size
;
6872 if (shdr
.get_sh_size() > sym_size
)
6873 must_merge_processor_specific_data
= true;
6875 else if (shdr
.get_sh_type() != elfcpp::SHT_STRTAB
)
6876 // If this is neither an empty symbol table nor a string table,
6878 must_merge_processor_specific_data
= true;
6880 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_REGINFO
)
6882 this->has_reginfo_section_
= true;
6883 // Read the gp value that was used to create this object. We need the
6884 // gp value while processing relocs. The .reginfo section is not used
6885 // in the 64-bit MIPS ELF ABI.
6886 section_offset_type section_offset
= shdr
.get_sh_offset();
6887 section_size_type section_size
=
6888 convert_to_section_size_type(shdr
.get_sh_size());
6889 const unsigned char* view
=
6890 this->get_view(section_offset
, section_size
, true, false);
6892 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 20);
6894 // Read the rest of .reginfo.
6895 this->gprmask_
= elfcpp::Swap
<size
, big_endian
>::readval(view
);
6896 this->cprmask1_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 4);
6897 this->cprmask2_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 8);
6898 this->cprmask3_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 12);
6899 this->cprmask4_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 16);
6902 if (shdr
.get_sh_type() == elfcpp::SHT_GNU_ATTRIBUTES
)
6904 gold_assert(this->attributes_section_data_
== NULL
);
6905 section_offset_type section_offset
= shdr
.get_sh_offset();
6906 section_size_type section_size
=
6907 convert_to_section_size_type(shdr
.get_sh_size());
6908 const unsigned char* view
=
6909 this->get_view(section_offset
, section_size
, true, false);
6910 this->attributes_section_data_
=
6911 new Attributes_section_data(view
, section_size
);
6914 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_ABIFLAGS
)
6916 gold_assert(this->abiflags_
== NULL
);
6917 section_offset_type section_offset
= shdr
.get_sh_offset();
6918 section_size_type section_size
=
6919 convert_to_section_size_type(shdr
.get_sh_size());
6920 const unsigned char* view
=
6921 this->get_view(section_offset
, section_size
, true, false);
6922 this->abiflags_
= new Mips_abiflags
<big_endian
>();
6924 this->abiflags_
->version
=
6925 elfcpp::Swap
<16, big_endian
>::readval(view
);
6926 if (this->abiflags_
->version
!= 0)
6928 gold_error(_("%s: .MIPS.abiflags section has "
6929 "unsupported version %u"),
6930 this->name().c_str(),
6931 this->abiflags_
->version
);
6934 this->abiflags_
->isa_level
=
6935 elfcpp::Swap
<8, big_endian
>::readval(view
+ 2);
6936 this->abiflags_
->isa_rev
=
6937 elfcpp::Swap
<8, big_endian
>::readval(view
+ 3);
6938 this->abiflags_
->gpr_size
=
6939 elfcpp::Swap
<8, big_endian
>::readval(view
+ 4);
6940 this->abiflags_
->cpr1_size
=
6941 elfcpp::Swap
<8, big_endian
>::readval(view
+ 5);
6942 this->abiflags_
->cpr2_size
=
6943 elfcpp::Swap
<8, big_endian
>::readval(view
+ 6);
6944 this->abiflags_
->fp_abi
=
6945 elfcpp::Swap
<8, big_endian
>::readval(view
+ 7);
6946 this->abiflags_
->isa_ext
=
6947 elfcpp::Swap
<32, big_endian
>::readval(view
+ 8);
6948 this->abiflags_
->ases
=
6949 elfcpp::Swap
<32, big_endian
>::readval(view
+ 12);
6950 this->abiflags_
->flags1
=
6951 elfcpp::Swap
<32, big_endian
>::readval(view
+ 16);
6952 this->abiflags_
->flags2
=
6953 elfcpp::Swap
<32, big_endian
>::readval(view
+ 20);
6956 // In the 64-bit ABI, .MIPS.options section holds register information.
6957 // A SHT_MIPS_OPTIONS section contains a series of options, each of which
6958 // starts with this header:
6962 // // Type of option.
6963 // unsigned char kind[1];
6964 // // Size of option descriptor, including header.
6965 // unsigned char size[1];
6966 // // Section index of affected section, or 0 for global option.
6967 // unsigned char section[2];
6968 // // Information specific to this kind of option.
6969 // unsigned char info[4];
6972 // For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and set
6973 // the gp value based on what we find. We may see both SHT_MIPS_REGINFO
6974 // and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case, they should agree.
6976 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_OPTIONS
)
6978 section_offset_type section_offset
= shdr
.get_sh_offset();
6979 section_size_type section_size
=
6980 convert_to_section_size_type(shdr
.get_sh_size());
6981 const unsigned char* view
=
6982 this->get_view(section_offset
, section_size
, true, false);
6983 const unsigned char* end
= view
+ section_size
;
6985 while (view
+ 8 <= end
)
6987 unsigned char kind
= elfcpp::Swap
<8, big_endian
>::readval(view
);
6988 unsigned char sz
= elfcpp::Swap
<8, big_endian
>::readval(view
+ 1);
6991 gold_error(_("%s: Warning: bad `%s' option size %u smaller "
6993 this->name().c_str(),
6994 this->mips_elf_options_section_name(), sz
);
6998 if (this->is_n64() && kind
== elfcpp::ODK_REGINFO
)
7000 // In the 64 bit ABI, an ODK_REGINFO option is the following
7001 // structure. The info field of the options header is not
7006 // // Mask of general purpose registers used.
7007 // unsigned char ri_gprmask[4];
7009 // unsigned char ri_pad[4];
7010 // // Mask of co-processor registers used.
7011 // unsigned char ri_cprmask[4][4];
7012 // // GP register value for this object file.
7013 // unsigned char ri_gp_value[8];
7016 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
7019 else if (kind
== elfcpp::ODK_REGINFO
)
7021 // In the 32 bit ABI, an ODK_REGINFO option is the following
7022 // structure. The info field of the options header is not
7023 // used. The same structure is used in .reginfo section.
7027 // unsigned char ri_gprmask[4];
7028 // unsigned char ri_cprmask[4][4];
7029 // unsigned char ri_gp_value[4];
7032 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
7039 const char* name
= pnames
+ shdr
.get_sh_name();
7040 this->section_is_mips16_fn_stub_
[i
] = is_prefix_of(".mips16.fn", name
);
7041 this->section_is_mips16_call_stub_
[i
] =
7042 is_prefix_of(".mips16.call.", name
);
7043 this->section_is_mips16_call_fp_stub_
[i
] =
7044 is_prefix_of(".mips16.call.fp.", name
);
7046 if (strcmp(name
, ".pdr") == 0)
7048 gold_assert(this->pdr_shndx_
== -1U);
7049 this->pdr_shndx_
= i
;
7054 if (!must_merge_processor_specific_data
)
7055 this->merge_processor_specific_data_
= false;
7058 // Discard MIPS16 stub secions that are not needed.
7060 template<int size
, bool big_endian
>
7062 Mips_relobj
<size
, big_endian
>::discard_mips16_stub_sections(Symbol_table
* symtab
)
7064 for (typename
Mips16_stubs_int_map::const_iterator
7065 it
= this->mips16_stub_sections_
.begin();
7066 it
!= this->mips16_stub_sections_
.end(); ++it
)
7068 Mips16_stub_section
<size
, big_endian
>* stub_section
= it
->second
;
7069 if (!stub_section
->is_target_found())
7071 gold_error(_("no relocation found in mips16 stub section '%s'"),
7072 stub_section
->object()
7073 ->section_name(stub_section
->shndx()).c_str());
7076 bool discard
= false;
7077 if (stub_section
->is_for_local_function())
7079 if (stub_section
->is_fn_stub())
7081 // This stub is for a local symbol. This stub will only
7082 // be needed if there is some relocation in this object,
7083 // other than a 16 bit function call, which refers to this
7085 if (!this->has_local_non_16bit_call_relocs(stub_section
->r_sym()))
7088 this->add_local_mips16_fn_stub(stub_section
);
7092 // This stub is for a local symbol. This stub will only
7093 // be needed if there is some relocation (R_MIPS16_26) in
7094 // this object that refers to this symbol.
7095 gold_assert(stub_section
->is_call_stub()
7096 || stub_section
->is_call_fp_stub());
7097 if (!this->has_local_16bit_call_relocs(stub_section
->r_sym()))
7100 this->add_local_mips16_call_stub(stub_section
);
7105 Mips_symbol
<size
>* gsym
= stub_section
->gsym();
7106 if (stub_section
->is_fn_stub())
7108 if (gsym
->has_mips16_fn_stub())
7109 // We already have a stub for this function.
7113 gsym
->set_mips16_fn_stub(stub_section
);
7114 if (gsym
->should_add_dynsym_entry(symtab
))
7116 // If we have a MIPS16 function with a stub, the
7117 // dynamic symbol must refer to the stub, since only
7118 // the stub uses the standard calling conventions.
7119 gsym
->set_need_fn_stub();
7120 if (gsym
->is_from_dynobj())
7121 gsym
->set_needs_dynsym_value();
7124 if (!gsym
->need_fn_stub())
7127 else if (stub_section
->is_call_stub())
7129 if (gsym
->is_mips16())
7130 // We don't need the call_stub; this is a 16 bit
7131 // function, so calls from other 16 bit functions are
7134 else if (gsym
->has_mips16_call_stub())
7135 // We already have a stub for this function.
7138 gsym
->set_mips16_call_stub(stub_section
);
7142 gold_assert(stub_section
->is_call_fp_stub());
7143 if (gsym
->is_mips16())
7144 // We don't need the call_stub; this is a 16 bit
7145 // function, so calls from other 16 bit functions are
7148 else if (gsym
->has_mips16_call_fp_stub())
7149 // We already have a stub for this function.
7152 gsym
->set_mips16_call_fp_stub(stub_section
);
7156 this->set_output_section(stub_section
->shndx(), NULL
);
7160 // Mips_output_data_la25_stub methods.
7162 // Template for standard LA25 stub.
7163 template<int size
, bool big_endian
>
7165 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_entry
[] =
7167 0x3c190000, // lui $25,%hi(func)
7168 0x08000000, // j func
7169 0x27390000, // add $25,$25,%lo(func)
7173 // Template for microMIPS LA25 stub.
7174 template<int size
, bool big_endian
>
7176 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_micromips_entry
[] =
7178 0x41b9, 0x0000, // lui t9,%hi(func)
7179 0xd400, 0x0000, // j func
7180 0x3339, 0x0000, // addiu t9,t9,%lo(func)
7181 0x0000, 0x0000 // nop
7184 // Create la25 stub for a symbol.
7186 template<int size
, bool big_endian
>
7188 Mips_output_data_la25_stub
<size
, big_endian
>::create_la25_stub(
7189 Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
7190 Mips_symbol
<size
>* gsym
)
7192 if (!gsym
->has_la25_stub())
7194 gsym
->set_la25_stub_offset(this->symbols_
.size() * 16);
7195 this->symbols_
.push_back(gsym
);
7196 this->create_stub_symbol(gsym
, symtab
, target
, 16);
7200 // Create a symbol for SYM stub's value and size, to help make the disassembly
7203 template<int size
, bool big_endian
>
7205 Mips_output_data_la25_stub
<size
, big_endian
>::create_stub_symbol(
7206 Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
7207 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
)
7209 std::string
name(".pic.");
7210 name
+= sym
->name();
7212 unsigned int offset
= sym
->la25_stub_offset();
7213 if (sym
->is_micromips())
7216 // Make it a local function.
7217 Symbol
* new_sym
= symtab
->define_in_output_data(name
.c_str(), NULL
,
7218 Symbol_table::PREDEFINED
,
7219 target
->la25_stub_section(),
7220 offset
, symsize
, elfcpp::STT_FUNC
,
7222 elfcpp::STV_DEFAULT
, 0,
7224 new_sym
->set_is_forced_local();
7227 // Write out la25 stubs. This uses the hand-coded instructions above,
7228 // and adjusts them as needed.
7230 template<int size
, bool big_endian
>
7232 Mips_output_data_la25_stub
<size
, big_endian
>::do_write(Output_file
* of
)
7234 const off_t offset
= this->offset();
7235 const section_size_type oview_size
=
7236 convert_to_section_size_type(this->data_size());
7237 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
7239 for (typename
std::vector
<Mips_symbol
<size
>*>::iterator
7240 p
= this->symbols_
.begin();
7241 p
!= this->symbols_
.end();
7244 Mips_symbol
<size
>* sym
= *p
;
7245 unsigned char* pov
= oview
+ sym
->la25_stub_offset();
7247 Mips_address target
= sym
->value();
7248 if (!sym
->is_micromips())
7250 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7251 la25_stub_entry
[0] | (((target
+ 0x8000) >> 16) & 0xffff));
7252 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7253 la25_stub_entry
[1] | ((target
>> 2) & 0x3ffffff));
7254 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
7255 la25_stub_entry
[2] | (target
& 0xffff));
7256 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12, la25_stub_entry
[3]);
7261 // First stub instruction. Paste high 16-bits of the target.
7262 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
7263 la25_stub_micromips_entry
[0]);
7264 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7265 ((target
+ 0x8000) >> 16) & 0xffff);
7266 // Second stub instruction. Paste low 26-bits of the target, shifted
7268 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
7269 la25_stub_micromips_entry
[2] | ((target
>> 17) & 0x3ff));
7270 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
7271 la25_stub_micromips_entry
[3] | ((target
>> 1) & 0xffff));
7272 // Third stub instruction. Paste low 16-bits of the target.
7273 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8,
7274 la25_stub_micromips_entry
[4]);
7275 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, target
& 0xffff);
7276 // Fourth stub instruction.
7277 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 12,
7278 la25_stub_micromips_entry
[6]);
7279 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 14,
7280 la25_stub_micromips_entry
[7]);
7284 of
->write_output_view(offset
, oview_size
, oview
);
7287 // Mips_output_data_plt methods.
7289 // The format of the first PLT entry in an O32 executable.
7290 template<int size
, bool big_endian
>
7291 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_o32
[] =
7293 0x3c1c0000, // lui $28, %hi(&GOTPLT[0])
7294 0x8f990000, // lw $25, %lo(&GOTPLT[0])($28)
7295 0x279c0000, // addiu $28, $28, %lo(&GOTPLT[0])
7296 0x031cc023, // subu $24, $24, $28
7297 0x03e07825, // or $15, $31, zero
7298 0x0018c082, // srl $24, $24, 2
7299 0x0320f809, // jalr $25
7300 0x2718fffe // subu $24, $24, 2
7303 // The format of the first PLT entry in an N32 executable. Different
7304 // because gp ($28) is not available; we use t2 ($14) instead.
7305 template<int size
, bool big_endian
>
7306 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n32
[] =
7308 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
7309 0x8dd90000, // lw $25, %lo(&GOTPLT[0])($14)
7310 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
7311 0x030ec023, // subu $24, $24, $14
7312 0x03e07825, // or $15, $31, zero
7313 0x0018c082, // srl $24, $24, 2
7314 0x0320f809, // jalr $25
7315 0x2718fffe // subu $24, $24, 2
7318 // The format of the first PLT entry in an N64 executable. Different
7319 // from N32 because of the increased size of GOT entries.
7320 template<int size
, bool big_endian
>
7321 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n64
[] =
7323 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
7324 0xddd90000, // ld $25, %lo(&GOTPLT[0])($14)
7325 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
7326 0x030ec023, // subu $24, $24, $14
7327 0x03e07825, // or $15, $31, zero
7328 0x0018c0c2, // srl $24, $24, 3
7329 0x0320f809, // jalr $25
7330 0x2718fffe // subu $24, $24, 2
7333 // The format of the microMIPS first PLT entry in an O32 executable.
7334 // We rely on v0 ($2) rather than t8 ($24) to contain the address
7335 // of the GOTPLT entry handled, so this stub may only be used when
7336 // all the subsequent PLT entries are microMIPS code too.
7338 // The trailing NOP is for alignment and correct disassembly only.
7339 template<int size
, bool big_endian
>
7340 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
7341 plt0_entry_micromips_o32
[] =
7343 0x7980, 0x0000, // addiupc $3, (&GOTPLT[0]) - .
7344 0xff23, 0x0000, // lw $25, 0($3)
7345 0x0535, // subu $2, $2, $3
7346 0x2525, // srl $2, $2, 2
7347 0x3302, 0xfffe, // subu $24, $2, 2
7348 0x0dff, // move $15, $31
7349 0x45f9, // jalrs $25
7350 0x0f83, // move $28, $3
7354 // The format of the microMIPS first PLT entry in an O32 executable
7355 // in the insn32 mode.
7356 template<int size
, bool big_endian
>
7357 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
7358 plt0_entry_micromips32_o32
[] =
7360 0x41bc, 0x0000, // lui $28, %hi(&GOTPLT[0])
7361 0xff3c, 0x0000, // lw $25, %lo(&GOTPLT[0])($28)
7362 0x339c, 0x0000, // addiu $28, $28, %lo(&GOTPLT[0])
7363 0x0398, 0xc1d0, // subu $24, $24, $28
7364 0x001f, 0x7a90, // or $15, $31, zero
7365 0x0318, 0x1040, // srl $24, $24, 2
7366 0x03f9, 0x0f3c, // jalr $25
7367 0x3318, 0xfffe // subu $24, $24, 2
7370 // The format of subsequent standard entries in the PLT.
7371 template<int size
, bool big_endian
>
7372 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry
[] =
7374 0x3c0f0000, // lui $15, %hi(.got.plt entry)
7375 0x01f90000, // l[wd] $25, %lo(.got.plt entry)($15)
7376 0x03200008, // jr $25
7377 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
7380 // The format of subsequent R6 PLT entries.
7381 template<int size
, bool big_endian
>
7382 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry_r6
[] =
7384 0x3c0f0000, // lui $15, %hi(.got.plt entry)
7385 0x01f90000, // l[wd] $25, %lo(.got.plt entry)($15)
7386 0x03200009, // jr $25
7387 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
7390 // The format of subsequent MIPS16 o32 PLT entries. We use v1 ($3) as a
7391 // temporary because t8 ($24) and t9 ($25) are not directly addressable.
7392 // Note that this differs from the GNU ld which uses both v0 ($2) and v1 ($3).
7393 // We cannot use v0 because MIPS16 call stubs from the CS toolchain expect
7394 // target function address in register v0.
7395 template<int size
, bool big_endian
>
7396 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry_mips16_o32
[] =
7398 0xb303, // lw $3, 12($pc)
7399 0x651b, // move $24, $3
7400 0x9b60, // lw $3, 0($3)
7402 0x653b, // move $25, $3
7404 0x0000, 0x0000 // .word (.got.plt entry)
7407 // The format of subsequent microMIPS o32 PLT entries. We use v0 ($2)
7408 // as a temporary because t8 ($24) is not addressable with ADDIUPC.
7409 template<int size
, bool big_endian
>
7410 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
7411 plt_entry_micromips_o32
[] =
7413 0x7900, 0x0000, // addiupc $2, (.got.plt entry) - .
7414 0xff22, 0x0000, // lw $25, 0($2)
7416 0x0f02 // move $24, $2
7419 // The format of subsequent microMIPS o32 PLT entries in the insn32 mode.
7420 template<int size
, bool big_endian
>
7421 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
7422 plt_entry_micromips32_o32
[] =
7424 0x41af, 0x0000, // lui $15, %hi(.got.plt entry)
7425 0xff2f, 0x0000, // lw $25, %lo(.got.plt entry)($15)
7426 0x0019, 0x0f3c, // jr $25
7427 0x330f, 0x0000 // addiu $24, $15, %lo(.got.plt entry)
7430 // Add an entry to the PLT for a symbol referenced by r_type relocation.
7432 template<int size
, bool big_endian
>
7434 Mips_output_data_plt
<size
, big_endian
>::add_entry(Mips_symbol
<size
>* gsym
,
7435 unsigned int r_type
)
7437 gold_assert(!gsym
->has_plt_offset());
7439 // Final PLT offset for a symbol will be set in method set_plt_offsets().
7440 gsym
->set_plt_offset(this->entry_count() * sizeof(plt_entry
)
7441 + sizeof(plt0_entry_o32
));
7442 this->symbols_
.push_back(gsym
);
7444 // Record whether the relocation requires a standard MIPS
7445 // or a compressed code entry.
7446 if (jal_reloc(r_type
))
7448 if (r_type
== elfcpp::R_MIPS_26
)
7449 gsym
->set_needs_mips_plt(true);
7451 gsym
->set_needs_comp_plt(true);
7454 section_offset_type got_offset
= this->got_plt_
->current_data_size();
7456 // Every PLT entry needs a GOT entry which points back to the PLT
7457 // entry (this will be changed by the dynamic linker, normally
7458 // lazily when the function is called).
7459 this->got_plt_
->set_current_data_size(got_offset
+ size
/8);
7461 gsym
->set_needs_dynsym_entry();
7462 this->rel_
->add_global(gsym
, elfcpp::R_MIPS_JUMP_SLOT
, this->got_plt_
,
7466 // Set final PLT offsets. For each symbol, determine whether standard or
7467 // compressed (MIPS16 or microMIPS) PLT entry is used.
7469 template<int size
, bool big_endian
>
7471 Mips_output_data_plt
<size
, big_endian
>::set_plt_offsets()
7473 // The sizes of individual PLT entries.
7474 unsigned int plt_mips_entry_size
= this->standard_plt_entry_size();
7475 unsigned int plt_comp_entry_size
= (!this->target_
->is_output_newabi()
7476 ? this->compressed_plt_entry_size() : 0);
7478 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
7479 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
7481 Mips_symbol
<size
>* mips_sym
= *p
;
7483 // There are no defined MIPS16 or microMIPS PLT entries for n32 or n64,
7484 // so always use a standard entry there.
7486 // If the symbol has a MIPS16 call stub and gets a PLT entry, then
7487 // all MIPS16 calls will go via that stub, and there is no benefit
7488 // to having a MIPS16 entry. And in the case of call_stub a
7489 // standard entry actually has to be used as the stub ends with a J
7491 if (this->target_
->is_output_newabi()
7492 || mips_sym
->has_mips16_call_stub()
7493 || mips_sym
->has_mips16_call_fp_stub())
7495 mips_sym
->set_needs_mips_plt(true);
7496 mips_sym
->set_needs_comp_plt(false);
7499 // Otherwise, if there are no direct calls to the function, we
7500 // have a free choice of whether to use standard or compressed
7501 // entries. Prefer microMIPS entries if the object is known to
7502 // contain microMIPS code, so that it becomes possible to create
7503 // pure microMIPS binaries. Prefer standard entries otherwise,
7504 // because MIPS16 ones are no smaller and are usually slower.
7505 if (!mips_sym
->needs_mips_plt() && !mips_sym
->needs_comp_plt())
7507 if (this->target_
->is_output_micromips())
7508 mips_sym
->set_needs_comp_plt(true);
7510 mips_sym
->set_needs_mips_plt(true);
7513 if (mips_sym
->needs_mips_plt())
7515 mips_sym
->set_mips_plt_offset(this->plt_mips_offset_
);
7516 this->plt_mips_offset_
+= plt_mips_entry_size
;
7518 if (mips_sym
->needs_comp_plt())
7520 mips_sym
->set_comp_plt_offset(this->plt_comp_offset_
);
7521 this->plt_comp_offset_
+= plt_comp_entry_size
;
7525 // Figure out the size of the PLT header if we know that we are using it.
7526 if (this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0)
7527 this->plt_header_size_
= this->get_plt_header_size();
7530 // Write out the PLT. This uses the hand-coded instructions above,
7531 // and adjusts them as needed.
7533 template<int size
, bool big_endian
>
7535 Mips_output_data_plt
<size
, big_endian
>::do_write(Output_file
* of
)
7537 const off_t offset
= this->offset();
7538 const section_size_type oview_size
=
7539 convert_to_section_size_type(this->data_size());
7540 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
7542 const off_t gotplt_file_offset
= this->got_plt_
->offset();
7543 const section_size_type gotplt_size
=
7544 convert_to_section_size_type(this->got_plt_
->data_size());
7545 unsigned char* const gotplt_view
= of
->get_output_view(gotplt_file_offset
,
7547 unsigned char* pov
= oview
;
7549 Mips_address plt_address
= this->address();
7551 // Calculate the address of .got.plt.
7552 Mips_address gotplt_addr
= this->got_plt_
->address();
7553 Mips_address gotplt_addr_high
= ((gotplt_addr
+ 0x8000) >> 16) & 0xffff;
7554 Mips_address gotplt_addr_low
= gotplt_addr
& 0xffff;
7556 // The PLT sequence is not safe for N64 if .got.plt's address can
7557 // not be loaded in two instructions.
7558 gold_assert((gotplt_addr
& ~(Mips_address
) 0x7fffffff) == 0
7559 || ~(gotplt_addr
| 0x7fffffff) == 0);
7561 // Write the PLT header.
7562 const uint32_t* plt0_entry
= this->get_plt_header_entry();
7563 if (plt0_entry
== plt0_entry_micromips_o32
)
7565 // Write microMIPS PLT header.
7566 gold_assert(gotplt_addr
% 4 == 0);
7568 Mips_address gotpc_offset
= gotplt_addr
- ((plt_address
| 3) ^ 3);
7570 // ADDIUPC has a span of +/-16MB, check we're in range.
7571 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
7573 gold_error(_(".got.plt offset of %ld from .plt beyond the range of "
7574 "ADDIUPC"), (long)gotpc_offset
);
7578 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
7579 plt0_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
7580 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7581 (gotpc_offset
>> 2) & 0xffff);
7583 for (unsigned int i
= 2;
7584 i
< (sizeof(plt0_entry_micromips_o32
)
7585 / sizeof(plt0_entry_micromips_o32
[0]));
7588 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7592 else if (plt0_entry
== plt0_entry_micromips32_o32
)
7594 // Write microMIPS PLT header in insn32 mode.
7595 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[0]);
7596 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, gotplt_addr_high
);
7597 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, plt0_entry
[2]);
7598 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, gotplt_addr_low
);
7599 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8, plt0_entry
[4]);
7600 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, gotplt_addr_low
);
7602 for (unsigned int i
= 6;
7603 i
< (sizeof(plt0_entry_micromips32_o32
)
7604 / sizeof(plt0_entry_micromips32_o32
[0]));
7607 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7613 // Write standard PLT header.
7614 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7615 plt0_entry
[0] | gotplt_addr_high
);
7616 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7617 plt0_entry
[1] | gotplt_addr_low
);
7618 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
7619 plt0_entry
[2] | gotplt_addr_low
);
7621 for (int i
= 3; i
< 8; i
++)
7623 elfcpp::Swap
<32, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7629 unsigned char* gotplt_pov
= gotplt_view
;
7630 unsigned int got_entry_size
= size
/8; // TODO(sasa): MIPS_ELF_GOT_SIZE
7632 // The first two entries in .got.plt are reserved.
7633 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
, 0);
7634 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
+ got_entry_size
, 0);
7636 unsigned int gotplt_offset
= 2 * got_entry_size
;
7637 gotplt_pov
+= 2 * got_entry_size
;
7639 // Calculate the address of the PLT header.
7640 Mips_address header_address
= (plt_address
7641 + (this->is_plt_header_compressed() ? 1 : 0));
7643 // Initialize compressed PLT area view.
7644 unsigned char* pov2
= pov
+ this->plt_mips_offset_
;
7646 // Write the PLT entries.
7647 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
7648 p
= this->symbols_
.begin();
7649 p
!= this->symbols_
.end();
7650 ++p
, gotplt_pov
+= got_entry_size
, gotplt_offset
+= got_entry_size
)
7652 Mips_symbol
<size
>* mips_sym
= *p
;
7654 // Calculate the address of the .got.plt entry.
7655 uint32_t gotplt_entry_addr
= (gotplt_addr
+ gotplt_offset
);
7656 uint32_t gotplt_entry_addr_hi
= (((gotplt_entry_addr
+ 0x8000) >> 16)
7658 uint32_t gotplt_entry_addr_lo
= gotplt_entry_addr
& 0xffff;
7660 // Initially point the .got.plt entry at the PLT header.
7661 if (this->target_
->is_output_n64())
7662 elfcpp::Swap
<64, big_endian
>::writeval(gotplt_pov
, header_address
);
7664 elfcpp::Swap
<32, big_endian
>::writeval(gotplt_pov
, header_address
);
7666 // Now handle the PLT itself. First the standard entry.
7667 if (mips_sym
->has_mips_plt_offset())
7669 // Pick the load opcode (LW or LD).
7670 uint64_t load
= this->target_
->is_output_n64() ? 0xdc000000
7673 const uint32_t* entry
= this->target_
->is_output_r6() ? plt_entry_r6
7676 // Fill in the PLT entry itself.
7677 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7678 entry
[0] | gotplt_entry_addr_hi
);
7679 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7680 entry
[1] | gotplt_entry_addr_lo
| load
);
7681 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8, entry
[2]);
7682 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12,
7683 entry
[3] | gotplt_entry_addr_lo
);
7687 // Now the compressed entry. They come after any standard ones.
7688 if (mips_sym
->has_comp_plt_offset())
7690 if (!this->target_
->is_output_micromips())
7692 // Write MIPS16 PLT entry.
7693 const uint32_t* plt_entry
= plt_entry_mips16_o32
;
7695 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
7696 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2, plt_entry
[1]);
7697 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7698 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
7699 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7700 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7701 elfcpp::Swap
<32, big_endian
>::writeval(pov2
+ 12,
7705 else if (this->target_
->use_32bit_micromips_instructions())
7707 // Write microMIPS PLT entry in insn32 mode.
7708 const uint32_t* plt_entry
= plt_entry_micromips32_o32
;
7710 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
7711 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2,
7712 gotplt_entry_addr_hi
);
7713 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7714 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6,
7715 gotplt_entry_addr_lo
);
7716 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7717 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7718 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 12, plt_entry
[6]);
7719 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 14,
7720 gotplt_entry_addr_lo
);
7725 // Write microMIPS PLT entry.
7726 const uint32_t* plt_entry
= plt_entry_micromips_o32
;
7728 gold_assert(gotplt_entry_addr
% 4 == 0);
7730 Mips_address loc_address
= plt_address
+ pov2
- oview
;
7731 int gotpc_offset
= gotplt_entry_addr
- ((loc_address
| 3) ^ 3);
7733 // ADDIUPC has a span of +/-16MB, check we're in range.
7734 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
7736 gold_error(_(".got.plt offset of %ld from .plt beyond the "
7737 "range of ADDIUPC"), (long)gotpc_offset
);
7741 elfcpp::Swap
<16, big_endian
>::writeval(pov2
,
7742 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
7743 elfcpp::Swap
<16, big_endian
>::writeval(
7744 pov2
+ 2, (gotpc_offset
>> 2) & 0xffff);
7745 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7746 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
7747 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7748 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7754 // Check the number of bytes written for standard entries.
7755 gold_assert(static_cast<section_size_type
>(
7756 pov
- oview
- this->plt_header_size_
) == this->plt_mips_offset_
);
7757 // Check the number of bytes written for compressed entries.
7758 gold_assert((static_cast<section_size_type
>(pov2
- pov
)
7759 == this->plt_comp_offset_
));
7760 // Check the total number of bytes written.
7761 gold_assert(static_cast<section_size_type
>(pov2
- oview
) == oview_size
);
7763 gold_assert(static_cast<section_size_type
>(gotplt_pov
- gotplt_view
)
7766 of
->write_output_view(offset
, oview_size
, oview
);
7767 of
->write_output_view(gotplt_file_offset
, gotplt_size
, gotplt_view
);
7770 // Mips_output_data_mips_stubs methods.
7772 // The format of the lazy binding stub when dynamic symbol count is less than
7773 // 64K, dynamic symbol index is less than 32K, and ABI is not N64.
7774 template<int size
, bool big_endian
>
7776 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1
[4] =
7778 0x8f998010, // lw t9,0x8010(gp)
7779 0x03e07825, // or t7,ra,zero
7780 0x0320f809, // jalr t9,ra
7781 0x24180000 // addiu t8,zero,DYN_INDEX sign extended
7784 // The format of the lazy binding stub when dynamic symbol count is less than
7785 // 64K, dynamic symbol index is less than 32K, and ABI is N64.
7786 template<int size
, bool big_endian
>
7788 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1_n64
[4] =
7790 0xdf998010, // ld t9,0x8010(gp)
7791 0x03e07825, // or t7,ra,zero
7792 0x0320f809, // jalr t9,ra
7793 0x64180000 // daddiu t8,zero,DYN_INDEX sign extended
7796 // The format of the lazy binding stub when dynamic symbol count is less than
7797 // 64K, dynamic symbol index is between 32K and 64K, and ABI is not N64.
7798 template<int size
, bool big_endian
>
7800 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2
[4] =
7802 0x8f998010, // lw t9,0x8010(gp)
7803 0x03e07825, // or t7,ra,zero
7804 0x0320f809, // jalr t9,ra
7805 0x34180000 // ori t8,zero,DYN_INDEX unsigned
7808 // The format of the lazy binding stub when dynamic symbol count is less than
7809 // 64K, dynamic symbol index is between 32K and 64K, and ABI is N64.
7810 template<int size
, bool big_endian
>
7812 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2_n64
[4] =
7814 0xdf998010, // ld t9,0x8010(gp)
7815 0x03e07825, // or t7,ra,zero
7816 0x0320f809, // jalr t9,ra
7817 0x34180000 // ori t8,zero,DYN_INDEX unsigned
7820 // The format of the lazy binding stub when dynamic symbol count is greater than
7821 // 64K, and ABI is not N64.
7822 template<int size
, bool big_endian
>
7823 const uint32_t Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big
[5] =
7825 0x8f998010, // lw t9,0x8010(gp)
7826 0x03e07825, // or t7,ra,zero
7827 0x3c180000, // lui t8,DYN_INDEX
7828 0x0320f809, // jalr t9,ra
7829 0x37180000 // ori t8,t8,DYN_INDEX
7832 // The format of the lazy binding stub when dynamic symbol count is greater than
7833 // 64K, and ABI is N64.
7834 template<int size
, bool big_endian
>
7836 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big_n64
[5] =
7838 0xdf998010, // ld t9,0x8010(gp)
7839 0x03e07825, // or t7,ra,zero
7840 0x3c180000, // lui t8,DYN_INDEX
7841 0x0320f809, // jalr t9,ra
7842 0x37180000 // ori t8,t8,DYN_INDEX
7847 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7848 // less than 64K, dynamic symbol index is less than 32K, and ABI is not N64.
7849 template<int size
, bool big_endian
>
7851 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_1
[] =
7853 0xff3c, 0x8010, // lw t9,0x8010(gp)
7854 0x0dff, // move t7,ra
7856 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
7859 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7860 // less than 64K, dynamic symbol index is less than 32K, and ABI is N64.
7861 template<int size
, bool big_endian
>
7863 Mips_output_data_mips_stubs
<size
, big_endian
>::
7864 lazy_stub_micromips_normal_1_n64
[] =
7866 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7867 0x0dff, // move t7,ra
7869 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
7872 // The format of the microMIPS lazy binding stub when dynamic symbol
7873 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7874 // and ABI is not N64.
7875 template<int size
, bool big_endian
>
7877 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_2
[] =
7879 0xff3c, 0x8010, // lw t9,0x8010(gp)
7880 0x0dff, // move t7,ra
7882 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7885 // The format of the microMIPS lazy binding stub when dynamic symbol
7886 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7888 template<int size
, bool big_endian
>
7890 Mips_output_data_mips_stubs
<size
, big_endian
>::
7891 lazy_stub_micromips_normal_2_n64
[] =
7893 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7894 0x0dff, // move t7,ra
7896 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7899 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7900 // greater than 64K, and ABI is not N64.
7901 template<int size
, bool big_endian
>
7903 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big
[] =
7905 0xff3c, 0x8010, // lw t9,0x8010(gp)
7906 0x0dff, // move t7,ra
7907 0x41b8, 0x0000, // lui t8,DYN_INDEX
7909 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7912 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7913 // greater than 64K, and ABI is N64.
7914 template<int size
, bool big_endian
>
7916 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big_n64
[] =
7918 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7919 0x0dff, // move t7,ra
7920 0x41b8, 0x0000, // lui t8,DYN_INDEX
7922 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7925 // 32-bit microMIPS stubs.
7927 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7928 // less than 64K, dynamic symbol index is less than 32K, ABI is not N64, and we
7929 // can use only 32-bit instructions.
7930 template<int size
, bool big_endian
>
7932 Mips_output_data_mips_stubs
<size
, big_endian
>::
7933 lazy_stub_micromips32_normal_1
[] =
7935 0xff3c, 0x8010, // lw t9,0x8010(gp)
7936 0x001f, 0x7a90, // or t7,ra,zero
7937 0x03f9, 0x0f3c, // jalr ra,t9
7938 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
7941 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7942 // less than 64K, dynamic symbol index is less than 32K, ABI is N64, and we can
7943 // use only 32-bit instructions.
7944 template<int size
, bool big_endian
>
7946 Mips_output_data_mips_stubs
<size
, big_endian
>::
7947 lazy_stub_micromips32_normal_1_n64
[] =
7949 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7950 0x001f, 0x7a90, // or t7,ra,zero
7951 0x03f9, 0x0f3c, // jalr ra,t9
7952 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
7955 // The format of the microMIPS lazy binding stub when dynamic symbol
7956 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7957 // ABI is not N64, and we can use only 32-bit instructions.
7958 template<int size
, bool big_endian
>
7960 Mips_output_data_mips_stubs
<size
, big_endian
>::
7961 lazy_stub_micromips32_normal_2
[] =
7963 0xff3c, 0x8010, // lw t9,0x8010(gp)
7964 0x001f, 0x7a90, // or t7,ra,zero
7965 0x03f9, 0x0f3c, // jalr ra,t9
7966 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7969 // The format of the microMIPS lazy binding stub when dynamic symbol
7970 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7971 // ABI is N64, and we can use only 32-bit instructions.
7972 template<int size
, bool big_endian
>
7974 Mips_output_data_mips_stubs
<size
, big_endian
>::
7975 lazy_stub_micromips32_normal_2_n64
[] =
7977 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7978 0x001f, 0x7a90, // or t7,ra,zero
7979 0x03f9, 0x0f3c, // jalr ra,t9
7980 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7983 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7984 // greater than 64K, ABI is not N64, and we can use only 32-bit instructions.
7985 template<int size
, bool big_endian
>
7987 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big
[] =
7989 0xff3c, 0x8010, // lw t9,0x8010(gp)
7990 0x001f, 0x7a90, // or t7,ra,zero
7991 0x41b8, 0x0000, // lui t8,DYN_INDEX
7992 0x03f9, 0x0f3c, // jalr ra,t9
7993 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7996 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7997 // greater than 64K, ABI is N64, and we can use only 32-bit instructions.
7998 template<int size
, bool big_endian
>
8000 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big_n64
[] =
8002 0xdf3c, 0x8010, // ld t9,0x8010(gp)
8003 0x001f, 0x7a90, // or t7,ra,zero
8004 0x41b8, 0x0000, // lui t8,DYN_INDEX
8005 0x03f9, 0x0f3c, // jalr ra,t9
8006 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
8009 // Create entry for a symbol.
8011 template<int size
, bool big_endian
>
8013 Mips_output_data_mips_stubs
<size
, big_endian
>::make_entry(
8014 Mips_symbol
<size
>* gsym
)
8016 if (!gsym
->has_lazy_stub() && !gsym
->has_plt_offset())
8018 this->symbols_
.insert(gsym
);
8019 gsym
->set_has_lazy_stub(true);
8023 // Remove entry for a symbol.
8025 template<int size
, bool big_endian
>
8027 Mips_output_data_mips_stubs
<size
, big_endian
>::remove_entry(
8028 Mips_symbol
<size
>* gsym
)
8030 if (gsym
->has_lazy_stub())
8032 this->symbols_
.erase(gsym
);
8033 gsym
->set_has_lazy_stub(false);
8037 // Set stub offsets for symbols. This method expects that the number of
8038 // entries in dynamic symbol table is set.
8040 template<int size
, bool big_endian
>
8042 Mips_output_data_mips_stubs
<size
, big_endian
>::set_lazy_stub_offsets()
8044 gold_assert(this->dynsym_count_
!= -1U);
8046 if (this->stub_offsets_are_set_
)
8049 unsigned int stub_size
= this->stub_size();
8050 unsigned int offset
= 0;
8051 for (typename
Mips_stubs_entry_set::const_iterator
8052 p
= this->symbols_
.begin();
8053 p
!= this->symbols_
.end();
8054 ++p
, offset
+= stub_size
)
8056 Mips_symbol
<size
>* mips_sym
= *p
;
8057 mips_sym
->set_lazy_stub_offset(offset
);
8059 this->stub_offsets_are_set_
= true;
8062 template<int size
, bool big_endian
>
8064 Mips_output_data_mips_stubs
<size
, big_endian
>::set_needs_dynsym_value()
8066 for (typename
Mips_stubs_entry_set::const_iterator
8067 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
8069 Mips_symbol
<size
>* sym
= *p
;
8070 if (sym
->is_from_dynobj())
8071 sym
->set_needs_dynsym_value();
8075 // Write out the .MIPS.stubs. This uses the hand-coded instructions and
8076 // adjusts them as needed.
8078 template<int size
, bool big_endian
>
8080 Mips_output_data_mips_stubs
<size
, big_endian
>::do_write(Output_file
* of
)
8082 const off_t offset
= this->offset();
8083 const section_size_type oview_size
=
8084 convert_to_section_size_type(this->data_size());
8085 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
8087 bool big_stub
= this->dynsym_count_
> 0x10000;
8089 unsigned char* pov
= oview
;
8090 for (typename
Mips_stubs_entry_set::const_iterator
8091 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
8093 Mips_symbol
<size
>* sym
= *p
;
8094 const uint32_t* lazy_stub
;
8095 bool n64
= this->target_
->is_output_n64();
8097 if (!this->target_
->is_output_micromips())
8099 // Write standard (non-microMIPS) stub.
8102 if (sym
->dynsym_index() & ~0x7fff)
8103 // Dynsym index is between 32K and 64K.
8104 lazy_stub
= n64
? lazy_stub_normal_2_n64
: lazy_stub_normal_2
;
8106 // Dynsym index is less than 32K.
8107 lazy_stub
= n64
? lazy_stub_normal_1_n64
: lazy_stub_normal_1
;
8110 lazy_stub
= n64
? lazy_stub_big_n64
: lazy_stub_big
;
8113 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8114 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 1]);
8120 // LUI instruction of the big stub. Paste high 16 bits of the
8122 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
8123 lazy_stub
[i
] | ((sym
->dynsym_index() >> 16) & 0x7fff));
8127 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8128 // Last stub instruction. Paste low 16 bits of the dynsym index.
8129 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
8130 lazy_stub
[i
+ 1] | (sym
->dynsym_index() & 0xffff));
8133 else if (this->target_
->use_32bit_micromips_instructions())
8135 // Write microMIPS stub in insn32 mode.
8138 if (sym
->dynsym_index() & ~0x7fff)
8139 // Dynsym index is between 32K and 64K.
8140 lazy_stub
= n64
? lazy_stub_micromips32_normal_2_n64
8141 : lazy_stub_micromips32_normal_2
;
8143 // Dynsym index is less than 32K.
8144 lazy_stub
= n64
? lazy_stub_micromips32_normal_1_n64
8145 : lazy_stub_micromips32_normal_1
;
8148 lazy_stub
= n64
? lazy_stub_micromips32_big_n64
8149 : lazy_stub_micromips32_big
;
8152 // First stub instruction. We emit 32-bit microMIPS instructions by
8153 // emitting two 16-bit parts because on microMIPS the 16-bit part of
8154 // the instruction where the opcode is must always come first, for
8155 // both little and big endian.
8156 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8157 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
8158 // Second stub instruction.
8159 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
8160 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, lazy_stub
[i
+ 3]);
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 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
8175 // Last stub instruction. Paste low 16 bits of the dynsym index.
8176 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
8177 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
8178 sym
->dynsym_index() & 0xffff);
8183 // Write microMIPS stub.
8186 if (sym
->dynsym_index() & ~0x7fff)
8187 // Dynsym index is between 32K and 64K.
8188 lazy_stub
= n64
? lazy_stub_micromips_normal_2_n64
8189 : lazy_stub_micromips_normal_2
;
8191 // Dynsym index is less than 32K.
8192 lazy_stub
= n64
? lazy_stub_micromips_normal_1_n64
8193 : lazy_stub_micromips_normal_1
;
8196 lazy_stub
= n64
? lazy_stub_micromips_big_n64
8197 : lazy_stub_micromips_big
;
8200 // First stub instruction. We emit 32-bit microMIPS instructions by
8201 // emitting two 16-bit parts because on microMIPS the 16-bit part of
8202 // the instruction where the opcode is must always come first, for
8203 // both little and big endian.
8204 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8205 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
8206 // Second stub instruction.
8207 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
8212 // LUI instruction of the big stub. Paste high 16 bits of the
8214 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8215 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
8216 (sym
->dynsym_index() >> 16) & 0x7fff);
8220 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8221 // Last stub instruction. Paste low 16 bits of the dynsym index.
8222 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
8223 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
8224 sym
->dynsym_index() & 0xffff);
8229 // We always allocate 20 bytes for every stub, because final dynsym count is
8230 // not known in method do_finalize_sections. There are 4 unused bytes per
8231 // stub if final dynsym count is less than 0x10000.
8232 unsigned int used
= pov
- oview
;
8233 unsigned int unused
= big_stub
? 0 : this->symbols_
.size() * 4;
8234 gold_assert(static_cast<section_size_type
>(used
+ unused
) == oview_size
);
8236 // Fill the unused space with zeroes.
8237 // TODO(sasa): Can we strip unused bytes during the relaxation?
8239 memset(pov
, 0, unused
);
8241 of
->write_output_view(offset
, oview_size
, oview
);
8244 // Mips_output_section_reginfo methods.
8246 template<int size
, bool big_endian
>
8248 Mips_output_section_reginfo
<size
, big_endian
>::do_write(Output_file
* of
)
8250 off_t offset
= this->offset();
8251 off_t data_size
= this->data_size();
8253 unsigned char* view
= of
->get_output_view(offset
, data_size
);
8254 elfcpp::Swap
<size
, big_endian
>::writeval(view
, this->gprmask_
);
8255 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 4, this->cprmask1_
);
8256 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 8, this->cprmask2_
);
8257 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 12, this->cprmask3_
);
8258 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 16, this->cprmask4_
);
8259 // Write the gp value.
8260 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 20,
8261 this->target_
->gp_value());
8263 of
->write_output_view(offset
, data_size
, view
);
8266 // Mips_output_section_options methods.
8268 template<int size
, bool big_endian
>
8270 Mips_output_section_options
<size
, big_endian
>::do_write(Output_file
* of
)
8272 off_t offset
= this->offset();
8273 const section_size_type oview_size
=
8274 convert_to_section_size_type(this->data_size());
8275 unsigned char* view
= of
->get_output_view(offset
, oview_size
);
8276 const unsigned char* end
= view
+ oview_size
;
8278 while (view
+ 8 <= end
)
8280 unsigned char kind
= elfcpp::Swap
<8, big_endian
>::readval(view
);
8281 unsigned char sz
= elfcpp::Swap
<8, big_endian
>::readval(view
+ 1);
8284 gold_error(_("Warning: bad `%s' option size %u smaller "
8285 "than its header in output section"),
8290 // Only update ri_gp_value (GP register value) field of ODK_REGINFO entry.
8291 if (this->target_
->is_output_n64() && kind
== elfcpp::ODK_REGINFO
)
8292 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 32,
8293 this->target_
->gp_value());
8294 else if (kind
== elfcpp::ODK_REGINFO
)
8295 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 28,
8296 this->target_
->gp_value());
8301 of
->write_output_view(offset
, oview_size
, view
);
8304 // Mips_output_section_abiflags methods.
8306 template<int size
, bool big_endian
>
8308 Mips_output_section_abiflags
<size
, big_endian
>::do_write(Output_file
* of
)
8310 off_t offset
= this->offset();
8311 off_t data_size
= this->data_size();
8313 unsigned char* view
= of
->get_output_view(offset
, data_size
);
8314 elfcpp::Swap
<16, big_endian
>::writeval(view
, this->abiflags_
.version
);
8315 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 2, this->abiflags_
.isa_level
);
8316 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 3, this->abiflags_
.isa_rev
);
8317 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 4, this->abiflags_
.gpr_size
);
8318 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 5, this->abiflags_
.cpr1_size
);
8319 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 6, this->abiflags_
.cpr2_size
);
8320 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 7, this->abiflags_
.fp_abi
);
8321 elfcpp::Swap
<32, big_endian
>::writeval(view
+ 8, this->abiflags_
.isa_ext
);
8322 elfcpp::Swap
<32, big_endian
>::writeval(view
+ 12, this->abiflags_
.ases
);
8323 elfcpp::Swap
<32, big_endian
>::writeval(view
+ 16, this->abiflags_
.flags1
);
8324 elfcpp::Swap
<32, big_endian
>::writeval(view
+ 20, this->abiflags_
.flags2
);
8326 of
->write_output_view(offset
, data_size
, view
);
8329 // Mips_copy_relocs methods.
8331 // Emit any saved relocs.
8333 template<int sh_type
, int size
, bool big_endian
>
8335 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_mips(
8336 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
8337 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
8339 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
8340 Copy_reloc_entries::iterator p
= this->entries_
.begin();
8341 p
!= this->entries_
.end();
8343 emit_entry(*p
, reloc_section
, symtab
, layout
, target
);
8345 // We no longer need the saved information.
8346 this->entries_
.clear();
8349 // Emit the reloc if appropriate.
8351 template<int sh_type
, int size
, bool big_endian
>
8353 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_entry(
8354 Copy_reloc_entry
& entry
,
8355 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
8356 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
8358 // If the symbol is no longer defined in a dynamic object, then we
8359 // emitted a COPY relocation, and we do not want to emit this
8360 // dynamic relocation.
8361 if (!entry
.sym_
->is_from_dynobj())
8364 bool can_make_dynamic
= (entry
.reloc_type_
== elfcpp::R_MIPS_32
8365 || entry
.reloc_type_
== elfcpp::R_MIPS_REL32
8366 || entry
.reloc_type_
== elfcpp::R_MIPS_64
);
8368 Mips_symbol
<size
>* sym
= Mips_symbol
<size
>::as_mips_sym(entry
.sym_
);
8369 if (can_make_dynamic
&& !sym
->has_static_relocs())
8371 Mips_relobj
<size
, big_endian
>* object
=
8372 Mips_relobj
<size
, big_endian
>::as_mips_relobj(entry
.relobj_
);
8373 target
->got_section(symtab
, layout
)->record_global_got_symbol(
8374 sym
, object
, entry
.reloc_type_
, true, false);
8375 if (!symbol_references_local(sym
, sym
->should_add_dynsym_entry(symtab
)))
8376 target
->rel_dyn_section(layout
)->add_global(sym
, elfcpp::R_MIPS_REL32
,
8377 entry
.output_section_
, entry
.relobj_
, entry
.shndx_
, entry
.address_
);
8379 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
8380 sym
, elfcpp::R_MIPS_REL32
, entry
.output_section_
, entry
.relobj_
,
8381 entry
.shndx_
, entry
.address_
);
8384 this->make_copy_reloc(symtab
, layout
,
8385 static_cast<Sized_symbol
<size
>*>(entry
.sym_
),
8390 // Target_mips methods.
8392 // Return the value to use for a dynamic symbol which requires special
8393 // treatment. This is how we support equality comparisons of function
8394 // pointers across shared library boundaries, as described in the
8395 // processor specific ABI supplement.
8397 template<int size
, bool big_endian
>
8399 Target_mips
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
8402 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
8404 if (!mips_sym
->has_lazy_stub())
8406 if (mips_sym
->has_plt_offset())
8408 // We distinguish between PLT entries and lazy-binding stubs by
8409 // giving the former an st_other value of STO_MIPS_PLT. Set the
8410 // value to the stub address if there are any relocations in the
8411 // binary where pointer equality matters.
8412 if (mips_sym
->pointer_equality_needed())
8414 // Prefer a standard MIPS PLT entry.
8415 if (mips_sym
->has_mips_plt_offset())
8416 value
= this->plt_section()->mips_entry_address(mips_sym
);
8418 value
= this->plt_section()->comp_entry_address(mips_sym
) + 1;
8426 // First, set stub offsets for symbols. This method expects that the
8427 // number of entries in dynamic symbol table is set.
8428 this->mips_stubs_section()->set_lazy_stub_offsets();
8430 // The run-time linker uses the st_value field of the symbol
8431 // to reset the global offset table entry for this external
8432 // to its stub address when unlinking a shared object.
8433 value
= this->mips_stubs_section()->stub_address(mips_sym
);
8436 if (mips_sym
->has_mips16_fn_stub())
8438 // If we have a MIPS16 function with a stub, the dynamic symbol must
8439 // refer to the stub, since only the stub uses the standard calling
8441 value
= mips_sym
->template
8442 get_mips16_fn_stub
<big_endian
>()->output_address();
8448 // Get the dynamic reloc section, creating it if necessary. It's always
8449 // .rel.dyn, even for MIPS64.
8451 template<int size
, bool big_endian
>
8452 typename Target_mips
<size
, big_endian
>::Reloc_section
*
8453 Target_mips
<size
, big_endian
>::rel_dyn_section(Layout
* layout
)
8455 if (this->rel_dyn_
== NULL
)
8457 gold_assert(layout
!= NULL
);
8458 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
8459 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
8460 elfcpp::SHF_ALLOC
, this->rel_dyn_
,
8461 ORDER_DYNAMIC_RELOCS
, false);
8463 // First entry in .rel.dyn has to be null.
8464 // This is hack - we define dummy output data and set its address to 0,
8465 // and define absolute R_MIPS_NONE relocation with offset 0 against it.
8466 // This ensures that the entry is null.
8467 Output_data
* od
= new Output_data_zero_fill(0, 0);
8469 this->rel_dyn_
->add_absolute(elfcpp::R_MIPS_NONE
, od
, 0);
8471 return this->rel_dyn_
;
8474 // Get the GOT section, creating it if necessary.
8476 template<int size
, bool big_endian
>
8477 Mips_output_data_got
<size
, big_endian
>*
8478 Target_mips
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
8481 if (this->got_
== NULL
)
8483 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
8485 this->got_
= new Mips_output_data_got
<size
, big_endian
>(this, symtab
,
8487 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
8488 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
|
8489 elfcpp::SHF_MIPS_GPREL
),
8490 this->got_
, ORDER_DATA
, false);
8492 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
8493 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
8494 Symbol_table::PREDEFINED
,
8496 0, 0, elfcpp::STT_OBJECT
,
8498 elfcpp::STV_HIDDEN
, 0,
8505 // Calculate value of _gp symbol.
8507 template<int size
, bool big_endian
>
8509 Target_mips
<size
, big_endian
>::set_gp(Layout
* layout
, Symbol_table
* symtab
)
8511 gold_assert(this->gp_
== NULL
);
8513 Sized_symbol
<size
>* gp
=
8514 static_cast<Sized_symbol
<size
>*>(symtab
->lookup("_gp"));
8516 // Set _gp symbol if the linker script hasn't created it.
8517 if (gp
== NULL
|| gp
->source() != Symbol::IS_CONSTANT
)
8519 // If there is no .got section, gp should be based on .sdata.
8520 Output_data
* gp_section
= (this->got_
!= NULL
8521 ? this->got_
->output_section()
8522 : layout
->find_output_section(".sdata"));
8524 if (gp_section
!= NULL
)
8525 gp
= static_cast<Sized_symbol
<size
>*>(symtab
->define_in_output_data(
8526 "_gp", NULL
, Symbol_table::PREDEFINED
,
8527 gp_section
, MIPS_GP_OFFSET
, 0,
8530 elfcpp::STV_DEFAULT
,
8537 // Set the dynamic symbol indexes. INDEX is the index of the first
8538 // global dynamic symbol. Pointers to the symbols are stored into the
8539 // vector SYMS. The names are added to DYNPOOL. This returns an
8540 // updated dynamic symbol index.
8542 template<int size
, bool big_endian
>
8544 Target_mips
<size
, big_endian
>::do_set_dynsym_indexes(
8545 std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
8546 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
8547 Versions
* versions
, Symbol_table
* symtab
) const
8549 std::vector
<Symbol
*> non_got_symbols
;
8550 std::vector
<Symbol
*> got_symbols
;
8552 reorder_dyn_symbols
<size
, big_endian
>(dyn_symbols
, &non_got_symbols
,
8555 for (std::vector
<Symbol
*>::iterator p
= non_got_symbols
.begin();
8556 p
!= non_got_symbols
.end();
8561 // Note that SYM may already have a dynamic symbol index, since
8562 // some symbols appear more than once in the symbol table, with
8563 // and without a version.
8565 if (!sym
->has_dynsym_index())
8567 sym
->set_dynsym_index(index
);
8569 syms
->push_back(sym
);
8570 dynpool
->add(sym
->name(), false, NULL
);
8572 // Record any version information.
8573 if (sym
->version() != NULL
)
8574 versions
->record_version(symtab
, dynpool
, sym
);
8576 // If the symbol is defined in a dynamic object and is
8577 // referenced in a regular object, then mark the dynamic
8578 // object as needed. This is used to implement --as-needed.
8579 if (sym
->is_from_dynobj() && sym
->in_reg())
8580 sym
->object()->set_is_needed();
8584 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
8585 p
!= got_symbols
.end();
8589 if (!sym
->has_dynsym_index())
8591 // Record any version information.
8592 if (sym
->version() != NULL
)
8593 versions
->record_version(symtab
, dynpool
, sym
);
8597 index
= versions
->finalize(symtab
, index
, syms
);
8599 int got_sym_count
= 0;
8600 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
8601 p
!= got_symbols
.end();
8606 if (!sym
->has_dynsym_index())
8609 sym
->set_dynsym_index(index
);
8611 syms
->push_back(sym
);
8612 dynpool
->add(sym
->name(), false, NULL
);
8614 // If the symbol is defined in a dynamic object and is
8615 // referenced in a regular object, then mark the dynamic
8616 // object as needed. This is used to implement --as-needed.
8617 if (sym
->is_from_dynobj() && sym
->in_reg())
8618 sym
->object()->set_is_needed();
8622 // Set index of the first symbol that has .got entry.
8623 this->got_
->set_first_global_got_dynsym_index(
8624 got_sym_count
> 0 ? index
- got_sym_count
: -1U);
8626 if (this->mips_stubs_
!= NULL
)
8627 this->mips_stubs_
->set_dynsym_count(index
);
8632 // Create a PLT entry for a global symbol referenced by r_type relocation.
8634 template<int size
, bool big_endian
>
8636 Target_mips
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
8638 Mips_symbol
<size
>* gsym
,
8639 unsigned int r_type
)
8641 if (gsym
->has_lazy_stub() || gsym
->has_plt_offset())
8644 if (this->plt_
== NULL
)
8646 // Create the GOT section first.
8647 this->got_section(symtab
, layout
);
8649 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
8650 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
8651 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
8652 this->got_plt_
, ORDER_DATA
, false);
8654 // The first two entries are reserved.
8655 this->got_plt_
->set_current_data_size(2 * size
/8);
8657 this->plt_
= new Mips_output_data_plt
<size
, big_endian
>(layout
,
8660 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
8662 | elfcpp::SHF_EXECINSTR
),
8663 this->plt_
, ORDER_PLT
, false);
8665 // Make the sh_info field of .rel.plt point to .plt.
8666 Output_section
* rel_plt_os
= this->plt_
->rel_plt()->output_section();
8667 rel_plt_os
->set_info_section(this->plt_
->output_section());
8670 this->plt_
->add_entry(gsym
, r_type
);
8674 // Get the .MIPS.stubs section, creating it if necessary.
8676 template<int size
, bool big_endian
>
8677 Mips_output_data_mips_stubs
<size
, big_endian
>*
8678 Target_mips
<size
, big_endian
>::mips_stubs_section(Layout
* layout
)
8680 if (this->mips_stubs_
== NULL
)
8683 new Mips_output_data_mips_stubs
<size
, big_endian
>(this);
8684 layout
->add_output_section_data(".MIPS.stubs", elfcpp::SHT_PROGBITS
,
8686 | elfcpp::SHF_EXECINSTR
),
8687 this->mips_stubs_
, ORDER_PLT
, false);
8689 return this->mips_stubs_
;
8692 // Get the LA25 stub section, creating it if necessary.
8694 template<int size
, bool big_endian
>
8695 Mips_output_data_la25_stub
<size
, big_endian
>*
8696 Target_mips
<size
, big_endian
>::la25_stub_section(Layout
* layout
)
8698 if (this->la25_stub_
== NULL
)
8700 this->la25_stub_
= new Mips_output_data_la25_stub
<size
, big_endian
>();
8701 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
8703 | elfcpp::SHF_EXECINSTR
),
8704 this->la25_stub_
, ORDER_TEXT
, false);
8706 return this->la25_stub_
;
8709 // Process the relocations to determine unreferenced sections for
8710 // garbage collection.
8712 template<int size
, bool big_endian
>
8714 Target_mips
<size
, big_endian
>::gc_process_relocs(
8715 Symbol_table
* symtab
,
8717 Sized_relobj_file
<size
, big_endian
>* object
,
8718 unsigned int data_shndx
,
8719 unsigned int sh_type
,
8720 const unsigned char* prelocs
,
8722 Output_section
* output_section
,
8723 bool needs_special_offset_handling
,
8724 size_t local_symbol_count
,
8725 const unsigned char* plocal_symbols
)
8727 typedef Target_mips
<size
, big_endian
> Mips
;
8729 if (sh_type
== elfcpp::SHT_REL
)
8731 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8734 gold::gc_process_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8743 needs_special_offset_handling
,
8747 else if (sh_type
== elfcpp::SHT_RELA
)
8749 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8752 gold::gc_process_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8761 needs_special_offset_handling
,
8769 // Scan relocations for a section.
8771 template<int size
, bool big_endian
>
8773 Target_mips
<size
, big_endian
>::scan_relocs(
8774 Symbol_table
* symtab
,
8776 Sized_relobj_file
<size
, big_endian
>* object
,
8777 unsigned int data_shndx
,
8778 unsigned int sh_type
,
8779 const unsigned char* prelocs
,
8781 Output_section
* output_section
,
8782 bool needs_special_offset_handling
,
8783 size_t local_symbol_count
,
8784 const unsigned char* plocal_symbols
)
8786 typedef Target_mips
<size
, big_endian
> Mips
;
8788 if (sh_type
== elfcpp::SHT_REL
)
8790 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8793 gold::scan_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8802 needs_special_offset_handling
,
8806 else if (sh_type
== elfcpp::SHT_RELA
)
8808 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8811 gold::scan_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8820 needs_special_offset_handling
,
8826 template<int size
, bool big_endian
>
8828 Target_mips
<size
, big_endian
>::mips_32bit_flags(elfcpp::Elf_Word flags
)
8830 return ((flags
& elfcpp::EF_MIPS_32BITMODE
) != 0
8831 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_O32
8832 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_EABI32
8833 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_1
8834 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_2
8835 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32
8836 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32R2
8837 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32R6
);
8840 // Return the MACH for a MIPS e_flags value.
8841 template<int size
, bool big_endian
>
8843 Target_mips
<size
, big_endian
>::elf_mips_mach(elfcpp::Elf_Word flags
)
8845 switch (flags
& elfcpp::EF_MIPS_MACH
)
8847 case elfcpp::E_MIPS_MACH_3900
:
8848 return mach_mips3900
;
8850 case elfcpp::E_MIPS_MACH_4010
:
8851 return mach_mips4010
;
8853 case elfcpp::E_MIPS_MACH_4100
:
8854 return mach_mips4100
;
8856 case elfcpp::E_MIPS_MACH_4111
:
8857 return mach_mips4111
;
8859 case elfcpp::E_MIPS_MACH_4120
:
8860 return mach_mips4120
;
8862 case elfcpp::E_MIPS_MACH_4650
:
8863 return mach_mips4650
;
8865 case elfcpp::E_MIPS_MACH_5400
:
8866 return mach_mips5400
;
8868 case elfcpp::E_MIPS_MACH_5500
:
8869 return mach_mips5500
;
8871 case elfcpp::E_MIPS_MACH_5900
:
8872 return mach_mips5900
;
8874 case elfcpp::E_MIPS_MACH_9000
:
8875 return mach_mips9000
;
8877 case elfcpp::E_MIPS_MACH_SB1
:
8878 return mach_mips_sb1
;
8880 case elfcpp::E_MIPS_MACH_LS2E
:
8881 return mach_mips_loongson_2e
;
8883 case elfcpp::E_MIPS_MACH_LS2F
:
8884 return mach_mips_loongson_2f
;
8886 case elfcpp::E_MIPS_MACH_LS3A
:
8887 return mach_mips_loongson_3a
;
8889 case elfcpp::E_MIPS_MACH_OCTEON3
:
8890 return mach_mips_octeon3
;
8892 case elfcpp::E_MIPS_MACH_OCTEON2
:
8893 return mach_mips_octeon2
;
8895 case elfcpp::E_MIPS_MACH_OCTEON
:
8896 return mach_mips_octeon
;
8898 case elfcpp::E_MIPS_MACH_XLR
:
8899 return mach_mips_xlr
;
8902 switch (flags
& elfcpp::EF_MIPS_ARCH
)
8905 case elfcpp::E_MIPS_ARCH_1
:
8906 return mach_mips3000
;
8908 case elfcpp::E_MIPS_ARCH_2
:
8909 return mach_mips6000
;
8911 case elfcpp::E_MIPS_ARCH_3
:
8912 return mach_mips4000
;
8914 case elfcpp::E_MIPS_ARCH_4
:
8915 return mach_mips8000
;
8917 case elfcpp::E_MIPS_ARCH_5
:
8920 case elfcpp::E_MIPS_ARCH_32
:
8921 return mach_mipsisa32
;
8923 case elfcpp::E_MIPS_ARCH_64
:
8924 return mach_mipsisa64
;
8926 case elfcpp::E_MIPS_ARCH_32R2
:
8927 return mach_mipsisa32r2
;
8929 case elfcpp::E_MIPS_ARCH_32R6
:
8930 return mach_mipsisa32r6
;
8932 case elfcpp::E_MIPS_ARCH_64R2
:
8933 return mach_mipsisa64r2
;
8935 case elfcpp::E_MIPS_ARCH_64R6
:
8936 return mach_mipsisa64r6
;
8943 // Return the MACH for each .MIPS.abiflags ISA Extension.
8945 template<int size
, bool big_endian
>
8947 Target_mips
<size
, big_endian
>::mips_isa_ext_mach(unsigned int isa_ext
)
8951 case elfcpp::AFL_EXT_3900
:
8952 return mach_mips3900
;
8954 case elfcpp::AFL_EXT_4010
:
8955 return mach_mips4010
;
8957 case elfcpp::AFL_EXT_4100
:
8958 return mach_mips4100
;
8960 case elfcpp::AFL_EXT_4111
:
8961 return mach_mips4111
;
8963 case elfcpp::AFL_EXT_4120
:
8964 return mach_mips4120
;
8966 case elfcpp::AFL_EXT_4650
:
8967 return mach_mips4650
;
8969 case elfcpp::AFL_EXT_5400
:
8970 return mach_mips5400
;
8972 case elfcpp::AFL_EXT_5500
:
8973 return mach_mips5500
;
8975 case elfcpp::AFL_EXT_5900
:
8976 return mach_mips5900
;
8978 case elfcpp::AFL_EXT_10000
:
8979 return mach_mips10000
;
8981 case elfcpp::AFL_EXT_LOONGSON_2E
:
8982 return mach_mips_loongson_2e
;
8984 case elfcpp::AFL_EXT_LOONGSON_2F
:
8985 return mach_mips_loongson_2f
;
8987 case elfcpp::AFL_EXT_LOONGSON_3A
:
8988 return mach_mips_loongson_3a
;
8990 case elfcpp::AFL_EXT_SB1
:
8991 return mach_mips_sb1
;
8993 case elfcpp::AFL_EXT_OCTEON
:
8994 return mach_mips_octeon
;
8996 case elfcpp::AFL_EXT_OCTEONP
:
8997 return mach_mips_octeonp
;
8999 case elfcpp::AFL_EXT_OCTEON2
:
9000 return mach_mips_octeon2
;
9002 case elfcpp::AFL_EXT_XLR
:
9003 return mach_mips_xlr
;
9006 return mach_mips3000
;
9010 // Return the .MIPS.abiflags value representing each ISA Extension.
9012 template<int size
, bool big_endian
>
9014 Target_mips
<size
, big_endian
>::mips_isa_ext(unsigned int mips_mach
)
9019 return elfcpp::AFL_EXT_3900
;
9022 return elfcpp::AFL_EXT_4010
;
9025 return elfcpp::AFL_EXT_4100
;
9028 return elfcpp::AFL_EXT_4111
;
9031 return elfcpp::AFL_EXT_4120
;
9034 return elfcpp::AFL_EXT_4650
;
9037 return elfcpp::AFL_EXT_5400
;
9040 return elfcpp::AFL_EXT_5500
;
9043 return elfcpp::AFL_EXT_5900
;
9045 case mach_mips10000
:
9046 return elfcpp::AFL_EXT_10000
;
9048 case mach_mips_loongson_2e
:
9049 return elfcpp::AFL_EXT_LOONGSON_2E
;
9051 case mach_mips_loongson_2f
:
9052 return elfcpp::AFL_EXT_LOONGSON_2F
;
9054 case mach_mips_loongson_3a
:
9055 return elfcpp::AFL_EXT_LOONGSON_3A
;
9058 return elfcpp::AFL_EXT_SB1
;
9060 case mach_mips_octeon
:
9061 return elfcpp::AFL_EXT_OCTEON
;
9063 case mach_mips_octeonp
:
9064 return elfcpp::AFL_EXT_OCTEONP
;
9066 case mach_mips_octeon3
:
9067 return elfcpp::AFL_EXT_OCTEON3
;
9069 case mach_mips_octeon2
:
9070 return elfcpp::AFL_EXT_OCTEON2
;
9073 return elfcpp::AFL_EXT_XLR
;
9080 // Update the isa_level, isa_rev, isa_ext fields of abiflags.
9082 template<int size
, bool big_endian
>
9084 Target_mips
<size
, big_endian
>::update_abiflags_isa(const std::string
& name
,
9085 elfcpp::Elf_Word e_flags
, Mips_abiflags
<big_endian
>* abiflags
)
9088 switch (e_flags
& elfcpp::EF_MIPS_ARCH
)
9090 case elfcpp::E_MIPS_ARCH_1
:
9091 new_isa
= this->level_rev(1, 0);
9093 case elfcpp::E_MIPS_ARCH_2
:
9094 new_isa
= this->level_rev(2, 0);
9096 case elfcpp::E_MIPS_ARCH_3
:
9097 new_isa
= this->level_rev(3, 0);
9099 case elfcpp::E_MIPS_ARCH_4
:
9100 new_isa
= this->level_rev(4, 0);
9102 case elfcpp::E_MIPS_ARCH_5
:
9103 new_isa
= this->level_rev(5, 0);
9105 case elfcpp::E_MIPS_ARCH_32
:
9106 new_isa
= this->level_rev(32, 1);
9108 case elfcpp::E_MIPS_ARCH_32R2
:
9109 new_isa
= this->level_rev(32, 2);
9111 case elfcpp::E_MIPS_ARCH_32R6
:
9112 new_isa
= this->level_rev(32, 6);
9114 case elfcpp::E_MIPS_ARCH_64
:
9115 new_isa
= this->level_rev(64, 1);
9117 case elfcpp::E_MIPS_ARCH_64R2
:
9118 new_isa
= this->level_rev(64, 2);
9120 case elfcpp::E_MIPS_ARCH_64R6
:
9121 new_isa
= this->level_rev(64, 6);
9124 gold_error(_("%s: Unknown architecture %s"), name
.c_str(),
9125 this->elf_mips_mach_name(e_flags
));
9128 if (new_isa
> this->level_rev(abiflags
->isa_level
, abiflags
->isa_rev
))
9130 // Decode a single value into level and revision.
9131 abiflags
->isa_level
= new_isa
>> 3;
9132 abiflags
->isa_rev
= new_isa
& 0x7;
9135 // Update the isa_ext if needed.
9136 if (this->mips_mach_extends(this->mips_isa_ext_mach(abiflags
->isa_ext
),
9137 this->elf_mips_mach(e_flags
)))
9138 abiflags
->isa_ext
= this->mips_isa_ext(this->elf_mips_mach(e_flags
));
9141 // Infer the content of the ABI flags based on the elf header.
9143 template<int size
, bool big_endian
>
9145 Target_mips
<size
, big_endian
>::infer_abiflags(
9146 Mips_relobj
<size
, big_endian
>* relobj
, Mips_abiflags
<big_endian
>* abiflags
)
9148 const Attributes_section_data
* pasd
= relobj
->attributes_section_data();
9149 int attr_fp_abi
= elfcpp::Val_GNU_MIPS_ABI_FP_ANY
;
9150 elfcpp::Elf_Word e_flags
= relobj
->processor_specific_flags();
9152 this->update_abiflags_isa(relobj
->name(), e_flags
, abiflags
);
9155 // Read fp_abi from the .gnu.attribute section.
9156 const Object_attribute
* attr
=
9157 pasd
->known_attributes(Object_attribute::OBJ_ATTR_GNU
);
9158 attr_fp_abi
= attr
[elfcpp::Tag_GNU_MIPS_ABI_FP
].int_value();
9161 abiflags
->fp_abi
= attr_fp_abi
;
9162 abiflags
->cpr1_size
= elfcpp::AFL_REG_NONE
;
9163 abiflags
->cpr2_size
= elfcpp::AFL_REG_NONE
;
9164 abiflags
->gpr_size
= this->mips_32bit_flags(e_flags
) ? elfcpp::AFL_REG_32
9165 : elfcpp::AFL_REG_64
;
9167 if (abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_SINGLE
9168 || abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_XX
9169 || (abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
9170 && abiflags
->gpr_size
== elfcpp::AFL_REG_32
))
9171 abiflags
->cpr1_size
= elfcpp::AFL_REG_32
;
9172 else if (abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
9173 || abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_64
9174 || abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
)
9175 abiflags
->cpr1_size
= elfcpp::AFL_REG_64
;
9177 if (e_flags
& elfcpp::EF_MIPS_ARCH_ASE_MDMX
)
9178 abiflags
->ases
|= elfcpp::AFL_ASE_MDMX
;
9179 if (e_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
)
9180 abiflags
->ases
|= elfcpp::AFL_ASE_MIPS16
;
9181 if (e_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
)
9182 abiflags
->ases
|= elfcpp::AFL_ASE_MICROMIPS
;
9184 if (abiflags
->fp_abi
!= elfcpp::Val_GNU_MIPS_ABI_FP_ANY
9185 && abiflags
->fp_abi
!= elfcpp::Val_GNU_MIPS_ABI_FP_SOFT
9186 && abiflags
->fp_abi
!= elfcpp::Val_GNU_MIPS_ABI_FP_64A
9187 && abiflags
->isa_level
>= 32
9188 && abiflags
->isa_ext
!= elfcpp::AFL_EXT_LOONGSON_3A
)
9189 abiflags
->flags1
|= elfcpp::AFL_FLAGS1_ODDSPREG
;
9192 // Create abiflags from elf header or from .MIPS.abiflags section.
9194 template<int size
, bool big_endian
>
9196 Target_mips
<size
, big_endian
>::create_abiflags(
9197 Mips_relobj
<size
, big_endian
>* relobj
,
9198 Mips_abiflags
<big_endian
>* abiflags
)
9200 Mips_abiflags
<big_endian
>* sec_abiflags
= relobj
->abiflags();
9201 Mips_abiflags
<big_endian
> header_abiflags
;
9203 this->infer_abiflags(relobj
, &header_abiflags
);
9205 if (sec_abiflags
== NULL
)
9207 // If there is no input .MIPS.abiflags section, use abiflags created
9209 *abiflags
= header_abiflags
;
9213 this->has_abiflags_section_
= true;
9215 // It is not possible to infer the correct ISA revision for R3 or R5
9216 // so drop down to R2 for the checks.
9217 unsigned char isa_rev
= sec_abiflags
->isa_rev
;
9218 if (isa_rev
== 3 || isa_rev
== 5)
9221 // Check compatibility between abiflags created from elf header
9222 // and abiflags from .MIPS.abiflags section in this object file.
9223 if (this->level_rev(sec_abiflags
->isa_level
, isa_rev
)
9224 < this->level_rev(header_abiflags
.isa_level
, header_abiflags
.isa_rev
))
9225 gold_warning(_("%s: Inconsistent ISA between e_flags and .MIPS.abiflags"),
9226 relobj
->name().c_str());
9227 if (header_abiflags
.fp_abi
!= elfcpp::Val_GNU_MIPS_ABI_FP_ANY
9228 && sec_abiflags
->fp_abi
!= header_abiflags
.fp_abi
)
9229 gold_warning(_("%s: Inconsistent FP ABI between .gnu.attributes and "
9230 ".MIPS.abiflags"), relobj
->name().c_str());
9231 if ((sec_abiflags
->ases
& header_abiflags
.ases
) != header_abiflags
.ases
)
9232 gold_warning(_("%s: Inconsistent ASEs between e_flags and .MIPS.abiflags"),
9233 relobj
->name().c_str());
9234 // The isa_ext is allowed to be an extension of what can be inferred
9236 if (!this->mips_mach_extends(this->mips_isa_ext_mach(header_abiflags
.isa_ext
),
9237 this->mips_isa_ext_mach(sec_abiflags
->isa_ext
)))
9238 gold_warning(_("%s: Inconsistent ISA extensions between e_flags and "
9239 ".MIPS.abiflags"), relobj
->name().c_str());
9240 if (sec_abiflags
->flags2
!= 0)
9241 gold_warning(_("%s: Unexpected flag in the flags2 field of "
9242 ".MIPS.abiflags (0x%x)"), relobj
->name().c_str(),
9243 sec_abiflags
->flags2
);
9244 // Use abiflags from .MIPS.abiflags section.
9245 *abiflags
= *sec_abiflags
;
9248 // Return the meaning of fp_abi, or "unknown" if not known.
9250 template<int size
, bool big_endian
>
9252 Target_mips
<size
, big_endian
>::fp_abi_string(int fp
)
9256 case elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
:
9257 return "-mdouble-float";
9258 case elfcpp::Val_GNU_MIPS_ABI_FP_SINGLE
:
9259 return "-msingle-float";
9260 case elfcpp::Val_GNU_MIPS_ABI_FP_SOFT
:
9261 return "-msoft-float";
9262 case elfcpp::Val_GNU_MIPS_ABI_FP_OLD_64
:
9263 return _("-mips32r2 -mfp64 (12 callee-saved)");
9264 case elfcpp::Val_GNU_MIPS_ABI_FP_XX
:
9266 case elfcpp::Val_GNU_MIPS_ABI_FP_64
:
9267 return "-mgp32 -mfp64";
9268 case elfcpp::Val_GNU_MIPS_ABI_FP_64A
:
9269 return "-mgp32 -mfp64 -mno-odd-spreg";
9277 template<int size
, bool big_endian
>
9279 Target_mips
<size
, big_endian
>::select_fp_abi(const std::string
& name
, int in_fp
,
9282 if (in_fp
== out_fp
)
9285 if (out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_ANY
)
9287 else if (out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_XX
9288 && (in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
9289 || in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64
9290 || in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
))
9292 else if (in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_XX
9293 && (out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
9294 || out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64
9295 || out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
))
9296 return out_fp
; // Keep the current setting.
9297 else if (out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
9298 && in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64
)
9300 else if (in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
9301 && out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64
)
9302 return out_fp
; // Keep the current setting.
9303 else if (in_fp
!= elfcpp::Val_GNU_MIPS_ABI_FP_ANY
)
9304 gold_warning(_("%s: FP ABI %s is incompatible with %s"), name
.c_str(),
9305 fp_abi_string(in_fp
), fp_abi_string(out_fp
));
9309 // Merge attributes from input object.
9311 template<int size
, bool big_endian
>
9313 Target_mips
<size
, big_endian
>::merge_obj_attributes(const std::string
& name
,
9314 const Attributes_section_data
* pasd
)
9316 // Return if there is no attributes section data.
9320 // If output has no object attributes, just copy.
9321 if (this->attributes_section_data_
== NULL
)
9323 this->attributes_section_data_
= new Attributes_section_data(*pasd
);
9327 Object_attribute
* out_attr
= this->attributes_section_data_
->known_attributes(
9328 Object_attribute::OBJ_ATTR_GNU
);
9330 out_attr
[elfcpp::Tag_GNU_MIPS_ABI_FP
].set_type(1);
9331 out_attr
[elfcpp::Tag_GNU_MIPS_ABI_FP
].set_int_value(this->abiflags_
->fp_abi
);
9333 // Merge Tag_compatibility attributes and any common GNU ones.
9334 this->attributes_section_data_
->merge(name
.c_str(), pasd
);
9337 // Merge abiflags from input object.
9339 template<int size
, bool big_endian
>
9341 Target_mips
<size
, big_endian
>::merge_obj_abiflags(const std::string
& name
,
9342 Mips_abiflags
<big_endian
>* in_abiflags
)
9344 // If output has no abiflags, just copy.
9345 if (this->abiflags_
== NULL
)
9347 this->abiflags_
= new Mips_abiflags
<big_endian
>(*in_abiflags
);
9351 this->abiflags_
->fp_abi
= this->select_fp_abi(name
, in_abiflags
->fp_abi
,
9352 this->abiflags_
->fp_abi
);
9355 this->abiflags_
->isa_level
= std::max(this->abiflags_
->isa_level
,
9356 in_abiflags
->isa_level
);
9357 this->abiflags_
->isa_rev
= std::max(this->abiflags_
->isa_rev
,
9358 in_abiflags
->isa_rev
);
9359 this->abiflags_
->gpr_size
= std::max(this->abiflags_
->gpr_size
,
9360 in_abiflags
->gpr_size
);
9361 this->abiflags_
->cpr1_size
= std::max(this->abiflags_
->cpr1_size
,
9362 in_abiflags
->cpr1_size
);
9363 this->abiflags_
->cpr2_size
= std::max(this->abiflags_
->cpr2_size
,
9364 in_abiflags
->cpr2_size
);
9365 this->abiflags_
->ases
|= in_abiflags
->ases
;
9366 this->abiflags_
->flags1
|= in_abiflags
->flags1
;
9369 // Check whether machine EXTENSION is an extension of machine BASE.
9370 template<int size
, bool big_endian
>
9372 Target_mips
<size
, big_endian
>::mips_mach_extends(unsigned int base
,
9373 unsigned int extension
)
9375 if (extension
== base
)
9378 if ((base
== mach_mipsisa32
)
9379 && this->mips_mach_extends(mach_mipsisa64
, extension
))
9382 if ((base
== mach_mipsisa32r2
)
9383 && this->mips_mach_extends(mach_mipsisa64r2
, extension
))
9386 for (unsigned int i
= 0; i
< this->mips_mach_extensions_
.size(); ++i
)
9387 if (extension
== this->mips_mach_extensions_
[i
].first
)
9389 extension
= this->mips_mach_extensions_
[i
].second
;
9390 if (extension
== base
)
9397 // Merge file header flags from input object.
9399 template<int size
, bool big_endian
>
9401 Target_mips
<size
, big_endian
>::merge_obj_e_flags(const std::string
& name
,
9402 elfcpp::Elf_Word in_flags
)
9404 // If flags are not set yet, just copy them.
9405 if (!this->are_processor_specific_flags_set())
9407 this->set_processor_specific_flags(in_flags
);
9408 this->mach_
= this->elf_mips_mach(in_flags
);
9412 elfcpp::Elf_Word new_flags
= in_flags
;
9413 elfcpp::Elf_Word old_flags
= this->processor_specific_flags();
9414 elfcpp::Elf_Word merged_flags
= this->processor_specific_flags();
9415 merged_flags
|= new_flags
& elfcpp::EF_MIPS_NOREORDER
;
9417 // Check flag compatibility.
9418 new_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
9419 old_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
9421 // Some IRIX 6 BSD-compatibility objects have this bit set. It
9422 // doesn't seem to matter.
9423 new_flags
&= ~elfcpp::EF_MIPS_XGOT
;
9424 old_flags
&= ~elfcpp::EF_MIPS_XGOT
;
9426 // MIPSpro generates ucode info in n64 objects. Again, we should
9427 // just be able to ignore this.
9428 new_flags
&= ~elfcpp::EF_MIPS_UCODE
;
9429 old_flags
&= ~elfcpp::EF_MIPS_UCODE
;
9431 if (new_flags
== old_flags
)
9433 this->set_processor_specific_flags(merged_flags
);
9437 if (((new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0)
9438 != ((old_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0))
9439 gold_warning(_("%s: linking abicalls files with non-abicalls files"),
9442 if (new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
))
9443 merged_flags
|= elfcpp::EF_MIPS_CPIC
;
9444 if (!(new_flags
& elfcpp::EF_MIPS_PIC
))
9445 merged_flags
&= ~elfcpp::EF_MIPS_PIC
;
9447 new_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
9448 old_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
9450 // Compare the ISAs.
9451 if (mips_32bit_flags(old_flags
) != mips_32bit_flags(new_flags
))
9452 gold_error(_("%s: linking 32-bit code with 64-bit code"), name
.c_str());
9453 else if (!this->mips_mach_extends(this->elf_mips_mach(in_flags
), this->mach_
))
9455 // Output ISA isn't the same as, or an extension of, input ISA.
9456 if (this->mips_mach_extends(this->mach_
, this->elf_mips_mach(in_flags
)))
9458 // Copy the architecture info from input object to output. Also copy
9459 // the 32-bit flag (if set) so that we continue to recognise
9460 // output as a 32-bit binary.
9461 this->mach_
= this->elf_mips_mach(in_flags
);
9462 merged_flags
&= ~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
);
9463 merged_flags
|= (new_flags
& (elfcpp::EF_MIPS_ARCH
9464 | elfcpp::EF_MIPS_MACH
| elfcpp::EF_MIPS_32BITMODE
));
9466 // Update the ABI flags isa_level, isa_rev, isa_ext fields.
9467 this->update_abiflags_isa(name
, merged_flags
, this->abiflags_
);
9469 // Copy across the ABI flags if output doesn't use them
9470 // and if that was what caused us to treat input object as 32-bit.
9471 if ((old_flags
& elfcpp::EF_MIPS_ABI
) == 0
9472 && this->mips_32bit_flags(new_flags
)
9473 && !this->mips_32bit_flags(new_flags
& ~elfcpp::EF_MIPS_ABI
))
9474 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ABI
;
9477 // The ISAs aren't compatible.
9478 gold_error(_("%s: linking %s module with previous %s modules"),
9479 name
.c_str(), this->elf_mips_mach_name(in_flags
),
9480 this->elf_mips_mach_name(merged_flags
));
9483 new_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
9484 | elfcpp::EF_MIPS_32BITMODE
));
9485 old_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
9486 | elfcpp::EF_MIPS_32BITMODE
));
9489 if ((new_flags
& elfcpp::EF_MIPS_ABI
) != (old_flags
& elfcpp::EF_MIPS_ABI
))
9491 // Only error if both are set (to different values).
9492 if ((new_flags
& elfcpp::EF_MIPS_ABI
)
9493 && (old_flags
& elfcpp::EF_MIPS_ABI
))
9494 gold_error(_("%s: ABI mismatch: linking %s module with "
9495 "previous %s modules"), name
.c_str(),
9496 this->elf_mips_abi_name(in_flags
),
9497 this->elf_mips_abi_name(merged_flags
));
9499 new_flags
&= ~elfcpp::EF_MIPS_ABI
;
9500 old_flags
&= ~elfcpp::EF_MIPS_ABI
;
9503 // Compare ASEs. Forbid linking MIPS16 and microMIPS ASE modules together
9504 // and allow arbitrary mixing of the remaining ASEs (retain the union).
9505 if ((new_flags
& elfcpp::EF_MIPS_ARCH_ASE
)
9506 != (old_flags
& elfcpp::EF_MIPS_ARCH_ASE
))
9508 int old_micro
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
9509 int new_micro
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
9510 int old_m16
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
9511 int new_m16
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
9512 int micro_mis
= old_m16
&& new_micro
;
9513 int m16_mis
= old_micro
&& new_m16
;
9515 if (m16_mis
|| micro_mis
)
9516 gold_error(_("%s: ASE mismatch: linking %s module with "
9517 "previous %s modules"), name
.c_str(),
9518 m16_mis
? "MIPS16" : "microMIPS",
9519 m16_mis
? "microMIPS" : "MIPS16");
9521 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ARCH_ASE
;
9523 new_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
9524 old_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
9527 // Compare NaN encodings.
9528 if ((new_flags
& elfcpp::EF_MIPS_NAN2008
) != (old_flags
& elfcpp::EF_MIPS_NAN2008
))
9530 gold_error(_("%s: linking %s module with previous %s modules"),
9532 (new_flags
& elfcpp::EF_MIPS_NAN2008
9533 ? "-mnan=2008" : "-mnan=legacy"),
9534 (old_flags
& elfcpp::EF_MIPS_NAN2008
9535 ? "-mnan=2008" : "-mnan=legacy"));
9537 new_flags
&= ~elfcpp::EF_MIPS_NAN2008
;
9538 old_flags
&= ~elfcpp::EF_MIPS_NAN2008
;
9541 // Compare FP64 state.
9542 if ((new_flags
& elfcpp::EF_MIPS_FP64
) != (old_flags
& elfcpp::EF_MIPS_FP64
))
9544 gold_error(_("%s: linking %s module with previous %s modules"),
9546 (new_flags
& elfcpp::EF_MIPS_FP64
9547 ? "-mfp64" : "-mfp32"),
9548 (old_flags
& elfcpp::EF_MIPS_FP64
9549 ? "-mfp64" : "-mfp32"));
9551 new_flags
&= ~elfcpp::EF_MIPS_FP64
;
9552 old_flags
&= ~elfcpp::EF_MIPS_FP64
;
9555 // Warn about any other mismatches.
9556 if (new_flags
!= old_flags
)
9557 gold_error(_("%s: uses different e_flags (0x%x) fields than previous "
9558 "modules (0x%x)"), name
.c_str(), new_flags
, old_flags
);
9560 this->set_processor_specific_flags(merged_flags
);
9563 // Adjust ELF file header.
9565 template<int size
, bool big_endian
>
9567 Target_mips
<size
, big_endian
>::do_adjust_elf_header(
9568 unsigned char* view
,
9571 gold_assert(len
== elfcpp::Elf_sizes
<size
>::ehdr_size
);
9573 elfcpp::Ehdr
<size
, big_endian
> ehdr(view
);
9574 unsigned char e_ident
[elfcpp::EI_NIDENT
];
9575 elfcpp::Elf_Word flags
= this->processor_specific_flags();
9576 memcpy(e_ident
, ehdr
.get_e_ident(), elfcpp::EI_NIDENT
);
9578 unsigned char ei_abiversion
= 0;
9579 elfcpp::Elf_Half type
= ehdr
.get_e_type();
9580 if (type
== elfcpp::ET_EXEC
9581 && parameters
->options().copyreloc()
9582 && (flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
))
9583 == elfcpp::EF_MIPS_CPIC
)
9586 if (this->abiflags_
!= NULL
9587 && (this->abiflags_
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_64
9588 || this->abiflags_
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
))
9591 e_ident
[elfcpp::EI_ABIVERSION
] = ei_abiversion
;
9592 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
9593 oehdr
.put_e_ident(e_ident
);
9595 if (this->entry_symbol_is_compressed_
)
9596 oehdr
.put_e_entry(ehdr
.get_e_entry() + 1);
9599 // do_make_elf_object to override the same function in the base class.
9600 // We need to use a target-specific sub-class of
9601 // Sized_relobj_file<size, big_endian> to store Mips specific information.
9602 // Hence we need to have our own ELF object creation.
9604 template<int size
, bool big_endian
>
9606 Target_mips
<size
, big_endian
>::do_make_elf_object(
9607 const std::string
& name
,
9608 Input_file
* input_file
,
9609 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
9611 int et
= ehdr
.get_e_type();
9612 // ET_EXEC files are valid input for --just-symbols/-R,
9613 // and we treat them as relocatable objects.
9614 if (et
== elfcpp::ET_REL
9615 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
9617 Mips_relobj
<size
, big_endian
>* obj
=
9618 new Mips_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
9622 else if (et
== elfcpp::ET_DYN
)
9624 // TODO(sasa): Should we create Mips_dynobj?
9625 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
9629 gold_error(_("%s: unsupported ELF file type %d"),
9635 // Finalize the sections.
9637 template <int size
, bool big_endian
>
9639 Target_mips
<size
, big_endian
>::do_finalize_sections(Layout
* layout
,
9640 const Input_objects
* input_objects
,
9641 Symbol_table
* symtab
)
9643 const bool relocatable
= parameters
->options().relocatable();
9645 // Add +1 to MIPS16 and microMIPS init_ and _fini symbols so that DT_INIT and
9646 // DT_FINI have correct values.
9647 Mips_symbol
<size
>* init
= static_cast<Mips_symbol
<size
>*>(
9648 symtab
->lookup(parameters
->options().init()));
9649 if (init
!= NULL
&& (init
->is_mips16() || init
->is_micromips()))
9650 init
->set_value(init
->value() | 1);
9651 Mips_symbol
<size
>* fini
= static_cast<Mips_symbol
<size
>*>(
9652 symtab
->lookup(parameters
->options().fini()));
9653 if (fini
!= NULL
&& (fini
->is_mips16() || fini
->is_micromips()))
9654 fini
->set_value(fini
->value() | 1);
9656 // Check whether the entry symbol is mips16 or micromips. This is needed to
9657 // adjust entry address in ELF header.
9658 Mips_symbol
<size
>* entry
=
9659 static_cast<Mips_symbol
<size
>*>(symtab
->lookup(this->entry_symbol_name()));
9660 this->entry_symbol_is_compressed_
= (entry
!= NULL
&& (entry
->is_mips16()
9661 || entry
->is_micromips()));
9663 if (!parameters
->doing_static_link()
9664 && (strcmp(parameters
->options().hash_style(), "gnu") == 0
9665 || strcmp(parameters
->options().hash_style(), "both") == 0))
9667 // .gnu.hash and the MIPS ABI require .dynsym to be sorted in different
9668 // ways. .gnu.hash needs symbols to be grouped by hash code whereas the
9669 // MIPS ABI requires a mapping between the GOT and the symbol table.
9670 gold_error(".gnu.hash is incompatible with the MIPS ABI");
9673 // Check whether the final section that was scanned has HI16 or GOT16
9674 // relocations without the corresponding LO16 part.
9675 if (this->got16_addends_
.size() > 0)
9676 gold_error("Can't find matching LO16 reloc");
9678 Valtype gprmask
= 0;
9679 Valtype cprmask1
= 0;
9680 Valtype cprmask2
= 0;
9681 Valtype cprmask3
= 0;
9682 Valtype cprmask4
= 0;
9683 bool has_reginfo_section
= false;
9685 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9686 p
!= input_objects
->relobj_end();
9689 Mips_relobj
<size
, big_endian
>* relobj
=
9690 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
9692 // Check for any mips16 stub sections that we can discard.
9694 relobj
->discard_mips16_stub_sections(symtab
);
9696 if (!relobj
->merge_processor_specific_data())
9699 // Merge .reginfo contents of input objects.
9700 if (relobj
->has_reginfo_section())
9702 has_reginfo_section
= true;
9703 gprmask
|= relobj
->gprmask();
9704 cprmask1
|= relobj
->cprmask1();
9705 cprmask2
|= relobj
->cprmask2();
9706 cprmask3
|= relobj
->cprmask3();
9707 cprmask4
|= relobj
->cprmask4();
9710 // Merge processor specific flags.
9711 Mips_abiflags
<big_endian
> in_abiflags
;
9713 this->create_abiflags(relobj
, &in_abiflags
);
9714 this->merge_obj_e_flags(relobj
->name(),
9715 relobj
->processor_specific_flags());
9716 this->merge_obj_abiflags(relobj
->name(), &in_abiflags
);
9717 this->merge_obj_attributes(relobj
->name(),
9718 relobj
->attributes_section_data());
9721 // Create a .gnu.attributes section if we have merged any attributes
9723 if (this->attributes_section_data_
!= NULL
)
9725 Output_attributes_section_data
* attributes_section
=
9726 new Output_attributes_section_data(*this->attributes_section_data_
);
9727 layout
->add_output_section_data(".gnu.attributes",
9728 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
9729 attributes_section
, ORDER_INVALID
, false);
9732 // Create .MIPS.abiflags output section if there is an input section.
9733 if (this->has_abiflags_section_
)
9735 Mips_output_section_abiflags
<size
, big_endian
>* abiflags_section
=
9736 new Mips_output_section_abiflags
<size
, big_endian
>(*this->abiflags_
);
9738 Output_section
* os
=
9739 layout
->add_output_section_data(".MIPS.abiflags",
9740 elfcpp::SHT_MIPS_ABIFLAGS
,
9742 abiflags_section
, ORDER_INVALID
, false);
9744 if (!relocatable
&& os
!= NULL
)
9746 Output_segment
* abiflags_segment
=
9747 layout
->make_output_segment(elfcpp::PT_MIPS_ABIFLAGS
, elfcpp::PF_R
);
9748 abiflags_segment
->add_output_section_to_nonload(os
, elfcpp::PF_R
);
9752 if (has_reginfo_section
&& !parameters
->options().gc_sections())
9754 // Create .reginfo output section.
9755 Mips_output_section_reginfo
<size
, big_endian
>* reginfo_section
=
9756 new Mips_output_section_reginfo
<size
, big_endian
>(this, gprmask
,
9758 cprmask3
, cprmask4
);
9760 Output_section
* os
=
9761 layout
->add_output_section_data(".reginfo", elfcpp::SHT_MIPS_REGINFO
,
9762 elfcpp::SHF_ALLOC
, reginfo_section
,
9763 ORDER_INVALID
, false);
9765 if (!relocatable
&& os
!= NULL
)
9767 Output_segment
* reginfo_segment
=
9768 layout
->make_output_segment(elfcpp::PT_MIPS_REGINFO
,
9770 reginfo_segment
->add_output_section_to_nonload(os
, elfcpp::PF_R
);
9774 if (this->plt_
!= NULL
)
9776 // Set final PLT offsets for symbols.
9777 this->plt_section()->set_plt_offsets();
9779 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
9780 // Set STO_MICROMIPS flag if the output has microMIPS code, but only if
9781 // there are no standard PLT entries present.
9782 unsigned char nonvis
= 0;
9783 if (this->is_output_micromips()
9784 && !this->plt_section()->has_standard_entries())
9785 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
9786 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
9787 Symbol_table::PREDEFINED
,
9789 0, 0, elfcpp::STT_FUNC
,
9791 elfcpp::STV_DEFAULT
, nonvis
,
9795 if (this->mips_stubs_
!= NULL
)
9797 // Define _MIPS_STUBS_ at the start of the .MIPS.stubs section.
9798 unsigned char nonvis
= 0;
9799 if (this->is_output_micromips())
9800 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
9801 symtab
->define_in_output_data("_MIPS_STUBS_", NULL
,
9802 Symbol_table::PREDEFINED
,
9804 0, 0, elfcpp::STT_FUNC
,
9806 elfcpp::STV_DEFAULT
, nonvis
,
9810 if (!relocatable
&& !parameters
->doing_static_link())
9811 // In case there is no .got section, create one.
9812 this->got_section(symtab
, layout
);
9814 // Emit any relocs we saved in an attempt to avoid generating COPY
9816 if (this->copy_relocs_
.any_saved_relocs())
9817 this->copy_relocs_
.emit_mips(this->rel_dyn_section(layout
), symtab
, layout
,
9821 this->set_gp(layout
, symtab
);
9823 // Emit dynamic relocs.
9824 for (typename
std::vector
<Dyn_reloc
>::iterator p
= this->dyn_relocs_
.begin();
9825 p
!= this->dyn_relocs_
.end();
9827 p
->emit(this->rel_dyn_section(layout
), this->got_section(), symtab
);
9829 if (this->has_got_section())
9830 this->got_section()->lay_out_got(layout
, symtab
, input_objects
);
9832 if (this->mips_stubs_
!= NULL
)
9833 this->mips_stubs_
->set_needs_dynsym_value();
9835 // Check for functions that might need $25 to be valid on entry.
9836 // TODO(sasa): Can we do this without iterating over all symbols?
9837 typedef Symbol_visitor_check_symbols
<size
, big_endian
> Symbol_visitor
;
9838 symtab
->for_all_symbols
<size
, Symbol_visitor
>(Symbol_visitor(this, layout
,
9841 // Add NULL segment.
9843 layout
->make_output_segment(elfcpp::PT_NULL
, 0);
9845 // Fill in some more dynamic tags.
9846 // TODO(sasa): Add more dynamic tags.
9847 const Reloc_section
* rel_plt
= (this->plt_
== NULL
9848 ? NULL
: this->plt_
->rel_plt());
9849 layout
->add_target_dynamic_tags(true, this->got_
, rel_plt
,
9850 this->rel_dyn_
, true, false);
9852 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
9855 && !parameters
->doing_static_link())
9858 // This element holds a 32-bit version id for the Runtime
9859 // Linker Interface. This will start at integer value 1.
9861 odyn
->add_constant(elfcpp::DT_MIPS_RLD_VERSION
, d_val
);
9864 d_val
= elfcpp::RHF_NOTPOT
;
9865 odyn
->add_constant(elfcpp::DT_MIPS_FLAGS
, d_val
);
9867 // Save layout for using when emitting custom dynamic tags.
9868 this->layout_
= layout
;
9870 // This member holds the base address of the segment.
9871 odyn
->add_custom(elfcpp::DT_MIPS_BASE_ADDRESS
);
9873 // This member holds the number of entries in the .dynsym section.
9874 odyn
->add_custom(elfcpp::DT_MIPS_SYMTABNO
);
9876 // This member holds the index of the first dynamic symbol
9877 // table entry that corresponds to an entry in the global offset table.
9878 odyn
->add_custom(elfcpp::DT_MIPS_GOTSYM
);
9880 // This member holds the number of local GOT entries.
9881 odyn
->add_constant(elfcpp::DT_MIPS_LOCAL_GOTNO
,
9882 this->got_
->get_local_gotno());
9884 if (this->plt_
!= NULL
)
9885 // DT_MIPS_PLTGOT dynamic tag
9886 odyn
->add_section_address(elfcpp::DT_MIPS_PLTGOT
, this->got_plt_
);
9888 if (!parameters
->options().shared())
9890 this->rld_map_
= new Output_data_zero_fill(size
/ 8, size
/ 8);
9892 layout
->add_output_section_data(".rld_map", elfcpp::SHT_PROGBITS
,
9893 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
9894 this->rld_map_
, ORDER_INVALID
, false);
9896 // __RLD_MAP will be filled in by the runtime loader to contain
9897 // a pointer to the _r_debug structure.
9898 Symbol
* rld_map
= symtab
->define_in_output_data("__RLD_MAP", NULL
,
9899 Symbol_table::PREDEFINED
,
9901 0, 0, elfcpp::STT_OBJECT
,
9903 elfcpp::STV_DEFAULT
, 0,
9906 if (!rld_map
->is_forced_local())
9907 rld_map
->set_needs_dynsym_entry();
9909 if (!parameters
->options().pie())
9910 // This member holds the absolute address of the debug pointer.
9911 odyn
->add_section_address(elfcpp::DT_MIPS_RLD_MAP
, this->rld_map_
);
9913 // This member holds the offset to the debug pointer,
9914 // relative to the address of the tag.
9915 odyn
->add_custom(elfcpp::DT_MIPS_RLD_MAP_REL
);
9920 // Get the custom dynamic tag value.
9921 template<int size
, bool big_endian
>
9923 Target_mips
<size
, big_endian
>::do_dynamic_tag_custom_value(elfcpp::DT tag
) const
9927 case elfcpp::DT_MIPS_BASE_ADDRESS
:
9929 // The base address of the segment.
9930 // At this point, the segment list has been sorted into final order,
9931 // so just return vaddr of the first readable PT_LOAD segment.
9932 Output_segment
* seg
=
9933 this->layout_
->find_output_segment(elfcpp::PT_LOAD
, elfcpp::PF_R
, 0);
9934 gold_assert(seg
!= NULL
);
9935 return seg
->vaddr();
9938 case elfcpp::DT_MIPS_SYMTABNO
:
9939 // The number of entries in the .dynsym section.
9940 return this->get_dt_mips_symtabno();
9942 case elfcpp::DT_MIPS_GOTSYM
:
9944 // The index of the first dynamic symbol table entry that corresponds
9945 // to an entry in the GOT.
9946 if (this->got_
->first_global_got_dynsym_index() != -1U)
9947 return this->got_
->first_global_got_dynsym_index();
9949 // In case if we don't have global GOT symbols we default to setting
9950 // DT_MIPS_GOTSYM to the same value as DT_MIPS_SYMTABNO.
9951 return this->get_dt_mips_symtabno();
9954 case elfcpp::DT_MIPS_RLD_MAP_REL
:
9956 // The MIPS_RLD_MAP_REL tag stores the offset to the debug pointer,
9957 // relative to the address of the tag.
9958 Output_data_dynamic
* const odyn
= this->layout_
->dynamic_data();
9959 unsigned int entry_offset
=
9960 odyn
->get_entry_offset(elfcpp::DT_MIPS_RLD_MAP_REL
);
9961 gold_assert(entry_offset
!= -1U);
9962 return this->rld_map_
->address() - (odyn
->address() + entry_offset
);
9965 gold_error(_("Unknown dynamic tag 0x%x"), (unsigned int)tag
);
9968 return (unsigned int)-1;
9971 // Relocate section data.
9973 template<int size
, bool big_endian
>
9975 Target_mips
<size
, big_endian
>::relocate_section(
9976 const Relocate_info
<size
, big_endian
>* relinfo
,
9977 unsigned int sh_type
,
9978 const unsigned char* prelocs
,
9980 Output_section
* output_section
,
9981 bool needs_special_offset_handling
,
9982 unsigned char* view
,
9983 Mips_address address
,
9984 section_size_type view_size
,
9985 const Reloc_symbol_changes
* reloc_symbol_changes
)
9987 typedef Target_mips
<size
, big_endian
> Mips
;
9988 typedef typename Target_mips
<size
, big_endian
>::Relocate Mips_relocate
;
9990 if (sh_type
== elfcpp::SHT_REL
)
9992 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
9995 gold::relocate_section
<size
, big_endian
, Mips
, Mips_relocate
,
9996 gold::Default_comdat_behavior
, Classify_reloc
>(
10002 needs_special_offset_handling
,
10006 reloc_symbol_changes
);
10008 else if (sh_type
== elfcpp::SHT_RELA
)
10010 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
10013 gold::relocate_section
<size
, big_endian
, Mips
, Mips_relocate
,
10014 gold::Default_comdat_behavior
, Classify_reloc
>(
10020 needs_special_offset_handling
,
10024 reloc_symbol_changes
);
10028 // Return the size of a relocation while scanning during a relocatable
10032 mips_get_size_for_reloc(unsigned int r_type
, Relobj
* object
)
10036 case elfcpp::R_MIPS_NONE
:
10037 case elfcpp::R_MIPS_TLS_DTPMOD64
:
10038 case elfcpp::R_MIPS_TLS_DTPREL64
:
10039 case elfcpp::R_MIPS_TLS_TPREL64
:
10042 case elfcpp::R_MIPS_32
:
10043 case elfcpp::R_MIPS_TLS_DTPMOD32
:
10044 case elfcpp::R_MIPS_TLS_DTPREL32
:
10045 case elfcpp::R_MIPS_TLS_TPREL32
:
10046 case elfcpp::R_MIPS_REL32
:
10047 case elfcpp::R_MIPS_PC32
:
10048 case elfcpp::R_MIPS_GPREL32
:
10049 case elfcpp::R_MIPS_JALR
:
10050 case elfcpp::R_MIPS_EH
:
10053 case elfcpp::R_MIPS_16
:
10054 case elfcpp::R_MIPS_HI16
:
10055 case elfcpp::R_MIPS_LO16
:
10056 case elfcpp::R_MIPS_HIGHER
:
10057 case elfcpp::R_MIPS_HIGHEST
:
10058 case elfcpp::R_MIPS_GPREL16
:
10059 case elfcpp::R_MIPS16_HI16
:
10060 case elfcpp::R_MIPS16_LO16
:
10061 case elfcpp::R_MIPS_PC16
:
10062 case elfcpp::R_MIPS_PCHI16
:
10063 case elfcpp::R_MIPS_PCLO16
:
10064 case elfcpp::R_MIPS_GOT16
:
10065 case elfcpp::R_MIPS16_GOT16
:
10066 case elfcpp::R_MIPS_CALL16
:
10067 case elfcpp::R_MIPS16_CALL16
:
10068 case elfcpp::R_MIPS_GOT_HI16
:
10069 case elfcpp::R_MIPS_CALL_HI16
:
10070 case elfcpp::R_MIPS_GOT_LO16
:
10071 case elfcpp::R_MIPS_CALL_LO16
:
10072 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
10073 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
10074 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
10075 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
10076 case elfcpp::R_MIPS16_GPREL
:
10077 case elfcpp::R_MIPS_GOT_DISP
:
10078 case elfcpp::R_MIPS_LITERAL
:
10079 case elfcpp::R_MIPS_GOT_PAGE
:
10080 case elfcpp::R_MIPS_GOT_OFST
:
10081 case elfcpp::R_MIPS_TLS_GD
:
10082 case elfcpp::R_MIPS_TLS_LDM
:
10083 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10086 // These relocations are not byte sized
10087 case elfcpp::R_MIPS_26
:
10088 case elfcpp::R_MIPS16_26
:
10089 case elfcpp::R_MIPS_PC21_S2
:
10090 case elfcpp::R_MIPS_PC26_S2
:
10091 case elfcpp::R_MIPS_PC18_S3
:
10092 case elfcpp::R_MIPS_PC19_S2
:
10095 case elfcpp::R_MIPS_COPY
:
10096 case elfcpp::R_MIPS_JUMP_SLOT
:
10097 object
->error(_("unexpected reloc %u in object file"), r_type
);
10101 object
->error(_("unsupported reloc %u in object file"), r_type
);
10106 // Scan the relocs during a relocatable link.
10108 template<int size
, bool big_endian
>
10110 Target_mips
<size
, big_endian
>::scan_relocatable_relocs(
10111 Symbol_table
* symtab
,
10113 Sized_relobj_file
<size
, big_endian
>* object
,
10114 unsigned int data_shndx
,
10115 unsigned int sh_type
,
10116 const unsigned char* prelocs
,
10117 size_t reloc_count
,
10118 Output_section
* output_section
,
10119 bool needs_special_offset_handling
,
10120 size_t local_symbol_count
,
10121 const unsigned char* plocal_symbols
,
10122 Relocatable_relocs
* rr
)
10124 if (sh_type
== elfcpp::SHT_REL
)
10126 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
10128 typedef Mips_scan_relocatable_relocs
<big_endian
, Classify_reloc
>
10129 Scan_relocatable_relocs
;
10131 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_relocatable_relocs
>(
10139 needs_special_offset_handling
,
10140 local_symbol_count
,
10144 else if (sh_type
== elfcpp::SHT_RELA
)
10146 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
10148 typedef Mips_scan_relocatable_relocs
<big_endian
, Classify_reloc
>
10149 Scan_relocatable_relocs
;
10151 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_relocatable_relocs
>(
10159 needs_special_offset_handling
,
10160 local_symbol_count
,
10165 gold_unreachable();
10168 // Scan the relocs for --emit-relocs.
10170 template<int size
, bool big_endian
>
10172 Target_mips
<size
, big_endian
>::emit_relocs_scan(
10173 Symbol_table
* symtab
,
10175 Sized_relobj_file
<size
, big_endian
>* object
,
10176 unsigned int data_shndx
,
10177 unsigned int sh_type
,
10178 const unsigned char* prelocs
,
10179 size_t reloc_count
,
10180 Output_section
* output_section
,
10181 bool needs_special_offset_handling
,
10182 size_t local_symbol_count
,
10183 const unsigned char* plocal_syms
,
10184 Relocatable_relocs
* rr
)
10186 if (sh_type
== elfcpp::SHT_REL
)
10188 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
10190 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
10191 Emit_relocs_strategy
;
10193 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
10201 needs_special_offset_handling
,
10202 local_symbol_count
,
10206 else if (sh_type
== elfcpp::SHT_RELA
)
10208 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
10210 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
10211 Emit_relocs_strategy
;
10213 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
10221 needs_special_offset_handling
,
10222 local_symbol_count
,
10227 gold_unreachable();
10230 // Emit relocations for a section.
10232 template<int size
, bool big_endian
>
10234 Target_mips
<size
, big_endian
>::relocate_relocs(
10235 const Relocate_info
<size
, big_endian
>* relinfo
,
10236 unsigned int sh_type
,
10237 const unsigned char* prelocs
,
10238 size_t reloc_count
,
10239 Output_section
* output_section
,
10240 typename
elfcpp::Elf_types
<size
>::Elf_Off
10241 offset_in_output_section
,
10242 unsigned char* view
,
10243 Mips_address view_address
,
10244 section_size_type view_size
,
10245 unsigned char* reloc_view
,
10246 section_size_type reloc_view_size
)
10248 if (sh_type
== elfcpp::SHT_REL
)
10250 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
10253 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
10258 offset_in_output_section
,
10265 else if (sh_type
== elfcpp::SHT_RELA
)
10267 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
10270 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
10275 offset_in_output_section
,
10283 gold_unreachable();
10286 // Perform target-specific processing in a relocatable link. This is
10287 // only used if we use the relocation strategy RELOC_SPECIAL.
10289 template<int size
, bool big_endian
>
10291 Target_mips
<size
, big_endian
>::relocate_special_relocatable(
10292 const Relocate_info
<size
, big_endian
>* relinfo
,
10293 unsigned int sh_type
,
10294 const unsigned char* preloc_in
,
10296 Output_section
* output_section
,
10297 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
10298 unsigned char* view
,
10299 Mips_address view_address
,
10301 unsigned char* preloc_out
)
10303 // We can only handle REL type relocation sections.
10304 gold_assert(sh_type
== elfcpp::SHT_REL
);
10306 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
10308 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc_write
10311 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
10313 const Mips_address invalid_address
= static_cast<Mips_address
>(0) - 1;
10315 Mips_relobj
<size
, big_endian
>* object
=
10316 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
10317 const unsigned int local_count
= object
->local_symbol_count();
10319 Reltype
reloc(preloc_in
);
10320 Reltype_write
reloc_write(preloc_out
);
10322 elfcpp::Elf_types
<32>::Elf_WXword r_info
= reloc
.get_r_info();
10323 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
10324 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
10326 // Get the new symbol index.
10327 // We only use RELOC_SPECIAL strategy in local relocations.
10328 gold_assert(r_sym
< local_count
);
10330 // We are adjusting a section symbol. We need to find
10331 // the symbol table index of the section symbol for
10332 // the output section corresponding to input section
10333 // in which this symbol is defined.
10335 unsigned int shndx
= object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
10336 gold_assert(is_ordinary
);
10337 Output_section
* os
= object
->output_section(shndx
);
10338 gold_assert(os
!= NULL
);
10339 gold_assert(os
->needs_symtab_index());
10340 unsigned int new_symndx
= os
->symtab_index();
10342 // Get the new offset--the location in the output section where
10343 // this relocation should be applied.
10345 Mips_address offset
= reloc
.get_r_offset();
10346 Mips_address new_offset
;
10347 if (offset_in_output_section
!= invalid_address
)
10348 new_offset
= offset
+ offset_in_output_section
;
10351 section_offset_type sot_offset
=
10352 convert_types
<section_offset_type
, Mips_address
>(offset
);
10353 section_offset_type new_sot_offset
=
10354 output_section
->output_offset(object
, relinfo
->data_shndx
,
10356 gold_assert(new_sot_offset
!= -1);
10357 new_offset
= new_sot_offset
;
10360 // In an object file, r_offset is an offset within the section.
10361 // In an executable or dynamic object, generated by
10362 // --emit-relocs, r_offset is an absolute address.
10363 if (!parameters
->options().relocatable())
10365 new_offset
+= view_address
;
10366 if (offset_in_output_section
!= invalid_address
)
10367 new_offset
-= offset_in_output_section
;
10370 reloc_write
.put_r_offset(new_offset
);
10371 reloc_write
.put_r_info(elfcpp::elf_r_info
<32>(new_symndx
, r_type
));
10373 // Handle the reloc addend.
10374 // The relocation uses a section symbol in the input file.
10375 // We are adjusting it to use a section symbol in the output
10376 // file. The input section symbol refers to some address in
10377 // the input section. We need the relocation in the output
10378 // file to refer to that same address. This adjustment to
10379 // the addend is the same calculation we use for a simple
10380 // absolute relocation for the input section symbol.
10381 Valtype calculated_value
= 0;
10382 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
10384 unsigned char* paddend
= view
+ offset
;
10385 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
10388 case elfcpp::R_MIPS_26
:
10389 reloc_status
= Reloc_funcs::rel26(paddend
, object
, psymval
,
10390 offset_in_output_section
, true, 0, sh_type
== elfcpp::SHT_REL
, NULL
,
10391 false /*TODO(sasa): cross mode jump*/, r_type
, this->jal_to_bal(),
10392 false, &calculated_value
);
10396 gold_unreachable();
10399 // Report any errors.
10400 switch (reloc_status
)
10402 case Reloc_funcs::STATUS_OKAY
:
10404 case Reloc_funcs::STATUS_OVERFLOW
:
10405 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
10406 _("relocation overflow: "
10407 "%u against local symbol %u in %s"),
10408 r_type
, r_sym
, object
->name().c_str());
10410 case Reloc_funcs::STATUS_BAD_RELOC
:
10411 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
10412 _("unexpected opcode while processing relocation"));
10415 gold_unreachable();
10419 // Optimize the TLS relocation type based on what we know about the
10420 // symbol. IS_FINAL is true if the final address of this symbol is
10421 // known at link time.
10423 template<int size
, bool big_endian
>
10424 tls::Tls_optimization
10425 Target_mips
<size
, big_endian
>::optimize_tls_reloc(bool, int)
10427 // FIXME: Currently we do not do any TLS optimization.
10428 return tls::TLSOPT_NONE
;
10431 // Scan a relocation for a local symbol.
10433 template<int size
, bool big_endian
>
10435 Target_mips
<size
, big_endian
>::Scan::local(
10436 Symbol_table
* symtab
,
10438 Target_mips
<size
, big_endian
>* target
,
10439 Sized_relobj_file
<size
, big_endian
>* object
,
10440 unsigned int data_shndx
,
10441 Output_section
* output_section
,
10442 const Relatype
* rela
,
10443 const Reltype
* rel
,
10444 unsigned int rel_type
,
10445 unsigned int r_type
,
10446 const elfcpp::Sym
<size
, big_endian
>& lsym
,
10452 Mips_address r_offset
;
10453 unsigned int r_sym
;
10454 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
10456 if (rel_type
== elfcpp::SHT_RELA
)
10458 r_offset
= rela
->get_r_offset();
10459 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10461 r_addend
= rela
->get_r_addend();
10465 r_offset
= rel
->get_r_offset();
10466 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
10471 Mips_relobj
<size
, big_endian
>* mips_obj
=
10472 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
10474 if (mips_obj
->is_mips16_stub_section(data_shndx
))
10476 mips_obj
->get_mips16_stub_section(data_shndx
)
10477 ->new_local_reloc_found(r_type
, r_sym
);
10480 if (r_type
== elfcpp::R_MIPS_NONE
)
10481 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
10485 if (!mips16_call_reloc(r_type
)
10486 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
10487 // This reloc would need to refer to a MIPS16 hard-float stub, if
10488 // there is one. We ignore MIPS16 stub sections and .pdr section when
10489 // looking for relocs that would need to refer to MIPS16 stubs.
10490 mips_obj
->add_local_non_16bit_call(r_sym
);
10492 if (r_type
== elfcpp::R_MIPS16_26
10493 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
10494 mips_obj
->add_local_16bit_call(r_sym
);
10498 case elfcpp::R_MIPS_GOT16
:
10499 case elfcpp::R_MIPS_CALL16
:
10500 case elfcpp::R_MIPS_CALL_HI16
:
10501 case elfcpp::R_MIPS_CALL_LO16
:
10502 case elfcpp::R_MIPS_GOT_HI16
:
10503 case elfcpp::R_MIPS_GOT_LO16
:
10504 case elfcpp::R_MIPS_GOT_PAGE
:
10505 case elfcpp::R_MIPS_GOT_OFST
:
10506 case elfcpp::R_MIPS_GOT_DISP
:
10507 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10508 case elfcpp::R_MIPS_TLS_GD
:
10509 case elfcpp::R_MIPS_TLS_LDM
:
10510 case elfcpp::R_MIPS16_GOT16
:
10511 case elfcpp::R_MIPS16_CALL16
:
10512 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10513 case elfcpp::R_MIPS16_TLS_GD
:
10514 case elfcpp::R_MIPS16_TLS_LDM
:
10515 case elfcpp::R_MICROMIPS_GOT16
:
10516 case elfcpp::R_MICROMIPS_CALL16
:
10517 case elfcpp::R_MICROMIPS_CALL_HI16
:
10518 case elfcpp::R_MICROMIPS_CALL_LO16
:
10519 case elfcpp::R_MICROMIPS_GOT_HI16
:
10520 case elfcpp::R_MICROMIPS_GOT_LO16
:
10521 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10522 case elfcpp::R_MICROMIPS_GOT_OFST
:
10523 case elfcpp::R_MICROMIPS_GOT_DISP
:
10524 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10525 case elfcpp::R_MICROMIPS_TLS_GD
:
10526 case elfcpp::R_MICROMIPS_TLS_LDM
:
10527 case elfcpp::R_MIPS_EH
:
10528 // We need a GOT section.
10529 target
->got_section(symtab
, layout
);
10536 if (call_lo16_reloc(r_type
)
10537 || got_lo16_reloc(r_type
)
10538 || got_disp_reloc(r_type
)
10539 || eh_reloc(r_type
))
10541 // We may need a local GOT entry for this relocation. We
10542 // don't count R_MIPS_GOT_PAGE because we can estimate the
10543 // maximum number of pages needed by looking at the size of
10544 // the segment. Similar comments apply to R_MIPS*_GOT16 and
10545 // R_MIPS*_CALL16. We don't count R_MIPS_GOT_HI16, or
10546 // R_MIPS_CALL_HI16 because these are always followed by an
10547 // R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
10548 Mips_output_data_got
<size
, big_endian
>* got
=
10549 target
->got_section(symtab
, layout
);
10550 bool is_section_symbol
= lsym
.get_st_type() == elfcpp::STT_SECTION
;
10551 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
, -1U,
10552 is_section_symbol
);
10557 case elfcpp::R_MIPS_CALL16
:
10558 case elfcpp::R_MIPS16_CALL16
:
10559 case elfcpp::R_MICROMIPS_CALL16
:
10560 gold_error(_("CALL16 reloc at 0x%lx not against global symbol "),
10561 (unsigned long)r_offset
);
10564 case elfcpp::R_MIPS_GOT_PAGE
:
10565 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10566 case elfcpp::R_MIPS16_GOT16
:
10567 case elfcpp::R_MIPS_GOT16
:
10568 case elfcpp::R_MIPS_GOT_HI16
:
10569 case elfcpp::R_MIPS_GOT_LO16
:
10570 case elfcpp::R_MICROMIPS_GOT16
:
10571 case elfcpp::R_MICROMIPS_GOT_HI16
:
10572 case elfcpp::R_MICROMIPS_GOT_LO16
:
10574 // This relocation needs a page entry in the GOT.
10575 // Get the section contents.
10576 section_size_type view_size
= 0;
10577 const unsigned char* view
= object
->section_contents(data_shndx
,
10578 &view_size
, false);
10581 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
10582 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
10585 if (rel_type
== elfcpp::SHT_REL
&& got16_reloc(r_type
))
10586 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
10587 object
, data_shndx
, r_type
, r_sym
, addend
));
10589 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
, addend
);
10593 case elfcpp::R_MIPS_HI16
:
10594 case elfcpp::R_MIPS_PCHI16
:
10595 case elfcpp::R_MIPS16_HI16
:
10596 case elfcpp::R_MICROMIPS_HI16
:
10597 // Record the reloc so that we can check whether the corresponding LO16
10599 if (rel_type
== elfcpp::SHT_REL
)
10600 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
10601 object
, data_shndx
, r_type
, r_sym
, 0));
10604 case elfcpp::R_MIPS_LO16
:
10605 case elfcpp::R_MIPS_PCLO16
:
10606 case elfcpp::R_MIPS16_LO16
:
10607 case elfcpp::R_MICROMIPS_LO16
:
10609 if (rel_type
!= elfcpp::SHT_REL
)
10612 // Find corresponding GOT16/HI16 relocation.
10614 // According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
10615 // be immediately following. However, for the IRIX6 ABI, the next
10616 // relocation may be a composed relocation consisting of several
10617 // relocations for the same address. In that case, the R_MIPS_LO16
10618 // relocation may occur as one of these. We permit a similar
10619 // extension in general, as that is useful for GCC.
10621 // In some cases GCC dead code elimination removes the LO16 but
10622 // keeps the corresponding HI16. This is strictly speaking a
10623 // violation of the ABI but not immediately harmful.
10625 typename
std::list
<got16_addend
<size
, big_endian
> >::iterator it
=
10626 target
->got16_addends_
.begin();
10627 while (it
!= target
->got16_addends_
.end())
10629 got16_addend
<size
, big_endian
> _got16_addend
= *it
;
10631 // TODO(sasa): Split got16_addends_ list into two lists - one for
10632 // GOT16 relocs and the other for HI16 relocs.
10634 // Report an error if we find HI16 or GOT16 reloc from the
10635 // previous section without the matching LO16 part.
10636 if (_got16_addend
.object
!= object
10637 || _got16_addend
.shndx
!= data_shndx
)
10639 gold_error("Can't find matching LO16 reloc");
10643 if (_got16_addend
.r_sym
!= r_sym
10644 || !is_matching_lo16_reloc(_got16_addend
.r_type
, r_type
))
10650 // We found a matching HI16 or GOT16 reloc for this LO16 reloc.
10651 // For GOT16, we need to calculate combined addend and record GOT page
10653 if (got16_reloc(_got16_addend
.r_type
))
10656 section_size_type view_size
= 0;
10657 const unsigned char* view
= object
->section_contents(data_shndx
,
10662 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
10663 int32_t addend
= Bits
<16>::sign_extend32(val
& 0xffff);
10665 addend
= (_got16_addend
.addend
<< 16) + addend
;
10666 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
,
10670 it
= target
->got16_addends_
.erase(it
);
10678 case elfcpp::R_MIPS_32
:
10679 case elfcpp::R_MIPS_REL32
:
10680 case elfcpp::R_MIPS_64
:
10682 if (parameters
->options().output_is_position_independent())
10684 // If building a shared library (or a position-independent
10685 // executable), we need to create a dynamic relocation for
10687 if (is_readonly_section(output_section
))
10689 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
10690 rel_dyn
->add_symbolless_local_addend(object
, r_sym
,
10691 elfcpp::R_MIPS_REL32
,
10692 output_section
, data_shndx
,
10698 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10699 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10700 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10701 case elfcpp::R_MIPS_TLS_LDM
:
10702 case elfcpp::R_MIPS16_TLS_LDM
:
10703 case elfcpp::R_MICROMIPS_TLS_LDM
:
10704 case elfcpp::R_MIPS_TLS_GD
:
10705 case elfcpp::R_MIPS16_TLS_GD
:
10706 case elfcpp::R_MICROMIPS_TLS_GD
:
10708 bool output_is_shared
= parameters
->options().shared();
10709 const tls::Tls_optimization optimized_type
10710 = Target_mips
<size
, big_endian
>::optimize_tls_reloc(
10711 !output_is_shared
, r_type
);
10714 case elfcpp::R_MIPS_TLS_GD
:
10715 case elfcpp::R_MIPS16_TLS_GD
:
10716 case elfcpp::R_MICROMIPS_TLS_GD
:
10717 if (optimized_type
== tls::TLSOPT_NONE
)
10719 // Create a pair of GOT entries for the module index and
10720 // dtv-relative offset.
10721 Mips_output_data_got
<size
, big_endian
>* got
=
10722 target
->got_section(symtab
, layout
);
10723 unsigned int shndx
= lsym
.get_st_shndx();
10725 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
10728 object
->error(_("local symbol %u has bad shndx %u"),
10732 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
10737 // FIXME: TLS optimization not supported yet.
10738 gold_unreachable();
10742 case elfcpp::R_MIPS_TLS_LDM
:
10743 case elfcpp::R_MIPS16_TLS_LDM
:
10744 case elfcpp::R_MICROMIPS_TLS_LDM
:
10745 if (optimized_type
== tls::TLSOPT_NONE
)
10747 // We always record LDM symbols as local with index 0.
10748 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
10754 // FIXME: TLS optimization not supported yet.
10755 gold_unreachable();
10758 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10759 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10760 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10761 layout
->set_has_static_tls();
10762 if (optimized_type
== tls::TLSOPT_NONE
)
10764 // Create a GOT entry for the tp-relative offset.
10765 Mips_output_data_got
<size
, big_endian
>* got
=
10766 target
->got_section(symtab
, layout
);
10767 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
10772 // FIXME: TLS optimization not supported yet.
10773 gold_unreachable();
10778 gold_unreachable();
10787 // Refuse some position-dependent relocations when creating a
10788 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
10789 // not PIC, but we can create dynamic relocations and the result
10790 // will be fine. Also do not refuse R_MIPS_LO16, which can be
10791 // combined with R_MIPS_GOT16.
10792 if (parameters
->options().shared())
10796 case elfcpp::R_MIPS16_HI16
:
10797 case elfcpp::R_MIPS_HI16
:
10798 case elfcpp::R_MIPS_HIGHER
:
10799 case elfcpp::R_MIPS_HIGHEST
:
10800 case elfcpp::R_MICROMIPS_HI16
:
10801 case elfcpp::R_MICROMIPS_HIGHER
:
10802 case elfcpp::R_MICROMIPS_HIGHEST
:
10803 // Don't refuse a high part relocation if it's against
10804 // no symbol (e.g. part of a compound relocation).
10809 case elfcpp::R_MIPS16_26
:
10810 case elfcpp::R_MIPS_26
:
10811 case elfcpp::R_MICROMIPS_26_S1
:
10812 gold_error(_("%s: relocation %u against `%s' can not be used when "
10813 "making a shared object; recompile with -fPIC"),
10814 object
->name().c_str(), r_type
, "a local symbol");
10821 template<int size
, bool big_endian
>
10823 Target_mips
<size
, big_endian
>::Scan::local(
10824 Symbol_table
* symtab
,
10826 Target_mips
<size
, big_endian
>* target
,
10827 Sized_relobj_file
<size
, big_endian
>* object
,
10828 unsigned int data_shndx
,
10829 Output_section
* output_section
,
10830 const Reltype
& reloc
,
10831 unsigned int r_type
,
10832 const elfcpp::Sym
<size
, big_endian
>& lsym
,
10845 (const Relatype
*) NULL
,
10849 lsym
, is_discarded
);
10853 template<int size
, bool big_endian
>
10855 Target_mips
<size
, big_endian
>::Scan::local(
10856 Symbol_table
* symtab
,
10858 Target_mips
<size
, big_endian
>* target
,
10859 Sized_relobj_file
<size
, big_endian
>* object
,
10860 unsigned int data_shndx
,
10861 Output_section
* output_section
,
10862 const Relatype
& reloc
,
10863 unsigned int r_type
,
10864 const elfcpp::Sym
<size
, big_endian
>& lsym
,
10878 (const Reltype
*) NULL
,
10881 lsym
, is_discarded
);
10884 // Scan a relocation for a global symbol.
10886 template<int size
, bool big_endian
>
10888 Target_mips
<size
, big_endian
>::Scan::global(
10889 Symbol_table
* symtab
,
10891 Target_mips
<size
, big_endian
>* target
,
10892 Sized_relobj_file
<size
, big_endian
>* object
,
10893 unsigned int data_shndx
,
10894 Output_section
* output_section
,
10895 const Relatype
* rela
,
10896 const Reltype
* rel
,
10897 unsigned int rel_type
,
10898 unsigned int r_type
,
10901 Mips_address r_offset
;
10902 unsigned int r_sym
;
10903 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
10905 if (rel_type
== elfcpp::SHT_RELA
)
10907 r_offset
= rela
->get_r_offset();
10908 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10910 r_addend
= rela
->get_r_addend();
10914 r_offset
= rel
->get_r_offset();
10915 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
10920 Mips_relobj
<size
, big_endian
>* mips_obj
=
10921 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
10922 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
10924 if (mips_obj
->is_mips16_stub_section(data_shndx
))
10926 mips_obj
->get_mips16_stub_section(data_shndx
)
10927 ->new_global_reloc_found(r_type
, mips_sym
);
10930 if (r_type
== elfcpp::R_MIPS_NONE
)
10931 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
10935 if (!mips16_call_reloc(r_type
)
10936 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
10937 // This reloc would need to refer to a MIPS16 hard-float stub, if
10938 // there is one. We ignore MIPS16 stub sections and .pdr section when
10939 // looking for relocs that would need to refer to MIPS16 stubs.
10940 mips_sym
->set_need_fn_stub();
10942 // We need PLT entries if there are static-only relocations against
10943 // an externally-defined function. This can technically occur for
10944 // shared libraries if there are branches to the symbol, although it
10945 // is unlikely that this will be used in practice due to the short
10946 // ranges involved. It can occur for any relative or absolute relocation
10947 // in executables; in that case, the PLT entry becomes the function's
10948 // canonical address.
10949 bool static_reloc
= false;
10951 // Set CAN_MAKE_DYNAMIC to true if we can convert this
10952 // relocation into a dynamic one.
10953 bool can_make_dynamic
= false;
10956 case elfcpp::R_MIPS_GOT16
:
10957 case elfcpp::R_MIPS_CALL16
:
10958 case elfcpp::R_MIPS_CALL_HI16
:
10959 case elfcpp::R_MIPS_CALL_LO16
:
10960 case elfcpp::R_MIPS_GOT_HI16
:
10961 case elfcpp::R_MIPS_GOT_LO16
:
10962 case elfcpp::R_MIPS_GOT_PAGE
:
10963 case elfcpp::R_MIPS_GOT_OFST
:
10964 case elfcpp::R_MIPS_GOT_DISP
:
10965 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10966 case elfcpp::R_MIPS_TLS_GD
:
10967 case elfcpp::R_MIPS_TLS_LDM
:
10968 case elfcpp::R_MIPS16_GOT16
:
10969 case elfcpp::R_MIPS16_CALL16
:
10970 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10971 case elfcpp::R_MIPS16_TLS_GD
:
10972 case elfcpp::R_MIPS16_TLS_LDM
:
10973 case elfcpp::R_MICROMIPS_GOT16
:
10974 case elfcpp::R_MICROMIPS_CALL16
:
10975 case elfcpp::R_MICROMIPS_CALL_HI16
:
10976 case elfcpp::R_MICROMIPS_CALL_LO16
:
10977 case elfcpp::R_MICROMIPS_GOT_HI16
:
10978 case elfcpp::R_MICROMIPS_GOT_LO16
:
10979 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10980 case elfcpp::R_MICROMIPS_GOT_OFST
:
10981 case elfcpp::R_MICROMIPS_GOT_DISP
:
10982 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10983 case elfcpp::R_MICROMIPS_TLS_GD
:
10984 case elfcpp::R_MICROMIPS_TLS_LDM
:
10985 case elfcpp::R_MIPS_EH
:
10986 // We need a GOT section.
10987 target
->got_section(symtab
, layout
);
10990 // This is just a hint; it can safely be ignored. Don't set
10991 // has_static_relocs for the corresponding symbol.
10992 case elfcpp::R_MIPS_JALR
:
10993 case elfcpp::R_MICROMIPS_JALR
:
10996 case elfcpp::R_MIPS_GPREL16
:
10997 case elfcpp::R_MIPS_GPREL32
:
10998 case elfcpp::R_MIPS16_GPREL
:
10999 case elfcpp::R_MICROMIPS_GPREL16
:
11001 // GP-relative relocations always resolve to a definition in a
11002 // regular input file, ignoring the one-definition rule. This is
11003 // important for the GP setup sequence in NewABI code, which
11004 // always resolves to a local function even if other relocations
11005 // against the symbol wouldn't.
11006 //constrain_symbol_p = FALSE;
11009 case elfcpp::R_MIPS_32
:
11010 case elfcpp::R_MIPS_REL32
:
11011 case elfcpp::R_MIPS_64
:
11012 if ((parameters
->options().shared()
11013 || (strcmp(gsym
->name(), "__gnu_local_gp") != 0
11014 && (!is_readonly_section(output_section
)
11015 || mips_obj
->is_pic())))
11016 && (output_section
->flags() & elfcpp::SHF_ALLOC
) != 0)
11018 if (r_type
!= elfcpp::R_MIPS_REL32
)
11019 mips_sym
->set_pointer_equality_needed();
11020 can_make_dynamic
= true;
11026 // Most static relocations require pointer equality, except
11028 mips_sym
->set_pointer_equality_needed();
11031 case elfcpp::R_MIPS_26
:
11032 case elfcpp::R_MIPS_PC16
:
11033 case elfcpp::R_MIPS_PC21_S2
:
11034 case elfcpp::R_MIPS_PC26_S2
:
11035 case elfcpp::R_MIPS16_26
:
11036 case elfcpp::R_MICROMIPS_26_S1
:
11037 case elfcpp::R_MICROMIPS_PC7_S1
:
11038 case elfcpp::R_MICROMIPS_PC10_S1
:
11039 case elfcpp::R_MICROMIPS_PC16_S1
:
11040 case elfcpp::R_MICROMIPS_PC23_S2
:
11041 static_reloc
= true;
11042 mips_sym
->set_has_static_relocs();
11046 // If there are call relocations against an externally-defined symbol,
11047 // see whether we can create a MIPS lazy-binding stub for it. We can
11048 // only do this if all references to the function are through call
11049 // relocations, and in that case, the traditional lazy-binding stubs
11050 // are much more efficient than PLT entries.
11053 case elfcpp::R_MIPS16_CALL16
:
11054 case elfcpp::R_MIPS_CALL16
:
11055 case elfcpp::R_MIPS_CALL_HI16
:
11056 case elfcpp::R_MIPS_CALL_LO16
:
11057 case elfcpp::R_MIPS_JALR
:
11058 case elfcpp::R_MICROMIPS_CALL16
:
11059 case elfcpp::R_MICROMIPS_CALL_HI16
:
11060 case elfcpp::R_MICROMIPS_CALL_LO16
:
11061 case elfcpp::R_MICROMIPS_JALR
:
11062 if (!mips_sym
->no_lazy_stub())
11064 if ((mips_sym
->needs_plt_entry() && mips_sym
->is_from_dynobj())
11065 // Calls from shared objects to undefined symbols of type
11066 // STT_NOTYPE need lazy-binding stub.
11067 || (mips_sym
->is_undefined() && parameters
->options().shared()))
11068 target
->mips_stubs_section(layout
)->make_entry(mips_sym
);
11073 // We must not create a stub for a symbol that has relocations
11074 // related to taking the function's address.
11075 mips_sym
->set_no_lazy_stub();
11076 target
->remove_lazy_stub_entry(mips_sym
);
11081 if (relocation_needs_la25_stub
<size
, big_endian
>(mips_obj
, r_type
,
11082 mips_sym
->is_mips16()))
11083 mips_sym
->set_has_nonpic_branches();
11085 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
11086 // and has a special meaning.
11087 bool gp_disp_against_hi16
= (!mips_obj
->is_newabi()
11088 && strcmp(gsym
->name(), "_gp_disp") == 0
11089 && (hi16_reloc(r_type
) || lo16_reloc(r_type
)));
11090 if (static_reloc
&& gsym
->needs_plt_entry())
11092 target
->make_plt_entry(symtab
, layout
, mips_sym
, r_type
);
11094 // Since this is not a PC-relative relocation, we may be
11095 // taking the address of a function. In that case we need to
11096 // set the entry in the dynamic symbol table to the address of
11098 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
11100 gsym
->set_needs_dynsym_value();
11101 // We distinguish between PLT entries and lazy-binding stubs by
11102 // giving the former an st_other value of STO_MIPS_PLT. Set the
11103 // flag if there are any relocations in the binary where pointer
11104 // equality matters.
11105 if (mips_sym
->pointer_equality_needed())
11106 mips_sym
->set_mips_plt();
11109 if ((static_reloc
|| can_make_dynamic
) && !gp_disp_against_hi16
)
11111 // Absolute addressing relocations.
11112 // Make a dynamic relocation if necessary.
11113 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
11115 if (gsym
->may_need_copy_reloc())
11117 target
->copy_reloc(symtab
, layout
, object
, data_shndx
,
11118 output_section
, gsym
, r_type
, r_offset
);
11120 else if (can_make_dynamic
)
11122 // Create .rel.dyn section.
11123 target
->rel_dyn_section(layout
);
11124 target
->dynamic_reloc(mips_sym
, elfcpp::R_MIPS_REL32
, mips_obj
,
11125 data_shndx
, output_section
, r_offset
);
11128 gold_error(_("non-dynamic relocations refer to dynamic symbol %s"),
11133 bool for_call
= false;
11136 case elfcpp::R_MIPS_CALL16
:
11137 case elfcpp::R_MIPS16_CALL16
:
11138 case elfcpp::R_MICROMIPS_CALL16
:
11139 case elfcpp::R_MIPS_CALL_HI16
:
11140 case elfcpp::R_MIPS_CALL_LO16
:
11141 case elfcpp::R_MICROMIPS_CALL_HI16
:
11142 case elfcpp::R_MICROMIPS_CALL_LO16
:
11146 case elfcpp::R_MIPS16_GOT16
:
11147 case elfcpp::R_MIPS_GOT16
:
11148 case elfcpp::R_MIPS_GOT_HI16
:
11149 case elfcpp::R_MIPS_GOT_LO16
:
11150 case elfcpp::R_MICROMIPS_GOT16
:
11151 case elfcpp::R_MICROMIPS_GOT_HI16
:
11152 case elfcpp::R_MICROMIPS_GOT_LO16
:
11153 case elfcpp::R_MIPS_GOT_DISP
:
11154 case elfcpp::R_MICROMIPS_GOT_DISP
:
11155 case elfcpp::R_MIPS_EH
:
11157 // The symbol requires a GOT entry.
11158 Mips_output_data_got
<size
, big_endian
>* got
=
11159 target
->got_section(symtab
, layout
);
11160 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
11162 mips_sym
->set_global_got_area(GGA_NORMAL
);
11166 case elfcpp::R_MIPS_GOT_PAGE
:
11167 case elfcpp::R_MICROMIPS_GOT_PAGE
:
11169 // This relocation needs a page entry in the GOT.
11170 // Get the section contents.
11171 section_size_type view_size
= 0;
11172 const unsigned char* view
=
11173 object
->section_contents(data_shndx
, &view_size
, false);
11176 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
11177 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
11179 Mips_output_data_got
<size
, big_endian
>* got
=
11180 target
->got_section(symtab
, layout
);
11181 got
->record_got_page_entry(mips_obj
, r_sym
, addend
);
11183 // If this is a global, overridable symbol, GOT_PAGE will
11184 // decay to GOT_DISP, so we'll need a GOT entry for it.
11185 bool def_regular
= (mips_sym
->source() == Symbol::FROM_OBJECT
11186 && !mips_sym
->object()->is_dynamic()
11187 && !mips_sym
->is_undefined());
11189 || (parameters
->options().output_is_position_independent()
11190 && !parameters
->options().Bsymbolic()
11191 && !mips_sym
->is_forced_local()))
11193 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
11195 mips_sym
->set_global_got_area(GGA_NORMAL
);
11200 case elfcpp::R_MIPS_TLS_GOTTPREL
:
11201 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
11202 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
11203 case elfcpp::R_MIPS_TLS_LDM
:
11204 case elfcpp::R_MIPS16_TLS_LDM
:
11205 case elfcpp::R_MICROMIPS_TLS_LDM
:
11206 case elfcpp::R_MIPS_TLS_GD
:
11207 case elfcpp::R_MIPS16_TLS_GD
:
11208 case elfcpp::R_MICROMIPS_TLS_GD
:
11210 const bool is_final
= gsym
->final_value_is_known();
11211 const tls::Tls_optimization optimized_type
=
11212 Target_mips
<size
, big_endian
>::optimize_tls_reloc(is_final
, r_type
);
11216 case elfcpp::R_MIPS_TLS_GD
:
11217 case elfcpp::R_MIPS16_TLS_GD
:
11218 case elfcpp::R_MICROMIPS_TLS_GD
:
11219 if (optimized_type
== tls::TLSOPT_NONE
)
11221 // Create a pair of GOT entries for the module index and
11222 // dtv-relative offset.
11223 Mips_output_data_got
<size
, big_endian
>* got
=
11224 target
->got_section(symtab
, layout
);
11225 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
11230 // FIXME: TLS optimization not supported yet.
11231 gold_unreachable();
11235 case elfcpp::R_MIPS_TLS_LDM
:
11236 case elfcpp::R_MIPS16_TLS_LDM
:
11237 case elfcpp::R_MICROMIPS_TLS_LDM
:
11238 if (optimized_type
== tls::TLSOPT_NONE
)
11240 // We always record LDM symbols as local with index 0.
11241 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
11247 // FIXME: TLS optimization not supported yet.
11248 gold_unreachable();
11251 case elfcpp::R_MIPS_TLS_GOTTPREL
:
11252 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
11253 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
11254 layout
->set_has_static_tls();
11255 if (optimized_type
== tls::TLSOPT_NONE
)
11257 // Create a GOT entry for the tp-relative offset.
11258 Mips_output_data_got
<size
, big_endian
>* got
=
11259 target
->got_section(symtab
, layout
);
11260 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
11265 // FIXME: TLS optimization not supported yet.
11266 gold_unreachable();
11271 gold_unreachable();
11275 case elfcpp::R_MIPS_COPY
:
11276 case elfcpp::R_MIPS_JUMP_SLOT
:
11277 // These are relocations which should only be seen by the
11278 // dynamic linker, and should never be seen here.
11279 gold_error(_("%s: unexpected reloc %u in object file"),
11280 object
->name().c_str(), r_type
);
11287 // Refuse some position-dependent relocations when creating a
11288 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
11289 // not PIC, but we can create dynamic relocations and the result
11290 // will be fine. Also do not refuse R_MIPS_LO16, which can be
11291 // combined with R_MIPS_GOT16.
11292 if (parameters
->options().shared())
11296 case elfcpp::R_MIPS16_HI16
:
11297 case elfcpp::R_MIPS_HI16
:
11298 case elfcpp::R_MIPS_HIGHER
:
11299 case elfcpp::R_MIPS_HIGHEST
:
11300 case elfcpp::R_MICROMIPS_HI16
:
11301 case elfcpp::R_MICROMIPS_HIGHER
:
11302 case elfcpp::R_MICROMIPS_HIGHEST
:
11303 // Don't refuse a high part relocation if it's against
11304 // no symbol (e.g. part of a compound relocation).
11308 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
11309 // and has a special meaning.
11310 if (!mips_obj
->is_newabi() && strcmp(gsym
->name(), "_gp_disp") == 0)
11314 case elfcpp::R_MIPS16_26
:
11315 case elfcpp::R_MIPS_26
:
11316 case elfcpp::R_MICROMIPS_26_S1
:
11317 gold_error(_("%s: relocation %u against `%s' can not be used when "
11318 "making a shared object; recompile with -fPIC"),
11319 object
->name().c_str(), r_type
, gsym
->name());
11326 template<int size
, bool big_endian
>
11328 Target_mips
<size
, big_endian
>::Scan::global(
11329 Symbol_table
* symtab
,
11331 Target_mips
<size
, big_endian
>* target
,
11332 Sized_relobj_file
<size
, big_endian
>* object
,
11333 unsigned int data_shndx
,
11334 Output_section
* output_section
,
11335 const Relatype
& reloc
,
11336 unsigned int r_type
,
11347 (const Reltype
*) NULL
,
11353 template<int size
, bool big_endian
>
11355 Target_mips
<size
, big_endian
>::Scan::global(
11356 Symbol_table
* symtab
,
11358 Target_mips
<size
, big_endian
>* target
,
11359 Sized_relobj_file
<size
, big_endian
>* object
,
11360 unsigned int data_shndx
,
11361 Output_section
* output_section
,
11362 const Reltype
& reloc
,
11363 unsigned int r_type
,
11373 (const Relatype
*) NULL
,
11380 // Return whether a R_MIPS_32/R_MIPS64 relocation needs to be applied.
11381 // In cases where Scan::local() or Scan::global() has created
11382 // a dynamic relocation, the addend of the relocation is carried
11383 // in the data, and we must not apply the static relocation.
11385 template<int size
, bool big_endian
>
11387 Target_mips
<size
, big_endian
>::Relocate::should_apply_static_reloc(
11388 const Mips_symbol
<size
>* gsym
,
11389 unsigned int r_type
,
11390 Output_section
* output_section
,
11391 Target_mips
* target
)
11393 // If the output section is not allocated, then we didn't call
11394 // scan_relocs, we didn't create a dynamic reloc, and we must apply
11396 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
11403 // For global symbols, we use the same helper routines used in the
11405 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
))
11406 && !gsym
->may_need_copy_reloc())
11408 // We have generated dynamic reloc (R_MIPS_REL32).
11410 bool multi_got
= false;
11411 if (target
->has_got_section())
11412 multi_got
= target
->got_section()->multi_got();
11413 bool has_got_offset
;
11415 has_got_offset
= gsym
->has_got_offset(GOT_TYPE_STANDARD
);
11417 has_got_offset
= gsym
->global_gotoffset() != -1U;
11418 if (!has_got_offset
)
11421 // Apply the relocation only if the symbol is in the local got.
11422 // Do not apply the relocation if the symbol is in the global
11424 return symbol_references_local(gsym
, gsym
->has_dynsym_index());
11427 // We have not generated dynamic reloc.
11432 // Perform a relocation.
11434 template<int size
, bool big_endian
>
11436 Target_mips
<size
, big_endian
>::Relocate::relocate(
11437 const Relocate_info
<size
, big_endian
>* relinfo
,
11438 unsigned int rel_type
,
11439 Target_mips
* target
,
11440 Output_section
* output_section
,
11442 const unsigned char* preloc
,
11443 const Sized_symbol
<size
>* gsym
,
11444 const Symbol_value
<size
>* psymval
,
11445 unsigned char* view
,
11446 Mips_address address
,
11449 Mips_address r_offset
;
11450 unsigned int r_sym
;
11451 unsigned int r_type
;
11452 unsigned int r_type2
;
11453 unsigned int r_type3
;
11454 unsigned char r_ssym
;
11455 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
11456 // r_offset and r_type of the next relocation is needed for resolving multiple
11457 // consecutive relocations with the same offset.
11458 Mips_address next_r_offset
= static_cast<Mips_address
>(0) - 1;
11459 unsigned int next_r_type
= elfcpp::R_MIPS_NONE
;
11461 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11462 size_t reloc_count
= shdr
.get_sh_size() / shdr
.get_sh_entsize();
11464 if (rel_type
== elfcpp::SHT_RELA
)
11466 const Relatype
rela(preloc
);
11467 r_offset
= rela
.get_r_offset();
11468 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11470 r_type
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11472 r_type2
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11473 get_r_type2(&rela
);
11474 r_type3
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11475 get_r_type3(&rela
);
11476 r_ssym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11478 r_addend
= rela
.get_r_addend();
11479 // If this is not last relocation, get r_offset and r_type of the next
11481 if (relnum
+ 1 < reloc_count
)
11483 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11484 const Relatype
next_rela(preloc
+ reloc_size
);
11485 next_r_offset
= next_rela
.get_r_offset();
11487 Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11488 get_r_type(&next_rela
);
11493 const Reltype
rel(preloc
);
11494 r_offset
= rel
.get_r_offset();
11495 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
11497 r_type
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
11500 r_type2
= elfcpp::R_MIPS_NONE
;
11501 r_type3
= elfcpp::R_MIPS_NONE
;
11503 // If this is not last relocation, get r_offset and r_type of the next
11505 if (relnum
+ 1 < reloc_count
)
11507 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rel_size
;
11508 const Reltype
next_rel(preloc
+ reloc_size
);
11509 next_r_offset
= next_rel
.get_r_offset();
11510 next_r_type
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
11511 get_r_type(&next_rel
);
11515 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
11516 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
11518 Mips_relobj
<size
, big_endian
>* object
=
11519 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
11521 bool target_is_16_bit_code
= false;
11522 bool target_is_micromips_code
= false;
11523 bool cross_mode_jump
;
11525 Symbol_value
<size
> symval
;
11527 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
11529 bool changed_symbol_value
= false;
11532 target_is_16_bit_code
= object
->local_symbol_is_mips16(r_sym
);
11533 target_is_micromips_code
= object
->local_symbol_is_micromips(r_sym
);
11534 if (target_is_16_bit_code
|| target_is_micromips_code
)
11536 // MIPS16/microMIPS text labels should be treated as odd.
11537 symval
.set_output_value(psymval
->value(object
, 1));
11539 changed_symbol_value
= true;
11544 target_is_16_bit_code
= mips_sym
->is_mips16();
11545 target_is_micromips_code
= mips_sym
->is_micromips();
11547 // If this is a mips16/microMIPS text symbol, add 1 to the value to make
11548 // it odd. This will cause something like .word SYM to come up with
11549 // the right value when it is loaded into the PC.
11551 if ((mips_sym
->is_mips16() || mips_sym
->is_micromips())
11552 && psymval
->value(object
, 0) != 0)
11554 symval
.set_output_value(psymval
->value(object
, 0) | 1);
11556 changed_symbol_value
= true;
11559 // Pick the value to use for symbols defined in shared objects.
11560 if (mips_sym
->use_plt_offset(Scan::get_reference_flags(r_type
))
11561 || mips_sym
->has_lazy_stub())
11563 Mips_address value
;
11564 if (!mips_sym
->has_lazy_stub())
11566 // Prefer a standard MIPS PLT entry.
11567 if (mips_sym
->has_mips_plt_offset())
11569 value
= target
->plt_section()->mips_entry_address(mips_sym
);
11570 target_is_micromips_code
= false;
11571 target_is_16_bit_code
= false;
11575 value
= (target
->plt_section()->comp_entry_address(mips_sym
)
11577 if (target
->is_output_micromips())
11578 target_is_micromips_code
= true;
11580 target_is_16_bit_code
= true;
11584 value
= target
->mips_stubs_section()->stub_address(mips_sym
);
11586 symval
.set_output_value(value
);
11591 // TRUE if the symbol referred to by this relocation is "_gp_disp".
11592 // Note that such a symbol must always be a global symbol.
11593 bool gp_disp
= (gsym
!= NULL
&& (strcmp(gsym
->name(), "_gp_disp") == 0)
11594 && !object
->is_newabi());
11596 // TRUE if the symbol referred to by this relocation is "__gnu_local_gp".
11597 // Note that such a symbol must always be a global symbol.
11598 bool gnu_local_gp
= gsym
&& (strcmp(gsym
->name(), "__gnu_local_gp") == 0);
11603 if (!hi16_reloc(r_type
) && !lo16_reloc(r_type
))
11604 gold_error_at_location(relinfo
, relnum
, r_offset
,
11605 _("relocations against _gp_disp are permitted only"
11606 " with R_MIPS_HI16 and R_MIPS_LO16 relocations."));
11608 else if (gnu_local_gp
)
11610 // __gnu_local_gp is _gp symbol.
11611 symval
.set_output_value(target
->adjusted_gp_value(object
));
11615 // If this is a reference to a 16-bit function with a stub, we need
11616 // to redirect the relocation to the stub unless:
11618 // (a) the relocation is for a MIPS16 JAL;
11620 // (b) the relocation is for a MIPS16 PIC call, and there are no
11621 // non-MIPS16 uses of the GOT slot; or
11623 // (c) the section allows direct references to MIPS16 functions.
11624 if (r_type
!= elfcpp::R_MIPS16_26
11625 && ((mips_sym
!= NULL
11626 && mips_sym
->has_mips16_fn_stub()
11627 && (r_type
!= elfcpp::R_MIPS16_CALL16
|| mips_sym
->need_fn_stub()))
11628 || (mips_sym
== NULL
11629 && object
->get_local_mips16_fn_stub(r_sym
) != NULL
))
11630 && !object
->section_allows_mips16_refs(relinfo
->data_shndx
))
11632 // This is a 32- or 64-bit call to a 16-bit function. We should
11633 // have already noticed that we were going to need the
11635 Mips_address value
;
11636 if (mips_sym
== NULL
)
11637 value
= object
->get_local_mips16_fn_stub(r_sym
)->output_address();
11640 gold_assert(mips_sym
->need_fn_stub());
11641 if (mips_sym
->has_la25_stub())
11642 value
= target
->la25_stub_section()->stub_address(mips_sym
);
11645 value
= mips_sym
->template
11646 get_mips16_fn_stub
<big_endian
>()->output_address();
11649 symval
.set_output_value(value
);
11651 changed_symbol_value
= true;
11653 // The target is 16-bit, but the stub isn't.
11654 target_is_16_bit_code
= false;
11656 // If this is a MIPS16 call with a stub, that is made through the PLT or
11657 // to a standard MIPS function, we need to redirect the call to the stub.
11658 // Note that we specifically exclude R_MIPS16_CALL16 from this behavior;
11659 // indirect calls should use an indirect stub instead.
11660 else if (r_type
== elfcpp::R_MIPS16_26
11661 && ((mips_sym
!= NULL
11662 && (mips_sym
->has_mips16_call_stub()
11663 || mips_sym
->has_mips16_call_fp_stub()))
11664 || (mips_sym
== NULL
11665 && object
->get_local_mips16_call_stub(r_sym
) != NULL
))
11666 && ((mips_sym
!= NULL
&& mips_sym
->has_plt_offset())
11667 || !target_is_16_bit_code
))
11669 Mips16_stub_section
<size
, big_endian
>* call_stub
;
11670 if (mips_sym
== NULL
)
11671 call_stub
= object
->get_local_mips16_call_stub(r_sym
);
11674 // If both call_stub and call_fp_stub are defined, we can figure
11675 // out which one to use by checking which one appears in the input
11677 if (mips_sym
->has_mips16_call_stub()
11678 && mips_sym
->has_mips16_call_fp_stub())
11681 for (unsigned int i
= 1; i
< object
->shnum(); ++i
)
11683 if (object
->is_mips16_call_fp_stub_section(i
))
11685 call_stub
= mips_sym
->template
11686 get_mips16_call_fp_stub
<big_endian
>();
11691 if (call_stub
== NULL
)
11693 mips_sym
->template get_mips16_call_stub
<big_endian
>();
11695 else if (mips_sym
->has_mips16_call_stub())
11696 call_stub
= mips_sym
->template get_mips16_call_stub
<big_endian
>();
11698 call_stub
= mips_sym
->template get_mips16_call_fp_stub
<big_endian
>();
11701 symval
.set_output_value(call_stub
->output_address());
11703 changed_symbol_value
= true;
11705 // If this is a direct call to a PIC function, redirect to the
11707 else if (mips_sym
!= NULL
11708 && mips_sym
->has_la25_stub()
11709 && relocation_needs_la25_stub
<size
, big_endian
>(
11710 object
, r_type
, target_is_16_bit_code
))
11712 Mips_address value
= target
->la25_stub_section()->stub_address(mips_sym
);
11713 if (mips_sym
->is_micromips())
11715 symval
.set_output_value(value
);
11718 // For direct MIPS16 and microMIPS calls make sure the compressed PLT
11719 // entry is used if a standard PLT entry has also been made.
11720 else if ((r_type
== elfcpp::R_MIPS16_26
11721 || r_type
== elfcpp::R_MICROMIPS_26_S1
)
11722 && mips_sym
!= NULL
11723 && mips_sym
->has_plt_offset()
11724 && mips_sym
->has_comp_plt_offset()
11725 && mips_sym
->has_mips_plt_offset())
11727 Mips_address value
= (target
->plt_section()->comp_entry_address(mips_sym
)
11729 symval
.set_output_value(value
);
11732 target_is_16_bit_code
= !target
->is_output_micromips();
11733 target_is_micromips_code
= target
->is_output_micromips();
11736 // Make sure MIPS16 and microMIPS are not used together.
11737 if ((r_type
== elfcpp::R_MIPS16_26
&& target_is_micromips_code
)
11738 || (micromips_branch_reloc(r_type
) && target_is_16_bit_code
))
11740 gold_error(_("MIPS16 and microMIPS functions cannot call each other"));
11743 // Calls from 16-bit code to 32-bit code and vice versa require the
11744 // mode change. However, we can ignore calls to undefined weak symbols,
11745 // which should never be executed at runtime. This exception is important
11746 // because the assembly writer may have "known" that any definition of the
11747 // symbol would be 16-bit code, and that direct jumps were therefore
11750 (!(gsym
!= NULL
&& gsym
->is_weak_undefined())
11751 && ((r_type
== elfcpp::R_MIPS16_26
&& !target_is_16_bit_code
)
11752 || (r_type
== elfcpp::R_MICROMIPS_26_S1
&& !target_is_micromips_code
)
11753 || ((r_type
== elfcpp::R_MIPS_26
|| r_type
== elfcpp::R_MIPS_JALR
)
11754 && (target_is_16_bit_code
|| target_is_micromips_code
))));
11756 bool local
= (mips_sym
== NULL
11757 || (mips_sym
->got_only_for_calls()
11758 ? symbol_calls_local(mips_sym
, mips_sym
->has_dynsym_index())
11759 : symbol_references_local(mips_sym
,
11760 mips_sym
->has_dynsym_index())));
11762 // Global R_MIPS_GOT_PAGE/R_MICROMIPS_GOT_PAGE relocations are equivalent
11763 // to R_MIPS_GOT_DISP/R_MICROMIPS_GOT_DISP. The addend is applied by the
11764 // corresponding R_MIPS_GOT_OFST/R_MICROMIPS_GOT_OFST.
11765 if (got_page_reloc(r_type
) && !local
)
11766 r_type
= (micromips_reloc(r_type
) ? elfcpp::R_MICROMIPS_GOT_DISP
11767 : elfcpp::R_MIPS_GOT_DISP
);
11769 unsigned int got_offset
= 0;
11772 // Whether we have to extract addend from instruction.
11773 bool extract_addend
= rel_type
== elfcpp::SHT_REL
;
11774 unsigned int r_types
[3] = { r_type
, r_type2
, r_type3
};
11776 Reloc_funcs::mips_reloc_unshuffle(view
, r_type
, false);
11778 // For Mips64 N64 ABI, there may be up to three operations specified per
11779 // record, by the fields r_type, r_type2, and r_type3. The first operation
11780 // takes its addend from the relocation record. Each subsequent operation
11781 // takes as its addend the result of the previous operation.
11782 // The first operation in a record which references a symbol uses the symbol
11783 // implied by r_sym. The next operation in a record which references a symbol
11784 // uses the special symbol value given by the r_ssym field. A third operation
11785 // in a record which references a symbol will assume a NULL symbol,
11786 // i.e. value zero.
11789 // Check if a record references to a symbol.
11790 for (unsigned int i
= 0; i
< 3; ++i
)
11792 if (r_types
[i
] == elfcpp::R_MIPS_NONE
)
11795 // If we didn't apply previous relocation, use its result as addend
11797 if (this->calculate_only_
)
11799 r_addend
= this->calculated_value_
;
11800 extract_addend
= false;
11803 // In the N32 and 64-bit ABIs there may be multiple consecutive
11804 // relocations for the same offset. In that case we are
11805 // supposed to treat the output of each relocation as the addend
11806 // for the next. For N64 ABI, we are checking offsets only in a
11807 // third operation in a record (r_type3).
11808 this->calculate_only_
=
11809 (object
->is_n64() && i
< 2
11810 ? r_types
[i
+1] != elfcpp::R_MIPS_NONE
11811 : (r_offset
== next_r_offset
) && (next_r_type
!= elfcpp::R_MIPS_NONE
));
11813 if (object
->is_n64())
11817 // Handle special symbol for r_type2 relocation type.
11821 symval
.set_output_value(0);
11824 symval
.set_output_value(target
->gp_value());
11827 symval
.set_output_value(object
->gp_value());
11830 symval
.set_output_value(address
);
11833 gold_unreachable();
11839 // For r_type3 symbol value is 0.
11840 symval
.set_output_value(0);
11844 bool update_got_entry
= false;
11845 switch (r_types
[i
])
11847 case elfcpp::R_MIPS_NONE
:
11849 case elfcpp::R_MIPS_16
:
11850 reloc_status
= Reloc_funcs::rel16(view
, object
, psymval
, r_addend
,
11852 this->calculate_only_
,
11853 &this->calculated_value_
);
11856 case elfcpp::R_MIPS_32
:
11857 if (should_apply_static_reloc(mips_sym
, r_types
[i
], output_section
,
11859 reloc_status
= Reloc_funcs::rel32(view
, object
, psymval
, r_addend
,
11861 this->calculate_only_
,
11862 &this->calculated_value_
);
11863 if (mips_sym
!= NULL
11864 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
11865 && mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
11867 // If mips_sym->has_mips16_fn_stub() is false, symbol value is
11868 // already updated by adding +1.
11869 if (mips_sym
->has_mips16_fn_stub())
11871 gold_assert(mips_sym
->need_fn_stub());
11872 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
11873 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
11875 symval
.set_output_value(fn_stub
->output_address());
11878 got_offset
= mips_sym
->global_gotoffset();
11879 update_got_entry
= true;
11883 case elfcpp::R_MIPS_64
:
11884 if (should_apply_static_reloc(mips_sym
, r_types
[i
], output_section
,
11886 reloc_status
= Reloc_funcs::rel64(view
, object
, psymval
, r_addend
,
11888 this->calculate_only_
,
11889 &this->calculated_value_
, false);
11890 else if (target
->is_output_n64() && r_addend
!= 0)
11891 // Only apply the addend. The static relocation was RELA, but the
11892 // dynamic relocation is REL, so we need to apply the addend.
11893 reloc_status
= Reloc_funcs::rel64(view
, object
, psymval
, r_addend
,
11895 this->calculate_only_
,
11896 &this->calculated_value_
, true);
11898 case elfcpp::R_MIPS_REL32
:
11899 gold_unreachable();
11901 case elfcpp::R_MIPS_PC32
:
11902 reloc_status
= Reloc_funcs::relpc32(view
, object
, psymval
, address
,
11903 r_addend
, extract_addend
,
11904 this->calculate_only_
,
11905 &this->calculated_value_
);
11908 case elfcpp::R_MIPS16_26
:
11909 // The calculation for R_MIPS16_26 is just the same as for an
11910 // R_MIPS_26. It's only the storage of the relocated field into
11911 // the output file that's different. So, we just fall through to the
11912 // R_MIPS_26 case here.
11913 case elfcpp::R_MIPS_26
:
11914 case elfcpp::R_MICROMIPS_26_S1
:
11915 reloc_status
= Reloc_funcs::rel26(view
, object
, psymval
, address
,
11916 gsym
== NULL
, r_addend
, extract_addend
, gsym
, cross_mode_jump
,
11917 r_types
[i
], target
->jal_to_bal(), this->calculate_only_
,
11918 &this->calculated_value_
);
11921 case elfcpp::R_MIPS_HI16
:
11922 case elfcpp::R_MIPS16_HI16
:
11923 case elfcpp::R_MICROMIPS_HI16
:
11924 if (rel_type
== elfcpp::SHT_RELA
)
11925 reloc_status
= Reloc_funcs::do_relhi16(view
, object
, psymval
,
11927 gp_disp
, r_types
[i
],
11930 this->calculate_only_
,
11931 &this->calculated_value_
);
11932 else if (rel_type
== elfcpp::SHT_REL
)
11933 reloc_status
= Reloc_funcs::relhi16(view
, object
, psymval
, r_addend
,
11934 address
, gp_disp
, r_types
[i
],
11935 r_sym
, extract_addend
);
11937 gold_unreachable();
11940 case elfcpp::R_MIPS_LO16
:
11941 case elfcpp::R_MIPS16_LO16
:
11942 case elfcpp::R_MICROMIPS_LO16
:
11943 case elfcpp::R_MICROMIPS_HI0_LO16
:
11944 reloc_status
= Reloc_funcs::rello16(target
, view
, object
, psymval
,
11945 r_addend
, extract_addend
, address
,
11946 gp_disp
, r_types
[i
], r_sym
,
11947 rel_type
, this->calculate_only_
,
11948 &this->calculated_value_
);
11951 case elfcpp::R_MIPS_LITERAL
:
11952 case elfcpp::R_MICROMIPS_LITERAL
:
11953 // Because we don't merge literal sections, we can handle this
11954 // just like R_MIPS_GPREL16. In the long run, we should merge
11955 // shared literals, and then we will need to additional work
11960 case elfcpp::R_MIPS_GPREL16
:
11961 case elfcpp::R_MIPS16_GPREL
:
11962 case elfcpp::R_MICROMIPS_GPREL7_S2
:
11963 case elfcpp::R_MICROMIPS_GPREL16
:
11964 reloc_status
= Reloc_funcs::relgprel(view
, object
, psymval
,
11965 target
->adjusted_gp_value(object
),
11966 r_addend
, extract_addend
,
11967 gsym
== NULL
, r_types
[i
],
11968 this->calculate_only_
,
11969 &this->calculated_value_
);
11972 case elfcpp::R_MIPS_PC16
:
11973 reloc_status
= Reloc_funcs::relpc16(view
, object
, psymval
, address
,
11974 r_addend
, extract_addend
,
11975 this->calculate_only_
,
11976 &this->calculated_value_
);
11979 case elfcpp::R_MIPS_PC21_S2
:
11980 reloc_status
= Reloc_funcs::relpc21(view
, object
, psymval
, address
,
11981 r_addend
, extract_addend
,
11982 this->calculate_only_
,
11983 &this->calculated_value_
);
11986 case elfcpp::R_MIPS_PC26_S2
:
11987 reloc_status
= Reloc_funcs::relpc26(view
, object
, psymval
, address
,
11988 r_addend
, extract_addend
,
11989 this->calculate_only_
,
11990 &this->calculated_value_
);
11993 case elfcpp::R_MIPS_PC18_S3
:
11994 reloc_status
= Reloc_funcs::relpc18(view
, object
, psymval
, address
,
11995 r_addend
, extract_addend
,
11996 this->calculate_only_
,
11997 &this->calculated_value_
);
12000 case elfcpp::R_MIPS_PC19_S2
:
12001 reloc_status
= Reloc_funcs::relpc19(view
, object
, psymval
, address
,
12002 r_addend
, extract_addend
,
12003 this->calculate_only_
,
12004 &this->calculated_value_
);
12007 case elfcpp::R_MIPS_PCHI16
:
12008 if (rel_type
== elfcpp::SHT_RELA
)
12009 reloc_status
= Reloc_funcs::do_relpchi16(view
, object
, psymval
,
12012 this->calculate_only_
,
12013 &this->calculated_value_
);
12014 else if (rel_type
== elfcpp::SHT_REL
)
12015 reloc_status
= Reloc_funcs::relpchi16(view
, object
, psymval
,
12016 r_addend
, address
, r_sym
,
12019 gold_unreachable();
12022 case elfcpp::R_MIPS_PCLO16
:
12023 reloc_status
= Reloc_funcs::relpclo16(view
, object
, psymval
, r_addend
,
12024 extract_addend
, address
, r_sym
,
12025 rel_type
, this->calculate_only_
,
12026 &this->calculated_value_
);
12028 case elfcpp::R_MICROMIPS_PC7_S1
:
12029 reloc_status
= Reloc_funcs::relmicromips_pc7_s1(view
, object
, psymval
,
12032 this->calculate_only_
,
12033 &this->calculated_value_
);
12035 case elfcpp::R_MICROMIPS_PC10_S1
:
12036 reloc_status
= Reloc_funcs::relmicromips_pc10_s1(view
, object
,
12038 r_addend
, extract_addend
,
12039 this->calculate_only_
,
12040 &this->calculated_value_
);
12042 case elfcpp::R_MICROMIPS_PC16_S1
:
12043 reloc_status
= Reloc_funcs::relmicromips_pc16_s1(view
, object
,
12045 r_addend
, extract_addend
,
12046 this->calculate_only_
,
12047 &this->calculated_value_
);
12049 case elfcpp::R_MIPS_GPREL32
:
12050 reloc_status
= Reloc_funcs::relgprel32(view
, object
, psymval
,
12051 target
->adjusted_gp_value(object
),
12052 r_addend
, extract_addend
,
12053 this->calculate_only_
,
12054 &this->calculated_value_
);
12056 case elfcpp::R_MIPS_GOT_HI16
:
12057 case elfcpp::R_MIPS_CALL_HI16
:
12058 case elfcpp::R_MICROMIPS_GOT_HI16
:
12059 case elfcpp::R_MICROMIPS_CALL_HI16
:
12061 got_offset
= target
->got_section()->got_offset(gsym
,
12065 got_offset
= target
->got_section()->got_offset(r_sym
,
12068 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12069 reloc_status
= Reloc_funcs::relgot_hi16(view
, gp_offset
,
12070 this->calculate_only_
,
12071 &this->calculated_value_
);
12072 update_got_entry
= changed_symbol_value
;
12075 case elfcpp::R_MIPS_GOT_LO16
:
12076 case elfcpp::R_MIPS_CALL_LO16
:
12077 case elfcpp::R_MICROMIPS_GOT_LO16
:
12078 case elfcpp::R_MICROMIPS_CALL_LO16
:
12080 got_offset
= target
->got_section()->got_offset(gsym
,
12084 got_offset
= target
->got_section()->got_offset(r_sym
,
12087 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12088 reloc_status
= Reloc_funcs::relgot_lo16(view
, gp_offset
,
12089 this->calculate_only_
,
12090 &this->calculated_value_
);
12091 update_got_entry
= changed_symbol_value
;
12094 case elfcpp::R_MIPS_GOT_DISP
:
12095 case elfcpp::R_MICROMIPS_GOT_DISP
:
12096 case elfcpp::R_MIPS_EH
:
12098 got_offset
= target
->got_section()->got_offset(gsym
,
12102 got_offset
= target
->got_section()->got_offset(r_sym
,
12105 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12106 if (eh_reloc(r_types
[i
]))
12107 reloc_status
= Reloc_funcs::releh(view
, gp_offset
,
12108 this->calculate_only_
,
12109 &this->calculated_value_
);
12111 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12112 this->calculate_only_
,
12113 &this->calculated_value_
);
12115 case elfcpp::R_MIPS_CALL16
:
12116 case elfcpp::R_MIPS16_CALL16
:
12117 case elfcpp::R_MICROMIPS_CALL16
:
12118 gold_assert(gsym
!= NULL
);
12119 got_offset
= target
->got_section()->got_offset(gsym
,
12122 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12123 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12124 this->calculate_only_
,
12125 &this->calculated_value_
);
12126 // TODO(sasa): We should also initialize update_got_entry
12127 // in other place swhere relgot is called.
12128 update_got_entry
= changed_symbol_value
;
12131 case elfcpp::R_MIPS_GOT16
:
12132 case elfcpp::R_MIPS16_GOT16
:
12133 case elfcpp::R_MICROMIPS_GOT16
:
12136 got_offset
= target
->got_section()->got_offset(gsym
,
12139 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12140 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12141 this->calculate_only_
,
12142 &this->calculated_value_
);
12146 if (rel_type
== elfcpp::SHT_RELA
)
12147 reloc_status
= Reloc_funcs::do_relgot16_local(view
, object
,
12151 this->calculate_only_
,
12152 &this->calculated_value_
);
12153 else if (rel_type
== elfcpp::SHT_REL
)
12154 reloc_status
= Reloc_funcs::relgot16_local(view
, object
,
12157 r_types
[i
], r_sym
);
12159 gold_unreachable();
12161 update_got_entry
= changed_symbol_value
;
12164 case elfcpp::R_MIPS_TLS_GD
:
12165 case elfcpp::R_MIPS16_TLS_GD
:
12166 case elfcpp::R_MICROMIPS_TLS_GD
:
12168 got_offset
= target
->got_section()->got_offset(gsym
,
12172 got_offset
= target
->got_section()->got_offset(r_sym
,
12175 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12176 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12177 this->calculate_only_
,
12178 &this->calculated_value_
);
12181 case elfcpp::R_MIPS_TLS_GOTTPREL
:
12182 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
12183 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
12185 got_offset
= target
->got_section()->got_offset(gsym
,
12186 GOT_TYPE_TLS_OFFSET
,
12189 got_offset
= target
->got_section()->got_offset(r_sym
,
12190 GOT_TYPE_TLS_OFFSET
,
12192 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12193 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12194 this->calculate_only_
,
12195 &this->calculated_value_
);
12198 case elfcpp::R_MIPS_TLS_LDM
:
12199 case elfcpp::R_MIPS16_TLS_LDM
:
12200 case elfcpp::R_MICROMIPS_TLS_LDM
:
12201 // Relocate the field with the offset of the GOT entry for
12202 // the module index.
12203 got_offset
= target
->got_section()->tls_ldm_offset(object
);
12204 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12205 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12206 this->calculate_only_
,
12207 &this->calculated_value_
);
12210 case elfcpp::R_MIPS_GOT_PAGE
:
12211 case elfcpp::R_MICROMIPS_GOT_PAGE
:
12212 reloc_status
= Reloc_funcs::relgotpage(target
, view
, object
, psymval
,
12213 r_addend
, extract_addend
,
12214 this->calculate_only_
,
12215 &this->calculated_value_
);
12218 case elfcpp::R_MIPS_GOT_OFST
:
12219 case elfcpp::R_MICROMIPS_GOT_OFST
:
12220 reloc_status
= Reloc_funcs::relgotofst(target
, view
, object
, psymval
,
12221 r_addend
, extract_addend
,
12222 local
, this->calculate_only_
,
12223 &this->calculated_value_
);
12226 case elfcpp::R_MIPS_JALR
:
12227 case elfcpp::R_MICROMIPS_JALR
:
12228 // This relocation is only a hint. In some cases, we optimize
12229 // it into a bal instruction. But we don't try to optimize
12230 // when the symbol does not resolve locally.
12232 || symbol_calls_local(gsym
, gsym
->has_dynsym_index()))
12233 reloc_status
= Reloc_funcs::reljalr(view
, object
, psymval
, address
,
12234 r_addend
, extract_addend
,
12235 cross_mode_jump
, r_types
[i
],
12236 target
->jalr_to_bal(),
12238 this->calculate_only_
,
12239 &this->calculated_value_
);
12242 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
12243 case elfcpp::R_MIPS16_TLS_DTPREL_HI16
:
12244 case elfcpp::R_MICROMIPS_TLS_DTPREL_HI16
:
12245 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
12246 elfcpp::DTP_OFFSET
, r_addend
,
12248 this->calculate_only_
,
12249 &this->calculated_value_
);
12251 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
12252 case elfcpp::R_MIPS16_TLS_DTPREL_LO16
:
12253 case elfcpp::R_MICROMIPS_TLS_DTPREL_LO16
:
12254 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
12255 elfcpp::DTP_OFFSET
, r_addend
,
12257 this->calculate_only_
,
12258 &this->calculated_value_
);
12260 case elfcpp::R_MIPS_TLS_DTPREL32
:
12261 case elfcpp::R_MIPS_TLS_DTPREL64
:
12262 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
12263 elfcpp::DTP_OFFSET
, r_addend
,
12265 this->calculate_only_
,
12266 &this->calculated_value_
);
12268 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
12269 case elfcpp::R_MIPS16_TLS_TPREL_HI16
:
12270 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
12271 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
12272 elfcpp::TP_OFFSET
, r_addend
,
12274 this->calculate_only_
,
12275 &this->calculated_value_
);
12277 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
12278 case elfcpp::R_MIPS16_TLS_TPREL_LO16
:
12279 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
12280 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
12281 elfcpp::TP_OFFSET
, r_addend
,
12283 this->calculate_only_
,
12284 &this->calculated_value_
);
12286 case elfcpp::R_MIPS_TLS_TPREL32
:
12287 case elfcpp::R_MIPS_TLS_TPREL64
:
12288 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
12289 elfcpp::TP_OFFSET
, r_addend
,
12291 this->calculate_only_
,
12292 &this->calculated_value_
);
12294 case elfcpp::R_MIPS_SUB
:
12295 case elfcpp::R_MICROMIPS_SUB
:
12296 reloc_status
= Reloc_funcs::relsub(view
, object
, psymval
, r_addend
,
12298 this->calculate_only_
,
12299 &this->calculated_value_
);
12301 case elfcpp::R_MIPS_HIGHER
:
12302 case elfcpp::R_MICROMIPS_HIGHER
:
12303 reloc_status
= Reloc_funcs::relhigher(view
, object
, psymval
, r_addend
,
12305 this->calculate_only_
,
12306 &this->calculated_value_
);
12308 case elfcpp::R_MIPS_HIGHEST
:
12309 case elfcpp::R_MICROMIPS_HIGHEST
:
12310 reloc_status
= Reloc_funcs::relhighest(view
, object
, psymval
,
12311 r_addend
, extract_addend
,
12312 this->calculate_only_
,
12313 &this->calculated_value_
);
12316 gold_error_at_location(relinfo
, relnum
, r_offset
,
12317 _("unsupported reloc %u"), r_types
[i
]);
12321 if (update_got_entry
)
12323 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
12324 if (mips_sym
!= NULL
&& mips_sym
->get_applied_secondary_got_fixup())
12325 got
->update_got_entry(got
->get_primary_got_offset(mips_sym
),
12326 psymval
->value(object
, 0));
12328 got
->update_got_entry(got_offset
, psymval
->value(object
, 0));
12332 bool jal_shuffle
= jal_reloc(r_type
);
12333 Reloc_funcs::mips_reloc_shuffle(view
, r_type
, jal_shuffle
);
12335 // Report any errors.
12336 switch (reloc_status
)
12338 case Reloc_funcs::STATUS_OKAY
:
12340 case Reloc_funcs::STATUS_OVERFLOW
:
12342 gold_error_at_location(relinfo
, relnum
, r_offset
,
12343 _("relocation overflow: "
12344 "%u against local symbol %u in %s"),
12345 r_type
, r_sym
, object
->name().c_str());
12346 else if (gsym
->is_defined() && gsym
->source() == Symbol::FROM_OBJECT
)
12347 gold_error_at_location(relinfo
, relnum
, r_offset
,
12348 _("relocation overflow: "
12349 "%u against '%s' defined in %s"),
12350 r_type
, gsym
->demangled_name().c_str(),
12351 gsym
->object()->name().c_str());
12353 gold_error_at_location(relinfo
, relnum
, r_offset
,
12354 _("relocation overflow: %u against '%s'"),
12355 r_type
, gsym
->demangled_name().c_str());
12357 case Reloc_funcs::STATUS_BAD_RELOC
:
12358 gold_error_at_location(relinfo
, relnum
, r_offset
,
12359 _("unexpected opcode while processing relocation"));
12361 case Reloc_funcs::STATUS_PCREL_UNALIGNED
:
12362 gold_error_at_location(relinfo
, relnum
, r_offset
,
12363 _("unaligned PC-relative relocation"));
12366 gold_unreachable();
12372 // Get the Reference_flags for a particular relocation.
12374 template<int size
, bool big_endian
>
12376 Target_mips
<size
, big_endian
>::Scan::get_reference_flags(
12377 unsigned int r_type
)
12381 case elfcpp::R_MIPS_NONE
:
12382 // No symbol reference.
12385 case elfcpp::R_MIPS_16
:
12386 case elfcpp::R_MIPS_32
:
12387 case elfcpp::R_MIPS_64
:
12388 case elfcpp::R_MIPS_HI16
:
12389 case elfcpp::R_MIPS_LO16
:
12390 case elfcpp::R_MIPS_HIGHER
:
12391 case elfcpp::R_MIPS_HIGHEST
:
12392 case elfcpp::R_MIPS16_HI16
:
12393 case elfcpp::R_MIPS16_LO16
:
12394 case elfcpp::R_MICROMIPS_HI16
:
12395 case elfcpp::R_MICROMIPS_LO16
:
12396 case elfcpp::R_MICROMIPS_HIGHER
:
12397 case elfcpp::R_MICROMIPS_HIGHEST
:
12398 return Symbol::ABSOLUTE_REF
;
12400 case elfcpp::R_MIPS_26
:
12401 case elfcpp::R_MIPS16_26
:
12402 case elfcpp::R_MICROMIPS_26_S1
:
12403 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
12405 case elfcpp::R_MIPS_PC18_S3
:
12406 case elfcpp::R_MIPS_PC19_S2
:
12407 case elfcpp::R_MIPS_PCHI16
:
12408 case elfcpp::R_MIPS_PCLO16
:
12409 case elfcpp::R_MIPS_GPREL32
:
12410 case elfcpp::R_MIPS_GPREL16
:
12411 case elfcpp::R_MIPS_REL32
:
12412 case elfcpp::R_MIPS16_GPREL
:
12413 return Symbol::RELATIVE_REF
;
12415 case elfcpp::R_MIPS_PC16
:
12416 case elfcpp::R_MIPS_PC32
:
12417 case elfcpp::R_MIPS_PC21_S2
:
12418 case elfcpp::R_MIPS_PC26_S2
:
12419 case elfcpp::R_MIPS_JALR
:
12420 case elfcpp::R_MICROMIPS_JALR
:
12421 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
12423 case elfcpp::R_MIPS_GOT16
:
12424 case elfcpp::R_MIPS_CALL16
:
12425 case elfcpp::R_MIPS_GOT_DISP
:
12426 case elfcpp::R_MIPS_GOT_HI16
:
12427 case elfcpp::R_MIPS_GOT_LO16
:
12428 case elfcpp::R_MIPS_CALL_HI16
:
12429 case elfcpp::R_MIPS_CALL_LO16
:
12430 case elfcpp::R_MIPS_LITERAL
:
12431 case elfcpp::R_MIPS_GOT_PAGE
:
12432 case elfcpp::R_MIPS_GOT_OFST
:
12433 case elfcpp::R_MIPS16_GOT16
:
12434 case elfcpp::R_MIPS16_CALL16
:
12435 case elfcpp::R_MICROMIPS_GOT16
:
12436 case elfcpp::R_MICROMIPS_CALL16
:
12437 case elfcpp::R_MICROMIPS_GOT_HI16
:
12438 case elfcpp::R_MICROMIPS_GOT_LO16
:
12439 case elfcpp::R_MICROMIPS_CALL_HI16
:
12440 case elfcpp::R_MICROMIPS_CALL_LO16
:
12441 case elfcpp::R_MIPS_EH
:
12442 // Absolute in GOT.
12443 return Symbol::RELATIVE_REF
;
12445 case elfcpp::R_MIPS_TLS_DTPMOD32
:
12446 case elfcpp::R_MIPS_TLS_DTPREL32
:
12447 case elfcpp::R_MIPS_TLS_DTPMOD64
:
12448 case elfcpp::R_MIPS_TLS_DTPREL64
:
12449 case elfcpp::R_MIPS_TLS_GD
:
12450 case elfcpp::R_MIPS_TLS_LDM
:
12451 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
12452 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
12453 case elfcpp::R_MIPS_TLS_GOTTPREL
:
12454 case elfcpp::R_MIPS_TLS_TPREL32
:
12455 case elfcpp::R_MIPS_TLS_TPREL64
:
12456 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
12457 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
12458 case elfcpp::R_MIPS16_TLS_GD
:
12459 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
12460 case elfcpp::R_MICROMIPS_TLS_GD
:
12461 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
12462 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
12463 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
12464 return Symbol::TLS_REF
;
12466 case elfcpp::R_MIPS_COPY
:
12467 case elfcpp::R_MIPS_JUMP_SLOT
:
12469 // Not expected. We will give an error later.
12474 // Report an unsupported relocation against a local symbol.
12476 template<int size
, bool big_endian
>
12478 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_local(
12479 Sized_relobj_file
<size
, big_endian
>* object
,
12480 unsigned int r_type
)
12482 gold_error(_("%s: unsupported reloc %u against local symbol"),
12483 object
->name().c_str(), r_type
);
12486 // Report an unsupported relocation against a global symbol.
12488 template<int size
, bool big_endian
>
12490 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_global(
12491 Sized_relobj_file
<size
, big_endian
>* object
,
12492 unsigned int r_type
,
12495 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
12496 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
12499 // Return printable name for ABI.
12500 template<int size
, bool big_endian
>
12502 Target_mips
<size
, big_endian
>::elf_mips_abi_name(elfcpp::Elf_Word e_flags
)
12504 switch (e_flags
& elfcpp::EF_MIPS_ABI
)
12507 if ((e_flags
& elfcpp::EF_MIPS_ABI2
) != 0)
12509 else if (size
== 64)
12513 case elfcpp::E_MIPS_ABI_O32
:
12515 case elfcpp::E_MIPS_ABI_O64
:
12517 case elfcpp::E_MIPS_ABI_EABI32
:
12519 case elfcpp::E_MIPS_ABI_EABI64
:
12522 return "unknown abi";
12526 template<int size
, bool big_endian
>
12528 Target_mips
<size
, big_endian
>::elf_mips_mach_name(elfcpp::Elf_Word e_flags
)
12530 switch (e_flags
& elfcpp::EF_MIPS_MACH
)
12532 case elfcpp::E_MIPS_MACH_3900
:
12533 return "mips:3900";
12534 case elfcpp::E_MIPS_MACH_4010
:
12535 return "mips:4010";
12536 case elfcpp::E_MIPS_MACH_4100
:
12537 return "mips:4100";
12538 case elfcpp::E_MIPS_MACH_4111
:
12539 return "mips:4111";
12540 case elfcpp::E_MIPS_MACH_4120
:
12541 return "mips:4120";
12542 case elfcpp::E_MIPS_MACH_4650
:
12543 return "mips:4650";
12544 case elfcpp::E_MIPS_MACH_5400
:
12545 return "mips:5400";
12546 case elfcpp::E_MIPS_MACH_5500
:
12547 return "mips:5500";
12548 case elfcpp::E_MIPS_MACH_5900
:
12549 return "mips:5900";
12550 case elfcpp::E_MIPS_MACH_SB1
:
12552 case elfcpp::E_MIPS_MACH_9000
:
12553 return "mips:9000";
12554 case elfcpp::E_MIPS_MACH_LS2E
:
12555 return "mips:loongson_2e";
12556 case elfcpp::E_MIPS_MACH_LS2F
:
12557 return "mips:loongson_2f";
12558 case elfcpp::E_MIPS_MACH_LS3A
:
12559 return "mips:loongson_3a";
12560 case elfcpp::E_MIPS_MACH_OCTEON
:
12561 return "mips:octeon";
12562 case elfcpp::E_MIPS_MACH_OCTEON2
:
12563 return "mips:octeon2";
12564 case elfcpp::E_MIPS_MACH_OCTEON3
:
12565 return "mips:octeon3";
12566 case elfcpp::E_MIPS_MACH_XLR
:
12569 switch (e_flags
& elfcpp::EF_MIPS_ARCH
)
12572 case elfcpp::E_MIPS_ARCH_1
:
12573 return "mips:3000";
12575 case elfcpp::E_MIPS_ARCH_2
:
12576 return "mips:6000";
12578 case elfcpp::E_MIPS_ARCH_3
:
12579 return "mips:4000";
12581 case elfcpp::E_MIPS_ARCH_4
:
12582 return "mips:8000";
12584 case elfcpp::E_MIPS_ARCH_5
:
12585 return "mips:mips5";
12587 case elfcpp::E_MIPS_ARCH_32
:
12588 return "mips:isa32";
12590 case elfcpp::E_MIPS_ARCH_64
:
12591 return "mips:isa64";
12593 case elfcpp::E_MIPS_ARCH_32R2
:
12594 return "mips:isa32r2";
12596 case elfcpp::E_MIPS_ARCH_32R6
:
12597 return "mips:isa32r6";
12599 case elfcpp::E_MIPS_ARCH_64R2
:
12600 return "mips:isa64r2";
12602 case elfcpp::E_MIPS_ARCH_64R6
:
12603 return "mips:isa64r6";
12606 return "unknown CPU";
12609 template<int size
, bool big_endian
>
12610 const Target::Target_info Target_mips
<size
, big_endian
>::mips_info
=
12613 big_endian
, // is_big_endian
12614 elfcpp::EM_MIPS
, // machine_code
12615 true, // has_make_symbol
12616 false, // has_resolve
12617 false, // has_code_fill
12618 true, // is_default_stack_executable
12619 false, // can_icf_inline_merge_sections
12621 size
== 32 ? "/lib/ld.so.1" : "/lib64/ld.so.1", // dynamic_linker
12622 0x400000, // default_text_segment_address
12623 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
12624 4 * 1024, // common_pagesize (overridable by -z common-page-size)
12625 false, // isolate_execinstr
12626 0, // rosegment_gap
12627 elfcpp::SHN_UNDEF
, // small_common_shndx
12628 elfcpp::SHN_UNDEF
, // large_common_shndx
12629 0, // small_common_section_flags
12630 0, // large_common_section_flags
12631 NULL
, // attributes_section
12632 NULL
, // attributes_vendor
12633 "__start", // entry_symbol_name
12634 32, // hash_entry_size
12635 elfcpp::SHT_PROGBITS
, // unwind_section_type
12638 template<int size
, bool big_endian
>
12639 class Target_mips_nacl
: public Target_mips
<size
, big_endian
>
12643 : Target_mips
<size
, big_endian
>(&mips_nacl_info
)
12647 static const Target::Target_info mips_nacl_info
;
12650 template<int size
, bool big_endian
>
12651 const Target::Target_info Target_mips_nacl
<size
, big_endian
>::mips_nacl_info
=
12654 big_endian
, // is_big_endian
12655 elfcpp::EM_MIPS
, // machine_code
12656 true, // has_make_symbol
12657 false, // has_resolve
12658 false, // has_code_fill
12659 true, // is_default_stack_executable
12660 false, // can_icf_inline_merge_sections
12662 "/lib/ld.so.1", // dynamic_linker
12663 0x20000, // default_text_segment_address
12664 0x10000, // abi_pagesize (overridable by -z max-page-size)
12665 0x10000, // common_pagesize (overridable by -z common-page-size)
12666 true, // isolate_execinstr
12667 0x10000000, // rosegment_gap
12668 elfcpp::SHN_UNDEF
, // small_common_shndx
12669 elfcpp::SHN_UNDEF
, // large_common_shndx
12670 0, // small_common_section_flags
12671 0, // large_common_section_flags
12672 NULL
, // attributes_section
12673 NULL
, // attributes_vendor
12674 "_start", // entry_symbol_name
12675 32, // hash_entry_size
12676 elfcpp::SHT_PROGBITS
, // unwind_section_type
12679 // Target selector for Mips. Note this is never instantiated directly.
12680 // It's only used in Target_selector_mips_nacl, below.
12682 template<int size
, bool big_endian
>
12683 class Target_selector_mips
: public Target_selector
12686 Target_selector_mips()
12687 : Target_selector(elfcpp::EM_MIPS
, size
, big_endian
,
12689 (big_endian
? "elf64-tradbigmips" : "elf64-tradlittlemips") :
12690 (big_endian
? "elf32-tradbigmips" : "elf32-tradlittlemips")),
12692 (big_endian
? "elf64btsmip" : "elf64ltsmip") :
12693 (big_endian
? "elf32btsmip" : "elf32ltsmip")))
12696 Target
* do_instantiate_target()
12697 { return new Target_mips
<size
, big_endian
>(); }
12700 template<int size
, bool big_endian
>
12701 class Target_selector_mips_nacl
12702 : public Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
12703 Target_mips_nacl
<size
, big_endian
> >
12706 Target_selector_mips_nacl()
12707 : Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
12708 Target_mips_nacl
<size
, big_endian
> >(
12709 // NaCl currently supports only MIPS32 little-endian.
12710 "mipsel", "elf32-tradlittlemips-nacl", "elf32-tradlittlemips-nacl")
12714 Target_selector_mips_nacl
<32, true> target_selector_mips32
;
12715 Target_selector_mips_nacl
<32, false> target_selector_mips32el
;
12716 Target_selector_mips_nacl
<64, true> target_selector_mips64
;
12717 Target_selector_mips_nacl
<64, false> target_selector_mips64el
;
12719 } // End anonymous namespace.