1 // mips.cc -- mips target support for gold.
3 // Copyright (C) 2011-2024 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
)
637 Got_page_entry(Object
* object_
, unsigned int symndx_
)
638 : object(object_
), symndx(symndx_
), ranges(NULL
)
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
;
649 // Hash for Got_page_entry.
651 struct Got_page_entry_hash
654 operator()(Got_page_entry
* entry
) const
655 { return reinterpret_cast<uintptr_t>(entry
->object
) + entry
->symndx
; }
658 // Equality for Got_page_entry.
660 struct Got_page_entry_eq
663 operator()(Got_page_entry
* entry1
, Got_page_entry
* entry2
) const
665 return entry1
->object
== entry2
->object
&& entry1
->symndx
== entry2
->symndx
;
669 // This class is used to hold .got information when linking.
671 template<int size
, bool big_endian
>
674 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
675 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
677 typedef Unordered_map
<unsigned int, unsigned int> Got_page_offsets
;
679 // Unordered set of GOT entries.
680 typedef Unordered_set
<Mips_got_entry
<size
, big_endian
>*,
681 Mips_got_entry_hash
<size
, big_endian
>,
682 Mips_got_entry_eq
<size
, big_endian
> > Got_entry_set
;
684 // Unordered set of GOT page entries.
685 typedef Unordered_set
<Got_page_entry
*,
686 Got_page_entry_hash
, Got_page_entry_eq
> Got_page_entry_set
;
688 // Unordered set of global GOT entries.
689 typedef Unordered_set
<Mips_symbol
<size
>*, Mips_symbol_hash
<size
> >
690 Global_got_entry_set
;
694 : local_gotno_(0), page_gotno_(0), global_gotno_(0), reloc_only_gotno_(0),
695 tls_gotno_(0), tls_ldm_offset_(-1U), global_got_symbols_(),
696 got_entries_(), got_page_entries_(), got_page_offset_start_(0),
697 got_page_offset_next_(0), got_page_offsets_(), next_(NULL
), index_(-1U),
701 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
702 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
704 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
705 unsigned int symndx
, Mips_address addend
,
706 unsigned int r_type
, unsigned int shndx
,
707 bool is_section_symbol
);
709 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
710 // in OBJECT. FOR_CALL is true if the caller is only interested in
711 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
714 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
715 Mips_relobj
<size
, big_endian
>* object
,
716 unsigned int r_type
, bool dyn_reloc
, bool for_call
);
718 // Add ENTRY to master GOT and to OBJECT's GOT.
720 record_got_entry(Mips_got_entry
<size
, big_endian
>* entry
,
721 Mips_relobj
<size
, big_endian
>* object
);
723 // Record that OBJECT has a page relocation against symbol SYMNDX and
724 // that ADDEND is the addend for that relocation.
726 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
727 unsigned int symndx
, int addend
);
729 // Create all entries that should be in the local part of the GOT.
731 add_local_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
733 // Create GOT page entries.
735 add_page_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
737 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
739 add_global_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
740 unsigned int non_reloc_only_global_gotno
);
742 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
744 add_reloc_only_entries(Mips_output_data_got
<size
, big_endian
>* got
);
746 // Create TLS GOT entries.
748 add_tls_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
750 // Decide whether the symbol needs an entry in the global part of the primary
751 // GOT, setting global_got_area accordingly. Count the number of global
752 // symbols that are in the primary GOT only because they have dynamic
753 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
755 count_got_symbols(Symbol_table
* symtab
);
757 // Return the offset of GOT page entry for VALUE.
759 get_got_page_offset(Mips_address value
,
760 Mips_output_data_got
<size
, big_endian
>* got
);
762 // Count the number of GOT entries required.
766 // Count the number of GOT entries required by ENTRY. Accumulate the result.
768 count_got_entry(Mips_got_entry
<size
, big_endian
>* entry
);
770 // Add FROM's GOT entries.
772 add_got_entries(Mips_got_info
<size
, big_endian
>* from
);
774 // Add FROM's GOT page entries.
776 add_got_page_count(Mips_got_info
<size
, big_endian
>* from
);
781 { return ((2 + this->local_gotno_
+ this->page_gotno_
+ this->global_gotno_
782 + this->tls_gotno_
) * size
/8);
785 // Return the number of local GOT entries.
788 { return this->local_gotno_
; }
790 // Return the maximum number of page GOT entries needed.
793 { return this->page_gotno_
; }
795 // Return the number of global GOT entries.
798 { return this->global_gotno_
; }
800 // Set the number of global GOT entries.
802 set_global_gotno(unsigned int global_gotno
)
803 { this->global_gotno_
= global_gotno
; }
805 // Return the number of GGA_RELOC_ONLY global GOT entries.
807 reloc_only_gotno() const
808 { return this->reloc_only_gotno_
; }
810 // Return the number of TLS GOT entries.
813 { return this->tls_gotno_
; }
815 // Return the GOT type for this GOT. Used for multi-GOT links only.
817 multigot_got_type(unsigned int got_type
) const
821 case GOT_TYPE_STANDARD
:
822 return GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
823 case GOT_TYPE_TLS_OFFSET
:
824 return GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
825 case GOT_TYPE_TLS_PAIR
:
826 return GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
832 // Remove lazy-binding stubs for global symbols in this GOT.
834 remove_lazy_stubs(Target_mips
<size
, big_endian
>* target
);
836 // Return offset of this GOT from the start of .got section.
839 { return this->offset_
; }
841 // Set offset of this GOT from the start of .got section.
843 set_offset(unsigned int offset
)
844 { this->offset_
= offset
; }
846 // Set index of this GOT in multi-GOT links.
848 set_index(unsigned int index
)
849 { this->index_
= index
; }
851 // Return next GOT in multi-GOT links.
852 Mips_got_info
<size
, big_endian
>*
854 { return this->next_
; }
856 // Set next GOT in multi-GOT links.
858 set_next(Mips_got_info
<size
, big_endian
>* next
)
859 { this->next_
= next
; }
861 // Return the offset of TLS LDM entry for this GOT.
863 tls_ldm_offset() const
864 { return this->tls_ldm_offset_
; }
866 // Set the offset of TLS LDM entry for this GOT.
868 set_tls_ldm_offset(unsigned int tls_ldm_offset
)
869 { this->tls_ldm_offset_
= tls_ldm_offset
; }
871 Global_got_entry_set
&
873 { return this->global_got_symbols_
; }
875 // Return the GOT_TLS_* type required by relocation type R_TYPE.
877 mips_elf_reloc_tls_type(unsigned int r_type
)
879 if (tls_gd_reloc(r_type
))
882 if (tls_ldm_reloc(r_type
))
885 if (tls_gottprel_reloc(r_type
))
891 // Return the number of GOT slots needed for GOT TLS type TYPE.
893 mips_tls_got_entries(unsigned int type
)
913 // The number of local GOT entries.
914 unsigned int local_gotno_
;
915 // The maximum number of page GOT entries needed.
916 unsigned int page_gotno_
;
917 // The number of global GOT entries.
918 unsigned int global_gotno_
;
919 // The number of global GOT entries that are in the GGA_RELOC_ONLY area.
920 unsigned int reloc_only_gotno_
;
921 // The number of TLS GOT entries.
922 unsigned int tls_gotno_
;
923 // The offset of TLS LDM entry for this GOT.
924 unsigned int tls_ldm_offset_
;
925 // All symbols that have global GOT entry.
926 Global_got_entry_set global_got_symbols_
;
927 // A hash table holding GOT entries.
928 Got_entry_set got_entries_
;
929 // A hash table of GOT page entries (only used in master GOT).
930 Got_page_entry_set got_page_entries_
;
931 // The offset of first GOT page entry for this GOT.
932 unsigned int got_page_offset_start_
;
933 // The offset of next available GOT page entry for this GOT.
934 unsigned int got_page_offset_next_
;
935 // A hash table that maps GOT page entry value to the GOT offset where
936 // the entry is located.
937 Got_page_offsets got_page_offsets_
;
938 // In multi-GOT links, a pointer to the next GOT.
939 Mips_got_info
<size
, big_endian
>* next_
;
940 // Index of this GOT in multi-GOT links.
942 // The offset of this GOT in multi-GOT links.
943 unsigned int offset_
;
946 // This is a helper class used during relocation scan. It records GOT16 addend.
948 template<int size
, bool big_endian
>
951 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
953 got16_addend(const Sized_relobj_file
<size
, big_endian
>* _object
,
954 unsigned int _shndx
, unsigned int _r_type
, unsigned int _r_sym
,
955 Mips_address _addend
)
956 : object(_object
), shndx(_shndx
), r_type(_r_type
), r_sym(_r_sym
),
960 const Sized_relobj_file
<size
, big_endian
>* object
;
967 // .MIPS.abiflags section content
969 template<bool big_endian
>
972 typedef typename
elfcpp::Swap
<8, big_endian
>::Valtype Valtype8
;
973 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype16
;
974 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
977 : version(0), isa_level(0), isa_rev(0), gpr_size(0), cpr1_size(0),
978 cpr2_size(0), fp_abi(0), isa_ext(0), ases(0), flags1(0), flags2(0)
981 // Version of flags structure.
983 // The level of the ISA: 1-5, 32, 64.
985 // The revision of ISA: 0 for MIPS V and below, 1-n otherwise.
987 // The size of general purpose registers.
989 // The size of co-processor 1 registers.
991 // The size of co-processor 2 registers.
993 // The floating-point ABI.
995 // Processor-specific extension.
997 // Mask of ASEs used.
999 // Mask of general flags.
1004 // Mips_symbol class. Holds additional symbol information needed for Mips.
1007 class Mips_symbol
: public Sized_symbol
<size
>
1011 : need_fn_stub_(false), has_nonpic_branches_(false), la25_stub_offset_(-1U),
1012 has_static_relocs_(false), no_lazy_stub_(false), lazy_stub_offset_(0),
1013 pointer_equality_needed_(false), global_got_area_(GGA_NONE
),
1014 global_gotoffset_(-1U), got_only_for_calls_(true), has_lazy_stub_(false),
1015 needs_mips_plt_(false), needs_comp_plt_(false), mips_plt_offset_(-1U),
1016 comp_plt_offset_(-1U), mips16_fn_stub_(NULL
), mips16_call_stub_(NULL
),
1017 mips16_call_fp_stub_(NULL
), applied_secondary_got_fixup_(false)
1020 // Return whether this is a MIPS16 symbol.
1024 // (st_other & STO_MIPS16) == STO_MIPS16
1025 return ((this->nonvis() & (elfcpp::STO_MIPS16
>> 2))
1026 == elfcpp::STO_MIPS16
>> 2);
1029 // Return whether this is a microMIPS symbol.
1031 is_micromips() const
1033 // (st_other & STO_MIPS_ISA) == STO_MICROMIPS
1034 return ((this->nonvis() & (elfcpp::STO_MIPS_ISA
>> 2))
1035 == elfcpp::STO_MICROMIPS
>> 2);
1038 // Return whether the symbol needs MIPS16 fn_stub.
1040 need_fn_stub() const
1041 { return this->need_fn_stub_
; }
1043 // Set that the symbol needs MIPS16 fn_stub.
1046 { this->need_fn_stub_
= true; }
1048 // Return whether this symbol is referenced by branch relocations from
1049 // any non-PIC input file.
1051 has_nonpic_branches() const
1052 { return this->has_nonpic_branches_
; }
1054 // Set that this symbol is referenced by branch relocations from
1055 // any non-PIC input file.
1057 set_has_nonpic_branches()
1058 { this->has_nonpic_branches_
= true; }
1060 // Return the offset of the la25 stub for this symbol from the start of the
1061 // la25 stub section.
1063 la25_stub_offset() const
1064 { return this->la25_stub_offset_
; }
1066 // Set the offset of the la25 stub for this symbol from the start of the
1067 // la25 stub section.
1069 set_la25_stub_offset(unsigned int offset
)
1070 { this->la25_stub_offset_
= offset
; }
1072 // Return whether the symbol has la25 stub. This is true if this symbol is
1073 // for a PIC function, and there are non-PIC branches and jumps to it.
1075 has_la25_stub() const
1076 { return this->la25_stub_offset_
!= -1U; }
1078 // Return whether there is a relocation against this symbol that must be
1079 // resolved by the static linker (that is, the relocation cannot possibly
1080 // be made dynamic).
1082 has_static_relocs() const
1083 { return this->has_static_relocs_
; }
1085 // Set that there is a relocation against this symbol that must be resolved
1086 // by the static linker (that is, the relocation cannot possibly be made
1089 set_has_static_relocs()
1090 { this->has_static_relocs_
= true; }
1092 // Return whether we must not create a lazy-binding stub for this symbol.
1094 no_lazy_stub() const
1095 { return this->no_lazy_stub_
; }
1097 // Set that we must not create a lazy-binding stub for this symbol.
1100 { this->no_lazy_stub_
= true; }
1102 // Return the offset of the lazy-binding stub for this symbol from the start
1103 // of .MIPS.stubs section.
1105 lazy_stub_offset() const
1106 { return this->lazy_stub_offset_
; }
1108 // Set the offset of the lazy-binding stub for this symbol from the start
1109 // of .MIPS.stubs section.
1111 set_lazy_stub_offset(unsigned int offset
)
1112 { this->lazy_stub_offset_
= offset
; }
1114 // Return whether there are any relocations for this symbol where
1115 // pointer equality matters.
1117 pointer_equality_needed() const
1118 { return this->pointer_equality_needed_
; }
1120 // Set that there are relocations for this symbol where pointer equality
1123 set_pointer_equality_needed()
1124 { this->pointer_equality_needed_
= true; }
1126 // Return global GOT area where this symbol in located.
1128 global_got_area() const
1129 { return this->global_got_area_
; }
1131 // Set global GOT area where this symbol in located.
1133 set_global_got_area(Global_got_area global_got_area
)
1134 { this->global_got_area_
= global_got_area
; }
1136 // Return the global GOT offset for this symbol. For multi-GOT links, this
1137 // returns the offset from the start of .got section to the first GOT entry
1138 // for the symbol. Note that in multi-GOT links the symbol can have entry
1139 // in more than one GOT.
1141 global_gotoffset() const
1142 { return this->global_gotoffset_
; }
1144 // Set the global GOT offset for this symbol. Note that in multi-GOT links
1145 // the symbol can have entry in more than one GOT. This method will set
1146 // the offset only if it is less than current offset.
1148 set_global_gotoffset(unsigned int offset
)
1150 if (this->global_gotoffset_
== -1U || offset
< this->global_gotoffset_
)
1151 this->global_gotoffset_
= offset
;
1154 // Return whether all GOT relocations for this symbol are for calls.
1156 got_only_for_calls() const
1157 { return this->got_only_for_calls_
; }
1159 // Set that there is a GOT relocation for this symbol that is not for call.
1161 set_got_not_only_for_calls()
1162 { this->got_only_for_calls_
= false; }
1164 // Return whether this is a PIC symbol.
1168 // (st_other & STO_MIPS_FLAGS) == STO_MIPS_PIC
1169 return ((this->nonvis() & (elfcpp::STO_MIPS_FLAGS
>> 2))
1170 == (elfcpp::STO_MIPS_PIC
>> 2));
1173 // Set the flag in st_other field that marks this symbol as PIC.
1177 if (this->is_mips16())
1178 // (st_other & ~(STO_MIPS16 | STO_MIPS_FLAGS)) | STO_MIPS_PIC
1179 this->set_nonvis((this->nonvis()
1180 & ~((elfcpp::STO_MIPS16
>> 2)
1181 | (elfcpp::STO_MIPS_FLAGS
>> 2)))
1182 | (elfcpp::STO_MIPS_PIC
>> 2));
1184 // (other & ~STO_MIPS_FLAGS) | STO_MIPS_PIC
1185 this->set_nonvis((this->nonvis() & ~(elfcpp::STO_MIPS_FLAGS
>> 2))
1186 | (elfcpp::STO_MIPS_PIC
>> 2));
1189 // Set the flag in st_other field that marks this symbol as PLT.
1193 if (this->is_mips16())
1194 // (st_other & (STO_MIPS16 | ~STO_MIPS_FLAGS)) | STO_MIPS_PLT
1195 this->set_nonvis((this->nonvis()
1196 & ((elfcpp::STO_MIPS16
>> 2)
1197 | ~(elfcpp::STO_MIPS_FLAGS
>> 2)))
1198 | (elfcpp::STO_MIPS_PLT
>> 2));
1201 // (st_other & ~STO_MIPS_FLAGS) | STO_MIPS_PLT
1202 this->set_nonvis((this->nonvis() & ~(elfcpp::STO_MIPS_FLAGS
>> 2))
1203 | (elfcpp::STO_MIPS_PLT
>> 2));
1206 // Downcast a base pointer to a Mips_symbol pointer.
1207 static Mips_symbol
<size
>*
1208 as_mips_sym(Symbol
* sym
)
1209 { return static_cast<Mips_symbol
<size
>*>(sym
); }
1211 // Downcast a base pointer to a Mips_symbol pointer.
1212 static const Mips_symbol
<size
>*
1213 as_mips_sym(const Symbol
* sym
)
1214 { return static_cast<const Mips_symbol
<size
>*>(sym
); }
1216 // Return whether the symbol has lazy-binding stub.
1218 has_lazy_stub() const
1219 { return this->has_lazy_stub_
; }
1221 // Set whether the symbol has lazy-binding stub.
1223 set_has_lazy_stub(bool has_lazy_stub
)
1224 { this->has_lazy_stub_
= has_lazy_stub
; }
1226 // Return whether the symbol needs a standard PLT entry.
1228 needs_mips_plt() const
1229 { return this->needs_mips_plt_
; }
1231 // Set whether the symbol needs a standard PLT entry.
1233 set_needs_mips_plt(bool needs_mips_plt
)
1234 { this->needs_mips_plt_
= needs_mips_plt
; }
1236 // Return whether the symbol needs a compressed (MIPS16 or microMIPS) PLT
1239 needs_comp_plt() const
1240 { return this->needs_comp_plt_
; }
1242 // Set whether the symbol needs a compressed (MIPS16 or microMIPS) PLT entry.
1244 set_needs_comp_plt(bool needs_comp_plt
)
1245 { this->needs_comp_plt_
= needs_comp_plt
; }
1247 // Return standard PLT entry offset, or -1 if none.
1249 mips_plt_offset() const
1250 { return this->mips_plt_offset_
; }
1252 // Set standard PLT entry offset.
1254 set_mips_plt_offset(unsigned int mips_plt_offset
)
1255 { this->mips_plt_offset_
= mips_plt_offset
; }
1257 // Return whether the symbol has standard PLT entry.
1259 has_mips_plt_offset() const
1260 { return this->mips_plt_offset_
!= -1U; }
1262 // Return compressed (MIPS16 or microMIPS) PLT entry offset, or -1 if none.
1264 comp_plt_offset() const
1265 { return this->comp_plt_offset_
; }
1267 // Set compressed (MIPS16 or microMIPS) PLT entry offset.
1269 set_comp_plt_offset(unsigned int comp_plt_offset
)
1270 { this->comp_plt_offset_
= comp_plt_offset
; }
1272 // Return whether the symbol has compressed (MIPS16 or microMIPS) PLT entry.
1274 has_comp_plt_offset() const
1275 { return this->comp_plt_offset_
!= -1U; }
1277 // Return MIPS16 fn stub for a symbol.
1278 template<bool big_endian
>
1279 Mips16_stub_section
<size
, big_endian
>*
1280 get_mips16_fn_stub() const
1282 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(mips16_fn_stub_
);
1285 // Set MIPS16 fn stub for a symbol.
1287 set_mips16_fn_stub(Mips16_stub_section_base
* stub
)
1288 { this->mips16_fn_stub_
= stub
; }
1290 // Return whether symbol has MIPS16 fn stub.
1292 has_mips16_fn_stub() const
1293 { return this->mips16_fn_stub_
!= NULL
; }
1295 // Return MIPS16 call stub for a symbol.
1296 template<bool big_endian
>
1297 Mips16_stub_section
<size
, big_endian
>*
1298 get_mips16_call_stub() const
1300 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(
1304 // Set MIPS16 call stub for a symbol.
1306 set_mips16_call_stub(Mips16_stub_section_base
* stub
)
1307 { this->mips16_call_stub_
= stub
; }
1309 // Return whether symbol has MIPS16 call stub.
1311 has_mips16_call_stub() const
1312 { return this->mips16_call_stub_
!= NULL
; }
1314 // Return MIPS16 call_fp stub for a symbol.
1315 template<bool big_endian
>
1316 Mips16_stub_section
<size
, big_endian
>*
1317 get_mips16_call_fp_stub() const
1319 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(
1320 mips16_call_fp_stub_
);
1323 // Set MIPS16 call_fp stub for a symbol.
1325 set_mips16_call_fp_stub(Mips16_stub_section_base
* stub
)
1326 { this->mips16_call_fp_stub_
= stub
; }
1328 // Return whether symbol has MIPS16 call_fp stub.
1330 has_mips16_call_fp_stub() const
1331 { return this->mips16_call_fp_stub_
!= NULL
; }
1334 get_applied_secondary_got_fixup() const
1335 { return applied_secondary_got_fixup_
; }
1338 set_applied_secondary_got_fixup()
1339 { this->applied_secondary_got_fixup_
= true; }
1341 // Return the hash of this symbol.
1345 return gold::string_hash
<char>(this->name());
1349 // Whether the symbol needs MIPS16 fn_stub. This is true if this symbol
1350 // appears in any relocs other than a 16 bit call.
1353 // True if this symbol is referenced by branch relocations from
1354 // any non-PIC input file. This is used to determine whether an
1355 // la25 stub is required.
1356 bool has_nonpic_branches_
;
1358 // The offset of the la25 stub for this symbol from the start of the
1359 // la25 stub section.
1360 unsigned int la25_stub_offset_
;
1362 // True if there is a relocation against this symbol that must be
1363 // resolved by the static linker (that is, the relocation cannot
1364 // possibly be made dynamic).
1365 bool has_static_relocs_
;
1367 // Whether we must not create a lazy-binding stub for this symbol.
1368 // This is true if the symbol has relocations related to taking the
1369 // function's address.
1372 // The offset of the lazy-binding stub for this symbol from the start of
1373 // .MIPS.stubs section.
1374 unsigned int lazy_stub_offset_
;
1376 // True if there are any relocations for this symbol where pointer equality
1378 bool pointer_equality_needed_
;
1380 // Global GOT area where this symbol in located, or GGA_NONE if symbol is not
1381 // in the global part of the GOT.
1382 Global_got_area global_got_area_
;
1384 // The global GOT offset for this symbol. For multi-GOT links, this is offset
1385 // from the start of .got section to the first GOT entry for the symbol.
1386 // Note that in multi-GOT links the symbol can have entry in more than one GOT.
1387 unsigned int global_gotoffset_
;
1389 // Whether all GOT relocations for this symbol are for calls.
1390 bool got_only_for_calls_
;
1391 // Whether the symbol has lazy-binding stub.
1392 bool has_lazy_stub_
;
1393 // Whether the symbol needs a standard PLT entry.
1394 bool needs_mips_plt_
;
1395 // Whether the symbol needs a compressed (MIPS16 or microMIPS) PLT entry.
1396 bool needs_comp_plt_
;
1397 // Standard PLT entry offset, or -1 if none.
1398 unsigned int mips_plt_offset_
;
1399 // Compressed (MIPS16 or microMIPS) PLT entry offset, or -1 if none.
1400 unsigned int comp_plt_offset_
;
1401 // MIPS16 fn stub for a symbol.
1402 Mips16_stub_section_base
* mips16_fn_stub_
;
1403 // MIPS16 call stub for a symbol.
1404 Mips16_stub_section_base
* mips16_call_stub_
;
1405 // MIPS16 call_fp stub for a symbol.
1406 Mips16_stub_section_base
* mips16_call_fp_stub_
;
1408 bool applied_secondary_got_fixup_
;
1411 // Mips16_stub_section class.
1413 // The mips16 compiler uses a couple of special sections to handle
1414 // floating point arguments.
1416 // Section names that look like .mips16.fn.FNNAME contain stubs that
1417 // copy floating point arguments from the fp regs to the gp regs and
1418 // then jump to FNNAME. If any 32 bit function calls FNNAME, the
1419 // call should be redirected to the stub instead. If no 32 bit
1420 // function calls FNNAME, the stub should be discarded. We need to
1421 // consider any reference to the function, not just a call, because
1422 // if the address of the function is taken we will need the stub,
1423 // since the address might be passed to a 32 bit function.
1425 // Section names that look like .mips16.call.FNNAME contain stubs
1426 // that copy floating point arguments from the gp regs to the fp
1427 // regs and then jump to FNNAME. If FNNAME is a 32 bit function,
1428 // then any 16 bit function that calls FNNAME should be redirected
1429 // to the stub instead. If FNNAME is not a 32 bit function, the
1430 // stub should be discarded.
1432 // .mips16.call.fp.FNNAME sections are similar, but contain stubs
1433 // which call FNNAME and then copy the return value from the fp regs
1434 // to the gp regs. These stubs store the return address in $18 while
1435 // calling FNNAME; any function which might call one of these stubs
1436 // must arrange to save $18 around the call. (This case is not
1437 // needed for 32 bit functions that call 16 bit functions, because
1438 // 16 bit functions always return floating point values in both
1439 // $f0/$f1 and $2/$3.)
1441 // Note that in all cases FNNAME might be defined statically.
1442 // Therefore, FNNAME is not used literally. Instead, the relocation
1443 // information will indicate which symbol the section is for.
1445 // We record any stubs that we find in the symbol table.
1447 // TODO(sasa): All mips16 stub sections should be emitted in the .text section.
1449 class Mips16_stub_section_base
{ };
1451 template<int size
, bool big_endian
>
1452 class Mips16_stub_section
: public Mips16_stub_section_base
1454 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1457 Mips16_stub_section(Mips_relobj
<size
, big_endian
>* object
, unsigned int shndx
)
1458 : object_(object
), shndx_(shndx
), r_sym_(0), gsym_(NULL
),
1459 found_r_mips_none_(false)
1461 gold_assert(object
->is_mips16_fn_stub_section(shndx
)
1462 || object
->is_mips16_call_stub_section(shndx
)
1463 || object
->is_mips16_call_fp_stub_section(shndx
));
1466 // Return the object of this stub section.
1467 Mips_relobj
<size
, big_endian
>*
1469 { return this->object_
; }
1471 // Return the size of a section.
1473 section_size() const
1474 { return this->object_
->section_size(this->shndx_
); }
1476 // Return section index of this stub section.
1479 { return this->shndx_
; }
1481 // Return symbol index, if stub is for a local function.
1484 { return this->r_sym_
; }
1486 // Return symbol, if stub is for a global function.
1489 { return this->gsym_
; }
1491 // Return whether stub is for a local function.
1493 is_for_local_function() const
1494 { return this->gsym_
== NULL
; }
1496 // This method is called when a new relocation R_TYPE for local symbol R_SYM
1497 // is found in the stub section. Try to find stub target.
1499 new_local_reloc_found(unsigned int r_type
, unsigned int r_sym
)
1501 // To find target symbol for this stub, trust the first R_MIPS_NONE
1502 // relocation, if any. Otherwise trust the first relocation, whatever
1504 if (this->found_r_mips_none_
)
1506 if (r_type
== elfcpp::R_MIPS_NONE
)
1508 this->r_sym_
= r_sym
;
1510 this->found_r_mips_none_
= true;
1512 else if (!is_target_found())
1513 this->r_sym_
= r_sym
;
1516 // This method is called when a new relocation R_TYPE for global symbol GSYM
1517 // is found in the stub section. Try to find stub target.
1519 new_global_reloc_found(unsigned int r_type
, Mips_symbol
<size
>* gsym
)
1521 // To find target symbol for this stub, trust the first R_MIPS_NONE
1522 // relocation, if any. Otherwise trust the first relocation, whatever
1524 if (this->found_r_mips_none_
)
1526 if (r_type
== elfcpp::R_MIPS_NONE
)
1530 this->found_r_mips_none_
= true;
1532 else if (!is_target_found())
1536 // Return whether we found the stub target.
1538 is_target_found() const
1539 { return this->r_sym_
!= 0 || this->gsym_
!= NULL
; }
1541 // Return whether this is a fn stub.
1544 { return this->object_
->is_mips16_fn_stub_section(this->shndx_
); }
1546 // Return whether this is a call stub.
1548 is_call_stub() const
1549 { return this->object_
->is_mips16_call_stub_section(this->shndx_
); }
1551 // Return whether this is a call_fp stub.
1553 is_call_fp_stub() const
1554 { return this->object_
->is_mips16_call_fp_stub_section(this->shndx_
); }
1556 // Return the output address.
1558 output_address() const
1560 return (this->object_
->output_section(this->shndx_
)->address()
1561 + this->object_
->output_section_offset(this->shndx_
));
1565 // The object of this stub section.
1566 Mips_relobj
<size
, big_endian
>* object_
;
1567 // The section index of this stub section.
1568 unsigned int shndx_
;
1569 // The symbol index, if stub is for a local function.
1570 unsigned int r_sym_
;
1571 // The symbol, if stub is for a global function.
1572 Mips_symbol
<size
>* gsym_
;
1573 // True if we found R_MIPS_NONE relocation in this stub.
1574 bool found_r_mips_none_
;
1577 // Mips_relobj class.
1579 template<int size
, bool big_endian
>
1580 class Mips_relobj
: public Sized_relobj_file
<size
, big_endian
>
1582 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1583 typedef std::map
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>
1584 Mips16_stubs_int_map
;
1585 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1588 Mips_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
1589 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1590 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
1591 processor_specific_flags_(0), local_symbol_is_mips16_(),
1592 local_symbol_is_micromips_(), mips16_stub_sections_(),
1593 local_non_16bit_calls_(), local_16bit_calls_(), local_mips16_fn_stubs_(),
1594 local_mips16_call_stubs_(), gp_(0), has_reginfo_section_(false),
1595 merge_processor_specific_data_(true), got_info_(NULL
),
1596 section_is_mips16_fn_stub_(), section_is_mips16_call_stub_(),
1597 section_is_mips16_call_fp_stub_(), pdr_shndx_(-1U),
1598 attributes_section_data_(NULL
), abiflags_(NULL
), gprmask_(0),
1599 cprmask1_(0), cprmask2_(0), cprmask3_(0), cprmask4_(0)
1601 this->is_pic_
= (ehdr
.get_e_flags() & elfcpp::EF_MIPS_PIC
) != 0;
1602 this->is_n32_
= elfcpp::abi_n32(ehdr
.get_e_flags());
1606 { delete this->attributes_section_data_
; }
1608 // Downcast a base pointer to a Mips_relobj pointer. This is
1609 // not type-safe but we only use Mips_relobj not the base class.
1610 static Mips_relobj
<size
, big_endian
>*
1611 as_mips_relobj(Relobj
* relobj
)
1612 { return static_cast<Mips_relobj
<size
, big_endian
>*>(relobj
); }
1614 // Downcast a base pointer to a Mips_relobj pointer. This is
1615 // not type-safe but we only use Mips_relobj not the base class.
1616 static const Mips_relobj
<size
, big_endian
>*
1617 as_mips_relobj(const Relobj
* relobj
)
1618 { return static_cast<const Mips_relobj
<size
, big_endian
>*>(relobj
); }
1620 // Processor-specific flags in ELF file header. This is valid only after
1623 processor_specific_flags() const
1624 { return this->processor_specific_flags_
; }
1626 // Whether a local symbol is MIPS16 symbol. R_SYM is the symbol table
1627 // index. This is only valid after do_count_local_symbol is called.
1629 local_symbol_is_mips16(unsigned int r_sym
) const
1631 gold_assert(r_sym
< this->local_symbol_is_mips16_
.size());
1632 return this->local_symbol_is_mips16_
[r_sym
];
1635 // Whether a local symbol is microMIPS symbol. R_SYM is the symbol table
1636 // index. This is only valid after do_count_local_symbol is called.
1638 local_symbol_is_micromips(unsigned int r_sym
) const
1640 gold_assert(r_sym
< this->local_symbol_is_micromips_
.size());
1641 return this->local_symbol_is_micromips_
[r_sym
];
1644 // Get or create MIPS16 stub section.
1645 Mips16_stub_section
<size
, big_endian
>*
1646 get_mips16_stub_section(unsigned int shndx
)
1648 typename
Mips16_stubs_int_map::const_iterator it
=
1649 this->mips16_stub_sections_
.find(shndx
);
1650 if (it
!= this->mips16_stub_sections_
.end())
1651 return (*it
).second
;
1653 Mips16_stub_section
<size
, big_endian
>* stub_section
=
1654 new Mips16_stub_section
<size
, big_endian
>(this, shndx
);
1655 this->mips16_stub_sections_
.insert(
1656 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1657 stub_section
->shndx(), stub_section
));
1658 return stub_section
;
1661 // Return MIPS16 fn stub section for local symbol R_SYM, or NULL if this
1662 // object doesn't have fn stub for R_SYM.
1663 Mips16_stub_section
<size
, big_endian
>*
1664 get_local_mips16_fn_stub(unsigned int r_sym
) const
1666 typename
Mips16_stubs_int_map::const_iterator it
=
1667 this->local_mips16_fn_stubs_
.find(r_sym
);
1668 if (it
!= this->local_mips16_fn_stubs_
.end())
1669 return (*it
).second
;
1673 // Record that this object has MIPS16 fn stub for local symbol. This method
1674 // is only called if we decided not to discard the stub.
1676 add_local_mips16_fn_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1678 gold_assert(stub
->is_for_local_function());
1679 unsigned int r_sym
= stub
->r_sym();
1680 this->local_mips16_fn_stubs_
.insert(
1681 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1685 // Return MIPS16 call stub section for local symbol R_SYM, or NULL if this
1686 // object doesn't have call stub for R_SYM.
1687 Mips16_stub_section
<size
, big_endian
>*
1688 get_local_mips16_call_stub(unsigned int r_sym
) const
1690 typename
Mips16_stubs_int_map::const_iterator it
=
1691 this->local_mips16_call_stubs_
.find(r_sym
);
1692 if (it
!= this->local_mips16_call_stubs_
.end())
1693 return (*it
).second
;
1697 // Record that this object has MIPS16 call stub for local symbol. This method
1698 // is only called if we decided not to discard the stub.
1700 add_local_mips16_call_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1702 gold_assert(stub
->is_for_local_function());
1703 unsigned int r_sym
= stub
->r_sym();
1704 this->local_mips16_call_stubs_
.insert(
1705 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1709 // Record that we found "non 16-bit" call relocation against local symbol
1710 // SYMNDX. This reloc would need to refer to a MIPS16 fn stub, if there
1713 add_local_non_16bit_call(unsigned int symndx
)
1714 { this->local_non_16bit_calls_
.insert(symndx
); }
1716 // Return true if there is any "non 16-bit" call relocation against local
1717 // symbol SYMNDX in this object.
1719 has_local_non_16bit_call_relocs(unsigned int symndx
)
1721 return (this->local_non_16bit_calls_
.find(symndx
)
1722 != this->local_non_16bit_calls_
.end());
1725 // Record that we found 16-bit call relocation R_MIPS16_26 against local
1726 // symbol SYMNDX. Local MIPS16 call or call_fp stubs will only be needed
1727 // if there is some R_MIPS16_26 relocation that refers to the stub symbol.
1729 add_local_16bit_call(unsigned int symndx
)
1730 { this->local_16bit_calls_
.insert(symndx
); }
1732 // Return true if there is any 16-bit call relocation R_MIPS16_26 against local
1733 // symbol SYMNDX in this object.
1735 has_local_16bit_call_relocs(unsigned int symndx
)
1737 return (this->local_16bit_calls_
.find(symndx
)
1738 != this->local_16bit_calls_
.end());
1741 // Get gp value that was used to create this object.
1744 { return this->gp_
; }
1746 // Return whether the object is a PIC object.
1749 { return this->is_pic_
; }
1751 // Return whether the object uses N32 ABI.
1754 { return this->is_n32_
; }
1756 // Return whether the object uses N64 ABI.
1759 { return size
== 64; }
1761 // Return whether the object uses NewABI conventions.
1764 { return this->is_n32() || this->is_n64(); }
1766 // Return Mips_got_info for this object.
1767 Mips_got_info
<size
, big_endian
>*
1768 get_got_info() const
1769 { return this->got_info_
; }
1771 // Return Mips_got_info for this object. Create new info if it doesn't exist.
1772 Mips_got_info
<size
, big_endian
>*
1773 get_or_create_got_info()
1775 if (!this->got_info_
)
1776 this->got_info_
= new Mips_got_info
<size
, big_endian
>();
1777 return this->got_info_
;
1780 // Set Mips_got_info for this object.
1782 set_got_info(Mips_got_info
<size
, big_endian
>* got_info
)
1783 { this->got_info_
= got_info
; }
1785 // Whether a section SHDNX is a MIPS16 stub section. This is only valid
1786 // after do_read_symbols is called.
1788 is_mips16_stub_section(unsigned int shndx
)
1790 return (is_mips16_fn_stub_section(shndx
)
1791 || is_mips16_call_stub_section(shndx
)
1792 || is_mips16_call_fp_stub_section(shndx
));
1795 // Return TRUE if relocations in section SHNDX can refer directly to a
1796 // MIPS16 function rather than to a hard-float stub. This is only valid
1797 // after do_read_symbols is called.
1799 section_allows_mips16_refs(unsigned int shndx
)
1801 return (this->is_mips16_stub_section(shndx
) || shndx
== this->pdr_shndx_
);
1804 // Whether a section SHDNX is a MIPS16 fn stub section. This is only valid
1805 // after do_read_symbols is called.
1807 is_mips16_fn_stub_section(unsigned int shndx
)
1809 gold_assert(shndx
< this->section_is_mips16_fn_stub_
.size());
1810 return this->section_is_mips16_fn_stub_
[shndx
];
1813 // Whether a section SHDNX is a MIPS16 call stub section. This is only valid
1814 // after do_read_symbols is called.
1816 is_mips16_call_stub_section(unsigned int shndx
)
1818 gold_assert(shndx
< this->section_is_mips16_call_stub_
.size());
1819 return this->section_is_mips16_call_stub_
[shndx
];
1822 // Whether a section SHDNX is a MIPS16 call_fp stub section. This is only
1823 // valid after do_read_symbols is called.
1825 is_mips16_call_fp_stub_section(unsigned int shndx
)
1827 gold_assert(shndx
< this->section_is_mips16_call_fp_stub_
.size());
1828 return this->section_is_mips16_call_fp_stub_
[shndx
];
1831 // Discard MIPS16 stub secions that are not needed.
1833 discard_mips16_stub_sections(Symbol_table
* symtab
);
1835 // Return whether there is a .reginfo section.
1837 has_reginfo_section() const
1838 { return this->has_reginfo_section_
; }
1840 // Return whether we want to merge processor-specific data.
1842 merge_processor_specific_data() const
1843 { return this->merge_processor_specific_data_
; }
1845 // Return gprmask from the .reginfo section of this object.
1848 { return this->gprmask_
; }
1850 // Return cprmask1 from the .reginfo section of this object.
1853 { return this->cprmask1_
; }
1855 // Return cprmask2 from the .reginfo section of this object.
1858 { return this->cprmask2_
; }
1860 // Return cprmask3 from the .reginfo section of this object.
1863 { return this->cprmask3_
; }
1865 // Return cprmask4 from the .reginfo section of this object.
1868 { return this->cprmask4_
; }
1870 // This is the contents of the .MIPS.abiflags section if there is one.
1871 Mips_abiflags
<big_endian
>*
1873 { return this->abiflags_
; }
1875 // This is the contents of the .gnu.attribute section if there is one.
1876 const Attributes_section_data
*
1877 attributes_section_data() const
1878 { return this->attributes_section_data_
; }
1881 // Count the local symbols.
1883 do_count_local_symbols(Stringpool_template
<char>*,
1884 Stringpool_template
<char>*);
1886 // Read the symbol information.
1888 do_read_symbols(Read_symbols_data
* sd
);
1891 // The name of the options section.
1892 const char* mips_elf_options_section_name()
1893 { return this->is_newabi() ? ".MIPS.options" : ".options"; }
1895 // processor-specific flags in ELF file header.
1896 elfcpp::Elf_Word processor_specific_flags_
;
1898 // Bit vector to tell if a local symbol is a MIPS16 symbol or not.
1899 // This is only valid after do_count_local_symbol is called.
1900 std::vector
<bool> local_symbol_is_mips16_
;
1902 // Bit vector to tell if a local symbol is a microMIPS symbol or not.
1903 // This is only valid after do_count_local_symbol is called.
1904 std::vector
<bool> local_symbol_is_micromips_
;
1906 // Map from section index to the MIPS16 stub for that section. This contains
1907 // all stubs found in this object.
1908 Mips16_stubs_int_map mips16_stub_sections_
;
1910 // Local symbols that have "non 16-bit" call relocation. This relocation
1911 // would need to refer to a MIPS16 fn stub, if there is one.
1912 std::set
<unsigned int> local_non_16bit_calls_
;
1914 // Local symbols that have 16-bit call relocation R_MIPS16_26. Local MIPS16
1915 // call or call_fp stubs will only be needed if there is some R_MIPS16_26
1916 // relocation that refers to the stub symbol.
1917 std::set
<unsigned int> local_16bit_calls_
;
1919 // Map from local symbol index to the MIPS16 fn stub for that symbol.
1920 // This contains only the stubs that we decided not to discard.
1921 Mips16_stubs_int_map local_mips16_fn_stubs_
;
1923 // Map from local symbol index to the MIPS16 call stub for that symbol.
1924 // This contains only the stubs that we decided not to discard.
1925 Mips16_stubs_int_map local_mips16_call_stubs_
;
1927 // gp value that was used to create this object.
1929 // Whether the object is a PIC object.
1931 // Whether the object uses N32 ABI.
1933 // Whether the object contains a .reginfo section.
1934 bool has_reginfo_section_
: 1;
1935 // Whether we merge processor-specific data of this object to output.
1936 bool merge_processor_specific_data_
: 1;
1937 // The Mips_got_info for this object.
1938 Mips_got_info
<size
, big_endian
>* got_info_
;
1940 // Bit vector to tell if a section is a MIPS16 fn stub section or not.
1941 // This is only valid after do_read_symbols is called.
1942 std::vector
<bool> section_is_mips16_fn_stub_
;
1944 // Bit vector to tell if a section is a MIPS16 call stub section or not.
1945 // This is only valid after do_read_symbols is called.
1946 std::vector
<bool> section_is_mips16_call_stub_
;
1948 // Bit vector to tell if a section is a MIPS16 call_fp stub section or not.
1949 // This is only valid after do_read_symbols is called.
1950 std::vector
<bool> section_is_mips16_call_fp_stub_
;
1952 // .pdr section index.
1953 unsigned int pdr_shndx_
;
1955 // Object attributes if there is a .gnu.attributes section or NULL.
1956 Attributes_section_data
* attributes_section_data_
;
1958 // Object abiflags if there is a .MIPS.abiflags section or NULL.
1959 Mips_abiflags
<big_endian
>* abiflags_
;
1961 // gprmask from the .reginfo section of this object.
1963 // cprmask1 from the .reginfo section of this object.
1965 // cprmask2 from the .reginfo section of this object.
1967 // cprmask3 from the .reginfo section of this object.
1969 // cprmask4 from the .reginfo section of this object.
1973 // Mips_output_data_got class.
1975 template<int size
, bool big_endian
>
1976 class Mips_output_data_got
: public Output_data_got
<size
, big_endian
>
1978 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1979 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
1981 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1984 Mips_output_data_got(Target_mips
<size
, big_endian
>* target
,
1985 Symbol_table
* symtab
, Layout
* layout
)
1986 : Output_data_got
<size
, big_endian
>(), target_(target
),
1987 symbol_table_(symtab
), layout_(layout
), static_relocs_(), got_view_(NULL
),
1988 first_global_got_dynsym_index_(-1U), primary_got_(NULL
),
1989 secondary_got_relocs_()
1991 this->master_got_info_
= new Mips_got_info
<size
, big_endian
>();
1992 this->set_addralign(16);
1995 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
1996 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
1998 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
1999 unsigned int symndx
, Mips_address addend
,
2000 unsigned int r_type
, unsigned int shndx
,
2001 bool is_section_symbol
)
2003 this->master_got_info_
->record_local_got_symbol(object
, symndx
, addend
,
2008 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
2009 // in OBJECT. FOR_CALL is true if the caller is only interested in
2010 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
2013 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
2014 Mips_relobj
<size
, big_endian
>* object
,
2015 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
2017 this->master_got_info_
->record_global_got_symbol(mips_sym
, object
, r_type
,
2018 dyn_reloc
, for_call
);
2021 // Record that OBJECT has a page relocation against symbol SYMNDX and
2022 // that ADDEND is the addend for that relocation.
2024 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
2025 unsigned int symndx
, int addend
)
2026 { this->master_got_info_
->record_got_page_entry(object
, symndx
, addend
); }
2028 // Add a static entry for the GOT entry at OFFSET. GSYM is a global
2029 // symbol and R_TYPE is the code of a dynamic relocation that needs to be
2030 // applied in a static link.
2032 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
2033 Mips_symbol
<size
>* gsym
)
2034 { this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, gsym
)); }
2036 // Add a static reloc for the GOT entry at OFFSET. RELOBJ is an object
2037 // defining a local symbol with INDEX. R_TYPE is the code of a dynamic
2038 // relocation that needs to be applied in a static link.
2040 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
2041 Sized_relobj_file
<size
, big_endian
>* relobj
,
2044 this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, relobj
,
2048 // Record that global symbol GSYM has R_TYPE dynamic relocation in the
2049 // secondary GOT at OFFSET.
2051 add_secondary_got_reloc(unsigned int got_offset
, unsigned int r_type
,
2052 Mips_symbol
<size
>* gsym
)
2054 this->secondary_got_relocs_
.push_back(Static_reloc(got_offset
,
2058 // Update GOT entry at OFFSET with VALUE.
2060 update_got_entry(unsigned int offset
, Mips_address value
)
2062 elfcpp::Swap
<size
, big_endian
>::writeval(this->got_view_
+ offset
, value
);
2065 // Return the number of entries in local part of the GOT. This includes
2066 // local entries, page entries and 2 reserved entries.
2068 get_local_gotno() const
2070 if (!this->multi_got())
2072 return (2 + this->master_got_info_
->local_gotno()
2073 + this->master_got_info_
->page_gotno());
2076 return 2 + this->primary_got_
->local_gotno() + this->primary_got_
->page_gotno();
2079 // Return dynamic symbol table index of the first symbol with global GOT
2082 first_global_got_dynsym_index() const
2083 { return this->first_global_got_dynsym_index_
; }
2085 // Set dynamic symbol table index of the first symbol with global GOT entry.
2087 set_first_global_got_dynsym_index(unsigned int index
)
2088 { this->first_global_got_dynsym_index_
= index
; }
2090 // Lay out the GOT. Add local, global and TLS entries. If GOT is
2091 // larger than 64K, create multi-GOT.
2093 lay_out_got(Layout
* layout
, Symbol_table
* symtab
,
2094 const Input_objects
* input_objects
);
2096 // Create multi-GOT. For every GOT, add local, global and TLS entries.
2098 lay_out_multi_got(Layout
* layout
, const Input_objects
* input_objects
);
2100 // Attempt to merge GOTs of different input objects.
2102 merge_gots(const Input_objects
* input_objects
);
2104 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
2105 // this would lead to overflow, true if they were merged successfully.
2107 merge_got_with(Mips_got_info
<size
, big_endian
>* from
,
2108 Mips_relobj
<size
, big_endian
>* object
,
2109 Mips_got_info
<size
, big_endian
>* to
);
2111 // Return the offset of GOT page entry for VALUE. For multi-GOT links,
2112 // use OBJECT's GOT.
2114 get_got_page_offset(Mips_address value
,
2115 const Mips_relobj
<size
, big_endian
>* object
)
2117 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2118 ? this->master_got_info_
2119 : object
->get_got_info());
2120 gold_assert(g
!= NULL
);
2121 return g
->get_got_page_offset(value
, this);
2124 // Return the GOT offset of type GOT_TYPE of the global symbol
2125 // GSYM. For multi-GOT links, use OBJECT's GOT.
2126 unsigned int got_offset(const Symbol
* gsym
, unsigned int got_type
,
2127 Mips_relobj
<size
, big_endian
>* object
) const
2129 if (!this->multi_got())
2130 return gsym
->got_offset(got_type
);
2133 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
2134 gold_assert(g
!= NULL
);
2135 return gsym
->got_offset(g
->multigot_got_type(got_type
));
2139 // Return the GOT offset of type GOT_TYPE of the local symbol
2142 got_offset(unsigned int symndx
, unsigned int got_type
,
2143 Sized_relobj_file
<size
, big_endian
>* object
,
2144 uint64_t addend
) const
2145 { return object
->local_got_offset(symndx
, got_type
, addend
); }
2147 // Return the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2149 tls_ldm_offset(Mips_relobj
<size
, big_endian
>* object
) const
2151 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2152 ? this->master_got_info_
2153 : object
->get_got_info());
2154 gold_assert(g
!= NULL
);
2155 return g
->tls_ldm_offset();
2158 // Set the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2160 set_tls_ldm_offset(unsigned int tls_ldm_offset
,
2161 Mips_relobj
<size
, big_endian
>* object
)
2163 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2164 ? this->master_got_info_
2165 : object
->get_got_info());
2166 gold_assert(g
!= NULL
);
2167 g
->set_tls_ldm_offset(tls_ldm_offset
);
2170 // Return true for multi-GOT links.
2173 { return this->primary_got_
!= NULL
; }
2175 // Return the offset of OBJECT's GOT from the start of .got section.
2177 get_got_offset(const Mips_relobj
<size
, big_endian
>* object
)
2179 if (!this->multi_got())
2183 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
2184 return g
!= NULL
? g
->offset() : 0;
2188 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
2190 add_reloc_only_entries()
2191 { this->master_got_info_
->add_reloc_only_entries(this); }
2193 // Return offset of the primary GOT's entry for global symbol.
2195 get_primary_got_offset(const Mips_symbol
<size
>* sym
) const
2197 gold_assert(sym
->global_got_area() != GGA_NONE
);
2198 return (this->get_local_gotno() + sym
->dynsym_index()
2199 - this->first_global_got_dynsym_index()) * size
/8;
2202 // For the entry at offset GOT_OFFSET, return its offset from the gp.
2203 // Input argument GOT_OFFSET is always global offset from the start of
2204 // .got section, for both single and multi-GOT links.
2205 // For single GOT links, this returns GOT_OFFSET - 0x7FF0. For multi-GOT
2206 // links, the return value is object_got_offset - 0x7FF0, where
2207 // object_got_offset is offset in the OBJECT's GOT.
2209 gp_offset(unsigned int got_offset
,
2210 const Mips_relobj
<size
, big_endian
>* object
) const
2212 return (this->address() + got_offset
2213 - this->target_
->adjusted_gp_value(object
));
2217 // Write out the GOT table.
2219 do_write(Output_file
*);
2223 // This class represent dynamic relocations that need to be applied by
2224 // gold because we are using TLS relocations in a static link.
2228 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2229 Mips_symbol
<size
>* gsym
)
2230 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(true)
2231 { this->u_
.global
.symbol
= gsym
; }
2233 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2234 Sized_relobj_file
<size
, big_endian
>* relobj
, unsigned int index
)
2235 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(false)
2237 this->u_
.local
.relobj
= relobj
;
2238 this->u_
.local
.index
= index
;
2241 // Return the GOT offset.
2244 { return this->got_offset_
; }
2249 { return this->r_type_
; }
2251 // Whether the symbol is global or not.
2253 symbol_is_global() const
2254 { return this->symbol_is_global_
; }
2256 // For a relocation against a global symbol, the global symbol.
2260 gold_assert(this->symbol_is_global_
);
2261 return this->u_
.global
.symbol
;
2264 // For a relocation against a local symbol, the defining object.
2265 Sized_relobj_file
<size
, big_endian
>*
2268 gold_assert(!this->symbol_is_global_
);
2269 return this->u_
.local
.relobj
;
2272 // For a relocation against a local symbol, the local symbol index.
2276 gold_assert(!this->symbol_is_global_
);
2277 return this->u_
.local
.index
;
2281 // GOT offset of the entry to which this relocation is applied.
2282 unsigned int got_offset_
;
2283 // Type of relocation.
2284 unsigned int r_type_
;
2285 // Whether this relocation is against a global symbol.
2286 bool symbol_is_global_
;
2287 // A global or local symbol.
2292 // For a global symbol, the symbol itself.
2293 Mips_symbol
<size
>* symbol
;
2297 // For a local symbol, the object defining object.
2298 Sized_relobj_file
<size
, big_endian
>* relobj
;
2299 // For a local symbol, the symbol index.
2306 Target_mips
<size
, big_endian
>* target_
;
2307 // The symbol table.
2308 Symbol_table
* symbol_table_
;
2311 // Static relocs to be applied to the GOT.
2312 std::vector
<Static_reloc
> static_relocs_
;
2313 // .got section view.
2314 unsigned char* got_view_
;
2315 // The dynamic symbol table index of the first symbol with global GOT entry.
2316 unsigned int first_global_got_dynsym_index_
;
2317 // The master GOT information.
2318 Mips_got_info
<size
, big_endian
>* master_got_info_
;
2319 // The primary GOT information.
2320 Mips_got_info
<size
, big_endian
>* primary_got_
;
2321 // Secondary GOT fixups.
2322 std::vector
<Static_reloc
> secondary_got_relocs_
;
2325 // A class to handle LA25 stubs - non-PIC interface to a PIC function. There are
2326 // two ways of creating these interfaces. The first is to add:
2328 // lui $25,%hi(func)
2330 // addiu $25,$25,%lo(func)
2332 // to a separate trampoline section. The second is to add:
2334 // lui $25,%hi(func)
2335 // addiu $25,$25,%lo(func)
2337 // immediately before a PIC function "func", but only if a function is at the
2338 // beginning of the section, and the section is not too heavily aligned (i.e we
2339 // would need to add no more than 2 nops before the stub.)
2341 // We only create stubs of the first type.
2343 template<int size
, bool big_endian
>
2344 class Mips_output_data_la25_stub
: public Output_section_data
2346 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2349 Mips_output_data_la25_stub()
2350 : Output_section_data(size
== 32 ? 4 : 8), symbols_()
2353 // Create LA25 stub for a symbol.
2355 create_la25_stub(Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
2356 Mips_symbol
<size
>* gsym
);
2358 // Return output address of a stub.
2360 stub_address(const Mips_symbol
<size
>* sym
) const
2362 gold_assert(sym
->has_la25_stub());
2363 return this->address() + sym
->la25_stub_offset();
2368 do_adjust_output_section(Output_section
* os
)
2369 { os
->set_entsize(0); }
2372 // Template for standard LA25 stub.
2373 static const uint32_t la25_stub_entry
[];
2374 // Template for microMIPS LA25 stub.
2375 static const uint32_t la25_stub_micromips_entry
[];
2377 // Set the final size.
2379 set_final_data_size()
2380 { this->set_data_size(this->symbols_
.size() * 16); }
2382 // Create a symbol for SYM stub's value and size, to help make the
2383 // disassembly easier to read.
2385 create_stub_symbol(Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
2386 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
);
2388 // Write to a map file.
2390 do_print_to_mapfile(Mapfile
* mapfile
) const
2391 { mapfile
->print_output_data(this, _(".LA25.stubs")); }
2393 // Write out the LA25 stub section.
2395 do_write(Output_file
*);
2397 // Symbols that have LA25 stubs.
2398 std::vector
<Mips_symbol
<size
>*> symbols_
;
2401 // MIPS-specific relocation writer.
2403 template<int sh_type
, bool dynamic
, int size
, bool big_endian
>
2404 struct Mips_output_reloc_writer
;
2406 template<int sh_type
, bool dynamic
, bool big_endian
>
2407 struct Mips_output_reloc_writer
<sh_type
, dynamic
, 32, big_endian
>
2409 typedef Output_reloc
<sh_type
, dynamic
, 32, big_endian
> Output_reloc_type
;
2410 typedef std::vector
<Output_reloc_type
> Relocs
;
2413 write(typename
Relocs::const_iterator p
, unsigned char* pov
)
2417 template<int sh_type
, bool dynamic
, bool big_endian
>
2418 struct Mips_output_reloc_writer
<sh_type
, dynamic
, 64, big_endian
>
2420 typedef Output_reloc
<sh_type
, dynamic
, 64, big_endian
> Output_reloc_type
;
2421 typedef std::vector
<Output_reloc_type
> Relocs
;
2424 write(typename
Relocs::const_iterator p
, unsigned char* pov
)
2426 elfcpp::Mips64_rel_write
<big_endian
> orel(pov
);
2427 orel
.put_r_offset(p
->get_address());
2428 orel
.put_r_sym(p
->get_symbol_index());
2429 orel
.put_r_ssym(RSS_UNDEF
);
2430 orel
.put_r_type(p
->type());
2431 if (p
->type() == elfcpp::R_MIPS_REL32
)
2432 orel
.put_r_type2(elfcpp::R_MIPS_64
);
2434 orel
.put_r_type2(elfcpp::R_MIPS_NONE
);
2435 orel
.put_r_type3(elfcpp::R_MIPS_NONE
);
2439 template<int sh_type
, bool dynamic
, int size
, bool big_endian
>
2440 class Mips_output_data_reloc
: public Output_data_reloc
<sh_type
, dynamic
,
2444 Mips_output_data_reloc(bool sort_relocs
)
2445 : Output_data_reloc
<sh_type
, dynamic
, size
, big_endian
>(sort_relocs
)
2449 // Write out the data.
2451 do_write(Output_file
* of
)
2453 typedef Mips_output_reloc_writer
<sh_type
, dynamic
, size
,
2455 this->template do_write_generic
<Writer
>(of
);
2460 // A class to handle the PLT data.
2462 template<int size
, bool big_endian
>
2463 class Mips_output_data_plt
: public Output_section_data
2465 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2466 typedef Mips_output_data_reloc
<elfcpp::SHT_REL
, true,
2467 size
, big_endian
> Reloc_section
;
2470 // Create the PLT section. The ordinary .got section is an argument,
2471 // since we need to refer to the start.
2472 Mips_output_data_plt(Layout
* layout
, Output_data_space
* got_plt
,
2473 Target_mips
<size
, big_endian
>* target
)
2474 : Output_section_data(size
== 32 ? 4 : 8), got_plt_(got_plt
), symbols_(),
2475 plt_mips_offset_(0), plt_comp_offset_(0), plt_header_size_(0),
2478 this->rel_
= new Reloc_section(false);
2479 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
2480 elfcpp::SHF_ALLOC
, this->rel_
,
2481 ORDER_DYNAMIC_PLT_RELOCS
, false);
2484 // Add an entry to the PLT for a symbol referenced by r_type relocation.
2486 add_entry(Mips_symbol
<size
>* gsym
, unsigned int r_type
);
2488 // Return the .rel.plt section data.
2491 { return this->rel_
; }
2493 // Return the number of PLT entries.
2496 { return this->symbols_
.size(); }
2498 // Return the offset of the first non-reserved PLT entry.
2500 first_plt_entry_offset() const
2501 { return sizeof(plt0_entry_o32
); }
2503 // Return the size of a PLT entry.
2505 plt_entry_size() const
2506 { return sizeof(plt_entry
); }
2508 // Set final PLT offsets. For each symbol, determine whether standard or
2509 // compressed (MIPS16 or microMIPS) PLT entry is used.
2513 // Return the offset of the first standard PLT entry.
2515 first_mips_plt_offset() const
2516 { return this->plt_header_size_
; }
2518 // Return the offset of the first compressed PLT entry.
2520 first_comp_plt_offset() const
2521 { return this->plt_header_size_
+ this->plt_mips_offset_
; }
2523 // Return whether there are any standard PLT entries.
2525 has_standard_entries() const
2526 { return this->plt_mips_offset_
> 0; }
2528 // Return the output address of standard PLT entry.
2530 mips_entry_address(const Mips_symbol
<size
>* sym
) const
2532 gold_assert (sym
->has_mips_plt_offset());
2533 return (this->address() + this->first_mips_plt_offset()
2534 + sym
->mips_plt_offset());
2537 // Return the output address of compressed (MIPS16 or microMIPS) PLT entry.
2539 comp_entry_address(const Mips_symbol
<size
>* sym
) const
2541 gold_assert (sym
->has_comp_plt_offset());
2542 return (this->address() + this->first_comp_plt_offset()
2543 + sym
->comp_plt_offset());
2548 do_adjust_output_section(Output_section
* os
)
2549 { os
->set_entsize(0); }
2551 // Write to a map file.
2553 do_print_to_mapfile(Mapfile
* mapfile
) const
2554 { mapfile
->print_output_data(this, _(".plt")); }
2557 // Template for the first PLT entry.
2558 static const uint32_t plt0_entry_o32
[];
2559 static const uint32_t plt0_entry_n32
[];
2560 static const uint32_t plt0_entry_n64
[];
2561 static const uint32_t plt0_entry_micromips_o32
[];
2562 static const uint32_t plt0_entry_micromips32_o32
[];
2564 // Template for subsequent PLT entries.
2565 static const uint32_t plt_entry
[];
2566 static const uint32_t plt_entry_r6
[];
2567 static const uint32_t plt_entry_mips16_o32
[];
2568 static const uint32_t plt_entry_micromips_o32
[];
2569 static const uint32_t plt_entry_micromips32_o32
[];
2571 // Set the final size.
2573 set_final_data_size()
2575 this->set_data_size(this->plt_header_size_
+ this->plt_mips_offset_
2576 + this->plt_comp_offset_
);
2579 // Write out the PLT data.
2581 do_write(Output_file
*);
2583 // Return whether the plt header contains microMIPS code. For the sake of
2584 // cache alignment always use a standard header whenever any standard entries
2585 // are present even if microMIPS entries are present as well. This also lets
2586 // the microMIPS header rely on the value of $v0 only set by microMIPS
2587 // entries, for a small size reduction.
2589 is_plt_header_compressed() const
2591 gold_assert(this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0);
2592 return this->target_
->is_output_micromips() && this->plt_mips_offset_
== 0;
2595 // Return the size of the PLT header.
2597 get_plt_header_size() const
2599 if (this->target_
->is_output_n64())
2600 return 4 * sizeof(plt0_entry_n64
) / sizeof(plt0_entry_n64
[0]);
2601 else if (this->target_
->is_output_n32())
2602 return 4 * sizeof(plt0_entry_n32
) / sizeof(plt0_entry_n32
[0]);
2603 else if (!this->is_plt_header_compressed())
2604 return 4 * sizeof(plt0_entry_o32
) / sizeof(plt0_entry_o32
[0]);
2605 else if (this->target_
->use_32bit_micromips_instructions())
2606 return (2 * sizeof(plt0_entry_micromips32_o32
)
2607 / sizeof(plt0_entry_micromips32_o32
[0]));
2609 return (2 * sizeof(plt0_entry_micromips_o32
)
2610 / sizeof(plt0_entry_micromips_o32
[0]));
2613 // Return the PLT header entry.
2615 get_plt_header_entry() const
2617 if (this->target_
->is_output_n64())
2618 return plt0_entry_n64
;
2619 else if (this->target_
->is_output_n32())
2620 return plt0_entry_n32
;
2621 else if (!this->is_plt_header_compressed())
2622 return plt0_entry_o32
;
2623 else if (this->target_
->use_32bit_micromips_instructions())
2624 return plt0_entry_micromips32_o32
;
2626 return plt0_entry_micromips_o32
;
2629 // Return the size of the standard PLT entry.
2631 standard_plt_entry_size() const
2632 { return 4 * sizeof(plt_entry
) / sizeof(plt_entry
[0]); }
2634 // Return the size of the compressed PLT entry.
2636 compressed_plt_entry_size() const
2638 gold_assert(!this->target_
->is_output_newabi());
2640 if (!this->target_
->is_output_micromips())
2641 return (2 * sizeof(plt_entry_mips16_o32
)
2642 / sizeof(plt_entry_mips16_o32
[0]));
2643 else if (this->target_
->use_32bit_micromips_instructions())
2644 return (2 * sizeof(plt_entry_micromips32_o32
)
2645 / sizeof(plt_entry_micromips32_o32
[0]));
2647 return (2 * sizeof(plt_entry_micromips_o32
)
2648 / sizeof(plt_entry_micromips_o32
[0]));
2651 // The reloc section.
2652 Reloc_section
* rel_
;
2653 // The .got.plt section.
2654 Output_data_space
* got_plt_
;
2655 // Symbols that have PLT entry.
2656 std::vector
<Mips_symbol
<size
>*> symbols_
;
2657 // The offset of the next standard PLT entry to create.
2658 unsigned int plt_mips_offset_
;
2659 // The offset of the next compressed PLT entry to create.
2660 unsigned int plt_comp_offset_
;
2661 // The size of the PLT header in bytes.
2662 unsigned int plt_header_size_
;
2664 Target_mips
<size
, big_endian
>* target_
;
2667 // A class to handle the .MIPS.stubs data.
2669 template<int size
, bool big_endian
>
2670 class Mips_output_data_mips_stubs
: public Output_section_data
2672 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2674 // Unordered set of .MIPS.stubs entries.
2675 typedef Unordered_set
<Mips_symbol
<size
>*, Mips_symbol_hash
<size
> >
2676 Mips_stubs_entry_set
;
2679 Mips_output_data_mips_stubs(Target_mips
<size
, big_endian
>* target
)
2680 : Output_section_data(size
== 32 ? 4 : 8), symbols_(), dynsym_count_(-1U),
2681 stub_offsets_are_set_(false), target_(target
)
2684 // Create entry for a symbol.
2686 make_entry(Mips_symbol
<size
>*);
2688 // Remove entry for a symbol.
2690 remove_entry(Mips_symbol
<size
>* gsym
);
2692 // Set stub offsets for symbols. This method expects that the number of
2693 // entries in dynamic symbol table is set.
2695 set_lazy_stub_offsets();
2698 set_needs_dynsym_value();
2700 // Set the number of entries in dynamic symbol table.
2702 set_dynsym_count(unsigned int dynsym_count
)
2703 { this->dynsym_count_
= dynsym_count
; }
2705 // Return maximum size of the stub, ie. the stub size if the dynamic symbol
2706 // count is greater than 0x10000. If the dynamic symbol count is less than
2707 // 0x10000, the stub will be 4 bytes smaller.
2708 // There's no disadvantage from using microMIPS code here, so for the sake of
2709 // pure-microMIPS binaries we prefer it whenever there's any microMIPS code in
2710 // output produced at all. This has a benefit of stubs being shorter by
2711 // 4 bytes each too, unless in the insn32 mode.
2713 stub_max_size() const
2715 if (!this->target_
->is_output_micromips()
2716 || this->target_
->use_32bit_micromips_instructions())
2722 // Return the size of the stub. This method expects that the final dynsym
2727 gold_assert(this->dynsym_count_
!= -1U);
2728 if (this->dynsym_count_
> 0x10000)
2729 return this->stub_max_size();
2731 return this->stub_max_size() - 4;
2734 // Return output address of a stub.
2736 stub_address(const Mips_symbol
<size
>* sym
) const
2738 gold_assert(sym
->has_lazy_stub());
2739 return this->address() + sym
->lazy_stub_offset();
2744 do_adjust_output_section(Output_section
* os
)
2745 { os
->set_entsize(0); }
2747 // Write to a map file.
2749 do_print_to_mapfile(Mapfile
* mapfile
) const
2750 { mapfile
->print_output_data(this, _(".MIPS.stubs")); }
2753 static const uint32_t lazy_stub_normal_1
[];
2754 static const uint32_t lazy_stub_normal_1_n64
[];
2755 static const uint32_t lazy_stub_normal_2
[];
2756 static const uint32_t lazy_stub_normal_2_n64
[];
2757 static const uint32_t lazy_stub_big
[];
2758 static const uint32_t lazy_stub_big_n64
[];
2760 static const uint32_t lazy_stub_micromips_normal_1
[];
2761 static const uint32_t lazy_stub_micromips_normal_1_n64
[];
2762 static const uint32_t lazy_stub_micromips_normal_2
[];
2763 static const uint32_t lazy_stub_micromips_normal_2_n64
[];
2764 static const uint32_t lazy_stub_micromips_big
[];
2765 static const uint32_t lazy_stub_micromips_big_n64
[];
2767 static const uint32_t lazy_stub_micromips32_normal_1
[];
2768 static const uint32_t lazy_stub_micromips32_normal_1_n64
[];
2769 static const uint32_t lazy_stub_micromips32_normal_2
[];
2770 static const uint32_t lazy_stub_micromips32_normal_2_n64
[];
2771 static const uint32_t lazy_stub_micromips32_big
[];
2772 static const uint32_t lazy_stub_micromips32_big_n64
[];
2774 // Set the final size.
2776 set_final_data_size()
2777 { this->set_data_size(this->symbols_
.size() * this->stub_max_size()); }
2779 // Write out the .MIPS.stubs data.
2781 do_write(Output_file
*);
2783 // .MIPS.stubs symbols
2784 Mips_stubs_entry_set symbols_
;
2785 // Number of entries in dynamic symbol table.
2786 unsigned int dynsym_count_
;
2787 // Whether the stub offsets are set.
2788 bool stub_offsets_are_set_
;
2790 Target_mips
<size
, big_endian
>* target_
;
2793 // This class handles Mips .reginfo output section.
2795 template<int size
, bool big_endian
>
2796 class Mips_output_section_reginfo
: public Output_section_data
2798 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
2801 Mips_output_section_reginfo(Target_mips
<size
, big_endian
>* target
,
2802 Valtype gprmask
, Valtype cprmask1
,
2803 Valtype cprmask2
, Valtype cprmask3
,
2805 : Output_section_data(24, 4, true), target_(target
),
2806 gprmask_(gprmask
), cprmask1_(cprmask1
), cprmask2_(cprmask2
),
2807 cprmask3_(cprmask3
), cprmask4_(cprmask4
)
2811 // Write to a map file.
2813 do_print_to_mapfile(Mapfile
* mapfile
) const
2814 { mapfile
->print_output_data(this, _(".reginfo")); }
2816 // Write out reginfo section.
2818 do_write(Output_file
* of
);
2821 Target_mips
<size
, big_endian
>* target_
;
2823 // gprmask of the output .reginfo section.
2825 // cprmask1 of the output .reginfo section.
2827 // cprmask2 of the output .reginfo section.
2829 // cprmask3 of the output .reginfo section.
2831 // cprmask4 of the output .reginfo section.
2835 // This class handles .MIPS.options output section.
2837 template<int size
, bool big_endian
>
2838 class Mips_output_section_options
: public Output_section
2841 Mips_output_section_options(const char* name
, elfcpp::Elf_Word type
,
2842 elfcpp::Elf_Xword flags
,
2843 Target_mips
<size
, big_endian
>* target
)
2844 : Output_section(name
, type
, flags
), target_(target
)
2846 // After the input sections are written, we only need to update
2847 // ri_gp_value field of ODK_REGINFO entries.
2848 this->set_after_input_sections();
2852 // Write out option section.
2854 do_write(Output_file
* of
);
2857 Target_mips
<size
, big_endian
>* target_
;
2860 // This class handles .MIPS.abiflags output section.
2862 template<int size
, bool big_endian
>
2863 class Mips_output_section_abiflags
: public Output_section_data
2866 Mips_output_section_abiflags(const Mips_abiflags
<big_endian
>& abiflags
)
2867 : Output_section_data(24, 8, true), abiflags_(abiflags
)
2871 // Write to a map file.
2873 do_print_to_mapfile(Mapfile
* mapfile
) const
2874 { mapfile
->print_output_data(this, _(".MIPS.abiflags")); }
2877 do_write(Output_file
* of
);
2880 const Mips_abiflags
<big_endian
>& abiflags_
;
2883 // The MIPS target has relocation types which default handling of relocatable
2884 // relocation cannot process. So we have to extend the default code.
2886 template<bool big_endian
, typename Classify_reloc
>
2887 class Mips_scan_relocatable_relocs
:
2888 public Default_scan_relocatable_relocs
<Classify_reloc
>
2891 // Return the strategy to use for a local symbol which is a section
2892 // symbol, given the relocation type.
2893 inline Relocatable_relocs::Reloc_strategy
2894 local_section_strategy(unsigned int r_type
, Relobj
* object
)
2896 if (Classify_reloc::sh_type
== elfcpp::SHT_RELA
)
2897 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
2902 case elfcpp::R_MIPS_26
:
2903 return Relocatable_relocs::RELOC_SPECIAL
;
2906 return Default_scan_relocatable_relocs
<Classify_reloc
>::
2907 local_section_strategy(r_type
, object
);
2913 // Mips_copy_relocs class. The only difference from the base class is the
2914 // method emit_mips, which should be called instead of Copy_reloc_entry::emit.
2915 // Mips cannot convert all relocation types to dynamic relocs. If a reloc
2916 // cannot be made dynamic, a COPY reloc is emitted.
2918 template<int sh_type
, int size
, bool big_endian
>
2919 class Mips_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
2923 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_MIPS_COPY
)
2926 // Emit any saved relocations which turn out to be needed. This is
2927 // called after all the relocs have been scanned.
2929 emit_mips(Output_data_reloc
<sh_type
, true, size
, big_endian
>*,
2930 Symbol_table
*, Layout
*, Target_mips
<size
, big_endian
>*);
2933 typedef typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
2936 // Emit this reloc if appropriate. This is called after we have
2937 // scanned all the relocations, so we know whether we emitted a
2938 // COPY relocation for SYM_.
2940 emit_entry(Copy_reloc_entry
& entry
,
2941 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
2942 Symbol_table
* symtab
, Layout
* layout
,
2943 Target_mips
<size
, big_endian
>* target
);
2947 // Return true if the symbol SYM should be considered to resolve local
2948 // to the current module, and false otherwise. The logic is taken from
2949 // GNU ld's method _bfd_elf_symbol_refs_local_p.
2951 symbol_refs_local(const Symbol
* sym
, bool has_dynsym_entry
,
2952 bool local_protected
)
2954 // If it's a local sym, of course we resolve locally.
2958 // STV_HIDDEN or STV_INTERNAL ones must be local.
2959 if (sym
->visibility() == elfcpp::STV_HIDDEN
2960 || sym
->visibility() == elfcpp::STV_INTERNAL
)
2963 // If we don't have a definition in a regular file, then we can't
2964 // resolve locally. The sym is either undefined or dynamic.
2965 if (sym
->is_from_dynobj() || sym
->is_undefined())
2968 // Forced local symbols resolve locally.
2969 if (sym
->is_forced_local())
2972 // As do non-dynamic symbols.
2973 if (!has_dynsym_entry
)
2976 // At this point, we know the symbol is defined and dynamic. In an
2977 // executable it must resolve locally, likewise when building symbolic
2978 // shared libraries.
2979 if (parameters
->options().output_is_executable()
2980 || parameters
->options().Bsymbolic())
2983 // Now deal with defined dynamic symbols in shared libraries. Ones
2984 // with default visibility might not resolve locally.
2985 if (sym
->visibility() == elfcpp::STV_DEFAULT
)
2988 // STV_PROTECTED non-function symbols are local.
2989 if (sym
->type() != elfcpp::STT_FUNC
)
2992 // Function pointer equality tests may require that STV_PROTECTED
2993 // symbols be treated as dynamic symbols. If the address of a
2994 // function not defined in an executable is set to that function's
2995 // plt entry in the executable, then the address of the function in
2996 // a shared library must also be the plt entry in the executable.
2997 return local_protected
;
3000 // Return TRUE if references to this symbol always reference the symbol in this
3003 symbol_references_local(const Symbol
* sym
, bool has_dynsym_entry
)
3005 return symbol_refs_local(sym
, has_dynsym_entry
, false);
3008 // Return TRUE if calls to this symbol always call the version in this object.
3010 symbol_calls_local(const Symbol
* sym
, bool has_dynsym_entry
)
3012 return symbol_refs_local(sym
, has_dynsym_entry
, true);
3015 // Compare GOT offsets of two symbols.
3017 template<int size
, bool big_endian
>
3019 got_offset_compare(Symbol
* sym1
, Symbol
* sym2
)
3021 Mips_symbol
<size
>* mips_sym1
= Mips_symbol
<size
>::as_mips_sym(sym1
);
3022 Mips_symbol
<size
>* mips_sym2
= Mips_symbol
<size
>::as_mips_sym(sym2
);
3023 unsigned int area1
= mips_sym1
->global_got_area();
3024 unsigned int area2
= mips_sym2
->global_got_area();
3025 gold_assert(area1
!= GGA_NONE
&& area1
!= GGA_NONE
);
3027 // GGA_NORMAL entries always come before GGA_RELOC_ONLY.
3029 return area1
< area2
;
3031 return mips_sym1
->global_gotoffset() < mips_sym2
->global_gotoffset();
3034 // This method divides dynamic symbols into symbols that have GOT entry, and
3035 // symbols that don't have GOT entry. It also sorts symbols with the GOT entry.
3036 // Mips ABI requires that symbols with the GOT entry must be at the end of
3037 // dynamic symbol table, and the order in dynamic symbol table must match the
3040 template<int size
, bool big_endian
>
3042 reorder_dyn_symbols(std::vector
<Symbol
*>* dyn_symbols
,
3043 std::vector
<Symbol
*>* non_got_symbols
,
3044 std::vector
<Symbol
*>* got_symbols
)
3046 for (std::vector
<Symbol
*>::iterator p
= dyn_symbols
->begin();
3047 p
!= dyn_symbols
->end();
3050 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(*p
);
3051 if (mips_sym
->global_got_area() == GGA_NORMAL
3052 || mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
3053 got_symbols
->push_back(mips_sym
);
3055 non_got_symbols
->push_back(mips_sym
);
3058 std::sort(got_symbols
->begin(), got_symbols
->end(),
3059 got_offset_compare
<size
, big_endian
>);
3062 // Functor class for processing the global symbol table.
3064 template<int size
, bool big_endian
>
3065 class Symbol_visitor_check_symbols
3068 Symbol_visitor_check_symbols(Target_mips
<size
, big_endian
>* target
,
3069 Layout
* layout
, Symbol_table
* symtab
)
3070 : target_(target
), layout_(layout
), symtab_(symtab
)
3074 operator()(Sized_symbol
<size
>* sym
)
3076 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
3077 if (local_pic_function
<size
, big_endian
>(mips_sym
))
3079 // SYM is a function that might need $25 to be valid on entry.
3080 // If we're creating a non-PIC relocatable object, mark SYM as
3081 // being PIC. If we're creating a non-relocatable object with
3082 // non-PIC branches and jumps to SYM, make sure that SYM has an la25
3084 if (parameters
->options().relocatable())
3086 if (!parameters
->options().output_is_position_independent())
3087 mips_sym
->set_pic();
3089 else if (mips_sym
->has_nonpic_branches())
3091 this->target_
->la25_stub_section(layout_
)
3092 ->create_la25_stub(this->symtab_
, this->target_
, mips_sym
);
3098 Target_mips
<size
, big_endian
>* target_
;
3100 Symbol_table
* symtab_
;
3103 // Relocation types, parameterized by SHT_REL vs. SHT_RELA, size,
3104 // and endianness. The relocation format for MIPS-64 is non-standard.
3106 template<int sh_type
, int size
, bool big_endian
>
3107 struct Mips_reloc_types
;
3109 template<bool big_endian
>
3110 struct Mips_reloc_types
<elfcpp::SHT_REL
, 32, big_endian
>
3112 typedef typename
elfcpp::Rel
<32, big_endian
> Reloc
;
3113 typedef typename
elfcpp::Rel_write
<32, big_endian
> Reloc_write
;
3115 static typename
elfcpp::Elf_types
<32>::Elf_Swxword
3116 get_r_addend(const Reloc
*)
3120 set_reloc_addend(Reloc_write
*,
3121 typename
elfcpp::Elf_types
<32>::Elf_Swxword
)
3122 { gold_unreachable(); }
3125 template<bool big_endian
>
3126 struct Mips_reloc_types
<elfcpp::SHT_RELA
, 32, big_endian
>
3128 typedef typename
elfcpp::Rela
<32, big_endian
> Reloc
;
3129 typedef typename
elfcpp::Rela_write
<32, big_endian
> Reloc_write
;
3131 static typename
elfcpp::Elf_types
<32>::Elf_Swxword
3132 get_r_addend(const Reloc
* reloc
)
3133 { return reloc
->get_r_addend(); }
3136 set_reloc_addend(Reloc_write
* p
,
3137 typename
elfcpp::Elf_types
<32>::Elf_Swxword val
)
3138 { p
->put_r_addend(val
); }
3141 template<bool big_endian
>
3142 struct Mips_reloc_types
<elfcpp::SHT_REL
, 64, big_endian
>
3144 typedef typename
elfcpp::Mips64_rel
<big_endian
> Reloc
;
3145 typedef typename
elfcpp::Mips64_rel_write
<big_endian
> Reloc_write
;
3147 static typename
elfcpp::Elf_types
<64>::Elf_Swxword
3148 get_r_addend(const Reloc
*)
3152 set_reloc_addend(Reloc_write
*,
3153 typename
elfcpp::Elf_types
<64>::Elf_Swxword
)
3154 { gold_unreachable(); }
3157 template<bool big_endian
>
3158 struct Mips_reloc_types
<elfcpp::SHT_RELA
, 64, big_endian
>
3160 typedef typename
elfcpp::Mips64_rela
<big_endian
> Reloc
;
3161 typedef typename
elfcpp::Mips64_rela_write
<big_endian
> Reloc_write
;
3163 static typename
elfcpp::Elf_types
<64>::Elf_Swxword
3164 get_r_addend(const Reloc
* reloc
)
3165 { return reloc
->get_r_addend(); }
3168 set_reloc_addend(Reloc_write
* p
,
3169 typename
elfcpp::Elf_types
<64>::Elf_Swxword val
)
3170 { p
->put_r_addend(val
); }
3173 // Forward declaration.
3175 mips_get_size_for_reloc(unsigned int, Relobj
*);
3177 // A class for inquiring about properties of a relocation,
3178 // used while scanning relocs during a relocatable link and
3179 // garbage collection.
3181 template<int sh_type_
, int size
, bool big_endian
>
3182 class Mips_classify_reloc
;
3184 template<int sh_type_
, bool big_endian
>
3185 class Mips_classify_reloc
<sh_type_
, 32, big_endian
> :
3186 public gold::Default_classify_reloc
<sh_type_
, 32, big_endian
>
3189 typedef typename Mips_reloc_types
<sh_type_
, 32, big_endian
>::Reloc
3191 typedef typename Mips_reloc_types
<sh_type_
, 32, big_endian
>::Reloc_write
3194 // Return the symbol referred to by the relocation.
3195 static inline unsigned int
3196 get_r_sym(const Reltype
* reloc
)
3197 { return elfcpp::elf_r_sym
<32>(reloc
->get_r_info()); }
3199 // Return the type of the relocation.
3200 static inline unsigned int
3201 get_r_type(const Reltype
* reloc
)
3202 { return elfcpp::elf_r_type
<32>(reloc
->get_r_info()); }
3204 static inline unsigned int
3205 get_r_type2(const Reltype
*)
3208 static inline unsigned int
3209 get_r_type3(const Reltype
*)
3212 static inline unsigned int
3213 get_r_ssym(const Reltype
*)
3216 // Return the explicit addend of the relocation (return 0 for SHT_REL).
3217 static inline unsigned int
3218 get_r_addend(const Reltype
* reloc
)
3220 if (sh_type_
== elfcpp::SHT_REL
)
3222 return Mips_reloc_types
<sh_type_
, 32, big_endian
>::get_r_addend(reloc
);
3225 // Write the r_info field to a new reloc, using the r_info field from
3226 // the original reloc, replacing the r_sym field with R_SYM.
3228 put_r_info(Reltype_write
* new_reloc
, Reltype
* reloc
, unsigned int r_sym
)
3230 unsigned int r_type
= elfcpp::elf_r_type
<32>(reloc
->get_r_info());
3231 new_reloc
->put_r_info(elfcpp::elf_r_info
<32>(r_sym
, r_type
));
3234 // Write the r_addend field to a new reloc.
3236 put_r_addend(Reltype_write
* to
,
3237 typename
elfcpp::Elf_types
<32>::Elf_Swxword addend
)
3238 { Mips_reloc_types
<sh_type_
, 32, big_endian
>::set_reloc_addend(to
, addend
); }
3240 // Return the size of the addend of the relocation (only used for SHT_REL).
3242 get_size_for_reloc(unsigned int r_type
, Relobj
* obj
)
3243 { return mips_get_size_for_reloc(r_type
, obj
); }
3246 template<int sh_type_
, bool big_endian
>
3247 class Mips_classify_reloc
<sh_type_
, 64, big_endian
> :
3248 public gold::Default_classify_reloc
<sh_type_
, 64, big_endian
>
3251 typedef typename Mips_reloc_types
<sh_type_
, 64, big_endian
>::Reloc
3253 typedef typename Mips_reloc_types
<sh_type_
, 64, big_endian
>::Reloc_write
3256 // Return the symbol referred to by the relocation.
3257 static inline unsigned int
3258 get_r_sym(const Reltype
* reloc
)
3259 { return reloc
->get_r_sym(); }
3261 // Return the r_type of the relocation.
3262 static inline unsigned int
3263 get_r_type(const Reltype
* reloc
)
3264 { return reloc
->get_r_type(); }
3266 // Return the r_type2 of the relocation.
3267 static inline unsigned int
3268 get_r_type2(const Reltype
* reloc
)
3269 { return reloc
->get_r_type2(); }
3271 // Return the r_type3 of the relocation.
3272 static inline unsigned int
3273 get_r_type3(const Reltype
* reloc
)
3274 { return reloc
->get_r_type3(); }
3276 // Return the special symbol of the relocation.
3277 static inline unsigned int
3278 get_r_ssym(const Reltype
* reloc
)
3279 { return reloc
->get_r_ssym(); }
3281 // Return the explicit addend of the relocation (return 0 for SHT_REL).
3282 static inline typename
elfcpp::Elf_types
<64>::Elf_Swxword
3283 get_r_addend(const Reltype
* reloc
)
3285 if (sh_type_
== elfcpp::SHT_REL
)
3287 return Mips_reloc_types
<sh_type_
, 64, big_endian
>::get_r_addend(reloc
);
3290 // Write the r_info field to a new reloc, using the r_info field from
3291 // the original reloc, replacing the r_sym field with R_SYM.
3293 put_r_info(Reltype_write
* new_reloc
, Reltype
* reloc
, unsigned int r_sym
)
3295 new_reloc
->put_r_sym(r_sym
);
3296 new_reloc
->put_r_ssym(reloc
->get_r_ssym());
3297 new_reloc
->put_r_type3(reloc
->get_r_type3());
3298 new_reloc
->put_r_type2(reloc
->get_r_type2());
3299 new_reloc
->put_r_type(reloc
->get_r_type());
3302 // Write the r_addend field to a new reloc.
3304 put_r_addend(Reltype_write
* to
,
3305 typename
elfcpp::Elf_types
<64>::Elf_Swxword addend
)
3306 { Mips_reloc_types
<sh_type_
, 64, big_endian
>::set_reloc_addend(to
, addend
); }
3308 // Return the size of the addend of the relocation (only used for SHT_REL).
3310 get_size_for_reloc(unsigned int r_type
, Relobj
* obj
)
3311 { return mips_get_size_for_reloc(r_type
, obj
); }
3314 template<int size
, bool big_endian
>
3315 class Target_mips
: public Sized_target
<size
, big_endian
>
3317 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
3318 typedef Mips_output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
3320 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
3321 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
3322 typedef typename Mips_reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
3324 typedef typename Mips_reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
3328 Target_mips(const Target::Target_info
* info
= &mips_info
)
3329 : Sized_target
<size
, big_endian
>(info
), got_(NULL
), gp_(NULL
), plt_(NULL
),
3330 got_plt_(NULL
), rel_dyn_(NULL
), rld_map_(NULL
), copy_relocs_(),
3331 dyn_relocs_(), la25_stub_(NULL
), mips_mach_extensions_(),
3332 mips_stubs_(NULL
), attributes_section_data_(NULL
), abiflags_(NULL
),
3333 mach_(0), layout_(NULL
), got16_addends_(), has_abiflags_section_(false),
3334 entry_symbol_is_compressed_(false), insn32_(false)
3336 this->add_machine_extensions();
3339 // The offset of $gp from the beginning of the .got section.
3340 static const unsigned int MIPS_GP_OFFSET
= 0x7ff0;
3342 // The maximum size of the GOT for it to be addressable using 16-bit
3343 // offsets from $gp.
3344 static const unsigned int MIPS_GOT_MAX_SIZE
= MIPS_GP_OFFSET
+ 0x7fff;
3346 // Make a new symbol table entry for the Mips target.
3348 make_symbol(const char*, elfcpp::STT
, Object
*, unsigned int, uint64_t)
3349 { return new Mips_symbol
<size
>(); }
3351 // Process the relocations to determine unreferenced sections for
3352 // garbage collection.
3354 gc_process_relocs(Symbol_table
* symtab
,
3356 Sized_relobj_file
<size
, big_endian
>* object
,
3357 unsigned int data_shndx
,
3358 unsigned int sh_type
,
3359 const unsigned char* prelocs
,
3361 Output_section
* output_section
,
3362 bool needs_special_offset_handling
,
3363 size_t local_symbol_count
,
3364 const unsigned char* plocal_symbols
);
3366 // Scan the relocations to look for symbol adjustments.
3368 scan_relocs(Symbol_table
* symtab
,
3370 Sized_relobj_file
<size
, big_endian
>* object
,
3371 unsigned int data_shndx
,
3372 unsigned int sh_type
,
3373 const unsigned char* prelocs
,
3375 Output_section
* output_section
,
3376 bool needs_special_offset_handling
,
3377 size_t local_symbol_count
,
3378 const unsigned char* plocal_symbols
);
3380 // Finalize the sections.
3382 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
3384 // Relocate a section.
3386 relocate_section(const Relocate_info
<size
, big_endian
>*,
3387 unsigned int sh_type
,
3388 const unsigned char* prelocs
,
3390 Output_section
* output_section
,
3391 bool needs_special_offset_handling
,
3392 unsigned char* view
,
3393 Mips_address view_address
,
3394 section_size_type view_size
,
3395 const Reloc_symbol_changes
*);
3397 // Scan the relocs during a relocatable link.
3399 scan_relocatable_relocs(Symbol_table
* symtab
,
3401 Sized_relobj_file
<size
, big_endian
>* object
,
3402 unsigned int data_shndx
,
3403 unsigned int sh_type
,
3404 const unsigned char* prelocs
,
3406 Output_section
* output_section
,
3407 bool needs_special_offset_handling
,
3408 size_t local_symbol_count
,
3409 const unsigned char* plocal_symbols
,
3410 Relocatable_relocs
*);
3412 // Scan the relocs for --emit-relocs.
3414 emit_relocs_scan(Symbol_table
* symtab
,
3416 Sized_relobj_file
<size
, big_endian
>* object
,
3417 unsigned int data_shndx
,
3418 unsigned int sh_type
,
3419 const unsigned char* prelocs
,
3421 Output_section
* output_section
,
3422 bool needs_special_offset_handling
,
3423 size_t local_symbol_count
,
3424 const unsigned char* plocal_syms
,
3425 Relocatable_relocs
* rr
);
3427 // Emit relocations for a section.
3429 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
3430 unsigned int sh_type
,
3431 const unsigned char* prelocs
,
3433 Output_section
* output_section
,
3434 typename
elfcpp::Elf_types
<size
>::Elf_Off
3435 offset_in_output_section
,
3436 unsigned char* view
,
3437 Mips_address view_address
,
3438 section_size_type view_size
,
3439 unsigned char* reloc_view
,
3440 section_size_type reloc_view_size
);
3442 // Perform target-specific processing in a relocatable link. This is
3443 // only used if we use the relocation strategy RELOC_SPECIAL.
3445 relocate_special_relocatable(const Relocate_info
<size
, big_endian
>* relinfo
,
3446 unsigned int sh_type
,
3447 const unsigned char* preloc_in
,
3449 Output_section
* output_section
,
3450 typename
elfcpp::Elf_types
<size
>::Elf_Off
3451 offset_in_output_section
,
3452 unsigned char* view
,
3453 Mips_address view_address
,
3454 section_size_type view_size
,
3455 unsigned char* preloc_out
);
3457 // Return whether SYM is defined by the ABI.
3459 do_is_defined_by_abi(const Symbol
* sym
) const
3461 return ((strcmp(sym
->name(), "__gnu_local_gp") == 0)
3462 || (strcmp(sym
->name(), "_gp_disp") == 0)
3463 || (strcmp(sym
->name(), "___tls_get_addr") == 0));
3466 // Return the number of entries in the GOT.
3468 got_entry_count() const
3470 if (!this->has_got_section())
3472 return this->got_size() / (size
/8);
3475 // Return the number of entries in the PLT.
3477 plt_entry_count() const
3479 if (this->plt_
== NULL
)
3481 return this->plt_
->entry_count();
3484 // Return the offset of the first non-reserved PLT entry.
3486 first_plt_entry_offset() const
3487 { return this->plt_
->first_plt_entry_offset(); }
3489 // Return the size of each PLT entry.
3491 plt_entry_size() const
3492 { return this->plt_
->plt_entry_size(); }
3494 // Get the GOT section, creating it if necessary.
3495 Mips_output_data_got
<size
, big_endian
>*
3496 got_section(Symbol_table
*, Layout
*);
3498 // Get the GOT section.
3499 Mips_output_data_got
<size
, big_endian
>*
3502 gold_assert(this->got_
!= NULL
);
3506 // Get the .MIPS.stubs section, creating it if necessary.
3507 Mips_output_data_mips_stubs
<size
, big_endian
>*
3508 mips_stubs_section(Layout
* layout
);
3510 // Get the .MIPS.stubs section.
3511 Mips_output_data_mips_stubs
<size
, big_endian
>*
3512 mips_stubs_section() const
3514 gold_assert(this->mips_stubs_
!= NULL
);
3515 return this->mips_stubs_
;
3518 // Get the LA25 stub section, creating it if necessary.
3519 Mips_output_data_la25_stub
<size
, big_endian
>*
3520 la25_stub_section(Layout
*);
3522 // Get the LA25 stub section.
3523 Mips_output_data_la25_stub
<size
, big_endian
>*
3526 gold_assert(this->la25_stub_
!= NULL
);
3527 return this->la25_stub_
;
3530 // Get gp value. It has the value of .got + 0x7FF0.
3534 if (this->gp_
!= NULL
)
3535 return this->gp_
->value();
3539 // Get gp value. It has the value of .got + 0x7FF0. Adjust it for
3540 // multi-GOT links so that OBJECT's GOT + 0x7FF0 is returned.
3542 adjusted_gp_value(const Mips_relobj
<size
, big_endian
>* object
)
3544 if (this->gp_
== NULL
)
3547 bool multi_got
= false;
3548 if (this->has_got_section())
3549 multi_got
= this->got_section()->multi_got();
3551 return this->gp_
->value();
3553 return this->gp_
->value() + this->got_section()->get_got_offset(object
);
3556 // Get the dynamic reloc section, creating it if necessary.
3558 rel_dyn_section(Layout
*);
3561 do_has_custom_set_dynsym_indexes() const
3564 // Don't emit input .reginfo/.MIPS.abiflags sections to
3565 // output .reginfo/.MIPS.abiflags.
3567 do_should_include_section(elfcpp::Elf_Word sh_type
) const
3569 return ((sh_type
!= elfcpp::SHT_MIPS_REGINFO
)
3570 && (sh_type
!= elfcpp::SHT_MIPS_ABIFLAGS
));
3573 // Set the dynamic symbol indexes. INDEX is the index of the first
3574 // global dynamic symbol. Pointers to the symbols are stored into the
3575 // vector SYMS. The names are added to DYNPOOL. This returns an
3576 // updated dynamic symbol index.
3578 do_set_dynsym_indexes(std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
3579 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
3580 Versions
* versions
, Symbol_table
* symtab
) const;
3582 // Remove .MIPS.stubs entry for a symbol.
3584 remove_lazy_stub_entry(Mips_symbol
<size
>* sym
)
3586 if (this->mips_stubs_
!= NULL
)
3587 this->mips_stubs_
->remove_entry(sym
);
3590 // The value to write into got[1] for SVR4 targets, to identify it is
3591 // a GNU object. The dynamic linker can then use got[1] to store the
3594 mips_elf_gnu_got1_mask()
3596 if (this->is_output_n64())
3597 return (uint64_t)1 << 63;
3602 // Whether the output has microMIPS code. This is valid only after
3603 // merge_obj_e_flags() is called.
3605 is_output_micromips() const
3607 gold_assert(this->are_processor_specific_flags_set());
3608 return elfcpp::is_micromips(this->processor_specific_flags());
3611 // Whether the output uses N32 ABI. This is valid only after
3612 // merge_obj_e_flags() is called.
3614 is_output_n32() const
3616 gold_assert(this->are_processor_specific_flags_set());
3617 return elfcpp::abi_n32(this->processor_specific_flags());
3620 // Whether the output uses R6 ISA. This is valid only after
3621 // merge_obj_e_flags() is called.
3623 is_output_r6() const
3625 gold_assert(this->are_processor_specific_flags_set());
3626 return elfcpp::r6_isa(this->processor_specific_flags());
3629 // Whether the output uses N64 ABI.
3631 is_output_n64() const
3632 { return size
== 64; }
3634 // Whether the output uses NEWABI. This is valid only after
3635 // merge_obj_e_flags() is called.
3637 is_output_newabi() const
3638 { return this->is_output_n32() || this->is_output_n64(); }
3640 // Whether we can only use 32-bit microMIPS instructions.
3642 use_32bit_micromips_instructions() const
3643 { return this->insn32_
; }
3645 // Return the r_sym field from a relocation.
3647 get_r_sym(const unsigned char* preloc
) const
3649 // Since REL and RELA relocs share the same structure through
3650 // the r_info field, we can just use REL here.
3651 Reltype
rel(preloc
);
3652 return Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
3657 // Return the value to use for a dynamic symbol which requires special
3658 // treatment. This is how we support equality comparisons of function
3659 // pointers across shared library boundaries, as described in the
3660 // processor specific ABI supplement.
3662 do_dynsym_value(const Symbol
* gsym
) const;
3664 // Make an ELF object.
3666 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
3667 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
);
3670 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
3671 const elfcpp::Ehdr
<size
, !big_endian
>&)
3672 { gold_unreachable(); }
3674 // Make an output section.
3676 do_make_output_section(const char* name
, elfcpp::Elf_Word type
,
3677 elfcpp::Elf_Xword flags
)
3679 if (type
== elfcpp::SHT_MIPS_OPTIONS
)
3680 return new Mips_output_section_options
<size
, big_endian
>(name
, type
,
3683 return new Output_section(name
, type
, flags
);
3686 // Adjust ELF file header.
3688 do_adjust_elf_header(unsigned char* view
, int len
);
3690 // Get the custom dynamic tag value.
3692 do_dynamic_tag_custom_value(elfcpp::DT
) const;
3694 // Adjust the value written to the dynamic symbol table.
3696 do_adjust_dyn_symbol(const Symbol
* sym
, unsigned char* view
) const
3698 elfcpp::Sym
<size
, big_endian
> isym(view
);
3699 elfcpp::Sym_write
<size
, big_endian
> osym(view
);
3700 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
3702 // Keep dynamic compressed symbols odd. This allows the dynamic linker
3703 // to treat compressed symbols like any other.
3704 Mips_address value
= isym
.get_st_value();
3705 if (mips_sym
->is_mips16() && value
!= 0)
3707 if (!mips_sym
->has_mips16_fn_stub())
3711 // If we have a MIPS16 function with a stub, the dynamic symbol
3712 // must refer to the stub, since only the stub uses the standard
3713 // calling conventions. Stub contains MIPS32 code, so don't add +1
3716 // There is a code which does this in the method
3717 // Target_mips::do_dynsym_value, but that code will only be
3718 // executed if the symbol is from dynobj.
3719 // TODO(sasa): GNU ld also changes the value in non-dynamic symbol
3722 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
3723 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
3724 value
= fn_stub
->output_address();
3725 osym
.put_st_size(fn_stub
->section_size());
3728 osym
.put_st_value(value
);
3729 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(),
3730 mips_sym
->nonvis() - (elfcpp::STO_MIPS16
>> 2)));
3732 else if ((mips_sym
->is_micromips()
3733 // Stubs are always microMIPS if there is any microMIPS code in
3735 || (this->is_output_micromips() && mips_sym
->has_lazy_stub()))
3738 osym
.put_st_value(value
| 1);
3739 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(),
3740 mips_sym
->nonvis() - (elfcpp::STO_MICROMIPS
>> 2)));
3745 // The class which scans relocations.
3753 get_reference_flags(unsigned int r_type
);
3756 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3757 Sized_relobj_file
<size
, big_endian
>* object
,
3758 unsigned int data_shndx
,
3759 Output_section
* output_section
,
3760 const Reltype
& reloc
, unsigned int r_type
,
3761 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3765 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3766 Sized_relobj_file
<size
, big_endian
>* object
,
3767 unsigned int data_shndx
,
3768 Output_section
* output_section
,
3769 const Relatype
& reloc
, unsigned int r_type
,
3770 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3774 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3775 Sized_relobj_file
<size
, big_endian
>* object
,
3776 unsigned int data_shndx
,
3777 Output_section
* output_section
,
3778 const Relatype
* rela
,
3780 unsigned int rel_type
,
3781 unsigned int r_type
,
3782 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3786 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3787 Sized_relobj_file
<size
, big_endian
>* object
,
3788 unsigned int data_shndx
,
3789 Output_section
* output_section
,
3790 const Reltype
& reloc
, unsigned int r_type
,
3794 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3795 Sized_relobj_file
<size
, big_endian
>* object
,
3796 unsigned int data_shndx
,
3797 Output_section
* output_section
,
3798 const Relatype
& reloc
, unsigned int r_type
,
3802 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3803 Sized_relobj_file
<size
, big_endian
>* object
,
3804 unsigned int data_shndx
,
3805 Output_section
* output_section
,
3806 const Relatype
* rela
,
3808 unsigned int rel_type
,
3809 unsigned int r_type
,
3813 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
*,
3815 Sized_relobj_file
<size
, big_endian
>*,
3820 const elfcpp::Sym
<size
, big_endian
>&)
3824 global_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3826 Sized_relobj_file
<size
, big_endian
>*,
3830 unsigned int, Symbol
*)
3834 local_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3836 Sized_relobj_file
<size
, big_endian
>*,
3841 const elfcpp::Sym
<size
, big_endian
>&)
3845 global_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3847 Sized_relobj_file
<size
, big_endian
>*,
3851 unsigned int, Symbol
*)
3855 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
3856 unsigned int r_type
);
3859 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
3860 unsigned int r_type
, Symbol
*);
3863 // The class which implements relocation.
3868 : calculated_value_(0), calculate_only_(false)
3874 // Return whether a R_MIPS_32/R_MIPS_64 relocation needs to be applied.
3876 should_apply_static_reloc(const Mips_symbol
<size
>* gsym
,
3877 unsigned int r_type
,
3878 Output_section
* output_section
,
3879 Target_mips
* target
);
3881 // Do a relocation. Return false if the caller should not issue
3882 // any warnings about this relocation.
3884 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
3885 Target_mips
*, Output_section
*, size_t, const unsigned char*,
3886 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
3887 unsigned char*, Mips_address
, section_size_type
);
3890 // Result of the relocation.
3891 Valtype calculated_value_
;
3892 // Whether we have to calculate relocation instead of applying it.
3893 bool calculate_only_
;
3896 // This POD class holds the dynamic relocations that should be emitted instead
3897 // of R_MIPS_32, R_MIPS_REL32 and R_MIPS_64 relocations. We will emit these
3898 // relocations if it turns out that the symbol does not have static
3903 Dyn_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
3904 Mips_relobj
<size
, big_endian
>* relobj
, unsigned int shndx
,
3905 Output_section
* output_section
, Mips_address r_offset
)
3906 : sym_(sym
), r_type_(r_type
), relobj_(relobj
),
3907 shndx_(shndx
), output_section_(output_section
),
3911 // Emit this reloc if appropriate. This is called after we have
3912 // scanned all the relocations, so we know whether the symbol has
3913 // static relocations.
3915 emit(Reloc_section
* rel_dyn
, Mips_output_data_got
<size
, big_endian
>* got
,
3916 Symbol_table
* symtab
)
3918 if (!this->sym_
->has_static_relocs())
3920 got
->record_global_got_symbol(this->sym_
, this->relobj_
,
3921 this->r_type_
, true, false);
3922 if (!symbol_references_local(this->sym_
,
3923 this->sym_
->should_add_dynsym_entry(symtab
)))
3924 rel_dyn
->add_global(this->sym_
, this->r_type_
,
3925 this->output_section_
, this->relobj_
,
3926 this->shndx_
, this->r_offset_
);
3928 rel_dyn
->add_symbolless_global_addend(this->sym_
, this->r_type_
,
3929 this->output_section_
, this->relobj_
,
3930 this->shndx_
, this->r_offset_
);
3935 Mips_symbol
<size
>* sym_
;
3936 unsigned int r_type_
;
3937 Mips_relobj
<size
, big_endian
>* relobj_
;
3938 unsigned int shndx_
;
3939 Output_section
* output_section_
;
3940 Mips_address r_offset_
;
3943 // Adjust TLS relocation type based on the options and whether this
3944 // is a local symbol.
3945 static tls::Tls_optimization
3946 optimize_tls_reloc(bool is_final
, int r_type
);
3948 // Return whether there is a GOT section.
3950 has_got_section() const
3951 { return this->got_
!= NULL
; }
3953 // Check whether the given ELF header flags describe a 32-bit binary.
3955 mips_32bit_flags(elfcpp::Elf_Word
);
3958 mach_mips3000
= 3000,
3959 mach_mips3900
= 3900,
3960 mach_mips4000
= 4000,
3961 mach_mips4010
= 4010,
3962 mach_mips4100
= 4100,
3963 mach_mips4111
= 4111,
3964 mach_mips4120
= 4120,
3965 mach_mips4300
= 4300,
3966 mach_mips4400
= 4400,
3967 mach_mips4600
= 4600,
3968 mach_mips4650
= 4650,
3969 mach_mips5000
= 5000,
3970 mach_mips5400
= 5400,
3971 mach_mips5500
= 5500,
3972 mach_mips5900
= 5900,
3973 mach_mips6000
= 6000,
3974 mach_mips7000
= 7000,
3975 mach_mips8000
= 8000,
3976 mach_mips9000
= 9000,
3977 mach_mips10000
= 10000,
3978 mach_mips12000
= 12000,
3979 mach_mips14000
= 14000,
3980 mach_mips16000
= 16000,
3983 mach_mips_loongson_2e
= 3001,
3984 mach_mips_loongson_2f
= 3002,
3985 mach_mips_gs464
= 3003,
3986 mach_mips_gs464e
= 3004,
3987 mach_mips_gs264e
= 3005,
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_gs264e
, mach_mips_gs464e
);
4154 this->add_extension(mach_mips_gs464e
, mach_mips_gs464
);
4155 this->add_extension(mach_mips_gs464
, mach_mipsisa64r2
);
4157 // MIPS64 extensions.
4158 this->add_extension(mach_mipsisa64r2
, mach_mipsisa64
);
4159 this->add_extension(mach_mips_sb1
, mach_mipsisa64
);
4160 this->add_extension(mach_mips_xlr
, mach_mipsisa64
);
4162 // MIPS V extensions.
4163 this->add_extension(mach_mipsisa64
, mach_mips5
);
4165 // R10000 extensions.
4166 this->add_extension(mach_mips12000
, mach_mips10000
);
4167 this->add_extension(mach_mips14000
, mach_mips10000
);
4168 this->add_extension(mach_mips16000
, mach_mips10000
);
4170 // R5000 extensions. Note: the vr5500 ISA is an extension of the core
4171 // vr5400 ISA, but doesn't include the multimedia stuff. It seems
4172 // better to allow vr5400 and vr5500 code to be merged anyway, since
4173 // many libraries will just use the core ISA. Perhaps we could add
4174 // some sort of ASE flag if this ever proves a problem.
4175 this->add_extension(mach_mips5500
, mach_mips5400
);
4176 this->add_extension(mach_mips5400
, mach_mips5000
);
4178 // MIPS IV extensions.
4179 this->add_extension(mach_mips5
, mach_mips8000
);
4180 this->add_extension(mach_mips10000
, mach_mips8000
);
4181 this->add_extension(mach_mips5000
, mach_mips8000
);
4182 this->add_extension(mach_mips7000
, mach_mips8000
);
4183 this->add_extension(mach_mips9000
, mach_mips8000
);
4185 // VR4100 extensions.
4186 this->add_extension(mach_mips4120
, mach_mips4100
);
4187 this->add_extension(mach_mips4111
, mach_mips4100
);
4189 // MIPS III extensions.
4190 this->add_extension(mach_mips_loongson_2e
, mach_mips4000
);
4191 this->add_extension(mach_mips_loongson_2f
, mach_mips4000
);
4192 this->add_extension(mach_mips8000
, mach_mips4000
);
4193 this->add_extension(mach_mips4650
, mach_mips4000
);
4194 this->add_extension(mach_mips4600
, mach_mips4000
);
4195 this->add_extension(mach_mips4400
, mach_mips4000
);
4196 this->add_extension(mach_mips4300
, mach_mips4000
);
4197 this->add_extension(mach_mips4100
, mach_mips4000
);
4198 this->add_extension(mach_mips4010
, mach_mips4000
);
4199 this->add_extension(mach_mips5900
, mach_mips4000
);
4201 // MIPS32 extensions.
4202 this->add_extension(mach_mipsisa32r2
, mach_mipsisa32
);
4204 // MIPS II extensions.
4205 this->add_extension(mach_mips4000
, mach_mips6000
);
4206 this->add_extension(mach_mipsisa32
, mach_mips6000
);
4208 // MIPS I extensions.
4209 this->add_extension(mach_mips6000
, mach_mips3000
);
4210 this->add_extension(mach_mips3900
, mach_mips3000
);
4213 // Add value to MIPS extenstions.
4215 add_extension(unsigned int base
, unsigned int extension
)
4217 std::pair
<unsigned int, unsigned int> ext(base
, extension
);
4218 this->mips_mach_extensions_
.push_back(ext
);
4221 // Return the number of entries in the .dynsym section.
4222 unsigned int get_dt_mips_symtabno() const
4224 return ((unsigned int)(this->layout_
->dynsym_section()->data_size()
4225 / elfcpp::Elf_sizes
<size
>::sym_size
));
4226 // TODO(sasa): Entry size is MIPS_ELF_SYM_SIZE.
4229 // Information about this specific target which we pass to the
4230 // general Target structure.
4231 static const Target::Target_info mips_info
;
4233 Mips_output_data_got
<size
, big_endian
>* got_
;
4234 // gp symbol. It has the value of .got + 0x7FF0.
4235 Sized_symbol
<size
>* gp_
;
4237 Mips_output_data_plt
<size
, big_endian
>* plt_
;
4238 // The GOT PLT section.
4239 Output_data_space
* got_plt_
;
4240 // The dynamic reloc section.
4241 Reloc_section
* rel_dyn_
;
4242 // The .rld_map section.
4243 Output_data_zero_fill
* rld_map_
;
4244 // Relocs saved to avoid a COPY reloc.
4245 Mips_copy_relocs
<elfcpp::SHT_REL
, size
, big_endian
> copy_relocs_
;
4247 // A list of dyn relocs to be saved.
4248 std::vector
<Dyn_reloc
> dyn_relocs_
;
4250 // The LA25 stub section.
4251 Mips_output_data_la25_stub
<size
, big_endian
>* la25_stub_
;
4252 // Architecture extensions.
4253 std::vector
<std::pair
<unsigned int, unsigned int> > mips_mach_extensions_
;
4255 Mips_output_data_mips_stubs
<size
, big_endian
>* mips_stubs_
;
4257 // Attributes section data in output.
4258 Attributes_section_data
* attributes_section_data_
;
4259 // .MIPS.abiflags section data in output.
4260 Mips_abiflags
<big_endian
>* abiflags_
;
4265 typename
std::list
<got16_addend
<size
, big_endian
> > got16_addends_
;
4267 // Whether there is an input .MIPS.abiflags section.
4268 bool has_abiflags_section_
;
4270 // Whether the entry symbol is mips16 or micromips.
4271 bool entry_symbol_is_compressed_
;
4273 // Whether we can use only 32-bit microMIPS instructions.
4274 // TODO(sasa): This should be a linker option.
4278 // Helper structure for R_MIPS*_HI16/LO16 and R_MIPS*_GOT16/LO16 relocations.
4279 // It records high part of the relocation pair.
4281 template<int size
, bool big_endian
>
4284 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
4286 reloc_high(unsigned char* _view
, const Mips_relobj
<size
, big_endian
>* _object
,
4287 const Symbol_value
<size
>* _psymval
, Mips_address _addend
,
4288 unsigned int _r_type
, unsigned int _r_sym
, bool _extract_addend
,
4289 Mips_address _address
= 0, bool _gp_disp
= false)
4290 : view(_view
), object(_object
), psymval(_psymval
), addend(_addend
),
4291 r_type(_r_type
), r_sym(_r_sym
), extract_addend(_extract_addend
),
4292 address(_address
), gp_disp(_gp_disp
)
4295 unsigned char* view
;
4296 const Mips_relobj
<size
, big_endian
>* object
;
4297 const Symbol_value
<size
>* psymval
;
4298 Mips_address addend
;
4299 unsigned int r_type
;
4301 bool extract_addend
;
4302 Mips_address address
;
4306 template<int size
, bool big_endian
>
4307 class Mips_relocate_functions
: public Relocate_functions
<size
, big_endian
>
4309 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
4310 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
4311 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype16
;
4312 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
4313 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype64
;
4318 STATUS_OKAY
, // No error during relocation.
4319 STATUS_OVERFLOW
, // Relocation overflow.
4320 STATUS_BAD_RELOC
, // Relocation cannot be applied.
4321 STATUS_PCREL_UNALIGNED
// Unaligned PC-relative relocation.
4325 typedef Relocate_functions
<size
, big_endian
> Base
;
4326 typedef Mips_relocate_functions
<size
, big_endian
> This
;
4328 static typename
std::list
<reloc_high
<size
, big_endian
> > hi16_relocs
;
4329 static typename
std::list
<reloc_high
<size
, big_endian
> > got16_relocs
;
4330 static typename
std::list
<reloc_high
<size
, big_endian
> > pchi16_relocs
;
4332 template<int valsize
>
4333 static inline typename
This::Status
4334 check_overflow(Valtype value
)
4337 return (Bits
<valsize
>::has_overflow32(value
)
4338 ? This::STATUS_OVERFLOW
4339 : This::STATUS_OKAY
);
4341 return (Bits
<valsize
>::has_overflow(value
)
4342 ? This::STATUS_OVERFLOW
4343 : This::STATUS_OKAY
);
4347 should_shuffle_micromips_reloc(unsigned int r_type
)
4349 return (micromips_reloc(r_type
)
4350 && r_type
!= elfcpp::R_MICROMIPS_PC7_S1
4351 && r_type
!= elfcpp::R_MICROMIPS_PC10_S1
4352 && r_type
!= elfcpp::R_MICROMIPS_GPREL7_S2
);
4356 // R_MIPS16_26 is used for the mips16 jal and jalx instructions.
4357 // Most mips16 instructions are 16 bits, but these instructions
4360 // The format of these instructions is:
4362 // +--------------+--------------------------------+
4363 // | JALX | X| Imm 20:16 | Imm 25:21 |
4364 // +--------------+--------------------------------+
4365 // | Immediate 15:0 |
4366 // +-----------------------------------------------+
4368 // JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
4369 // Note that the immediate value in the first word is swapped.
4371 // When producing a relocatable object file, R_MIPS16_26 is
4372 // handled mostly like R_MIPS_26. In particular, the addend is
4373 // stored as a straight 26-bit value in a 32-bit instruction.
4374 // (gas makes life simpler for itself by never adjusting a
4375 // R_MIPS16_26 reloc to be against a section, so the addend is
4376 // always zero). However, the 32 bit instruction is stored as 2
4377 // 16-bit values, rather than a single 32-bit value. In a
4378 // big-endian file, the result is the same; in a little-endian
4379 // file, the two 16-bit halves of the 32 bit value are swapped.
4380 // This is so that a disassembler can recognize the jal
4383 // When doing a final link, R_MIPS16_26 is treated as a 32 bit
4384 // instruction stored as two 16-bit values. The addend A is the
4385 // contents of the targ26 field. The calculation is the same as
4386 // R_MIPS_26. When storing the calculated value, reorder the
4387 // immediate value as shown above, and don't forget to store the
4388 // value as two 16-bit values.
4390 // To put it in MIPS ABI terms, the relocation field is T-targ26-16,
4394 // +--------+----------------------+
4398 // +--------+----------------------+
4401 // +----------+------+-------------+
4403 // | sub1 | | sub2 |
4404 // |0 9|10 15|16 31|
4405 // +----------+--------------------+
4406 // where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
4407 // ((sub1 << 16) | sub2)).
4409 // When producing a relocatable object file, the calculation is
4410 // (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
4411 // When producing a fully linked file, the calculation is
4412 // let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
4413 // ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
4415 // The table below lists the other MIPS16 instruction relocations.
4416 // Each one is calculated in the same way as the non-MIPS16 relocation
4417 // given on the right, but using the extended MIPS16 layout of 16-bit
4418 // immediate fields:
4420 // R_MIPS16_GPREL R_MIPS_GPREL16
4421 // R_MIPS16_GOT16 R_MIPS_GOT16
4422 // R_MIPS16_CALL16 R_MIPS_CALL16
4423 // R_MIPS16_HI16 R_MIPS_HI16
4424 // R_MIPS16_LO16 R_MIPS_LO16
4426 // A typical instruction will have a format like this:
4428 // +--------------+--------------------------------+
4429 // | EXTEND | Imm 10:5 | Imm 15:11 |
4430 // +--------------+--------------------------------+
4431 // | Major | rx | ry | Imm 4:0 |
4432 // +--------------+--------------------------------+
4434 // EXTEND is the five bit value 11110. Major is the instruction
4437 // All we need to do here is shuffle the bits appropriately.
4438 // As above, the two 16-bit halves must be swapped on a
4439 // little-endian system.
4441 // Similar to MIPS16, the two 16-bit halves in microMIPS must be swapped
4442 // on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1,
4443 // R_MICROMIPS_PC10_S1 and R_MICROMIPS_GPREL7_S2 relocs that apply
4444 // to 16-bit instructions.
4447 mips_reloc_unshuffle(unsigned char* view
, unsigned int r_type
,
4450 if (!mips16_reloc(r_type
)
4451 && !should_shuffle_micromips_reloc(r_type
))
4454 // Pick up the first and second halfwords of the instruction.
4455 Valtype16 first
= elfcpp::Swap
<16, big_endian
>::readval(view
);
4456 Valtype16 second
= elfcpp::Swap
<16, big_endian
>::readval(view
+ 2);
4459 if (micromips_reloc(r_type
)
4460 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
4461 val
= first
<< 16 | second
;
4462 else if (r_type
!= elfcpp::R_MIPS16_26
)
4463 val
= (((first
& 0xf800) << 16) | ((second
& 0xffe0) << 11)
4464 | ((first
& 0x1f) << 11) | (first
& 0x7e0) | (second
& 0x1f));
4466 val
= (((first
& 0xfc00) << 16) | ((first
& 0x3e0) << 11)
4467 | ((first
& 0x1f) << 21) | second
);
4469 elfcpp::Swap
<32, big_endian
>::writeval(view
, val
);
4473 mips_reloc_shuffle(unsigned char* view
, unsigned int r_type
, bool jal_shuffle
)
4475 if (!mips16_reloc(r_type
)
4476 && !should_shuffle_micromips_reloc(r_type
))
4479 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4480 Valtype16 first
, second
;
4482 if (micromips_reloc(r_type
)
4483 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
4485 second
= val
& 0xffff;
4488 else if (r_type
!= elfcpp::R_MIPS16_26
)
4490 second
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
4491 first
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
4495 second
= val
& 0xffff;
4496 first
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
4497 | ((val
>> 21) & 0x1f);
4500 elfcpp::Swap
<16, big_endian
>::writeval(view
+ 2, second
);
4501 elfcpp::Swap
<16, big_endian
>::writeval(view
, first
);
4504 // R_MIPS_16: S + sign-extend(A)
4505 static inline typename
This::Status
4506 rel16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4507 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4508 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
4510 Valtype16
* wv
= reinterpret_cast<Valtype16
*>(view
);
4511 Valtype16 val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
4513 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
)
4516 Valtype x
= psymval
->value(object
, addend
);
4517 val
= Bits
<16>::bit_select32(val
, x
, 0xffffU
);
4521 *calculated_value
= x
;
4522 return This::STATUS_OKAY
;
4525 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
4527 return check_overflow
<16>(x
);
4531 static inline typename
This::Status
4532 rel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4533 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4534 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
4536 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4537 Valtype addend
= (extract_addend
4538 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
4540 Valtype x
= psymval
->value(object
, addend
);
4543 *calculated_value
= x
;
4545 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4547 return This::STATUS_OKAY
;
4550 // R_MIPS_JALR, R_MICROMIPS_JALR
4551 static inline typename
This::Status
4552 reljalr(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4553 const Symbol_value
<size
>* psymval
, Mips_address address
,
4554 Mips_address addend_a
, bool extract_addend
, bool cross_mode_jump
,
4555 unsigned int r_type
, bool jalr_to_bal
, bool jr_to_b
,
4556 bool calculate_only
, Valtype
* calculated_value
)
4558 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4559 Valtype addend
= extract_addend
? 0 : addend_a
;
4560 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4562 // Try converting J(AL)R to B(AL), if the target is in range.
4563 if (r_type
== elfcpp::R_MIPS_JALR
4565 && ((jalr_to_bal
&& val
== 0x0320f809) // jalr t9
4566 || (jr_to_b
&& val
== 0x03200008))) // jr t9
4568 int offset
= psymval
->value(object
, addend
) - (address
+ 4);
4569 if (!Bits
<18>::has_overflow32(offset
))
4571 if (val
== 0x03200008) // jr t9
4572 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4574 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4579 *calculated_value
= val
;
4581 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4583 return This::STATUS_OKAY
;
4586 // R_MIPS_PC32: S + A - P
4587 static inline typename
This::Status
4588 relpc32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4589 const Symbol_value
<size
>* psymval
, Mips_address address
,
4590 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4591 Valtype
* calculated_value
)
4593 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4594 Valtype addend
= (extract_addend
4595 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
4597 Valtype x
= psymval
->value(object
, addend
) - address
;
4600 *calculated_value
= x
;
4602 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4604 return This::STATUS_OKAY
;
4607 // R_MIPS_26, R_MIPS16_26, R_MICROMIPS_26_S1
4608 static inline typename
This::Status
4609 rel26(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4610 const Symbol_value
<size
>* psymval
, Mips_address address
,
4611 bool local
, Mips_address addend_a
, bool extract_addend
,
4612 const Symbol
* gsym
, bool cross_mode_jump
, unsigned int r_type
,
4613 bool jal_to_bal
, bool calculate_only
, Valtype
* calculated_value
)
4615 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4616 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4621 if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4622 addend
= (val
& 0x03ffffff) << 1;
4624 addend
= (val
& 0x03ffffff) << 2;
4629 // Make sure the target of JALX is word-aligned. Bit 0 must be
4630 // the correct ISA mode selector and bit 1 must be 0.
4631 if (!calculate_only
&& cross_mode_jump
4632 && (psymval
->value(object
, 0) & 3) != (r_type
== elfcpp::R_MIPS_26
))
4634 gold_warning(_("JALX to a non-word-aligned address"));
4635 return This::STATUS_BAD_RELOC
;
4638 // Shift is 2, unusually, for microMIPS JALX.
4639 unsigned int shift
=
4640 (!cross_mode_jump
&& r_type
== elfcpp::R_MICROMIPS_26_S1
) ? 1 : 2;
4644 x
= addend
| ((address
+ 4) & (0xfc000000 << shift
));
4648 x
= Bits
<27>::sign_extend32(addend
);
4650 x
= Bits
<28>::sign_extend32(addend
);
4652 x
= psymval
->value(object
, x
) >> shift
;
4654 if (!calculate_only
&& !local
&& !gsym
->is_weak_undefined()
4655 && ((x
>> 26) != ((address
+ 4) >> (26 + shift
))))
4656 return This::STATUS_OVERFLOW
;
4658 val
= Bits
<32>::bit_select32(val
, x
, 0x03ffffff);
4660 // If required, turn JAL into JALX.
4661 if (cross_mode_jump
)
4664 Valtype32 opcode
= val
>> 26;
4665 Valtype32 jalx_opcode
;
4667 // Check to see if the opcode is already JAL or JALX.
4668 if (r_type
== elfcpp::R_MIPS16_26
)
4670 ok
= (opcode
== 0x6) || (opcode
== 0x7);
4673 else if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4675 ok
= (opcode
== 0x3d) || (opcode
== 0x3c);
4680 ok
= (opcode
== 0x3) || (opcode
== 0x1d);
4684 // If the opcode is not JAL or JALX, there's a problem. We cannot
4685 // convert J or JALS to JALX.
4686 if (!calculate_only
&& !ok
)
4688 gold_error(_("Unsupported jump between ISA modes; consider "
4689 "recompiling with interlinking enabled."));
4690 return This::STATUS_BAD_RELOC
;
4693 // Make this the JALX opcode.
4694 val
= (val
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
4697 // Try converting JAL to BAL, if the target is in range.
4698 if (!parameters
->options().relocatable()
4701 && r_type
== elfcpp::R_MIPS_26
4702 && (val
>> 26) == 0x3))) // jal addr
4704 Valtype32 dest
= (x
<< 2) | (((address
+ 4) >> 28) << 28);
4705 int offset
= dest
- (address
+ 4);
4706 if (!Bits
<18>::has_overflow32(offset
))
4708 if (val
== 0x03200008) // jr t9
4709 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4711 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4716 *calculated_value
= val
;
4718 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4720 return This::STATUS_OKAY
;
4724 static inline typename
This::Status
4725 relpc16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4726 const Symbol_value
<size
>* psymval
, Mips_address address
,
4727 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4728 Valtype
* calculated_value
)
4730 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4731 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4733 Valtype addend
= (extract_addend
4734 ? Bits
<18>::sign_extend32((val
& 0xffff) << 2)
4737 Valtype x
= psymval
->value(object
, addend
) - address
;
4738 val
= Bits
<16>::bit_select32(val
, x
>> 2, 0xffff);
4742 *calculated_value
= x
>> 2;
4743 return This::STATUS_OKAY
;
4746 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4748 if (psymval
->value(object
, addend
) & 3)
4749 return This::STATUS_PCREL_UNALIGNED
;
4751 return check_overflow
<18>(x
);
4755 static inline typename
This::Status
4756 relpc21(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4757 const Symbol_value
<size
>* psymval
, Mips_address address
,
4758 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4759 Valtype
* calculated_value
)
4761 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4762 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4764 Valtype addend
= (extract_addend
4765 ? Bits
<23>::sign_extend32((val
& 0x1fffff) << 2)
4768 Valtype x
= psymval
->value(object
, addend
) - address
;
4769 val
= Bits
<21>::bit_select32(val
, x
>> 2, 0x1fffff);
4773 *calculated_value
= x
>> 2;
4774 return This::STATUS_OKAY
;
4777 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4779 if (psymval
->value(object
, addend
) & 3)
4780 return This::STATUS_PCREL_UNALIGNED
;
4782 return check_overflow
<23>(x
);
4786 static inline typename
This::Status
4787 relpc26(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4788 const Symbol_value
<size
>* psymval
, Mips_address address
,
4789 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4790 Valtype
* calculated_value
)
4792 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4793 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4795 Valtype addend
= (extract_addend
4796 ? Bits
<28>::sign_extend32((val
& 0x3ffffff) << 2)
4799 Valtype x
= psymval
->value(object
, addend
) - address
;
4800 val
= Bits
<26>::bit_select32(val
, x
>> 2, 0x3ffffff);
4804 *calculated_value
= x
>> 2;
4805 return This::STATUS_OKAY
;
4808 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4810 if (psymval
->value(object
, addend
) & 3)
4811 return This::STATUS_PCREL_UNALIGNED
;
4813 return check_overflow
<28>(x
);
4817 static inline typename
This::Status
4818 relpc18(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4819 const Symbol_value
<size
>* psymval
, Mips_address address
,
4820 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4821 Valtype
* calculated_value
)
4823 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4824 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4826 Valtype addend
= (extract_addend
4827 ? Bits
<21>::sign_extend32((val
& 0x3ffff) << 3)
4830 Valtype x
= psymval
->value(object
, addend
) - ((address
| 7) ^ 7);
4831 val
= Bits
<18>::bit_select32(val
, x
>> 3, 0x3ffff);
4835 *calculated_value
= x
>> 3;
4836 return This::STATUS_OKAY
;
4839 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4841 if (psymval
->value(object
, addend
) & 7)
4842 return This::STATUS_PCREL_UNALIGNED
;
4844 return check_overflow
<21>(x
);
4848 static inline typename
This::Status
4849 relpc19(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4850 const Symbol_value
<size
>* psymval
, Mips_address address
,
4851 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4852 Valtype
* calculated_value
)
4854 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4855 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4857 Valtype addend
= (extract_addend
4858 ? Bits
<21>::sign_extend32((val
& 0x7ffff) << 2)
4861 Valtype x
= psymval
->value(object
, addend
) - address
;
4862 val
= Bits
<19>::bit_select32(val
, x
>> 2, 0x7ffff);
4866 *calculated_value
= x
>> 2;
4867 return This::STATUS_OKAY
;
4870 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4872 if (psymval
->value(object
, addend
) & 3)
4873 return This::STATUS_PCREL_UNALIGNED
;
4875 return check_overflow
<21>(x
);
4879 static inline typename
This::Status
4880 relpchi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4881 const Symbol_value
<size
>* psymval
, Mips_address addend
,
4882 Mips_address address
, unsigned int r_sym
, bool extract_addend
)
4884 // Record the relocation. It will be resolved when we find pclo16 part.
4885 pchi16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
4886 addend
, 0, r_sym
, extract_addend
, address
));
4887 return This::STATUS_OKAY
;
4891 static inline typename
This::Status
4892 do_relpchi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4893 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
4894 Mips_address address
, bool extract_addend
, Valtype32 addend_lo
,
4895 bool calculate_only
, Valtype
* calculated_value
)
4897 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4898 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4900 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
4903 Valtype value
= psymval
->value(object
, addend
) - address
;
4904 Valtype x
= ((value
+ 0x8000) >> 16) & 0xffff;
4905 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4908 *calculated_value
= x
;
4910 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4912 return This::STATUS_OKAY
;
4916 static inline typename
This::Status
4917 relpclo16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4918 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4919 bool extract_addend
, Mips_address address
, unsigned int r_sym
,
4920 unsigned int rel_type
, bool calculate_only
,
4921 Valtype
* calculated_value
)
4923 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4924 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4926 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
4929 if (rel_type
== elfcpp::SHT_REL
)
4931 // Resolve pending R_MIPS_PCHI16 relocations.
4932 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it
=
4933 pchi16_relocs
.begin();
4934 while (it
!= pchi16_relocs
.end())
4936 reloc_high
<size
, big_endian
> pchi16
= *it
;
4937 if (pchi16
.r_sym
== r_sym
)
4939 do_relpchi16(pchi16
.view
, pchi16
.object
, pchi16
.psymval
,
4940 pchi16
.addend
, pchi16
.address
,
4941 pchi16
.extract_addend
, addend
, calculate_only
,
4943 it
= pchi16_relocs
.erase(it
);
4950 // Resolve R_MIPS_PCLO16 relocation.
4951 Valtype x
= psymval
->value(object
, addend
) - address
;
4952 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4955 *calculated_value
= x
;
4957 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4959 return This::STATUS_OKAY
;
4962 // R_MICROMIPS_PC7_S1
4963 static inline typename
This::Status
4964 relmicromips_pc7_s1(unsigned char* view
,
4965 const Mips_relobj
<size
, big_endian
>* object
,
4966 const Symbol_value
<size
>* psymval
, Mips_address address
,
4967 Mips_address addend_a
, bool extract_addend
,
4968 bool calculate_only
, Valtype
* calculated_value
)
4970 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4971 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4973 Valtype addend
= extract_addend
? Bits
<8>::sign_extend32((val
& 0x7f) << 1)
4976 Valtype x
= psymval
->value(object
, addend
) - address
;
4977 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x7f);
4981 *calculated_value
= x
>> 1;
4982 return This::STATUS_OKAY
;
4985 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4987 return check_overflow
<8>(x
);
4990 // R_MICROMIPS_PC10_S1
4991 static inline typename
This::Status
4992 relmicromips_pc10_s1(unsigned char* view
,
4993 const Mips_relobj
<size
, big_endian
>* object
,
4994 const Symbol_value
<size
>* psymval
, Mips_address address
,
4995 Mips_address addend_a
, bool extract_addend
,
4996 bool calculate_only
, Valtype
* calculated_value
)
4998 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4999 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5001 Valtype addend
= (extract_addend
5002 ? Bits
<11>::sign_extend32((val
& 0x3ff) << 1)
5005 Valtype x
= psymval
->value(object
, addend
) - address
;
5006 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x3ff);
5010 *calculated_value
= x
>> 1;
5011 return This::STATUS_OKAY
;
5014 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5016 return check_overflow
<11>(x
);
5019 // R_MICROMIPS_PC16_S1
5020 static inline typename
This::Status
5021 relmicromips_pc16_s1(unsigned char* view
,
5022 const Mips_relobj
<size
, big_endian
>* object
,
5023 const Symbol_value
<size
>* psymval
, Mips_address address
,
5024 Mips_address addend_a
, bool extract_addend
,
5025 bool calculate_only
, Valtype
* calculated_value
)
5027 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5028 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5030 Valtype addend
= (extract_addend
5031 ? Bits
<17>::sign_extend32((val
& 0xffff) << 1)
5034 Valtype x
= psymval
->value(object
, addend
) - address
;
5035 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0xffff);
5039 *calculated_value
= x
>> 1;
5040 return This::STATUS_OKAY
;
5043 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5045 return check_overflow
<17>(x
);
5048 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
5049 static inline typename
This::Status
5050 relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5051 const Symbol_value
<size
>* psymval
, Mips_address addend
,
5052 Mips_address address
, bool gp_disp
, unsigned int r_type
,
5053 unsigned int r_sym
, bool extract_addend
)
5055 // Record the relocation. It will be resolved when we find lo16 part.
5056 hi16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
5057 addend
, r_type
, r_sym
, extract_addend
, address
,
5059 return This::STATUS_OKAY
;
5062 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
5063 static inline typename
This::Status
5064 do_relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5065 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
5066 Mips_address address
, bool is_gp_disp
, unsigned int r_type
,
5067 bool extract_addend
, Valtype32 addend_lo
,
5068 Target_mips
<size
, big_endian
>* target
, bool calculate_only
,
5069 Valtype
* calculated_value
)
5071 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5072 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5074 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
5079 value
= psymval
->value(object
, addend
);
5082 // For MIPS16 ABI code we generate this sequence
5083 // 0: li $v0,%hi(_gp_disp)
5084 // 4: addiupc $v1,%lo(_gp_disp)
5088 // So the offsets of hi and lo relocs are the same, but the
5089 // base $pc is that used by the ADDIUPC instruction at $t9 + 4.
5090 // ADDIUPC clears the low two bits of the instruction address,
5091 // so the base is ($t9 + 4) & ~3.
5093 if (r_type
== elfcpp::R_MIPS16_HI16
)
5094 gp_disp
= (target
->adjusted_gp_value(object
)
5095 - ((address
+ 4) & ~0x3));
5096 // The microMIPS .cpload sequence uses the same assembly
5097 // instructions as the traditional psABI version, but the
5098 // incoming $t9 has the low bit set.
5099 else if (r_type
== elfcpp::R_MICROMIPS_HI16
)
5100 gp_disp
= target
->adjusted_gp_value(object
) - address
- 1;
5102 gp_disp
= target
->adjusted_gp_value(object
) - address
;
5103 value
= gp_disp
+ addend
;
5105 Valtype x
= ((value
+ 0x8000) >> 16) & 0xffff;
5106 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5110 *calculated_value
= x
;
5111 return This::STATUS_OKAY
;
5114 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5116 return (is_gp_disp
? check_overflow
<16>(x
)
5117 : This::STATUS_OKAY
);
5120 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
5121 static inline typename
This::Status
5122 relgot16_local(unsigned char* view
,
5123 const Mips_relobj
<size
, big_endian
>* object
,
5124 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5125 bool extract_addend
, unsigned int r_type
, unsigned int r_sym
)
5127 // Record the relocation. It will be resolved when we find lo16 part.
5128 got16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
5129 addend_a
, r_type
, r_sym
, extract_addend
));
5130 return This::STATUS_OKAY
;
5133 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
5134 static inline typename
This::Status
5135 do_relgot16_local(unsigned char* view
,
5136 const Mips_relobj
<size
, big_endian
>* object
,
5137 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
5138 bool extract_addend
, Valtype32 addend_lo
,
5139 Target_mips
<size
, big_endian
>* target
, bool calculate_only
,
5140 Valtype
* calculated_value
)
5142 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5143 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5145 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
5148 // Find GOT page entry.
5149 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000) >> 16)
5152 unsigned int got_offset
=
5153 target
->got_section()->get_got_page_offset(value
, object
);
5155 // Resolve the relocation.
5156 Valtype x
= target
->got_section()->gp_offset(got_offset
, object
);
5157 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5161 *calculated_value
= x
;
5162 return This::STATUS_OKAY
;
5165 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5167 return check_overflow
<16>(x
);
5170 // R_MIPS_LO16, R_MIPS16_LO16, R_MICROMIPS_LO16, R_MICROMIPS_HI0_LO16
5171 static inline typename
This::Status
5172 rello16(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
5173 const Mips_relobj
<size
, big_endian
>* object
,
5174 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5175 bool extract_addend
, Mips_address address
, bool is_gp_disp
,
5176 unsigned int r_type
, unsigned int r_sym
, unsigned int rel_type
,
5177 bool calculate_only
, Valtype
* calculated_value
)
5179 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5180 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5182 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
5185 if (rel_type
== elfcpp::SHT_REL
)
5187 typename
This::Status reloc_status
= This::STATUS_OKAY
;
5188 // Resolve pending R_MIPS_HI16 relocations.
5189 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it
=
5190 hi16_relocs
.begin();
5191 while (it
!= hi16_relocs
.end())
5193 reloc_high
<size
, big_endian
> hi16
= *it
;
5194 if (hi16
.r_sym
== r_sym
5195 && is_matching_lo16_reloc(hi16
.r_type
, r_type
))
5197 mips_reloc_unshuffle(hi16
.view
, hi16
.r_type
, false);
5198 reloc_status
= do_relhi16(hi16
.view
, hi16
.object
, hi16
.psymval
,
5199 hi16
.addend
, hi16
.address
, hi16
.gp_disp
,
5200 hi16
.r_type
, hi16
.extract_addend
, addend
,
5201 target
, calculate_only
, calculated_value
);
5202 mips_reloc_shuffle(hi16
.view
, hi16
.r_type
, false);
5203 if (reloc_status
== This::STATUS_OVERFLOW
)
5204 return This::STATUS_OVERFLOW
;
5205 it
= hi16_relocs
.erase(it
);
5211 // Resolve pending local R_MIPS_GOT16 relocations.
5212 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it2
=
5213 got16_relocs
.begin();
5214 while (it2
!= got16_relocs
.end())
5216 reloc_high
<size
, big_endian
> got16
= *it2
;
5217 if (got16
.r_sym
== r_sym
5218 && is_matching_lo16_reloc(got16
.r_type
, r_type
))
5220 mips_reloc_unshuffle(got16
.view
, got16
.r_type
, false);
5222 reloc_status
= do_relgot16_local(got16
.view
, got16
.object
,
5223 got16
.psymval
, got16
.addend
,
5224 got16
.extract_addend
, addend
, target
,
5225 calculate_only
, calculated_value
);
5227 mips_reloc_shuffle(got16
.view
, got16
.r_type
, false);
5228 if (reloc_status
== This::STATUS_OVERFLOW
)
5229 return This::STATUS_OVERFLOW
;
5230 it2
= got16_relocs
.erase(it2
);
5237 // Resolve R_MIPS_LO16 relocation.
5240 x
= psymval
->value(object
, addend
);
5243 // See the comment for R_MIPS16_HI16 above for the reason
5244 // for this conditional.
5246 if (r_type
== elfcpp::R_MIPS16_LO16
)
5247 gp_disp
= target
->adjusted_gp_value(object
) - (address
& ~0x3);
5248 else if (r_type
== elfcpp::R_MICROMIPS_LO16
5249 || r_type
== elfcpp::R_MICROMIPS_HI0_LO16
)
5250 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 3;
5252 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 4;
5253 // The MIPS ABI requires checking the R_MIPS_LO16 relocation
5254 // for overflow. Relocations against _gp_disp are normally
5255 // generated from the .cpload pseudo-op. It generates code
5256 // that normally looks like this:
5258 // lui $gp,%hi(_gp_disp)
5259 // addiu $gp,$gp,%lo(_gp_disp)
5262 // Here $t9 holds the address of the function being called,
5263 // as required by the MIPS ELF ABI. The R_MIPS_LO16
5264 // relocation can easily overflow in this situation, but the
5265 // R_MIPS_HI16 relocation will handle the overflow.
5266 // Therefore, we consider this a bug in the MIPS ABI, and do
5267 // not check for overflow here.
5268 x
= gp_disp
+ addend
;
5270 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5273 *calculated_value
= x
;
5275 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5277 return This::STATUS_OKAY
;
5280 // R_MIPS_CALL16, R_MIPS16_CALL16, R_MICROMIPS_CALL16
5281 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
5282 // R_MIPS_TLS_GD, R_MIPS16_TLS_GD, R_MICROMIPS_TLS_GD
5283 // R_MIPS_TLS_GOTTPREL, R_MIPS16_TLS_GOTTPREL, R_MICROMIPS_TLS_GOTTPREL
5284 // R_MIPS_TLS_LDM, R_MIPS16_TLS_LDM, R_MICROMIPS_TLS_LDM
5285 // R_MIPS_GOT_DISP, R_MICROMIPS_GOT_DISP
5286 static inline typename
This::Status
5287 relgot(unsigned char* view
, int gp_offset
, bool calculate_only
,
5288 Valtype
* calculated_value
)
5290 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5291 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5292 Valtype x
= gp_offset
;
5293 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5297 *calculated_value
= x
;
5298 return This::STATUS_OKAY
;
5301 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5303 return check_overflow
<16>(x
);
5307 static inline typename
This::Status
5308 releh(unsigned char* view
, int gp_offset
, bool calculate_only
,
5309 Valtype
* calculated_value
)
5311 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5312 Valtype x
= gp_offset
;
5316 *calculated_value
= x
;
5317 return This::STATUS_OKAY
;
5320 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5322 return check_overflow
<32>(x
);
5325 // R_MIPS_GOT_PAGE, R_MICROMIPS_GOT_PAGE
5326 static inline typename
This::Status
5327 relgotpage(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
5328 const Mips_relobj
<size
, big_endian
>* object
,
5329 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5330 bool extract_addend
, bool calculate_only
,
5331 Valtype
* calculated_value
)
5333 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5334 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
5335 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5337 // Find a GOT page entry that points to within 32KB of symbol + addend.
5338 Mips_address value
= (psymval
->value(object
, addend
) + 0x8000) & ~0xffff;
5339 unsigned int got_offset
=
5340 target
->got_section()->get_got_page_offset(value
, object
);
5342 Valtype x
= target
->got_section()->gp_offset(got_offset
, object
);
5343 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5347 *calculated_value
= x
;
5348 return This::STATUS_OKAY
;
5351 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5353 return check_overflow
<16>(x
);
5356 // R_MIPS_GOT_OFST, R_MICROMIPS_GOT_OFST
5357 static inline typename
This::Status
5358 relgotofst(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
5359 const Mips_relobj
<size
, big_endian
>* object
,
5360 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5361 bool extract_addend
, bool local
, bool calculate_only
,
5362 Valtype
* calculated_value
)
5364 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5365 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
5366 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5368 // For a local symbol, find a GOT page entry that points to within 32KB of
5369 // symbol + addend. Relocation value is the offset of the GOT page entry's
5370 // value from symbol + addend.
5371 // For a global symbol, relocation value is addend.
5375 // Find GOT page entry.
5376 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000)
5378 target
->got_section()->get_got_page_offset(value
, object
);
5380 x
= psymval
->value(object
, addend
) - value
;
5384 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5388 *calculated_value
= x
;
5389 return This::STATUS_OKAY
;
5392 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5394 return check_overflow
<16>(x
);
5397 // R_MIPS_GOT_HI16, R_MIPS_CALL_HI16,
5398 // R_MICROMIPS_GOT_HI16, R_MICROMIPS_CALL_HI16
5399 static inline typename
This::Status
5400 relgot_hi16(unsigned char* view
, int gp_offset
, bool calculate_only
,
5401 Valtype
* calculated_value
)
5403 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5404 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5405 Valtype x
= gp_offset
;
5406 x
= ((x
+ 0x8000) >> 16) & 0xffff;
5407 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5410 *calculated_value
= x
;
5412 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5414 return This::STATUS_OKAY
;
5417 // R_MIPS_GOT_LO16, R_MIPS_CALL_LO16,
5418 // R_MICROMIPS_GOT_LO16, R_MICROMIPS_CALL_LO16
5419 static inline typename
This::Status
5420 relgot_lo16(unsigned char* view
, int gp_offset
, bool calculate_only
,
5421 Valtype
* calculated_value
)
5423 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5424 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5425 Valtype x
= gp_offset
;
5426 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5429 *calculated_value
= x
;
5431 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5433 return This::STATUS_OKAY
;
5436 // R_MIPS_GPREL16, R_MIPS16_GPREL, R_MIPS_LITERAL, R_MICROMIPS_LITERAL
5437 // R_MICROMIPS_GPREL16
5438 static inline typename
This::Status
5439 relgprel(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5440 const Symbol_value
<size
>* psymval
, Mips_address gp
,
5441 Mips_address addend_a
, bool extract_addend
, bool local
,
5442 bool calculate_only
, Valtype
* calculated_value
)
5444 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5445 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
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 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5473 *calculated_value
= x
;
5474 return This::STATUS_OKAY
;
5477 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5479 if (check_overflow
<16>(x
) == This::STATUS_OVERFLOW
)
5481 gold_error(_("small-data section too large;"
5482 " lower small-data size limit (see option -G)"));
5483 return This::STATUS_OVERFLOW
;
5485 return This::STATUS_OKAY
;
5488 // R_MICROMIPS_GPREL7_S2
5489 static inline typename
This::Status
5490 relgprel7(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5491 const Symbol_value
<size
>* psymval
, Mips_address gp
,
5492 Mips_address addend_a
, bool extract_addend
, bool local
,
5493 bool calculate_only
, Valtype
* calculated_value
)
5495 Valtype16
* wv
= reinterpret_cast<Valtype16
*>(view
);
5496 Valtype16 val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
5501 addend
= (val
& 0x7f) << 2;
5502 addend
= Bits
<9>::sign_extend32(addend
);
5507 Valtype x
= psymval
->value(object
, addend
) - gp
;
5510 x
+= object
->gp_value();
5512 val
= Bits
<16>::bit_select32(val
, x
>> 2, 0x7f);
5516 *calculated_value
= x
;
5517 return This::STATUS_OKAY
;
5520 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
5522 if (check_overflow
<9>(x
) == This::STATUS_OVERFLOW
)
5524 gold_error(_("small-data section too large;"
5525 " lower small-data size limit (see option -G)"));
5526 return This::STATUS_OVERFLOW
;
5528 return This::STATUS_OKAY
;
5532 static inline typename
This::Status
5533 relgprel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5534 const Symbol_value
<size
>* psymval
, Mips_address gp
,
5535 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5536 Valtype
* calculated_value
)
5538 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5539 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5540 Valtype addend
= extract_addend
? val
: addend_a
;
5542 // R_MIPS_GPREL32 relocations are defined for local symbols only.
5543 Valtype x
= psymval
->value(object
, addend
) + object
->gp_value() - gp
;
5546 *calculated_value
= x
;
5548 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5550 return This::STATUS_OKAY
;
5553 // R_MIPS_TLS_TPREL_HI16, R_MIPS16_TLS_TPREL_HI16, R_MICROMIPS_TLS_TPREL_HI16
5554 // R_MIPS_TLS_DTPREL_HI16, R_MIPS16_TLS_DTPREL_HI16,
5555 // R_MICROMIPS_TLS_DTPREL_HI16
5556 static inline typename
This::Status
5557 tlsrelhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5558 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5559 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5560 Valtype
* calculated_value
)
5562 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5563 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5564 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5566 // tls symbol values are relative to tls_segment()->vaddr()
5567 Valtype x
= ((psymval
->value(object
, addend
) - tp_offset
) + 0x8000) >> 16;
5568 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5571 *calculated_value
= x
;
5573 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5575 return This::STATUS_OKAY
;
5578 // R_MIPS_TLS_TPREL_LO16, R_MIPS16_TLS_TPREL_LO16, R_MICROMIPS_TLS_TPREL_LO16,
5579 // R_MIPS_TLS_DTPREL_LO16, R_MIPS16_TLS_DTPREL_LO16,
5580 // R_MICROMIPS_TLS_DTPREL_LO16,
5581 static inline typename
This::Status
5582 tlsrello16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5583 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5584 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5585 Valtype
* calculated_value
)
5587 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5588 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5589 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5591 // tls symbol values are relative to tls_segment()->vaddr()
5592 Valtype x
= psymval
->value(object
, addend
) - tp_offset
;
5593 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5596 *calculated_value
= x
;
5598 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5600 return This::STATUS_OKAY
;
5603 // R_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL64,
5604 // R_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL64
5605 static inline typename
This::Status
5606 tlsrel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5607 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5608 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5609 Valtype
* calculated_value
)
5611 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5612 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5613 Valtype addend
= extract_addend
? val
: addend_a
;
5615 // tls symbol values are relative to tls_segment()->vaddr()
5616 Valtype x
= psymval
->value(object
, addend
) - tp_offset
;
5619 *calculated_value
= x
;
5621 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5623 return This::STATUS_OKAY
;
5626 // R_MIPS_SUB, R_MICROMIPS_SUB
5627 static inline typename
This::Status
5628 relsub(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5629 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5630 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
5632 Valtype64
* wv
= reinterpret_cast<Valtype64
*>(view
);
5633 Valtype64 addend
= (extract_addend
5634 ? elfcpp::Swap
<64, big_endian
>::readval(wv
)
5637 Valtype64 x
= psymval
->value(object
, -addend
);
5639 *calculated_value
= x
;
5641 elfcpp::Swap
<64, big_endian
>::writeval(wv
, x
);
5643 return This::STATUS_OKAY
;
5647 static inline typename
This::Status
5648 rel64(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5649 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5650 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
,
5651 bool apply_addend_only
)
5653 Valtype64
* wv
= reinterpret_cast<Valtype64
*>(view
);
5654 Valtype64 addend
= (extract_addend
5655 ? elfcpp::Swap
<64, big_endian
>::readval(wv
)
5658 Valtype64 x
= psymval
->value(object
, addend
);
5660 *calculated_value
= x
;
5663 if (apply_addend_only
)
5665 elfcpp::Swap
<64, big_endian
>::writeval(wv
, x
);
5668 return This::STATUS_OKAY
;
5671 // R_MIPS_HIGHER, R_MICROMIPS_HIGHER
5672 static inline typename
This::Status
5673 relhigher(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5674 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5675 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
5677 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5678 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5679 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
5682 Valtype x
= psymval
->value(object
, addend
);
5683 x
= ((x
+ (uint64_t) 0x80008000) >> 32) & 0xffff;
5684 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5687 *calculated_value
= x
;
5689 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5691 return This::STATUS_OKAY
;
5694 // R_MIPS_HIGHEST, R_MICROMIPS_HIGHEST
5695 static inline typename
This::Status
5696 relhighest(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5697 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5698 bool extract_addend
, bool calculate_only
,
5699 Valtype
* calculated_value
)
5701 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5702 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5703 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
5706 Valtype x
= psymval
->value(object
, addend
);
5707 x
= ((x
+ (uint64_t) 0x800080008000llu
) >> 48) & 0xffff;
5708 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5711 *calculated_value
= x
;
5713 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5715 return This::STATUS_OKAY
;
5719 template<int size
, bool big_endian
>
5720 typename
std::list
<reloc_high
<size
, big_endian
> >
5721 Mips_relocate_functions
<size
, big_endian
>::hi16_relocs
;
5723 template<int size
, bool big_endian
>
5724 typename
std::list
<reloc_high
<size
, big_endian
> >
5725 Mips_relocate_functions
<size
, big_endian
>::got16_relocs
;
5727 template<int size
, bool big_endian
>
5728 typename
std::list
<reloc_high
<size
, big_endian
> >
5729 Mips_relocate_functions
<size
, big_endian
>::pchi16_relocs
;
5731 // Mips_got_info methods.
5733 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
5734 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
5736 template<int size
, bool big_endian
>
5738 Mips_got_info
<size
, big_endian
>::record_local_got_symbol(
5739 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
,
5740 Mips_address addend
, unsigned int r_type
, unsigned int shndx
,
5741 bool is_section_symbol
)
5743 Mips_got_entry
<size
, big_endian
>* entry
=
5744 new Mips_got_entry
<size
, big_endian
>(object
, symndx
, addend
,
5745 mips_elf_reloc_tls_type(r_type
),
5746 shndx
, is_section_symbol
);
5747 this->record_got_entry(entry
, object
);
5750 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
5751 // in OBJECT. FOR_CALL is true if the caller is only interested in
5752 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
5755 template<int size
, bool big_endian
>
5757 Mips_got_info
<size
, big_endian
>::record_global_got_symbol(
5758 Mips_symbol
<size
>* mips_sym
, Mips_relobj
<size
, big_endian
>* object
,
5759 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
5762 mips_sym
->set_got_not_only_for_calls();
5764 // A global symbol in the GOT must also be in the dynamic symbol table.
5765 if (!mips_sym
->needs_dynsym_entry() && !mips_sym
->is_forced_local())
5767 switch (mips_sym
->visibility())
5769 case elfcpp::STV_INTERNAL
:
5770 case elfcpp::STV_HIDDEN
:
5771 mips_sym
->set_is_forced_local();
5774 mips_sym
->set_needs_dynsym_entry();
5779 unsigned char tls_type
= mips_elf_reloc_tls_type(r_type
);
5780 if (tls_type
== GOT_TLS_NONE
)
5781 this->global_got_symbols_
.insert(mips_sym
);
5785 if (mips_sym
->global_got_area() == GGA_NONE
)
5786 mips_sym
->set_global_got_area(GGA_RELOC_ONLY
);
5790 Mips_got_entry
<size
, big_endian
>* entry
=
5791 new Mips_got_entry
<size
, big_endian
>(mips_sym
, tls_type
);
5793 this->record_got_entry(entry
, object
);
5796 // Add ENTRY to master GOT and to OBJECT's GOT.
5798 template<int size
, bool big_endian
>
5800 Mips_got_info
<size
, big_endian
>::record_got_entry(
5801 Mips_got_entry
<size
, big_endian
>* entry
,
5802 Mips_relobj
<size
, big_endian
>* object
)
5804 this->got_entries_
.insert(entry
);
5806 // Create the GOT entry for the OBJECT's GOT.
5807 Mips_got_info
<size
, big_endian
>* g
= object
->get_or_create_got_info();
5808 Mips_got_entry
<size
, big_endian
>* entry2
=
5809 new Mips_got_entry
<size
, big_endian
>(*entry
);
5811 g
->got_entries_
.insert(entry2
);
5814 // Record that OBJECT has a page relocation against symbol SYMNDX and
5815 // that ADDEND is the addend for that relocation.
5816 // This function creates an upper bound on the number of GOT slots
5817 // required; no attempt is made to combine references to non-overridable
5818 // global symbols across multiple input files.
5820 template<int size
, bool big_endian
>
5822 Mips_got_info
<size
, big_endian
>::record_got_page_entry(
5823 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
, int addend
)
5825 struct Got_page_range
**range_ptr
, *range
;
5826 int old_pages
, new_pages
;
5828 // Find the Got_page_entry for this symbol.
5829 Got_page_entry
* entry
= new Got_page_entry(object
, symndx
);
5830 typename
Got_page_entry_set::iterator it
=
5831 this->got_page_entries_
.find(entry
);
5832 if (it
!= this->got_page_entries_
.end())
5835 this->got_page_entries_
.insert(entry
);
5837 // Get the object's GOT, but we don't need to insert an entry here.
5838 Mips_got_info
<size
, big_endian
>* g2
= object
->get_or_create_got_info();
5840 // Skip over ranges whose maximum extent cannot share a page entry
5842 range_ptr
= &entry
->ranges
;
5843 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
5844 range_ptr
= &(*range_ptr
)->next
;
5846 // If we scanned to the end of the list, or found a range whose
5847 // minimum extent cannot share a page entry with ADDEND, create
5848 // a new singleton range.
5850 if (!range
|| addend
< range
->min_addend
- 0xffff)
5852 range
= new Got_page_range();
5853 range
->next
= *range_ptr
;
5854 range
->min_addend
= addend
;
5855 range
->max_addend
= addend
;
5858 ++this->page_gotno_
;
5863 // Remember how many pages the old range contributed.
5864 old_pages
= range
->get_max_pages();
5866 // Update the ranges.
5867 if (addend
< range
->min_addend
)
5868 range
->min_addend
= addend
;
5869 else if (addend
> range
->max_addend
)
5871 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
5873 old_pages
+= range
->next
->get_max_pages();
5874 range
->max_addend
= range
->next
->max_addend
;
5875 range
->next
= range
->next
->next
;
5878 range
->max_addend
= addend
;
5881 // Record any change in the total estimate.
5882 new_pages
= range
->get_max_pages();
5883 if (old_pages
!= new_pages
)
5885 this->page_gotno_
+= new_pages
- old_pages
;
5886 g2
->page_gotno_
+= new_pages
- old_pages
;
5890 // Create all entries that should be in the local part of the GOT.
5892 template<int size
, bool big_endian
>
5894 Mips_got_info
<size
, big_endian
>::add_local_entries(
5895 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5897 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5898 // First two GOT entries are reserved. The first entry will be filled at
5899 // runtime. The second entry will be used by some runtime loaders.
5900 got
->add_constant(0);
5901 got
->add_constant(target
->mips_elf_gnu_got1_mask());
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_local_symbol() && !entry
->is_tls_entry())
5911 got
->add_local(entry
->object(), entry
->symndx(),
5912 GOT_TYPE_STANDARD
, entry
->addend());
5913 unsigned int got_offset
= entry
->object()->local_got_offset(
5914 entry
->symndx(), GOT_TYPE_STANDARD
, entry
->addend());
5915 if (got
->multi_got() && this->index_
> 0
5916 && parameters
->options().output_is_position_independent())
5918 if (!entry
->is_section_symbol())
5919 target
->rel_dyn_section(layout
)->add_local(entry
->object(),
5920 entry
->symndx(), elfcpp::R_MIPS_REL32
, got
, got_offset
);
5922 target
->rel_dyn_section(layout
)->add_symbolless_local_addend(
5923 entry
->object(), entry
->symndx(), elfcpp::R_MIPS_REL32
,
5929 this->add_page_entries(target
, layout
);
5931 // Add global entries that should be in the local area.
5932 for (typename
Got_entry_set::iterator
5933 p
= this->got_entries_
.begin();
5934 p
!= this->got_entries_
.end();
5937 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5938 if (!entry
->is_for_global_symbol())
5941 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5942 if (mips_sym
->global_got_area() == GGA_NONE
&& !entry
->is_tls_entry())
5944 unsigned int got_type
;
5945 if (!got
->multi_got())
5946 got_type
= GOT_TYPE_STANDARD
;
5948 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
5949 if (got
->add_global(mips_sym
, got_type
))
5951 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5952 if (got
->multi_got() && this->index_
> 0
5953 && parameters
->options().output_is_position_independent())
5954 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
5955 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
5956 mips_sym
->got_offset(got_type
));
5962 // Create GOT page entries.
5964 template<int size
, bool big_endian
>
5966 Mips_got_info
<size
, big_endian
>::add_page_entries(
5967 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5969 if (this->page_gotno_
== 0)
5972 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5973 this->got_page_offset_start_
= got
->add_constant(0);
5974 if (got
->multi_got() && this->index_
> 0
5975 && parameters
->options().output_is_position_independent())
5976 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
5977 this->got_page_offset_start_
);
5978 int num_entries
= this->page_gotno_
;
5979 unsigned int prev_offset
= this->got_page_offset_start_
;
5980 while (--num_entries
> 0)
5982 unsigned int next_offset
= got
->add_constant(0);
5983 if (got
->multi_got() && this->index_
> 0
5984 && parameters
->options().output_is_position_independent())
5985 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
5987 gold_assert(next_offset
== prev_offset
+ size
/8);
5988 prev_offset
= next_offset
;
5990 this->got_page_offset_next_
= this->got_page_offset_start_
;
5993 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
5995 template<int size
, bool big_endian
>
5997 Mips_got_info
<size
, big_endian
>::add_global_entries(
5998 Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
5999 unsigned int non_reloc_only_global_gotno
)
6001 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
6002 // Add GGA_NORMAL entries.
6003 unsigned int count
= 0;
6004 for (typename
Got_entry_set::iterator
6005 p
= this->got_entries_
.begin();
6006 p
!= this->got_entries_
.end();
6009 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
6010 if (!entry
->is_for_global_symbol())
6013 Mips_symbol
<size
>* mips_sym
= entry
->sym();
6014 if (mips_sym
->global_got_area() != GGA_NORMAL
)
6017 unsigned int got_type
;
6018 if (!got
->multi_got())
6019 got_type
= GOT_TYPE_STANDARD
;
6021 // In multi-GOT links, global symbol can be in both primary and
6022 // secondary GOT(s). By creating custom GOT type
6023 // (GOT_TYPE_STANDARD_MULTIGOT + got_index) we ensure that symbol
6024 // is added to secondary GOT(s).
6025 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
6026 if (!got
->add_global(mips_sym
, got_type
))
6029 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
6030 if (got
->multi_got() && this->index_
== 0)
6032 if (got
->multi_got() && this->index_
> 0)
6034 if (parameters
->options().output_is_position_independent()
6035 || (!parameters
->doing_static_link()
6036 && mips_sym
->is_from_dynobj() && !mips_sym
->is_undefined()))
6038 target
->rel_dyn_section(layout
)->add_global(
6039 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
6040 mips_sym
->got_offset(got_type
));
6041 got
->add_secondary_got_reloc(mips_sym
->got_offset(got_type
),
6042 elfcpp::R_MIPS_REL32
, mips_sym
);
6047 if (!got
->multi_got() || this->index_
== 0)
6049 if (got
->multi_got())
6051 // We need to allocate space in the primary GOT for GGA_NORMAL entries
6052 // of secondary GOTs, to ensure that GOT offsets of GGA_RELOC_ONLY
6053 // entries correspond to dynamic symbol indexes.
6054 while (count
< non_reloc_only_global_gotno
)
6056 got
->add_constant(0);
6061 // Add GGA_RELOC_ONLY entries.
6062 got
->add_reloc_only_entries();
6066 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
6068 template<int size
, bool big_endian
>
6070 Mips_got_info
<size
, big_endian
>::add_reloc_only_entries(
6071 Mips_output_data_got
<size
, big_endian
>* got
)
6073 for (typename
Global_got_entry_set::iterator
6074 p
= this->global_got_symbols_
.begin();
6075 p
!= this->global_got_symbols_
.end();
6078 Mips_symbol
<size
>* mips_sym
= *p
;
6079 if (mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
6081 unsigned int got_type
;
6082 if (!got
->multi_got())
6083 got_type
= GOT_TYPE_STANDARD
;
6085 got_type
= GOT_TYPE_STANDARD_MULTIGOT
;
6086 if (got
->add_global(mips_sym
, got_type
))
6087 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
6092 // Create TLS GOT entries.
6094 template<int size
, bool big_endian
>
6096 Mips_got_info
<size
, big_endian
>::add_tls_entries(
6097 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
6099 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
6100 // Add local tls entries.
6101 for (typename
Got_entry_set::iterator
6102 p
= this->got_entries_
.begin();
6103 p
!= this->got_entries_
.end();
6106 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
6107 if (!entry
->is_tls_entry() || !entry
->is_for_local_symbol())
6110 if (entry
->tls_type() == GOT_TLS_GD
)
6112 unsigned int got_type
= GOT_TYPE_TLS_PAIR
;
6113 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
6114 : elfcpp::R_MIPS_TLS_DTPMOD64
);
6115 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
6116 : elfcpp::R_MIPS_TLS_DTPREL64
);
6118 if (!parameters
->doing_static_link())
6120 got
->add_local_pair_with_rel(entry
->object(), entry
->symndx(),
6121 entry
->shndx(), got_type
,
6122 target
->rel_dyn_section(layout
),
6123 r_type1
, entry
->addend());
6124 unsigned int got_offset
=
6125 entry
->object()->local_got_offset(entry
->symndx(), got_type
,
6127 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
6128 entry
->object(), entry
->symndx());
6132 // We are doing a static link. Mark it as belong to module 1,
6134 unsigned int got_offset
= got
->add_constant(1);
6135 entry
->object()->set_local_got_offset(entry
->symndx(), got_type
,
6138 got
->add_constant(0);
6139 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
6140 entry
->object(), entry
->symndx());
6143 else if (entry
->tls_type() == GOT_TLS_IE
)
6145 unsigned int got_type
= GOT_TYPE_TLS_OFFSET
;
6146 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
6147 : elfcpp::R_MIPS_TLS_TPREL64
);
6148 if (!parameters
->doing_static_link())
6149 got
->add_local_with_rel(entry
->object(), entry
->symndx(), got_type
,
6150 target
->rel_dyn_section(layout
), r_type
,
6154 got
->add_local(entry
->object(), entry
->symndx(), got_type
,
6156 unsigned int got_offset
=
6157 entry
->object()->local_got_offset(entry
->symndx(), got_type
,
6159 got
->add_static_reloc(got_offset
, r_type
, entry
->object(),
6163 else if (entry
->tls_type() == GOT_TLS_LDM
)
6165 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
6166 : elfcpp::R_MIPS_TLS_DTPMOD64
);
6167 unsigned int got_offset
;
6168 if (!parameters
->doing_static_link())
6170 got_offset
= got
->add_constant(0);
6171 target
->rel_dyn_section(layout
)->add_local(
6172 entry
->object(), 0, r_type
, got
, got_offset
);
6175 // We are doing a static link. Just mark it as belong to module 1,
6177 got_offset
= got
->add_constant(1);
6179 got
->add_constant(0);
6180 got
->set_tls_ldm_offset(got_offset
, entry
->object());
6186 // Add global tls entries.
6187 for (typename
Got_entry_set::iterator
6188 p
= this->got_entries_
.begin();
6189 p
!= this->got_entries_
.end();
6192 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
6193 if (!entry
->is_tls_entry() || !entry
->is_for_global_symbol())
6196 Mips_symbol
<size
>* mips_sym
= entry
->sym();
6197 if (entry
->tls_type() == GOT_TLS_GD
)
6199 unsigned int got_type
;
6200 if (!got
->multi_got())
6201 got_type
= GOT_TYPE_TLS_PAIR
;
6203 got_type
= GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
6204 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
6205 : elfcpp::R_MIPS_TLS_DTPMOD64
);
6206 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
6207 : elfcpp::R_MIPS_TLS_DTPREL64
);
6208 if (!parameters
->doing_static_link())
6209 got
->add_global_pair_with_rel(mips_sym
, got_type
,
6210 target
->rel_dyn_section(layout
), r_type1
, r_type2
);
6213 // Add a GOT pair for for R_MIPS_TLS_GD. The creates a pair of
6214 // GOT entries. The first one is initialized to be 1, which is the
6215 // module index for the main executable and the second one 0. A
6216 // reloc of the type R_MIPS_TLS_DTPREL32/64 will be created for
6217 // the second GOT entry and will be applied by gold.
6218 unsigned int got_offset
= got
->add_constant(1);
6219 mips_sym
->set_got_offset(got_type
, got_offset
);
6220 got
->add_constant(0);
6221 got
->add_static_reloc(got_offset
+ size
/8, r_type2
, mips_sym
);
6224 else if (entry
->tls_type() == GOT_TLS_IE
)
6226 unsigned int got_type
;
6227 if (!got
->multi_got())
6228 got_type
= GOT_TYPE_TLS_OFFSET
;
6230 got_type
= GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
6231 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
6232 : elfcpp::R_MIPS_TLS_TPREL64
);
6233 if (!parameters
->doing_static_link())
6234 got
->add_global_with_rel(mips_sym
, got_type
,
6235 target
->rel_dyn_section(layout
), r_type
);
6238 got
->add_global(mips_sym
, got_type
);
6239 unsigned int got_offset
= mips_sym
->got_offset(got_type
);
6240 got
->add_static_reloc(got_offset
, r_type
, mips_sym
);
6248 // Decide whether the symbol needs an entry in the global part of the primary
6249 // GOT, setting global_got_area accordingly. Count the number of global
6250 // symbols that are in the primary GOT only because they have dynamic
6251 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
6253 template<int size
, bool big_endian
>
6255 Mips_got_info
<size
, big_endian
>::count_got_symbols(Symbol_table
* symtab
)
6257 for (typename
Global_got_entry_set::iterator
6258 p
= this->global_got_symbols_
.begin();
6259 p
!= this->global_got_symbols_
.end();
6262 Mips_symbol
<size
>* sym
= *p
;
6263 // Make a final decision about whether the symbol belongs in the
6264 // local or global GOT. Symbols that bind locally can (and in the
6265 // case of forced-local symbols, must) live in the local GOT.
6266 // Those that are aren't in the dynamic symbol table must also
6267 // live in the local GOT.
6269 if (!sym
->should_add_dynsym_entry(symtab
)
6270 || (sym
->got_only_for_calls()
6271 ? symbol_calls_local(sym
, sym
->should_add_dynsym_entry(symtab
))
6272 : symbol_references_local(sym
,
6273 sym
->should_add_dynsym_entry(symtab
))))
6274 // The symbol belongs in the local GOT. We no longer need this
6275 // entry if it was only used for relocations; those relocations
6276 // will be against the null or section symbol instead.
6277 sym
->set_global_got_area(GGA_NONE
);
6278 else if (sym
->global_got_area() == GGA_RELOC_ONLY
)
6280 ++this->reloc_only_gotno_
;
6281 ++this->global_gotno_
;
6286 // Return the offset of GOT page entry for VALUE. Initialize the entry with
6287 // VALUE if it is not initialized.
6289 template<int size
, bool big_endian
>
6291 Mips_got_info
<size
, big_endian
>::get_got_page_offset(Mips_address value
,
6292 Mips_output_data_got
<size
, big_endian
>* got
)
6294 typename
Got_page_offsets::iterator it
= this->got_page_offsets_
.find(value
);
6295 if (it
!= this->got_page_offsets_
.end())
6298 gold_assert(this->got_page_offset_next_
< this->got_page_offset_start_
6299 + (size
/8) * this->page_gotno_
);
6301 unsigned int got_offset
= this->got_page_offset_next_
;
6302 this->got_page_offsets_
[value
] = got_offset
;
6303 this->got_page_offset_next_
+= size
/8;
6304 got
->update_got_entry(got_offset
, value
);
6308 // Remove lazy-binding stubs for global symbols in this GOT.
6310 template<int size
, bool big_endian
>
6312 Mips_got_info
<size
, big_endian
>::remove_lazy_stubs(
6313 Target_mips
<size
, big_endian
>* target
)
6315 for (typename
Got_entry_set::iterator
6316 p
= this->got_entries_
.begin();
6317 p
!= this->got_entries_
.end();
6320 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
6321 if (entry
->is_for_global_symbol())
6322 target
->remove_lazy_stub_entry(entry
->sym());
6326 // Count the number of GOT entries required.
6328 template<int size
, bool big_endian
>
6330 Mips_got_info
<size
, big_endian
>::count_got_entries()
6332 for (typename
Got_entry_set::iterator
6333 p
= this->got_entries_
.begin();
6334 p
!= this->got_entries_
.end();
6337 this->count_got_entry(*p
);
6341 // Count the number of GOT entries required by ENTRY. Accumulate the result.
6343 template<int size
, bool big_endian
>
6345 Mips_got_info
<size
, big_endian
>::count_got_entry(
6346 Mips_got_entry
<size
, big_endian
>* entry
)
6348 if (entry
->is_tls_entry())
6349 this->tls_gotno_
+= mips_tls_got_entries(entry
->tls_type());
6350 else if (entry
->is_for_local_symbol()
6351 || entry
->sym()->global_got_area() == GGA_NONE
)
6352 ++this->local_gotno_
;
6354 ++this->global_gotno_
;
6357 // Add FROM's GOT entries.
6359 template<int size
, bool big_endian
>
6361 Mips_got_info
<size
, big_endian
>::add_got_entries(
6362 Mips_got_info
<size
, big_endian
>* from
)
6364 for (typename
Got_entry_set::iterator
6365 p
= from
->got_entries_
.begin();
6366 p
!= from
->got_entries_
.end();
6369 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
6370 if (this->got_entries_
.find(entry
) == this->got_entries_
.end())
6372 Mips_got_entry
<size
, big_endian
>* entry2
=
6373 new Mips_got_entry
<size
, big_endian
>(*entry
);
6374 this->got_entries_
.insert(entry2
);
6375 this->count_got_entry(entry
);
6380 // Add FROM's GOT page entries.
6382 template<int size
, bool big_endian
>
6384 Mips_got_info
<size
, big_endian
>::add_got_page_count(
6385 Mips_got_info
<size
, big_endian
>* from
)
6387 this->page_gotno_
+= from
->page_gotno_
;
6390 // Mips_output_data_got methods.
6392 // Lay out the GOT. Add local, global and TLS entries. If GOT is
6393 // larger than 64K, create multi-GOT.
6395 template<int size
, bool big_endian
>
6397 Mips_output_data_got
<size
, big_endian
>::lay_out_got(Layout
* layout
,
6398 Symbol_table
* symtab
, const Input_objects
* input_objects
)
6400 // Decide which symbols need to go in the global part of the GOT and
6401 // count the number of reloc-only GOT symbols.
6402 this->master_got_info_
->count_got_symbols(symtab
);
6404 // Count the number of GOT entries.
6405 this->master_got_info_
->count_got_entries();
6407 unsigned int got_size
= this->master_got_info_
->got_size();
6408 if (got_size
> Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
)
6409 this->lay_out_multi_got(layout
, input_objects
);
6412 // Record that all objects use single GOT.
6413 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
6414 p
!= input_objects
->relobj_end();
6417 Mips_relobj
<size
, big_endian
>* object
=
6418 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
6419 if (object
->get_got_info() != NULL
)
6420 object
->set_got_info(this->master_got_info_
);
6423 this->master_got_info_
->add_local_entries(this->target_
, layout
);
6424 this->master_got_info_
->add_global_entries(this->target_
, layout
,
6426 this->master_got_info_
->add_tls_entries(this->target_
, layout
);
6430 // Create multi-GOT. For every GOT, add local, global and TLS entries.
6432 template<int size
, bool big_endian
>
6434 Mips_output_data_got
<size
, big_endian
>::lay_out_multi_got(Layout
* layout
,
6435 const Input_objects
* input_objects
)
6437 // Try to merge the GOTs of input objects together, as long as they
6438 // don't seem to exceed the maximum GOT size, choosing one of them
6439 // to be the primary GOT.
6440 this->merge_gots(input_objects
);
6442 // Every symbol that is referenced in a dynamic relocation must be
6443 // present in the primary GOT.
6444 this->primary_got_
->set_global_gotno(this->master_got_info_
->global_gotno());
6448 unsigned int offset
= 0;
6449 Mips_got_info
<size
, big_endian
>* g
= this->primary_got_
;
6453 g
->set_offset(offset
);
6455 g
->add_local_entries(this->target_
, layout
);
6457 g
->add_global_entries(this->target_
, layout
,
6458 (this->master_got_info_
->global_gotno()
6459 - this->master_got_info_
->reloc_only_gotno()));
6461 g
->add_global_entries(this->target_
, layout
, /*not used*/-1U);
6462 g
->add_tls_entries(this->target_
, layout
);
6464 // Forbid global symbols in every non-primary GOT from having
6465 // lazy-binding stubs.
6467 g
->remove_lazy_stubs(this->target_
);
6470 offset
+= g
->got_size();
6476 // Attempt to merge GOTs of different input objects. Try to use as much as
6477 // possible of the primary GOT, since it doesn't require explicit dynamic
6478 // relocations, but don't use objects that would reference global symbols
6479 // out of the addressable range. Failing the primary GOT, attempt to merge
6480 // with the current GOT, or finish the current GOT and then make make the new
6483 template<int size
, bool big_endian
>
6485 Mips_output_data_got
<size
, big_endian
>::merge_gots(
6486 const Input_objects
* input_objects
)
6488 gold_assert(this->primary_got_
== NULL
);
6489 Mips_got_info
<size
, big_endian
>* current
= NULL
;
6491 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
6492 p
!= input_objects
->relobj_end();
6495 Mips_relobj
<size
, big_endian
>* object
=
6496 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
6498 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
6502 g
->count_got_entries();
6504 // Work out the number of page, local and TLS entries.
6505 unsigned int estimate
= this->master_got_info_
->page_gotno();
6506 if (estimate
> g
->page_gotno())
6507 estimate
= g
->page_gotno();
6508 estimate
+= g
->local_gotno() + g
->tls_gotno();
6510 // We place TLS GOT entries after both locals and globals. The globals
6511 // for the primary GOT may overflow the normal GOT size limit, so be
6512 // sure not to merge a GOT which requires TLS with the primary GOT in that
6513 // case. This doesn't affect non-primary GOTs.
6514 estimate
+= (g
->tls_gotno() > 0 ? this->master_got_info_
->global_gotno()
6515 : g
->global_gotno());
6517 unsigned int max_count
=
6518 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
6519 if (estimate
<= max_count
)
6521 // If we don't have a primary GOT, use it as
6522 // a starting point for the primary GOT.
6523 if (!this->primary_got_
)
6525 this->primary_got_
= g
;
6529 // Try merging with the primary GOT.
6530 if (this->merge_got_with(g
, object
, this->primary_got_
))
6534 // If we can merge with the last-created GOT, do it.
6535 if (current
&& this->merge_got_with(g
, object
, current
))
6538 // Well, we couldn't merge, so create a new GOT. Don't check if it
6539 // fits; if it turns out that it doesn't, we'll get relocation
6540 // overflows anyway.
6541 g
->set_next(current
);
6545 // If we do not find any suitable primary GOT, create an empty one.
6546 if (this->primary_got_
== NULL
)
6547 this->primary_got_
= new Mips_got_info
<size
, big_endian
>();
6549 // Link primary GOT with secondary GOTs.
6550 this->primary_got_
->set_next(current
);
6553 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
6554 // this would lead to overflow, true if they were merged successfully.
6556 template<int size
, bool big_endian
>
6558 Mips_output_data_got
<size
, big_endian
>::merge_got_with(
6559 Mips_got_info
<size
, big_endian
>* from
,
6560 Mips_relobj
<size
, big_endian
>* object
,
6561 Mips_got_info
<size
, big_endian
>* to
)
6563 // Work out how many page entries we would need for the combined GOT.
6564 unsigned int estimate
= this->master_got_info_
->page_gotno();
6565 if (estimate
>= from
->page_gotno() + to
->page_gotno())
6566 estimate
= from
->page_gotno() + to
->page_gotno();
6568 // Conservatively estimate how many local and TLS entries would be needed.
6569 estimate
+= from
->local_gotno() + to
->local_gotno();
6570 estimate
+= from
->tls_gotno() + to
->tls_gotno();
6572 // If we're merging with the primary got, any TLS relocations will
6573 // come after the full set of global entries. Otherwise estimate those
6574 // conservatively as well.
6575 if (to
== this->primary_got_
&& (from
->tls_gotno() + to
->tls_gotno()) > 0)
6576 estimate
+= this->master_got_info_
->global_gotno();
6578 estimate
+= from
->global_gotno() + to
->global_gotno();
6580 // Bail out if the combined GOT might be too big.
6581 unsigned int max_count
=
6582 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
6583 if (estimate
> max_count
)
6586 // Transfer the object's GOT information from FROM to TO.
6587 to
->add_got_entries(from
);
6588 to
->add_got_page_count(from
);
6590 // Record that OBJECT should use output GOT TO.
6591 object
->set_got_info(to
);
6596 // Write out the GOT.
6598 template<int size
, bool big_endian
>
6600 Mips_output_data_got
<size
, big_endian
>::do_write(Output_file
* of
)
6602 typedef Unordered_set
<Mips_symbol
<size
>*, Mips_symbol_hash
<size
> >
6603 Mips_stubs_entry_set
;
6605 // Call parent to write out GOT.
6606 Output_data_got
<size
, big_endian
>::do_write(of
);
6608 const off_t offset
= this->offset();
6609 const section_size_type oview_size
=
6610 convert_to_section_size_type(this->data_size());
6611 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6613 // Needed for fixing values of .got section.
6614 this->got_view_
= oview
;
6616 // Write lazy stub addresses.
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 (mips_sym
->has_lazy_stub())
6625 Valtype
* wv
= reinterpret_cast<Valtype
*>(
6626 oview
+ this->get_primary_got_offset(mips_sym
));
6628 this->target_
->mips_stubs_section()->stub_address(mips_sym
);
6629 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
6633 // Add +1 to GGA_NONE nonzero MIPS16 and microMIPS entries.
6634 for (typename
Mips_stubs_entry_set::iterator
6635 p
= this->master_got_info_
->global_got_symbols().begin();
6636 p
!= this->master_got_info_
->global_got_symbols().end();
6639 Mips_symbol
<size
>* mips_sym
= *p
;
6640 if (!this->multi_got()
6641 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
6642 && mips_sym
->global_got_area() == GGA_NONE
6643 && mips_sym
->has_got_offset(GOT_TYPE_STANDARD
))
6645 Valtype
* wv
= reinterpret_cast<Valtype
*>(
6646 oview
+ mips_sym
->got_offset(GOT_TYPE_STANDARD
));
6647 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv
);
6651 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
6656 if (!this->secondary_got_relocs_
.empty())
6658 // Fixup for the secondary GOT R_MIPS_REL32 relocs. For global
6659 // secondary GOT entries with non-zero initial value copy the value
6660 // to the corresponding primary GOT entry, and set the secondary GOT
6662 // TODO(sasa): This is workaround. It needs to be investigated further.
6664 for (size_t i
= 0; i
< this->secondary_got_relocs_
.size(); ++i
)
6666 Static_reloc
& reloc(this->secondary_got_relocs_
[i
]);
6667 if (reloc
.symbol_is_global())
6669 Mips_symbol
<size
>* gsym
= reloc
.symbol();
6670 gold_assert(gsym
!= NULL
);
6672 unsigned got_offset
= reloc
.got_offset();
6673 gold_assert(got_offset
< oview_size
);
6675 // Find primary GOT entry.
6676 Valtype
* wv_prim
= reinterpret_cast<Valtype
*>(
6677 oview
+ this->get_primary_got_offset(gsym
));
6679 // Find secondary GOT entry.
6680 Valtype
* wv_sec
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6682 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv_sec
);
6685 elfcpp::Swap
<size
, big_endian
>::writeval(wv_prim
, value
);
6686 elfcpp::Swap
<size
, big_endian
>::writeval(wv_sec
, 0);
6687 gsym
->set_applied_secondary_got_fixup();
6692 of
->write_output_view(offset
, oview_size
, oview
);
6695 // We are done if there is no fix up.
6696 if (this->static_relocs_
.empty())
6699 Output_segment
* tls_segment
= this->layout_
->tls_segment();
6700 gold_assert(tls_segment
!= NULL
);
6702 for (size_t i
= 0; i
< this->static_relocs_
.size(); ++i
)
6704 Static_reloc
& reloc(this->static_relocs_
[i
]);
6707 if (!reloc
.symbol_is_global())
6709 Sized_relobj_file
<size
, big_endian
>* object
= reloc
.relobj();
6710 const Symbol_value
<size
>* psymval
=
6711 object
->local_symbol(reloc
.index());
6713 // We are doing static linking. Issue an error and skip this
6714 // relocation if the symbol is undefined or in a discarded_section.
6716 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
6717 if ((shndx
== elfcpp::SHN_UNDEF
)
6719 && shndx
!= elfcpp::SHN_UNDEF
6720 && !object
->is_section_included(shndx
)
6721 && !this->symbol_table_
->is_section_folded(object
, shndx
)))
6723 gold_error(_("undefined or discarded local symbol %u from "
6724 " object %s in GOT"),
6725 reloc
.index(), reloc
.relobj()->name().c_str());
6729 value
= psymval
->value(object
, 0);
6733 const Mips_symbol
<size
>* gsym
= reloc
.symbol();
6734 gold_assert(gsym
!= NULL
);
6736 // We are doing static linking. Issue an error and skip this
6737 // relocation if the symbol is undefined or in a discarded_section
6738 // unless it is a weakly_undefined symbol.
6739 if ((gsym
->is_defined_in_discarded_section() || gsym
->is_undefined())
6740 && !gsym
->is_weak_undefined())
6742 gold_error(_("undefined or discarded symbol %s in GOT"),
6747 if (!gsym
->is_weak_undefined())
6748 value
= gsym
->value();
6753 unsigned got_offset
= reloc
.got_offset();
6754 gold_assert(got_offset
< oview_size
);
6756 Valtype
* wv
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6759 switch (reloc
.r_type())
6761 case elfcpp::R_MIPS_TLS_DTPMOD32
:
6762 case elfcpp::R_MIPS_TLS_DTPMOD64
:
6765 case elfcpp::R_MIPS_TLS_DTPREL32
:
6766 case elfcpp::R_MIPS_TLS_DTPREL64
:
6767 x
= value
- elfcpp::DTP_OFFSET
;
6769 case elfcpp::R_MIPS_TLS_TPREL32
:
6770 case elfcpp::R_MIPS_TLS_TPREL64
:
6771 x
= value
- elfcpp::TP_OFFSET
;
6778 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, x
);
6781 of
->write_output_view(offset
, oview_size
, oview
);
6784 // Mips_relobj methods.
6786 // Count the local symbols. The Mips backend needs to know if a symbol
6787 // is a MIPS16 or microMIPS function or not. For global symbols, it is easy
6788 // because the Symbol object keeps the ELF symbol type and st_other field.
6789 // For local symbol it is harder because we cannot access this information.
6790 // So we override the do_count_local_symbol in parent and scan local symbols to
6791 // mark MIPS16 and microMIPS functions. This is not the most efficient way but
6792 // I do not want to slow down other ports by calling a per symbol target hook
6793 // inside Sized_relobj_file<size, big_endian>::do_count_local_symbols.
6795 template<int size
, bool big_endian
>
6797 Mips_relobj
<size
, big_endian
>::do_count_local_symbols(
6798 Stringpool_template
<char>* pool
,
6799 Stringpool_template
<char>* dynpool
)
6801 // Ask parent to count the local symbols.
6802 Sized_relobj_file
<size
, big_endian
>::do_count_local_symbols(pool
, dynpool
);
6803 const unsigned int loccount
= this->local_symbol_count();
6807 // Initialize the mips16 and micromips function bit-vector.
6808 this->local_symbol_is_mips16_
.resize(loccount
, false);
6809 this->local_symbol_is_micromips_
.resize(loccount
, false);
6811 // Read the symbol table section header.
6812 const unsigned int symtab_shndx
= this->symtab_shndx();
6813 elfcpp::Shdr
<size
, big_endian
>
6814 symtabshdr(this, this->elf_file()->section_header(symtab_shndx
));
6815 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
6817 // Read the local symbols.
6818 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
6819 gold_assert(loccount
== symtabshdr
.get_sh_info());
6820 off_t locsize
= loccount
* sym_size
;
6821 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
6822 locsize
, true, true);
6824 // Loop over the local symbols and mark any MIPS16 or microMIPS local symbols.
6826 // Skip the first dummy symbol.
6828 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
6830 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
6831 unsigned char st_other
= sym
.get_st_other();
6832 this->local_symbol_is_mips16_
[i
] = elfcpp::elf_st_is_mips16(st_other
);
6833 this->local_symbol_is_micromips_
[i
] =
6834 elfcpp::elf_st_is_micromips(st_other
);
6838 // Read the symbol information.
6840 template<int size
, bool big_endian
>
6842 Mips_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
6844 // Call parent class to read symbol information.
6845 this->base_read_symbols(sd
);
6847 // If this input file is a binary file, it has no processor
6849 Input_file::Format format
= this->input_file()->format();
6850 if (format
!= Input_file::FORMAT_ELF
)
6852 gold_assert(format
== Input_file::FORMAT_BINARY
);
6853 this->merge_processor_specific_data_
= false;
6857 // Read processor-specific flags in ELF file header.
6858 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
6859 elfcpp::Elf_sizes
<size
>::ehdr_size
,
6861 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
6862 this->processor_specific_flags_
= ehdr
.get_e_flags();
6864 // Get the section names.
6865 const unsigned char* pnamesu
= sd
->section_names
->data();
6866 const char* pnames
= reinterpret_cast<const char*>(pnamesu
);
6868 // Initialize the mips16 stub section bit-vectors.
6869 this->section_is_mips16_fn_stub_
.resize(this->shnum(), false);
6870 this->section_is_mips16_call_stub_
.resize(this->shnum(), false);
6871 this->section_is_mips16_call_fp_stub_
.resize(this->shnum(), false);
6873 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
6874 const unsigned char* pshdrs
= sd
->section_headers
->data();
6875 const unsigned char* ps
= pshdrs
+ shdr_size
;
6876 bool must_merge_processor_specific_data
= false;
6877 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
6879 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
6881 // Sometimes an object has no contents except the section name string
6882 // table and an empty symbol table with the undefined symbol. We
6883 // don't want to merge processor-specific data from such an object.
6884 if (shdr
.get_sh_type() == elfcpp::SHT_SYMTAB
)
6886 // Symbol table is not empty.
6887 const typename
elfcpp::Elf_types
<size
>::Elf_WXword sym_size
=
6888 elfcpp::Elf_sizes
<size
>::sym_size
;
6889 if (shdr
.get_sh_size() > sym_size
)
6890 must_merge_processor_specific_data
= true;
6892 else if (shdr
.get_sh_type() != elfcpp::SHT_STRTAB
)
6893 // If this is neither an empty symbol table nor a string table,
6895 must_merge_processor_specific_data
= true;
6897 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_REGINFO
)
6899 this->has_reginfo_section_
= true;
6900 // Read the gp value that was used to create this object. We need the
6901 // gp value while processing relocs. The .reginfo section is not used
6902 // in the 64-bit MIPS ELF ABI.
6903 section_offset_type section_offset
= shdr
.get_sh_offset();
6904 section_size_type section_size
=
6905 convert_to_section_size_type(shdr
.get_sh_size());
6906 const unsigned char* view
=
6907 this->get_view(section_offset
, section_size
, true, false);
6909 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 20);
6911 // Read the rest of .reginfo.
6912 this->gprmask_
= elfcpp::Swap
<size
, big_endian
>::readval(view
);
6913 this->cprmask1_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 4);
6914 this->cprmask2_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 8);
6915 this->cprmask3_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 12);
6916 this->cprmask4_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 16);
6919 if (shdr
.get_sh_type() == elfcpp::SHT_GNU_ATTRIBUTES
)
6921 gold_assert(this->attributes_section_data_
== NULL
);
6922 section_offset_type section_offset
= shdr
.get_sh_offset();
6923 section_size_type section_size
=
6924 convert_to_section_size_type(shdr
.get_sh_size());
6925 const unsigned char* view
=
6926 this->get_view(section_offset
, section_size
, true, false);
6927 this->attributes_section_data_
=
6928 new Attributes_section_data(view
, section_size
);
6931 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_ABIFLAGS
)
6933 gold_assert(this->abiflags_
== NULL
);
6934 section_offset_type section_offset
= shdr
.get_sh_offset();
6935 section_size_type section_size
=
6936 convert_to_section_size_type(shdr
.get_sh_size());
6937 const unsigned char* view
=
6938 this->get_view(section_offset
, section_size
, true, false);
6939 this->abiflags_
= new Mips_abiflags
<big_endian
>();
6941 this->abiflags_
->version
=
6942 elfcpp::Swap
<16, big_endian
>::readval(view
);
6943 if (this->abiflags_
->version
!= 0)
6945 gold_error(_("%s: .MIPS.abiflags section has "
6946 "unsupported version %u"),
6947 this->name().c_str(),
6948 this->abiflags_
->version
);
6951 this->abiflags_
->isa_level
=
6952 elfcpp::Swap
<8, big_endian
>::readval(view
+ 2);
6953 this->abiflags_
->isa_rev
=
6954 elfcpp::Swap
<8, big_endian
>::readval(view
+ 3);
6955 this->abiflags_
->gpr_size
=
6956 elfcpp::Swap
<8, big_endian
>::readval(view
+ 4);
6957 this->abiflags_
->cpr1_size
=
6958 elfcpp::Swap
<8, big_endian
>::readval(view
+ 5);
6959 this->abiflags_
->cpr2_size
=
6960 elfcpp::Swap
<8, big_endian
>::readval(view
+ 6);
6961 this->abiflags_
->fp_abi
=
6962 elfcpp::Swap
<8, big_endian
>::readval(view
+ 7);
6963 this->abiflags_
->isa_ext
=
6964 elfcpp::Swap
<32, big_endian
>::readval(view
+ 8);
6965 this->abiflags_
->ases
=
6966 elfcpp::Swap
<32, big_endian
>::readval(view
+ 12);
6967 this->abiflags_
->flags1
=
6968 elfcpp::Swap
<32, big_endian
>::readval(view
+ 16);
6969 this->abiflags_
->flags2
=
6970 elfcpp::Swap
<32, big_endian
>::readval(view
+ 20);
6973 // In the 64-bit ABI, .MIPS.options section holds register information.
6974 // A SHT_MIPS_OPTIONS section contains a series of options, each of which
6975 // starts with this header:
6979 // // Type of option.
6980 // unsigned char kind[1];
6981 // // Size of option descriptor, including header.
6982 // unsigned char size[1];
6983 // // Section index of affected section, or 0 for global option.
6984 // unsigned char section[2];
6985 // // Information specific to this kind of option.
6986 // unsigned char info[4];
6989 // For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and set
6990 // the gp value based on what we find. We may see both SHT_MIPS_REGINFO
6991 // and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case, they should agree.
6993 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_OPTIONS
)
6995 section_offset_type section_offset
= shdr
.get_sh_offset();
6996 section_size_type section_size
=
6997 convert_to_section_size_type(shdr
.get_sh_size());
6998 const unsigned char* view
=
6999 this->get_view(section_offset
, section_size
, true, false);
7000 const unsigned char* end
= view
+ section_size
;
7002 while (view
+ 8 <= end
)
7004 unsigned char kind
= elfcpp::Swap
<8, big_endian
>::readval(view
);
7005 unsigned char sz
= elfcpp::Swap
<8, big_endian
>::readval(view
+ 1);
7008 gold_error(_("%s: Warning: bad `%s' option size %u smaller "
7010 this->name().c_str(),
7011 this->mips_elf_options_section_name(), sz
);
7015 if (this->is_n64() && kind
== elfcpp::ODK_REGINFO
)
7017 // In the 64 bit ABI, an ODK_REGINFO option is the following
7018 // structure. The info field of the options header is not
7023 // // Mask of general purpose registers used.
7024 // unsigned char ri_gprmask[4];
7026 // unsigned char ri_pad[4];
7027 // // Mask of co-processor registers used.
7028 // unsigned char ri_cprmask[4][4];
7029 // // GP register value for this object file.
7030 // unsigned char ri_gp_value[8];
7033 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
7036 else if (kind
== elfcpp::ODK_REGINFO
)
7038 // In the 32 bit ABI, an ODK_REGINFO option is the following
7039 // structure. The info field of the options header is not
7040 // used. The same structure is used in .reginfo section.
7044 // unsigned char ri_gprmask[4];
7045 // unsigned char ri_cprmask[4][4];
7046 // unsigned char ri_gp_value[4];
7049 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
7056 const char* name
= pnames
+ shdr
.get_sh_name();
7057 this->section_is_mips16_fn_stub_
[i
] = is_prefix_of(".mips16.fn", name
);
7058 this->section_is_mips16_call_stub_
[i
] =
7059 is_prefix_of(".mips16.call.", name
);
7060 this->section_is_mips16_call_fp_stub_
[i
] =
7061 is_prefix_of(".mips16.call.fp.", name
);
7063 if (strcmp(name
, ".pdr") == 0)
7065 gold_assert(this->pdr_shndx_
== -1U);
7066 this->pdr_shndx_
= i
;
7071 if (!must_merge_processor_specific_data
)
7072 this->merge_processor_specific_data_
= false;
7075 // Discard MIPS16 stub secions that are not needed.
7077 template<int size
, bool big_endian
>
7079 Mips_relobj
<size
, big_endian
>::discard_mips16_stub_sections(Symbol_table
* symtab
)
7081 for (typename
Mips16_stubs_int_map::const_iterator
7082 it
= this->mips16_stub_sections_
.begin();
7083 it
!= this->mips16_stub_sections_
.end(); ++it
)
7085 Mips16_stub_section
<size
, big_endian
>* stub_section
= it
->second
;
7086 if (!stub_section
->is_target_found())
7088 gold_error(_("no relocation found in mips16 stub section '%s'"),
7089 stub_section
->object()
7090 ->section_name(stub_section
->shndx()).c_str());
7093 bool discard
= false;
7094 if (stub_section
->is_for_local_function())
7096 if (stub_section
->is_fn_stub())
7098 // This stub is for a local symbol. This stub will only
7099 // be needed if there is some relocation in this object,
7100 // other than a 16 bit function call, which refers to this
7102 if (!this->has_local_non_16bit_call_relocs(stub_section
->r_sym()))
7105 this->add_local_mips16_fn_stub(stub_section
);
7109 // This stub is for a local symbol. This stub will only
7110 // be needed if there is some relocation (R_MIPS16_26) in
7111 // this object that refers to this symbol.
7112 gold_assert(stub_section
->is_call_stub()
7113 || stub_section
->is_call_fp_stub());
7114 if (!this->has_local_16bit_call_relocs(stub_section
->r_sym()))
7117 this->add_local_mips16_call_stub(stub_section
);
7122 Mips_symbol
<size
>* gsym
= stub_section
->gsym();
7123 if (stub_section
->is_fn_stub())
7125 if (gsym
->has_mips16_fn_stub())
7126 // We already have a stub for this function.
7130 gsym
->set_mips16_fn_stub(stub_section
);
7131 if (gsym
->should_add_dynsym_entry(symtab
))
7133 // If we have a MIPS16 function with a stub, the
7134 // dynamic symbol must refer to the stub, since only
7135 // the stub uses the standard calling conventions.
7136 gsym
->set_need_fn_stub();
7137 if (gsym
->is_from_dynobj())
7138 gsym
->set_needs_dynsym_value();
7141 if (!gsym
->need_fn_stub())
7144 else if (stub_section
->is_call_stub())
7146 if (gsym
->is_mips16())
7147 // We don't need the call_stub; this is a 16 bit
7148 // function, so calls from other 16 bit functions are
7151 else if (gsym
->has_mips16_call_stub())
7152 // We already have a stub for this function.
7155 gsym
->set_mips16_call_stub(stub_section
);
7159 gold_assert(stub_section
->is_call_fp_stub());
7160 if (gsym
->is_mips16())
7161 // We don't need the call_stub; this is a 16 bit
7162 // function, so calls from other 16 bit functions are
7165 else if (gsym
->has_mips16_call_fp_stub())
7166 // We already have a stub for this function.
7169 gsym
->set_mips16_call_fp_stub(stub_section
);
7173 this->set_output_section(stub_section
->shndx(), NULL
);
7177 // Mips_output_data_la25_stub methods.
7179 // Template for standard LA25 stub.
7180 template<int size
, bool big_endian
>
7182 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_entry
[] =
7184 0x3c190000, // lui $25,%hi(func)
7185 0x08000000, // j func
7186 0x27390000, // add $25,$25,%lo(func)
7190 // Template for microMIPS LA25 stub.
7191 template<int size
, bool big_endian
>
7193 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_micromips_entry
[] =
7195 0x41b9, 0x0000, // lui t9,%hi(func)
7196 0xd400, 0x0000, // j func
7197 0x3339, 0x0000, // addiu t9,t9,%lo(func)
7198 0x0000, 0x0000 // nop
7201 // Create la25 stub for a symbol.
7203 template<int size
, bool big_endian
>
7205 Mips_output_data_la25_stub
<size
, big_endian
>::create_la25_stub(
7206 Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
7207 Mips_symbol
<size
>* gsym
)
7209 if (!gsym
->has_la25_stub())
7211 gsym
->set_la25_stub_offset(this->symbols_
.size() * 16);
7212 this->symbols_
.push_back(gsym
);
7213 this->create_stub_symbol(gsym
, symtab
, target
, 16);
7217 // Create a symbol for SYM stub's value and size, to help make the disassembly
7220 template<int size
, bool big_endian
>
7222 Mips_output_data_la25_stub
<size
, big_endian
>::create_stub_symbol(
7223 Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
7224 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
)
7226 std::string
name(".pic.");
7227 name
+= sym
->name();
7229 unsigned int offset
= sym
->la25_stub_offset();
7230 if (sym
->is_micromips())
7233 // Make it a local function.
7234 Symbol
* new_sym
= symtab
->define_in_output_data(name
.c_str(), NULL
,
7235 Symbol_table::PREDEFINED
,
7236 target
->la25_stub_section(),
7237 offset
, symsize
, elfcpp::STT_FUNC
,
7239 elfcpp::STV_DEFAULT
, 0,
7241 new_sym
->set_is_forced_local();
7244 // Write out la25 stubs. This uses the hand-coded instructions above,
7245 // and adjusts them as needed.
7247 template<int size
, bool big_endian
>
7249 Mips_output_data_la25_stub
<size
, big_endian
>::do_write(Output_file
* of
)
7251 const off_t offset
= this->offset();
7252 const section_size_type oview_size
=
7253 convert_to_section_size_type(this->data_size());
7254 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
7256 for (typename
std::vector
<Mips_symbol
<size
>*>::iterator
7257 p
= this->symbols_
.begin();
7258 p
!= this->symbols_
.end();
7261 Mips_symbol
<size
>* sym
= *p
;
7262 unsigned char* pov
= oview
+ sym
->la25_stub_offset();
7264 Mips_address target
= sym
->value();
7265 if (!sym
->is_micromips())
7267 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7268 la25_stub_entry
[0] | (((target
+ 0x8000) >> 16) & 0xffff));
7269 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7270 la25_stub_entry
[1] | ((target
>> 2) & 0x3ffffff));
7271 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
7272 la25_stub_entry
[2] | (target
& 0xffff));
7273 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12, la25_stub_entry
[3]);
7278 // First stub instruction. Paste high 16-bits of the target.
7279 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
7280 la25_stub_micromips_entry
[0]);
7281 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7282 ((target
+ 0x8000) >> 16) & 0xffff);
7283 // Second stub instruction. Paste low 26-bits of the target, shifted
7285 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
7286 la25_stub_micromips_entry
[2] | ((target
>> 17) & 0x3ff));
7287 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
7288 la25_stub_micromips_entry
[3] | ((target
>> 1) & 0xffff));
7289 // Third stub instruction. Paste low 16-bits of the target.
7290 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8,
7291 la25_stub_micromips_entry
[4]);
7292 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, target
& 0xffff);
7293 // Fourth stub instruction.
7294 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 12,
7295 la25_stub_micromips_entry
[6]);
7296 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 14,
7297 la25_stub_micromips_entry
[7]);
7301 of
->write_output_view(offset
, oview_size
, oview
);
7304 // Mips_output_data_plt methods.
7306 // The format of the first PLT entry in an O32 executable.
7307 template<int size
, bool big_endian
>
7308 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_o32
[] =
7310 0x3c1c0000, // lui $28, %hi(&GOTPLT[0])
7311 0x8f990000, // lw $25, %lo(&GOTPLT[0])($28)
7312 0x279c0000, // addiu $28, $28, %lo(&GOTPLT[0])
7313 0x031cc023, // subu $24, $24, $28
7314 0x03e07825, // or $15, $31, zero
7315 0x0018c082, // srl $24, $24, 2
7316 0x0320f809, // jalr $25
7317 0x2718fffe // subu $24, $24, 2
7320 // The format of the first PLT entry in an N32 executable. Different
7321 // because gp ($28) is not available; we use t2 ($14) instead.
7322 template<int size
, bool big_endian
>
7323 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n32
[] =
7325 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
7326 0x8dd90000, // lw $25, %lo(&GOTPLT[0])($14)
7327 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
7328 0x030ec023, // subu $24, $24, $14
7329 0x03e07825, // or $15, $31, zero
7330 0x0018c082, // srl $24, $24, 2
7331 0x0320f809, // jalr $25
7332 0x2718fffe // subu $24, $24, 2
7335 // The format of the first PLT entry in an N64 executable. Different
7336 // from N32 because of the increased size of GOT entries.
7337 template<int size
, bool big_endian
>
7338 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n64
[] =
7340 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
7341 0xddd90000, // ld $25, %lo(&GOTPLT[0])($14)
7342 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
7343 0x030ec023, // subu $24, $24, $14
7344 0x03e07825, // or $15, $31, zero
7345 0x0018c0c2, // srl $24, $24, 3
7346 0x0320f809, // jalr $25
7347 0x2718fffe // subu $24, $24, 2
7350 // The format of the microMIPS first PLT entry in an O32 executable.
7351 // We rely on v0 ($2) rather than t8 ($24) to contain the address
7352 // of the GOTPLT entry handled, so this stub may only be used when
7353 // all the subsequent PLT entries are microMIPS code too.
7355 // The trailing NOP is for alignment and correct disassembly only.
7356 template<int size
, bool big_endian
>
7357 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
7358 plt0_entry_micromips_o32
[] =
7360 0x7980, 0x0000, // addiupc $3, (&GOTPLT[0]) - .
7361 0xff23, 0x0000, // lw $25, 0($3)
7362 0x0535, // subu $2, $2, $3
7363 0x2525, // srl $2, $2, 2
7364 0x3302, 0xfffe, // subu $24, $2, 2
7365 0x0dff, // move $15, $31
7366 0x45f9, // jalrs $25
7367 0x0f83, // move $28, $3
7371 // The format of the microMIPS first PLT entry in an O32 executable
7372 // in the insn32 mode.
7373 template<int size
, bool big_endian
>
7374 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
7375 plt0_entry_micromips32_o32
[] =
7377 0x41bc, 0x0000, // lui $28, %hi(&GOTPLT[0])
7378 0xff3c, 0x0000, // lw $25, %lo(&GOTPLT[0])($28)
7379 0x339c, 0x0000, // addiu $28, $28, %lo(&GOTPLT[0])
7380 0x0398, 0xc1d0, // subu $24, $24, $28
7381 0x001f, 0x7a90, // or $15, $31, zero
7382 0x0318, 0x1040, // srl $24, $24, 2
7383 0x03f9, 0x0f3c, // jalr $25
7384 0x3318, 0xfffe // subu $24, $24, 2
7387 // The format of subsequent standard entries in the PLT.
7388 template<int size
, bool big_endian
>
7389 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry
[] =
7391 0x3c0f0000, // lui $15, %hi(.got.plt entry)
7392 0x01f90000, // l[wd] $25, %lo(.got.plt entry)($15)
7393 0x03200008, // jr $25
7394 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
7397 // The format of subsequent R6 PLT entries.
7398 template<int size
, bool big_endian
>
7399 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry_r6
[] =
7401 0x3c0f0000, // lui $15, %hi(.got.plt entry)
7402 0x01f90000, // l[wd] $25, %lo(.got.plt entry)($15)
7403 0x03200009, // jr $25
7404 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
7407 // The format of subsequent MIPS16 o32 PLT entries. We use v1 ($3) as a
7408 // temporary because t8 ($24) and t9 ($25) are not directly addressable.
7409 // Note that this differs from the GNU ld which uses both v0 ($2) and v1 ($3).
7410 // We cannot use v0 because MIPS16 call stubs from the CS toolchain expect
7411 // target function address in register v0.
7412 template<int size
, bool big_endian
>
7413 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry_mips16_o32
[] =
7415 0xb303, // lw $3, 12($pc)
7416 0x651b, // move $24, $3
7417 0x9b60, // lw $3, 0($3)
7419 0x653b, // move $25, $3
7421 0x0000, 0x0000 // .word (.got.plt entry)
7424 // The format of subsequent microMIPS o32 PLT entries. We use v0 ($2)
7425 // as a temporary because t8 ($24) is not addressable with ADDIUPC.
7426 template<int size
, bool big_endian
>
7427 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
7428 plt_entry_micromips_o32
[] =
7430 0x7900, 0x0000, // addiupc $2, (.got.plt entry) - .
7431 0xff22, 0x0000, // lw $25, 0($2)
7433 0x0f02 // move $24, $2
7436 // The format of subsequent microMIPS o32 PLT entries in the insn32 mode.
7437 template<int size
, bool big_endian
>
7438 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
7439 plt_entry_micromips32_o32
[] =
7441 0x41af, 0x0000, // lui $15, %hi(.got.plt entry)
7442 0xff2f, 0x0000, // lw $25, %lo(.got.plt entry)($15)
7443 0x0019, 0x0f3c, // jr $25
7444 0x330f, 0x0000 // addiu $24, $15, %lo(.got.plt entry)
7447 // Add an entry to the PLT for a symbol referenced by r_type relocation.
7449 template<int size
, bool big_endian
>
7451 Mips_output_data_plt
<size
, big_endian
>::add_entry(Mips_symbol
<size
>* gsym
,
7452 unsigned int r_type
)
7454 gold_assert(!gsym
->has_plt_offset());
7456 // Final PLT offset for a symbol will be set in method set_plt_offsets().
7457 gsym
->set_plt_offset(this->entry_count() * sizeof(plt_entry
)
7458 + sizeof(plt0_entry_o32
));
7459 this->symbols_
.push_back(gsym
);
7461 // Record whether the relocation requires a standard MIPS
7462 // or a compressed code entry.
7463 if (jal_reloc(r_type
))
7465 if (r_type
== elfcpp::R_MIPS_26
)
7466 gsym
->set_needs_mips_plt(true);
7468 gsym
->set_needs_comp_plt(true);
7471 section_offset_type got_offset
= this->got_plt_
->current_data_size();
7473 // Every PLT entry needs a GOT entry which points back to the PLT
7474 // entry (this will be changed by the dynamic linker, normally
7475 // lazily when the function is called).
7476 this->got_plt_
->set_current_data_size(got_offset
+ size
/8);
7478 gsym
->set_needs_dynsym_entry();
7479 this->rel_
->add_global(gsym
, elfcpp::R_MIPS_JUMP_SLOT
, this->got_plt_
,
7483 // Set final PLT offsets. For each symbol, determine whether standard or
7484 // compressed (MIPS16 or microMIPS) PLT entry is used.
7486 template<int size
, bool big_endian
>
7488 Mips_output_data_plt
<size
, big_endian
>::set_plt_offsets()
7490 // The sizes of individual PLT entries.
7491 unsigned int plt_mips_entry_size
= this->standard_plt_entry_size();
7492 unsigned int plt_comp_entry_size
= (!this->target_
->is_output_newabi()
7493 ? this->compressed_plt_entry_size() : 0);
7495 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
7496 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
7498 Mips_symbol
<size
>* mips_sym
= *p
;
7500 // There are no defined MIPS16 or microMIPS PLT entries for n32 or n64,
7501 // so always use a standard entry there.
7503 // If the symbol has a MIPS16 call stub and gets a PLT entry, then
7504 // all MIPS16 calls will go via that stub, and there is no benefit
7505 // to having a MIPS16 entry. And in the case of call_stub a
7506 // standard entry actually has to be used as the stub ends with a J
7508 if (this->target_
->is_output_newabi()
7509 || mips_sym
->has_mips16_call_stub()
7510 || mips_sym
->has_mips16_call_fp_stub())
7512 mips_sym
->set_needs_mips_plt(true);
7513 mips_sym
->set_needs_comp_plt(false);
7516 // Otherwise, if there are no direct calls to the function, we
7517 // have a free choice of whether to use standard or compressed
7518 // entries. Prefer microMIPS entries if the object is known to
7519 // contain microMIPS code, so that it becomes possible to create
7520 // pure microMIPS binaries. Prefer standard entries otherwise,
7521 // because MIPS16 ones are no smaller and are usually slower.
7522 if (!mips_sym
->needs_mips_plt() && !mips_sym
->needs_comp_plt())
7524 if (this->target_
->is_output_micromips())
7525 mips_sym
->set_needs_comp_plt(true);
7527 mips_sym
->set_needs_mips_plt(true);
7530 if (mips_sym
->needs_mips_plt())
7532 mips_sym
->set_mips_plt_offset(this->plt_mips_offset_
);
7533 this->plt_mips_offset_
+= plt_mips_entry_size
;
7535 if (mips_sym
->needs_comp_plt())
7537 mips_sym
->set_comp_plt_offset(this->plt_comp_offset_
);
7538 this->plt_comp_offset_
+= plt_comp_entry_size
;
7542 // Figure out the size of the PLT header if we know that we are using it.
7543 if (this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0)
7544 this->plt_header_size_
= this->get_plt_header_size();
7547 // Write out the PLT. This uses the hand-coded instructions above,
7548 // and adjusts them as needed.
7550 template<int size
, bool big_endian
>
7552 Mips_output_data_plt
<size
, big_endian
>::do_write(Output_file
* of
)
7554 const off_t offset
= this->offset();
7555 const section_size_type oview_size
=
7556 convert_to_section_size_type(this->data_size());
7557 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
7559 const off_t gotplt_file_offset
= this->got_plt_
->offset();
7560 const section_size_type gotplt_size
=
7561 convert_to_section_size_type(this->got_plt_
->data_size());
7562 unsigned char* const gotplt_view
= of
->get_output_view(gotplt_file_offset
,
7564 unsigned char* pov
= oview
;
7566 Mips_address plt_address
= this->address();
7568 // Calculate the address of .got.plt.
7569 Mips_address gotplt_addr
= this->got_plt_
->address();
7570 Mips_address gotplt_addr_high
= ((gotplt_addr
+ 0x8000) >> 16) & 0xffff;
7571 Mips_address gotplt_addr_low
= gotplt_addr
& 0xffff;
7573 // The PLT sequence is not safe for N64 if .got.plt's address can
7574 // not be loaded in two instructions.
7575 gold_assert((gotplt_addr
& ~(Mips_address
) 0x7fffffff) == 0
7576 || ~(gotplt_addr
| 0x7fffffff) == 0);
7578 // Write the PLT header.
7579 const uint32_t* plt0_entry
= this->get_plt_header_entry();
7580 if (plt0_entry
== plt0_entry_micromips_o32
)
7582 // Write microMIPS PLT header.
7583 gold_assert(gotplt_addr
% 4 == 0);
7585 Mips_address gotpc_offset
= gotplt_addr
- ((plt_address
| 3) ^ 3);
7587 // ADDIUPC has a span of +/-16MB, check we're in range.
7588 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
7590 gold_error(_(".got.plt offset of %ld from .plt beyond the range of "
7591 "ADDIUPC"), (long)gotpc_offset
);
7595 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
7596 plt0_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
7597 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7598 (gotpc_offset
>> 2) & 0xffff);
7600 for (unsigned int i
= 2;
7601 i
< (sizeof(plt0_entry_micromips_o32
)
7602 / sizeof(plt0_entry_micromips_o32
[0]));
7605 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7609 else if (plt0_entry
== plt0_entry_micromips32_o32
)
7611 // Write microMIPS PLT header in insn32 mode.
7612 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[0]);
7613 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, gotplt_addr_high
);
7614 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, plt0_entry
[2]);
7615 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, gotplt_addr_low
);
7616 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8, plt0_entry
[4]);
7617 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, gotplt_addr_low
);
7619 for (unsigned int i
= 6;
7620 i
< (sizeof(plt0_entry_micromips32_o32
)
7621 / sizeof(plt0_entry_micromips32_o32
[0]));
7624 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7630 // Write standard PLT header.
7631 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7632 plt0_entry
[0] | gotplt_addr_high
);
7633 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7634 plt0_entry
[1] | gotplt_addr_low
);
7635 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
7636 plt0_entry
[2] | gotplt_addr_low
);
7638 for (int i
= 3; i
< 8; i
++)
7640 elfcpp::Swap
<32, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7646 unsigned char* gotplt_pov
= gotplt_view
;
7647 unsigned int got_entry_size
= size
/8; // TODO(sasa): MIPS_ELF_GOT_SIZE
7649 // The first two entries in .got.plt are reserved.
7650 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
, 0);
7651 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
+ got_entry_size
, 0);
7653 unsigned int gotplt_offset
= 2 * got_entry_size
;
7654 gotplt_pov
+= 2 * got_entry_size
;
7656 // Calculate the address of the PLT header.
7657 Mips_address header_address
= (plt_address
7658 + (this->is_plt_header_compressed() ? 1 : 0));
7660 // Initialize compressed PLT area view.
7661 unsigned char* pov2
= pov
+ this->plt_mips_offset_
;
7663 // Write the PLT entries.
7664 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
7665 p
= this->symbols_
.begin();
7666 p
!= this->symbols_
.end();
7667 ++p
, gotplt_pov
+= got_entry_size
, gotplt_offset
+= got_entry_size
)
7669 Mips_symbol
<size
>* mips_sym
= *p
;
7671 // Calculate the address of the .got.plt entry.
7672 uint32_t gotplt_entry_addr
= (gotplt_addr
+ gotplt_offset
);
7673 uint32_t gotplt_entry_addr_hi
= (((gotplt_entry_addr
+ 0x8000) >> 16)
7675 uint32_t gotplt_entry_addr_lo
= gotplt_entry_addr
& 0xffff;
7677 // Initially point the .got.plt entry at the PLT header.
7678 if (this->target_
->is_output_n64())
7679 elfcpp::Swap
<64, big_endian
>::writeval(gotplt_pov
, header_address
);
7681 elfcpp::Swap
<32, big_endian
>::writeval(gotplt_pov
, header_address
);
7683 // Now handle the PLT itself. First the standard entry.
7684 if (mips_sym
->has_mips_plt_offset())
7686 // Pick the load opcode (LW or LD).
7687 uint64_t load
= this->target_
->is_output_n64() ? 0xdc000000
7690 const uint32_t* entry
= this->target_
->is_output_r6() ? plt_entry_r6
7693 // Fill in the PLT entry itself.
7694 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7695 entry
[0] | gotplt_entry_addr_hi
);
7696 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7697 entry
[1] | gotplt_entry_addr_lo
| load
);
7698 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8, entry
[2]);
7699 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12,
7700 entry
[3] | gotplt_entry_addr_lo
);
7704 // Now the compressed entry. They come after any standard ones.
7705 if (mips_sym
->has_comp_plt_offset())
7707 if (!this->target_
->is_output_micromips())
7709 // Write MIPS16 PLT entry.
7710 const uint32_t* plt_entry
= plt_entry_mips16_o32
;
7712 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
7713 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2, plt_entry
[1]);
7714 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7715 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
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
<32, big_endian
>::writeval(pov2
+ 12,
7722 else if (this->target_
->use_32bit_micromips_instructions())
7724 // Write microMIPS PLT entry in insn32 mode.
7725 const uint32_t* plt_entry
= plt_entry_micromips32_o32
;
7727 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
7728 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2,
7729 gotplt_entry_addr_hi
);
7730 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7731 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6,
7732 gotplt_entry_addr_lo
);
7733 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7734 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7735 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 12, plt_entry
[6]);
7736 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 14,
7737 gotplt_entry_addr_lo
);
7742 // Write microMIPS PLT entry.
7743 const uint32_t* plt_entry
= plt_entry_micromips_o32
;
7745 gold_assert(gotplt_entry_addr
% 4 == 0);
7747 Mips_address loc_address
= plt_address
+ pov2
- oview
;
7748 int gotpc_offset
= gotplt_entry_addr
- ((loc_address
| 3) ^ 3);
7750 // ADDIUPC has a span of +/-16MB, check we're in range.
7751 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
7753 gold_error(_(".got.plt offset of %ld from .plt beyond the "
7754 "range of ADDIUPC"), (long)gotpc_offset
);
7758 elfcpp::Swap
<16, big_endian
>::writeval(pov2
,
7759 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
7760 elfcpp::Swap
<16, big_endian
>::writeval(
7761 pov2
+ 2, (gotpc_offset
>> 2) & 0xffff);
7762 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7763 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
7764 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7765 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7771 // Check the number of bytes written for standard entries.
7772 gold_assert(static_cast<section_size_type
>(
7773 pov
- oview
- this->plt_header_size_
) == this->plt_mips_offset_
);
7774 // Check the number of bytes written for compressed entries.
7775 gold_assert((static_cast<section_size_type
>(pov2
- pov
)
7776 == this->plt_comp_offset_
));
7777 // Check the total number of bytes written.
7778 gold_assert(static_cast<section_size_type
>(pov2
- oview
) == oview_size
);
7780 gold_assert(static_cast<section_size_type
>(gotplt_pov
- gotplt_view
)
7783 of
->write_output_view(offset
, oview_size
, oview
);
7784 of
->write_output_view(gotplt_file_offset
, gotplt_size
, gotplt_view
);
7787 // Mips_output_data_mips_stubs methods.
7789 // The format of the lazy binding stub when dynamic symbol count is less than
7790 // 64K, dynamic symbol index is less than 32K, and ABI is not N64.
7791 template<int size
, bool big_endian
>
7793 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1
[4] =
7795 0x8f998010, // lw t9,0x8010(gp)
7796 0x03e07825, // or t7,ra,zero
7797 0x0320f809, // jalr t9,ra
7798 0x24180000 // addiu t8,zero,DYN_INDEX sign extended
7801 // The format of the lazy binding stub when dynamic symbol count is less than
7802 // 64K, dynamic symbol index is less than 32K, and ABI is N64.
7803 template<int size
, bool big_endian
>
7805 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1_n64
[4] =
7807 0xdf998010, // ld t9,0x8010(gp)
7808 0x03e07825, // or t7,ra,zero
7809 0x0320f809, // jalr t9,ra
7810 0x64180000 // daddiu t8,zero,DYN_INDEX sign extended
7813 // The format of the lazy binding stub when dynamic symbol count is less than
7814 // 64K, dynamic symbol index is between 32K and 64K, and ABI is not N64.
7815 template<int size
, bool big_endian
>
7817 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2
[4] =
7819 0x8f998010, // lw t9,0x8010(gp)
7820 0x03e07825, // or t7,ra,zero
7821 0x0320f809, // jalr t9,ra
7822 0x34180000 // ori t8,zero,DYN_INDEX unsigned
7825 // The format of the lazy binding stub when dynamic symbol count is less than
7826 // 64K, dynamic symbol index is between 32K and 64K, and ABI is N64.
7827 template<int size
, bool big_endian
>
7829 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2_n64
[4] =
7831 0xdf998010, // ld t9,0x8010(gp)
7832 0x03e07825, // or t7,ra,zero
7833 0x0320f809, // jalr t9,ra
7834 0x34180000 // ori t8,zero,DYN_INDEX unsigned
7837 // The format of the lazy binding stub when dynamic symbol count is greater than
7838 // 64K, and ABI is not N64.
7839 template<int size
, bool big_endian
>
7840 const uint32_t Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big
[5] =
7842 0x8f998010, // lw t9,0x8010(gp)
7843 0x03e07825, // or t7,ra,zero
7844 0x3c180000, // lui t8,DYN_INDEX
7845 0x0320f809, // jalr t9,ra
7846 0x37180000 // ori t8,t8,DYN_INDEX
7849 // The format of the lazy binding stub when dynamic symbol count is greater than
7850 // 64K, and ABI is N64.
7851 template<int size
, bool big_endian
>
7853 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big_n64
[5] =
7855 0xdf998010, // ld t9,0x8010(gp)
7856 0x03e07825, // or t7,ra,zero
7857 0x3c180000, // lui t8,DYN_INDEX
7858 0x0320f809, // jalr t9,ra
7859 0x37180000 // ori t8,t8,DYN_INDEX
7864 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7865 // less than 64K, dynamic symbol index is less than 32K, and ABI is not N64.
7866 template<int size
, bool big_endian
>
7868 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_1
[] =
7870 0xff3c, 0x8010, // lw t9,0x8010(gp)
7871 0x0dff, // move t7,ra
7873 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
7876 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7877 // less than 64K, dynamic symbol index is less than 32K, and ABI is N64.
7878 template<int size
, bool big_endian
>
7880 Mips_output_data_mips_stubs
<size
, big_endian
>::
7881 lazy_stub_micromips_normal_1_n64
[] =
7883 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7884 0x0dff, // move t7,ra
7886 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
7889 // The format of the microMIPS lazy binding stub when dynamic symbol
7890 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7891 // and ABI is not N64.
7892 template<int size
, bool big_endian
>
7894 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_2
[] =
7896 0xff3c, 0x8010, // lw t9,0x8010(gp)
7897 0x0dff, // move t7,ra
7899 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7902 // The format of the microMIPS lazy binding stub when dynamic symbol
7903 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7905 template<int size
, bool big_endian
>
7907 Mips_output_data_mips_stubs
<size
, big_endian
>::
7908 lazy_stub_micromips_normal_2_n64
[] =
7910 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7911 0x0dff, // move t7,ra
7913 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7916 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7917 // greater than 64K, and ABI is not N64.
7918 template<int size
, bool big_endian
>
7920 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big
[] =
7922 0xff3c, 0x8010, // lw t9,0x8010(gp)
7923 0x0dff, // move t7,ra
7924 0x41b8, 0x0000, // lui t8,DYN_INDEX
7926 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7929 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7930 // greater than 64K, and ABI is N64.
7931 template<int size
, bool big_endian
>
7933 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big_n64
[] =
7935 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7936 0x0dff, // move t7,ra
7937 0x41b8, 0x0000, // lui t8,DYN_INDEX
7939 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7942 // 32-bit microMIPS stubs.
7944 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7945 // less than 64K, dynamic symbol index is less than 32K, ABI is not N64, and we
7946 // can use only 32-bit instructions.
7947 template<int size
, bool big_endian
>
7949 Mips_output_data_mips_stubs
<size
, big_endian
>::
7950 lazy_stub_micromips32_normal_1
[] =
7952 0xff3c, 0x8010, // lw t9,0x8010(gp)
7953 0x001f, 0x7a90, // or t7,ra,zero
7954 0x03f9, 0x0f3c, // jalr ra,t9
7955 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
7958 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7959 // less than 64K, dynamic symbol index is less than 32K, ABI is N64, and we can
7960 // use only 32-bit instructions.
7961 template<int size
, bool big_endian
>
7963 Mips_output_data_mips_stubs
<size
, big_endian
>::
7964 lazy_stub_micromips32_normal_1_n64
[] =
7966 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7967 0x001f, 0x7a90, // or t7,ra,zero
7968 0x03f9, 0x0f3c, // jalr ra,t9
7969 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
7972 // The format of the microMIPS lazy binding stub when dynamic symbol
7973 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7974 // ABI is not N64, and we can use only 32-bit instructions.
7975 template<int size
, bool big_endian
>
7977 Mips_output_data_mips_stubs
<size
, big_endian
>::
7978 lazy_stub_micromips32_normal_2
[] =
7980 0xff3c, 0x8010, // lw t9,0x8010(gp)
7981 0x001f, 0x7a90, // or t7,ra,zero
7982 0x03f9, 0x0f3c, // jalr ra,t9
7983 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7986 // The format of the microMIPS lazy binding stub when dynamic symbol
7987 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7988 // ABI is N64, and we can use only 32-bit instructions.
7989 template<int size
, bool big_endian
>
7991 Mips_output_data_mips_stubs
<size
, big_endian
>::
7992 lazy_stub_micromips32_normal_2_n64
[] =
7994 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7995 0x001f, 0x7a90, // or t7,ra,zero
7996 0x03f9, 0x0f3c, // jalr ra,t9
7997 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
8000 // The format of the microMIPS lazy binding stub when dynamic symbol count is
8001 // greater than 64K, ABI is not N64, and we can use only 32-bit instructions.
8002 template<int size
, bool big_endian
>
8004 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big
[] =
8006 0xff3c, 0x8010, // lw t9,0x8010(gp)
8007 0x001f, 0x7a90, // or t7,ra,zero
8008 0x41b8, 0x0000, // lui t8,DYN_INDEX
8009 0x03f9, 0x0f3c, // jalr ra,t9
8010 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
8013 // The format of the microMIPS lazy binding stub when dynamic symbol count is
8014 // greater than 64K, ABI is N64, and we can use only 32-bit instructions.
8015 template<int size
, bool big_endian
>
8017 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big_n64
[] =
8019 0xdf3c, 0x8010, // ld t9,0x8010(gp)
8020 0x001f, 0x7a90, // or t7,ra,zero
8021 0x41b8, 0x0000, // lui t8,DYN_INDEX
8022 0x03f9, 0x0f3c, // jalr ra,t9
8023 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
8026 // Create entry for a symbol.
8028 template<int size
, bool big_endian
>
8030 Mips_output_data_mips_stubs
<size
, big_endian
>::make_entry(
8031 Mips_symbol
<size
>* gsym
)
8033 if (!gsym
->has_lazy_stub() && !gsym
->has_plt_offset())
8035 this->symbols_
.insert(gsym
);
8036 gsym
->set_has_lazy_stub(true);
8040 // Remove entry for a symbol.
8042 template<int size
, bool big_endian
>
8044 Mips_output_data_mips_stubs
<size
, big_endian
>::remove_entry(
8045 Mips_symbol
<size
>* gsym
)
8047 if (gsym
->has_lazy_stub())
8049 this->symbols_
.erase(gsym
);
8050 gsym
->set_has_lazy_stub(false);
8054 // Set stub offsets for symbols. This method expects that the number of
8055 // entries in dynamic symbol table is set.
8057 template<int size
, bool big_endian
>
8059 Mips_output_data_mips_stubs
<size
, big_endian
>::set_lazy_stub_offsets()
8061 gold_assert(this->dynsym_count_
!= -1U);
8063 if (this->stub_offsets_are_set_
)
8066 unsigned int stub_size
= this->stub_size();
8067 unsigned int offset
= 0;
8068 for (typename
Mips_stubs_entry_set::const_iterator
8069 p
= this->symbols_
.begin();
8070 p
!= this->symbols_
.end();
8071 ++p
, offset
+= stub_size
)
8073 Mips_symbol
<size
>* mips_sym
= *p
;
8074 mips_sym
->set_lazy_stub_offset(offset
);
8076 this->stub_offsets_are_set_
= true;
8079 template<int size
, bool big_endian
>
8081 Mips_output_data_mips_stubs
<size
, big_endian
>::set_needs_dynsym_value()
8083 for (typename
Mips_stubs_entry_set::const_iterator
8084 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
8086 Mips_symbol
<size
>* sym
= *p
;
8087 if (sym
->is_from_dynobj())
8088 sym
->set_needs_dynsym_value();
8092 // Write out the .MIPS.stubs. This uses the hand-coded instructions and
8093 // adjusts them as needed.
8095 template<int size
, bool big_endian
>
8097 Mips_output_data_mips_stubs
<size
, big_endian
>::do_write(Output_file
* of
)
8099 const off_t offset
= this->offset();
8100 const section_size_type oview_size
=
8101 convert_to_section_size_type(this->data_size());
8102 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
8104 bool big_stub
= this->dynsym_count_
> 0x10000;
8106 unsigned char* pov
= oview
;
8107 for (typename
Mips_stubs_entry_set::const_iterator
8108 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
8110 Mips_symbol
<size
>* sym
= *p
;
8111 const uint32_t* lazy_stub
;
8112 bool n64
= this->target_
->is_output_n64();
8114 if (!this->target_
->is_output_micromips())
8116 // Write standard (non-microMIPS) stub.
8119 if (sym
->dynsym_index() & ~0x7fff)
8120 // Dynsym index is between 32K and 64K.
8121 lazy_stub
= n64
? lazy_stub_normal_2_n64
: lazy_stub_normal_2
;
8123 // Dynsym index is less than 32K.
8124 lazy_stub
= n64
? lazy_stub_normal_1_n64
: lazy_stub_normal_1
;
8127 lazy_stub
= n64
? lazy_stub_big_n64
: lazy_stub_big
;
8130 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8131 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 1]);
8137 // LUI instruction of the big stub. Paste high 16 bits of the
8139 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
8140 lazy_stub
[i
] | ((sym
->dynsym_index() >> 16) & 0x7fff));
8144 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8145 // Last stub instruction. Paste low 16 bits of the dynsym index.
8146 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
8147 lazy_stub
[i
+ 1] | (sym
->dynsym_index() & 0xffff));
8150 else if (this->target_
->use_32bit_micromips_instructions())
8152 // Write microMIPS stub in insn32 mode.
8155 if (sym
->dynsym_index() & ~0x7fff)
8156 // Dynsym index is between 32K and 64K.
8157 lazy_stub
= n64
? lazy_stub_micromips32_normal_2_n64
8158 : lazy_stub_micromips32_normal_2
;
8160 // Dynsym index is less than 32K.
8161 lazy_stub
= n64
? lazy_stub_micromips32_normal_1_n64
8162 : lazy_stub_micromips32_normal_1
;
8165 lazy_stub
= n64
? lazy_stub_micromips32_big_n64
8166 : lazy_stub_micromips32_big
;
8169 // First stub instruction. We emit 32-bit microMIPS instructions by
8170 // emitting two 16-bit parts because on microMIPS the 16-bit part of
8171 // the instruction where the opcode is must always come first, for
8172 // both little and big endian.
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 // Second stub instruction.
8176 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
8177 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, lazy_stub
[i
+ 3]);
8182 // LUI instruction of the big stub. Paste high 16 bits of the
8184 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8185 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
8186 (sym
->dynsym_index() >> 16) & 0x7fff);
8190 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8191 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
8192 // Last stub instruction. Paste low 16 bits of the dynsym index.
8193 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
8194 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
8195 sym
->dynsym_index() & 0xffff);
8200 // Write microMIPS stub.
8203 if (sym
->dynsym_index() & ~0x7fff)
8204 // Dynsym index is between 32K and 64K.
8205 lazy_stub
= n64
? lazy_stub_micromips_normal_2_n64
8206 : lazy_stub_micromips_normal_2
;
8208 // Dynsym index is less than 32K.
8209 lazy_stub
= n64
? lazy_stub_micromips_normal_1_n64
8210 : lazy_stub_micromips_normal_1
;
8213 lazy_stub
= n64
? lazy_stub_micromips_big_n64
8214 : lazy_stub_micromips_big
;
8217 // First stub instruction. We emit 32-bit microMIPS instructions by
8218 // emitting two 16-bit parts because on microMIPS the 16-bit part of
8219 // the instruction where the opcode is must always come first, for
8220 // both little and big endian.
8221 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8222 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
8223 // Second stub instruction.
8224 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
8229 // LUI instruction of the big stub. Paste high 16 bits of the
8231 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8232 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
8233 (sym
->dynsym_index() >> 16) & 0x7fff);
8237 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
8238 // Last stub instruction. Paste low 16 bits of the dynsym index.
8239 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
8240 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
8241 sym
->dynsym_index() & 0xffff);
8246 // We always allocate 20 bytes for every stub, because final dynsym count is
8247 // not known in method do_finalize_sections. There are 4 unused bytes per
8248 // stub if final dynsym count is less than 0x10000.
8249 unsigned int used
= pov
- oview
;
8250 unsigned int unused
= big_stub
? 0 : this->symbols_
.size() * 4;
8251 gold_assert(static_cast<section_size_type
>(used
+ unused
) == oview_size
);
8253 // Fill the unused space with zeroes.
8254 // TODO(sasa): Can we strip unused bytes during the relaxation?
8256 memset(pov
, 0, unused
);
8258 of
->write_output_view(offset
, oview_size
, oview
);
8261 // Mips_output_section_reginfo methods.
8263 template<int size
, bool big_endian
>
8265 Mips_output_section_reginfo
<size
, big_endian
>::do_write(Output_file
* of
)
8267 off_t offset
= this->offset();
8268 off_t data_size
= this->data_size();
8270 unsigned char* view
= of
->get_output_view(offset
, data_size
);
8271 elfcpp::Swap
<size
, big_endian
>::writeval(view
, this->gprmask_
);
8272 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 4, this->cprmask1_
);
8273 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 8, this->cprmask2_
);
8274 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 12, this->cprmask3_
);
8275 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 16, this->cprmask4_
);
8276 // Write the gp value.
8277 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 20,
8278 this->target_
->gp_value());
8280 of
->write_output_view(offset
, data_size
, view
);
8283 // Mips_output_section_options methods.
8285 template<int size
, bool big_endian
>
8287 Mips_output_section_options
<size
, big_endian
>::do_write(Output_file
* of
)
8289 off_t offset
= this->offset();
8290 const section_size_type oview_size
=
8291 convert_to_section_size_type(this->data_size());
8292 unsigned char* view
= of
->get_output_view(offset
, oview_size
);
8293 const unsigned char* end
= view
+ oview_size
;
8295 while (view
+ 8 <= end
)
8297 unsigned char kind
= elfcpp::Swap
<8, big_endian
>::readval(view
);
8298 unsigned char sz
= elfcpp::Swap
<8, big_endian
>::readval(view
+ 1);
8301 gold_error(_("Warning: bad `%s' option size %u smaller "
8302 "than its header in output section"),
8307 // Only update ri_gp_value (GP register value) field of ODK_REGINFO entry.
8308 if (this->target_
->is_output_n64() && kind
== elfcpp::ODK_REGINFO
)
8309 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 32,
8310 this->target_
->gp_value());
8311 else if (kind
== elfcpp::ODK_REGINFO
)
8312 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 28,
8313 this->target_
->gp_value());
8318 of
->write_output_view(offset
, oview_size
, view
);
8321 // Mips_output_section_abiflags methods.
8323 template<int size
, bool big_endian
>
8325 Mips_output_section_abiflags
<size
, big_endian
>::do_write(Output_file
* of
)
8327 off_t offset
= this->offset();
8328 off_t data_size
= this->data_size();
8330 unsigned char* view
= of
->get_output_view(offset
, data_size
);
8331 elfcpp::Swap
<16, big_endian
>::writeval(view
, this->abiflags_
.version
);
8332 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 2, this->abiflags_
.isa_level
);
8333 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 3, this->abiflags_
.isa_rev
);
8334 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 4, this->abiflags_
.gpr_size
);
8335 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 5, this->abiflags_
.cpr1_size
);
8336 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 6, this->abiflags_
.cpr2_size
);
8337 elfcpp::Swap
<8, big_endian
>::writeval(view
+ 7, this->abiflags_
.fp_abi
);
8338 elfcpp::Swap
<32, big_endian
>::writeval(view
+ 8, this->abiflags_
.isa_ext
);
8339 elfcpp::Swap
<32, big_endian
>::writeval(view
+ 12, this->abiflags_
.ases
);
8340 elfcpp::Swap
<32, big_endian
>::writeval(view
+ 16, this->abiflags_
.flags1
);
8341 elfcpp::Swap
<32, big_endian
>::writeval(view
+ 20, this->abiflags_
.flags2
);
8343 of
->write_output_view(offset
, data_size
, view
);
8346 // Mips_copy_relocs methods.
8348 // Emit any saved relocs.
8350 template<int sh_type
, int size
, bool big_endian
>
8352 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_mips(
8353 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
8354 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
8356 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
8357 Copy_reloc_entries::iterator p
= this->entries_
.begin();
8358 p
!= this->entries_
.end();
8360 emit_entry(*p
, reloc_section
, symtab
, layout
, target
);
8362 // We no longer need the saved information.
8363 this->entries_
.clear();
8366 // Emit the reloc if appropriate.
8368 template<int sh_type
, int size
, bool big_endian
>
8370 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_entry(
8371 Copy_reloc_entry
& entry
,
8372 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
8373 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
8375 // If the symbol is no longer defined in a dynamic object, then we
8376 // emitted a COPY relocation, and we do not want to emit this
8377 // dynamic relocation.
8378 if (!entry
.sym_
->is_from_dynobj())
8381 bool can_make_dynamic
= (entry
.reloc_type_
== elfcpp::R_MIPS_32
8382 || entry
.reloc_type_
== elfcpp::R_MIPS_REL32
8383 || entry
.reloc_type_
== elfcpp::R_MIPS_64
);
8385 Mips_symbol
<size
>* sym
= Mips_symbol
<size
>::as_mips_sym(entry
.sym_
);
8386 if (can_make_dynamic
&& !sym
->has_static_relocs())
8388 Mips_relobj
<size
, big_endian
>* object
=
8389 Mips_relobj
<size
, big_endian
>::as_mips_relobj(entry
.relobj_
);
8390 target
->got_section(symtab
, layout
)->record_global_got_symbol(
8391 sym
, object
, entry
.reloc_type_
, true, false);
8392 if (!symbol_references_local(sym
, sym
->should_add_dynsym_entry(symtab
)))
8393 target
->rel_dyn_section(layout
)->add_global(sym
, elfcpp::R_MIPS_REL32
,
8394 entry
.output_section_
, entry
.relobj_
, entry
.shndx_
, entry
.address_
);
8396 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
8397 sym
, elfcpp::R_MIPS_REL32
, entry
.output_section_
, entry
.relobj_
,
8398 entry
.shndx_
, entry
.address_
);
8401 this->make_copy_reloc(symtab
, layout
,
8402 static_cast<Sized_symbol
<size
>*>(entry
.sym_
),
8407 // Target_mips methods.
8409 // Return the value to use for a dynamic symbol which requires special
8410 // treatment. This is how we support equality comparisons of function
8411 // pointers across shared library boundaries, as described in the
8412 // processor specific ABI supplement.
8414 template<int size
, bool big_endian
>
8416 Target_mips
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
8419 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
8421 if (!mips_sym
->has_lazy_stub())
8423 if (mips_sym
->has_plt_offset())
8425 // We distinguish between PLT entries and lazy-binding stubs by
8426 // giving the former an st_other value of STO_MIPS_PLT. Set the
8427 // value to the stub address if there are any relocations in the
8428 // binary where pointer equality matters.
8429 if (mips_sym
->pointer_equality_needed())
8431 // Prefer a standard MIPS PLT entry.
8432 if (mips_sym
->has_mips_plt_offset())
8433 value
= this->plt_section()->mips_entry_address(mips_sym
);
8435 value
= this->plt_section()->comp_entry_address(mips_sym
) + 1;
8443 // First, set stub offsets for symbols. This method expects that the
8444 // number of entries in dynamic symbol table is set.
8445 this->mips_stubs_section()->set_lazy_stub_offsets();
8447 // The run-time linker uses the st_value field of the symbol
8448 // to reset the global offset table entry for this external
8449 // to its stub address when unlinking a shared object.
8450 value
= this->mips_stubs_section()->stub_address(mips_sym
);
8453 if (mips_sym
->has_mips16_fn_stub())
8455 // If we have a MIPS16 function with a stub, the dynamic symbol must
8456 // refer to the stub, since only the stub uses the standard calling
8458 value
= mips_sym
->template
8459 get_mips16_fn_stub
<big_endian
>()->output_address();
8465 // Get the dynamic reloc section, creating it if necessary. It's always
8466 // .rel.dyn, even for MIPS64.
8468 template<int size
, bool big_endian
>
8469 typename Target_mips
<size
, big_endian
>::Reloc_section
*
8470 Target_mips
<size
, big_endian
>::rel_dyn_section(Layout
* layout
)
8472 if (this->rel_dyn_
== NULL
)
8474 gold_assert(layout
!= NULL
);
8475 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
8476 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
8477 elfcpp::SHF_ALLOC
, this->rel_dyn_
,
8478 ORDER_DYNAMIC_RELOCS
, false);
8480 // First entry in .rel.dyn has to be null.
8481 // This is hack - we define dummy output data and set its address to 0,
8482 // and define absolute R_MIPS_NONE relocation with offset 0 against it.
8483 // This ensures that the entry is null.
8484 Output_data
* od
= new Output_data_zero_fill(0, 0);
8486 this->rel_dyn_
->add_absolute(elfcpp::R_MIPS_NONE
, od
, 0);
8488 return this->rel_dyn_
;
8491 // Get the GOT section, creating it if necessary.
8493 template<int size
, bool big_endian
>
8494 Mips_output_data_got
<size
, big_endian
>*
8495 Target_mips
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
8498 if (this->got_
== NULL
)
8500 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
8502 this->got_
= new Mips_output_data_got
<size
, big_endian
>(this, symtab
,
8504 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
8505 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
|
8506 elfcpp::SHF_MIPS_GPREL
),
8507 this->got_
, ORDER_DATA
, false);
8509 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
8510 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
8511 Symbol_table::PREDEFINED
,
8513 0, 0, elfcpp::STT_OBJECT
,
8515 elfcpp::STV_HIDDEN
, 0,
8522 // Calculate value of _gp symbol.
8524 template<int size
, bool big_endian
>
8526 Target_mips
<size
, big_endian
>::set_gp(Layout
* layout
, Symbol_table
* symtab
)
8528 gold_assert(this->gp_
== NULL
);
8530 Sized_symbol
<size
>* gp
=
8531 static_cast<Sized_symbol
<size
>*>(symtab
->lookup("_gp"));
8533 // Set _gp symbol if the linker script hasn't created it.
8534 if (gp
== NULL
|| gp
->source() != Symbol::IS_CONSTANT
)
8536 // If there is no .got section, gp should be based on .sdata.
8537 Output_data
* gp_section
= (this->got_
!= NULL
8538 ? this->got_
->output_section()
8539 : layout
->find_output_section(".sdata"));
8541 if (gp_section
!= NULL
)
8542 gp
= static_cast<Sized_symbol
<size
>*>(symtab
->define_in_output_data(
8543 "_gp", NULL
, Symbol_table::PREDEFINED
,
8544 gp_section
, MIPS_GP_OFFSET
, 0,
8547 elfcpp::STV_DEFAULT
,
8554 // Set the dynamic symbol indexes. INDEX is the index of the first
8555 // global dynamic symbol. Pointers to the symbols are stored into the
8556 // vector SYMS. The names are added to DYNPOOL. This returns an
8557 // updated dynamic symbol index.
8559 template<int size
, bool big_endian
>
8561 Target_mips
<size
, big_endian
>::do_set_dynsym_indexes(
8562 std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
8563 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
8564 Versions
* versions
, Symbol_table
* symtab
) const
8566 std::vector
<Symbol
*> non_got_symbols
;
8567 std::vector
<Symbol
*> got_symbols
;
8569 reorder_dyn_symbols
<size
, big_endian
>(dyn_symbols
, &non_got_symbols
,
8572 for (std::vector
<Symbol
*>::iterator p
= non_got_symbols
.begin();
8573 p
!= non_got_symbols
.end();
8578 // Note that SYM may already have a dynamic symbol index, since
8579 // some symbols appear more than once in the symbol table, with
8580 // and without a version.
8582 if (!sym
->has_dynsym_index())
8584 sym
->set_dynsym_index(index
);
8586 syms
->push_back(sym
);
8587 dynpool
->add(sym
->name(), false, NULL
);
8589 // Record any version information.
8590 if (sym
->version() != NULL
)
8591 versions
->record_version(symtab
, dynpool
, sym
);
8593 // If the symbol is defined in a dynamic object and is
8594 // referenced in a regular object, then mark the dynamic
8595 // object as needed. This is used to implement --as-needed.
8596 if (sym
->is_from_dynobj() && sym
->in_reg())
8597 sym
->object()->set_is_needed();
8601 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
8602 p
!= got_symbols
.end();
8606 if (!sym
->has_dynsym_index())
8608 // Record any version information.
8609 if (sym
->version() != NULL
)
8610 versions
->record_version(symtab
, dynpool
, sym
);
8614 index
= versions
->finalize(symtab
, index
, syms
);
8616 int got_sym_count
= 0;
8617 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
8618 p
!= got_symbols
.end();
8623 if (!sym
->has_dynsym_index())
8626 sym
->set_dynsym_index(index
);
8628 syms
->push_back(sym
);
8629 dynpool
->add(sym
->name(), false, NULL
);
8631 // If the symbol is defined in a dynamic object and is
8632 // referenced in a regular object, then mark the dynamic
8633 // object as needed. This is used to implement --as-needed.
8634 if (sym
->is_from_dynobj() && sym
->in_reg())
8635 sym
->object()->set_is_needed();
8639 // Set index of the first symbol that has .got entry.
8640 this->got_
->set_first_global_got_dynsym_index(
8641 got_sym_count
> 0 ? index
- got_sym_count
: -1U);
8643 if (this->mips_stubs_
!= NULL
)
8644 this->mips_stubs_
->set_dynsym_count(index
);
8649 // Create a PLT entry for a global symbol referenced by r_type relocation.
8651 template<int size
, bool big_endian
>
8653 Target_mips
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
8655 Mips_symbol
<size
>* gsym
,
8656 unsigned int r_type
)
8658 if (gsym
->has_lazy_stub() || gsym
->has_plt_offset())
8661 if (this->plt_
== NULL
)
8663 // Create the GOT section first.
8664 this->got_section(symtab
, layout
);
8666 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
8667 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
8668 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
8669 this->got_plt_
, ORDER_DATA
, false);
8671 // The first two entries are reserved.
8672 this->got_plt_
->set_current_data_size(2 * size
/8);
8674 this->plt_
= new Mips_output_data_plt
<size
, big_endian
>(layout
,
8677 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
8679 | elfcpp::SHF_EXECINSTR
),
8680 this->plt_
, ORDER_PLT
, false);
8682 // Make the sh_info field of .rel.plt point to .plt.
8683 Output_section
* rel_plt_os
= this->plt_
->rel_plt()->output_section();
8684 rel_plt_os
->set_info_section(this->plt_
->output_section());
8687 this->plt_
->add_entry(gsym
, r_type
);
8691 // Get the .MIPS.stubs section, creating it if necessary.
8693 template<int size
, bool big_endian
>
8694 Mips_output_data_mips_stubs
<size
, big_endian
>*
8695 Target_mips
<size
, big_endian
>::mips_stubs_section(Layout
* layout
)
8697 if (this->mips_stubs_
== NULL
)
8700 new Mips_output_data_mips_stubs
<size
, big_endian
>(this);
8701 layout
->add_output_section_data(".MIPS.stubs", elfcpp::SHT_PROGBITS
,
8703 | elfcpp::SHF_EXECINSTR
),
8704 this->mips_stubs_
, ORDER_PLT
, false);
8706 return this->mips_stubs_
;
8709 // Get the LA25 stub section, creating it if necessary.
8711 template<int size
, bool big_endian
>
8712 Mips_output_data_la25_stub
<size
, big_endian
>*
8713 Target_mips
<size
, big_endian
>::la25_stub_section(Layout
* layout
)
8715 if (this->la25_stub_
== NULL
)
8717 this->la25_stub_
= new Mips_output_data_la25_stub
<size
, big_endian
>();
8718 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
8720 | elfcpp::SHF_EXECINSTR
),
8721 this->la25_stub_
, ORDER_TEXT
, false);
8723 return this->la25_stub_
;
8726 // Process the relocations to determine unreferenced sections for
8727 // garbage collection.
8729 template<int size
, bool big_endian
>
8731 Target_mips
<size
, big_endian
>::gc_process_relocs(
8732 Symbol_table
* symtab
,
8734 Sized_relobj_file
<size
, big_endian
>* object
,
8735 unsigned int data_shndx
,
8736 unsigned int sh_type
,
8737 const unsigned char* prelocs
,
8739 Output_section
* output_section
,
8740 bool needs_special_offset_handling
,
8741 size_t local_symbol_count
,
8742 const unsigned char* plocal_symbols
)
8744 typedef Target_mips
<size
, big_endian
> Mips
;
8746 if (sh_type
== elfcpp::SHT_REL
)
8748 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8751 gold::gc_process_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8760 needs_special_offset_handling
,
8764 else if (sh_type
== elfcpp::SHT_RELA
)
8766 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8769 gold::gc_process_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8778 needs_special_offset_handling
,
8786 // Scan relocations for a section.
8788 template<int size
, bool big_endian
>
8790 Target_mips
<size
, big_endian
>::scan_relocs(
8791 Symbol_table
* symtab
,
8793 Sized_relobj_file
<size
, big_endian
>* object
,
8794 unsigned int data_shndx
,
8795 unsigned int sh_type
,
8796 const unsigned char* prelocs
,
8798 Output_section
* output_section
,
8799 bool needs_special_offset_handling
,
8800 size_t local_symbol_count
,
8801 const unsigned char* plocal_symbols
)
8803 typedef Target_mips
<size
, big_endian
> Mips
;
8805 if (sh_type
== elfcpp::SHT_REL
)
8807 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8810 gold::scan_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8819 needs_special_offset_handling
,
8823 else if (sh_type
== elfcpp::SHT_RELA
)
8825 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8828 gold::scan_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8837 needs_special_offset_handling
,
8843 template<int size
, bool big_endian
>
8845 Target_mips
<size
, big_endian
>::mips_32bit_flags(elfcpp::Elf_Word flags
)
8847 return ((flags
& elfcpp::EF_MIPS_32BITMODE
) != 0
8848 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::EF_MIPS_ABI_O32
8849 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::EF_MIPS_ABI_EABI32
8850 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::EF_MIPS_ARCH_1
8851 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::EF_MIPS_ARCH_2
8852 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::EF_MIPS_ARCH_32
8853 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::EF_MIPS_ARCH_32R2
8854 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::EF_MIPS_ARCH_32R6
);
8857 // Return the MACH for a MIPS e_flags value.
8858 template<int size
, bool big_endian
>
8860 Target_mips
<size
, big_endian
>::elf_mips_mach(elfcpp::Elf_Word flags
)
8862 switch (flags
& elfcpp::EF_MIPS_MACH
)
8864 case elfcpp::EF_MIPS_MACH_3900
:
8865 return mach_mips3900
;
8867 case elfcpp::EF_MIPS_MACH_4010
:
8868 return mach_mips4010
;
8870 case elfcpp::EF_MIPS_MACH_4100
:
8871 return mach_mips4100
;
8873 case elfcpp::EF_MIPS_MACH_4111
:
8874 return mach_mips4111
;
8876 case elfcpp::EF_MIPS_MACH_4120
:
8877 return mach_mips4120
;
8879 case elfcpp::EF_MIPS_MACH_4650
:
8880 return mach_mips4650
;
8882 case elfcpp::EF_MIPS_MACH_5400
:
8883 return mach_mips5400
;
8885 case elfcpp::EF_MIPS_MACH_5500
:
8886 return mach_mips5500
;
8888 case elfcpp::EF_MIPS_MACH_5900
:
8889 return mach_mips5900
;
8891 case elfcpp::EF_MIPS_MACH_9000
:
8892 return mach_mips9000
;
8894 case elfcpp::EF_MIPS_MACH_SB1
:
8895 return mach_mips_sb1
;
8897 case elfcpp::EF_MIPS_MACH_LS2E
:
8898 return mach_mips_loongson_2e
;
8900 case elfcpp::EF_MIPS_MACH_LS2F
:
8901 return mach_mips_loongson_2f
;
8903 case elfcpp::EF_MIPS_MACH_GS464
:
8904 return mach_mips_gs464
;
8906 case elfcpp::EF_MIPS_MACH_GS464E
:
8907 return mach_mips_gs464e
;
8909 case elfcpp::EF_MIPS_MACH_GS264E
:
8910 return mach_mips_gs264e
;
8912 case elfcpp::EF_MIPS_MACH_OCTEON3
:
8913 return mach_mips_octeon3
;
8915 case elfcpp::EF_MIPS_MACH_OCTEON2
:
8916 return mach_mips_octeon2
;
8918 case elfcpp::EF_MIPS_MACH_OCTEON
:
8919 return mach_mips_octeon
;
8921 case elfcpp::EF_MIPS_MACH_XLR
:
8922 return mach_mips_xlr
;
8925 switch (flags
& elfcpp::EF_MIPS_ARCH
)
8928 case elfcpp::EF_MIPS_ARCH_1
:
8929 return mach_mips3000
;
8931 case elfcpp::EF_MIPS_ARCH_2
:
8932 return mach_mips6000
;
8934 case elfcpp::EF_MIPS_ARCH_3
:
8935 return mach_mips4000
;
8937 case elfcpp::EF_MIPS_ARCH_4
:
8938 return mach_mips8000
;
8940 case elfcpp::EF_MIPS_ARCH_5
:
8943 case elfcpp::EF_MIPS_ARCH_32
:
8944 return mach_mipsisa32
;
8946 case elfcpp::EF_MIPS_ARCH_64
:
8947 return mach_mipsisa64
;
8949 case elfcpp::EF_MIPS_ARCH_32R2
:
8950 return mach_mipsisa32r2
;
8952 case elfcpp::EF_MIPS_ARCH_32R6
:
8953 return mach_mipsisa32r6
;
8955 case elfcpp::EF_MIPS_ARCH_64R2
:
8956 return mach_mipsisa64r2
;
8958 case elfcpp::EF_MIPS_ARCH_64R6
:
8959 return mach_mipsisa64r6
;
8966 // Return the MACH for each .MIPS.abiflags ISA Extension.
8968 template<int size
, bool big_endian
>
8970 Target_mips
<size
, big_endian
>::mips_isa_ext_mach(unsigned int isa_ext
)
8974 case elfcpp::AFL_EXT_3900
:
8975 return mach_mips3900
;
8977 case elfcpp::AFL_EXT_4010
:
8978 return mach_mips4010
;
8980 case elfcpp::AFL_EXT_4100
:
8981 return mach_mips4100
;
8983 case elfcpp::AFL_EXT_4111
:
8984 return mach_mips4111
;
8986 case elfcpp::AFL_EXT_4120
:
8987 return mach_mips4120
;
8989 case elfcpp::AFL_EXT_4650
:
8990 return mach_mips4650
;
8992 case elfcpp::AFL_EXT_5400
:
8993 return mach_mips5400
;
8995 case elfcpp::AFL_EXT_5500
:
8996 return mach_mips5500
;
8998 case elfcpp::AFL_EXT_5900
:
8999 return mach_mips5900
;
9001 case elfcpp::AFL_EXT_10000
:
9002 return mach_mips10000
;
9004 case elfcpp::AFL_EXT_LOONGSON_2E
:
9005 return mach_mips_loongson_2e
;
9007 case elfcpp::AFL_EXT_LOONGSON_2F
:
9008 return mach_mips_loongson_2f
;
9010 case elfcpp::AFL_EXT_SB1
:
9011 return mach_mips_sb1
;
9013 case elfcpp::AFL_EXT_OCTEON
:
9014 return mach_mips_octeon
;
9016 case elfcpp::AFL_EXT_OCTEONP
:
9017 return mach_mips_octeonp
;
9019 case elfcpp::AFL_EXT_OCTEON2
:
9020 return mach_mips_octeon2
;
9022 case elfcpp::AFL_EXT_XLR
:
9023 return mach_mips_xlr
;
9026 return mach_mips3000
;
9030 // Return the .MIPS.abiflags value representing each ISA Extension.
9032 template<int size
, bool big_endian
>
9034 Target_mips
<size
, big_endian
>::mips_isa_ext(unsigned int mips_mach
)
9039 return elfcpp::AFL_EXT_3900
;
9042 return elfcpp::AFL_EXT_4010
;
9045 return elfcpp::AFL_EXT_4100
;
9048 return elfcpp::AFL_EXT_4111
;
9051 return elfcpp::AFL_EXT_4120
;
9054 return elfcpp::AFL_EXT_4650
;
9057 return elfcpp::AFL_EXT_5400
;
9060 return elfcpp::AFL_EXT_5500
;
9063 return elfcpp::AFL_EXT_5900
;
9065 case mach_mips10000
:
9066 return elfcpp::AFL_EXT_10000
;
9068 case mach_mips_loongson_2e
:
9069 return elfcpp::AFL_EXT_LOONGSON_2E
;
9071 case mach_mips_loongson_2f
:
9072 return elfcpp::AFL_EXT_LOONGSON_2F
;
9075 return elfcpp::AFL_EXT_SB1
;
9077 case mach_mips_octeon
:
9078 return elfcpp::AFL_EXT_OCTEON
;
9080 case mach_mips_octeonp
:
9081 return elfcpp::AFL_EXT_OCTEONP
;
9083 case mach_mips_octeon3
:
9084 return elfcpp::AFL_EXT_OCTEON3
;
9086 case mach_mips_octeon2
:
9087 return elfcpp::AFL_EXT_OCTEON2
;
9090 return elfcpp::AFL_EXT_XLR
;
9097 // Update the isa_level, isa_rev, isa_ext fields of abiflags.
9099 template<int size
, bool big_endian
>
9101 Target_mips
<size
, big_endian
>::update_abiflags_isa(const std::string
& name
,
9102 elfcpp::Elf_Word e_flags
, Mips_abiflags
<big_endian
>* abiflags
)
9105 switch (e_flags
& elfcpp::EF_MIPS_ARCH
)
9107 case elfcpp::EF_MIPS_ARCH_1
:
9108 new_isa
= this->level_rev(1, 0);
9110 case elfcpp::EF_MIPS_ARCH_2
:
9111 new_isa
= this->level_rev(2, 0);
9113 case elfcpp::EF_MIPS_ARCH_3
:
9114 new_isa
= this->level_rev(3, 0);
9116 case elfcpp::EF_MIPS_ARCH_4
:
9117 new_isa
= this->level_rev(4, 0);
9119 case elfcpp::EF_MIPS_ARCH_5
:
9120 new_isa
= this->level_rev(5, 0);
9122 case elfcpp::EF_MIPS_ARCH_32
:
9123 new_isa
= this->level_rev(32, 1);
9125 case elfcpp::EF_MIPS_ARCH_32R2
:
9126 new_isa
= this->level_rev(32, 2);
9128 case elfcpp::EF_MIPS_ARCH_32R6
:
9129 new_isa
= this->level_rev(32, 6);
9131 case elfcpp::EF_MIPS_ARCH_64
:
9132 new_isa
= this->level_rev(64, 1);
9134 case elfcpp::EF_MIPS_ARCH_64R2
:
9135 new_isa
= this->level_rev(64, 2);
9137 case elfcpp::EF_MIPS_ARCH_64R6
:
9138 new_isa
= this->level_rev(64, 6);
9141 gold_error(_("%s: Unknown architecture %s"), name
.c_str(),
9142 this->elf_mips_mach_name(e_flags
));
9145 if (new_isa
> this->level_rev(abiflags
->isa_level
, abiflags
->isa_rev
))
9147 // Decode a single value into level and revision.
9148 abiflags
->isa_level
= new_isa
>> 3;
9149 abiflags
->isa_rev
= new_isa
& 0x7;
9152 // Update the isa_ext if needed.
9153 if (this->mips_mach_extends(this->mips_isa_ext_mach(abiflags
->isa_ext
),
9154 this->elf_mips_mach(e_flags
)))
9155 abiflags
->isa_ext
= this->mips_isa_ext(this->elf_mips_mach(e_flags
));
9158 // Infer the content of the ABI flags based on the elf header.
9160 template<int size
, bool big_endian
>
9162 Target_mips
<size
, big_endian
>::infer_abiflags(
9163 Mips_relobj
<size
, big_endian
>* relobj
, Mips_abiflags
<big_endian
>* abiflags
)
9165 const Attributes_section_data
* pasd
= relobj
->attributes_section_data();
9166 int attr_fp_abi
= elfcpp::Val_GNU_MIPS_ABI_FP_ANY
;
9167 elfcpp::Elf_Word e_flags
= relobj
->processor_specific_flags();
9169 this->update_abiflags_isa(relobj
->name(), e_flags
, abiflags
);
9172 // Read fp_abi from the .gnu.attribute section.
9173 const Object_attribute
* attr
=
9174 pasd
->known_attributes(Object_attribute::OBJ_ATTR_GNU
);
9175 attr_fp_abi
= attr
[elfcpp::Tag_GNU_MIPS_ABI_FP
].int_value();
9178 abiflags
->fp_abi
= attr_fp_abi
;
9179 abiflags
->cpr1_size
= elfcpp::AFL_REG_NONE
;
9180 abiflags
->cpr2_size
= elfcpp::AFL_REG_NONE
;
9181 abiflags
->gpr_size
= this->mips_32bit_flags(e_flags
) ? elfcpp::AFL_REG_32
9182 : elfcpp::AFL_REG_64
;
9184 if (abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_SINGLE
9185 || abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_XX
9186 || (abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
9187 && abiflags
->gpr_size
== elfcpp::AFL_REG_32
))
9188 abiflags
->cpr1_size
= elfcpp::AFL_REG_32
;
9189 else if (abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
9190 || abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_64
9191 || abiflags
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
)
9192 abiflags
->cpr1_size
= elfcpp::AFL_REG_64
;
9194 if (e_flags
& elfcpp::EF_MIPS_ARCH_ASE_MDMX
)
9195 abiflags
->ases
|= elfcpp::AFL_ASE_MDMX
;
9196 if (e_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
)
9197 abiflags
->ases
|= elfcpp::AFL_ASE_MIPS16
;
9198 if (e_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
)
9199 abiflags
->ases
|= elfcpp::AFL_ASE_MICROMIPS
;
9201 if (abiflags
->fp_abi
!= elfcpp::Val_GNU_MIPS_ABI_FP_ANY
9202 && abiflags
->fp_abi
!= elfcpp::Val_GNU_MIPS_ABI_FP_SOFT
9203 && abiflags
->fp_abi
!= elfcpp::Val_GNU_MIPS_ABI_FP_64A
9204 && abiflags
->isa_level
>= 32
9205 && abiflags
->ases
!= elfcpp::AFL_ASE_LOONGSON_EXT
)
9206 abiflags
->flags1
|= elfcpp::AFL_FLAGS1_ODDSPREG
;
9209 // Create abiflags from elf header or from .MIPS.abiflags section.
9211 template<int size
, bool big_endian
>
9213 Target_mips
<size
, big_endian
>::create_abiflags(
9214 Mips_relobj
<size
, big_endian
>* relobj
,
9215 Mips_abiflags
<big_endian
>* abiflags
)
9217 Mips_abiflags
<big_endian
>* sec_abiflags
= relobj
->abiflags();
9218 Mips_abiflags
<big_endian
> header_abiflags
;
9220 this->infer_abiflags(relobj
, &header_abiflags
);
9222 if (sec_abiflags
== NULL
)
9224 // If there is no input .MIPS.abiflags section, use abiflags created
9226 *abiflags
= header_abiflags
;
9230 this->has_abiflags_section_
= true;
9232 // It is not possible to infer the correct ISA revision for R3 or R5
9233 // so drop down to R2 for the checks.
9234 unsigned char isa_rev
= sec_abiflags
->isa_rev
;
9235 if (isa_rev
== 3 || isa_rev
== 5)
9238 // Check compatibility between abiflags created from elf header
9239 // and abiflags from .MIPS.abiflags section in this object file.
9240 if (this->level_rev(sec_abiflags
->isa_level
, isa_rev
)
9241 < this->level_rev(header_abiflags
.isa_level
, header_abiflags
.isa_rev
))
9242 gold_warning(_("%s: Inconsistent ISA between e_flags and .MIPS.abiflags"),
9243 relobj
->name().c_str());
9244 if (header_abiflags
.fp_abi
!= elfcpp::Val_GNU_MIPS_ABI_FP_ANY
9245 && sec_abiflags
->fp_abi
!= header_abiflags
.fp_abi
)
9246 gold_warning(_("%s: Inconsistent FP ABI between .gnu.attributes and "
9247 ".MIPS.abiflags"), relobj
->name().c_str());
9248 if ((sec_abiflags
->ases
& header_abiflags
.ases
) != header_abiflags
.ases
)
9249 gold_warning(_("%s: Inconsistent ASEs between e_flags and .MIPS.abiflags"),
9250 relobj
->name().c_str());
9251 // The isa_ext is allowed to be an extension of what can be inferred
9253 if (!this->mips_mach_extends(this->mips_isa_ext_mach(header_abiflags
.isa_ext
),
9254 this->mips_isa_ext_mach(sec_abiflags
->isa_ext
)))
9255 gold_warning(_("%s: Inconsistent ISA extensions between e_flags and "
9256 ".MIPS.abiflags"), relobj
->name().c_str());
9257 if (sec_abiflags
->flags2
!= 0)
9258 gold_warning(_("%s: Unexpected flag in the flags2 field of "
9259 ".MIPS.abiflags (0x%x)"), relobj
->name().c_str(),
9260 sec_abiflags
->flags2
);
9261 // Use abiflags from .MIPS.abiflags section.
9262 *abiflags
= *sec_abiflags
;
9265 // Return the meaning of fp_abi, or "unknown" if not known.
9267 template<int size
, bool big_endian
>
9269 Target_mips
<size
, big_endian
>::fp_abi_string(int fp
)
9273 case elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
:
9274 return "-mdouble-float";
9275 case elfcpp::Val_GNU_MIPS_ABI_FP_SINGLE
:
9276 return "-msingle-float";
9277 case elfcpp::Val_GNU_MIPS_ABI_FP_SOFT
:
9278 return "-msoft-float";
9279 case elfcpp::Val_GNU_MIPS_ABI_FP_OLD_64
:
9280 return _("-mips32r2 -mfp64 (12 callee-saved)");
9281 case elfcpp::Val_GNU_MIPS_ABI_FP_XX
:
9283 case elfcpp::Val_GNU_MIPS_ABI_FP_64
:
9284 return "-mgp32 -mfp64";
9285 case elfcpp::Val_GNU_MIPS_ABI_FP_64A
:
9286 return "-mgp32 -mfp64 -mno-odd-spreg";
9294 template<int size
, bool big_endian
>
9296 Target_mips
<size
, big_endian
>::select_fp_abi(const std::string
& name
, int in_fp
,
9299 if (in_fp
== out_fp
)
9302 if (out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_ANY
)
9304 else if (out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_XX
9305 && (in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
9306 || in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64
9307 || in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
))
9309 else if (in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_XX
9310 && (out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_DOUBLE
9311 || out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64
9312 || out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
))
9313 return out_fp
; // Keep the current setting.
9314 else if (out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
9315 && in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64
)
9317 else if (in_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
9318 && out_fp
== elfcpp::Val_GNU_MIPS_ABI_FP_64
)
9319 return out_fp
; // Keep the current setting.
9320 else if (in_fp
!= elfcpp::Val_GNU_MIPS_ABI_FP_ANY
)
9321 gold_warning(_("%s: FP ABI %s is incompatible with %s"), name
.c_str(),
9322 fp_abi_string(in_fp
), fp_abi_string(out_fp
));
9326 // Merge attributes from input object.
9328 template<int size
, bool big_endian
>
9330 Target_mips
<size
, big_endian
>::merge_obj_attributes(const std::string
& name
,
9331 const Attributes_section_data
* pasd
)
9333 // Return if there is no attributes section data.
9337 // If output has no object attributes, just copy.
9338 if (this->attributes_section_data_
== NULL
)
9340 this->attributes_section_data_
= new Attributes_section_data(*pasd
);
9344 Object_attribute
* out_attr
= this->attributes_section_data_
->known_attributes(
9345 Object_attribute::OBJ_ATTR_GNU
);
9347 out_attr
[elfcpp::Tag_GNU_MIPS_ABI_FP
].set_type(1);
9348 out_attr
[elfcpp::Tag_GNU_MIPS_ABI_FP
].set_int_value(this->abiflags_
->fp_abi
);
9350 // Merge Tag_compatibility attributes and any common GNU ones.
9351 this->attributes_section_data_
->merge(name
.c_str(), pasd
);
9354 // Merge abiflags from input object.
9356 template<int size
, bool big_endian
>
9358 Target_mips
<size
, big_endian
>::merge_obj_abiflags(const std::string
& name
,
9359 Mips_abiflags
<big_endian
>* in_abiflags
)
9361 // If output has no abiflags, just copy.
9362 if (this->abiflags_
== NULL
)
9364 this->abiflags_
= new Mips_abiflags
<big_endian
>(*in_abiflags
);
9368 this->abiflags_
->fp_abi
= this->select_fp_abi(name
, in_abiflags
->fp_abi
,
9369 this->abiflags_
->fp_abi
);
9372 this->abiflags_
->isa_level
= std::max(this->abiflags_
->isa_level
,
9373 in_abiflags
->isa_level
);
9374 this->abiflags_
->isa_rev
= std::max(this->abiflags_
->isa_rev
,
9375 in_abiflags
->isa_rev
);
9376 this->abiflags_
->gpr_size
= std::max(this->abiflags_
->gpr_size
,
9377 in_abiflags
->gpr_size
);
9378 this->abiflags_
->cpr1_size
= std::max(this->abiflags_
->cpr1_size
,
9379 in_abiflags
->cpr1_size
);
9380 this->abiflags_
->cpr2_size
= std::max(this->abiflags_
->cpr2_size
,
9381 in_abiflags
->cpr2_size
);
9382 this->abiflags_
->ases
|= in_abiflags
->ases
;
9383 this->abiflags_
->flags1
|= in_abiflags
->flags1
;
9386 // Check whether machine EXTENSION is an extension of machine BASE.
9387 template<int size
, bool big_endian
>
9389 Target_mips
<size
, big_endian
>::mips_mach_extends(unsigned int base
,
9390 unsigned int extension
)
9392 if (extension
== base
)
9395 if ((base
== mach_mipsisa32
)
9396 && this->mips_mach_extends(mach_mipsisa64
, extension
))
9399 if ((base
== mach_mipsisa32r2
)
9400 && this->mips_mach_extends(mach_mipsisa64r2
, extension
))
9403 for (unsigned int i
= 0; i
< this->mips_mach_extensions_
.size(); ++i
)
9404 if (extension
== this->mips_mach_extensions_
[i
].first
)
9406 extension
= this->mips_mach_extensions_
[i
].second
;
9407 if (extension
== base
)
9414 // Merge file header flags from input object.
9416 template<int size
, bool big_endian
>
9418 Target_mips
<size
, big_endian
>::merge_obj_e_flags(const std::string
& name
,
9419 elfcpp::Elf_Word in_flags
)
9421 // If flags are not set yet, just copy them.
9422 if (!this->are_processor_specific_flags_set())
9424 this->set_processor_specific_flags(in_flags
);
9425 this->mach_
= this->elf_mips_mach(in_flags
);
9429 elfcpp::Elf_Word new_flags
= in_flags
;
9430 elfcpp::Elf_Word old_flags
= this->processor_specific_flags();
9431 elfcpp::Elf_Word merged_flags
= this->processor_specific_flags();
9432 merged_flags
|= new_flags
& elfcpp::EF_MIPS_NOREORDER
;
9434 // Check flag compatibility.
9435 new_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
9436 old_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
9438 // Some IRIX 6 BSD-compatibility objects have this bit set. It
9439 // doesn't seem to matter.
9440 new_flags
&= ~elfcpp::EF_MIPS_XGOT
;
9441 old_flags
&= ~elfcpp::EF_MIPS_XGOT
;
9443 // MIPSpro generates ucode info in n64 objects. Again, we should
9444 // just be able to ignore this.
9445 new_flags
&= ~elfcpp::EF_MIPS_UCODE
;
9446 old_flags
&= ~elfcpp::EF_MIPS_UCODE
;
9448 if (new_flags
== old_flags
)
9450 this->set_processor_specific_flags(merged_flags
);
9454 if (((new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0)
9455 != ((old_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0))
9456 gold_warning(_("%s: linking abicalls files with non-abicalls files"),
9459 if (new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
))
9460 merged_flags
|= elfcpp::EF_MIPS_CPIC
;
9461 if (!(new_flags
& elfcpp::EF_MIPS_PIC
))
9462 merged_flags
&= ~elfcpp::EF_MIPS_PIC
;
9464 new_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
9465 old_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
9467 // Compare the ISAs.
9468 if (mips_32bit_flags(old_flags
) != mips_32bit_flags(new_flags
))
9469 gold_error(_("%s: linking 32-bit code with 64-bit code"), name
.c_str());
9470 else if (!this->mips_mach_extends(this->elf_mips_mach(in_flags
), this->mach_
))
9472 // Output ISA isn't the same as, or an extension of, input ISA.
9473 if (this->mips_mach_extends(this->mach_
, this->elf_mips_mach(in_flags
)))
9475 // Copy the architecture info from input object to output. Also copy
9476 // the 32-bit flag (if set) so that we continue to recognise
9477 // output as a 32-bit binary.
9478 this->mach_
= this->elf_mips_mach(in_flags
);
9479 merged_flags
&= ~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
);
9480 merged_flags
|= (new_flags
& (elfcpp::EF_MIPS_ARCH
9481 | elfcpp::EF_MIPS_MACH
| elfcpp::EF_MIPS_32BITMODE
));
9483 // Update the ABI flags isa_level, isa_rev, isa_ext fields.
9484 this->update_abiflags_isa(name
, merged_flags
, this->abiflags_
);
9486 // Copy across the ABI flags if output doesn't use them
9487 // and if that was what caused us to treat input object as 32-bit.
9488 if ((old_flags
& elfcpp::EF_MIPS_ABI
) == 0
9489 && this->mips_32bit_flags(new_flags
)
9490 && !this->mips_32bit_flags(new_flags
& ~elfcpp::EF_MIPS_ABI
))
9491 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ABI
;
9494 // The ISAs aren't compatible.
9495 gold_error(_("%s: linking %s module with previous %s modules"),
9496 name
.c_str(), this->elf_mips_mach_name(in_flags
),
9497 this->elf_mips_mach_name(merged_flags
));
9500 new_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
9501 | elfcpp::EF_MIPS_32BITMODE
));
9502 old_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
9503 | elfcpp::EF_MIPS_32BITMODE
));
9506 if ((new_flags
& elfcpp::EF_MIPS_ABI
) != (old_flags
& elfcpp::EF_MIPS_ABI
))
9508 // Only error if both are set (to different values).
9509 if ((new_flags
& elfcpp::EF_MIPS_ABI
)
9510 && (old_flags
& elfcpp::EF_MIPS_ABI
))
9511 gold_error(_("%s: ABI mismatch: linking %s module with "
9512 "previous %s modules"), name
.c_str(),
9513 this->elf_mips_abi_name(in_flags
),
9514 this->elf_mips_abi_name(merged_flags
));
9516 new_flags
&= ~elfcpp::EF_MIPS_ABI
;
9517 old_flags
&= ~elfcpp::EF_MIPS_ABI
;
9520 // Compare ASEs. Forbid linking MIPS16 and microMIPS ASE modules together
9521 // and allow arbitrary mixing of the remaining ASEs (retain the union).
9522 if ((new_flags
& elfcpp::EF_MIPS_ARCH_ASE
)
9523 != (old_flags
& elfcpp::EF_MIPS_ARCH_ASE
))
9525 int old_micro
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
9526 int new_micro
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
9527 int old_m16
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
9528 int new_m16
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
9529 int micro_mis
= old_m16
&& new_micro
;
9530 int m16_mis
= old_micro
&& new_m16
;
9532 if (m16_mis
|| micro_mis
)
9533 gold_error(_("%s: ASE mismatch: linking %s module with "
9534 "previous %s modules"), name
.c_str(),
9535 m16_mis
? "MIPS16" : "microMIPS",
9536 m16_mis
? "microMIPS" : "MIPS16");
9538 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ARCH_ASE
;
9540 new_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
9541 old_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
9544 // Compare NaN encodings.
9545 if ((new_flags
& elfcpp::EF_MIPS_NAN2008
) != (old_flags
& elfcpp::EF_MIPS_NAN2008
))
9547 gold_error(_("%s: linking %s module with previous %s modules"),
9549 (new_flags
& elfcpp::EF_MIPS_NAN2008
9550 ? "-mnan=2008" : "-mnan=legacy"),
9551 (old_flags
& elfcpp::EF_MIPS_NAN2008
9552 ? "-mnan=2008" : "-mnan=legacy"));
9554 new_flags
&= ~elfcpp::EF_MIPS_NAN2008
;
9555 old_flags
&= ~elfcpp::EF_MIPS_NAN2008
;
9558 // Compare FP64 state.
9559 if ((new_flags
& elfcpp::EF_MIPS_FP64
) != (old_flags
& elfcpp::EF_MIPS_FP64
))
9561 gold_error(_("%s: linking %s module with previous %s modules"),
9563 (new_flags
& elfcpp::EF_MIPS_FP64
9564 ? "-mfp64" : "-mfp32"),
9565 (old_flags
& elfcpp::EF_MIPS_FP64
9566 ? "-mfp64" : "-mfp32"));
9568 new_flags
&= ~elfcpp::EF_MIPS_FP64
;
9569 old_flags
&= ~elfcpp::EF_MIPS_FP64
;
9572 // Warn about any other mismatches.
9573 if (new_flags
!= old_flags
)
9574 gold_error(_("%s: uses different e_flags (0x%x) fields than previous "
9575 "modules (0x%x)"), name
.c_str(), new_flags
, old_flags
);
9577 this->set_processor_specific_flags(merged_flags
);
9580 // Adjust ELF file header.
9582 template<int size
, bool big_endian
>
9584 Target_mips
<size
, big_endian
>::do_adjust_elf_header(
9585 unsigned char* view
,
9588 gold_assert(len
== elfcpp::Elf_sizes
<size
>::ehdr_size
);
9590 elfcpp::Ehdr
<size
, big_endian
> ehdr(view
);
9591 unsigned char e_ident
[elfcpp::EI_NIDENT
];
9592 elfcpp::Elf_Word flags
= this->processor_specific_flags();
9593 memcpy(e_ident
, ehdr
.get_e_ident(), elfcpp::EI_NIDENT
);
9595 unsigned char ei_abiversion
= 0;
9596 elfcpp::Elf_Half type
= ehdr
.get_e_type();
9597 if (type
== elfcpp::ET_EXEC
9598 && parameters
->options().copyreloc()
9599 && (flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
))
9600 == elfcpp::EF_MIPS_CPIC
)
9603 if (this->abiflags_
!= NULL
9604 && (this->abiflags_
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_64
9605 || this->abiflags_
->fp_abi
== elfcpp::Val_GNU_MIPS_ABI_FP_64A
))
9608 e_ident
[elfcpp::EI_ABIVERSION
] = ei_abiversion
;
9609 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
9610 oehdr
.put_e_ident(e_ident
);
9612 if (this->entry_symbol_is_compressed_
)
9613 oehdr
.put_e_entry(ehdr
.get_e_entry() + 1);
9616 // do_make_elf_object to override the same function in the base class.
9617 // We need to use a target-specific sub-class of
9618 // Sized_relobj_file<size, big_endian> to store Mips specific information.
9619 // Hence we need to have our own ELF object creation.
9621 template<int size
, bool big_endian
>
9623 Target_mips
<size
, big_endian
>::do_make_elf_object(
9624 const std::string
& name
,
9625 Input_file
* input_file
,
9626 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
9628 int et
= ehdr
.get_e_type();
9629 // ET_EXEC files are valid input for --just-symbols/-R,
9630 // and we treat them as relocatable objects.
9631 if (et
== elfcpp::ET_REL
9632 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
9634 Mips_relobj
<size
, big_endian
>* obj
=
9635 new Mips_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
9639 else if (et
== elfcpp::ET_DYN
)
9641 // TODO(sasa): Should we create Mips_dynobj?
9642 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
9646 gold_error(_("%s: unsupported ELF file type %d"),
9652 // Finalize the sections.
9654 template <int size
, bool big_endian
>
9656 Target_mips
<size
, big_endian
>::do_finalize_sections(Layout
* layout
,
9657 const Input_objects
* input_objects
,
9658 Symbol_table
* symtab
)
9660 const bool relocatable
= parameters
->options().relocatable();
9662 // Add +1 to MIPS16 and microMIPS init_ and _fini symbols so that DT_INIT and
9663 // DT_FINI have correct values.
9664 Mips_symbol
<size
>* init
= static_cast<Mips_symbol
<size
>*>(
9665 symtab
->lookup(parameters
->options().init()));
9666 if (init
!= NULL
&& (init
->is_mips16() || init
->is_micromips()))
9667 init
->set_value(init
->value() | 1);
9668 Mips_symbol
<size
>* fini
= static_cast<Mips_symbol
<size
>*>(
9669 symtab
->lookup(parameters
->options().fini()));
9670 if (fini
!= NULL
&& (fini
->is_mips16() || fini
->is_micromips()))
9671 fini
->set_value(fini
->value() | 1);
9673 // Check whether the entry symbol is mips16 or micromips. This is needed to
9674 // adjust entry address in ELF header.
9675 Mips_symbol
<size
>* entry
=
9676 static_cast<Mips_symbol
<size
>*>(symtab
->lookup(this->entry_symbol_name()));
9677 this->entry_symbol_is_compressed_
= (entry
!= NULL
&& (entry
->is_mips16()
9678 || entry
->is_micromips()));
9680 if (!parameters
->doing_static_link()
9681 && (strcmp(parameters
->options().hash_style(), "gnu") == 0
9682 || strcmp(parameters
->options().hash_style(), "both") == 0))
9684 // .gnu.hash and the MIPS ABI require .dynsym to be sorted in different
9685 // ways. .gnu.hash needs symbols to be grouped by hash code whereas the
9686 // MIPS ABI requires a mapping between the GOT and the symbol table.
9687 gold_error(".gnu.hash is incompatible with the MIPS ABI");
9690 // Check whether the final section that was scanned has HI16 or GOT16
9691 // relocations without the corresponding LO16 part.
9692 if (this->got16_addends_
.size() > 0)
9693 gold_error("Can't find matching LO16 reloc");
9695 Valtype gprmask
= 0;
9696 Valtype cprmask1
= 0;
9697 Valtype cprmask2
= 0;
9698 Valtype cprmask3
= 0;
9699 Valtype cprmask4
= 0;
9700 bool has_reginfo_section
= false;
9702 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9703 p
!= input_objects
->relobj_end();
9706 Mips_relobj
<size
, big_endian
>* relobj
=
9707 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
9709 // Check for any mips16 stub sections that we can discard.
9711 relobj
->discard_mips16_stub_sections(symtab
);
9713 if (!relobj
->merge_processor_specific_data())
9716 // Merge .reginfo contents of input objects.
9717 if (relobj
->has_reginfo_section())
9719 has_reginfo_section
= true;
9720 gprmask
|= relobj
->gprmask();
9721 cprmask1
|= relobj
->cprmask1();
9722 cprmask2
|= relobj
->cprmask2();
9723 cprmask3
|= relobj
->cprmask3();
9724 cprmask4
|= relobj
->cprmask4();
9727 // Merge processor specific flags.
9728 Mips_abiflags
<big_endian
> in_abiflags
;
9730 this->create_abiflags(relobj
, &in_abiflags
);
9731 this->merge_obj_e_flags(relobj
->name(),
9732 relobj
->processor_specific_flags());
9733 this->merge_obj_abiflags(relobj
->name(), &in_abiflags
);
9734 this->merge_obj_attributes(relobj
->name(),
9735 relobj
->attributes_section_data());
9738 // Create a .gnu.attributes section if we have merged any attributes
9740 if (this->attributes_section_data_
!= NULL
)
9742 Output_attributes_section_data
* attributes_section
=
9743 new Output_attributes_section_data(*this->attributes_section_data_
);
9744 layout
->add_output_section_data(".gnu.attributes",
9745 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
9746 attributes_section
, ORDER_INVALID
, false);
9749 // Create .MIPS.abiflags output section if there is an input section.
9750 if (this->has_abiflags_section_
)
9752 Mips_output_section_abiflags
<size
, big_endian
>* abiflags_section
=
9753 new Mips_output_section_abiflags
<size
, big_endian
>(*this->abiflags_
);
9755 Output_section
* os
=
9756 layout
->add_output_section_data(".MIPS.abiflags",
9757 elfcpp::SHT_MIPS_ABIFLAGS
,
9759 abiflags_section
, ORDER_INVALID
, false);
9761 if (!relocatable
&& os
!= NULL
)
9763 Output_segment
* abiflags_segment
=
9764 layout
->make_output_segment(elfcpp::PT_MIPS_ABIFLAGS
, elfcpp::PF_R
);
9765 abiflags_segment
->add_output_section_to_nonload(os
, elfcpp::PF_R
);
9769 if (has_reginfo_section
&& !parameters
->options().gc_sections())
9771 // Create .reginfo output section.
9772 Mips_output_section_reginfo
<size
, big_endian
>* reginfo_section
=
9773 new Mips_output_section_reginfo
<size
, big_endian
>(this, gprmask
,
9775 cprmask3
, cprmask4
);
9777 Output_section
* os
=
9778 layout
->add_output_section_data(".reginfo", elfcpp::SHT_MIPS_REGINFO
,
9779 elfcpp::SHF_ALLOC
, reginfo_section
,
9780 ORDER_INVALID
, false);
9782 if (!relocatable
&& os
!= NULL
)
9784 Output_segment
* reginfo_segment
=
9785 layout
->make_output_segment(elfcpp::PT_MIPS_REGINFO
,
9787 reginfo_segment
->add_output_section_to_nonload(os
, elfcpp::PF_R
);
9791 if (this->plt_
!= NULL
)
9793 // Set final PLT offsets for symbols.
9794 this->plt_section()->set_plt_offsets();
9796 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
9797 // Set STO_MICROMIPS flag if the output has microMIPS code, but only if
9798 // there are no standard PLT entries present.
9799 unsigned char nonvis
= 0;
9800 if (this->is_output_micromips()
9801 && !this->plt_section()->has_standard_entries())
9802 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
9803 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
9804 Symbol_table::PREDEFINED
,
9806 0, 0, elfcpp::STT_FUNC
,
9808 elfcpp::STV_DEFAULT
, nonvis
,
9812 if (this->mips_stubs_
!= NULL
)
9814 // Define _MIPS_STUBS_ at the start of the .MIPS.stubs section.
9815 unsigned char nonvis
= 0;
9816 if (this->is_output_micromips())
9817 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
9818 symtab
->define_in_output_data("_MIPS_STUBS_", NULL
,
9819 Symbol_table::PREDEFINED
,
9821 0, 0, elfcpp::STT_FUNC
,
9823 elfcpp::STV_DEFAULT
, nonvis
,
9827 if (!relocatable
&& !parameters
->doing_static_link())
9828 // In case there is no .got section, create one.
9829 this->got_section(symtab
, layout
);
9831 // Emit any relocs we saved in an attempt to avoid generating COPY
9833 if (this->copy_relocs_
.any_saved_relocs())
9834 this->copy_relocs_
.emit_mips(this->rel_dyn_section(layout
), symtab
, layout
,
9838 this->set_gp(layout
, symtab
);
9840 // Emit dynamic relocs.
9841 for (typename
std::vector
<Dyn_reloc
>::iterator p
= this->dyn_relocs_
.begin();
9842 p
!= this->dyn_relocs_
.end();
9844 p
->emit(this->rel_dyn_section(layout
), this->got_section(), symtab
);
9846 if (this->has_got_section())
9847 this->got_section()->lay_out_got(layout
, symtab
, input_objects
);
9849 if (this->mips_stubs_
!= NULL
)
9850 this->mips_stubs_
->set_needs_dynsym_value();
9852 // Check for functions that might need $25 to be valid on entry.
9853 // TODO(sasa): Can we do this without iterating over all symbols?
9854 typedef Symbol_visitor_check_symbols
<size
, big_endian
> Symbol_visitor
;
9855 symtab
->for_all_symbols
<size
, Symbol_visitor
>(Symbol_visitor(this, layout
,
9858 // Add NULL segment.
9860 layout
->make_output_segment(elfcpp::PT_NULL
, 0);
9862 // Fill in some more dynamic tags.
9863 // TODO(sasa): Add more dynamic tags.
9864 const Reloc_section
* rel_plt
= (this->plt_
== NULL
9865 ? NULL
: this->plt_
->rel_plt());
9866 layout
->add_target_dynamic_tags(true, this->got_
, rel_plt
,
9867 this->rel_dyn_
, true, false, false);
9869 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
9872 && !parameters
->doing_static_link())
9875 // This element holds a 32-bit version id for the Runtime
9876 // Linker Interface. This will start at integer value 1.
9878 odyn
->add_constant(elfcpp::DT_MIPS_RLD_VERSION
, d_val
);
9881 d_val
= elfcpp::RHF_NOTPOT
;
9882 odyn
->add_constant(elfcpp::DT_MIPS_FLAGS
, d_val
);
9884 // Save layout for using when emitting custom dynamic tags.
9885 this->layout_
= layout
;
9887 // This member holds the base address of the segment.
9888 odyn
->add_custom(elfcpp::DT_MIPS_BASE_ADDRESS
);
9890 // This member holds the number of entries in the .dynsym section.
9891 odyn
->add_custom(elfcpp::DT_MIPS_SYMTABNO
);
9893 // This member holds the index of the first dynamic symbol
9894 // table entry that corresponds to an entry in the global offset table.
9895 odyn
->add_custom(elfcpp::DT_MIPS_GOTSYM
);
9897 // This member holds the number of local GOT entries.
9898 odyn
->add_constant(elfcpp::DT_MIPS_LOCAL_GOTNO
,
9899 this->got_
->get_local_gotno());
9901 if (this->plt_
!= NULL
)
9902 // DT_MIPS_PLTGOT dynamic tag
9903 odyn
->add_section_address(elfcpp::DT_MIPS_PLTGOT
, this->got_plt_
);
9905 if (!parameters
->options().shared())
9907 this->rld_map_
= new Output_data_zero_fill(size
/ 8, size
/ 8);
9909 layout
->add_output_section_data(".rld_map", elfcpp::SHT_PROGBITS
,
9910 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
9911 this->rld_map_
, ORDER_INVALID
, false);
9913 // __RLD_MAP will be filled in by the runtime loader to contain
9914 // a pointer to the _r_debug structure.
9915 Symbol
* rld_map
= symtab
->define_in_output_data("__RLD_MAP", NULL
,
9916 Symbol_table::PREDEFINED
,
9918 0, 0, elfcpp::STT_OBJECT
,
9920 elfcpp::STV_DEFAULT
, 0,
9923 if (!rld_map
->is_forced_local())
9924 rld_map
->set_needs_dynsym_entry();
9926 if (!parameters
->options().pie())
9927 // This member holds the absolute address of the debug pointer.
9928 odyn
->add_section_address(elfcpp::DT_MIPS_RLD_MAP
, this->rld_map_
);
9930 // This member holds the offset to the debug pointer,
9931 // relative to the address of the tag.
9932 odyn
->add_custom(elfcpp::DT_MIPS_RLD_MAP_REL
);
9937 // Get the custom dynamic tag value.
9938 template<int size
, bool big_endian
>
9940 Target_mips
<size
, big_endian
>::do_dynamic_tag_custom_value(elfcpp::DT tag
) const
9944 case elfcpp::DT_MIPS_BASE_ADDRESS
:
9946 // The base address of the segment.
9947 // At this point, the segment list has been sorted into final order,
9948 // so just return vaddr of the first readable PT_LOAD segment.
9949 Output_segment
* seg
=
9950 this->layout_
->find_output_segment(elfcpp::PT_LOAD
, elfcpp::PF_R
, 0);
9951 gold_assert(seg
!= NULL
);
9952 return seg
->vaddr();
9955 case elfcpp::DT_MIPS_SYMTABNO
:
9956 // The number of entries in the .dynsym section.
9957 return this->get_dt_mips_symtabno();
9959 case elfcpp::DT_MIPS_GOTSYM
:
9961 // The index of the first dynamic symbol table entry that corresponds
9962 // to an entry in the GOT.
9963 if (this->got_
->first_global_got_dynsym_index() != -1U)
9964 return this->got_
->first_global_got_dynsym_index();
9966 // In case if we don't have global GOT symbols we default to setting
9967 // DT_MIPS_GOTSYM to the same value as DT_MIPS_SYMTABNO.
9968 return this->get_dt_mips_symtabno();
9971 case elfcpp::DT_MIPS_RLD_MAP_REL
:
9973 // The MIPS_RLD_MAP_REL tag stores the offset to the debug pointer,
9974 // relative to the address of the tag.
9975 Output_data_dynamic
* const odyn
= this->layout_
->dynamic_data();
9976 unsigned int entry_offset
=
9977 odyn
->get_entry_offset(elfcpp::DT_MIPS_RLD_MAP_REL
);
9978 gold_assert(entry_offset
!= -1U);
9979 return this->rld_map_
->address() - (odyn
->address() + entry_offset
);
9982 gold_error(_("Unknown dynamic tag 0x%x"), (unsigned int)tag
);
9985 return (unsigned int)-1;
9988 // Relocate section data.
9990 template<int size
, bool big_endian
>
9992 Target_mips
<size
, big_endian
>::relocate_section(
9993 const Relocate_info
<size
, big_endian
>* relinfo
,
9994 unsigned int sh_type
,
9995 const unsigned char* prelocs
,
9997 Output_section
* output_section
,
9998 bool needs_special_offset_handling
,
9999 unsigned char* view
,
10000 Mips_address address
,
10001 section_size_type view_size
,
10002 const Reloc_symbol_changes
* reloc_symbol_changes
)
10004 typedef Target_mips
<size
, big_endian
> Mips
;
10005 typedef typename Target_mips
<size
, big_endian
>::Relocate Mips_relocate
;
10007 if (sh_type
== elfcpp::SHT_REL
)
10009 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
10012 gold::relocate_section
<size
, big_endian
, Mips
, Mips_relocate
,
10013 gold::Default_comdat_behavior
, Classify_reloc
>(
10019 needs_special_offset_handling
,
10023 reloc_symbol_changes
);
10025 else if (sh_type
== elfcpp::SHT_RELA
)
10027 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
10030 gold::relocate_section
<size
, big_endian
, Mips
, Mips_relocate
,
10031 gold::Default_comdat_behavior
, Classify_reloc
>(
10037 needs_special_offset_handling
,
10041 reloc_symbol_changes
);
10045 // Return the size of a relocation while scanning during a relocatable
10049 mips_get_size_for_reloc(unsigned int r_type
, Relobj
* object
)
10053 case elfcpp::R_MIPS_NONE
:
10054 case elfcpp::R_MIPS_TLS_DTPMOD64
:
10055 case elfcpp::R_MIPS_TLS_DTPREL64
:
10056 case elfcpp::R_MIPS_TLS_TPREL64
:
10059 case elfcpp::R_MIPS_32
:
10060 case elfcpp::R_MIPS_TLS_DTPMOD32
:
10061 case elfcpp::R_MIPS_TLS_DTPREL32
:
10062 case elfcpp::R_MIPS_TLS_TPREL32
:
10063 case elfcpp::R_MIPS_REL32
:
10064 case elfcpp::R_MIPS_PC32
:
10065 case elfcpp::R_MIPS_GPREL32
:
10066 case elfcpp::R_MIPS_JALR
:
10067 case elfcpp::R_MIPS_EH
:
10070 case elfcpp::R_MIPS_16
:
10071 case elfcpp::R_MIPS_HI16
:
10072 case elfcpp::R_MIPS_LO16
:
10073 case elfcpp::R_MIPS_HIGHER
:
10074 case elfcpp::R_MIPS_HIGHEST
:
10075 case elfcpp::R_MIPS_GPREL16
:
10076 case elfcpp::R_MIPS16_HI16
:
10077 case elfcpp::R_MIPS16_LO16
:
10078 case elfcpp::R_MIPS_PC16
:
10079 case elfcpp::R_MIPS_PCHI16
:
10080 case elfcpp::R_MIPS_PCLO16
:
10081 case elfcpp::R_MIPS_GOT16
:
10082 case elfcpp::R_MIPS16_GOT16
:
10083 case elfcpp::R_MIPS_CALL16
:
10084 case elfcpp::R_MIPS16_CALL16
:
10085 case elfcpp::R_MIPS_GOT_HI16
:
10086 case elfcpp::R_MIPS_CALL_HI16
:
10087 case elfcpp::R_MIPS_GOT_LO16
:
10088 case elfcpp::R_MIPS_CALL_LO16
:
10089 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
10090 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
10091 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
10092 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
10093 case elfcpp::R_MIPS16_GPREL
:
10094 case elfcpp::R_MIPS_GOT_DISP
:
10095 case elfcpp::R_MIPS_LITERAL
:
10096 case elfcpp::R_MIPS_GOT_PAGE
:
10097 case elfcpp::R_MIPS_GOT_OFST
:
10098 case elfcpp::R_MIPS_TLS_GD
:
10099 case elfcpp::R_MIPS_TLS_LDM
:
10100 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10103 // These relocations are not byte sized
10104 case elfcpp::R_MIPS_26
:
10105 case elfcpp::R_MIPS16_26
:
10106 case elfcpp::R_MIPS_PC21_S2
:
10107 case elfcpp::R_MIPS_PC26_S2
:
10108 case elfcpp::R_MIPS_PC18_S3
:
10109 case elfcpp::R_MIPS_PC19_S2
:
10112 case elfcpp::R_MIPS_COPY
:
10113 case elfcpp::R_MIPS_JUMP_SLOT
:
10114 object
->error(_("unexpected reloc %u in object file"), r_type
);
10118 object
->error(_("unsupported reloc %u in object file"), r_type
);
10123 // Scan the relocs during a relocatable link.
10125 template<int size
, bool big_endian
>
10127 Target_mips
<size
, big_endian
>::scan_relocatable_relocs(
10128 Symbol_table
* symtab
,
10130 Sized_relobj_file
<size
, big_endian
>* object
,
10131 unsigned int data_shndx
,
10132 unsigned int sh_type
,
10133 const unsigned char* prelocs
,
10134 size_t reloc_count
,
10135 Output_section
* output_section
,
10136 bool needs_special_offset_handling
,
10137 size_t local_symbol_count
,
10138 const unsigned char* plocal_symbols
,
10139 Relocatable_relocs
* rr
)
10141 if (sh_type
== elfcpp::SHT_REL
)
10143 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
10145 typedef Mips_scan_relocatable_relocs
<big_endian
, Classify_reloc
>
10146 Scan_relocatable_relocs
;
10148 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_relocatable_relocs
>(
10156 needs_special_offset_handling
,
10157 local_symbol_count
,
10161 else if (sh_type
== elfcpp::SHT_RELA
)
10163 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
10165 typedef Mips_scan_relocatable_relocs
<big_endian
, Classify_reloc
>
10166 Scan_relocatable_relocs
;
10168 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_relocatable_relocs
>(
10176 needs_special_offset_handling
,
10177 local_symbol_count
,
10182 gold_unreachable();
10185 // Scan the relocs for --emit-relocs.
10187 template<int size
, bool big_endian
>
10189 Target_mips
<size
, big_endian
>::emit_relocs_scan(
10190 Symbol_table
* symtab
,
10192 Sized_relobj_file
<size
, big_endian
>* object
,
10193 unsigned int data_shndx
,
10194 unsigned int sh_type
,
10195 const unsigned char* prelocs
,
10196 size_t reloc_count
,
10197 Output_section
* output_section
,
10198 bool needs_special_offset_handling
,
10199 size_t local_symbol_count
,
10200 const unsigned char* plocal_syms
,
10201 Relocatable_relocs
* rr
)
10203 if (sh_type
== elfcpp::SHT_REL
)
10205 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
10207 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
10208 Emit_relocs_strategy
;
10210 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
10218 needs_special_offset_handling
,
10219 local_symbol_count
,
10223 else if (sh_type
== elfcpp::SHT_RELA
)
10225 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
10227 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
10228 Emit_relocs_strategy
;
10230 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
10238 needs_special_offset_handling
,
10239 local_symbol_count
,
10244 gold_unreachable();
10247 // Emit relocations for a section.
10249 template<int size
, bool big_endian
>
10251 Target_mips
<size
, big_endian
>::relocate_relocs(
10252 const Relocate_info
<size
, big_endian
>* relinfo
,
10253 unsigned int sh_type
,
10254 const unsigned char* prelocs
,
10255 size_t reloc_count
,
10256 Output_section
* output_section
,
10257 typename
elfcpp::Elf_types
<size
>::Elf_Off
10258 offset_in_output_section
,
10259 unsigned char* view
,
10260 Mips_address view_address
,
10261 section_size_type view_size
,
10262 unsigned char* reloc_view
,
10263 section_size_type reloc_view_size
)
10265 if (sh_type
== elfcpp::SHT_REL
)
10267 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
10270 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
10275 offset_in_output_section
,
10282 else if (sh_type
== elfcpp::SHT_RELA
)
10284 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
10287 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
10292 offset_in_output_section
,
10300 gold_unreachable();
10303 // Perform target-specific processing in a relocatable link. This is
10304 // only used if we use the relocation strategy RELOC_SPECIAL.
10306 template<int size
, bool big_endian
>
10308 Target_mips
<size
, big_endian
>::relocate_special_relocatable(
10309 const Relocate_info
<size
, big_endian
>* relinfo
,
10310 unsigned int sh_type
,
10311 const unsigned char* preloc_in
,
10313 Output_section
* output_section
,
10314 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
10315 unsigned char* view
,
10316 Mips_address view_address
,
10318 unsigned char* preloc_out
)
10320 // We can only handle REL type relocation sections.
10321 gold_assert(sh_type
== elfcpp::SHT_REL
);
10323 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
10325 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc_write
10328 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
10330 const Mips_address invalid_address
= static_cast<Mips_address
>(0) - 1;
10332 Mips_relobj
<size
, big_endian
>* object
=
10333 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
10334 const unsigned int local_count
= object
->local_symbol_count();
10336 Reltype
reloc(preloc_in
);
10337 Reltype_write
reloc_write(preloc_out
);
10339 elfcpp::Elf_types
<32>::Elf_WXword r_info
= reloc
.get_r_info();
10340 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
10341 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
10343 // Get the new symbol index.
10344 // We only use RELOC_SPECIAL strategy in local relocations.
10345 gold_assert(r_sym
< local_count
);
10347 // We are adjusting a section symbol. We need to find
10348 // the symbol table index of the section symbol for
10349 // the output section corresponding to input section
10350 // in which this symbol is defined.
10352 unsigned int shndx
= object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
10353 gold_assert(is_ordinary
);
10354 Output_section
* os
= object
->output_section(shndx
);
10355 gold_assert(os
!= NULL
);
10356 gold_assert(os
->needs_symtab_index());
10357 unsigned int new_symndx
= os
->symtab_index();
10359 // Get the new offset--the location in the output section where
10360 // this relocation should be applied.
10362 Mips_address offset
= reloc
.get_r_offset();
10363 Mips_address new_offset
;
10364 if (offset_in_output_section
!= invalid_address
)
10365 new_offset
= offset
+ offset_in_output_section
;
10368 section_offset_type sot_offset
=
10369 convert_types
<section_offset_type
, Mips_address
>(offset
);
10370 section_offset_type new_sot_offset
=
10371 output_section
->output_offset(object
, relinfo
->data_shndx
,
10373 gold_assert(new_sot_offset
!= -1);
10374 new_offset
= new_sot_offset
;
10377 // In an object file, r_offset is an offset within the section.
10378 // In an executable or dynamic object, generated by
10379 // --emit-relocs, r_offset is an absolute address.
10380 if (!parameters
->options().relocatable())
10382 new_offset
+= view_address
;
10383 if (offset_in_output_section
!= invalid_address
)
10384 new_offset
-= offset_in_output_section
;
10387 reloc_write
.put_r_offset(new_offset
);
10388 reloc_write
.put_r_info(elfcpp::elf_r_info
<32>(new_symndx
, r_type
));
10390 // Handle the reloc addend.
10391 // The relocation uses a section symbol in the input file.
10392 // We are adjusting it to use a section symbol in the output
10393 // file. The input section symbol refers to some address in
10394 // the input section. We need the relocation in the output
10395 // file to refer to that same address. This adjustment to
10396 // the addend is the same calculation we use for a simple
10397 // absolute relocation for the input section symbol.
10398 Valtype calculated_value
= 0;
10399 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
10401 unsigned char* paddend
= view
+ offset
;
10402 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
10405 case elfcpp::R_MIPS_26
:
10406 reloc_status
= Reloc_funcs::rel26(paddend
, object
, psymval
,
10407 offset_in_output_section
, true, 0, sh_type
== elfcpp::SHT_REL
, NULL
,
10408 false /*TODO(sasa): cross mode jump*/, r_type
, this->jal_to_bal(),
10409 false, &calculated_value
);
10413 gold_unreachable();
10416 // Report any errors.
10417 switch (reloc_status
)
10419 case Reloc_funcs::STATUS_OKAY
:
10421 case Reloc_funcs::STATUS_OVERFLOW
:
10422 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
10423 _("relocation overflow: "
10424 "%u against local symbol %u in %s"),
10425 r_type
, r_sym
, object
->name().c_str());
10427 case Reloc_funcs::STATUS_BAD_RELOC
:
10428 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
10429 _("unexpected opcode while processing relocation"));
10432 gold_unreachable();
10436 // Optimize the TLS relocation type based on what we know about the
10437 // symbol. IS_FINAL is true if the final address of this symbol is
10438 // known at link time.
10440 template<int size
, bool big_endian
>
10441 tls::Tls_optimization
10442 Target_mips
<size
, big_endian
>::optimize_tls_reloc(bool, int)
10444 // FIXME: Currently we do not do any TLS optimization.
10445 return tls::TLSOPT_NONE
;
10448 // Scan a relocation for a local symbol.
10450 template<int size
, bool big_endian
>
10452 Target_mips
<size
, big_endian
>::Scan::local(
10453 Symbol_table
* symtab
,
10455 Target_mips
<size
, big_endian
>* target
,
10456 Sized_relobj_file
<size
, big_endian
>* object
,
10457 unsigned int data_shndx
,
10458 Output_section
* output_section
,
10459 const Relatype
* rela
,
10460 const Reltype
* rel
,
10461 unsigned int rel_type
,
10462 unsigned int r_type
,
10463 const elfcpp::Sym
<size
, big_endian
>& lsym
,
10469 Mips_address r_offset
;
10470 unsigned int r_sym
;
10471 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
10473 if (rel_type
== elfcpp::SHT_RELA
)
10475 r_offset
= rela
->get_r_offset();
10476 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10478 r_addend
= rela
->get_r_addend();
10482 r_offset
= rel
->get_r_offset();
10483 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
10488 Mips_relobj
<size
, big_endian
>* mips_obj
=
10489 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
10491 if (mips_obj
->is_mips16_stub_section(data_shndx
))
10493 mips_obj
->get_mips16_stub_section(data_shndx
)
10494 ->new_local_reloc_found(r_type
, r_sym
);
10497 if (r_type
== elfcpp::R_MIPS_NONE
)
10498 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
10502 if (!mips16_call_reloc(r_type
)
10503 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
10504 // This reloc would need to refer to a MIPS16 hard-float stub, if
10505 // there is one. We ignore MIPS16 stub sections and .pdr section when
10506 // looking for relocs that would need to refer to MIPS16 stubs.
10507 mips_obj
->add_local_non_16bit_call(r_sym
);
10509 if (r_type
== elfcpp::R_MIPS16_26
10510 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
10511 mips_obj
->add_local_16bit_call(r_sym
);
10515 case elfcpp::R_MIPS_GOT16
:
10516 case elfcpp::R_MIPS_CALL16
:
10517 case elfcpp::R_MIPS_CALL_HI16
:
10518 case elfcpp::R_MIPS_CALL_LO16
:
10519 case elfcpp::R_MIPS_GOT_HI16
:
10520 case elfcpp::R_MIPS_GOT_LO16
:
10521 case elfcpp::R_MIPS_GOT_PAGE
:
10522 case elfcpp::R_MIPS_GOT_OFST
:
10523 case elfcpp::R_MIPS_GOT_DISP
:
10524 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10525 case elfcpp::R_MIPS_TLS_GD
:
10526 case elfcpp::R_MIPS_TLS_LDM
:
10527 case elfcpp::R_MIPS16_GOT16
:
10528 case elfcpp::R_MIPS16_CALL16
:
10529 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10530 case elfcpp::R_MIPS16_TLS_GD
:
10531 case elfcpp::R_MIPS16_TLS_LDM
:
10532 case elfcpp::R_MICROMIPS_GOT16
:
10533 case elfcpp::R_MICROMIPS_CALL16
:
10534 case elfcpp::R_MICROMIPS_CALL_HI16
:
10535 case elfcpp::R_MICROMIPS_CALL_LO16
:
10536 case elfcpp::R_MICROMIPS_GOT_HI16
:
10537 case elfcpp::R_MICROMIPS_GOT_LO16
:
10538 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10539 case elfcpp::R_MICROMIPS_GOT_OFST
:
10540 case elfcpp::R_MICROMIPS_GOT_DISP
:
10541 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10542 case elfcpp::R_MICROMIPS_TLS_GD
:
10543 case elfcpp::R_MICROMIPS_TLS_LDM
:
10544 case elfcpp::R_MIPS_EH
:
10545 // We need a GOT section.
10546 target
->got_section(symtab
, layout
);
10553 if (call_lo16_reloc(r_type
)
10554 || got_lo16_reloc(r_type
)
10555 || got_disp_reloc(r_type
)
10556 || eh_reloc(r_type
))
10558 // We may need a local GOT entry for this relocation. We
10559 // don't count R_MIPS_GOT_PAGE because we can estimate the
10560 // maximum number of pages needed by looking at the size of
10561 // the segment. Similar comments apply to R_MIPS*_GOT16 and
10562 // R_MIPS*_CALL16. We don't count R_MIPS_GOT_HI16, or
10563 // R_MIPS_CALL_HI16 because these are always followed by an
10564 // R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
10565 Mips_output_data_got
<size
, big_endian
>* got
=
10566 target
->got_section(symtab
, layout
);
10567 bool is_section_symbol
= lsym
.get_st_type() == elfcpp::STT_SECTION
;
10568 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
, -1U,
10569 is_section_symbol
);
10574 case elfcpp::R_MIPS_CALL16
:
10575 case elfcpp::R_MIPS16_CALL16
:
10576 case elfcpp::R_MICROMIPS_CALL16
:
10577 gold_error(_("CALL16 reloc at 0x%lx not against global symbol "),
10578 (unsigned long)r_offset
);
10581 case elfcpp::R_MIPS_GOT_PAGE
:
10582 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10583 case elfcpp::R_MIPS16_GOT16
:
10584 case elfcpp::R_MIPS_GOT16
:
10585 case elfcpp::R_MIPS_GOT_HI16
:
10586 case elfcpp::R_MIPS_GOT_LO16
:
10587 case elfcpp::R_MICROMIPS_GOT16
:
10588 case elfcpp::R_MICROMIPS_GOT_HI16
:
10589 case elfcpp::R_MICROMIPS_GOT_LO16
:
10591 // This relocation needs a page entry in the GOT.
10592 // Get the section contents.
10593 section_size_type view_size
= 0;
10594 const unsigned char* view
= object
->section_contents(data_shndx
,
10595 &view_size
, false);
10598 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
10599 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
10602 if (rel_type
== elfcpp::SHT_REL
&& got16_reloc(r_type
))
10603 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
10604 object
, data_shndx
, r_type
, r_sym
, addend
));
10606 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
, addend
);
10610 case elfcpp::R_MIPS_HI16
:
10611 case elfcpp::R_MIPS_PCHI16
:
10612 case elfcpp::R_MIPS16_HI16
:
10613 case elfcpp::R_MICROMIPS_HI16
:
10614 // Record the reloc so that we can check whether the corresponding LO16
10616 if (rel_type
== elfcpp::SHT_REL
)
10617 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
10618 object
, data_shndx
, r_type
, r_sym
, 0));
10621 case elfcpp::R_MIPS_LO16
:
10622 case elfcpp::R_MIPS_PCLO16
:
10623 case elfcpp::R_MIPS16_LO16
:
10624 case elfcpp::R_MICROMIPS_LO16
:
10626 if (rel_type
!= elfcpp::SHT_REL
)
10629 // Find corresponding GOT16/HI16 relocation.
10631 // According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
10632 // be immediately following. However, for the IRIX6 ABI, the next
10633 // relocation may be a composed relocation consisting of several
10634 // relocations for the same address. In that case, the R_MIPS_LO16
10635 // relocation may occur as one of these. We permit a similar
10636 // extension in general, as that is useful for GCC.
10638 // In some cases GCC dead code elimination removes the LO16 but
10639 // keeps the corresponding HI16. This is strictly speaking a
10640 // violation of the ABI but not immediately harmful.
10642 typename
std::list
<got16_addend
<size
, big_endian
> >::iterator it
=
10643 target
->got16_addends_
.begin();
10644 while (it
!= target
->got16_addends_
.end())
10646 got16_addend
<size
, big_endian
> _got16_addend
= *it
;
10648 // TODO(sasa): Split got16_addends_ list into two lists - one for
10649 // GOT16 relocs and the other for HI16 relocs.
10651 // Report an error if we find HI16 or GOT16 reloc from the
10652 // previous section without the matching LO16 part.
10653 if (_got16_addend
.object
!= object
10654 || _got16_addend
.shndx
!= data_shndx
)
10656 gold_error("Can't find matching LO16 reloc");
10660 if (_got16_addend
.r_sym
!= r_sym
10661 || !is_matching_lo16_reloc(_got16_addend
.r_type
, r_type
))
10667 // We found a matching HI16 or GOT16 reloc for this LO16 reloc.
10668 // For GOT16, we need to calculate combined addend and record GOT page
10670 if (got16_reloc(_got16_addend
.r_type
))
10673 section_size_type view_size
= 0;
10674 const unsigned char* view
= object
->section_contents(data_shndx
,
10679 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
10680 int32_t addend
= Bits
<16>::sign_extend32(val
& 0xffff);
10682 addend
= (_got16_addend
.addend
<< 16) + addend
;
10683 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
,
10687 it
= target
->got16_addends_
.erase(it
);
10695 case elfcpp::R_MIPS_32
:
10696 case elfcpp::R_MIPS_REL32
:
10697 case elfcpp::R_MIPS_64
:
10699 if (parameters
->options().output_is_position_independent())
10701 // If building a shared library (or a position-independent
10702 // executable), we need to create a dynamic relocation for
10704 if (is_readonly_section(output_section
))
10706 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
10707 rel_dyn
->add_symbolless_local_addend(object
, r_sym
,
10708 elfcpp::R_MIPS_REL32
,
10709 output_section
, data_shndx
,
10715 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10716 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10717 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10718 case elfcpp::R_MIPS_TLS_LDM
:
10719 case elfcpp::R_MIPS16_TLS_LDM
:
10720 case elfcpp::R_MICROMIPS_TLS_LDM
:
10721 case elfcpp::R_MIPS_TLS_GD
:
10722 case elfcpp::R_MIPS16_TLS_GD
:
10723 case elfcpp::R_MICROMIPS_TLS_GD
:
10725 bool output_is_shared
= parameters
->options().shared();
10726 const tls::Tls_optimization optimized_type
10727 = Target_mips
<size
, big_endian
>::optimize_tls_reloc(
10728 !output_is_shared
, r_type
);
10731 case elfcpp::R_MIPS_TLS_GD
:
10732 case elfcpp::R_MIPS16_TLS_GD
:
10733 case elfcpp::R_MICROMIPS_TLS_GD
:
10734 if (optimized_type
== tls::TLSOPT_NONE
)
10736 // Create a pair of GOT entries for the module index and
10737 // dtv-relative offset.
10738 Mips_output_data_got
<size
, big_endian
>* got
=
10739 target
->got_section(symtab
, layout
);
10740 unsigned int shndx
= lsym
.get_st_shndx();
10742 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
10745 object
->error(_("local symbol %u has bad shndx %u"),
10749 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
10754 // FIXME: TLS optimization not supported yet.
10755 gold_unreachable();
10759 case elfcpp::R_MIPS_TLS_LDM
:
10760 case elfcpp::R_MIPS16_TLS_LDM
:
10761 case elfcpp::R_MICROMIPS_TLS_LDM
:
10762 if (optimized_type
== tls::TLSOPT_NONE
)
10764 // We always record LDM symbols as local with index 0.
10765 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
10771 // FIXME: TLS optimization not supported yet.
10772 gold_unreachable();
10775 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10776 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10777 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10778 layout
->set_has_static_tls();
10779 if (optimized_type
== tls::TLSOPT_NONE
)
10781 // Create a GOT entry for the tp-relative offset.
10782 Mips_output_data_got
<size
, big_endian
>* got
=
10783 target
->got_section(symtab
, layout
);
10784 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
10789 // FIXME: TLS optimization not supported yet.
10790 gold_unreachable();
10795 gold_unreachable();
10804 // Refuse some position-dependent relocations when creating a
10805 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
10806 // not PIC, but we can create dynamic relocations and the result
10807 // will be fine. Also do not refuse R_MIPS_LO16, which can be
10808 // combined with R_MIPS_GOT16.
10809 if (parameters
->options().shared())
10813 case elfcpp::R_MIPS16_HI16
:
10814 case elfcpp::R_MIPS_HI16
:
10815 case elfcpp::R_MIPS_HIGHER
:
10816 case elfcpp::R_MIPS_HIGHEST
:
10817 case elfcpp::R_MICROMIPS_HI16
:
10818 case elfcpp::R_MICROMIPS_HIGHER
:
10819 case elfcpp::R_MICROMIPS_HIGHEST
:
10820 // Don't refuse a high part relocation if it's against
10821 // no symbol (e.g. part of a compound relocation).
10826 case elfcpp::R_MIPS16_26
:
10827 case elfcpp::R_MIPS_26
:
10828 case elfcpp::R_MICROMIPS_26_S1
:
10829 gold_error(_("%s: relocation %u against `%s' can not be used when "
10830 "making a shared object; recompile with -fPIC"),
10831 object
->name().c_str(), r_type
, "a local symbol");
10838 template<int size
, bool big_endian
>
10840 Target_mips
<size
, big_endian
>::Scan::local(
10841 Symbol_table
* symtab
,
10843 Target_mips
<size
, big_endian
>* target
,
10844 Sized_relobj_file
<size
, big_endian
>* object
,
10845 unsigned int data_shndx
,
10846 Output_section
* output_section
,
10847 const Reltype
& reloc
,
10848 unsigned int r_type
,
10849 const elfcpp::Sym
<size
, big_endian
>& lsym
,
10862 (const Relatype
*) NULL
,
10866 lsym
, is_discarded
);
10870 template<int size
, bool big_endian
>
10872 Target_mips
<size
, big_endian
>::Scan::local(
10873 Symbol_table
* symtab
,
10875 Target_mips
<size
, big_endian
>* target
,
10876 Sized_relobj_file
<size
, big_endian
>* object
,
10877 unsigned int data_shndx
,
10878 Output_section
* output_section
,
10879 const Relatype
& reloc
,
10880 unsigned int r_type
,
10881 const elfcpp::Sym
<size
, big_endian
>& lsym
,
10895 (const Reltype
*) NULL
,
10898 lsym
, is_discarded
);
10901 // Scan a relocation for a global symbol.
10903 template<int size
, bool big_endian
>
10905 Target_mips
<size
, big_endian
>::Scan::global(
10906 Symbol_table
* symtab
,
10908 Target_mips
<size
, big_endian
>* target
,
10909 Sized_relobj_file
<size
, big_endian
>* object
,
10910 unsigned int data_shndx
,
10911 Output_section
* output_section
,
10912 const Relatype
* rela
,
10913 const Reltype
* rel
,
10914 unsigned int rel_type
,
10915 unsigned int r_type
,
10918 Mips_address r_offset
;
10919 unsigned int r_sym
;
10920 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
10922 if (rel_type
== elfcpp::SHT_RELA
)
10924 r_offset
= rela
->get_r_offset();
10925 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10927 r_addend
= rela
->get_r_addend();
10931 r_offset
= rel
->get_r_offset();
10932 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
10937 Mips_relobj
<size
, big_endian
>* mips_obj
=
10938 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
10939 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
10941 if (mips_obj
->is_mips16_stub_section(data_shndx
))
10943 mips_obj
->get_mips16_stub_section(data_shndx
)
10944 ->new_global_reloc_found(r_type
, mips_sym
);
10947 if (r_type
== elfcpp::R_MIPS_NONE
)
10948 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
10952 if (!mips16_call_reloc(r_type
)
10953 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
10954 // This reloc would need to refer to a MIPS16 hard-float stub, if
10955 // there is one. We ignore MIPS16 stub sections and .pdr section when
10956 // looking for relocs that would need to refer to MIPS16 stubs.
10957 mips_sym
->set_need_fn_stub();
10959 // We need PLT entries if there are static-only relocations against
10960 // an externally-defined function. This can technically occur for
10961 // shared libraries if there are branches to the symbol, although it
10962 // is unlikely that this will be used in practice due to the short
10963 // ranges involved. It can occur for any relative or absolute relocation
10964 // in executables; in that case, the PLT entry becomes the function's
10965 // canonical address.
10966 bool static_reloc
= false;
10968 // Set CAN_MAKE_DYNAMIC to true if we can convert this
10969 // relocation into a dynamic one.
10970 bool can_make_dynamic
= false;
10973 case elfcpp::R_MIPS_GOT16
:
10974 case elfcpp::R_MIPS_CALL16
:
10975 case elfcpp::R_MIPS_CALL_HI16
:
10976 case elfcpp::R_MIPS_CALL_LO16
:
10977 case elfcpp::R_MIPS_GOT_HI16
:
10978 case elfcpp::R_MIPS_GOT_LO16
:
10979 case elfcpp::R_MIPS_GOT_PAGE
:
10980 case elfcpp::R_MIPS_GOT_OFST
:
10981 case elfcpp::R_MIPS_GOT_DISP
:
10982 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10983 case elfcpp::R_MIPS_TLS_GD
:
10984 case elfcpp::R_MIPS_TLS_LDM
:
10985 case elfcpp::R_MIPS16_GOT16
:
10986 case elfcpp::R_MIPS16_CALL16
:
10987 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10988 case elfcpp::R_MIPS16_TLS_GD
:
10989 case elfcpp::R_MIPS16_TLS_LDM
:
10990 case elfcpp::R_MICROMIPS_GOT16
:
10991 case elfcpp::R_MICROMIPS_CALL16
:
10992 case elfcpp::R_MICROMIPS_CALL_HI16
:
10993 case elfcpp::R_MICROMIPS_CALL_LO16
:
10994 case elfcpp::R_MICROMIPS_GOT_HI16
:
10995 case elfcpp::R_MICROMIPS_GOT_LO16
:
10996 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10997 case elfcpp::R_MICROMIPS_GOT_OFST
:
10998 case elfcpp::R_MICROMIPS_GOT_DISP
:
10999 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
11000 case elfcpp::R_MICROMIPS_TLS_GD
:
11001 case elfcpp::R_MICROMIPS_TLS_LDM
:
11002 case elfcpp::R_MIPS_EH
:
11003 // We need a GOT section.
11004 target
->got_section(symtab
, layout
);
11007 // This is just a hint; it can safely be ignored. Don't set
11008 // has_static_relocs for the corresponding symbol.
11009 case elfcpp::R_MIPS_JALR
:
11010 case elfcpp::R_MICROMIPS_JALR
:
11013 case elfcpp::R_MIPS_GPREL16
:
11014 case elfcpp::R_MIPS_GPREL32
:
11015 case elfcpp::R_MIPS16_GPREL
:
11016 case elfcpp::R_MICROMIPS_GPREL16
:
11018 // GP-relative relocations always resolve to a definition in a
11019 // regular input file, ignoring the one-definition rule. This is
11020 // important for the GP setup sequence in NewABI code, which
11021 // always resolves to a local function even if other relocations
11022 // against the symbol wouldn't.
11023 //constrain_symbol_p = FALSE;
11026 case elfcpp::R_MIPS_32
:
11027 case elfcpp::R_MIPS_REL32
:
11028 case elfcpp::R_MIPS_64
:
11029 if ((parameters
->options().shared()
11030 || (strcmp(gsym
->name(), "__gnu_local_gp") != 0
11031 && (!is_readonly_section(output_section
)
11032 || mips_obj
->is_pic())))
11033 && (output_section
->flags() & elfcpp::SHF_ALLOC
) != 0)
11035 if (r_type
!= elfcpp::R_MIPS_REL32
)
11036 mips_sym
->set_pointer_equality_needed();
11037 can_make_dynamic
= true;
11043 // Most static relocations require pointer equality, except
11045 mips_sym
->set_pointer_equality_needed();
11048 case elfcpp::R_MIPS_26
:
11049 case elfcpp::R_MIPS_PC16
:
11050 case elfcpp::R_MIPS_PC21_S2
:
11051 case elfcpp::R_MIPS_PC26_S2
:
11052 case elfcpp::R_MIPS16_26
:
11053 case elfcpp::R_MICROMIPS_26_S1
:
11054 case elfcpp::R_MICROMIPS_PC7_S1
:
11055 case elfcpp::R_MICROMIPS_PC10_S1
:
11056 case elfcpp::R_MICROMIPS_PC16_S1
:
11057 case elfcpp::R_MICROMIPS_PC23_S2
:
11058 static_reloc
= true;
11059 mips_sym
->set_has_static_relocs();
11063 // If there are call relocations against an externally-defined symbol,
11064 // see whether we can create a MIPS lazy-binding stub for it. We can
11065 // only do this if all references to the function are through call
11066 // relocations, and in that case, the traditional lazy-binding stubs
11067 // are much more efficient than PLT entries.
11070 case elfcpp::R_MIPS16_CALL16
:
11071 case elfcpp::R_MIPS_CALL16
:
11072 case elfcpp::R_MIPS_CALL_HI16
:
11073 case elfcpp::R_MIPS_CALL_LO16
:
11074 case elfcpp::R_MIPS_JALR
:
11075 case elfcpp::R_MICROMIPS_CALL16
:
11076 case elfcpp::R_MICROMIPS_CALL_HI16
:
11077 case elfcpp::R_MICROMIPS_CALL_LO16
:
11078 case elfcpp::R_MICROMIPS_JALR
:
11079 if (!mips_sym
->no_lazy_stub())
11081 if ((mips_sym
->needs_plt_entry() && mips_sym
->is_from_dynobj())
11082 // Calls from shared objects to undefined symbols of type
11083 // STT_NOTYPE need lazy-binding stub.
11084 || (mips_sym
->is_undefined() && parameters
->options().shared()))
11085 target
->mips_stubs_section(layout
)->make_entry(mips_sym
);
11090 // We must not create a stub for a symbol that has relocations
11091 // related to taking the function's address.
11092 mips_sym
->set_no_lazy_stub();
11093 target
->remove_lazy_stub_entry(mips_sym
);
11098 if (relocation_needs_la25_stub
<size
, big_endian
>(mips_obj
, r_type
,
11099 mips_sym
->is_mips16()))
11100 mips_sym
->set_has_nonpic_branches();
11102 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
11103 // and has a special meaning.
11104 bool gp_disp_against_hi16
= (!mips_obj
->is_newabi()
11105 && strcmp(gsym
->name(), "_gp_disp") == 0
11106 && (hi16_reloc(r_type
) || lo16_reloc(r_type
)));
11107 if (static_reloc
&& gsym
->needs_plt_entry())
11109 target
->make_plt_entry(symtab
, layout
, mips_sym
, r_type
);
11111 // Since this is not a PC-relative relocation, we may be
11112 // taking the address of a function. In that case we need to
11113 // set the entry in the dynamic symbol table to the address of
11115 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
11117 gsym
->set_needs_dynsym_value();
11118 // We distinguish between PLT entries and lazy-binding stubs by
11119 // giving the former an st_other value of STO_MIPS_PLT. Set the
11120 // flag if there are any relocations in the binary where pointer
11121 // equality matters.
11122 if (mips_sym
->pointer_equality_needed())
11123 mips_sym
->set_mips_plt();
11126 if ((static_reloc
|| can_make_dynamic
) && !gp_disp_against_hi16
)
11128 // Absolute addressing relocations.
11129 // Make a dynamic relocation if necessary.
11130 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
11132 if (gsym
->may_need_copy_reloc())
11134 target
->copy_reloc(symtab
, layout
, object
, data_shndx
,
11135 output_section
, gsym
, r_type
, r_offset
);
11137 else if (can_make_dynamic
)
11139 // Create .rel.dyn section.
11140 target
->rel_dyn_section(layout
);
11141 target
->dynamic_reloc(mips_sym
, elfcpp::R_MIPS_REL32
, mips_obj
,
11142 data_shndx
, output_section
, r_offset
);
11145 gold_error(_("non-dynamic relocations refer to dynamic symbol %s"),
11150 bool for_call
= false;
11153 case elfcpp::R_MIPS_CALL16
:
11154 case elfcpp::R_MIPS16_CALL16
:
11155 case elfcpp::R_MICROMIPS_CALL16
:
11156 case elfcpp::R_MIPS_CALL_HI16
:
11157 case elfcpp::R_MIPS_CALL_LO16
:
11158 case elfcpp::R_MICROMIPS_CALL_HI16
:
11159 case elfcpp::R_MICROMIPS_CALL_LO16
:
11163 case elfcpp::R_MIPS16_GOT16
:
11164 case elfcpp::R_MIPS_GOT16
:
11165 case elfcpp::R_MIPS_GOT_HI16
:
11166 case elfcpp::R_MIPS_GOT_LO16
:
11167 case elfcpp::R_MICROMIPS_GOT16
:
11168 case elfcpp::R_MICROMIPS_GOT_HI16
:
11169 case elfcpp::R_MICROMIPS_GOT_LO16
:
11170 case elfcpp::R_MIPS_GOT_DISP
:
11171 case elfcpp::R_MICROMIPS_GOT_DISP
:
11172 case elfcpp::R_MIPS_EH
:
11174 // The symbol requires a GOT entry.
11175 Mips_output_data_got
<size
, big_endian
>* got
=
11176 target
->got_section(symtab
, layout
);
11177 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
11179 mips_sym
->set_global_got_area(GGA_NORMAL
);
11183 case elfcpp::R_MIPS_GOT_PAGE
:
11184 case elfcpp::R_MICROMIPS_GOT_PAGE
:
11186 // This relocation needs a page entry in the GOT.
11187 // Get the section contents.
11188 section_size_type view_size
= 0;
11189 const unsigned char* view
=
11190 object
->section_contents(data_shndx
, &view_size
, false);
11193 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
11194 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
11196 Mips_output_data_got
<size
, big_endian
>* got
=
11197 target
->got_section(symtab
, layout
);
11198 got
->record_got_page_entry(mips_obj
, r_sym
, addend
);
11200 // If this is a global, overridable symbol, GOT_PAGE will
11201 // decay to GOT_DISP, so we'll need a GOT entry for it.
11202 bool def_regular
= (mips_sym
->source() == Symbol::FROM_OBJECT
11203 && !mips_sym
->object()->is_dynamic()
11204 && !mips_sym
->is_undefined());
11206 || (parameters
->options().output_is_position_independent()
11207 && !parameters
->options().Bsymbolic()
11208 && !mips_sym
->is_forced_local()))
11210 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
11212 mips_sym
->set_global_got_area(GGA_NORMAL
);
11217 case elfcpp::R_MIPS_TLS_GOTTPREL
:
11218 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
11219 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
11220 case elfcpp::R_MIPS_TLS_LDM
:
11221 case elfcpp::R_MIPS16_TLS_LDM
:
11222 case elfcpp::R_MICROMIPS_TLS_LDM
:
11223 case elfcpp::R_MIPS_TLS_GD
:
11224 case elfcpp::R_MIPS16_TLS_GD
:
11225 case elfcpp::R_MICROMIPS_TLS_GD
:
11227 const bool is_final
= gsym
->final_value_is_known();
11228 const tls::Tls_optimization optimized_type
=
11229 Target_mips
<size
, big_endian
>::optimize_tls_reloc(is_final
, r_type
);
11233 case elfcpp::R_MIPS_TLS_GD
:
11234 case elfcpp::R_MIPS16_TLS_GD
:
11235 case elfcpp::R_MICROMIPS_TLS_GD
:
11236 if (optimized_type
== tls::TLSOPT_NONE
)
11238 // Create a pair of GOT entries for the module index and
11239 // dtv-relative offset.
11240 Mips_output_data_got
<size
, big_endian
>* got
=
11241 target
->got_section(symtab
, layout
);
11242 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
11247 // FIXME: TLS optimization not supported yet.
11248 gold_unreachable();
11252 case elfcpp::R_MIPS_TLS_LDM
:
11253 case elfcpp::R_MIPS16_TLS_LDM
:
11254 case elfcpp::R_MICROMIPS_TLS_LDM
:
11255 if (optimized_type
== tls::TLSOPT_NONE
)
11257 // We always record LDM symbols as local with index 0.
11258 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
11264 // FIXME: TLS optimization not supported yet.
11265 gold_unreachable();
11268 case elfcpp::R_MIPS_TLS_GOTTPREL
:
11269 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
11270 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
11271 layout
->set_has_static_tls();
11272 if (optimized_type
== tls::TLSOPT_NONE
)
11274 // Create a GOT entry for the tp-relative offset.
11275 Mips_output_data_got
<size
, big_endian
>* got
=
11276 target
->got_section(symtab
, layout
);
11277 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
11282 // FIXME: TLS optimization not supported yet.
11283 gold_unreachable();
11288 gold_unreachable();
11292 case elfcpp::R_MIPS_COPY
:
11293 case elfcpp::R_MIPS_JUMP_SLOT
:
11294 // These are relocations which should only be seen by the
11295 // dynamic linker, and should never be seen here.
11296 gold_error(_("%s: unexpected reloc %u in object file"),
11297 object
->name().c_str(), r_type
);
11304 // Refuse some position-dependent relocations when creating a
11305 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
11306 // not PIC, but we can create dynamic relocations and the result
11307 // will be fine. Also do not refuse R_MIPS_LO16, which can be
11308 // combined with R_MIPS_GOT16.
11309 if (parameters
->options().shared())
11313 case elfcpp::R_MIPS16_HI16
:
11314 case elfcpp::R_MIPS_HI16
:
11315 case elfcpp::R_MIPS_HIGHER
:
11316 case elfcpp::R_MIPS_HIGHEST
:
11317 case elfcpp::R_MICROMIPS_HI16
:
11318 case elfcpp::R_MICROMIPS_HIGHER
:
11319 case elfcpp::R_MICROMIPS_HIGHEST
:
11320 // Don't refuse a high part relocation if it's against
11321 // no symbol (e.g. part of a compound relocation).
11325 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
11326 // and has a special meaning.
11327 if (!mips_obj
->is_newabi() && strcmp(gsym
->name(), "_gp_disp") == 0)
11331 case elfcpp::R_MIPS16_26
:
11332 case elfcpp::R_MIPS_26
:
11333 case elfcpp::R_MICROMIPS_26_S1
:
11334 gold_error(_("%s: relocation %u against `%s' can not be used when "
11335 "making a shared object; recompile with -fPIC"),
11336 object
->name().c_str(), r_type
, gsym
->name());
11343 template<int size
, bool big_endian
>
11345 Target_mips
<size
, big_endian
>::Scan::global(
11346 Symbol_table
* symtab
,
11348 Target_mips
<size
, big_endian
>* target
,
11349 Sized_relobj_file
<size
, big_endian
>* object
,
11350 unsigned int data_shndx
,
11351 Output_section
* output_section
,
11352 const Relatype
& reloc
,
11353 unsigned int r_type
,
11364 (const Reltype
*) NULL
,
11370 template<int size
, bool big_endian
>
11372 Target_mips
<size
, big_endian
>::Scan::global(
11373 Symbol_table
* symtab
,
11375 Target_mips
<size
, big_endian
>* target
,
11376 Sized_relobj_file
<size
, big_endian
>* object
,
11377 unsigned int data_shndx
,
11378 Output_section
* output_section
,
11379 const Reltype
& reloc
,
11380 unsigned int r_type
,
11390 (const Relatype
*) NULL
,
11397 // Return whether a R_MIPS_32/R_MIPS64 relocation needs to be applied.
11398 // In cases where Scan::local() or Scan::global() has created
11399 // a dynamic relocation, the addend of the relocation is carried
11400 // in the data, and we must not apply the static relocation.
11402 template<int size
, bool big_endian
>
11404 Target_mips
<size
, big_endian
>::Relocate::should_apply_static_reloc(
11405 const Mips_symbol
<size
>* gsym
,
11406 unsigned int r_type
,
11407 Output_section
* output_section
,
11408 Target_mips
* target
)
11410 // If the output section is not allocated, then we didn't call
11411 // scan_relocs, we didn't create a dynamic reloc, and we must apply
11413 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
11420 // For global symbols, we use the same helper routines used in the
11422 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
))
11423 && !gsym
->may_need_copy_reloc())
11425 // We have generated dynamic reloc (R_MIPS_REL32).
11427 bool multi_got
= false;
11428 if (target
->has_got_section())
11429 multi_got
= target
->got_section()->multi_got();
11430 bool has_got_offset
;
11432 has_got_offset
= gsym
->has_got_offset(GOT_TYPE_STANDARD
);
11434 has_got_offset
= gsym
->global_gotoffset() != -1U;
11435 if (!has_got_offset
)
11438 // Apply the relocation only if the symbol is in the local got.
11439 // Do not apply the relocation if the symbol is in the global
11441 return symbol_references_local(gsym
, gsym
->has_dynsym_index());
11444 // We have not generated dynamic reloc.
11449 // Perform a relocation.
11451 template<int size
, bool big_endian
>
11453 Target_mips
<size
, big_endian
>::Relocate::relocate(
11454 const Relocate_info
<size
, big_endian
>* relinfo
,
11455 unsigned int rel_type
,
11456 Target_mips
* target
,
11457 Output_section
* output_section
,
11459 const unsigned char* preloc
,
11460 const Sized_symbol
<size
>* gsym
,
11461 const Symbol_value
<size
>* psymval
,
11462 unsigned char* view
,
11463 Mips_address address
,
11466 Mips_address r_offset
;
11467 unsigned int r_sym
;
11468 unsigned int r_type
;
11469 unsigned int r_type2
;
11470 unsigned int r_type3
;
11471 unsigned char r_ssym
;
11472 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
11473 // r_offset and r_type of the next relocation is needed for resolving multiple
11474 // consecutive relocations with the same offset.
11475 Mips_address next_r_offset
= static_cast<Mips_address
>(0) - 1;
11476 unsigned int next_r_type
= elfcpp::R_MIPS_NONE
;
11478 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11479 size_t reloc_count
= shdr
.get_sh_size() / shdr
.get_sh_entsize();
11481 if (rel_type
== elfcpp::SHT_RELA
)
11483 const Relatype
rela(preloc
);
11484 r_offset
= rela
.get_r_offset();
11485 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11487 r_type
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11489 r_type2
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11490 get_r_type2(&rela
);
11491 r_type3
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11492 get_r_type3(&rela
);
11493 r_ssym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11495 r_addend
= rela
.get_r_addend();
11496 // If this is not last relocation, get r_offset and r_type of the next
11498 if (relnum
+ 1 < reloc_count
)
11500 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11501 const Relatype
next_rela(preloc
+ reloc_size
);
11502 next_r_offset
= next_rela
.get_r_offset();
11504 Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
11505 get_r_type(&next_rela
);
11510 const Reltype
rel(preloc
);
11511 r_offset
= rel
.get_r_offset();
11512 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
11514 r_type
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
11517 r_type2
= elfcpp::R_MIPS_NONE
;
11518 r_type3
= elfcpp::R_MIPS_NONE
;
11520 // If this is not last relocation, get r_offset and r_type of the next
11522 if (relnum
+ 1 < reloc_count
)
11524 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rel_size
;
11525 const Reltype
next_rel(preloc
+ reloc_size
);
11526 next_r_offset
= next_rel
.get_r_offset();
11527 next_r_type
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
11528 get_r_type(&next_rel
);
11532 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
11533 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
11535 Mips_relobj
<size
, big_endian
>* object
=
11536 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
11538 bool target_is_16_bit_code
= false;
11539 bool target_is_micromips_code
= false;
11540 bool cross_mode_jump
;
11542 Symbol_value
<size
> symval
;
11544 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
11546 bool changed_symbol_value
= false;
11549 target_is_16_bit_code
= object
->local_symbol_is_mips16(r_sym
);
11550 target_is_micromips_code
= object
->local_symbol_is_micromips(r_sym
);
11551 if (target_is_16_bit_code
|| target_is_micromips_code
)
11553 // MIPS16/microMIPS text labels should be treated as odd.
11554 symval
.set_output_value(psymval
->value(object
, 1));
11556 changed_symbol_value
= true;
11561 target_is_16_bit_code
= mips_sym
->is_mips16();
11562 target_is_micromips_code
= mips_sym
->is_micromips();
11564 // If this is a mips16/microMIPS text symbol, add 1 to the value to make
11565 // it odd. This will cause something like .word SYM to come up with
11566 // the right value when it is loaded into the PC.
11568 if ((mips_sym
->is_mips16() || mips_sym
->is_micromips())
11569 && psymval
->value(object
, 0) != 0)
11571 symval
.set_output_value(psymval
->value(object
, 0) | 1);
11573 changed_symbol_value
= true;
11576 // Pick the value to use for symbols defined in shared objects.
11577 if (mips_sym
->use_plt_offset(Scan::get_reference_flags(r_type
))
11578 || mips_sym
->has_lazy_stub())
11580 Mips_address value
;
11581 if (!mips_sym
->has_lazy_stub())
11583 // Prefer a standard MIPS PLT entry.
11584 if (mips_sym
->has_mips_plt_offset())
11586 value
= target
->plt_section()->mips_entry_address(mips_sym
);
11587 target_is_micromips_code
= false;
11588 target_is_16_bit_code
= false;
11592 value
= (target
->plt_section()->comp_entry_address(mips_sym
)
11594 if (target
->is_output_micromips())
11595 target_is_micromips_code
= true;
11597 target_is_16_bit_code
= true;
11601 value
= target
->mips_stubs_section()->stub_address(mips_sym
);
11603 symval
.set_output_value(value
);
11608 // TRUE if the symbol referred to by this relocation is "_gp_disp".
11609 // Note that such a symbol must always be a global symbol.
11610 bool gp_disp
= (gsym
!= NULL
&& (strcmp(gsym
->name(), "_gp_disp") == 0)
11611 && !object
->is_newabi());
11613 // TRUE if the symbol referred to by this relocation is "__gnu_local_gp".
11614 // Note that such a symbol must always be a global symbol.
11615 bool gnu_local_gp
= gsym
&& (strcmp(gsym
->name(), "__gnu_local_gp") == 0);
11620 if (!hi16_reloc(r_type
) && !lo16_reloc(r_type
))
11621 gold_error_at_location(relinfo
, relnum
, r_offset
,
11622 _("relocations against _gp_disp are permitted only"
11623 " with R_MIPS_HI16 and R_MIPS_LO16 relocations."));
11625 else if (gnu_local_gp
)
11627 // __gnu_local_gp is _gp symbol.
11628 symval
.set_output_value(target
->adjusted_gp_value(object
));
11632 // If this is a reference to a 16-bit function with a stub, we need
11633 // to redirect the relocation to the stub unless:
11635 // (a) the relocation is for a MIPS16 JAL;
11637 // (b) the relocation is for a MIPS16 PIC call, and there are no
11638 // non-MIPS16 uses of the GOT slot; or
11640 // (c) the section allows direct references to MIPS16 functions.
11641 if (r_type
!= elfcpp::R_MIPS16_26
11642 && ((mips_sym
!= NULL
11643 && mips_sym
->has_mips16_fn_stub()
11644 && (r_type
!= elfcpp::R_MIPS16_CALL16
|| mips_sym
->need_fn_stub()))
11645 || (mips_sym
== NULL
11646 && object
->get_local_mips16_fn_stub(r_sym
) != NULL
))
11647 && !object
->section_allows_mips16_refs(relinfo
->data_shndx
))
11649 // This is a 32- or 64-bit call to a 16-bit function. We should
11650 // have already noticed that we were going to need the
11652 Mips_address value
;
11653 if (mips_sym
== NULL
)
11654 value
= object
->get_local_mips16_fn_stub(r_sym
)->output_address();
11657 gold_assert(mips_sym
->need_fn_stub());
11658 if (mips_sym
->has_la25_stub())
11659 value
= target
->la25_stub_section()->stub_address(mips_sym
);
11662 value
= mips_sym
->template
11663 get_mips16_fn_stub
<big_endian
>()->output_address();
11666 symval
.set_output_value(value
);
11668 changed_symbol_value
= true;
11670 // The target is 16-bit, but the stub isn't.
11671 target_is_16_bit_code
= false;
11673 // If this is a MIPS16 call with a stub, that is made through the PLT or
11674 // to a standard MIPS function, we need to redirect the call to the stub.
11675 // Note that we specifically exclude R_MIPS16_CALL16 from this behavior;
11676 // indirect calls should use an indirect stub instead.
11677 else if (r_type
== elfcpp::R_MIPS16_26
11678 && ((mips_sym
!= NULL
11679 && (mips_sym
->has_mips16_call_stub()
11680 || mips_sym
->has_mips16_call_fp_stub()))
11681 || (mips_sym
== NULL
11682 && object
->get_local_mips16_call_stub(r_sym
) != NULL
))
11683 && ((mips_sym
!= NULL
&& mips_sym
->has_plt_offset())
11684 || !target_is_16_bit_code
))
11686 Mips16_stub_section
<size
, big_endian
>* call_stub
;
11687 if (mips_sym
== NULL
)
11688 call_stub
= object
->get_local_mips16_call_stub(r_sym
);
11691 // If both call_stub and call_fp_stub are defined, we can figure
11692 // out which one to use by checking which one appears in the input
11694 if (mips_sym
->has_mips16_call_stub()
11695 && mips_sym
->has_mips16_call_fp_stub())
11698 for (unsigned int i
= 1; i
< object
->shnum(); ++i
)
11700 if (object
->is_mips16_call_fp_stub_section(i
))
11702 call_stub
= mips_sym
->template
11703 get_mips16_call_fp_stub
<big_endian
>();
11708 if (call_stub
== NULL
)
11710 mips_sym
->template get_mips16_call_stub
<big_endian
>();
11712 else if (mips_sym
->has_mips16_call_stub())
11713 call_stub
= mips_sym
->template get_mips16_call_stub
<big_endian
>();
11715 call_stub
= mips_sym
->template get_mips16_call_fp_stub
<big_endian
>();
11718 symval
.set_output_value(call_stub
->output_address());
11720 changed_symbol_value
= true;
11722 // If this is a direct call to a PIC function, redirect to the
11724 else if (mips_sym
!= NULL
11725 && mips_sym
->has_la25_stub()
11726 && relocation_needs_la25_stub
<size
, big_endian
>(
11727 object
, r_type
, target_is_16_bit_code
))
11729 Mips_address value
= target
->la25_stub_section()->stub_address(mips_sym
);
11730 if (mips_sym
->is_micromips())
11732 symval
.set_output_value(value
);
11735 // For direct MIPS16 and microMIPS calls make sure the compressed PLT
11736 // entry is used if a standard PLT entry has also been made.
11737 else if ((r_type
== elfcpp::R_MIPS16_26
11738 || r_type
== elfcpp::R_MICROMIPS_26_S1
)
11739 && mips_sym
!= NULL
11740 && mips_sym
->has_plt_offset()
11741 && mips_sym
->has_comp_plt_offset()
11742 && mips_sym
->has_mips_plt_offset())
11744 Mips_address value
= (target
->plt_section()->comp_entry_address(mips_sym
)
11746 symval
.set_output_value(value
);
11749 target_is_16_bit_code
= !target
->is_output_micromips();
11750 target_is_micromips_code
= target
->is_output_micromips();
11753 // Make sure MIPS16 and microMIPS are not used together.
11754 if ((r_type
== elfcpp::R_MIPS16_26
&& target_is_micromips_code
)
11755 || (micromips_branch_reloc(r_type
) && target_is_16_bit_code
))
11757 gold_error(_("MIPS16 and microMIPS functions cannot call each other"));
11760 // Calls from 16-bit code to 32-bit code and vice versa require the
11761 // mode change. However, we can ignore calls to undefined weak symbols,
11762 // which should never be executed at runtime. This exception is important
11763 // because the assembly writer may have "known" that any definition of the
11764 // symbol would be 16-bit code, and that direct jumps were therefore
11767 (!(gsym
!= NULL
&& gsym
->is_weak_undefined())
11768 && ((r_type
== elfcpp::R_MIPS16_26
&& !target_is_16_bit_code
)
11769 || (r_type
== elfcpp::R_MICROMIPS_26_S1
&& !target_is_micromips_code
)
11770 || ((r_type
== elfcpp::R_MIPS_26
|| r_type
== elfcpp::R_MIPS_JALR
)
11771 && (target_is_16_bit_code
|| target_is_micromips_code
))));
11773 bool local
= (mips_sym
== NULL
11774 || (mips_sym
->got_only_for_calls()
11775 ? symbol_calls_local(mips_sym
, mips_sym
->has_dynsym_index())
11776 : symbol_references_local(mips_sym
,
11777 mips_sym
->has_dynsym_index())));
11779 // Global R_MIPS_GOT_PAGE/R_MICROMIPS_GOT_PAGE relocations are equivalent
11780 // to R_MIPS_GOT_DISP/R_MICROMIPS_GOT_DISP. The addend is applied by the
11781 // corresponding R_MIPS_GOT_OFST/R_MICROMIPS_GOT_OFST.
11782 if (got_page_reloc(r_type
) && !local
)
11783 r_type
= (micromips_reloc(r_type
) ? elfcpp::R_MICROMIPS_GOT_DISP
11784 : elfcpp::R_MIPS_GOT_DISP
);
11786 unsigned int got_offset
= 0;
11789 // Whether we have to extract addend from instruction.
11790 bool extract_addend
= rel_type
== elfcpp::SHT_REL
;
11791 unsigned int r_types
[3] = { r_type
, r_type2
, r_type3
};
11793 Reloc_funcs::mips_reloc_unshuffle(view
, r_type
, false);
11795 // For Mips64 N64 ABI, there may be up to three operations specified per
11796 // record, by the fields r_type, r_type2, and r_type3. The first operation
11797 // takes its addend from the relocation record. Each subsequent operation
11798 // takes as its addend the result of the previous operation.
11799 // The first operation in a record which references a symbol uses the symbol
11800 // implied by r_sym. The next operation in a record which references a symbol
11801 // uses the special symbol value given by the r_ssym field. A third operation
11802 // in a record which references a symbol will assume a NULL symbol,
11803 // i.e. value zero.
11806 // Check if a record references to a symbol.
11807 for (unsigned int i
= 0; i
< 3; ++i
)
11809 if (r_types
[i
] == elfcpp::R_MIPS_NONE
)
11812 // If we didn't apply previous relocation, use its result as addend
11814 if (this->calculate_only_
)
11816 r_addend
= this->calculated_value_
;
11817 extract_addend
= false;
11820 // In the N32 and 64-bit ABIs there may be multiple consecutive
11821 // relocations for the same offset. In that case we are
11822 // supposed to treat the output of each relocation as the addend
11823 // for the next. For N64 ABI, we are checking offsets only in a
11824 // third operation in a record (r_type3).
11825 this->calculate_only_
=
11826 (object
->is_n64() && i
< 2
11827 ? r_types
[i
+1] != elfcpp::R_MIPS_NONE
11828 : (r_offset
== next_r_offset
) && (next_r_type
!= elfcpp::R_MIPS_NONE
));
11830 if (object
->is_n64())
11834 // Handle special symbol for r_type2 relocation type.
11838 symval
.set_output_value(0);
11841 symval
.set_output_value(target
->gp_value());
11844 symval
.set_output_value(object
->gp_value());
11847 symval
.set_output_value(address
);
11850 gold_unreachable();
11856 // For r_type3 symbol value is 0.
11857 symval
.set_output_value(0);
11861 bool update_got_entry
= false;
11862 switch (r_types
[i
])
11864 case elfcpp::R_MIPS_NONE
:
11866 case elfcpp::R_MIPS_16
:
11867 reloc_status
= Reloc_funcs::rel16(view
, object
, psymval
, r_addend
,
11869 this->calculate_only_
,
11870 &this->calculated_value_
);
11873 case elfcpp::R_MIPS_32
:
11874 if (should_apply_static_reloc(mips_sym
, r_types
[i
], output_section
,
11876 reloc_status
= Reloc_funcs::rel32(view
, object
, psymval
, r_addend
,
11878 this->calculate_only_
,
11879 &this->calculated_value_
);
11880 if (mips_sym
!= NULL
11881 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
11882 && mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
11884 // If mips_sym->has_mips16_fn_stub() is false, symbol value is
11885 // already updated by adding +1.
11886 if (mips_sym
->has_mips16_fn_stub())
11888 gold_assert(mips_sym
->need_fn_stub());
11889 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
11890 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
11892 symval
.set_output_value(fn_stub
->output_address());
11895 got_offset
= mips_sym
->global_gotoffset();
11896 update_got_entry
= true;
11900 case elfcpp::R_MIPS_64
:
11901 if (should_apply_static_reloc(mips_sym
, r_types
[i
], output_section
,
11903 reloc_status
= Reloc_funcs::rel64(view
, object
, psymval
, r_addend
,
11905 this->calculate_only_
,
11906 &this->calculated_value_
, false);
11907 else if (target
->is_output_n64() && r_addend
!= 0)
11908 // Only apply the addend. The static relocation was RELA, but the
11909 // dynamic relocation is REL, so we need to apply the addend.
11910 reloc_status
= Reloc_funcs::rel64(view
, object
, psymval
, r_addend
,
11912 this->calculate_only_
,
11913 &this->calculated_value_
, true);
11915 case elfcpp::R_MIPS_REL32
:
11916 gold_unreachable();
11918 case elfcpp::R_MIPS_PC32
:
11919 reloc_status
= Reloc_funcs::relpc32(view
, object
, psymval
, address
,
11920 r_addend
, extract_addend
,
11921 this->calculate_only_
,
11922 &this->calculated_value_
);
11925 case elfcpp::R_MIPS16_26
:
11926 // The calculation for R_MIPS16_26 is just the same as for an
11927 // R_MIPS_26. It's only the storage of the relocated field into
11928 // the output file that's different. So, we just fall through to the
11929 // R_MIPS_26 case here.
11930 case elfcpp::R_MIPS_26
:
11931 case elfcpp::R_MICROMIPS_26_S1
:
11932 reloc_status
= Reloc_funcs::rel26(view
, object
, psymval
, address
,
11933 gsym
== NULL
, r_addend
, extract_addend
, gsym
, cross_mode_jump
,
11934 r_types
[i
], target
->jal_to_bal(), this->calculate_only_
,
11935 &this->calculated_value_
);
11938 case elfcpp::R_MIPS_HI16
:
11939 case elfcpp::R_MIPS16_HI16
:
11940 case elfcpp::R_MICROMIPS_HI16
:
11941 if (rel_type
== elfcpp::SHT_RELA
)
11942 reloc_status
= Reloc_funcs::do_relhi16(view
, object
, psymval
,
11944 gp_disp
, r_types
[i
],
11947 this->calculate_only_
,
11948 &this->calculated_value_
);
11949 else if (rel_type
== elfcpp::SHT_REL
)
11950 reloc_status
= Reloc_funcs::relhi16(view
, object
, psymval
, r_addend
,
11951 address
, gp_disp
, r_types
[i
],
11952 r_sym
, extract_addend
);
11954 gold_unreachable();
11957 case elfcpp::R_MIPS_LO16
:
11958 case elfcpp::R_MIPS16_LO16
:
11959 case elfcpp::R_MICROMIPS_LO16
:
11960 case elfcpp::R_MICROMIPS_HI0_LO16
:
11961 reloc_status
= Reloc_funcs::rello16(target
, view
, object
, psymval
,
11962 r_addend
, extract_addend
, address
,
11963 gp_disp
, r_types
[i
], r_sym
,
11964 rel_type
, this->calculate_only_
,
11965 &this->calculated_value_
);
11968 case elfcpp::R_MIPS_LITERAL
:
11969 case elfcpp::R_MICROMIPS_LITERAL
:
11970 // Because we don't merge literal sections, we can handle this
11971 // just like R_MIPS_GPREL16. In the long run, we should merge
11972 // shared literals, and then we will need to additional work
11977 case elfcpp::R_MIPS_GPREL16
:
11978 case elfcpp::R_MIPS16_GPREL
:
11979 case elfcpp::R_MICROMIPS_GPREL16
:
11980 reloc_status
= Reloc_funcs::relgprel(view
, object
, psymval
,
11981 target
->adjusted_gp_value(object
),
11982 r_addend
, extract_addend
,
11984 this->calculate_only_
,
11985 &this->calculated_value_
);
11988 case elfcpp::R_MICROMIPS_GPREL7_S2
:
11989 reloc_status
= Reloc_funcs::relgprel7(view
, object
, psymval
,
11990 target
->adjusted_gp_value(object
),
11991 r_addend
, extract_addend
,
11993 this->calculate_only_
,
11994 &this->calculated_value_
);
11997 case elfcpp::R_MIPS_PC16
:
11998 reloc_status
= Reloc_funcs::relpc16(view
, object
, psymval
, address
,
11999 r_addend
, extract_addend
,
12000 this->calculate_only_
,
12001 &this->calculated_value_
);
12004 case elfcpp::R_MIPS_PC21_S2
:
12005 reloc_status
= Reloc_funcs::relpc21(view
, object
, psymval
, address
,
12006 r_addend
, extract_addend
,
12007 this->calculate_only_
,
12008 &this->calculated_value_
);
12011 case elfcpp::R_MIPS_PC26_S2
:
12012 reloc_status
= Reloc_funcs::relpc26(view
, object
, psymval
, address
,
12013 r_addend
, extract_addend
,
12014 this->calculate_only_
,
12015 &this->calculated_value_
);
12018 case elfcpp::R_MIPS_PC18_S3
:
12019 reloc_status
= Reloc_funcs::relpc18(view
, object
, psymval
, address
,
12020 r_addend
, extract_addend
,
12021 this->calculate_only_
,
12022 &this->calculated_value_
);
12025 case elfcpp::R_MIPS_PC19_S2
:
12026 reloc_status
= Reloc_funcs::relpc19(view
, object
, psymval
, address
,
12027 r_addend
, extract_addend
,
12028 this->calculate_only_
,
12029 &this->calculated_value_
);
12032 case elfcpp::R_MIPS_PCHI16
:
12033 if (rel_type
== elfcpp::SHT_RELA
)
12034 reloc_status
= Reloc_funcs::do_relpchi16(view
, object
, psymval
,
12037 this->calculate_only_
,
12038 &this->calculated_value_
);
12039 else if (rel_type
== elfcpp::SHT_REL
)
12040 reloc_status
= Reloc_funcs::relpchi16(view
, object
, psymval
,
12041 r_addend
, address
, r_sym
,
12044 gold_unreachable();
12047 case elfcpp::R_MIPS_PCLO16
:
12048 reloc_status
= Reloc_funcs::relpclo16(view
, object
, psymval
, r_addend
,
12049 extract_addend
, address
, r_sym
,
12050 rel_type
, this->calculate_only_
,
12051 &this->calculated_value_
);
12053 case elfcpp::R_MICROMIPS_PC7_S1
:
12054 reloc_status
= Reloc_funcs::relmicromips_pc7_s1(view
, object
, psymval
,
12057 this->calculate_only_
,
12058 &this->calculated_value_
);
12060 case elfcpp::R_MICROMIPS_PC10_S1
:
12061 reloc_status
= Reloc_funcs::relmicromips_pc10_s1(view
, object
,
12063 r_addend
, extract_addend
,
12064 this->calculate_only_
,
12065 &this->calculated_value_
);
12067 case elfcpp::R_MICROMIPS_PC16_S1
:
12068 reloc_status
= Reloc_funcs::relmicromips_pc16_s1(view
, object
,
12070 r_addend
, extract_addend
,
12071 this->calculate_only_
,
12072 &this->calculated_value_
);
12074 case elfcpp::R_MIPS_GPREL32
:
12075 reloc_status
= Reloc_funcs::relgprel32(view
, object
, psymval
,
12076 target
->adjusted_gp_value(object
),
12077 r_addend
, extract_addend
,
12078 this->calculate_only_
,
12079 &this->calculated_value_
);
12081 case elfcpp::R_MIPS_GOT_HI16
:
12082 case elfcpp::R_MIPS_CALL_HI16
:
12083 case elfcpp::R_MICROMIPS_GOT_HI16
:
12084 case elfcpp::R_MICROMIPS_CALL_HI16
:
12086 got_offset
= target
->got_section()->got_offset(gsym
,
12090 got_offset
= target
->got_section()->got_offset(r_sym
,
12093 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12094 reloc_status
= Reloc_funcs::relgot_hi16(view
, gp_offset
,
12095 this->calculate_only_
,
12096 &this->calculated_value_
);
12097 update_got_entry
= changed_symbol_value
;
12100 case elfcpp::R_MIPS_GOT_LO16
:
12101 case elfcpp::R_MIPS_CALL_LO16
:
12102 case elfcpp::R_MICROMIPS_GOT_LO16
:
12103 case elfcpp::R_MICROMIPS_CALL_LO16
:
12105 got_offset
= target
->got_section()->got_offset(gsym
,
12109 got_offset
= target
->got_section()->got_offset(r_sym
,
12112 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12113 reloc_status
= Reloc_funcs::relgot_lo16(view
, gp_offset
,
12114 this->calculate_only_
,
12115 &this->calculated_value_
);
12116 update_got_entry
= changed_symbol_value
;
12119 case elfcpp::R_MIPS_GOT_DISP
:
12120 case elfcpp::R_MICROMIPS_GOT_DISP
:
12121 case elfcpp::R_MIPS_EH
:
12123 got_offset
= target
->got_section()->got_offset(gsym
,
12127 got_offset
= target
->got_section()->got_offset(r_sym
,
12130 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12131 if (eh_reloc(r_types
[i
]))
12132 reloc_status
= Reloc_funcs::releh(view
, gp_offset
,
12133 this->calculate_only_
,
12134 &this->calculated_value_
);
12136 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12137 this->calculate_only_
,
12138 &this->calculated_value_
);
12140 case elfcpp::R_MIPS_CALL16
:
12141 case elfcpp::R_MIPS16_CALL16
:
12142 case elfcpp::R_MICROMIPS_CALL16
:
12143 gold_assert(gsym
!= NULL
);
12144 got_offset
= target
->got_section()->got_offset(gsym
,
12147 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12148 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12149 this->calculate_only_
,
12150 &this->calculated_value_
);
12151 // TODO(sasa): We should also initialize update_got_entry
12152 // in other place swhere relgot is called.
12153 update_got_entry
= changed_symbol_value
;
12156 case elfcpp::R_MIPS_GOT16
:
12157 case elfcpp::R_MIPS16_GOT16
:
12158 case elfcpp::R_MICROMIPS_GOT16
:
12161 got_offset
= target
->got_section()->got_offset(gsym
,
12164 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12165 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12166 this->calculate_only_
,
12167 &this->calculated_value_
);
12171 if (rel_type
== elfcpp::SHT_RELA
)
12172 reloc_status
= Reloc_funcs::do_relgot16_local(view
, object
,
12176 this->calculate_only_
,
12177 &this->calculated_value_
);
12178 else if (rel_type
== elfcpp::SHT_REL
)
12179 reloc_status
= Reloc_funcs::relgot16_local(view
, object
,
12182 r_types
[i
], r_sym
);
12184 gold_unreachable();
12186 update_got_entry
= changed_symbol_value
;
12189 case elfcpp::R_MIPS_TLS_GD
:
12190 case elfcpp::R_MIPS16_TLS_GD
:
12191 case elfcpp::R_MICROMIPS_TLS_GD
:
12193 got_offset
= target
->got_section()->got_offset(gsym
,
12197 got_offset
= target
->got_section()->got_offset(r_sym
,
12200 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12201 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12202 this->calculate_only_
,
12203 &this->calculated_value_
);
12206 case elfcpp::R_MIPS_TLS_GOTTPREL
:
12207 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
12208 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
12210 got_offset
= target
->got_section()->got_offset(gsym
,
12211 GOT_TYPE_TLS_OFFSET
,
12214 got_offset
= target
->got_section()->got_offset(r_sym
,
12215 GOT_TYPE_TLS_OFFSET
,
12217 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12218 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12219 this->calculate_only_
,
12220 &this->calculated_value_
);
12223 case elfcpp::R_MIPS_TLS_LDM
:
12224 case elfcpp::R_MIPS16_TLS_LDM
:
12225 case elfcpp::R_MICROMIPS_TLS_LDM
:
12226 // Relocate the field with the offset of the GOT entry for
12227 // the module index.
12228 got_offset
= target
->got_section()->tls_ldm_offset(object
);
12229 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
12230 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
12231 this->calculate_only_
,
12232 &this->calculated_value_
);
12235 case elfcpp::R_MIPS_GOT_PAGE
:
12236 case elfcpp::R_MICROMIPS_GOT_PAGE
:
12237 reloc_status
= Reloc_funcs::relgotpage(target
, view
, object
, psymval
,
12238 r_addend
, extract_addend
,
12239 this->calculate_only_
,
12240 &this->calculated_value_
);
12243 case elfcpp::R_MIPS_GOT_OFST
:
12244 case elfcpp::R_MICROMIPS_GOT_OFST
:
12245 reloc_status
= Reloc_funcs::relgotofst(target
, view
, object
, psymval
,
12246 r_addend
, extract_addend
,
12247 local
, this->calculate_only_
,
12248 &this->calculated_value_
);
12251 case elfcpp::R_MIPS_JALR
:
12252 case elfcpp::R_MICROMIPS_JALR
:
12253 // This relocation is only a hint. In some cases, we optimize
12254 // it into a bal instruction. But we don't try to optimize
12255 // when the symbol does not resolve locally.
12257 || symbol_calls_local(gsym
, gsym
->has_dynsym_index()))
12258 reloc_status
= Reloc_funcs::reljalr(view
, object
, psymval
, address
,
12259 r_addend
, extract_addend
,
12260 cross_mode_jump
, r_types
[i
],
12261 target
->jalr_to_bal(),
12263 this->calculate_only_
,
12264 &this->calculated_value_
);
12267 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
12268 case elfcpp::R_MIPS16_TLS_DTPREL_HI16
:
12269 case elfcpp::R_MICROMIPS_TLS_DTPREL_HI16
:
12270 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
12271 elfcpp::DTP_OFFSET
, r_addend
,
12273 this->calculate_only_
,
12274 &this->calculated_value_
);
12276 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
12277 case elfcpp::R_MIPS16_TLS_DTPREL_LO16
:
12278 case elfcpp::R_MICROMIPS_TLS_DTPREL_LO16
:
12279 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
12280 elfcpp::DTP_OFFSET
, r_addend
,
12282 this->calculate_only_
,
12283 &this->calculated_value_
);
12285 case elfcpp::R_MIPS_TLS_DTPREL32
:
12286 case elfcpp::R_MIPS_TLS_DTPREL64
:
12287 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
12288 elfcpp::DTP_OFFSET
, r_addend
,
12290 this->calculate_only_
,
12291 &this->calculated_value_
);
12293 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
12294 case elfcpp::R_MIPS16_TLS_TPREL_HI16
:
12295 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
12296 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
12297 elfcpp::TP_OFFSET
, r_addend
,
12299 this->calculate_only_
,
12300 &this->calculated_value_
);
12302 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
12303 case elfcpp::R_MIPS16_TLS_TPREL_LO16
:
12304 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
12305 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
12306 elfcpp::TP_OFFSET
, r_addend
,
12308 this->calculate_only_
,
12309 &this->calculated_value_
);
12311 case elfcpp::R_MIPS_TLS_TPREL32
:
12312 case elfcpp::R_MIPS_TLS_TPREL64
:
12313 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
12314 elfcpp::TP_OFFSET
, r_addend
,
12316 this->calculate_only_
,
12317 &this->calculated_value_
);
12319 case elfcpp::R_MIPS_SUB
:
12320 case elfcpp::R_MICROMIPS_SUB
:
12321 reloc_status
= Reloc_funcs::relsub(view
, object
, psymval
, r_addend
,
12323 this->calculate_only_
,
12324 &this->calculated_value_
);
12326 case elfcpp::R_MIPS_HIGHER
:
12327 case elfcpp::R_MICROMIPS_HIGHER
:
12328 reloc_status
= Reloc_funcs::relhigher(view
, object
, psymval
, r_addend
,
12330 this->calculate_only_
,
12331 &this->calculated_value_
);
12333 case elfcpp::R_MIPS_HIGHEST
:
12334 case elfcpp::R_MICROMIPS_HIGHEST
:
12335 reloc_status
= Reloc_funcs::relhighest(view
, object
, psymval
,
12336 r_addend
, extract_addend
,
12337 this->calculate_only_
,
12338 &this->calculated_value_
);
12341 gold_error_at_location(relinfo
, relnum
, r_offset
,
12342 _("unsupported reloc %u"), r_types
[i
]);
12346 if (update_got_entry
)
12348 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
12349 if (mips_sym
!= NULL
&& mips_sym
->get_applied_secondary_got_fixup())
12350 got
->update_got_entry(got
->get_primary_got_offset(mips_sym
),
12351 psymval
->value(object
, 0));
12353 got
->update_got_entry(got_offset
, psymval
->value(object
, 0));
12357 bool jal_shuffle
= jal_reloc(r_type
);
12358 Reloc_funcs::mips_reloc_shuffle(view
, r_type
, jal_shuffle
);
12360 // Report any errors.
12361 switch (reloc_status
)
12363 case Reloc_funcs::STATUS_OKAY
:
12365 case Reloc_funcs::STATUS_OVERFLOW
:
12367 gold_error_at_location(relinfo
, relnum
, r_offset
,
12368 _("relocation overflow: "
12369 "%u against local symbol %u in %s"),
12370 r_type
, r_sym
, object
->name().c_str());
12371 else if (gsym
->is_defined() && gsym
->source() == Symbol::FROM_OBJECT
)
12372 gold_error_at_location(relinfo
, relnum
, r_offset
,
12373 _("relocation overflow: "
12374 "%u against '%s' defined in %s"),
12375 r_type
, gsym
->demangled_name().c_str(),
12376 gsym
->object()->name().c_str());
12378 gold_error_at_location(relinfo
, relnum
, r_offset
,
12379 _("relocation overflow: %u against '%s'"),
12380 r_type
, gsym
->demangled_name().c_str());
12382 case Reloc_funcs::STATUS_BAD_RELOC
:
12383 gold_error_at_location(relinfo
, relnum
, r_offset
,
12384 _("unexpected opcode while processing relocation"));
12386 case Reloc_funcs::STATUS_PCREL_UNALIGNED
:
12387 gold_error_at_location(relinfo
, relnum
, r_offset
,
12388 _("unaligned PC-relative relocation"));
12391 gold_unreachable();
12397 // Get the Reference_flags for a particular relocation.
12399 template<int size
, bool big_endian
>
12401 Target_mips
<size
, big_endian
>::Scan::get_reference_flags(
12402 unsigned int r_type
)
12406 case elfcpp::R_MIPS_NONE
:
12407 // No symbol reference.
12410 case elfcpp::R_MIPS_16
:
12411 case elfcpp::R_MIPS_32
:
12412 case elfcpp::R_MIPS_64
:
12413 case elfcpp::R_MIPS_HI16
:
12414 case elfcpp::R_MIPS_LO16
:
12415 case elfcpp::R_MIPS_HIGHER
:
12416 case elfcpp::R_MIPS_HIGHEST
:
12417 case elfcpp::R_MIPS16_HI16
:
12418 case elfcpp::R_MIPS16_LO16
:
12419 case elfcpp::R_MICROMIPS_HI16
:
12420 case elfcpp::R_MICROMIPS_LO16
:
12421 case elfcpp::R_MICROMIPS_HIGHER
:
12422 case elfcpp::R_MICROMIPS_HIGHEST
:
12423 return Symbol::ABSOLUTE_REF
;
12425 case elfcpp::R_MIPS_26
:
12426 case elfcpp::R_MIPS16_26
:
12427 case elfcpp::R_MICROMIPS_26_S1
:
12428 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
12430 case elfcpp::R_MIPS_PC18_S3
:
12431 case elfcpp::R_MIPS_PC19_S2
:
12432 case elfcpp::R_MIPS_PCHI16
:
12433 case elfcpp::R_MIPS_PCLO16
:
12434 case elfcpp::R_MIPS_GPREL32
:
12435 case elfcpp::R_MIPS_GPREL16
:
12436 case elfcpp::R_MIPS_REL32
:
12437 case elfcpp::R_MIPS16_GPREL
:
12438 return Symbol::RELATIVE_REF
;
12440 case elfcpp::R_MIPS_PC16
:
12441 case elfcpp::R_MIPS_PC32
:
12442 case elfcpp::R_MIPS_PC21_S2
:
12443 case elfcpp::R_MIPS_PC26_S2
:
12444 case elfcpp::R_MIPS_JALR
:
12445 case elfcpp::R_MICROMIPS_JALR
:
12446 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
12448 case elfcpp::R_MIPS_GOT16
:
12449 case elfcpp::R_MIPS_CALL16
:
12450 case elfcpp::R_MIPS_GOT_DISP
:
12451 case elfcpp::R_MIPS_GOT_HI16
:
12452 case elfcpp::R_MIPS_GOT_LO16
:
12453 case elfcpp::R_MIPS_CALL_HI16
:
12454 case elfcpp::R_MIPS_CALL_LO16
:
12455 case elfcpp::R_MIPS_LITERAL
:
12456 case elfcpp::R_MIPS_GOT_PAGE
:
12457 case elfcpp::R_MIPS_GOT_OFST
:
12458 case elfcpp::R_MIPS16_GOT16
:
12459 case elfcpp::R_MIPS16_CALL16
:
12460 case elfcpp::R_MICROMIPS_GOT16
:
12461 case elfcpp::R_MICROMIPS_CALL16
:
12462 case elfcpp::R_MICROMIPS_GOT_HI16
:
12463 case elfcpp::R_MICROMIPS_GOT_LO16
:
12464 case elfcpp::R_MICROMIPS_CALL_HI16
:
12465 case elfcpp::R_MICROMIPS_CALL_LO16
:
12466 case elfcpp::R_MIPS_EH
:
12467 // Absolute in GOT.
12468 return Symbol::RELATIVE_REF
;
12470 case elfcpp::R_MIPS_TLS_DTPMOD32
:
12471 case elfcpp::R_MIPS_TLS_DTPREL32
:
12472 case elfcpp::R_MIPS_TLS_DTPMOD64
:
12473 case elfcpp::R_MIPS_TLS_DTPREL64
:
12474 case elfcpp::R_MIPS_TLS_GD
:
12475 case elfcpp::R_MIPS_TLS_LDM
:
12476 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
12477 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
12478 case elfcpp::R_MIPS_TLS_GOTTPREL
:
12479 case elfcpp::R_MIPS_TLS_TPREL32
:
12480 case elfcpp::R_MIPS_TLS_TPREL64
:
12481 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
12482 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
12483 case elfcpp::R_MIPS16_TLS_GD
:
12484 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
12485 case elfcpp::R_MICROMIPS_TLS_GD
:
12486 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
12487 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
12488 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
12489 return Symbol::TLS_REF
;
12491 case elfcpp::R_MIPS_COPY
:
12492 case elfcpp::R_MIPS_JUMP_SLOT
:
12494 // Not expected. We will give an error later.
12499 // Report an unsupported relocation against a local symbol.
12501 template<int size
, bool big_endian
>
12503 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_local(
12504 Sized_relobj_file
<size
, big_endian
>* object
,
12505 unsigned int r_type
)
12507 gold_error(_("%s: unsupported reloc %u against local symbol"),
12508 object
->name().c_str(), r_type
);
12511 // Report an unsupported relocation against a global symbol.
12513 template<int size
, bool big_endian
>
12515 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_global(
12516 Sized_relobj_file
<size
, big_endian
>* object
,
12517 unsigned int r_type
,
12520 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
12521 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
12524 // Return printable name for ABI.
12525 template<int size
, bool big_endian
>
12527 Target_mips
<size
, big_endian
>::elf_mips_abi_name(elfcpp::Elf_Word e_flags
)
12529 switch (e_flags
& elfcpp::EF_MIPS_ABI
)
12532 if ((e_flags
& elfcpp::EF_MIPS_ABI2
) != 0)
12534 else if (size
== 64)
12538 case elfcpp::EF_MIPS_ABI_O32
:
12540 case elfcpp::EF_MIPS_ABI_O64
:
12542 case elfcpp::EF_MIPS_ABI_EABI32
:
12544 case elfcpp::EF_MIPS_ABI_EABI64
:
12547 return "unknown abi";
12551 template<int size
, bool big_endian
>
12553 Target_mips
<size
, big_endian
>::elf_mips_mach_name(elfcpp::Elf_Word e_flags
)
12555 switch (e_flags
& elfcpp::EF_MIPS_MACH
)
12557 case elfcpp::EF_MIPS_MACH_3900
:
12558 return "mips:3900";
12559 case elfcpp::EF_MIPS_MACH_4010
:
12560 return "mips:4010";
12561 case elfcpp::EF_MIPS_MACH_4100
:
12562 return "mips:4100";
12563 case elfcpp::EF_MIPS_MACH_4111
:
12564 return "mips:4111";
12565 case elfcpp::EF_MIPS_MACH_4120
:
12566 return "mips:4120";
12567 case elfcpp::EF_MIPS_MACH_4650
:
12568 return "mips:4650";
12569 case elfcpp::EF_MIPS_MACH_5400
:
12570 return "mips:5400";
12571 case elfcpp::EF_MIPS_MACH_5500
:
12572 return "mips:5500";
12573 case elfcpp::EF_MIPS_MACH_5900
:
12574 return "mips:5900";
12575 case elfcpp::EF_MIPS_MACH_SB1
:
12577 case elfcpp::EF_MIPS_MACH_9000
:
12578 return "mips:9000";
12579 case elfcpp::EF_MIPS_MACH_LS2E
:
12580 return "mips:loongson_2e";
12581 case elfcpp::EF_MIPS_MACH_LS2F
:
12582 return "mips:loongson_2f";
12583 case elfcpp::EF_MIPS_MACH_GS464
:
12584 return "mips:gs464";
12585 case elfcpp::EF_MIPS_MACH_GS464E
:
12586 return "mips:gs464e";
12587 case elfcpp::EF_MIPS_MACH_GS264E
:
12588 return "mips:gs264e";
12589 case elfcpp::EF_MIPS_MACH_OCTEON
:
12590 return "mips:octeon";
12591 case elfcpp::EF_MIPS_MACH_OCTEON2
:
12592 return "mips:octeon2";
12593 case elfcpp::EF_MIPS_MACH_OCTEON3
:
12594 return "mips:octeon3";
12595 case elfcpp::EF_MIPS_MACH_XLR
:
12598 switch (e_flags
& elfcpp::EF_MIPS_ARCH
)
12601 case elfcpp::EF_MIPS_ARCH_1
:
12602 return "mips:3000";
12604 case elfcpp::EF_MIPS_ARCH_2
:
12605 return "mips:6000";
12607 case elfcpp::EF_MIPS_ARCH_3
:
12608 return "mips:4000";
12610 case elfcpp::EF_MIPS_ARCH_4
:
12611 return "mips:8000";
12613 case elfcpp::EF_MIPS_ARCH_5
:
12614 return "mips:mips5";
12616 case elfcpp::EF_MIPS_ARCH_32
:
12617 return "mips:isa32";
12619 case elfcpp::EF_MIPS_ARCH_64
:
12620 return "mips:isa64";
12622 case elfcpp::EF_MIPS_ARCH_32R2
:
12623 return "mips:isa32r2";
12625 case elfcpp::EF_MIPS_ARCH_32R6
:
12626 return "mips:isa32r6";
12628 case elfcpp::EF_MIPS_ARCH_64R2
:
12629 return "mips:isa64r2";
12631 case elfcpp::EF_MIPS_ARCH_64R6
:
12632 return "mips:isa64r6";
12635 return "unknown CPU";
12638 template<int size
, bool big_endian
>
12639 const Target::Target_info Target_mips
<size
, big_endian
>::mips_info
=
12642 big_endian
, // is_big_endian
12643 elfcpp::EM_MIPS
, // machine_code
12644 true, // has_make_symbol
12645 false, // has_resolve
12646 false, // has_code_fill
12647 true, // is_default_stack_executable
12648 false, // can_icf_inline_merge_sections
12650 size
== 32 ? "/lib/ld.so.1" : "/lib64/ld.so.1", // dynamic_linker
12651 0x400000, // default_text_segment_address
12652 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
12653 4 * 1024, // common_pagesize (overridable by -z common-page-size)
12654 false, // isolate_execinstr
12655 0, // rosegment_gap
12656 elfcpp::SHN_UNDEF
, // small_common_shndx
12657 elfcpp::SHN_UNDEF
, // large_common_shndx
12658 0, // small_common_section_flags
12659 0, // large_common_section_flags
12660 NULL
, // attributes_section
12661 NULL
, // attributes_vendor
12662 "__start", // entry_symbol_name
12663 32, // hash_entry_size
12664 elfcpp::SHT_PROGBITS
, // unwind_section_type
12667 template<int size
, bool big_endian
>
12668 class Target_mips_nacl
: public Target_mips
<size
, big_endian
>
12672 : Target_mips
<size
, big_endian
>(&mips_nacl_info
)
12676 static const Target::Target_info mips_nacl_info
;
12679 template<int size
, bool big_endian
>
12680 const Target::Target_info Target_mips_nacl
<size
, big_endian
>::mips_nacl_info
=
12683 big_endian
, // is_big_endian
12684 elfcpp::EM_MIPS
, // machine_code
12685 true, // has_make_symbol
12686 false, // has_resolve
12687 false, // has_code_fill
12688 true, // is_default_stack_executable
12689 false, // can_icf_inline_merge_sections
12691 "/lib/ld.so.1", // dynamic_linker
12692 0x20000, // default_text_segment_address
12693 0x10000, // abi_pagesize (overridable by -z max-page-size)
12694 0x10000, // common_pagesize (overridable by -z common-page-size)
12695 true, // isolate_execinstr
12696 0x10000000, // rosegment_gap
12697 elfcpp::SHN_UNDEF
, // small_common_shndx
12698 elfcpp::SHN_UNDEF
, // large_common_shndx
12699 0, // small_common_section_flags
12700 0, // large_common_section_flags
12701 NULL
, // attributes_section
12702 NULL
, // attributes_vendor
12703 "_start", // entry_symbol_name
12704 32, // hash_entry_size
12705 elfcpp::SHT_PROGBITS
, // unwind_section_type
12708 // Target selector for Mips. Note this is never instantiated directly.
12709 // It's only used in Target_selector_mips_nacl, below.
12711 template<int size
, bool big_endian
>
12712 class Target_selector_mips
: public Target_selector
12715 Target_selector_mips()
12716 : Target_selector(elfcpp::EM_MIPS
, size
, big_endian
,
12718 (big_endian
? "elf64-tradbigmips" : "elf64-tradlittlemips") :
12719 (big_endian
? "elf32-tradbigmips" : "elf32-tradlittlemips")),
12721 (big_endian
? "elf64btsmip" : "elf64ltsmip") :
12722 (big_endian
? "elf32btsmip" : "elf32ltsmip")))
12725 Target
* do_instantiate_target()
12726 { return new Target_mips
<size
, big_endian
>(); }
12729 template<int size
, bool big_endian
>
12730 class Target_selector_mips_nacl
12731 : public Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
12732 Target_mips_nacl
<size
, big_endian
> >
12735 Target_selector_mips_nacl()
12736 : Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
12737 Target_mips_nacl
<size
, big_endian
> >(
12738 // NaCl currently supports only MIPS32 little-endian.
12739 "mipsel", "elf32-tradlittlemips-nacl", "elf32-tradlittlemips-nacl")
12743 Target_selector_mips_nacl
<32, true> target_selector_mips32
;
12744 Target_selector_mips_nacl
<32, false> target_selector_mips32el
;
12745 Target_selector_mips_nacl
<64, true> target_selector_mips64
;
12746 Target_selector_mips_nacl
<64, false> target_selector_mips64el
;
12748 } // End anonymous namespace.