1 // mips.cc -- mips target support for gold.
3 // Copyright (C) 2011-2016 Free Software Foundation, Inc.
4 // Written by Sasa Stankovic <sasa.stankovic@imgtec.com>
5 // and Aleksandar Simeonov <aleksandar.simeonov@rt-rk.com>.
6 // This file contains borrowed and adapted code from bfd/elfxx-mips.c.
8 // This file is part of gold.
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 3 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 // MA 02110-1301, USA.
33 #include "parameters.h"
40 #include "copy-relocs.h"
42 #include "target-reloc.h"
43 #include "target-select.h"
53 template<int size
, bool big_endian
>
54 class Mips_output_data_plt
;
56 template<int size
, bool big_endian
>
57 class Mips_output_data_got
;
59 template<int size
, bool big_endian
>
62 template<int size
, bool big_endian
>
63 class Mips_output_section_reginfo
;
65 template<int size
, bool big_endian
>
66 class Mips_output_data_la25_stub
;
68 template<int size
, bool big_endian
>
69 class Mips_output_data_mips_stubs
;
74 template<int size
, bool big_endian
>
77 template<int size
, bool big_endian
>
80 class Mips16_stub_section_base
;
82 template<int size
, bool big_endian
>
83 class Mips16_stub_section
;
85 // The ABI says that every symbol used by dynamic relocations must have
86 // a global GOT entry. Among other things, this provides the dynamic
87 // linker with a free, directly-indexed cache. The GOT can therefore
88 // contain symbols that are not referenced by GOT relocations themselves
89 // (in other words, it may have symbols that are not referenced by things
90 // like R_MIPS_GOT16 and R_MIPS_GOT_PAGE).
92 // GOT relocations are less likely to overflow if we put the associated
93 // GOT entries towards the beginning. We therefore divide the global
94 // GOT entries into two areas: "normal" and "reloc-only". Entries in
95 // the first area can be used for both dynamic relocations and GP-relative
96 // accesses, while those in the "reloc-only" area are for dynamic
99 // These GGA_* ("Global GOT Area") values are organised so that lower
100 // values are more general than higher values. Also, non-GGA_NONE
101 // values are ordered by the position of the area in the GOT.
110 // The types of GOT entries needed for this platform.
111 // These values are exposed to the ABI in an incremental link.
112 // Do not renumber existing values without changing the version
113 // number of the .gnu_incremental_inputs section.
116 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
117 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
118 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
120 // GOT entries for multi-GOT. We support up to 1024 GOTs in multi-GOT links.
121 GOT_TYPE_STANDARD_MULTIGOT
= 3,
122 GOT_TYPE_TLS_OFFSET_MULTIGOT
= GOT_TYPE_STANDARD_MULTIGOT
+ 1024,
123 GOT_TYPE_TLS_PAIR_MULTIGOT
= GOT_TYPE_TLS_OFFSET_MULTIGOT
+ 1024
126 // TLS type of GOT entry.
135 // Values found in the r_ssym field of a relocation entry.
136 enum Special_relocation_symbol
138 RSS_UNDEF
= 0, // None - value is zero.
139 RSS_GP
= 1, // Value of GP.
140 RSS_GP0
= 2, // Value of GP in object being relocated.
141 RSS_LOC
= 3 // Address of location being relocated.
144 // Whether the section is readonly.
146 is_readonly_section(Output_section
* output_section
)
148 elfcpp::Elf_Xword section_flags
= output_section
->flags();
149 elfcpp::Elf_Word section_type
= output_section
->type();
151 if (section_type
== elfcpp::SHT_NOBITS
)
154 if (section_flags
& elfcpp::SHF_WRITE
)
160 // Return TRUE if a relocation of type R_TYPE from OBJECT might
161 // require an la25 stub. See also local_pic_function, which determines
162 // whether the destination function ever requires a stub.
163 template<int size
, bool big_endian
>
165 relocation_needs_la25_stub(Mips_relobj
<size
, big_endian
>* object
,
166 unsigned int r_type
, bool target_is_16_bit_code
)
168 // We specifically ignore branches and jumps from EF_PIC objects,
169 // where the onus is on the compiler or programmer to perform any
170 // necessary initialization of $25. Sometimes such initialization
171 // is unnecessary; for example, -mno-shared functions do not use
172 // the incoming value of $25, and may therefore be called directly.
173 if (object
->is_pic())
178 case elfcpp::R_MIPS_26
:
179 case elfcpp::R_MIPS_PC16
:
180 case elfcpp::R_MICROMIPS_26_S1
:
181 case elfcpp::R_MICROMIPS_PC7_S1
:
182 case elfcpp::R_MICROMIPS_PC10_S1
:
183 case elfcpp::R_MICROMIPS_PC16_S1
:
184 case elfcpp::R_MICROMIPS_PC23_S2
:
187 case elfcpp::R_MIPS16_26
:
188 return !target_is_16_bit_code
;
195 // Return true if SYM is a locally-defined PIC function, in the sense
196 // that it or its fn_stub might need $25 to be valid on entry.
197 // Note that MIPS16 functions set up $gp using PC-relative instructions,
198 // so they themselves never need $25 to be valid. Only non-MIPS16
199 // entry points are of interest here.
200 template<int size
, bool big_endian
>
202 local_pic_function(Mips_symbol
<size
>* sym
)
204 bool def_regular
= (sym
->source() == Symbol::FROM_OBJECT
205 && !sym
->object()->is_dynamic()
206 && !sym
->is_undefined());
208 if (sym
->is_defined() && def_regular
)
210 Mips_relobj
<size
, big_endian
>* object
=
211 static_cast<Mips_relobj
<size
, big_endian
>*>(sym
->object());
213 if ((object
->is_pic() || sym
->is_pic())
214 && (!sym
->is_mips16()
215 || (sym
->has_mips16_fn_stub() && sym
->need_fn_stub())))
222 hi16_reloc(int r_type
)
224 return (r_type
== elfcpp::R_MIPS_HI16
225 || r_type
== elfcpp::R_MIPS16_HI16
226 || r_type
== elfcpp::R_MICROMIPS_HI16
);
230 lo16_reloc(int r_type
)
232 return (r_type
== elfcpp::R_MIPS_LO16
233 || r_type
== elfcpp::R_MIPS16_LO16
234 || r_type
== elfcpp::R_MICROMIPS_LO16
);
238 got16_reloc(unsigned int r_type
)
240 return (r_type
== elfcpp::R_MIPS_GOT16
241 || r_type
== elfcpp::R_MIPS16_GOT16
242 || r_type
== elfcpp::R_MICROMIPS_GOT16
);
246 call_lo16_reloc(unsigned int r_type
)
248 return (r_type
== elfcpp::R_MIPS_CALL_LO16
249 || r_type
== elfcpp::R_MICROMIPS_CALL_LO16
);
253 got_lo16_reloc(unsigned int r_type
)
255 return (r_type
== elfcpp::R_MIPS_GOT_LO16
256 || r_type
== elfcpp::R_MICROMIPS_GOT_LO16
);
260 eh_reloc(unsigned int r_type
)
262 return (r_type
== elfcpp::R_MIPS_EH
);
266 got_disp_reloc(unsigned int r_type
)
268 return (r_type
== elfcpp::R_MIPS_GOT_DISP
269 || r_type
== elfcpp::R_MICROMIPS_GOT_DISP
);
273 got_page_reloc(unsigned int r_type
)
275 return (r_type
== elfcpp::R_MIPS_GOT_PAGE
276 || r_type
== elfcpp::R_MICROMIPS_GOT_PAGE
);
280 tls_gd_reloc(unsigned int r_type
)
282 return (r_type
== elfcpp::R_MIPS_TLS_GD
283 || r_type
== elfcpp::R_MIPS16_TLS_GD
284 || r_type
== elfcpp::R_MICROMIPS_TLS_GD
);
288 tls_gottprel_reloc(unsigned int r_type
)
290 return (r_type
== elfcpp::R_MIPS_TLS_GOTTPREL
291 || r_type
== elfcpp::R_MIPS16_TLS_GOTTPREL
292 || r_type
== elfcpp::R_MICROMIPS_TLS_GOTTPREL
);
296 tls_ldm_reloc(unsigned int r_type
)
298 return (r_type
== elfcpp::R_MIPS_TLS_LDM
299 || r_type
== elfcpp::R_MIPS16_TLS_LDM
300 || r_type
== elfcpp::R_MICROMIPS_TLS_LDM
);
304 mips16_call_reloc(unsigned int r_type
)
306 return (r_type
== elfcpp::R_MIPS16_26
307 || r_type
== elfcpp::R_MIPS16_CALL16
);
311 jal_reloc(unsigned int r_type
)
313 return (r_type
== elfcpp::R_MIPS_26
314 || r_type
== elfcpp::R_MIPS16_26
315 || r_type
== elfcpp::R_MICROMIPS_26_S1
);
319 micromips_branch_reloc(unsigned int r_type
)
321 return (r_type
== elfcpp::R_MICROMIPS_26_S1
322 || r_type
== elfcpp::R_MICROMIPS_PC16_S1
323 || r_type
== elfcpp::R_MICROMIPS_PC10_S1
324 || r_type
== elfcpp::R_MICROMIPS_PC7_S1
);
327 // Check if R_TYPE is a MIPS16 reloc.
329 mips16_reloc(unsigned int r_type
)
333 case elfcpp::R_MIPS16_26
:
334 case elfcpp::R_MIPS16_GPREL
:
335 case elfcpp::R_MIPS16_GOT16
:
336 case elfcpp::R_MIPS16_CALL16
:
337 case elfcpp::R_MIPS16_HI16
:
338 case elfcpp::R_MIPS16_LO16
:
339 case elfcpp::R_MIPS16_TLS_GD
:
340 case elfcpp::R_MIPS16_TLS_LDM
:
341 case elfcpp::R_MIPS16_TLS_DTPREL_HI16
:
342 case elfcpp::R_MIPS16_TLS_DTPREL_LO16
:
343 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
344 case elfcpp::R_MIPS16_TLS_TPREL_HI16
:
345 case elfcpp::R_MIPS16_TLS_TPREL_LO16
:
353 // Check if R_TYPE is a microMIPS reloc.
355 micromips_reloc(unsigned int r_type
)
359 case elfcpp::R_MICROMIPS_26_S1
:
360 case elfcpp::R_MICROMIPS_HI16
:
361 case elfcpp::R_MICROMIPS_LO16
:
362 case elfcpp::R_MICROMIPS_GPREL16
:
363 case elfcpp::R_MICROMIPS_LITERAL
:
364 case elfcpp::R_MICROMIPS_GOT16
:
365 case elfcpp::R_MICROMIPS_PC7_S1
:
366 case elfcpp::R_MICROMIPS_PC10_S1
:
367 case elfcpp::R_MICROMIPS_PC16_S1
:
368 case elfcpp::R_MICROMIPS_CALL16
:
369 case elfcpp::R_MICROMIPS_GOT_DISP
:
370 case elfcpp::R_MICROMIPS_GOT_PAGE
:
371 case elfcpp::R_MICROMIPS_GOT_OFST
:
372 case elfcpp::R_MICROMIPS_GOT_HI16
:
373 case elfcpp::R_MICROMIPS_GOT_LO16
:
374 case elfcpp::R_MICROMIPS_SUB
:
375 case elfcpp::R_MICROMIPS_HIGHER
:
376 case elfcpp::R_MICROMIPS_HIGHEST
:
377 case elfcpp::R_MICROMIPS_CALL_HI16
:
378 case elfcpp::R_MICROMIPS_CALL_LO16
:
379 case elfcpp::R_MICROMIPS_SCN_DISP
:
380 case elfcpp::R_MICROMIPS_JALR
:
381 case elfcpp::R_MICROMIPS_HI0_LO16
:
382 case elfcpp::R_MICROMIPS_TLS_GD
:
383 case elfcpp::R_MICROMIPS_TLS_LDM
:
384 case elfcpp::R_MICROMIPS_TLS_DTPREL_HI16
:
385 case elfcpp::R_MICROMIPS_TLS_DTPREL_LO16
:
386 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
387 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
388 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
389 case elfcpp::R_MICROMIPS_GPREL7_S2
:
390 case elfcpp::R_MICROMIPS_PC23_S2
:
399 is_matching_lo16_reloc(unsigned int high_reloc
, unsigned int lo16_reloc
)
403 case elfcpp::R_MIPS_HI16
:
404 case elfcpp::R_MIPS_GOT16
:
405 return lo16_reloc
== elfcpp::R_MIPS_LO16
;
406 case elfcpp::R_MIPS16_HI16
:
407 case elfcpp::R_MIPS16_GOT16
:
408 return lo16_reloc
== elfcpp::R_MIPS16_LO16
;
409 case elfcpp::R_MICROMIPS_HI16
:
410 case elfcpp::R_MICROMIPS_GOT16
:
411 return lo16_reloc
== elfcpp::R_MICROMIPS_LO16
;
417 // This class is used to hold information about one GOT entry.
418 // There are three types of entry:
420 // (1) a SYMBOL + OFFSET address, where SYMBOL is local to an input object
421 // (object != NULL, symndx >= 0, tls_type != GOT_TLS_LDM)
422 // (2) a SYMBOL address, where SYMBOL is not local to an input object
423 // (sym != NULL, symndx == -1)
424 // (3) a TLS LDM slot (there's only one of these per GOT.)
425 // (object != NULL, symndx == 0, tls_type == GOT_TLS_LDM)
427 template<int size
, bool big_endian
>
430 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
433 Mips_got_entry(Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
,
434 Mips_address addend
, unsigned char tls_type
,
435 unsigned int shndx
, bool is_section_symbol
)
436 : addend_(addend
), symndx_(symndx
), tls_type_(tls_type
),
437 is_section_symbol_(is_section_symbol
), shndx_(shndx
)
438 { this->d
.object
= object
; }
440 Mips_got_entry(Mips_symbol
<size
>* sym
, unsigned char tls_type
)
441 : addend_(0), symndx_(-1U), tls_type_(tls_type
),
442 is_section_symbol_(false), shndx_(-1U)
443 { this->d
.sym
= sym
; }
445 // Return whether this entry is for a local symbol.
447 is_for_local_symbol() const
448 { return this->symndx_
!= -1U; }
450 // Return whether this entry is for a global symbol.
452 is_for_global_symbol() const
453 { return this->symndx_
== -1U; }
455 // Return the hash of this entry.
459 if (this->tls_type_
== GOT_TLS_LDM
)
460 return this->symndx_
+ (1 << 18);
462 size_t name_hash_value
= gold::string_hash
<char>(
463 (this->symndx_
!= -1U)
464 ? this->d
.object
->name().c_str()
465 : this->d
.sym
->name());
466 size_t addend
= this->addend_
;
467 return name_hash_value
^ this->symndx_
^ addend
;
470 // Return whether this entry is equal to OTHER.
472 equals(Mips_got_entry
<size
, big_endian
>* other
) const
474 if (this->tls_type_
== GOT_TLS_LDM
)
477 return ((this->tls_type_
== other
->tls_type_
)
478 && (this->symndx_
== other
->symndx_
)
479 && ((this->symndx_
!= -1U)
480 ? (this->d
.object
== other
->d
.object
)
481 : (this->d
.sym
== other
->d
.sym
))
482 && (this->addend_
== other
->addend_
));
485 // Return input object that needs this GOT entry.
486 Mips_relobj
<size
, big_endian
>*
489 gold_assert(this->symndx_
!= -1U);
490 return this->d
.object
;
493 // Return local symbol index for local GOT entries.
497 gold_assert(this->symndx_
!= -1U);
498 return this->symndx_
;
501 // Return the relocation addend for local GOT entries.
504 { return this->addend_
; }
506 // Return global symbol for global GOT entries.
510 gold_assert(this->symndx_
== -1U);
514 // Return whether this is a TLS GOT entry.
517 { return this->tls_type_
!= GOT_TLS_NONE
; }
519 // Return TLS type of this GOT entry.
522 { return this->tls_type_
; }
524 // Return section index of the local symbol for local GOT entries.
527 { return this->shndx_
; }
529 // Return whether this is a STT_SECTION symbol.
531 is_section_symbol() const
532 { return this->is_section_symbol_
; }
536 Mips_address addend_
;
538 // The index of the symbol if we have a local symbol; -1 otherwise.
539 unsigned int symndx_
;
543 // The input object for local symbols that needs the GOT entry.
544 Mips_relobj
<size
, big_endian
>* object
;
545 // If symndx == -1, the global symbol corresponding to this GOT entry. The
546 // symbol's entry is in the local area if mips_sym->global_got_area is
547 // GGA_NONE, otherwise it is in the global area.
548 Mips_symbol
<size
>* sym
;
551 // The TLS type of this GOT entry. An LDM GOT entry will be a local
552 // symbol entry with r_symndx == 0.
553 unsigned char tls_type_
;
555 // Whether this is a STT_SECTION symbol.
556 bool is_section_symbol_
;
558 // For local GOT entries, section index of the local symbol.
562 // Hash for Mips_got_entry.
564 template<int size
, bool big_endian
>
565 class Mips_got_entry_hash
569 operator()(Mips_got_entry
<size
, big_endian
>* entry
) const
570 { return entry
->hash(); }
573 // Equality for Mips_got_entry.
575 template<int size
, bool big_endian
>
576 class Mips_got_entry_eq
580 operator()(Mips_got_entry
<size
, big_endian
>* e1
,
581 Mips_got_entry
<size
, big_endian
>* e2
) const
582 { return e1
->equals(e2
); }
585 // Hash for Mips_symbol.
588 class Mips_symbol_hash
592 operator()(Mips_symbol
<size
>* sym
) const
593 { return sym
->hash(); }
596 // Got_page_range. This class describes a range of addends: [MIN_ADDEND,
597 // MAX_ADDEND]. The instances form a non-overlapping list that is sorted by
598 // increasing MIN_ADDEND.
600 struct Got_page_range
603 : next(NULL
), min_addend(0), max_addend(0)
606 Got_page_range
* next
;
610 // Return the maximum number of GOT page entries required.
613 { return (this->max_addend
- this->min_addend
+ 0x1ffff) >> 16; }
616 // Got_page_entry. This class describes the range of addends that are applied
617 // to page relocations against a given symbol.
619 struct Got_page_entry
622 : object(NULL
), symndx(-1U), ranges(NULL
), num_pages(0)
625 Got_page_entry(Object
* object_
, unsigned int symndx_
)
626 : object(object_
), symndx(symndx_
), ranges(NULL
), num_pages(0)
629 // The input object that needs the GOT page entry.
631 // The index of the symbol, as stored in the relocation r_info.
633 // The ranges for this page entry.
634 Got_page_range
* ranges
;
635 // The maximum number of page entries needed for RANGES.
636 unsigned int num_pages
;
639 // Hash for Got_page_entry.
641 struct Got_page_entry_hash
644 operator()(Got_page_entry
* entry
) const
645 { return reinterpret_cast<uintptr_t>(entry
->object
) + entry
->symndx
; }
648 // Equality for Got_page_entry.
650 struct Got_page_entry_eq
653 operator()(Got_page_entry
* entry1
, Got_page_entry
* entry2
) const
655 return entry1
->object
== entry2
->object
&& entry1
->symndx
== entry2
->symndx
;
659 // This class is used to hold .got information when linking.
661 template<int size
, bool big_endian
>
664 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
665 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
667 typedef Unordered_map
<unsigned int, unsigned int> Got_page_offsets
;
669 // Unordered set of GOT entries.
670 typedef Unordered_set
<Mips_got_entry
<size
, big_endian
>*,
671 Mips_got_entry_hash
<size
, big_endian
>,
672 Mips_got_entry_eq
<size
, big_endian
> > Got_entry_set
;
674 // Unordered set of GOT page entries.
675 typedef Unordered_set
<Got_page_entry
*,
676 Got_page_entry_hash
, Got_page_entry_eq
> Got_page_entry_set
;
678 // Unordered set of global GOT entries.
679 typedef Unordered_set
<Mips_symbol
<size
>*, Mips_symbol_hash
<size
> >
680 Global_got_entry_set
;
684 : local_gotno_(0), page_gotno_(0), global_gotno_(0), reloc_only_gotno_(0),
685 tls_gotno_(0), tls_ldm_offset_(-1U), global_got_symbols_(),
686 got_entries_(), got_page_entries_(), got_page_offset_start_(0),
687 got_page_offset_next_(0), got_page_offsets_(), next_(NULL
), index_(-1U),
691 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
692 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
694 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
695 unsigned int symndx
, Mips_address addend
,
696 unsigned int r_type
, unsigned int shndx
,
697 bool is_section_symbol
);
699 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
700 // in OBJECT. FOR_CALL is true if the caller is only interested in
701 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
704 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
705 Mips_relobj
<size
, big_endian
>* object
,
706 unsigned int r_type
, bool dyn_reloc
, bool for_call
);
708 // Add ENTRY to master GOT and to OBJECT's GOT.
710 record_got_entry(Mips_got_entry
<size
, big_endian
>* entry
,
711 Mips_relobj
<size
, big_endian
>* object
);
713 // Record that OBJECT has a page relocation against symbol SYMNDX and
714 // that ADDEND is the addend for that relocation.
716 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
717 unsigned int symndx
, int addend
);
719 // Create all entries that should be in the local part of the GOT.
721 add_local_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
723 // Create GOT page entries.
725 add_page_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
727 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
729 add_global_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
730 unsigned int non_reloc_only_global_gotno
);
732 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
734 add_reloc_only_entries(Mips_output_data_got
<size
, big_endian
>* got
);
736 // Create TLS GOT entries.
738 add_tls_entries(Target_mips
<size
, big_endian
>* target
, Layout
* layout
);
740 // Decide whether the symbol needs an entry in the global part of the primary
741 // GOT, setting global_got_area accordingly. Count the number of global
742 // symbols that are in the primary GOT only because they have dynamic
743 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
745 count_got_symbols(Symbol_table
* symtab
);
747 // Return the offset of GOT page entry for VALUE.
749 get_got_page_offset(Mips_address value
,
750 Mips_output_data_got
<size
, big_endian
>* got
);
752 // Count the number of GOT entries required.
756 // Count the number of GOT entries required by ENTRY. Accumulate the result.
758 count_got_entry(Mips_got_entry
<size
, big_endian
>* entry
);
760 // Add FROM's GOT entries.
762 add_got_entries(Mips_got_info
<size
, big_endian
>* from
);
764 // Add FROM's GOT page entries.
766 add_got_page_entries(Mips_got_info
<size
, big_endian
>* from
);
771 { return ((2 + this->local_gotno_
+ this->page_gotno_
+ this->global_gotno_
772 + this->tls_gotno_
) * size
/8);
775 // Return the number of local GOT entries.
778 { return this->local_gotno_
; }
780 // Return the maximum number of page GOT entries needed.
783 { return this->page_gotno_
; }
785 // Return the number of global GOT entries.
788 { return this->global_gotno_
; }
790 // Set the number of global GOT entries.
792 set_global_gotno(unsigned int global_gotno
)
793 { this->global_gotno_
= global_gotno
; }
795 // Return the number of GGA_RELOC_ONLY global GOT entries.
797 reloc_only_gotno() const
798 { return this->reloc_only_gotno_
; }
800 // Return the number of TLS GOT entries.
803 { return this->tls_gotno_
; }
805 // Return the GOT type for this GOT. Used for multi-GOT links only.
807 multigot_got_type(unsigned int got_type
) const
811 case GOT_TYPE_STANDARD
:
812 return GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
813 case GOT_TYPE_TLS_OFFSET
:
814 return GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
815 case GOT_TYPE_TLS_PAIR
:
816 return GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
822 // Remove lazy-binding stubs for global symbols in this GOT.
824 remove_lazy_stubs(Target_mips
<size
, big_endian
>* target
);
826 // Return offset of this GOT from the start of .got section.
829 { return this->offset_
; }
831 // Set offset of this GOT from the start of .got section.
833 set_offset(unsigned int offset
)
834 { this->offset_
= offset
; }
836 // Set index of this GOT in multi-GOT links.
838 set_index(unsigned int index
)
839 { this->index_
= index
; }
841 // Return next GOT in multi-GOT links.
842 Mips_got_info
<size
, big_endian
>*
844 { return this->next_
; }
846 // Set next GOT in multi-GOT links.
848 set_next(Mips_got_info
<size
, big_endian
>* next
)
849 { this->next_
= next
; }
851 // Return the offset of TLS LDM entry for this GOT.
853 tls_ldm_offset() const
854 { return this->tls_ldm_offset_
; }
856 // Set the offset of TLS LDM entry for this GOT.
858 set_tls_ldm_offset(unsigned int tls_ldm_offset
)
859 { this->tls_ldm_offset_
= tls_ldm_offset
; }
861 Global_got_entry_set
&
863 { return this->global_got_symbols_
; }
865 // Return the GOT_TLS_* type required by relocation type R_TYPE.
867 mips_elf_reloc_tls_type(unsigned int r_type
)
869 if (tls_gd_reloc(r_type
))
872 if (tls_ldm_reloc(r_type
))
875 if (tls_gottprel_reloc(r_type
))
881 // Return the number of GOT slots needed for GOT TLS type TYPE.
883 mips_tls_got_entries(unsigned int type
)
903 // The number of local GOT entries.
904 unsigned int local_gotno_
;
905 // The maximum number of page GOT entries needed.
906 unsigned int page_gotno_
;
907 // The number of global GOT entries.
908 unsigned int global_gotno_
;
909 // The number of global GOT entries that are in the GGA_RELOC_ONLY area.
910 unsigned int reloc_only_gotno_
;
911 // The number of TLS GOT entries.
912 unsigned int tls_gotno_
;
913 // The offset of TLS LDM entry for this GOT.
914 unsigned int tls_ldm_offset_
;
915 // All symbols that have global GOT entry.
916 Global_got_entry_set global_got_symbols_
;
917 // A hash table holding GOT entries.
918 Got_entry_set got_entries_
;
919 // A hash table of GOT page entries.
920 Got_page_entry_set got_page_entries_
;
921 // The offset of first GOT page entry for this GOT.
922 unsigned int got_page_offset_start_
;
923 // The offset of next available GOT page entry for this GOT.
924 unsigned int got_page_offset_next_
;
925 // A hash table that maps GOT page entry value to the GOT offset where
926 // the entry is located.
927 Got_page_offsets got_page_offsets_
;
928 // In multi-GOT links, a pointer to the next GOT.
929 Mips_got_info
<size
, big_endian
>* next_
;
930 // Index of this GOT in multi-GOT links.
932 // The offset of this GOT in multi-GOT links.
933 unsigned int offset_
;
936 // This is a helper class used during relocation scan. It records GOT16 addend.
938 template<int size
, bool big_endian
>
941 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
943 got16_addend(const Sized_relobj_file
<size
, big_endian
>* _object
,
944 unsigned int _shndx
, unsigned int _r_type
, unsigned int _r_sym
,
945 Mips_address _addend
)
946 : object(_object
), shndx(_shndx
), r_type(_r_type
), r_sym(_r_sym
),
950 const Sized_relobj_file
<size
, big_endian
>* object
;
957 // Mips_symbol class. Holds additional symbol information needed for Mips.
960 class Mips_symbol
: public Sized_symbol
<size
>
964 : need_fn_stub_(false), has_nonpic_branches_(false), la25_stub_offset_(-1U),
965 has_static_relocs_(false), no_lazy_stub_(false), lazy_stub_offset_(0),
966 pointer_equality_needed_(false), global_got_area_(GGA_NONE
),
967 global_gotoffset_(-1U), got_only_for_calls_(true), has_lazy_stub_(false),
968 needs_mips_plt_(false), needs_comp_plt_(false), mips_plt_offset_(-1U),
969 comp_plt_offset_(-1U), mips16_fn_stub_(NULL
), mips16_call_stub_(NULL
),
970 mips16_call_fp_stub_(NULL
), applied_secondary_got_fixup_(false)
973 // Return whether this is a MIPS16 symbol.
977 // (st_other & STO_MIPS16) == STO_MIPS16
978 return ((this->nonvis() & (elfcpp::STO_MIPS16
>> 2))
979 == elfcpp::STO_MIPS16
>> 2);
982 // Return whether this is a microMIPS symbol.
986 // (st_other & STO_MIPS_ISA) == STO_MICROMIPS
987 return ((this->nonvis() & (elfcpp::STO_MIPS_ISA
>> 2))
988 == elfcpp::STO_MICROMIPS
>> 2);
991 // Return whether the symbol needs MIPS16 fn_stub.
994 { return this->need_fn_stub_
; }
996 // Set that the symbol needs MIPS16 fn_stub.
999 { this->need_fn_stub_
= true; }
1001 // Return whether this symbol is referenced by branch relocations from
1002 // any non-PIC input file.
1004 has_nonpic_branches() const
1005 { return this->has_nonpic_branches_
; }
1007 // Set that this symbol is referenced by branch relocations from
1008 // any non-PIC input file.
1010 set_has_nonpic_branches()
1011 { this->has_nonpic_branches_
= true; }
1013 // Return the offset of the la25 stub for this symbol from the start of the
1014 // la25 stub section.
1016 la25_stub_offset() const
1017 { return this->la25_stub_offset_
; }
1019 // Set the offset of the la25 stub for this symbol from the start of the
1020 // la25 stub section.
1022 set_la25_stub_offset(unsigned int offset
)
1023 { this->la25_stub_offset_
= offset
; }
1025 // Return whether the symbol has la25 stub. This is true if this symbol is
1026 // for a PIC function, and there are non-PIC branches and jumps to it.
1028 has_la25_stub() const
1029 { return this->la25_stub_offset_
!= -1U; }
1031 // Return whether there is a relocation against this symbol that must be
1032 // resolved by the static linker (that is, the relocation cannot possibly
1033 // be made dynamic).
1035 has_static_relocs() const
1036 { return this->has_static_relocs_
; }
1038 // Set that there is a relocation against this symbol that must be resolved
1039 // by the static linker (that is, the relocation cannot possibly be made
1042 set_has_static_relocs()
1043 { this->has_static_relocs_
= true; }
1045 // Return whether we must not create a lazy-binding stub for this symbol.
1047 no_lazy_stub() const
1048 { return this->no_lazy_stub_
; }
1050 // Set that we must not create a lazy-binding stub for this symbol.
1053 { this->no_lazy_stub_
= true; }
1055 // Return the offset of the lazy-binding stub for this symbol from the start
1056 // of .MIPS.stubs section.
1058 lazy_stub_offset() const
1059 { return this->lazy_stub_offset_
; }
1061 // Set the offset of the lazy-binding stub for this symbol from the start
1062 // of .MIPS.stubs section.
1064 set_lazy_stub_offset(unsigned int offset
)
1065 { this->lazy_stub_offset_
= offset
; }
1067 // Return whether there are any relocations for this symbol where
1068 // pointer equality matters.
1070 pointer_equality_needed() const
1071 { return this->pointer_equality_needed_
; }
1073 // Set that there are relocations for this symbol where pointer equality
1076 set_pointer_equality_needed()
1077 { this->pointer_equality_needed_
= true; }
1079 // Return global GOT area where this symbol in located.
1081 global_got_area() const
1082 { return this->global_got_area_
; }
1084 // Set global GOT area where this symbol in located.
1086 set_global_got_area(Global_got_area global_got_area
)
1087 { this->global_got_area_
= global_got_area
; }
1089 // Return the global GOT offset for this symbol. For multi-GOT links, this
1090 // returns the offset from the start of .got section to the first GOT entry
1091 // for the symbol. Note that in multi-GOT links the symbol can have entry
1092 // in more than one GOT.
1094 global_gotoffset() const
1095 { return this->global_gotoffset_
; }
1097 // Set the global GOT offset for this symbol. Note that in multi-GOT links
1098 // the symbol can have entry in more than one GOT. This method will set
1099 // the offset only if it is less than current offset.
1101 set_global_gotoffset(unsigned int offset
)
1103 if (this->global_gotoffset_
== -1U || offset
< this->global_gotoffset_
)
1104 this->global_gotoffset_
= offset
;
1107 // Return whether all GOT relocations for this symbol are for calls.
1109 got_only_for_calls() const
1110 { return this->got_only_for_calls_
; }
1112 // Set that there is a GOT relocation for this symbol that is not for call.
1114 set_got_not_only_for_calls()
1115 { this->got_only_for_calls_
= false; }
1117 // Return whether this is a PIC symbol.
1121 // (st_other & STO_MIPS_FLAGS) == STO_MIPS_PIC
1122 return ((this->nonvis() & (elfcpp::STO_MIPS_FLAGS
>> 2))
1123 == (elfcpp::STO_MIPS_PIC
>> 2));
1126 // Set the flag in st_other field that marks this symbol as PIC.
1130 if (this->is_mips16())
1131 // (st_other & ~(STO_MIPS16 | STO_MIPS_FLAGS)) | STO_MIPS_PIC
1132 this->set_nonvis((this->nonvis()
1133 & ~((elfcpp::STO_MIPS16
>> 2)
1134 | (elfcpp::STO_MIPS_FLAGS
>> 2)))
1135 | (elfcpp::STO_MIPS_PIC
>> 2));
1137 // (other & ~STO_MIPS_FLAGS) | STO_MIPS_PIC
1138 this->set_nonvis((this->nonvis() & ~(elfcpp::STO_MIPS_FLAGS
>> 2))
1139 | (elfcpp::STO_MIPS_PIC
>> 2));
1142 // Set the flag in st_other field that marks this symbol as PLT.
1146 if (this->is_mips16())
1147 // (st_other & (STO_MIPS16 | ~STO_MIPS_FLAGS)) | STO_MIPS_PLT
1148 this->set_nonvis((this->nonvis()
1149 & ((elfcpp::STO_MIPS16
>> 2)
1150 | ~(elfcpp::STO_MIPS_FLAGS
>> 2)))
1151 | (elfcpp::STO_MIPS_PLT
>> 2));
1154 // (st_other & ~STO_MIPS_FLAGS) | STO_MIPS_PLT
1155 this->set_nonvis((this->nonvis() & ~(elfcpp::STO_MIPS_FLAGS
>> 2))
1156 | (elfcpp::STO_MIPS_PLT
>> 2));
1159 // Downcast a base pointer to a Mips_symbol pointer.
1160 static Mips_symbol
<size
>*
1161 as_mips_sym(Symbol
* sym
)
1162 { return static_cast<Mips_symbol
<size
>*>(sym
); }
1164 // Downcast a base pointer to a Mips_symbol pointer.
1165 static const Mips_symbol
<size
>*
1166 as_mips_sym(const Symbol
* sym
)
1167 { return static_cast<const Mips_symbol
<size
>*>(sym
); }
1169 // Return whether the symbol has lazy-binding stub.
1171 has_lazy_stub() const
1172 { return this->has_lazy_stub_
; }
1174 // Set whether the symbol has lazy-binding stub.
1176 set_has_lazy_stub(bool has_lazy_stub
)
1177 { this->has_lazy_stub_
= has_lazy_stub
; }
1179 // Return whether the symbol needs a standard PLT entry.
1181 needs_mips_plt() const
1182 { return this->needs_mips_plt_
; }
1184 // Set whether the symbol needs a standard PLT entry.
1186 set_needs_mips_plt(bool needs_mips_plt
)
1187 { this->needs_mips_plt_
= needs_mips_plt
; }
1189 // Return whether the symbol needs a compressed (MIPS16 or microMIPS) PLT
1192 needs_comp_plt() const
1193 { return this->needs_comp_plt_
; }
1195 // Set whether the symbol needs a compressed (MIPS16 or microMIPS) PLT entry.
1197 set_needs_comp_plt(bool needs_comp_plt
)
1198 { this->needs_comp_plt_
= needs_comp_plt
; }
1200 // Return standard PLT entry offset, or -1 if none.
1202 mips_plt_offset() const
1203 { return this->mips_plt_offset_
; }
1205 // Set standard PLT entry offset.
1207 set_mips_plt_offset(unsigned int mips_plt_offset
)
1208 { this->mips_plt_offset_
= mips_plt_offset
; }
1210 // Return whether the symbol has standard PLT entry.
1212 has_mips_plt_offset() const
1213 { return this->mips_plt_offset_
!= -1U; }
1215 // Return compressed (MIPS16 or microMIPS) PLT entry offset, or -1 if none.
1217 comp_plt_offset() const
1218 { return this->comp_plt_offset_
; }
1220 // Set compressed (MIPS16 or microMIPS) PLT entry offset.
1222 set_comp_plt_offset(unsigned int comp_plt_offset
)
1223 { this->comp_plt_offset_
= comp_plt_offset
; }
1225 // Return whether the symbol has compressed (MIPS16 or microMIPS) PLT entry.
1227 has_comp_plt_offset() const
1228 { return this->comp_plt_offset_
!= -1U; }
1230 // Return MIPS16 fn stub for a symbol.
1231 template<bool big_endian
>
1232 Mips16_stub_section
<size
, big_endian
>*
1233 get_mips16_fn_stub() const
1235 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(mips16_fn_stub_
);
1238 // Set MIPS16 fn stub for a symbol.
1240 set_mips16_fn_stub(Mips16_stub_section_base
* stub
)
1241 { this->mips16_fn_stub_
= stub
; }
1243 // Return whether symbol has MIPS16 fn stub.
1245 has_mips16_fn_stub() const
1246 { return this->mips16_fn_stub_
!= NULL
; }
1248 // Return MIPS16 call stub for a symbol.
1249 template<bool big_endian
>
1250 Mips16_stub_section
<size
, big_endian
>*
1251 get_mips16_call_stub() const
1253 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(
1257 // Set MIPS16 call stub for a symbol.
1259 set_mips16_call_stub(Mips16_stub_section_base
* stub
)
1260 { this->mips16_call_stub_
= stub
; }
1262 // Return whether symbol has MIPS16 call stub.
1264 has_mips16_call_stub() const
1265 { return this->mips16_call_stub_
!= NULL
; }
1267 // Return MIPS16 call_fp stub for a symbol.
1268 template<bool big_endian
>
1269 Mips16_stub_section
<size
, big_endian
>*
1270 get_mips16_call_fp_stub() const
1272 return static_cast<Mips16_stub_section
<size
, big_endian
>*>(
1273 mips16_call_fp_stub_
);
1276 // Set MIPS16 call_fp stub for a symbol.
1278 set_mips16_call_fp_stub(Mips16_stub_section_base
* stub
)
1279 { this->mips16_call_fp_stub_
= stub
; }
1281 // Return whether symbol has MIPS16 call_fp stub.
1283 has_mips16_call_fp_stub() const
1284 { return this->mips16_call_fp_stub_
!= NULL
; }
1287 get_applied_secondary_got_fixup() const
1288 { return applied_secondary_got_fixup_
; }
1291 set_applied_secondary_got_fixup()
1292 { this->applied_secondary_got_fixup_
= true; }
1294 // Return the hash of this symbol.
1298 return gold::string_hash
<char>(this->name());
1302 // Whether the symbol needs MIPS16 fn_stub. This is true if this symbol
1303 // appears in any relocs other than a 16 bit call.
1306 // True if this symbol is referenced by branch relocations from
1307 // any non-PIC input file. This is used to determine whether an
1308 // la25 stub is required.
1309 bool has_nonpic_branches_
;
1311 // The offset of the la25 stub for this symbol from the start of the
1312 // la25 stub section.
1313 unsigned int la25_stub_offset_
;
1315 // True if there is a relocation against this symbol that must be
1316 // resolved by the static linker (that is, the relocation cannot
1317 // possibly be made dynamic).
1318 bool has_static_relocs_
;
1320 // Whether we must not create a lazy-binding stub for this symbol.
1321 // This is true if the symbol has relocations related to taking the
1322 // function's address.
1325 // The offset of the lazy-binding stub for this symbol from the start of
1326 // .MIPS.stubs section.
1327 unsigned int lazy_stub_offset_
;
1329 // True if there are any relocations for this symbol where pointer equality
1331 bool pointer_equality_needed_
;
1333 // Global GOT area where this symbol in located, or GGA_NONE if symbol is not
1334 // in the global part of the GOT.
1335 Global_got_area global_got_area_
;
1337 // The global GOT offset for this symbol. For multi-GOT links, this is offset
1338 // from the start of .got section to the first GOT entry for the symbol.
1339 // Note that in multi-GOT links the symbol can have entry in more than one GOT.
1340 unsigned int global_gotoffset_
;
1342 // Whether all GOT relocations for this symbol are for calls.
1343 bool got_only_for_calls_
;
1344 // Whether the symbol has lazy-binding stub.
1345 bool has_lazy_stub_
;
1346 // Whether the symbol needs a standard PLT entry.
1347 bool needs_mips_plt_
;
1348 // Whether the symbol needs a compressed (MIPS16 or microMIPS) PLT entry.
1349 bool needs_comp_plt_
;
1350 // Standard PLT entry offset, or -1 if none.
1351 unsigned int mips_plt_offset_
;
1352 // Compressed (MIPS16 or microMIPS) PLT entry offset, or -1 if none.
1353 unsigned int comp_plt_offset_
;
1354 // MIPS16 fn stub for a symbol.
1355 Mips16_stub_section_base
* mips16_fn_stub_
;
1356 // MIPS16 call stub for a symbol.
1357 Mips16_stub_section_base
* mips16_call_stub_
;
1358 // MIPS16 call_fp stub for a symbol.
1359 Mips16_stub_section_base
* mips16_call_fp_stub_
;
1361 bool applied_secondary_got_fixup_
;
1364 // Mips16_stub_section class.
1366 // The mips16 compiler uses a couple of special sections to handle
1367 // floating point arguments.
1369 // Section names that look like .mips16.fn.FNNAME contain stubs that
1370 // copy floating point arguments from the fp regs to the gp regs and
1371 // then jump to FNNAME. If any 32 bit function calls FNNAME, the
1372 // call should be redirected to the stub instead. If no 32 bit
1373 // function calls FNNAME, the stub should be discarded. We need to
1374 // consider any reference to the function, not just a call, because
1375 // if the address of the function is taken we will need the stub,
1376 // since the address might be passed to a 32 bit function.
1378 // Section names that look like .mips16.call.FNNAME contain stubs
1379 // that copy floating point arguments from the gp regs to the fp
1380 // regs and then jump to FNNAME. If FNNAME is a 32 bit function,
1381 // then any 16 bit function that calls FNNAME should be redirected
1382 // to the stub instead. If FNNAME is not a 32 bit function, the
1383 // stub should be discarded.
1385 // .mips16.call.fp.FNNAME sections are similar, but contain stubs
1386 // which call FNNAME and then copy the return value from the fp regs
1387 // to the gp regs. These stubs store the return address in $18 while
1388 // calling FNNAME; any function which might call one of these stubs
1389 // must arrange to save $18 around the call. (This case is not
1390 // needed for 32 bit functions that call 16 bit functions, because
1391 // 16 bit functions always return floating point values in both
1392 // $f0/$f1 and $2/$3.)
1394 // Note that in all cases FNNAME might be defined statically.
1395 // Therefore, FNNAME is not used literally. Instead, the relocation
1396 // information will indicate which symbol the section is for.
1398 // We record any stubs that we find in the symbol table.
1400 // TODO(sasa): All mips16 stub sections should be emitted in the .text section.
1402 class Mips16_stub_section_base
{ };
1404 template<int size
, bool big_endian
>
1405 class Mips16_stub_section
: public Mips16_stub_section_base
1407 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1410 Mips16_stub_section(Mips_relobj
<size
, big_endian
>* object
, unsigned int shndx
)
1411 : object_(object
), shndx_(shndx
), r_sym_(0), gsym_(NULL
),
1412 found_r_mips_none_(false)
1414 gold_assert(object
->is_mips16_fn_stub_section(shndx
)
1415 || object
->is_mips16_call_stub_section(shndx
)
1416 || object
->is_mips16_call_fp_stub_section(shndx
));
1419 // Return the object of this stub section.
1420 Mips_relobj
<size
, big_endian
>*
1422 { return this->object_
; }
1424 // Return the size of a section.
1426 section_size() const
1427 { return this->object_
->section_size(this->shndx_
); }
1429 // Return section index of this stub section.
1432 { return this->shndx_
; }
1434 // Return symbol index, if stub is for a local function.
1437 { return this->r_sym_
; }
1439 // Return symbol, if stub is for a global function.
1442 { return this->gsym_
; }
1444 // Return whether stub is for a local function.
1446 is_for_local_function() const
1447 { return this->gsym_
== NULL
; }
1449 // This method is called when a new relocation R_TYPE for local symbol R_SYM
1450 // is found in the stub section. Try to find stub target.
1452 new_local_reloc_found(unsigned int r_type
, unsigned int r_sym
)
1454 // To find target symbol for this stub, trust the first R_MIPS_NONE
1455 // relocation, if any. Otherwise trust the first relocation, whatever
1457 if (this->found_r_mips_none_
)
1459 if (r_type
== elfcpp::R_MIPS_NONE
)
1461 this->r_sym_
= r_sym
;
1463 this->found_r_mips_none_
= true;
1465 else if (!is_target_found())
1466 this->r_sym_
= r_sym
;
1469 // This method is called when a new relocation R_TYPE for global symbol GSYM
1470 // is found in the stub section. Try to find stub target.
1472 new_global_reloc_found(unsigned int r_type
, Mips_symbol
<size
>* gsym
)
1474 // To find target symbol for this stub, trust the first R_MIPS_NONE
1475 // relocation, if any. Otherwise trust the first relocation, whatever
1477 if (this->found_r_mips_none_
)
1479 if (r_type
== elfcpp::R_MIPS_NONE
)
1483 this->found_r_mips_none_
= true;
1485 else if (!is_target_found())
1489 // Return whether we found the stub target.
1491 is_target_found() const
1492 { return this->r_sym_
!= 0 || this->gsym_
!= NULL
; }
1494 // Return whether this is a fn stub.
1497 { return this->object_
->is_mips16_fn_stub_section(this->shndx_
); }
1499 // Return whether this is a call stub.
1501 is_call_stub() const
1502 { return this->object_
->is_mips16_call_stub_section(this->shndx_
); }
1504 // Return whether this is a call_fp stub.
1506 is_call_fp_stub() const
1507 { return this->object_
->is_mips16_call_fp_stub_section(this->shndx_
); }
1509 // Return the output address.
1511 output_address() const
1513 return (this->object_
->output_section(this->shndx_
)->address()
1514 + this->object_
->output_section_offset(this->shndx_
));
1518 // The object of this stub section.
1519 Mips_relobj
<size
, big_endian
>* object_
;
1520 // The section index of this stub section.
1521 unsigned int shndx_
;
1522 // The symbol index, if stub is for a local function.
1523 unsigned int r_sym_
;
1524 // The symbol, if stub is for a global function.
1525 Mips_symbol
<size
>* gsym_
;
1526 // True if we found R_MIPS_NONE relocation in this stub.
1527 bool found_r_mips_none_
;
1530 // Mips_relobj class.
1532 template<int size
, bool big_endian
>
1533 class Mips_relobj
: public Sized_relobj_file
<size
, big_endian
>
1535 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1536 typedef std::map
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>
1537 Mips16_stubs_int_map
;
1538 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1541 Mips_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
1542 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1543 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
1544 processor_specific_flags_(0), local_symbol_is_mips16_(),
1545 local_symbol_is_micromips_(), mips16_stub_sections_(),
1546 local_non_16bit_calls_(), local_16bit_calls_(), local_mips16_fn_stubs_(),
1547 local_mips16_call_stubs_(), gp_(0), got_info_(NULL
),
1548 section_is_mips16_fn_stub_(), section_is_mips16_call_stub_(),
1549 section_is_mips16_call_fp_stub_(), pdr_shndx_(-1U), gprmask_(0),
1550 cprmask1_(0), cprmask2_(0), cprmask3_(0), cprmask4_(0)
1552 this->is_pic_
= (ehdr
.get_e_flags() & elfcpp::EF_MIPS_PIC
) != 0;
1553 this->is_n32_
= elfcpp::abi_n32(ehdr
.get_e_flags());
1559 // Downcast a base pointer to a Mips_relobj pointer. This is
1560 // not type-safe but we only use Mips_relobj not the base class.
1561 static Mips_relobj
<size
, big_endian
>*
1562 as_mips_relobj(Relobj
* relobj
)
1563 { return static_cast<Mips_relobj
<size
, big_endian
>*>(relobj
); }
1565 // Downcast a base pointer to a Mips_relobj pointer. This is
1566 // not type-safe but we only use Mips_relobj not the base class.
1567 static const Mips_relobj
<size
, big_endian
>*
1568 as_mips_relobj(const Relobj
* relobj
)
1569 { return static_cast<const Mips_relobj
<size
, big_endian
>*>(relobj
); }
1571 // Processor-specific flags in ELF file header. This is valid only after
1574 processor_specific_flags() const
1575 { return this->processor_specific_flags_
; }
1577 // Whether a local symbol is MIPS16 symbol. R_SYM is the symbol table
1578 // index. This is only valid after do_count_local_symbol is called.
1580 local_symbol_is_mips16(unsigned int r_sym
) const
1582 gold_assert(r_sym
< this->local_symbol_is_mips16_
.size());
1583 return this->local_symbol_is_mips16_
[r_sym
];
1586 // Whether a local symbol is microMIPS symbol. R_SYM is the symbol table
1587 // index. This is only valid after do_count_local_symbol is called.
1589 local_symbol_is_micromips(unsigned int r_sym
) const
1591 gold_assert(r_sym
< this->local_symbol_is_micromips_
.size());
1592 return this->local_symbol_is_micromips_
[r_sym
];
1595 // Get or create MIPS16 stub section.
1596 Mips16_stub_section
<size
, big_endian
>*
1597 get_mips16_stub_section(unsigned int shndx
)
1599 typename
Mips16_stubs_int_map::const_iterator it
=
1600 this->mips16_stub_sections_
.find(shndx
);
1601 if (it
!= this->mips16_stub_sections_
.end())
1602 return (*it
).second
;
1604 Mips16_stub_section
<size
, big_endian
>* stub_section
=
1605 new Mips16_stub_section
<size
, big_endian
>(this, shndx
);
1606 this->mips16_stub_sections_
.insert(
1607 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1608 stub_section
->shndx(), stub_section
));
1609 return stub_section
;
1612 // Return MIPS16 fn stub section for local symbol R_SYM, or NULL if this
1613 // object doesn't have fn stub for R_SYM.
1614 Mips16_stub_section
<size
, big_endian
>*
1615 get_local_mips16_fn_stub(unsigned int r_sym
) const
1617 typename
Mips16_stubs_int_map::const_iterator it
=
1618 this->local_mips16_fn_stubs_
.find(r_sym
);
1619 if (it
!= this->local_mips16_fn_stubs_
.end())
1620 return (*it
).second
;
1624 // Record that this object has MIPS16 fn stub for local symbol. This method
1625 // is only called if we decided not to discard the stub.
1627 add_local_mips16_fn_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1629 gold_assert(stub
->is_for_local_function());
1630 unsigned int r_sym
= stub
->r_sym();
1631 this->local_mips16_fn_stubs_
.insert(
1632 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1636 // Return MIPS16 call stub section for local symbol R_SYM, or NULL if this
1637 // object doesn't have call stub for R_SYM.
1638 Mips16_stub_section
<size
, big_endian
>*
1639 get_local_mips16_call_stub(unsigned int r_sym
) const
1641 typename
Mips16_stubs_int_map::const_iterator it
=
1642 this->local_mips16_call_stubs_
.find(r_sym
);
1643 if (it
!= this->local_mips16_call_stubs_
.end())
1644 return (*it
).second
;
1648 // Record that this object has MIPS16 call stub for local symbol. This method
1649 // is only called if we decided not to discard the stub.
1651 add_local_mips16_call_stub(Mips16_stub_section
<size
, big_endian
>* stub
)
1653 gold_assert(stub
->is_for_local_function());
1654 unsigned int r_sym
= stub
->r_sym();
1655 this->local_mips16_call_stubs_
.insert(
1656 std::pair
<unsigned int, Mips16_stub_section
<size
, big_endian
>*>(
1660 // Record that we found "non 16-bit" call relocation against local symbol
1661 // SYMNDX. This reloc would need to refer to a MIPS16 fn stub, if there
1664 add_local_non_16bit_call(unsigned int symndx
)
1665 { this->local_non_16bit_calls_
.insert(symndx
); }
1667 // Return true if there is any "non 16-bit" call relocation against local
1668 // symbol SYMNDX in this object.
1670 has_local_non_16bit_call_relocs(unsigned int symndx
)
1672 return (this->local_non_16bit_calls_
.find(symndx
)
1673 != this->local_non_16bit_calls_
.end());
1676 // Record that we found 16-bit call relocation R_MIPS16_26 against local
1677 // symbol SYMNDX. Local MIPS16 call or call_fp stubs will only be needed
1678 // if there is some R_MIPS16_26 relocation that refers to the stub symbol.
1680 add_local_16bit_call(unsigned int symndx
)
1681 { this->local_16bit_calls_
.insert(symndx
); }
1683 // Return true if there is any 16-bit call relocation R_MIPS16_26 against local
1684 // symbol SYMNDX in this object.
1686 has_local_16bit_call_relocs(unsigned int symndx
)
1688 return (this->local_16bit_calls_
.find(symndx
)
1689 != this->local_16bit_calls_
.end());
1692 // Get gp value that was used to create this object.
1695 { return this->gp_
; }
1697 // Return whether the object is a PIC object.
1700 { return this->is_pic_
; }
1702 // Return whether the object uses N32 ABI.
1705 { return this->is_n32_
; }
1707 // Return whether the object uses N64 ABI.
1710 { return size
== 64; }
1712 // Return whether the object uses NewABI conventions.
1715 { return this->is_n32() || this->is_n64(); }
1717 // Return Mips_got_info for this object.
1718 Mips_got_info
<size
, big_endian
>*
1719 get_got_info() const
1720 { return this->got_info_
; }
1722 // Return Mips_got_info for this object. Create new info if it doesn't exist.
1723 Mips_got_info
<size
, big_endian
>*
1724 get_or_create_got_info()
1726 if (!this->got_info_
)
1727 this->got_info_
= new Mips_got_info
<size
, big_endian
>();
1728 return this->got_info_
;
1731 // Set Mips_got_info for this object.
1733 set_got_info(Mips_got_info
<size
, big_endian
>* got_info
)
1734 { this->got_info_
= got_info
; }
1736 // Whether a section SHDNX is a MIPS16 stub section. This is only valid
1737 // after do_read_symbols is called.
1739 is_mips16_stub_section(unsigned int shndx
)
1741 return (is_mips16_fn_stub_section(shndx
)
1742 || is_mips16_call_stub_section(shndx
)
1743 || is_mips16_call_fp_stub_section(shndx
));
1746 // Return TRUE if relocations in section SHNDX can refer directly to a
1747 // MIPS16 function rather than to a hard-float stub. This is only valid
1748 // after do_read_symbols is called.
1750 section_allows_mips16_refs(unsigned int shndx
)
1752 return (this->is_mips16_stub_section(shndx
) || shndx
== this->pdr_shndx_
);
1755 // Whether a section SHDNX is a MIPS16 fn stub section. This is only valid
1756 // after do_read_symbols is called.
1758 is_mips16_fn_stub_section(unsigned int shndx
)
1760 gold_assert(shndx
< this->section_is_mips16_fn_stub_
.size());
1761 return this->section_is_mips16_fn_stub_
[shndx
];
1764 // Whether a section SHDNX is a MIPS16 call stub section. This is only valid
1765 // after do_read_symbols is called.
1767 is_mips16_call_stub_section(unsigned int shndx
)
1769 gold_assert(shndx
< this->section_is_mips16_call_stub_
.size());
1770 return this->section_is_mips16_call_stub_
[shndx
];
1773 // Whether a section SHDNX is a MIPS16 call_fp stub section. This is only
1774 // valid after do_read_symbols is called.
1776 is_mips16_call_fp_stub_section(unsigned int shndx
)
1778 gold_assert(shndx
< this->section_is_mips16_call_fp_stub_
.size());
1779 return this->section_is_mips16_call_fp_stub_
[shndx
];
1782 // Discard MIPS16 stub secions that are not needed.
1784 discard_mips16_stub_sections(Symbol_table
* symtab
);
1786 // Return gprmask from the .reginfo section of this object.
1789 { return this->gprmask_
; }
1791 // Return cprmask1 from the .reginfo section of this object.
1794 { return this->cprmask1_
; }
1796 // Return cprmask2 from the .reginfo section of this object.
1799 { return this->cprmask2_
; }
1801 // Return cprmask3 from the .reginfo section of this object.
1804 { return this->cprmask3_
; }
1806 // Return cprmask4 from the .reginfo section of this object.
1809 { return this->cprmask4_
; }
1812 // Count the local symbols.
1814 do_count_local_symbols(Stringpool_template
<char>*,
1815 Stringpool_template
<char>*);
1817 // Read the symbol information.
1819 do_read_symbols(Read_symbols_data
* sd
);
1822 // The name of the options section.
1823 const char* mips_elf_options_section_name()
1824 { return this->is_newabi() ? ".MIPS.options" : ".options"; }
1826 // processor-specific flags in ELF file header.
1827 elfcpp::Elf_Word processor_specific_flags_
;
1829 // Bit vector to tell if a local symbol is a MIPS16 symbol or not.
1830 // This is only valid after do_count_local_symbol is called.
1831 std::vector
<bool> local_symbol_is_mips16_
;
1833 // Bit vector to tell if a local symbol is a microMIPS symbol or not.
1834 // This is only valid after do_count_local_symbol is called.
1835 std::vector
<bool> local_symbol_is_micromips_
;
1837 // Map from section index to the MIPS16 stub for that section. This contains
1838 // all stubs found in this object.
1839 Mips16_stubs_int_map mips16_stub_sections_
;
1841 // Local symbols that have "non 16-bit" call relocation. This relocation
1842 // would need to refer to a MIPS16 fn stub, if there is one.
1843 std::set
<unsigned int> local_non_16bit_calls_
;
1845 // Local symbols that have 16-bit call relocation R_MIPS16_26. Local MIPS16
1846 // call or call_fp stubs will only be needed if there is some R_MIPS16_26
1847 // relocation that refers to the stub symbol.
1848 std::set
<unsigned int> local_16bit_calls_
;
1850 // Map from local symbol index to the MIPS16 fn stub for that symbol.
1851 // This contains only the stubs that we decided not to discard.
1852 Mips16_stubs_int_map local_mips16_fn_stubs_
;
1854 // Map from local symbol index to the MIPS16 call stub for that symbol.
1855 // This contains only the stubs that we decided not to discard.
1856 Mips16_stubs_int_map local_mips16_call_stubs_
;
1858 // gp value that was used to create this object.
1860 // Whether the object is a PIC object.
1862 // Whether the object uses N32 ABI.
1864 // The Mips_got_info for this object.
1865 Mips_got_info
<size
, big_endian
>* got_info_
;
1867 // Bit vector to tell if a section is a MIPS16 fn stub section or not.
1868 // This is only valid after do_read_symbols is called.
1869 std::vector
<bool> section_is_mips16_fn_stub_
;
1871 // Bit vector to tell if a section is a MIPS16 call stub section or not.
1872 // This is only valid after do_read_symbols is called.
1873 std::vector
<bool> section_is_mips16_call_stub_
;
1875 // Bit vector to tell if a section is a MIPS16 call_fp stub section or not.
1876 // This is only valid after do_read_symbols is called.
1877 std::vector
<bool> section_is_mips16_call_fp_stub_
;
1879 // .pdr section index.
1880 unsigned int pdr_shndx_
;
1882 // gprmask from the .reginfo section of this object.
1884 // cprmask1 from the .reginfo section of this object.
1886 // cprmask2 from the .reginfo section of this object.
1888 // cprmask3 from the .reginfo section of this object.
1890 // cprmask4 from the .reginfo section of this object.
1894 // Mips_output_data_got class.
1896 template<int size
, bool big_endian
>
1897 class Mips_output_data_got
: public Output_data_got
<size
, big_endian
>
1899 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
1900 typedef Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
1902 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1905 Mips_output_data_got(Target_mips
<size
, big_endian
>* target
,
1906 Symbol_table
* symtab
, Layout
* layout
)
1907 : Output_data_got
<size
, big_endian
>(), target_(target
),
1908 symbol_table_(symtab
), layout_(layout
), static_relocs_(), got_view_(NULL
),
1909 first_global_got_dynsym_index_(-1U), primary_got_(NULL
),
1910 secondary_got_relocs_()
1912 this->master_got_info_
= new Mips_got_info
<size
, big_endian
>();
1913 this->set_addralign(16);
1916 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
1917 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
1919 record_local_got_symbol(Mips_relobj
<size
, big_endian
>* object
,
1920 unsigned int symndx
, Mips_address addend
,
1921 unsigned int r_type
, unsigned int shndx
,
1922 bool is_section_symbol
)
1924 this->master_got_info_
->record_local_got_symbol(object
, symndx
, addend
,
1929 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
1930 // in OBJECT. FOR_CALL is true if the caller is only interested in
1931 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
1934 record_global_got_symbol(Mips_symbol
<size
>* mips_sym
,
1935 Mips_relobj
<size
, big_endian
>* object
,
1936 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
1938 this->master_got_info_
->record_global_got_symbol(mips_sym
, object
, r_type
,
1939 dyn_reloc
, for_call
);
1942 // Record that OBJECT has a page relocation against symbol SYMNDX and
1943 // that ADDEND is the addend for that relocation.
1945 record_got_page_entry(Mips_relobj
<size
, big_endian
>* object
,
1946 unsigned int symndx
, int addend
)
1947 { this->master_got_info_
->record_got_page_entry(object
, symndx
, addend
); }
1949 // Add a static entry for the GOT entry at OFFSET. GSYM is a global
1950 // symbol and R_TYPE is the code of a dynamic relocation that needs to be
1951 // applied in a static link.
1953 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
1954 Mips_symbol
<size
>* gsym
)
1955 { this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, gsym
)); }
1957 // Add a static reloc for the GOT entry at OFFSET. RELOBJ is an object
1958 // defining a local symbol with INDEX. R_TYPE is the code of a dynamic
1959 // relocation that needs to be applied in a static link.
1961 add_static_reloc(unsigned int got_offset
, unsigned int r_type
,
1962 Sized_relobj_file
<size
, big_endian
>* relobj
,
1965 this->static_relocs_
.push_back(Static_reloc(got_offset
, r_type
, relobj
,
1969 // Record that global symbol GSYM has R_TYPE dynamic relocation in the
1970 // secondary GOT at OFFSET.
1972 add_secondary_got_reloc(unsigned int got_offset
, unsigned int r_type
,
1973 Mips_symbol
<size
>* gsym
)
1975 this->secondary_got_relocs_
.push_back(Static_reloc(got_offset
,
1979 // Update GOT entry at OFFSET with VALUE.
1981 update_got_entry(unsigned int offset
, Mips_address value
)
1983 elfcpp::Swap
<size
, big_endian
>::writeval(this->got_view_
+ offset
, value
);
1986 // Return the number of entries in local part of the GOT. This includes
1987 // local entries, page entries and 2 reserved entries.
1989 get_local_gotno() const
1991 if (!this->multi_got())
1993 return (2 + this->master_got_info_
->local_gotno()
1994 + this->master_got_info_
->page_gotno());
1997 return 2 + this->primary_got_
->local_gotno() + this->primary_got_
->page_gotno();
2000 // Return dynamic symbol table index of the first symbol with global GOT
2003 first_global_got_dynsym_index() const
2004 { return this->first_global_got_dynsym_index_
; }
2006 // Set dynamic symbol table index of the first symbol with global GOT entry.
2008 set_first_global_got_dynsym_index(unsigned int index
)
2009 { this->first_global_got_dynsym_index_
= index
; }
2011 // Lay out the GOT. Add local, global and TLS entries. If GOT is
2012 // larger than 64K, create multi-GOT.
2014 lay_out_got(Layout
* layout
, Symbol_table
* symtab
,
2015 const Input_objects
* input_objects
);
2017 // Create multi-GOT. For every GOT, add local, global and TLS entries.
2019 lay_out_multi_got(Layout
* layout
, const Input_objects
* input_objects
);
2021 // Attempt to merge GOTs of different input objects.
2023 merge_gots(const Input_objects
* input_objects
);
2025 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
2026 // this would lead to overflow, true if they were merged successfully.
2028 merge_got_with(Mips_got_info
<size
, big_endian
>* from
,
2029 Mips_relobj
<size
, big_endian
>* object
,
2030 Mips_got_info
<size
, big_endian
>* to
);
2032 // Return the offset of GOT page entry for VALUE. For multi-GOT links,
2033 // use OBJECT's GOT.
2035 get_got_page_offset(Mips_address value
,
2036 const Mips_relobj
<size
, big_endian
>* object
)
2038 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2039 ? this->master_got_info_
2040 : object
->get_got_info());
2041 gold_assert(g
!= NULL
);
2042 return g
->get_got_page_offset(value
, this);
2045 // Return the GOT offset of type GOT_TYPE of the global symbol
2046 // GSYM. For multi-GOT links, use OBJECT's GOT.
2047 unsigned int got_offset(const Symbol
* gsym
, unsigned int got_type
,
2048 Mips_relobj
<size
, big_endian
>* object
) const
2050 if (!this->multi_got())
2051 return gsym
->got_offset(got_type
);
2054 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
2055 gold_assert(g
!= NULL
);
2056 return gsym
->got_offset(g
->multigot_got_type(got_type
));
2060 // Return the GOT offset of type GOT_TYPE of the local symbol
2063 got_offset(unsigned int symndx
, unsigned int got_type
,
2064 Sized_relobj_file
<size
, big_endian
>* object
,
2065 uint64_t addend
) const
2066 { return object
->local_got_offset(symndx
, got_type
, addend
); }
2068 // Return the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2070 tls_ldm_offset(Mips_relobj
<size
, big_endian
>* object
) const
2072 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2073 ? this->master_got_info_
2074 : object
->get_got_info());
2075 gold_assert(g
!= NULL
);
2076 return g
->tls_ldm_offset();
2079 // Set the offset of TLS LDM entry. For multi-GOT links, use OBJECT's GOT.
2081 set_tls_ldm_offset(unsigned int tls_ldm_offset
,
2082 Mips_relobj
<size
, big_endian
>* object
)
2084 Mips_got_info
<size
, big_endian
>* g
= (!this->multi_got()
2085 ? this->master_got_info_
2086 : object
->get_got_info());
2087 gold_assert(g
!= NULL
);
2088 g
->set_tls_ldm_offset(tls_ldm_offset
);
2091 // Return true for multi-GOT links.
2094 { return this->primary_got_
!= NULL
; }
2096 // Return the offset of OBJECT's GOT from the start of .got section.
2098 get_got_offset(const Mips_relobj
<size
, big_endian
>* object
)
2100 if (!this->multi_got())
2104 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
2105 return g
!= NULL
? g
->offset() : 0;
2109 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
2111 add_reloc_only_entries()
2112 { this->master_got_info_
->add_reloc_only_entries(this); }
2114 // Return offset of the primary GOT's entry for global symbol.
2116 get_primary_got_offset(const Mips_symbol
<size
>* sym
) const
2118 gold_assert(sym
->global_got_area() != GGA_NONE
);
2119 return (this->get_local_gotno() + sym
->dynsym_index()
2120 - this->first_global_got_dynsym_index()) * size
/8;
2123 // For the entry at offset GOT_OFFSET, return its offset from the gp.
2124 // Input argument GOT_OFFSET is always global offset from the start of
2125 // .got section, for both single and multi-GOT links.
2126 // For single GOT links, this returns GOT_OFFSET - 0x7FF0. For multi-GOT
2127 // links, the return value is object_got_offset - 0x7FF0, where
2128 // object_got_offset is offset in the OBJECT's GOT.
2130 gp_offset(unsigned int got_offset
,
2131 const Mips_relobj
<size
, big_endian
>* object
) const
2133 return (this->address() + got_offset
2134 - this->target_
->adjusted_gp_value(object
));
2138 // Write out the GOT table.
2140 do_write(Output_file
*);
2144 // This class represent dynamic relocations that need to be applied by
2145 // gold because we are using TLS relocations in a static link.
2149 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2150 Mips_symbol
<size
>* gsym
)
2151 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(true)
2152 { this->u_
.global
.symbol
= gsym
; }
2154 Static_reloc(unsigned int got_offset
, unsigned int r_type
,
2155 Sized_relobj_file
<size
, big_endian
>* relobj
, unsigned int index
)
2156 : got_offset_(got_offset
), r_type_(r_type
), symbol_is_global_(false)
2158 this->u_
.local
.relobj
= relobj
;
2159 this->u_
.local
.index
= index
;
2162 // Return the GOT offset.
2165 { return this->got_offset_
; }
2170 { return this->r_type_
; }
2172 // Whether the symbol is global or not.
2174 symbol_is_global() const
2175 { return this->symbol_is_global_
; }
2177 // For a relocation against a global symbol, the global symbol.
2181 gold_assert(this->symbol_is_global_
);
2182 return this->u_
.global
.symbol
;
2185 // For a relocation against a local symbol, the defining object.
2186 Sized_relobj_file
<size
, big_endian
>*
2189 gold_assert(!this->symbol_is_global_
);
2190 return this->u_
.local
.relobj
;
2193 // For a relocation against a local symbol, the local symbol index.
2197 gold_assert(!this->symbol_is_global_
);
2198 return this->u_
.local
.index
;
2202 // GOT offset of the entry to which this relocation is applied.
2203 unsigned int got_offset_
;
2204 // Type of relocation.
2205 unsigned int r_type_
;
2206 // Whether this relocation is against a global symbol.
2207 bool symbol_is_global_
;
2208 // A global or local symbol.
2213 // For a global symbol, the symbol itself.
2214 Mips_symbol
<size
>* symbol
;
2218 // For a local symbol, the object defining object.
2219 Sized_relobj_file
<size
, big_endian
>* relobj
;
2220 // For a local symbol, the symbol index.
2227 Target_mips
<size
, big_endian
>* target_
;
2228 // The symbol table.
2229 Symbol_table
* symbol_table_
;
2232 // Static relocs to be applied to the GOT.
2233 std::vector
<Static_reloc
> static_relocs_
;
2234 // .got section view.
2235 unsigned char* got_view_
;
2236 // The dynamic symbol table index of the first symbol with global GOT entry.
2237 unsigned int first_global_got_dynsym_index_
;
2238 // The master GOT information.
2239 Mips_got_info
<size
, big_endian
>* master_got_info_
;
2240 // The primary GOT information.
2241 Mips_got_info
<size
, big_endian
>* primary_got_
;
2242 // Secondary GOT fixups.
2243 std::vector
<Static_reloc
> secondary_got_relocs_
;
2246 // A class to handle LA25 stubs - non-PIC interface to a PIC function. There are
2247 // two ways of creating these interfaces. The first is to add:
2249 // lui $25,%hi(func)
2251 // addiu $25,$25,%lo(func)
2253 // to a separate trampoline section. The second is to add:
2255 // lui $25,%hi(func)
2256 // addiu $25,$25,%lo(func)
2258 // immediately before a PIC function "func", but only if a function is at the
2259 // beginning of the section, and the section is not too heavily aligned (i.e we
2260 // would need to add no more than 2 nops before the stub.)
2262 // We only create stubs of the first type.
2264 template<int size
, bool big_endian
>
2265 class Mips_output_data_la25_stub
: public Output_section_data
2267 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2270 Mips_output_data_la25_stub()
2271 : Output_section_data(size
== 32 ? 4 : 8), symbols_()
2274 // Create LA25 stub for a symbol.
2276 create_la25_stub(Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
2277 Mips_symbol
<size
>* gsym
);
2279 // Return output address of a stub.
2281 stub_address(const Mips_symbol
<size
>* sym
) const
2283 gold_assert(sym
->has_la25_stub());
2284 return this->address() + sym
->la25_stub_offset();
2289 do_adjust_output_section(Output_section
* os
)
2290 { os
->set_entsize(0); }
2293 // Template for standard LA25 stub.
2294 static const uint32_t la25_stub_entry
[];
2295 // Template for microMIPS LA25 stub.
2296 static const uint32_t la25_stub_micromips_entry
[];
2298 // Set the final size.
2300 set_final_data_size()
2301 { this->set_data_size(this->symbols_
.size() * 16); }
2303 // Create a symbol for SYM stub's value and size, to help make the
2304 // disassembly easier to read.
2306 create_stub_symbol(Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
2307 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
);
2309 // Write to a map file.
2311 do_print_to_mapfile(Mapfile
* mapfile
) const
2312 { mapfile
->print_output_data(this, _(".LA25.stubs")); }
2314 // Write out the LA25 stub section.
2316 do_write(Output_file
*);
2318 // Symbols that have LA25 stubs.
2319 std::vector
<Mips_symbol
<size
>*> symbols_
;
2322 // MIPS-specific relocation writer.
2324 template<int sh_type
, bool dynamic
, int size
, bool big_endian
>
2325 struct Mips_output_reloc_writer
;
2327 template<int sh_type
, bool dynamic
, bool big_endian
>
2328 struct Mips_output_reloc_writer
<sh_type
, dynamic
, 32, big_endian
>
2330 typedef Output_reloc
<sh_type
, dynamic
, 32, big_endian
> Output_reloc_type
;
2331 typedef std::vector
<Output_reloc_type
> Relocs
;
2334 write(typename
Relocs::const_iterator p
, unsigned char* pov
)
2338 template<int sh_type
, bool dynamic
, bool big_endian
>
2339 struct Mips_output_reloc_writer
<sh_type
, dynamic
, 64, big_endian
>
2341 typedef Output_reloc
<sh_type
, dynamic
, 64, big_endian
> Output_reloc_type
;
2342 typedef std::vector
<Output_reloc_type
> Relocs
;
2345 write(typename
Relocs::const_iterator p
, unsigned char* pov
)
2347 elfcpp::Mips64_rel_write
<big_endian
> orel(pov
);
2348 orel
.put_r_offset(p
->get_address());
2349 orel
.put_r_sym(p
->get_symbol_index());
2350 orel
.put_r_ssym(RSS_UNDEF
);
2351 orel
.put_r_type(p
->type());
2352 if (p
->type() == elfcpp::R_MIPS_REL32
)
2353 orel
.put_r_type2(elfcpp::R_MIPS_64
);
2355 orel
.put_r_type2(elfcpp::R_MIPS_NONE
);
2356 orel
.put_r_type3(elfcpp::R_MIPS_NONE
);
2360 template<int sh_type
, bool dynamic
, int size
, bool big_endian
>
2361 class Mips_output_data_reloc
: public Output_data_reloc
<sh_type
, dynamic
,
2365 Mips_output_data_reloc(bool sort_relocs
)
2366 : Output_data_reloc
<sh_type
, dynamic
, size
, big_endian
>(sort_relocs
)
2370 // Write out the data.
2372 do_write(Output_file
* of
)
2374 typedef Mips_output_reloc_writer
<sh_type
, dynamic
, size
,
2376 this->template do_write_generic
<Writer
>(of
);
2381 // A class to handle the PLT data.
2383 template<int size
, bool big_endian
>
2384 class Mips_output_data_plt
: public Output_section_data
2386 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2387 typedef Mips_output_data_reloc
<elfcpp::SHT_REL
, true,
2388 size
, big_endian
> Reloc_section
;
2391 // Create the PLT section. The ordinary .got section is an argument,
2392 // since we need to refer to the start.
2393 Mips_output_data_plt(Layout
* layout
, Output_data_space
* got_plt
,
2394 Target_mips
<size
, big_endian
>* target
)
2395 : Output_section_data(size
== 32 ? 4 : 8), got_plt_(got_plt
), symbols_(),
2396 plt_mips_offset_(0), plt_comp_offset_(0), plt_header_size_(0),
2399 this->rel_
= new Reloc_section(false);
2400 layout
->add_output_section_data(".rel.plt", elfcpp::SHT_REL
,
2401 elfcpp::SHF_ALLOC
, this->rel_
,
2402 ORDER_DYNAMIC_PLT_RELOCS
, false);
2405 // Add an entry to the PLT for a symbol referenced by r_type relocation.
2407 add_entry(Mips_symbol
<size
>* gsym
, unsigned int r_type
);
2409 // Return the .rel.plt section data.
2410 const Reloc_section
*
2412 { return this->rel_
; }
2414 // Return the number of PLT entries.
2417 { return this->symbols_
.size(); }
2419 // Return the offset of the first non-reserved PLT entry.
2421 first_plt_entry_offset() const
2422 { return sizeof(plt0_entry_o32
); }
2424 // Return the size of a PLT entry.
2426 plt_entry_size() const
2427 { return sizeof(plt_entry
); }
2429 // Set final PLT offsets. For each symbol, determine whether standard or
2430 // compressed (MIPS16 or microMIPS) PLT entry is used.
2434 // Return the offset of the first standard PLT entry.
2436 first_mips_plt_offset() const
2437 { return this->plt_header_size_
; }
2439 // Return the offset of the first compressed PLT entry.
2441 first_comp_plt_offset() const
2442 { return this->plt_header_size_
+ this->plt_mips_offset_
; }
2444 // Return whether there are any standard PLT entries.
2446 has_standard_entries() const
2447 { return this->plt_mips_offset_
> 0; }
2449 // Return the output address of standard PLT entry.
2451 mips_entry_address(const Mips_symbol
<size
>* sym
) const
2453 gold_assert (sym
->has_mips_plt_offset());
2454 return (this->address() + this->first_mips_plt_offset()
2455 + sym
->mips_plt_offset());
2458 // Return the output address of compressed (MIPS16 or microMIPS) PLT entry.
2460 comp_entry_address(const Mips_symbol
<size
>* sym
) const
2462 gold_assert (sym
->has_comp_plt_offset());
2463 return (this->address() + this->first_comp_plt_offset()
2464 + sym
->comp_plt_offset());
2469 do_adjust_output_section(Output_section
* os
)
2470 { os
->set_entsize(0); }
2472 // Write to a map file.
2474 do_print_to_mapfile(Mapfile
* mapfile
) const
2475 { mapfile
->print_output_data(this, _(".plt")); }
2478 // Template for the first PLT entry.
2479 static const uint32_t plt0_entry_o32
[];
2480 static const uint32_t plt0_entry_n32
[];
2481 static const uint32_t plt0_entry_n64
[];
2482 static const uint32_t plt0_entry_micromips_o32
[];
2483 static const uint32_t plt0_entry_micromips32_o32
[];
2485 // Template for subsequent PLT entries.
2486 static const uint32_t plt_entry
[];
2487 static const uint32_t plt_entry_mips16_o32
[];
2488 static const uint32_t plt_entry_micromips_o32
[];
2489 static const uint32_t plt_entry_micromips32_o32
[];
2491 // Set the final size.
2493 set_final_data_size()
2495 this->set_data_size(this->plt_header_size_
+ this->plt_mips_offset_
2496 + this->plt_comp_offset_
);
2499 // Write out the PLT data.
2501 do_write(Output_file
*);
2503 // Return whether the plt header contains microMIPS code. For the sake of
2504 // cache alignment always use a standard header whenever any standard entries
2505 // are present even if microMIPS entries are present as well. This also lets
2506 // the microMIPS header rely on the value of $v0 only set by microMIPS
2507 // entries, for a small size reduction.
2509 is_plt_header_compressed() const
2511 gold_assert(this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0);
2512 return this->target_
->is_output_micromips() && this->plt_mips_offset_
== 0;
2515 // Return the size of the PLT header.
2517 get_plt_header_size() const
2519 if (this->target_
->is_output_n64())
2520 return 4 * sizeof(plt0_entry_n64
) / sizeof(plt0_entry_n64
[0]);
2521 else if (this->target_
->is_output_n32())
2522 return 4 * sizeof(plt0_entry_n32
) / sizeof(plt0_entry_n32
[0]);
2523 else if (!this->is_plt_header_compressed())
2524 return 4 * sizeof(plt0_entry_o32
) / sizeof(plt0_entry_o32
[0]);
2525 else if (this->target_
->use_32bit_micromips_instructions())
2526 return (2 * sizeof(plt0_entry_micromips32_o32
)
2527 / sizeof(plt0_entry_micromips32_o32
[0]));
2529 return (2 * sizeof(plt0_entry_micromips_o32
)
2530 / sizeof(plt0_entry_micromips_o32
[0]));
2533 // Return the PLT header entry.
2535 get_plt_header_entry() const
2537 if (this->target_
->is_output_n64())
2538 return plt0_entry_n64
;
2539 else if (this->target_
->is_output_n32())
2540 return plt0_entry_n32
;
2541 else if (!this->is_plt_header_compressed())
2542 return plt0_entry_o32
;
2543 else if (this->target_
->use_32bit_micromips_instructions())
2544 return plt0_entry_micromips32_o32
;
2546 return plt0_entry_micromips_o32
;
2549 // Return the size of the standard PLT entry.
2551 standard_plt_entry_size() const
2552 { return 4 * sizeof(plt_entry
) / sizeof(plt_entry
[0]); }
2554 // Return the size of the compressed PLT entry.
2556 compressed_plt_entry_size() const
2558 gold_assert(!this->target_
->is_output_newabi());
2560 if (!this->target_
->is_output_micromips())
2561 return (2 * sizeof(plt_entry_mips16_o32
)
2562 / sizeof(plt_entry_mips16_o32
[0]));
2563 else if (this->target_
->use_32bit_micromips_instructions())
2564 return (2 * sizeof(plt_entry_micromips32_o32
)
2565 / sizeof(plt_entry_micromips32_o32
[0]));
2567 return (2 * sizeof(plt_entry_micromips_o32
)
2568 / sizeof(plt_entry_micromips_o32
[0]));
2571 // The reloc section.
2572 Reloc_section
* rel_
;
2573 // The .got.plt section.
2574 Output_data_space
* got_plt_
;
2575 // Symbols that have PLT entry.
2576 std::vector
<Mips_symbol
<size
>*> symbols_
;
2577 // The offset of the next standard PLT entry to create.
2578 unsigned int plt_mips_offset_
;
2579 // The offset of the next compressed PLT entry to create.
2580 unsigned int plt_comp_offset_
;
2581 // The size of the PLT header in bytes.
2582 unsigned int plt_header_size_
;
2584 Target_mips
<size
, big_endian
>* target_
;
2587 // A class to handle the .MIPS.stubs data.
2589 template<int size
, bool big_endian
>
2590 class Mips_output_data_mips_stubs
: public Output_section_data
2592 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
2594 // Unordered set of .MIPS.stubs entries.
2595 typedef Unordered_set
<Mips_symbol
<size
>*, Mips_symbol_hash
<size
> >
2596 Mips_stubs_entry_set
;
2599 Mips_output_data_mips_stubs(Target_mips
<size
, big_endian
>* target
)
2600 : Output_section_data(size
== 32 ? 4 : 8), symbols_(), dynsym_count_(-1U),
2601 stub_offsets_are_set_(false), target_(target
)
2604 // Create entry for a symbol.
2606 make_entry(Mips_symbol
<size
>*);
2608 // Remove entry for a symbol.
2610 remove_entry(Mips_symbol
<size
>* gsym
);
2612 // Set stub offsets for symbols. This method expects that the number of
2613 // entries in dynamic symbol table is set.
2615 set_lazy_stub_offsets();
2618 set_needs_dynsym_value();
2620 // Set the number of entries in dynamic symbol table.
2622 set_dynsym_count(unsigned int dynsym_count
)
2623 { this->dynsym_count_
= dynsym_count
; }
2625 // Return maximum size of the stub, ie. the stub size if the dynamic symbol
2626 // count is greater than 0x10000. If the dynamic symbol count is less than
2627 // 0x10000, the stub will be 4 bytes smaller.
2628 // There's no disadvantage from using microMIPS code here, so for the sake of
2629 // pure-microMIPS binaries we prefer it whenever there's any microMIPS code in
2630 // output produced at all. This has a benefit of stubs being shorter by
2631 // 4 bytes each too, unless in the insn32 mode.
2633 stub_max_size() const
2635 if (!this->target_
->is_output_micromips()
2636 || this->target_
->use_32bit_micromips_instructions())
2642 // Return the size of the stub. This method expects that the final dynsym
2647 gold_assert(this->dynsym_count_
!= -1U);
2648 if (this->dynsym_count_
> 0x10000)
2649 return this->stub_max_size();
2651 return this->stub_max_size() - 4;
2654 // Return output address of a stub.
2656 stub_address(const Mips_symbol
<size
>* sym
) const
2658 gold_assert(sym
->has_lazy_stub());
2659 return this->address() + sym
->lazy_stub_offset();
2664 do_adjust_output_section(Output_section
* os
)
2665 { os
->set_entsize(0); }
2667 // Write to a map file.
2669 do_print_to_mapfile(Mapfile
* mapfile
) const
2670 { mapfile
->print_output_data(this, _(".MIPS.stubs")); }
2673 static const uint32_t lazy_stub_normal_1
[];
2674 static const uint32_t lazy_stub_normal_1_n64
[];
2675 static const uint32_t lazy_stub_normal_2
[];
2676 static const uint32_t lazy_stub_normal_2_n64
[];
2677 static const uint32_t lazy_stub_big
[];
2678 static const uint32_t lazy_stub_big_n64
[];
2680 static const uint32_t lazy_stub_micromips_normal_1
[];
2681 static const uint32_t lazy_stub_micromips_normal_1_n64
[];
2682 static const uint32_t lazy_stub_micromips_normal_2
[];
2683 static const uint32_t lazy_stub_micromips_normal_2_n64
[];
2684 static const uint32_t lazy_stub_micromips_big
[];
2685 static const uint32_t lazy_stub_micromips_big_n64
[];
2687 static const uint32_t lazy_stub_micromips32_normal_1
[];
2688 static const uint32_t lazy_stub_micromips32_normal_1_n64
[];
2689 static const uint32_t lazy_stub_micromips32_normal_2
[];
2690 static const uint32_t lazy_stub_micromips32_normal_2_n64
[];
2691 static const uint32_t lazy_stub_micromips32_big
[];
2692 static const uint32_t lazy_stub_micromips32_big_n64
[];
2694 // Set the final size.
2696 set_final_data_size()
2697 { this->set_data_size(this->symbols_
.size() * this->stub_max_size()); }
2699 // Write out the .MIPS.stubs data.
2701 do_write(Output_file
*);
2703 // .MIPS.stubs symbols
2704 Mips_stubs_entry_set symbols_
;
2705 // Number of entries in dynamic symbol table.
2706 unsigned int dynsym_count_
;
2707 // Whether the stub offsets are set.
2708 bool stub_offsets_are_set_
;
2710 Target_mips
<size
, big_endian
>* target_
;
2713 // This class handles Mips .reginfo output section.
2715 template<int size
, bool big_endian
>
2716 class Mips_output_section_reginfo
: public Output_section
2718 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
2721 Mips_output_section_reginfo(const char* name
, elfcpp::Elf_Word type
,
2722 elfcpp::Elf_Xword flags
,
2723 Target_mips
<size
, big_endian
>* target
)
2724 : Output_section(name
, type
, flags
), target_(target
), gprmask_(0),
2725 cprmask1_(0), cprmask2_(0), cprmask3_(0), cprmask4_(0)
2728 // Downcast a base pointer to a Mips_output_section_reginfo pointer.
2729 static Mips_output_section_reginfo
<size
, big_endian
>*
2730 as_mips_output_section_reginfo(Output_section
* os
)
2731 { return static_cast<Mips_output_section_reginfo
<size
, big_endian
>*>(os
); }
2733 // Set masks of the output .reginfo section.
2735 set_masks(Valtype gprmask
, Valtype cprmask1
, Valtype cprmask2
,
2736 Valtype cprmask3
, Valtype cprmask4
)
2738 this->gprmask_
= gprmask
;
2739 this->cprmask1_
= cprmask1
;
2740 this->cprmask2_
= cprmask2
;
2741 this->cprmask3_
= cprmask3
;
2742 this->cprmask4_
= cprmask4
;
2746 // Set the final data size.
2748 set_final_data_size()
2749 { this->set_data_size(24); }
2751 // Write out reginfo section.
2753 do_write(Output_file
* of
);
2756 Target_mips
<size
, big_endian
>* target_
;
2758 // gprmask of the output .reginfo section.
2760 // cprmask1 of the output .reginfo section.
2762 // cprmask2 of the output .reginfo section.
2764 // cprmask3 of the output .reginfo section.
2766 // cprmask4 of the output .reginfo section.
2770 // The MIPS target has relocation types which default handling of relocatable
2771 // relocation cannot process. So we have to extend the default code.
2773 template<bool big_endian
, typename Classify_reloc
>
2774 class Mips_scan_relocatable_relocs
:
2775 public Default_scan_relocatable_relocs
<Classify_reloc
>
2778 // Return the strategy to use for a local symbol which is a section
2779 // symbol, given the relocation type.
2780 inline Relocatable_relocs::Reloc_strategy
2781 local_section_strategy(unsigned int r_type
, Relobj
* object
)
2783 if (Classify_reloc::sh_type
== elfcpp::SHT_RELA
)
2784 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
2789 case elfcpp::R_MIPS_26
:
2790 return Relocatable_relocs::RELOC_SPECIAL
;
2793 return Default_scan_relocatable_relocs
<Classify_reloc
>::
2794 local_section_strategy(r_type
, object
);
2800 // Mips_copy_relocs class. The only difference from the base class is the
2801 // method emit_mips, which should be called instead of Copy_reloc_entry::emit.
2802 // Mips cannot convert all relocation types to dynamic relocs. If a reloc
2803 // cannot be made dynamic, a COPY reloc is emitted.
2805 template<int sh_type
, int size
, bool big_endian
>
2806 class Mips_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
2810 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_MIPS_COPY
)
2813 // Emit any saved relocations which turn out to be needed. This is
2814 // called after all the relocs have been scanned.
2816 emit_mips(Output_data_reloc
<sh_type
, true, size
, big_endian
>*,
2817 Symbol_table
*, Layout
*, Target_mips
<size
, big_endian
>*);
2820 typedef typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
2823 // Emit this reloc if appropriate. This is called after we have
2824 // scanned all the relocations, so we know whether we emitted a
2825 // COPY relocation for SYM_.
2827 emit_entry(Copy_reloc_entry
& entry
,
2828 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
2829 Symbol_table
* symtab
, Layout
* layout
,
2830 Target_mips
<size
, big_endian
>* target
);
2834 // Return true if the symbol SYM should be considered to resolve local
2835 // to the current module, and false otherwise. The logic is taken from
2836 // GNU ld's method _bfd_elf_symbol_refs_local_p.
2838 symbol_refs_local(const Symbol
* sym
, bool has_dynsym_entry
,
2839 bool local_protected
)
2841 // If it's a local sym, of course we resolve locally.
2845 // STV_HIDDEN or STV_INTERNAL ones must be local.
2846 if (sym
->visibility() == elfcpp::STV_HIDDEN
2847 || sym
->visibility() == elfcpp::STV_INTERNAL
)
2850 // If we don't have a definition in a regular file, then we can't
2851 // resolve locally. The sym is either undefined or dynamic.
2852 if (sym
->source() != Symbol::FROM_OBJECT
|| sym
->object()->is_dynamic()
2853 || sym
->is_undefined())
2856 // Forced local symbols resolve locally.
2857 if (sym
->is_forced_local())
2860 // As do non-dynamic symbols.
2861 if (!has_dynsym_entry
)
2864 // At this point, we know the symbol is defined and dynamic. In an
2865 // executable it must resolve locally, likewise when building symbolic
2866 // shared libraries.
2867 if (parameters
->options().output_is_executable()
2868 || parameters
->options().Bsymbolic())
2871 // Now deal with defined dynamic symbols in shared libraries. Ones
2872 // with default visibility might not resolve locally.
2873 if (sym
->visibility() == elfcpp::STV_DEFAULT
)
2876 // STV_PROTECTED non-function symbols are local.
2877 if (sym
->type() != elfcpp::STT_FUNC
)
2880 // Function pointer equality tests may require that STV_PROTECTED
2881 // symbols be treated as dynamic symbols. If the address of a
2882 // function not defined in an executable is set to that function's
2883 // plt entry in the executable, then the address of the function in
2884 // a shared library must also be the plt entry in the executable.
2885 return local_protected
;
2888 // Return TRUE if references to this symbol always reference the symbol in this
2891 symbol_references_local(const Symbol
* sym
, bool has_dynsym_entry
)
2893 return symbol_refs_local(sym
, has_dynsym_entry
, false);
2896 // Return TRUE if calls to this symbol always call the version in this object.
2898 symbol_calls_local(const Symbol
* sym
, bool has_dynsym_entry
)
2900 return symbol_refs_local(sym
, has_dynsym_entry
, true);
2903 // Compare GOT offsets of two symbols.
2905 template<int size
, bool big_endian
>
2907 got_offset_compare(Symbol
* sym1
, Symbol
* sym2
)
2909 Mips_symbol
<size
>* mips_sym1
= Mips_symbol
<size
>::as_mips_sym(sym1
);
2910 Mips_symbol
<size
>* mips_sym2
= Mips_symbol
<size
>::as_mips_sym(sym2
);
2911 unsigned int area1
= mips_sym1
->global_got_area();
2912 unsigned int area2
= mips_sym2
->global_got_area();
2913 gold_assert(area1
!= GGA_NONE
&& area1
!= GGA_NONE
);
2915 // GGA_NORMAL entries always come before GGA_RELOC_ONLY.
2917 return area1
< area2
;
2919 return mips_sym1
->global_gotoffset() < mips_sym2
->global_gotoffset();
2922 // This method divides dynamic symbols into symbols that have GOT entry, and
2923 // symbols that don't have GOT entry. It also sorts symbols with the GOT entry.
2924 // Mips ABI requires that symbols with the GOT entry must be at the end of
2925 // dynamic symbol table, and the order in dynamic symbol table must match the
2928 template<int size
, bool big_endian
>
2930 reorder_dyn_symbols(std::vector
<Symbol
*>* dyn_symbols
,
2931 std::vector
<Symbol
*>* non_got_symbols
,
2932 std::vector
<Symbol
*>* got_symbols
)
2934 for (std::vector
<Symbol
*>::iterator p
= dyn_symbols
->begin();
2935 p
!= dyn_symbols
->end();
2938 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(*p
);
2939 if (mips_sym
->global_got_area() == GGA_NORMAL
2940 || mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
2941 got_symbols
->push_back(mips_sym
);
2943 non_got_symbols
->push_back(mips_sym
);
2946 std::sort(got_symbols
->begin(), got_symbols
->end(),
2947 got_offset_compare
<size
, big_endian
>);
2950 // Functor class for processing the global symbol table.
2952 template<int size
, bool big_endian
>
2953 class Symbol_visitor_check_symbols
2956 Symbol_visitor_check_symbols(Target_mips
<size
, big_endian
>* target
,
2957 Layout
* layout
, Symbol_table
* symtab
)
2958 : target_(target
), layout_(layout
), symtab_(symtab
)
2962 operator()(Sized_symbol
<size
>* sym
)
2964 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
2965 if (local_pic_function
<size
, big_endian
>(mips_sym
))
2967 // SYM is a function that might need $25 to be valid on entry.
2968 // If we're creating a non-PIC relocatable object, mark SYM as
2969 // being PIC. If we're creating a non-relocatable object with
2970 // non-PIC branches and jumps to SYM, make sure that SYM has an la25
2972 if (parameters
->options().relocatable())
2974 if (!parameters
->options().output_is_position_independent())
2975 mips_sym
->set_pic();
2977 else if (mips_sym
->has_nonpic_branches())
2979 this->target_
->la25_stub_section(layout_
)
2980 ->create_la25_stub(this->symtab_
, this->target_
, mips_sym
);
2986 Target_mips
<size
, big_endian
>* target_
;
2988 Symbol_table
* symtab_
;
2991 // Relocation types, parameterized by SHT_REL vs. SHT_RELA, size,
2992 // and endianness. The relocation format for MIPS-64 is non-standard.
2994 template<int sh_type
, int size
, bool big_endian
>
2995 struct Mips_reloc_types
;
2997 template<bool big_endian
>
2998 struct Mips_reloc_types
<elfcpp::SHT_REL
, 32, big_endian
>
3000 typedef typename
elfcpp::Rel
<32, big_endian
> Reloc
;
3001 typedef typename
elfcpp::Rel_write
<32, big_endian
> Reloc_write
;
3003 static typename
elfcpp::Elf_types
<32>::Elf_Swxword
3004 get_r_addend(const Reloc
*)
3008 set_reloc_addend(Reloc_write
*,
3009 typename
elfcpp::Elf_types
<32>::Elf_Swxword
)
3010 { gold_unreachable(); }
3013 template<bool big_endian
>
3014 struct Mips_reloc_types
<elfcpp::SHT_RELA
, 32, big_endian
>
3016 typedef typename
elfcpp::Rela
<32, big_endian
> Reloc
;
3017 typedef typename
elfcpp::Rela_write
<32, big_endian
> Reloc_write
;
3019 static typename
elfcpp::Elf_types
<32>::Elf_Swxword
3020 get_r_addend(const Reloc
* reloc
)
3021 { return reloc
->get_r_addend(); }
3024 set_reloc_addend(Reloc_write
* p
,
3025 typename
elfcpp::Elf_types
<32>::Elf_Swxword val
)
3026 { p
->put_r_addend(val
); }
3029 template<bool big_endian
>
3030 struct Mips_reloc_types
<elfcpp::SHT_REL
, 64, big_endian
>
3032 typedef typename
elfcpp::Mips64_rel
<big_endian
> Reloc
;
3033 typedef typename
elfcpp::Mips64_rel_write
<big_endian
> Reloc_write
;
3035 static typename
elfcpp::Elf_types
<64>::Elf_Swxword
3036 get_r_addend(const Reloc
*)
3040 set_reloc_addend(Reloc_write
*,
3041 typename
elfcpp::Elf_types
<64>::Elf_Swxword
)
3042 { gold_unreachable(); }
3045 template<bool big_endian
>
3046 struct Mips_reloc_types
<elfcpp::SHT_RELA
, 64, big_endian
>
3048 typedef typename
elfcpp::Mips64_rela
<big_endian
> Reloc
;
3049 typedef typename
elfcpp::Mips64_rela_write
<big_endian
> Reloc_write
;
3051 static typename
elfcpp::Elf_types
<64>::Elf_Swxword
3052 get_r_addend(const Reloc
* reloc
)
3053 { return reloc
->get_r_addend(); }
3056 set_reloc_addend(Reloc_write
* p
,
3057 typename
elfcpp::Elf_types
<64>::Elf_Swxword val
)
3058 { p
->put_r_addend(val
); }
3061 // Forward declaration.
3063 mips_get_size_for_reloc(unsigned int, Relobj
*);
3065 // A class for inquiring about properties of a relocation,
3066 // used while scanning relocs during a relocatable link and
3067 // garbage collection.
3069 template<int sh_type_
, int size
, bool big_endian
>
3070 class Mips_classify_reloc
;
3072 template<int sh_type_
, bool big_endian
>
3073 class Mips_classify_reloc
<sh_type_
, 32, big_endian
> :
3074 public gold::Default_classify_reloc
<sh_type_
, 32, big_endian
>
3077 typedef typename Mips_reloc_types
<sh_type_
, 32, big_endian
>::Reloc
3079 typedef typename Mips_reloc_types
<sh_type_
, 32, big_endian
>::Reloc_write
3082 // Return the symbol referred to by the relocation.
3083 static inline unsigned int
3084 get_r_sym(const Reltype
* reloc
)
3085 { return elfcpp::elf_r_sym
<32>(reloc
->get_r_info()); }
3087 // Return the type of the relocation.
3088 static inline unsigned int
3089 get_r_type(const Reltype
* reloc
)
3090 { return elfcpp::elf_r_type
<32>(reloc
->get_r_info()); }
3092 static inline unsigned int
3093 get_r_type2(const Reltype
*)
3096 static inline unsigned int
3097 get_r_type3(const Reltype
*)
3100 static inline unsigned int
3101 get_r_ssym(const Reltype
*)
3104 // Return the explicit addend of the relocation (return 0 for SHT_REL).
3105 static inline unsigned int
3106 get_r_addend(const Reltype
* reloc
)
3108 if (sh_type_
== elfcpp::SHT_REL
)
3110 return Mips_reloc_types
<sh_type_
, 32, big_endian
>::get_r_addend(reloc
);
3113 // Write the r_info field to a new reloc, using the r_info field from
3114 // the original reloc, replacing the r_sym field with R_SYM.
3116 put_r_info(Reltype_write
* new_reloc
, Reltype
* reloc
, unsigned int r_sym
)
3118 unsigned int r_type
= elfcpp::elf_r_type
<32>(reloc
->get_r_info());
3119 new_reloc
->put_r_info(elfcpp::elf_r_info
<32>(r_sym
, r_type
));
3122 // Write the r_addend field to a new reloc.
3124 put_r_addend(Reltype_write
* to
,
3125 typename
elfcpp::Elf_types
<32>::Elf_Swxword addend
)
3126 { Mips_reloc_types
<sh_type_
, 32, big_endian
>::set_reloc_addend(to
, addend
); }
3128 // Return the size of the addend of the relocation (only used for SHT_REL).
3130 get_size_for_reloc(unsigned int r_type
, Relobj
* obj
)
3131 { return mips_get_size_for_reloc(r_type
, obj
); }
3134 template<int sh_type_
, bool big_endian
>
3135 class Mips_classify_reloc
<sh_type_
, 64, big_endian
> :
3136 public gold::Default_classify_reloc
<sh_type_
, 64, big_endian
>
3139 typedef typename Mips_reloc_types
<sh_type_
, 64, big_endian
>::Reloc
3141 typedef typename Mips_reloc_types
<sh_type_
, 64, big_endian
>::Reloc_write
3144 // Return the symbol referred to by the relocation.
3145 static inline unsigned int
3146 get_r_sym(const Reltype
* reloc
)
3147 { return reloc
->get_r_sym(); }
3149 // Return the r_type of the relocation.
3150 static inline unsigned int
3151 get_r_type(const Reltype
* reloc
)
3152 { return reloc
->get_r_type(); }
3154 // Return the r_type2 of the relocation.
3155 static inline unsigned int
3156 get_r_type2(const Reltype
* reloc
)
3157 { return reloc
->get_r_type2(); }
3159 // Return the r_type3 of the relocation.
3160 static inline unsigned int
3161 get_r_type3(const Reltype
* reloc
)
3162 { return reloc
->get_r_type3(); }
3164 // Return the special symbol of the relocation.
3165 static inline unsigned int
3166 get_r_ssym(const Reltype
* reloc
)
3167 { return reloc
->get_r_ssym(); }
3169 // Return the explicit addend of the relocation (return 0 for SHT_REL).
3170 static inline typename
elfcpp::Elf_types
<64>::Elf_Swxword
3171 get_r_addend(const Reltype
* reloc
)
3173 if (sh_type_
== elfcpp::SHT_REL
)
3175 return Mips_reloc_types
<sh_type_
, 64, big_endian
>::get_r_addend(reloc
);
3178 // Write the r_info field to a new reloc, using the r_info field from
3179 // the original reloc, replacing the r_sym field with R_SYM.
3181 put_r_info(Reltype_write
* new_reloc
, Reltype
* reloc
, unsigned int r_sym
)
3183 new_reloc
->put_r_sym(r_sym
);
3184 new_reloc
->put_r_ssym(reloc
->get_r_ssym());
3185 new_reloc
->put_r_type3(reloc
->get_r_type3());
3186 new_reloc
->put_r_type2(reloc
->get_r_type2());
3187 new_reloc
->put_r_type(reloc
->get_r_type());
3190 // Write the r_addend field to a new reloc.
3192 put_r_addend(Reltype_write
* to
,
3193 typename
elfcpp::Elf_types
<64>::Elf_Swxword addend
)
3194 { Mips_reloc_types
<sh_type_
, 64, big_endian
>::set_reloc_addend(to
, addend
); }
3196 // Return the size of the addend of the relocation (only used for SHT_REL).
3198 get_size_for_reloc(unsigned int r_type
, Relobj
* obj
)
3199 { return mips_get_size_for_reloc(r_type
, obj
); }
3202 template<int size
, bool big_endian
>
3203 class Target_mips
: public Sized_target
<size
, big_endian
>
3205 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
3206 typedef Mips_output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>
3208 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
3209 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
3210 typedef typename Mips_reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
3212 typedef typename Mips_reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
3216 Target_mips(const Target::Target_info
* info
= &mips_info
)
3217 : Sized_target
<size
, big_endian
>(info
), got_(NULL
), gp_(NULL
), plt_(NULL
),
3218 got_plt_(NULL
), rel_dyn_(NULL
), copy_relocs_(),
3219 dyn_relocs_(), la25_stub_(NULL
), mips_mach_extensions_(),
3220 mips_stubs_(NULL
), mach_(0), layout_(NULL
), got16_addends_(),
3221 entry_symbol_is_compressed_(false), insn32_(false)
3223 this->add_machine_extensions();
3226 // The offset of $gp from the beginning of the .got section.
3227 static const unsigned int MIPS_GP_OFFSET
= 0x7ff0;
3229 // The maximum size of the GOT for it to be addressable using 16-bit
3230 // offsets from $gp.
3231 static const unsigned int MIPS_GOT_MAX_SIZE
= MIPS_GP_OFFSET
+ 0x7fff;
3233 // Make a new symbol table entry for the Mips target.
3235 make_symbol(const char*, elfcpp::STT
, Object
*, unsigned int, uint64_t)
3236 { return new Mips_symbol
<size
>(); }
3238 // Process the relocations to determine unreferenced sections for
3239 // garbage collection.
3241 gc_process_relocs(Symbol_table
* symtab
,
3243 Sized_relobj_file
<size
, big_endian
>* object
,
3244 unsigned int data_shndx
,
3245 unsigned int sh_type
,
3246 const unsigned char* prelocs
,
3248 Output_section
* output_section
,
3249 bool needs_special_offset_handling
,
3250 size_t local_symbol_count
,
3251 const unsigned char* plocal_symbols
);
3253 // Scan the relocations to look for symbol adjustments.
3255 scan_relocs(Symbol_table
* symtab
,
3257 Sized_relobj_file
<size
, big_endian
>* object
,
3258 unsigned int data_shndx
,
3259 unsigned int sh_type
,
3260 const unsigned char* prelocs
,
3262 Output_section
* output_section
,
3263 bool needs_special_offset_handling
,
3264 size_t local_symbol_count
,
3265 const unsigned char* plocal_symbols
);
3267 // Finalize the sections.
3269 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
3271 // Relocate a section.
3273 relocate_section(const Relocate_info
<size
, big_endian
>*,
3274 unsigned int sh_type
,
3275 const unsigned char* prelocs
,
3277 Output_section
* output_section
,
3278 bool needs_special_offset_handling
,
3279 unsigned char* view
,
3280 Mips_address view_address
,
3281 section_size_type view_size
,
3282 const Reloc_symbol_changes
*);
3284 // Scan the relocs during a relocatable link.
3286 scan_relocatable_relocs(Symbol_table
* symtab
,
3288 Sized_relobj_file
<size
, big_endian
>* object
,
3289 unsigned int data_shndx
,
3290 unsigned int sh_type
,
3291 const unsigned char* prelocs
,
3293 Output_section
* output_section
,
3294 bool needs_special_offset_handling
,
3295 size_t local_symbol_count
,
3296 const unsigned char* plocal_symbols
,
3297 Relocatable_relocs
*);
3299 // Scan the relocs for --emit-relocs.
3301 emit_relocs_scan(Symbol_table
* symtab
,
3303 Sized_relobj_file
<size
, big_endian
>* object
,
3304 unsigned int data_shndx
,
3305 unsigned int sh_type
,
3306 const unsigned char* prelocs
,
3308 Output_section
* output_section
,
3309 bool needs_special_offset_handling
,
3310 size_t local_symbol_count
,
3311 const unsigned char* plocal_syms
,
3312 Relocatable_relocs
* rr
);
3314 // Emit relocations for a section.
3316 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
3317 unsigned int sh_type
,
3318 const unsigned char* prelocs
,
3320 Output_section
* output_section
,
3321 typename
elfcpp::Elf_types
<size
>::Elf_Off
3322 offset_in_output_section
,
3323 unsigned char* view
,
3324 Mips_address view_address
,
3325 section_size_type view_size
,
3326 unsigned char* reloc_view
,
3327 section_size_type reloc_view_size
);
3329 // Perform target-specific processing in a relocatable link. This is
3330 // only used if we use the relocation strategy RELOC_SPECIAL.
3332 relocate_special_relocatable(const Relocate_info
<size
, big_endian
>* relinfo
,
3333 unsigned int sh_type
,
3334 const unsigned char* preloc_in
,
3336 Output_section
* output_section
,
3337 typename
elfcpp::Elf_types
<size
>::Elf_Off
3338 offset_in_output_section
,
3339 unsigned char* view
,
3340 Mips_address view_address
,
3341 section_size_type view_size
,
3342 unsigned char* preloc_out
);
3344 // Return whether SYM is defined by the ABI.
3346 do_is_defined_by_abi(const Symbol
* sym
) const
3348 return ((strcmp(sym
->name(), "__gnu_local_gp") == 0)
3349 || (strcmp(sym
->name(), "_gp_disp") == 0)
3350 || (strcmp(sym
->name(), "___tls_get_addr") == 0));
3353 // Return the number of entries in the GOT.
3355 got_entry_count() const
3357 if (!this->has_got_section())
3359 return this->got_size() / (size
/8);
3362 // Return the number of entries in the PLT.
3364 plt_entry_count() const
3366 if (this->plt_
== NULL
)
3368 return this->plt_
->entry_count();
3371 // Return the offset of the first non-reserved PLT entry.
3373 first_plt_entry_offset() const
3374 { return this->plt_
->first_plt_entry_offset(); }
3376 // Return the size of each PLT entry.
3378 plt_entry_size() const
3379 { return this->plt_
->plt_entry_size(); }
3381 // Get the GOT section, creating it if necessary.
3382 Mips_output_data_got
<size
, big_endian
>*
3383 got_section(Symbol_table
*, Layout
*);
3385 // Get the GOT section.
3386 Mips_output_data_got
<size
, big_endian
>*
3389 gold_assert(this->got_
!= NULL
);
3393 // Get the .MIPS.stubs section, creating it if necessary.
3394 Mips_output_data_mips_stubs
<size
, big_endian
>*
3395 mips_stubs_section(Layout
* layout
);
3397 // Get the .MIPS.stubs section.
3398 Mips_output_data_mips_stubs
<size
, big_endian
>*
3399 mips_stubs_section() const
3401 gold_assert(this->mips_stubs_
!= NULL
);
3402 return this->mips_stubs_
;
3405 // Get the LA25 stub section, creating it if necessary.
3406 Mips_output_data_la25_stub
<size
, big_endian
>*
3407 la25_stub_section(Layout
*);
3409 // Get the LA25 stub section.
3410 Mips_output_data_la25_stub
<size
, big_endian
>*
3413 gold_assert(this->la25_stub_
!= NULL
);
3414 return this->la25_stub_
;
3417 // Get gp value. It has the value of .got + 0x7FF0.
3421 if (this->gp_
!= NULL
)
3422 return this->gp_
->value();
3426 // Get gp value. It has the value of .got + 0x7FF0. Adjust it for
3427 // multi-GOT links so that OBJECT's GOT + 0x7FF0 is returned.
3429 adjusted_gp_value(const Mips_relobj
<size
, big_endian
>* object
)
3431 if (this->gp_
== NULL
)
3434 bool multi_got
= false;
3435 if (this->has_got_section())
3436 multi_got
= this->got_section()->multi_got();
3438 return this->gp_
->value();
3440 return this->gp_
->value() + this->got_section()->get_got_offset(object
);
3443 // Get the dynamic reloc section, creating it if necessary.
3445 rel_dyn_section(Layout
*);
3448 do_has_custom_set_dynsym_indexes() const
3451 // Don't emit input .reginfo sections to output .reginfo.
3453 do_should_include_section(elfcpp::Elf_Word sh_type
) const
3454 { return sh_type
!= elfcpp::SHT_MIPS_REGINFO
; }
3456 // Set the dynamic symbol indexes. INDEX is the index of the first
3457 // global dynamic symbol. Pointers to the symbols are stored into the
3458 // vector SYMS. The names are added to DYNPOOL. This returns an
3459 // updated dynamic symbol index.
3461 do_set_dynsym_indexes(std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
3462 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
3463 Versions
* versions
, Symbol_table
* symtab
) const;
3465 // Remove .MIPS.stubs entry for a symbol.
3467 remove_lazy_stub_entry(Mips_symbol
<size
>* sym
)
3469 if (this->mips_stubs_
!= NULL
)
3470 this->mips_stubs_
->remove_entry(sym
);
3473 // The value to write into got[1] for SVR4 targets, to identify it is
3474 // a GNU object. The dynamic linker can then use got[1] to store the
3477 mips_elf_gnu_got1_mask()
3479 if (this->is_output_n64())
3480 return (uint64_t)1 << 63;
3485 // Whether the output has microMIPS code. This is valid only after
3486 // merge_processor_specific_flags() is called.
3488 is_output_micromips() const
3490 gold_assert(this->are_processor_specific_flags_set());
3491 return elfcpp::is_micromips(this->processor_specific_flags());
3494 // Whether the output uses N32 ABI. This is valid only after
3495 // merge_processor_specific_flags() is called.
3497 is_output_n32() const
3499 gold_assert(this->are_processor_specific_flags_set());
3500 return elfcpp::abi_n32(this->processor_specific_flags());
3503 // Whether the output uses N64 ABI.
3505 is_output_n64() const
3506 { return size
== 64; }
3508 // Whether the output uses NEWABI. This is valid only after
3509 // merge_processor_specific_flags() is called.
3511 is_output_newabi() const
3512 { return this->is_output_n32() || this->is_output_n64(); }
3514 // Whether we can only use 32-bit microMIPS instructions.
3516 use_32bit_micromips_instructions() const
3517 { return this->insn32_
; }
3519 // Return the r_sym field from a relocation.
3521 get_r_sym(const unsigned char* preloc
) const
3523 // Since REL and RELA relocs share the same structure through
3524 // the r_info field, we can just use REL here.
3525 Reltype
rel(preloc
);
3526 return Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
3531 // Return the value to use for a dynamic symbol which requires special
3532 // treatment. This is how we support equality comparisons of function
3533 // pointers across shared library boundaries, as described in the
3534 // processor specific ABI supplement.
3536 do_dynsym_value(const Symbol
* gsym
) const;
3538 // Make an ELF object.
3540 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
3541 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
);
3544 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
3545 const elfcpp::Ehdr
<size
, !big_endian
>&)
3546 { gold_unreachable(); }
3548 // Make an output section.
3550 do_make_output_section(const char* name
, elfcpp::Elf_Word type
,
3551 elfcpp::Elf_Xword flags
)
3553 if (type
== elfcpp::SHT_MIPS_REGINFO
)
3554 return new Mips_output_section_reginfo
<size
, big_endian
>(name
, type
,
3557 return new Output_section(name
, type
, flags
);
3560 // Adjust ELF file header.
3562 do_adjust_elf_header(unsigned char* view
, int len
);
3564 // Get the custom dynamic tag value.
3566 do_dynamic_tag_custom_value(elfcpp::DT
) const;
3568 // Adjust the value written to the dynamic symbol table.
3570 do_adjust_dyn_symbol(const Symbol
* sym
, unsigned char* view
) const
3572 elfcpp::Sym
<size
, big_endian
> isym(view
);
3573 elfcpp::Sym_write
<size
, big_endian
> osym(view
);
3574 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(sym
);
3576 // Keep dynamic compressed symbols odd. This allows the dynamic linker
3577 // to treat compressed symbols like any other.
3578 Mips_address value
= isym
.get_st_value();
3579 if (mips_sym
->is_mips16() && value
!= 0)
3581 if (!mips_sym
->has_mips16_fn_stub())
3585 // If we have a MIPS16 function with a stub, the dynamic symbol
3586 // must refer to the stub, since only the stub uses the standard
3587 // calling conventions. Stub contains MIPS32 code, so don't add +1
3590 // There is a code which does this in the method
3591 // Target_mips::do_dynsym_value, but that code will only be
3592 // executed if the symbol is from dynobj.
3593 // TODO(sasa): GNU ld also changes the value in non-dynamic symbol
3596 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
3597 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
3598 value
= fn_stub
->output_address();
3599 osym
.put_st_size(fn_stub
->section_size());
3602 osym
.put_st_value(value
);
3603 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(),
3604 mips_sym
->nonvis() - (elfcpp::STO_MIPS16
>> 2)));
3606 else if ((mips_sym
->is_micromips()
3607 // Stubs are always microMIPS if there is any microMIPS code in
3609 || (this->is_output_micromips() && mips_sym
->has_lazy_stub()))
3612 osym
.put_st_value(value
| 1);
3613 osym
.put_st_other(elfcpp::elf_st_other(sym
->visibility(),
3614 mips_sym
->nonvis() - (elfcpp::STO_MICROMIPS
>> 2)));
3619 // The class which scans relocations.
3627 get_reference_flags(unsigned int r_type
);
3630 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3631 Sized_relobj_file
<size
, big_endian
>* object
,
3632 unsigned int data_shndx
,
3633 Output_section
* output_section
,
3634 const Reltype
& reloc
, unsigned int r_type
,
3635 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3639 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3640 Sized_relobj_file
<size
, big_endian
>* object
,
3641 unsigned int data_shndx
,
3642 Output_section
* output_section
,
3643 const Relatype
& reloc
, unsigned int r_type
,
3644 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3648 local(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3649 Sized_relobj_file
<size
, big_endian
>* object
,
3650 unsigned int data_shndx
,
3651 Output_section
* output_section
,
3652 const Relatype
* rela
,
3654 unsigned int rel_type
,
3655 unsigned int r_type
,
3656 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3660 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3661 Sized_relobj_file
<size
, big_endian
>* object
,
3662 unsigned int data_shndx
,
3663 Output_section
* output_section
,
3664 const Reltype
& reloc
, unsigned int r_type
,
3668 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3669 Sized_relobj_file
<size
, big_endian
>* object
,
3670 unsigned int data_shndx
,
3671 Output_section
* output_section
,
3672 const Relatype
& reloc
, unsigned int r_type
,
3676 global(Symbol_table
* symtab
, Layout
* layout
, Target_mips
* target
,
3677 Sized_relobj_file
<size
, big_endian
>* object
,
3678 unsigned int data_shndx
,
3679 Output_section
* output_section
,
3680 const Relatype
* rela
,
3682 unsigned int rel_type
,
3683 unsigned int r_type
,
3687 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
*,
3689 Sized_relobj_file
<size
, big_endian
>*,
3694 const elfcpp::Sym
<size
, big_endian
>&)
3698 global_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3700 Sized_relobj_file
<size
, big_endian
>*,
3704 unsigned int, Symbol
*)
3708 local_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3710 Sized_relobj_file
<size
, big_endian
>*,
3715 const elfcpp::Sym
<size
, big_endian
>&)
3719 global_reloc_may_be_function_pointer(Symbol_table
*, Layout
*,
3721 Sized_relobj_file
<size
, big_endian
>*,
3725 unsigned int, Symbol
*)
3729 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
3730 unsigned int r_type
);
3733 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
3734 unsigned int r_type
, Symbol
*);
3737 // The class which implements relocation.
3747 // Return whether a R_MIPS_32/R_MIPS_64 relocation needs to be applied.
3749 should_apply_static_reloc(const Mips_symbol
<size
>* gsym
,
3750 unsigned int r_type
,
3751 Output_section
* output_section
,
3752 Target_mips
* target
);
3754 // Do a relocation. Return false if the caller should not issue
3755 // any warnings about this relocation.
3757 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
3758 Target_mips
*, Output_section
*, size_t, const unsigned char*,
3759 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
3760 unsigned char*, Mips_address
, section_size_type
);
3763 // This POD class holds the dynamic relocations that should be emitted instead
3764 // of R_MIPS_32, R_MIPS_REL32 and R_MIPS_64 relocations. We will emit these
3765 // relocations if it turns out that the symbol does not have static
3770 Dyn_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
3771 Mips_relobj
<size
, big_endian
>* relobj
, unsigned int shndx
,
3772 Output_section
* output_section
, Mips_address r_offset
)
3773 : sym_(sym
), r_type_(r_type
), relobj_(relobj
),
3774 shndx_(shndx
), output_section_(output_section
),
3778 // Emit this reloc if appropriate. This is called after we have
3779 // scanned all the relocations, so we know whether the symbol has
3780 // static relocations.
3782 emit(Reloc_section
* rel_dyn
, Mips_output_data_got
<size
, big_endian
>* got
,
3783 Symbol_table
* symtab
)
3785 if (!this->sym_
->has_static_relocs())
3787 got
->record_global_got_symbol(this->sym_
, this->relobj_
,
3788 this->r_type_
, true, false);
3789 if (!symbol_references_local(this->sym_
,
3790 this->sym_
->should_add_dynsym_entry(symtab
)))
3791 rel_dyn
->add_global(this->sym_
, this->r_type_
,
3792 this->output_section_
, this->relobj_
,
3793 this->shndx_
, this->r_offset_
);
3795 rel_dyn
->add_symbolless_global_addend(this->sym_
, this->r_type_
,
3796 this->output_section_
, this->relobj_
,
3797 this->shndx_
, this->r_offset_
);
3802 Mips_symbol
<size
>* sym_
;
3803 unsigned int r_type_
;
3804 Mips_relobj
<size
, big_endian
>* relobj_
;
3805 unsigned int shndx_
;
3806 Output_section
* output_section_
;
3807 Mips_address r_offset_
;
3810 // Adjust TLS relocation type based on the options and whether this
3811 // is a local symbol.
3812 static tls::Tls_optimization
3813 optimize_tls_reloc(bool is_final
, int r_type
);
3815 // Return whether there is a GOT section.
3817 has_got_section() const
3818 { return this->got_
!= NULL
; }
3820 // Check whether the given ELF header flags describe a 32-bit binary.
3822 mips_32bit_flags(elfcpp::Elf_Word
);
3825 mach_mips3000
= 3000,
3826 mach_mips3900
= 3900,
3827 mach_mips4000
= 4000,
3828 mach_mips4010
= 4010,
3829 mach_mips4100
= 4100,
3830 mach_mips4111
= 4111,
3831 mach_mips4120
= 4120,
3832 mach_mips4300
= 4300,
3833 mach_mips4400
= 4400,
3834 mach_mips4600
= 4600,
3835 mach_mips4650
= 4650,
3836 mach_mips5000
= 5000,
3837 mach_mips5400
= 5400,
3838 mach_mips5500
= 5500,
3839 mach_mips6000
= 6000,
3840 mach_mips7000
= 7000,
3841 mach_mips8000
= 8000,
3842 mach_mips9000
= 9000,
3843 mach_mips10000
= 10000,
3844 mach_mips12000
= 12000,
3845 mach_mips14000
= 14000,
3846 mach_mips16000
= 16000,
3849 mach_mips_loongson_2e
= 3001,
3850 mach_mips_loongson_2f
= 3002,
3851 mach_mips_loongson_3a
= 3003,
3852 mach_mips_sb1
= 12310201, // octal 'SB', 01
3853 mach_mips_octeon
= 6501,
3854 mach_mips_octeonp
= 6601,
3855 mach_mips_octeon2
= 6502,
3856 mach_mips_xlr
= 887682, // decimal 'XLR'
3857 mach_mipsisa32
= 32,
3858 mach_mipsisa32r2
= 33,
3859 mach_mipsisa64
= 64,
3860 mach_mipsisa64r2
= 65,
3861 mach_mips_micromips
= 96
3864 // Return the MACH for a MIPS e_flags value.
3866 elf_mips_mach(elfcpp::Elf_Word
);
3868 // Check whether machine EXTENSION is an extension of machine BASE.
3870 mips_mach_extends(unsigned int, unsigned int);
3872 // Merge processor specific flags.
3874 merge_processor_specific_flags(const std::string
&, elfcpp::Elf_Word
, bool);
3876 // True if we are linking for CPUs that are faster if JAL is converted to BAL.
3881 // True if we are linking for CPUs that are faster if JALR is converted to
3882 // BAL. This should be safe for all architectures. We enable this predicate
3888 // True if we are linking for CPUs that are faster if JR is converted to B.
3889 // This should be safe for all architectures. We enable this predicate for
3895 // Return the size of the GOT section.
3899 gold_assert(this->got_
!= NULL
);
3900 return this->got_
->data_size();
3903 // Create a PLT entry for a global symbol referenced by r_type relocation.
3905 make_plt_entry(Symbol_table
*, Layout
*, Mips_symbol
<size
>*,
3906 unsigned int r_type
);
3908 // Get the PLT section.
3909 Mips_output_data_plt
<size
, big_endian
>*
3912 gold_assert(this->plt_
!= NULL
);
3916 // Get the GOT PLT section.
3917 const Mips_output_data_plt
<size
, big_endian
>*
3918 got_plt_section() const
3920 gold_assert(this->got_plt_
!= NULL
);
3921 return this->got_plt_
;
3924 // Copy a relocation against a global symbol.
3926 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
3927 Sized_relobj_file
<size
, big_endian
>* object
,
3928 unsigned int shndx
, Output_section
* output_section
,
3929 Symbol
* sym
, unsigned int r_type
, Mips_address r_offset
)
3931 this->copy_relocs_
.copy_reloc(symtab
, layout
,
3932 symtab
->get_sized_symbol
<size
>(sym
),
3933 object
, shndx
, output_section
,
3934 r_type
, r_offset
, 0,
3935 this->rel_dyn_section(layout
));
3939 dynamic_reloc(Mips_symbol
<size
>* sym
, unsigned int r_type
,
3940 Mips_relobj
<size
, big_endian
>* relobj
,
3941 unsigned int shndx
, Output_section
* output_section
,
3942 Mips_address r_offset
)
3944 this->dyn_relocs_
.push_back(Dyn_reloc(sym
, r_type
, relobj
, shndx
,
3945 output_section
, r_offset
));
3948 // Calculate value of _gp symbol.
3950 set_gp(Layout
*, Symbol_table
*);
3953 elf_mips_abi_name(elfcpp::Elf_Word e_flags
);
3955 elf_mips_mach_name(elfcpp::Elf_Word e_flags
);
3957 // Adds entries that describe how machines relate to one another. The entries
3958 // are ordered topologically with MIPS I extensions listed last. First
3959 // element is extension, second element is base.
3961 add_machine_extensions()
3963 // MIPS64r2 extensions.
3964 this->add_extension(mach_mips_octeon2
, mach_mips_octeonp
);
3965 this->add_extension(mach_mips_octeonp
, mach_mips_octeon
);
3966 this->add_extension(mach_mips_octeon
, mach_mipsisa64r2
);
3968 // MIPS64 extensions.
3969 this->add_extension(mach_mipsisa64r2
, mach_mipsisa64
);
3970 this->add_extension(mach_mips_sb1
, mach_mipsisa64
);
3971 this->add_extension(mach_mips_xlr
, mach_mipsisa64
);
3972 this->add_extension(mach_mips_loongson_3a
, mach_mipsisa64
);
3974 // MIPS V extensions.
3975 this->add_extension(mach_mipsisa64
, mach_mips5
);
3977 // R10000 extensions.
3978 this->add_extension(mach_mips12000
, mach_mips10000
);
3979 this->add_extension(mach_mips14000
, mach_mips10000
);
3980 this->add_extension(mach_mips16000
, mach_mips10000
);
3982 // R5000 extensions. Note: the vr5500 ISA is an extension of the core
3983 // vr5400 ISA, but doesn't include the multimedia stuff. It seems
3984 // better to allow vr5400 and vr5500 code to be merged anyway, since
3985 // many libraries will just use the core ISA. Perhaps we could add
3986 // some sort of ASE flag if this ever proves a problem.
3987 this->add_extension(mach_mips5500
, mach_mips5400
);
3988 this->add_extension(mach_mips5400
, mach_mips5000
);
3990 // MIPS IV extensions.
3991 this->add_extension(mach_mips5
, mach_mips8000
);
3992 this->add_extension(mach_mips10000
, mach_mips8000
);
3993 this->add_extension(mach_mips5000
, mach_mips8000
);
3994 this->add_extension(mach_mips7000
, mach_mips8000
);
3995 this->add_extension(mach_mips9000
, mach_mips8000
);
3997 // VR4100 extensions.
3998 this->add_extension(mach_mips4120
, mach_mips4100
);
3999 this->add_extension(mach_mips4111
, mach_mips4100
);
4001 // MIPS III extensions.
4002 this->add_extension(mach_mips_loongson_2e
, mach_mips4000
);
4003 this->add_extension(mach_mips_loongson_2f
, mach_mips4000
);
4004 this->add_extension(mach_mips8000
, mach_mips4000
);
4005 this->add_extension(mach_mips4650
, mach_mips4000
);
4006 this->add_extension(mach_mips4600
, mach_mips4000
);
4007 this->add_extension(mach_mips4400
, mach_mips4000
);
4008 this->add_extension(mach_mips4300
, mach_mips4000
);
4009 this->add_extension(mach_mips4100
, mach_mips4000
);
4010 this->add_extension(mach_mips4010
, mach_mips4000
);
4012 // MIPS32 extensions.
4013 this->add_extension(mach_mipsisa32r2
, mach_mipsisa32
);
4015 // MIPS II extensions.
4016 this->add_extension(mach_mips4000
, mach_mips6000
);
4017 this->add_extension(mach_mipsisa32
, mach_mips6000
);
4019 // MIPS I extensions.
4020 this->add_extension(mach_mips6000
, mach_mips3000
);
4021 this->add_extension(mach_mips3900
, mach_mips3000
);
4024 // Add value to MIPS extenstions.
4026 add_extension(unsigned int base
, unsigned int extension
)
4028 std::pair
<unsigned int, unsigned int> ext(base
, extension
);
4029 this->mips_mach_extensions_
.push_back(ext
);
4032 // Return the number of entries in the .dynsym section.
4033 unsigned int get_dt_mips_symtabno() const
4035 return ((unsigned int)(this->layout_
->dynsym_section()->data_size()
4036 / elfcpp::Elf_sizes
<size
>::sym_size
));
4037 // TODO(sasa): Entry size is MIPS_ELF_SYM_SIZE.
4040 // Information about this specific target which we pass to the
4041 // general Target structure.
4042 static const Target::Target_info mips_info
;
4044 Mips_output_data_got
<size
, big_endian
>* got_
;
4045 // gp symbol. It has the value of .got + 0x7FF0.
4046 Sized_symbol
<size
>* gp_
;
4048 Mips_output_data_plt
<size
, big_endian
>* plt_
;
4049 // The GOT PLT section.
4050 Output_data_space
* got_plt_
;
4051 // The dynamic reloc section.
4052 Reloc_section
* rel_dyn_
;
4053 // Relocs saved to avoid a COPY reloc.
4054 Mips_copy_relocs
<elfcpp::SHT_REL
, size
, big_endian
> copy_relocs_
;
4056 // A list of dyn relocs to be saved.
4057 std::vector
<Dyn_reloc
> dyn_relocs_
;
4059 // The LA25 stub section.
4060 Mips_output_data_la25_stub
<size
, big_endian
>* la25_stub_
;
4061 // Architecture extensions.
4062 std::vector
<std::pair
<unsigned int, unsigned int> > mips_mach_extensions_
;
4064 Mips_output_data_mips_stubs
<size
, big_endian
>* mips_stubs_
;
4069 typename
std::list
<got16_addend
<size
, big_endian
> > got16_addends_
;
4071 // Whether the entry symbol is mips16 or micromips.
4072 bool entry_symbol_is_compressed_
;
4074 // Whether we can use only 32-bit microMIPS instructions.
4075 // TODO(sasa): This should be a linker option.
4079 // Helper structure for R_MIPS*_HI16/LO16 and R_MIPS*_GOT16/LO16 relocations.
4080 // It records high part of the relocation pair.
4082 template<int size
, bool big_endian
>
4085 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
4087 reloc_high(unsigned char* _view
, const Mips_relobj
<size
, big_endian
>* _object
,
4088 const Symbol_value
<size
>* _psymval
, Mips_address _addend
,
4089 unsigned int _r_type
, unsigned int _r_sym
, bool _extract_addend
,
4090 Mips_address _address
= 0, bool _gp_disp
= false)
4091 : view(_view
), object(_object
), psymval(_psymval
), addend(_addend
),
4092 r_type(_r_type
), r_sym(_r_sym
), extract_addend(_extract_addend
),
4093 address(_address
), gp_disp(_gp_disp
)
4096 unsigned char* view
;
4097 const Mips_relobj
<size
, big_endian
>* object
;
4098 const Symbol_value
<size
>* psymval
;
4099 Mips_address addend
;
4100 unsigned int r_type
;
4102 bool extract_addend
;
4103 Mips_address address
;
4107 template<int size
, bool big_endian
>
4108 class Mips_relocate_functions
: public Relocate_functions
<size
, big_endian
>
4110 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Mips_address
;
4111 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
4112 typedef typename
elfcpp::Swap
<16, big_endian
>::Valtype Valtype16
;
4113 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype32
;
4114 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype64
;
4119 STATUS_OKAY
, // No error during relocation.
4120 STATUS_OVERFLOW
, // Relocation overflow.
4121 STATUS_BAD_RELOC
// Relocation cannot be applied.
4125 typedef Relocate_functions
<size
, big_endian
> Base
;
4126 typedef Mips_relocate_functions
<size
, big_endian
> This
;
4128 static typename
std::list
<reloc_high
<size
, big_endian
> > hi16_relocs
;
4129 static typename
std::list
<reloc_high
<size
, big_endian
> > got16_relocs
;
4131 template<int valsize
>
4132 static inline typename
This::Status
4133 check_overflow(Valtype value
)
4136 return (Bits
<valsize
>::has_overflow32(value
)
4137 ? This::STATUS_OVERFLOW
4138 : This::STATUS_OKAY
);
4140 return (Bits
<valsize
>::has_overflow(value
)
4141 ? This::STATUS_OVERFLOW
4142 : This::STATUS_OKAY
);
4146 should_shuffle_micromips_reloc(unsigned int r_type
)
4148 return (micromips_reloc(r_type
)
4149 && r_type
!= elfcpp::R_MICROMIPS_PC7_S1
4150 && r_type
!= elfcpp::R_MICROMIPS_PC10_S1
);
4154 // R_MIPS16_26 is used for the mips16 jal and jalx instructions.
4155 // Most mips16 instructions are 16 bits, but these instructions
4158 // The format of these instructions is:
4160 // +--------------+--------------------------------+
4161 // | JALX | X| Imm 20:16 | Imm 25:21 |
4162 // +--------------+--------------------------------+
4163 // | Immediate 15:0 |
4164 // +-----------------------------------------------+
4166 // JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
4167 // Note that the immediate value in the first word is swapped.
4169 // When producing a relocatable object file, R_MIPS16_26 is
4170 // handled mostly like R_MIPS_26. In particular, the addend is
4171 // stored as a straight 26-bit value in a 32-bit instruction.
4172 // (gas makes life simpler for itself by never adjusting a
4173 // R_MIPS16_26 reloc to be against a section, so the addend is
4174 // always zero). However, the 32 bit instruction is stored as 2
4175 // 16-bit values, rather than a single 32-bit value. In a
4176 // big-endian file, the result is the same; in a little-endian
4177 // file, the two 16-bit halves of the 32 bit value are swapped.
4178 // This is so that a disassembler can recognize the jal
4181 // When doing a final link, R_MIPS16_26 is treated as a 32 bit
4182 // instruction stored as two 16-bit values. The addend A is the
4183 // contents of the targ26 field. The calculation is the same as
4184 // R_MIPS_26. When storing the calculated value, reorder the
4185 // immediate value as shown above, and don't forget to store the
4186 // value as two 16-bit values.
4188 // To put it in MIPS ABI terms, the relocation field is T-targ26-16,
4192 // +--------+----------------------+
4196 // +--------+----------------------+
4199 // +----------+------+-------------+
4201 // | sub1 | | sub2 |
4202 // |0 9|10 15|16 31|
4203 // +----------+--------------------+
4204 // where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
4205 // ((sub1 << 16) | sub2)).
4207 // When producing a relocatable object file, the calculation is
4208 // (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
4209 // When producing a fully linked file, the calculation is
4210 // let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
4211 // ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
4213 // The table below lists the other MIPS16 instruction relocations.
4214 // Each one is calculated in the same way as the non-MIPS16 relocation
4215 // given on the right, but using the extended MIPS16 layout of 16-bit
4216 // immediate fields:
4218 // R_MIPS16_GPREL R_MIPS_GPREL16
4219 // R_MIPS16_GOT16 R_MIPS_GOT16
4220 // R_MIPS16_CALL16 R_MIPS_CALL16
4221 // R_MIPS16_HI16 R_MIPS_HI16
4222 // R_MIPS16_LO16 R_MIPS_LO16
4224 // A typical instruction will have a format like this:
4226 // +--------------+--------------------------------+
4227 // | EXTEND | Imm 10:5 | Imm 15:11 |
4228 // +--------------+--------------------------------+
4229 // | Major | rx | ry | Imm 4:0 |
4230 // +--------------+--------------------------------+
4232 // EXTEND is the five bit value 11110. Major is the instruction
4235 // All we need to do here is shuffle the bits appropriately.
4236 // As above, the two 16-bit halves must be swapped on a
4237 // little-endian system.
4239 // Similar to MIPS16, the two 16-bit halves in microMIPS must be swapped
4240 // on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1
4241 // and R_MICROMIPS_PC10_S1 relocs that apply to 16-bit instructions.
4244 mips_reloc_unshuffle(unsigned char* view
, unsigned int r_type
,
4247 if (!mips16_reloc(r_type
)
4248 && !should_shuffle_micromips_reloc(r_type
))
4251 // Pick up the first and second halfwords of the instruction.
4252 Valtype16 first
= elfcpp::Swap
<16, big_endian
>::readval(view
);
4253 Valtype16 second
= elfcpp::Swap
<16, big_endian
>::readval(view
+ 2);
4256 if (micromips_reloc(r_type
)
4257 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
4258 val
= first
<< 16 | second
;
4259 else if (r_type
!= elfcpp::R_MIPS16_26
)
4260 val
= (((first
& 0xf800) << 16) | ((second
& 0xffe0) << 11)
4261 | ((first
& 0x1f) << 11) | (first
& 0x7e0) | (second
& 0x1f));
4263 val
= (((first
& 0xfc00) << 16) | ((first
& 0x3e0) << 11)
4264 | ((first
& 0x1f) << 21) | second
);
4266 elfcpp::Swap
<32, big_endian
>::writeval(view
, val
);
4270 mips_reloc_shuffle(unsigned char* view
, unsigned int r_type
, bool jal_shuffle
)
4272 if (!mips16_reloc(r_type
)
4273 && !should_shuffle_micromips_reloc(r_type
))
4276 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4277 Valtype16 first
, second
;
4279 if (micromips_reloc(r_type
)
4280 || (r_type
== elfcpp::R_MIPS16_26
&& !jal_shuffle
))
4282 second
= val
& 0xffff;
4285 else if (r_type
!= elfcpp::R_MIPS16_26
)
4287 second
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
4288 first
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
4292 second
= val
& 0xffff;
4293 first
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
4294 | ((val
>> 21) & 0x1f);
4297 elfcpp::Swap
<16, big_endian
>::writeval(view
+ 2, second
);
4298 elfcpp::Swap
<16, big_endian
>::writeval(view
, first
);
4301 // R_MIPS_16: S + sign-extend(A)
4302 static inline typename
This::Status
4303 rel16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4304 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4305 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
4307 Valtype16
* wv
= reinterpret_cast<Valtype16
*>(view
);
4308 Valtype16 val
= elfcpp::Swap
<16, big_endian
>::readval(wv
);
4310 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
)
4313 Valtype x
= psymval
->value(object
, addend
);
4314 val
= Bits
<16>::bit_select32(val
, x
, 0xffffU
);
4318 *calculated_value
= x
;
4319 return This::STATUS_OKAY
;
4322 elfcpp::Swap
<16, big_endian
>::writeval(wv
, val
);
4324 return check_overflow
<16>(x
);
4328 static inline typename
This::Status
4329 rel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4330 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4331 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
4333 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4334 Valtype addend
= (extract_addend
4335 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
4337 Valtype x
= psymval
->value(object
, addend
);
4340 *calculated_value
= x
;
4342 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4344 return This::STATUS_OKAY
;
4347 // R_MIPS_JALR, R_MICROMIPS_JALR
4348 static inline typename
This::Status
4349 reljalr(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4350 const Symbol_value
<size
>* psymval
, Mips_address address
,
4351 Mips_address addend_a
, bool extract_addend
, bool cross_mode_jump
,
4352 unsigned int r_type
, bool jalr_to_bal
, bool jr_to_b
,
4353 bool calculate_only
, Valtype
* calculated_value
)
4355 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4356 Valtype addend
= extract_addend
? 0 : addend_a
;
4357 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4359 // Try converting J(AL)R to B(AL), if the target is in range.
4360 if (!parameters
->options().relocatable()
4361 && r_type
== elfcpp::R_MIPS_JALR
4363 && ((jalr_to_bal
&& val
== 0x0320f809) // jalr t9
4364 || (jr_to_b
&& val
== 0x03200008))) // jr t9
4366 int offset
= psymval
->value(object
, addend
) - (address
+ 4);
4367 if (!Bits
<18>::has_overflow32(offset
))
4369 if (val
== 0x03200008) // jr t9
4370 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4372 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4377 *calculated_value
= val
;
4379 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4381 return This::STATUS_OKAY
;
4384 // R_MIPS_PC32: S + A - P
4385 static inline typename
This::Status
4386 relpc32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4387 const Symbol_value
<size
>* psymval
, Mips_address address
,
4388 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4389 Valtype
* calculated_value
)
4391 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4392 Valtype addend
= (extract_addend
4393 ? elfcpp::Swap
<32, big_endian
>::readval(wv
)
4395 Valtype x
= psymval
->value(object
, addend
) - address
;
4398 *calculated_value
= x
;
4400 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4402 return This::STATUS_OKAY
;
4405 // R_MIPS_26, R_MIPS16_26, R_MICROMIPS_26_S1
4406 static inline typename
This::Status
4407 rel26(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4408 const Symbol_value
<size
>* psymval
, Mips_address address
,
4409 bool local
, Mips_address addend_a
, bool extract_addend
,
4410 const Symbol
* gsym
, bool cross_mode_jump
, unsigned int r_type
,
4411 bool jal_to_bal
, bool calculate_only
, Valtype
* calculated_value
)
4413 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4414 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4419 if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4420 addend
= (val
& 0x03ffffff) << 1;
4422 addend
= (val
& 0x03ffffff) << 2;
4427 // Make sure the target of JALX is word-aligned. Bit 0 must be
4428 // the correct ISA mode selector and bit 1 must be 0.
4429 if (!calculate_only
&& cross_mode_jump
4430 && (psymval
->value(object
, 0) & 3) != (r_type
== elfcpp::R_MIPS_26
))
4432 gold_warning(_("JALX to a non-word-aligned address"));
4433 return This::STATUS_BAD_RELOC
;
4436 // Shift is 2, unusually, for microMIPS JALX.
4437 unsigned int shift
=
4438 (!cross_mode_jump
&& r_type
== elfcpp::R_MICROMIPS_26_S1
) ? 1 : 2;
4442 x
= addend
| ((address
+ 4) & (0xfc000000 << shift
));
4446 x
= Bits
<27>::sign_extend32(addend
);
4448 x
= Bits
<28>::sign_extend32(addend
);
4450 x
= psymval
->value(object
, x
) >> shift
;
4452 if (!calculate_only
&& !local
&& !gsym
->is_weak_undefined())
4454 if ((x
>> 26) != ((address
+ 4) >> (26 + shift
)))
4456 gold_error(_("relocation truncated to fit: %u against '%s'"),
4457 r_type
, gsym
->name());
4458 return This::STATUS_OVERFLOW
;
4462 val
= Bits
<32>::bit_select32(val
, x
, 0x03ffffff);
4464 // If required, turn JAL into JALX.
4465 if (cross_mode_jump
)
4468 Valtype32 opcode
= val
>> 26;
4469 Valtype32 jalx_opcode
;
4471 // Check to see if the opcode is already JAL or JALX.
4472 if (r_type
== elfcpp::R_MIPS16_26
)
4474 ok
= (opcode
== 0x6) || (opcode
== 0x7);
4477 else if (r_type
== elfcpp::R_MICROMIPS_26_S1
)
4479 ok
= (opcode
== 0x3d) || (opcode
== 0x3c);
4484 ok
= (opcode
== 0x3) || (opcode
== 0x1d);
4488 // If the opcode is not JAL or JALX, there's a problem. We cannot
4489 // convert J or JALS to JALX.
4490 if (!calculate_only
&& !ok
)
4492 gold_error(_("Unsupported jump between ISA modes; consider "
4493 "recompiling with interlinking enabled."));
4494 return This::STATUS_BAD_RELOC
;
4497 // Make this the JALX opcode.
4498 val
= (val
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
4501 // Try converting JAL to BAL, if the target is in range.
4502 if (!parameters
->options().relocatable()
4505 && r_type
== elfcpp::R_MIPS_26
4506 && (val
>> 26) == 0x3))) // jal addr
4508 Valtype32 dest
= (x
<< 2) | (((address
+ 4) >> 28) << 28);
4509 int offset
= dest
- (address
+ 4);
4510 if (!Bits
<18>::has_overflow32(offset
))
4512 if (val
== 0x03200008) // jr t9
4513 val
= 0x10000000 | (((Valtype32
)offset
>> 2) & 0xffff); // b addr
4515 val
= 0x04110000 | (((Valtype32
)offset
>> 2) & 0xffff); //bal addr
4520 *calculated_value
= val
;
4522 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4524 return This::STATUS_OKAY
;
4528 static inline typename
This::Status
4529 relpc16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4530 const Symbol_value
<size
>* psymval
, Mips_address address
,
4531 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
4532 Valtype
* calculated_value
)
4534 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4535 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4537 Valtype addend
= (extract_addend
4538 ? Bits
<18>::sign_extend32((val
& 0xffff) << 2)
4541 Valtype x
= psymval
->value(object
, addend
) - address
;
4542 val
= Bits
<16>::bit_select32(val
, x
>> 2, 0xffff);
4546 *calculated_value
= x
>> 2;
4547 return This::STATUS_OKAY
;
4550 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4552 return check_overflow
<18>(x
);
4555 // R_MICROMIPS_PC7_S1
4556 static inline typename
This::Status
4557 relmicromips_pc7_s1(unsigned char* view
,
4558 const Mips_relobj
<size
, big_endian
>* object
,
4559 const Symbol_value
<size
>* psymval
, Mips_address address
,
4560 Mips_address addend_a
, bool extract_addend
,
4561 bool calculate_only
, Valtype
* calculated_value
)
4563 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4564 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4566 Valtype addend
= extract_addend
? Bits
<8>::sign_extend32((val
& 0x7f) << 1)
4569 Valtype x
= psymval
->value(object
, addend
) - address
;
4570 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x7f);
4574 *calculated_value
= x
>> 1;
4575 return This::STATUS_OKAY
;
4578 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4580 return check_overflow
<8>(x
);
4583 // R_MICROMIPS_PC10_S1
4584 static inline typename
This::Status
4585 relmicromips_pc10_s1(unsigned char* view
,
4586 const Mips_relobj
<size
, big_endian
>* object
,
4587 const Symbol_value
<size
>* psymval
, Mips_address address
,
4588 Mips_address addend_a
, bool extract_addend
,
4589 bool calculate_only
, Valtype
* calculated_value
)
4591 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4592 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4594 Valtype addend
= (extract_addend
4595 ? Bits
<11>::sign_extend32((val
& 0x3ff) << 1)
4598 Valtype x
= psymval
->value(object
, addend
) - address
;
4599 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0x3ff);
4603 *calculated_value
= x
>> 1;
4604 return This::STATUS_OKAY
;
4607 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4609 return check_overflow
<11>(x
);
4612 // R_MICROMIPS_PC16_S1
4613 static inline typename
This::Status
4614 relmicromips_pc16_s1(unsigned char* view
,
4615 const Mips_relobj
<size
, big_endian
>* object
,
4616 const Symbol_value
<size
>* psymval
, Mips_address address
,
4617 Mips_address addend_a
, bool extract_addend
,
4618 bool calculate_only
, Valtype
* calculated_value
)
4620 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4621 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4623 Valtype addend
= (extract_addend
4624 ? Bits
<17>::sign_extend32((val
& 0xffff) << 1)
4627 Valtype x
= psymval
->value(object
, addend
) - address
;
4628 val
= Bits
<16>::bit_select32(val
, x
>> 1, 0xffff);
4632 *calculated_value
= x
>> 1;
4633 return This::STATUS_OKAY
;
4636 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4638 return check_overflow
<17>(x
);
4641 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
4642 static inline typename
This::Status
4643 relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4644 const Symbol_value
<size
>* psymval
, Mips_address addend
,
4645 Mips_address address
, bool gp_disp
, unsigned int r_type
,
4646 unsigned int r_sym
, bool extract_addend
)
4648 // Record the relocation. It will be resolved when we find lo16 part.
4649 hi16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
4650 addend
, r_type
, r_sym
, extract_addend
, address
,
4652 return This::STATUS_OKAY
;
4655 // R_MIPS_HI16, R_MIPS16_HI16, R_MICROMIPS_HI16,
4656 static inline typename
This::Status
4657 do_relhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
4658 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
4659 Mips_address address
, bool is_gp_disp
, unsigned int r_type
,
4660 bool extract_addend
, Valtype32 addend_lo
,
4661 Target_mips
<size
, big_endian
>* target
, bool calculate_only
,
4662 Valtype
* calculated_value
)
4664 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4665 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4667 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
4672 value
= psymval
->value(object
, addend
);
4675 // For MIPS16 ABI code we generate this sequence
4676 // 0: li $v0,%hi(_gp_disp)
4677 // 4: addiupc $v1,%lo(_gp_disp)
4681 // So the offsets of hi and lo relocs are the same, but the
4682 // base $pc is that used by the ADDIUPC instruction at $t9 + 4.
4683 // ADDIUPC clears the low two bits of the instruction address,
4684 // so the base is ($t9 + 4) & ~3.
4686 if (r_type
== elfcpp::R_MIPS16_HI16
)
4687 gp_disp
= (target
->adjusted_gp_value(object
)
4688 - ((address
+ 4) & ~0x3));
4689 // The microMIPS .cpload sequence uses the same assembly
4690 // instructions as the traditional psABI version, but the
4691 // incoming $t9 has the low bit set.
4692 else if (r_type
== elfcpp::R_MICROMIPS_HI16
)
4693 gp_disp
= target
->adjusted_gp_value(object
) - address
- 1;
4695 gp_disp
= target
->adjusted_gp_value(object
) - address
;
4696 value
= gp_disp
+ addend
;
4698 Valtype x
= ((value
+ 0x8000) >> 16) & 0xffff;
4699 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4703 *calculated_value
= x
;
4704 return This::STATUS_OKAY
;
4707 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4709 return (is_gp_disp
? check_overflow
<16>(x
)
4710 : This::STATUS_OKAY
);
4713 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4714 static inline typename
This::Status
4715 relgot16_local(unsigned char* view
,
4716 const Mips_relobj
<size
, big_endian
>* object
,
4717 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4718 bool extract_addend
, unsigned int r_type
, unsigned int r_sym
)
4720 // Record the relocation. It will be resolved when we find lo16 part.
4721 got16_relocs
.push_back(reloc_high
<size
, big_endian
>(view
, object
, psymval
,
4722 addend_a
, r_type
, r_sym
, extract_addend
));
4723 return This::STATUS_OKAY
;
4726 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4727 static inline typename
This::Status
4728 do_relgot16_local(unsigned char* view
,
4729 const Mips_relobj
<size
, big_endian
>* object
,
4730 const Symbol_value
<size
>* psymval
, Mips_address addend_hi
,
4731 bool extract_addend
, Valtype32 addend_lo
,
4732 Target_mips
<size
, big_endian
>* target
, bool calculate_only
,
4733 Valtype
* calculated_value
)
4735 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4736 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4738 Valtype addend
= (extract_addend
? ((val
& 0xffff) << 16) + addend_lo
4741 // Find GOT page entry.
4742 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000) >> 16)
4745 unsigned int got_offset
=
4746 target
->got_section()->get_got_page_offset(value
, object
);
4748 // Resolve the relocation.
4749 Valtype x
= target
->got_section()->gp_offset(got_offset
, object
);
4750 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4754 *calculated_value
= x
;
4755 return This::STATUS_OKAY
;
4758 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4760 return check_overflow
<16>(x
);
4763 // R_MIPS_LO16, R_MIPS16_LO16, R_MICROMIPS_LO16, R_MICROMIPS_HI0_LO16
4764 static inline typename
This::Status
4765 rello16(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4766 const Mips_relobj
<size
, big_endian
>* object
,
4767 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4768 bool extract_addend
, Mips_address address
, bool is_gp_disp
,
4769 unsigned int r_type
, unsigned int r_sym
, unsigned int rel_type
,
4770 bool calculate_only
, Valtype
* calculated_value
)
4772 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4773 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4775 Valtype addend
= (extract_addend
? Bits
<16>::sign_extend32(val
& 0xffff)
4778 if (rel_type
== elfcpp::SHT_REL
)
4780 typename
This::Status reloc_status
= This::STATUS_OKAY
;
4781 // Resolve pending R_MIPS_HI16 relocations.
4782 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it
=
4783 hi16_relocs
.begin();
4784 while (it
!= hi16_relocs
.end())
4786 reloc_high
<size
, big_endian
> hi16
= *it
;
4787 if (hi16
.r_sym
== r_sym
4788 && is_matching_lo16_reloc(hi16
.r_type
, r_type
))
4790 mips_reloc_unshuffle(hi16
.view
, hi16
.r_type
, false);
4791 reloc_status
= do_relhi16(hi16
.view
, hi16
.object
, hi16
.psymval
,
4792 hi16
.addend
, hi16
.address
, hi16
.gp_disp
,
4793 hi16
.r_type
, hi16
.extract_addend
, addend
,
4794 target
, calculate_only
, calculated_value
);
4795 mips_reloc_shuffle(hi16
.view
, hi16
.r_type
, false);
4796 if (reloc_status
== This::STATUS_OVERFLOW
)
4797 return This::STATUS_OVERFLOW
;
4798 it
= hi16_relocs
.erase(it
);
4804 // Resolve pending local R_MIPS_GOT16 relocations.
4805 typename
std::list
<reloc_high
<size
, big_endian
> >::iterator it2
=
4806 got16_relocs
.begin();
4807 while (it2
!= got16_relocs
.end())
4809 reloc_high
<size
, big_endian
> got16
= *it2
;
4810 if (got16
.r_sym
== r_sym
4811 && is_matching_lo16_reloc(got16
.r_type
, r_type
))
4813 mips_reloc_unshuffle(got16
.view
, got16
.r_type
, false);
4815 reloc_status
= do_relgot16_local(got16
.view
, got16
.object
,
4816 got16
.psymval
, got16
.addend
,
4817 got16
.extract_addend
, addend
, target
,
4818 calculate_only
, calculated_value
);
4820 mips_reloc_shuffle(got16
.view
, got16
.r_type
, false);
4821 if (reloc_status
== This::STATUS_OVERFLOW
)
4822 return This::STATUS_OVERFLOW
;
4823 it2
= got16_relocs
.erase(it2
);
4830 // Resolve R_MIPS_LO16 relocation.
4833 x
= psymval
->value(object
, addend
);
4836 // See the comment for R_MIPS16_HI16 above for the reason
4837 // for this conditional.
4839 if (r_type
== elfcpp::R_MIPS16_LO16
)
4840 gp_disp
= target
->adjusted_gp_value(object
) - (address
& ~0x3);
4841 else if (r_type
== elfcpp::R_MICROMIPS_LO16
4842 || r_type
== elfcpp::R_MICROMIPS_HI0_LO16
)
4843 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 3;
4845 gp_disp
= target
->adjusted_gp_value(object
) - address
+ 4;
4846 // The MIPS ABI requires checking the R_MIPS_LO16 relocation
4847 // for overflow. Relocations against _gp_disp are normally
4848 // generated from the .cpload pseudo-op. It generates code
4849 // that normally looks like this:
4851 // lui $gp,%hi(_gp_disp)
4852 // addiu $gp,$gp,%lo(_gp_disp)
4855 // Here $t9 holds the address of the function being called,
4856 // as required by the MIPS ELF ABI. The R_MIPS_LO16
4857 // relocation can easily overflow in this situation, but the
4858 // R_MIPS_HI16 relocation will handle the overflow.
4859 // Therefore, we consider this a bug in the MIPS ABI, and do
4860 // not check for overflow here.
4861 x
= gp_disp
+ addend
;
4863 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4866 *calculated_value
= x
;
4868 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4870 return This::STATUS_OKAY
;
4873 // R_MIPS_CALL16, R_MIPS16_CALL16, R_MICROMIPS_CALL16
4874 // R_MIPS_GOT16, R_MIPS16_GOT16, R_MICROMIPS_GOT16
4875 // R_MIPS_TLS_GD, R_MIPS16_TLS_GD, R_MICROMIPS_TLS_GD
4876 // R_MIPS_TLS_GOTTPREL, R_MIPS16_TLS_GOTTPREL, R_MICROMIPS_TLS_GOTTPREL
4877 // R_MIPS_TLS_LDM, R_MIPS16_TLS_LDM, R_MICROMIPS_TLS_LDM
4878 // R_MIPS_GOT_DISP, R_MICROMIPS_GOT_DISP
4879 static inline typename
This::Status
4880 relgot(unsigned char* view
, int gp_offset
, bool calculate_only
,
4881 Valtype
* calculated_value
)
4883 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4884 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4885 Valtype x
= gp_offset
;
4886 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4890 *calculated_value
= x
;
4891 return This::STATUS_OKAY
;
4894 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4896 return check_overflow
<16>(x
);
4900 static inline typename
This::Status
4901 releh(unsigned char* view
, int gp_offset
, bool calculate_only
,
4902 Valtype
* calculated_value
)
4904 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4905 Valtype x
= gp_offset
;
4909 *calculated_value
= x
;
4910 return This::STATUS_OKAY
;
4913 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
4915 return check_overflow
<32>(x
);
4918 // R_MIPS_GOT_PAGE, R_MICROMIPS_GOT_PAGE
4919 static inline typename
This::Status
4920 relgotpage(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4921 const Mips_relobj
<size
, big_endian
>* object
,
4922 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4923 bool extract_addend
, bool calculate_only
,
4924 Valtype
* calculated_value
)
4926 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4927 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4928 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
4930 // Find a GOT page entry that points to within 32KB of symbol + addend.
4931 Mips_address value
= (psymval
->value(object
, addend
) + 0x8000) & ~0xffff;
4932 unsigned int got_offset
=
4933 target
->got_section()->get_got_page_offset(value
, object
);
4935 Valtype x
= target
->got_section()->gp_offset(got_offset
, object
);
4936 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4940 *calculated_value
= x
;
4941 return This::STATUS_OKAY
;
4944 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4946 return check_overflow
<16>(x
);
4949 // R_MIPS_GOT_OFST, R_MICROMIPS_GOT_OFST
4950 static inline typename
This::Status
4951 relgotofst(Target_mips
<size
, big_endian
>* target
, unsigned char* view
,
4952 const Mips_relobj
<size
, big_endian
>* object
,
4953 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
4954 bool extract_addend
, bool local
, bool calculate_only
,
4955 Valtype
* calculated_value
)
4957 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4958 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
4959 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
4961 // For a local symbol, find a GOT page entry that points to within 32KB of
4962 // symbol + addend. Relocation value is the offset of the GOT page entry's
4963 // value from symbol + addend.
4964 // For a global symbol, relocation value is addend.
4968 // Find GOT page entry.
4969 Mips_address value
= ((psymval
->value(object
, addend
) + 0x8000)
4971 target
->got_section()->get_got_page_offset(value
, object
);
4973 x
= psymval
->value(object
, addend
) - value
;
4977 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
4981 *calculated_value
= x
;
4982 return This::STATUS_OKAY
;
4985 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
4987 return check_overflow
<16>(x
);
4990 // R_MIPS_GOT_HI16, R_MIPS_CALL_HI16,
4991 // R_MICROMIPS_GOT_HI16, R_MICROMIPS_CALL_HI16
4992 static inline typename
This::Status
4993 relgot_hi16(unsigned char* view
, int gp_offset
, bool calculate_only
,
4994 Valtype
* calculated_value
)
4996 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
4997 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4998 Valtype x
= gp_offset
;
4999 x
= ((x
+ 0x8000) >> 16) & 0xffff;
5000 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5003 *calculated_value
= x
;
5005 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5007 return This::STATUS_OKAY
;
5010 // R_MIPS_GOT_LO16, R_MIPS_CALL_LO16,
5011 // R_MICROMIPS_GOT_LO16, R_MICROMIPS_CALL_LO16
5012 static inline typename
This::Status
5013 relgot_lo16(unsigned char* view
, int gp_offset
, bool calculate_only
,
5014 Valtype
* calculated_value
)
5016 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5017 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5018 Valtype x
= gp_offset
;
5019 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5022 *calculated_value
= x
;
5024 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5026 return This::STATUS_OKAY
;
5029 // R_MIPS_GPREL16, R_MIPS16_GPREL, R_MIPS_LITERAL, R_MICROMIPS_LITERAL
5030 // R_MICROMIPS_GPREL7_S2, R_MICROMIPS_GPREL16
5031 static inline typename
This::Status
5032 relgprel(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5033 const Symbol_value
<size
>* psymval
, Mips_address gp
,
5034 Mips_address addend_a
, bool extract_addend
, bool local
,
5035 unsigned int r_type
, bool calculate_only
,
5036 Valtype
* calculated_value
)
5038 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5039 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5044 if (r_type
== elfcpp::R_MICROMIPS_GPREL7_S2
)
5045 addend
= (val
& 0x7f) << 2;
5047 addend
= val
& 0xffff;
5048 // Only sign-extend the addend if it was extracted from the
5049 // instruction. If the addend was separate, leave it alone,
5050 // otherwise we may lose significant bits.
5051 addend
= Bits
<16>::sign_extend32(addend
);
5056 Valtype x
= psymval
->value(object
, addend
) - gp
;
5058 // If the symbol was local, any earlier relocatable links will
5059 // have adjusted its addend with the gp offset, so compensate
5060 // for that now. Don't do it for symbols forced local in this
5061 // link, though, since they won't have had the gp offset applied
5064 x
+= object
->gp_value();
5066 if (r_type
== elfcpp::R_MICROMIPS_GPREL7_S2
)
5067 val
= Bits
<32>::bit_select32(val
, x
, 0x7f);
5069 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5073 *calculated_value
= x
;
5074 return This::STATUS_OKAY
;
5077 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5079 if (check_overflow
<16>(x
) == This::STATUS_OVERFLOW
)
5081 gold_error(_("small-data section exceeds 64KB; lower small-data size "
5082 "limit (see option -G)"));
5083 return This::STATUS_OVERFLOW
;
5085 return This::STATUS_OKAY
;
5089 static inline typename
This::Status
5090 relgprel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5091 const Symbol_value
<size
>* psymval
, Mips_address gp
,
5092 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5093 Valtype
* calculated_value
)
5095 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5096 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5097 Valtype addend
= extract_addend
? val
: addend_a
;
5099 // R_MIPS_GPREL32 relocations are defined for local symbols only.
5100 Valtype x
= psymval
->value(object
, addend
) + object
->gp_value() - gp
;
5103 *calculated_value
= x
;
5105 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5107 return This::STATUS_OKAY
;
5110 // R_MIPS_TLS_TPREL_HI16, R_MIPS16_TLS_TPREL_HI16, R_MICROMIPS_TLS_TPREL_HI16
5111 // R_MIPS_TLS_DTPREL_HI16, R_MIPS16_TLS_DTPREL_HI16,
5112 // R_MICROMIPS_TLS_DTPREL_HI16
5113 static inline typename
This::Status
5114 tlsrelhi16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5115 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5116 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5117 Valtype
* calculated_value
)
5119 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5120 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5121 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5123 // tls symbol values are relative to tls_segment()->vaddr()
5124 Valtype x
= ((psymval
->value(object
, addend
) - tp_offset
) + 0x8000) >> 16;
5125 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5128 *calculated_value
= x
;
5130 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5132 return This::STATUS_OKAY
;
5135 // R_MIPS_TLS_TPREL_LO16, R_MIPS16_TLS_TPREL_LO16, R_MICROMIPS_TLS_TPREL_LO16,
5136 // R_MIPS_TLS_DTPREL_LO16, R_MIPS16_TLS_DTPREL_LO16,
5137 // R_MICROMIPS_TLS_DTPREL_LO16,
5138 static inline typename
This::Status
5139 tlsrello16(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5140 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5141 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5142 Valtype
* calculated_value
)
5144 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5145 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5146 Valtype addend
= extract_addend
? val
& 0xffff : addend_a
;
5148 // tls symbol values are relative to tls_segment()->vaddr()
5149 Valtype x
= psymval
->value(object
, addend
) - tp_offset
;
5150 val
= Bits
<32>::bit_select32(val
, x
, 0xffff);
5153 *calculated_value
= x
;
5155 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
5157 return This::STATUS_OKAY
;
5160 // R_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL64,
5161 // R_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL64
5162 static inline typename
This::Status
5163 tlsrel32(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5164 const Symbol_value
<size
>* psymval
, Valtype32 tp_offset
,
5165 Mips_address addend_a
, bool extract_addend
, bool calculate_only
,
5166 Valtype
* calculated_value
)
5168 Valtype32
* wv
= reinterpret_cast<Valtype32
*>(view
);
5169 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5170 Valtype addend
= extract_addend
? val
: addend_a
;
5172 // tls symbol values are relative to tls_segment()->vaddr()
5173 Valtype x
= psymval
->value(object
, addend
) - tp_offset
;
5176 *calculated_value
= x
;
5178 elfcpp::Swap
<32, big_endian
>::writeval(wv
, x
);
5180 return This::STATUS_OKAY
;
5183 // R_MIPS_SUB, R_MICROMIPS_SUB
5184 static inline typename
This::Status
5185 relsub(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5186 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5187 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
)
5189 Valtype64
* wv
= reinterpret_cast<Valtype64
*>(view
);
5190 Valtype64 addend
= (extract_addend
5191 ? elfcpp::Swap
<64, big_endian
>::readval(wv
)
5194 Valtype64 x
= psymval
->value(object
, -addend
);
5196 *calculated_value
= x
;
5198 elfcpp::Swap
<64, big_endian
>::writeval(wv
, x
);
5200 return This::STATUS_OKAY
;
5204 static inline typename
This::Status
5205 rel64(unsigned char* view
, const Mips_relobj
<size
, big_endian
>* object
,
5206 const Symbol_value
<size
>* psymval
, Mips_address addend_a
,
5207 bool extract_addend
, bool calculate_only
, Valtype
* calculated_value
,
5208 bool apply_addend_only
)
5210 Valtype64
* wv
= reinterpret_cast<Valtype64
*>(view
);
5211 Valtype64 addend
= (extract_addend
5212 ? elfcpp::Swap
<64, big_endian
>::readval(wv
)
5215 Valtype64 x
= psymval
->value(object
, addend
);
5217 *calculated_value
= x
;
5220 if (apply_addend_only
)
5222 elfcpp::Swap
<64, big_endian
>::writeval(wv
, x
);
5225 return This::STATUS_OKAY
;
5230 template<int size
, bool big_endian
>
5231 typename
std::list
<reloc_high
<size
, big_endian
> >
5232 Mips_relocate_functions
<size
, big_endian
>::hi16_relocs
;
5234 template<int size
, bool big_endian
>
5235 typename
std::list
<reloc_high
<size
, big_endian
> >
5236 Mips_relocate_functions
<size
, big_endian
>::got16_relocs
;
5238 // Mips_got_info methods.
5240 // Reserve GOT entry for a GOT relocation of type R_TYPE against symbol
5241 // SYMNDX + ADDEND, where SYMNDX is a local symbol in section SHNDX in OBJECT.
5243 template<int size
, bool big_endian
>
5245 Mips_got_info
<size
, big_endian
>::record_local_got_symbol(
5246 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
,
5247 Mips_address addend
, unsigned int r_type
, unsigned int shndx
,
5248 bool is_section_symbol
)
5250 Mips_got_entry
<size
, big_endian
>* entry
=
5251 new Mips_got_entry
<size
, big_endian
>(object
, symndx
, addend
,
5252 mips_elf_reloc_tls_type(r_type
),
5253 shndx
, is_section_symbol
);
5254 this->record_got_entry(entry
, object
);
5257 // Reserve GOT entry for a GOT relocation of type R_TYPE against MIPS_SYM,
5258 // in OBJECT. FOR_CALL is true if the caller is only interested in
5259 // using the GOT entry for calls. DYN_RELOC is true if R_TYPE is a dynamic
5262 template<int size
, bool big_endian
>
5264 Mips_got_info
<size
, big_endian
>::record_global_got_symbol(
5265 Mips_symbol
<size
>* mips_sym
, Mips_relobj
<size
, big_endian
>* object
,
5266 unsigned int r_type
, bool dyn_reloc
, bool for_call
)
5269 mips_sym
->set_got_not_only_for_calls();
5271 // A global symbol in the GOT must also be in the dynamic symbol table.
5272 if (!mips_sym
->needs_dynsym_entry())
5274 switch (mips_sym
->visibility())
5276 case elfcpp::STV_INTERNAL
:
5277 case elfcpp::STV_HIDDEN
:
5278 mips_sym
->set_is_forced_local();
5281 mips_sym
->set_needs_dynsym_entry();
5286 unsigned char tls_type
= mips_elf_reloc_tls_type(r_type
);
5287 if (tls_type
== GOT_TLS_NONE
)
5288 this->global_got_symbols_
.insert(mips_sym
);
5292 if (mips_sym
->global_got_area() == GGA_NONE
)
5293 mips_sym
->set_global_got_area(GGA_RELOC_ONLY
);
5297 Mips_got_entry
<size
, big_endian
>* entry
=
5298 new Mips_got_entry
<size
, big_endian
>(mips_sym
, tls_type
);
5300 this->record_got_entry(entry
, object
);
5303 // Add ENTRY to master GOT and to OBJECT's GOT.
5305 template<int size
, bool big_endian
>
5307 Mips_got_info
<size
, big_endian
>::record_got_entry(
5308 Mips_got_entry
<size
, big_endian
>* entry
,
5309 Mips_relobj
<size
, big_endian
>* object
)
5311 this->got_entries_
.insert(entry
);
5313 // Create the GOT entry for the OBJECT's GOT.
5314 Mips_got_info
<size
, big_endian
>* g
= object
->get_or_create_got_info();
5315 Mips_got_entry
<size
, big_endian
>* entry2
=
5316 new Mips_got_entry
<size
, big_endian
>(*entry
);
5318 g
->got_entries_
.insert(entry2
);
5321 // Record that OBJECT has a page relocation against symbol SYMNDX and
5322 // that ADDEND is the addend for that relocation.
5323 // This function creates an upper bound on the number of GOT slots
5324 // required; no attempt is made to combine references to non-overridable
5325 // global symbols across multiple input files.
5327 template<int size
, bool big_endian
>
5329 Mips_got_info
<size
, big_endian
>::record_got_page_entry(
5330 Mips_relobj
<size
, big_endian
>* object
, unsigned int symndx
, int addend
)
5332 struct Got_page_range
**range_ptr
, *range
;
5333 int old_pages
, new_pages
;
5335 // Find the Got_page_entry for this symbol.
5336 Got_page_entry
* entry
= new Got_page_entry(object
, symndx
);
5337 typename
Got_page_entry_set::iterator it
=
5338 this->got_page_entries_
.find(entry
);
5339 if (it
!= this->got_page_entries_
.end())
5342 this->got_page_entries_
.insert(entry
);
5344 // Add the same entry to the OBJECT's GOT.
5345 Got_page_entry
* entry2
= NULL
;
5346 Mips_got_info
<size
, big_endian
>* g2
= object
->get_or_create_got_info();
5347 if (g2
->got_page_entries_
.find(entry
) == g2
->got_page_entries_
.end())
5349 entry2
= new Got_page_entry(*entry
);
5350 g2
->got_page_entries_
.insert(entry2
);
5353 // Skip over ranges whose maximum extent cannot share a page entry
5355 range_ptr
= &entry
->ranges
;
5356 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
5357 range_ptr
= &(*range_ptr
)->next
;
5359 // If we scanned to the end of the list, or found a range whose
5360 // minimum extent cannot share a page entry with ADDEND, create
5361 // a new singleton range.
5363 if (!range
|| addend
< range
->min_addend
- 0xffff)
5365 range
= new Got_page_range();
5366 range
->next
= *range_ptr
;
5367 range
->min_addend
= addend
;
5368 range
->max_addend
= addend
;
5373 ++entry2
->num_pages
;
5374 ++this->page_gotno_
;
5379 // Remember how many pages the old range contributed.
5380 old_pages
= range
->get_max_pages();
5382 // Update the ranges.
5383 if (addend
< range
->min_addend
)
5384 range
->min_addend
= addend
;
5385 else if (addend
> range
->max_addend
)
5387 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
5389 old_pages
+= range
->next
->get_max_pages();
5390 range
->max_addend
= range
->next
->max_addend
;
5391 range
->next
= range
->next
->next
;
5394 range
->max_addend
= addend
;
5397 // Record any change in the total estimate.
5398 new_pages
= range
->get_max_pages();
5399 if (old_pages
!= new_pages
)
5401 entry
->num_pages
+= new_pages
- old_pages
;
5403 entry2
->num_pages
+= new_pages
- old_pages
;
5404 this->page_gotno_
+= new_pages
- old_pages
;
5405 g2
->page_gotno_
+= new_pages
- old_pages
;
5409 // Create all entries that should be in the local part of the GOT.
5411 template<int size
, bool big_endian
>
5413 Mips_got_info
<size
, big_endian
>::add_local_entries(
5414 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5416 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5417 // First two GOT entries are reserved. The first entry will be filled at
5418 // runtime. The second entry will be used by some runtime loaders.
5419 got
->add_constant(0);
5420 got
->add_constant(target
->mips_elf_gnu_got1_mask());
5422 for (typename
Got_entry_set::iterator
5423 p
= this->got_entries_
.begin();
5424 p
!= this->got_entries_
.end();
5427 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5428 if (entry
->is_for_local_symbol() && !entry
->is_tls_entry())
5430 got
->add_local(entry
->object(), entry
->symndx(),
5431 GOT_TYPE_STANDARD
, entry
->addend());
5432 unsigned int got_offset
= entry
->object()->local_got_offset(
5433 entry
->symndx(), GOT_TYPE_STANDARD
, entry
->addend());
5434 if (got
->multi_got() && this->index_
> 0
5435 && parameters
->options().output_is_position_independent())
5437 if (!entry
->is_section_symbol())
5438 target
->rel_dyn_section(layout
)->add_local(entry
->object(),
5439 entry
->symndx(), elfcpp::R_MIPS_REL32
, got
, got_offset
);
5441 target
->rel_dyn_section(layout
)->add_symbolless_local_addend(
5442 entry
->object(), entry
->symndx(), elfcpp::R_MIPS_REL32
,
5448 this->add_page_entries(target
, layout
);
5450 // Add global entries that should be in the local area.
5451 for (typename
Got_entry_set::iterator
5452 p
= this->got_entries_
.begin();
5453 p
!= this->got_entries_
.end();
5456 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5457 if (!entry
->is_for_global_symbol())
5460 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5461 if (mips_sym
->global_got_area() == GGA_NONE
&& !entry
->is_tls_entry())
5463 unsigned int got_type
;
5464 if (!got
->multi_got())
5465 got_type
= GOT_TYPE_STANDARD
;
5467 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
5468 if (got
->add_global(mips_sym
, got_type
))
5470 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5471 if (got
->multi_got() && this->index_
> 0
5472 && parameters
->options().output_is_position_independent())
5473 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
5474 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
5475 mips_sym
->got_offset(got_type
));
5481 // Create GOT page entries.
5483 template<int size
, bool big_endian
>
5485 Mips_got_info
<size
, big_endian
>::add_page_entries(
5486 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5488 if (this->page_gotno_
== 0)
5491 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5492 this->got_page_offset_start_
= got
->add_constant(0);
5493 if (got
->multi_got() && this->index_
> 0
5494 && parameters
->options().output_is_position_independent())
5495 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
5496 this->got_page_offset_start_
);
5497 int num_entries
= this->page_gotno_
;
5498 unsigned int prev_offset
= this->got_page_offset_start_
;
5499 while (--num_entries
> 0)
5501 unsigned int next_offset
= got
->add_constant(0);
5502 if (got
->multi_got() && this->index_
> 0
5503 && parameters
->options().output_is_position_independent())
5504 target
->rel_dyn_section(layout
)->add_absolute(elfcpp::R_MIPS_REL32
, got
,
5506 gold_assert(next_offset
== prev_offset
+ size
/8);
5507 prev_offset
= next_offset
;
5509 this->got_page_offset_next_
= this->got_page_offset_start_
;
5512 // Create global GOT entries, both GGA_NORMAL and GGA_RELOC_ONLY.
5514 template<int size
, bool big_endian
>
5516 Mips_got_info
<size
, big_endian
>::add_global_entries(
5517 Target_mips
<size
, big_endian
>* target
, Layout
* layout
,
5518 unsigned int non_reloc_only_global_gotno
)
5520 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5521 // Add GGA_NORMAL entries.
5522 unsigned int count
= 0;
5523 for (typename
Got_entry_set::iterator
5524 p
= this->got_entries_
.begin();
5525 p
!= this->got_entries_
.end();
5528 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5529 if (!entry
->is_for_global_symbol())
5532 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5533 if (mips_sym
->global_got_area() != GGA_NORMAL
)
5536 unsigned int got_type
;
5537 if (!got
->multi_got())
5538 got_type
= GOT_TYPE_STANDARD
;
5540 // In multi-GOT links, global symbol can be in both primary and
5541 // secondary GOT(s). By creating custom GOT type
5542 // (GOT_TYPE_STANDARD_MULTIGOT + got_index) we ensure that symbol
5543 // is added to secondary GOT(s).
5544 got_type
= GOT_TYPE_STANDARD_MULTIGOT
+ this->index_
;
5545 if (!got
->add_global(mips_sym
, got_type
))
5548 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5549 if (got
->multi_got() && this->index_
== 0)
5551 if (got
->multi_got() && this->index_
> 0)
5553 if (parameters
->options().output_is_position_independent()
5554 || (!parameters
->doing_static_link()
5555 && mips_sym
->is_from_dynobj() && !mips_sym
->is_undefined()))
5557 target
->rel_dyn_section(layout
)->add_global(
5558 mips_sym
, elfcpp::R_MIPS_REL32
, got
,
5559 mips_sym
->got_offset(got_type
));
5560 got
->add_secondary_got_reloc(mips_sym
->got_offset(got_type
),
5561 elfcpp::R_MIPS_REL32
, mips_sym
);
5566 if (!got
->multi_got() || this->index_
== 0)
5568 if (got
->multi_got())
5570 // We need to allocate space in the primary GOT for GGA_NORMAL entries
5571 // of secondary GOTs, to ensure that GOT offsets of GGA_RELOC_ONLY
5572 // entries correspond to dynamic symbol indexes.
5573 while (count
< non_reloc_only_global_gotno
)
5575 got
->add_constant(0);
5580 // Add GGA_RELOC_ONLY entries.
5581 got
->add_reloc_only_entries();
5585 // Create global GOT entries that should be in the GGA_RELOC_ONLY area.
5587 template<int size
, bool big_endian
>
5589 Mips_got_info
<size
, big_endian
>::add_reloc_only_entries(
5590 Mips_output_data_got
<size
, big_endian
>* got
)
5592 for (typename
Global_got_entry_set::iterator
5593 p
= this->global_got_symbols_
.begin();
5594 p
!= this->global_got_symbols_
.end();
5597 Mips_symbol
<size
>* mips_sym
= *p
;
5598 if (mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
5600 unsigned int got_type
;
5601 if (!got
->multi_got())
5602 got_type
= GOT_TYPE_STANDARD
;
5604 got_type
= GOT_TYPE_STANDARD_MULTIGOT
;
5605 if (got
->add_global(mips_sym
, got_type
))
5606 mips_sym
->set_global_gotoffset(mips_sym
->got_offset(got_type
));
5611 // Create TLS GOT entries.
5613 template<int size
, bool big_endian
>
5615 Mips_got_info
<size
, big_endian
>::add_tls_entries(
5616 Target_mips
<size
, big_endian
>* target
, Layout
* layout
)
5618 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
5619 // Add local tls entries.
5620 for (typename
Got_entry_set::iterator
5621 p
= this->got_entries_
.begin();
5622 p
!= this->got_entries_
.end();
5625 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5626 if (!entry
->is_tls_entry() || !entry
->is_for_local_symbol())
5629 if (entry
->tls_type() == GOT_TLS_GD
)
5631 unsigned int got_type
= GOT_TYPE_TLS_PAIR
;
5632 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5633 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5634 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
5635 : elfcpp::R_MIPS_TLS_DTPREL64
);
5637 if (!parameters
->doing_static_link())
5639 got
->add_local_pair_with_rel(entry
->object(), entry
->symndx(),
5640 entry
->shndx(), got_type
,
5641 target
->rel_dyn_section(layout
),
5642 r_type1
, entry
->addend());
5643 unsigned int got_offset
=
5644 entry
->object()->local_got_offset(entry
->symndx(), got_type
,
5646 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
5647 entry
->object(), entry
->symndx());
5651 // We are doing a static link. Mark it as belong to module 1,
5653 unsigned int got_offset
= got
->add_constant(1);
5654 entry
->object()->set_local_got_offset(entry
->symndx(), got_type
,
5657 got
->add_constant(0);
5658 got
->add_static_reloc(got_offset
+ size
/8, r_type2
,
5659 entry
->object(), entry
->symndx());
5662 else if (entry
->tls_type() == GOT_TLS_IE
)
5664 unsigned int got_type
= GOT_TYPE_TLS_OFFSET
;
5665 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
5666 : elfcpp::R_MIPS_TLS_TPREL64
);
5667 if (!parameters
->doing_static_link())
5668 got
->add_local_with_rel(entry
->object(), entry
->symndx(), got_type
,
5669 target
->rel_dyn_section(layout
), r_type
,
5673 got
->add_local(entry
->object(), entry
->symndx(), got_type
,
5675 unsigned int got_offset
=
5676 entry
->object()->local_got_offset(entry
->symndx(), got_type
,
5678 got
->add_static_reloc(got_offset
, r_type
, entry
->object(),
5682 else if (entry
->tls_type() == GOT_TLS_LDM
)
5684 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5685 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5686 unsigned int got_offset
;
5687 if (!parameters
->doing_static_link())
5689 got_offset
= got
->add_constant(0);
5690 target
->rel_dyn_section(layout
)->add_local(
5691 entry
->object(), 0, r_type
, got
, got_offset
);
5694 // We are doing a static link. Just mark it as belong to module 1,
5696 got_offset
= got
->add_constant(1);
5698 got
->add_constant(0);
5699 got
->set_tls_ldm_offset(got_offset
, entry
->object());
5705 // Add global tls entries.
5706 for (typename
Got_entry_set::iterator
5707 p
= this->got_entries_
.begin();
5708 p
!= this->got_entries_
.end();
5711 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5712 if (!entry
->is_tls_entry() || !entry
->is_for_global_symbol())
5715 Mips_symbol
<size
>* mips_sym
= entry
->sym();
5716 if (entry
->tls_type() == GOT_TLS_GD
)
5718 unsigned int got_type
;
5719 if (!got
->multi_got())
5720 got_type
= GOT_TYPE_TLS_PAIR
;
5722 got_type
= GOT_TYPE_TLS_PAIR_MULTIGOT
+ this->index_
;
5723 unsigned int r_type1
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPMOD32
5724 : elfcpp::R_MIPS_TLS_DTPMOD64
);
5725 unsigned int r_type2
= (size
== 32 ? elfcpp::R_MIPS_TLS_DTPREL32
5726 : elfcpp::R_MIPS_TLS_DTPREL64
);
5727 if (!parameters
->doing_static_link())
5728 got
->add_global_pair_with_rel(mips_sym
, got_type
,
5729 target
->rel_dyn_section(layout
), r_type1
, r_type2
);
5732 // Add a GOT pair for for R_MIPS_TLS_GD. The creates a pair of
5733 // GOT entries. The first one is initialized to be 1, which is the
5734 // module index for the main executable and the second one 0. A
5735 // reloc of the type R_MIPS_TLS_DTPREL32/64 will be created for
5736 // the second GOT entry and will be applied by gold.
5737 unsigned int got_offset
= got
->add_constant(1);
5738 mips_sym
->set_got_offset(got_type
, got_offset
);
5739 got
->add_constant(0);
5740 got
->add_static_reloc(got_offset
+ size
/8, r_type2
, mips_sym
);
5743 else if (entry
->tls_type() == GOT_TLS_IE
)
5745 unsigned int got_type
;
5746 if (!got
->multi_got())
5747 got_type
= GOT_TYPE_TLS_OFFSET
;
5749 got_type
= GOT_TYPE_TLS_OFFSET_MULTIGOT
+ this->index_
;
5750 unsigned int r_type
= (size
== 32 ? elfcpp::R_MIPS_TLS_TPREL32
5751 : elfcpp::R_MIPS_TLS_TPREL64
);
5752 if (!parameters
->doing_static_link())
5753 got
->add_global_with_rel(mips_sym
, got_type
,
5754 target
->rel_dyn_section(layout
), r_type
);
5757 got
->add_global(mips_sym
, got_type
);
5758 unsigned int got_offset
= mips_sym
->got_offset(got_type
);
5759 got
->add_static_reloc(got_offset
, r_type
, mips_sym
);
5767 // Decide whether the symbol needs an entry in the global part of the primary
5768 // GOT, setting global_got_area accordingly. Count the number of global
5769 // symbols that are in the primary GOT only because they have dynamic
5770 // relocations R_MIPS_REL32 against them (reloc_only_gotno).
5772 template<int size
, bool big_endian
>
5774 Mips_got_info
<size
, big_endian
>::count_got_symbols(Symbol_table
* symtab
)
5776 for (typename
Global_got_entry_set::iterator
5777 p
= this->global_got_symbols_
.begin();
5778 p
!= this->global_got_symbols_
.end();
5781 Mips_symbol
<size
>* sym
= *p
;
5782 // Make a final decision about whether the symbol belongs in the
5783 // local or global GOT. Symbols that bind locally can (and in the
5784 // case of forced-local symbols, must) live in the local GOT.
5785 // Those that are aren't in the dynamic symbol table must also
5786 // live in the local GOT.
5788 if (!sym
->should_add_dynsym_entry(symtab
)
5789 || (sym
->got_only_for_calls()
5790 ? symbol_calls_local(sym
, sym
->should_add_dynsym_entry(symtab
))
5791 : symbol_references_local(sym
,
5792 sym
->should_add_dynsym_entry(symtab
))))
5793 // The symbol belongs in the local GOT. We no longer need this
5794 // entry if it was only used for relocations; those relocations
5795 // will be against the null or section symbol instead.
5796 sym
->set_global_got_area(GGA_NONE
);
5797 else if (sym
->global_got_area() == GGA_RELOC_ONLY
)
5799 ++this->reloc_only_gotno_
;
5800 ++this->global_gotno_
;
5805 // Return the offset of GOT page entry for VALUE. Initialize the entry with
5806 // VALUE if it is not initialized.
5808 template<int size
, bool big_endian
>
5810 Mips_got_info
<size
, big_endian
>::get_got_page_offset(Mips_address value
,
5811 Mips_output_data_got
<size
, big_endian
>* got
)
5813 typename
Got_page_offsets::iterator it
= this->got_page_offsets_
.find(value
);
5814 if (it
!= this->got_page_offsets_
.end())
5817 gold_assert(this->got_page_offset_next_
< this->got_page_offset_start_
5818 + (size
/8) * this->page_gotno_
);
5820 unsigned int got_offset
= this->got_page_offset_next_
;
5821 this->got_page_offsets_
[value
] = got_offset
;
5822 this->got_page_offset_next_
+= size
/8;
5823 got
->update_got_entry(got_offset
, value
);
5827 // Remove lazy-binding stubs for global symbols in this GOT.
5829 template<int size
, bool big_endian
>
5831 Mips_got_info
<size
, big_endian
>::remove_lazy_stubs(
5832 Target_mips
<size
, big_endian
>* target
)
5834 for (typename
Got_entry_set::iterator
5835 p
= this->got_entries_
.begin();
5836 p
!= this->got_entries_
.end();
5839 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5840 if (entry
->is_for_global_symbol())
5841 target
->remove_lazy_stub_entry(entry
->sym());
5845 // Count the number of GOT entries required.
5847 template<int size
, bool big_endian
>
5849 Mips_got_info
<size
, big_endian
>::count_got_entries()
5851 for (typename
Got_entry_set::iterator
5852 p
= this->got_entries_
.begin();
5853 p
!= this->got_entries_
.end();
5856 this->count_got_entry(*p
);
5860 // Count the number of GOT entries required by ENTRY. Accumulate the result.
5862 template<int size
, bool big_endian
>
5864 Mips_got_info
<size
, big_endian
>::count_got_entry(
5865 Mips_got_entry
<size
, big_endian
>* entry
)
5867 if (entry
->is_tls_entry())
5868 this->tls_gotno_
+= mips_tls_got_entries(entry
->tls_type());
5869 else if (entry
->is_for_local_symbol()
5870 || entry
->sym()->global_got_area() == GGA_NONE
)
5871 ++this->local_gotno_
;
5873 ++this->global_gotno_
;
5876 // Add FROM's GOT entries.
5878 template<int size
, bool big_endian
>
5880 Mips_got_info
<size
, big_endian
>::add_got_entries(
5881 Mips_got_info
<size
, big_endian
>* from
)
5883 for (typename
Got_entry_set::iterator
5884 p
= from
->got_entries_
.begin();
5885 p
!= from
->got_entries_
.end();
5888 Mips_got_entry
<size
, big_endian
>* entry
= *p
;
5889 if (this->got_entries_
.find(entry
) == this->got_entries_
.end())
5891 Mips_got_entry
<size
, big_endian
>* entry2
=
5892 new Mips_got_entry
<size
, big_endian
>(*entry
);
5893 this->got_entries_
.insert(entry2
);
5894 this->count_got_entry(entry
);
5899 // Add FROM's GOT page entries.
5901 template<int size
, bool big_endian
>
5903 Mips_got_info
<size
, big_endian
>::add_got_page_entries(
5904 Mips_got_info
<size
, big_endian
>* from
)
5906 for (typename
Got_page_entry_set::iterator
5907 p
= from
->got_page_entries_
.begin();
5908 p
!= from
->got_page_entries_
.end();
5911 Got_page_entry
* entry
= *p
;
5912 if (this->got_page_entries_
.find(entry
) == this->got_page_entries_
.end())
5914 Got_page_entry
* entry2
= new Got_page_entry(*entry
);
5915 this->got_page_entries_
.insert(entry2
);
5916 this->page_gotno_
+= entry
->num_pages
;
5921 // Mips_output_data_got methods.
5923 // Lay out the GOT. Add local, global and TLS entries. If GOT is
5924 // larger than 64K, create multi-GOT.
5926 template<int size
, bool big_endian
>
5928 Mips_output_data_got
<size
, big_endian
>::lay_out_got(Layout
* layout
,
5929 Symbol_table
* symtab
, const Input_objects
* input_objects
)
5931 // Decide which symbols need to go in the global part of the GOT and
5932 // count the number of reloc-only GOT symbols.
5933 this->master_got_info_
->count_got_symbols(symtab
);
5935 // Count the number of GOT entries.
5936 this->master_got_info_
->count_got_entries();
5938 unsigned int got_size
= this->master_got_info_
->got_size();
5939 if (got_size
> Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
)
5940 this->lay_out_multi_got(layout
, input_objects
);
5943 // Record that all objects use single GOT.
5944 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
5945 p
!= input_objects
->relobj_end();
5948 Mips_relobj
<size
, big_endian
>* object
=
5949 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
5950 if (object
->get_got_info() != NULL
)
5951 object
->set_got_info(this->master_got_info_
);
5954 this->master_got_info_
->add_local_entries(this->target_
, layout
);
5955 this->master_got_info_
->add_global_entries(this->target_
, layout
,
5957 this->master_got_info_
->add_tls_entries(this->target_
, layout
);
5961 // Create multi-GOT. For every GOT, add local, global and TLS entries.
5963 template<int size
, bool big_endian
>
5965 Mips_output_data_got
<size
, big_endian
>::lay_out_multi_got(Layout
* layout
,
5966 const Input_objects
* input_objects
)
5968 // Try to merge the GOTs of input objects together, as long as they
5969 // don't seem to exceed the maximum GOT size, choosing one of them
5970 // to be the primary GOT.
5971 this->merge_gots(input_objects
);
5973 // Every symbol that is referenced in a dynamic relocation must be
5974 // present in the primary GOT.
5975 this->primary_got_
->set_global_gotno(this->master_got_info_
->global_gotno());
5979 unsigned int offset
= 0;
5980 Mips_got_info
<size
, big_endian
>* g
= this->primary_got_
;
5984 g
->set_offset(offset
);
5986 g
->add_local_entries(this->target_
, layout
);
5988 g
->add_global_entries(this->target_
, layout
,
5989 (this->master_got_info_
->global_gotno()
5990 - this->master_got_info_
->reloc_only_gotno()));
5992 g
->add_global_entries(this->target_
, layout
, /*not used*/-1U);
5993 g
->add_tls_entries(this->target_
, layout
);
5995 // Forbid global symbols in every non-primary GOT from having
5996 // lazy-binding stubs.
5998 g
->remove_lazy_stubs(this->target_
);
6001 offset
+= g
->got_size();
6007 // Attempt to merge GOTs of different input objects. Try to use as much as
6008 // possible of the primary GOT, since it doesn't require explicit dynamic
6009 // relocations, but don't use objects that would reference global symbols
6010 // out of the addressable range. Failing the primary GOT, attempt to merge
6011 // with the current GOT, or finish the current GOT and then make make the new
6014 template<int size
, bool big_endian
>
6016 Mips_output_data_got
<size
, big_endian
>::merge_gots(
6017 const Input_objects
* input_objects
)
6019 gold_assert(this->primary_got_
== NULL
);
6020 Mips_got_info
<size
, big_endian
>* current
= NULL
;
6022 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
6023 p
!= input_objects
->relobj_end();
6026 Mips_relobj
<size
, big_endian
>* object
=
6027 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
6029 Mips_got_info
<size
, big_endian
>* g
= object
->get_got_info();
6033 g
->count_got_entries();
6035 // Work out the number of page, local and TLS entries.
6036 unsigned int estimate
= this->master_got_info_
->page_gotno();
6037 if (estimate
> g
->page_gotno())
6038 estimate
= g
->page_gotno();
6039 estimate
+= g
->local_gotno() + g
->tls_gotno();
6041 // We place TLS GOT entries after both locals and globals. The globals
6042 // for the primary GOT may overflow the normal GOT size limit, so be
6043 // sure not to merge a GOT which requires TLS with the primary GOT in that
6044 // case. This doesn't affect non-primary GOTs.
6045 estimate
+= (g
->tls_gotno() > 0 ? this->master_got_info_
->global_gotno()
6046 : g
->global_gotno());
6048 unsigned int max_count
=
6049 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
6050 if (estimate
<= max_count
)
6052 // If we don't have a primary GOT, use it as
6053 // a starting point for the primary GOT.
6054 if (!this->primary_got_
)
6056 this->primary_got_
= g
;
6060 // Try merging with the primary GOT.
6061 if (this->merge_got_with(g
, object
, this->primary_got_
))
6065 // If we can merge with the last-created GOT, do it.
6066 if (current
&& this->merge_got_with(g
, object
, current
))
6069 // Well, we couldn't merge, so create a new GOT. Don't check if it
6070 // fits; if it turns out that it doesn't, we'll get relocation
6071 // overflows anyway.
6072 g
->set_next(current
);
6076 // If we do not find any suitable primary GOT, create an empty one.
6077 if (this->primary_got_
== NULL
)
6078 this->primary_got_
= new Mips_got_info
<size
, big_endian
>();
6080 // Link primary GOT with secondary GOTs.
6081 this->primary_got_
->set_next(current
);
6084 // Consider merging FROM, which is OBJECT's GOT, into TO. Return false if
6085 // this would lead to overflow, true if they were merged successfully.
6087 template<int size
, bool big_endian
>
6089 Mips_output_data_got
<size
, big_endian
>::merge_got_with(
6090 Mips_got_info
<size
, big_endian
>* from
,
6091 Mips_relobj
<size
, big_endian
>* object
,
6092 Mips_got_info
<size
, big_endian
>* to
)
6094 // Work out how many page entries we would need for the combined GOT.
6095 unsigned int estimate
= this->master_got_info_
->page_gotno();
6096 if (estimate
>= from
->page_gotno() + to
->page_gotno())
6097 estimate
= from
->page_gotno() + to
->page_gotno();
6099 // Conservatively estimate how many local and TLS entries would be needed.
6100 estimate
+= from
->local_gotno() + to
->local_gotno();
6101 estimate
+= from
->tls_gotno() + to
->tls_gotno();
6103 // If we're merging with the primary got, any TLS relocations will
6104 // come after the full set of global entries. Otherwise estimate those
6105 // conservatively as well.
6106 if (to
== this->primary_got_
&& (from
->tls_gotno() + to
->tls_gotno()) > 0)
6107 estimate
+= this->master_got_info_
->global_gotno();
6109 estimate
+= from
->global_gotno() + to
->global_gotno();
6111 // Bail out if the combined GOT might be too big.
6112 unsigned int max_count
=
6113 Target_mips
<size
, big_endian
>::MIPS_GOT_MAX_SIZE
/ (size
/8) - 2;
6114 if (estimate
> max_count
)
6117 // Transfer the object's GOT information from FROM to TO.
6118 to
->add_got_entries(from
);
6119 to
->add_got_page_entries(from
);
6121 // Record that OBJECT should use output GOT TO.
6122 object
->set_got_info(to
);
6127 // Write out the GOT.
6129 template<int size
, bool big_endian
>
6131 Mips_output_data_got
<size
, big_endian
>::do_write(Output_file
* of
)
6133 typedef Unordered_set
<Mips_symbol
<size
>*, Mips_symbol_hash
<size
> >
6134 Mips_stubs_entry_set
;
6136 // Call parent to write out GOT.
6137 Output_data_got
<size
, big_endian
>::do_write(of
);
6139 const off_t offset
= this->offset();
6140 const section_size_type oview_size
=
6141 convert_to_section_size_type(this->data_size());
6142 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6144 // Needed for fixing values of .got section.
6145 this->got_view_
= oview
;
6147 // Write lazy stub addresses.
6148 for (typename
Mips_stubs_entry_set::iterator
6149 p
= this->master_got_info_
->global_got_symbols().begin();
6150 p
!= this->master_got_info_
->global_got_symbols().end();
6153 Mips_symbol
<size
>* mips_sym
= *p
;
6154 if (mips_sym
->has_lazy_stub())
6156 Valtype
* wv
= reinterpret_cast<Valtype
*>(
6157 oview
+ this->get_primary_got_offset(mips_sym
));
6159 this->target_
->mips_stubs_section()->stub_address(mips_sym
);
6160 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
6164 // Add +1 to GGA_NONE nonzero MIPS16 and microMIPS entries.
6165 for (typename
Mips_stubs_entry_set::iterator
6166 p
= this->master_got_info_
->global_got_symbols().begin();
6167 p
!= this->master_got_info_
->global_got_symbols().end();
6170 Mips_symbol
<size
>* mips_sym
= *p
;
6171 if (!this->multi_got()
6172 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
6173 && mips_sym
->global_got_area() == GGA_NONE
6174 && mips_sym
->has_got_offset(GOT_TYPE_STANDARD
))
6176 Valtype
* wv
= reinterpret_cast<Valtype
*>(
6177 oview
+ mips_sym
->got_offset(GOT_TYPE_STANDARD
));
6178 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv
);
6182 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
6187 if (!this->secondary_got_relocs_
.empty())
6189 // Fixup for the secondary GOT R_MIPS_REL32 relocs. For global
6190 // secondary GOT entries with non-zero initial value copy the value
6191 // to the corresponding primary GOT entry, and set the secondary GOT
6193 // TODO(sasa): This is workaround. It needs to be investigated further.
6195 for (size_t i
= 0; i
< this->secondary_got_relocs_
.size(); ++i
)
6197 Static_reloc
& reloc(this->secondary_got_relocs_
[i
]);
6198 if (reloc
.symbol_is_global())
6200 Mips_symbol
<size
>* gsym
= reloc
.symbol();
6201 gold_assert(gsym
!= NULL
);
6203 unsigned got_offset
= reloc
.got_offset();
6204 gold_assert(got_offset
< oview_size
);
6206 // Find primary GOT entry.
6207 Valtype
* wv_prim
= reinterpret_cast<Valtype
*>(
6208 oview
+ this->get_primary_got_offset(gsym
));
6210 // Find secondary GOT entry.
6211 Valtype
* wv_sec
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6213 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv_sec
);
6216 elfcpp::Swap
<size
, big_endian
>::writeval(wv_prim
, value
);
6217 elfcpp::Swap
<size
, big_endian
>::writeval(wv_sec
, 0);
6218 gsym
->set_applied_secondary_got_fixup();
6223 of
->write_output_view(offset
, oview_size
, oview
);
6226 // We are done if there is no fix up.
6227 if (this->static_relocs_
.empty())
6230 Output_segment
* tls_segment
= this->layout_
->tls_segment();
6231 gold_assert(tls_segment
!= NULL
);
6233 for (size_t i
= 0; i
< this->static_relocs_
.size(); ++i
)
6235 Static_reloc
& reloc(this->static_relocs_
[i
]);
6238 if (!reloc
.symbol_is_global())
6240 Sized_relobj_file
<size
, big_endian
>* object
= reloc
.relobj();
6241 const Symbol_value
<size
>* psymval
=
6242 object
->local_symbol(reloc
.index());
6244 // We are doing static linking. Issue an error and skip this
6245 // relocation if the symbol is undefined or in a discarded_section.
6247 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
6248 if ((shndx
== elfcpp::SHN_UNDEF
)
6250 && shndx
!= elfcpp::SHN_UNDEF
6251 && !object
->is_section_included(shndx
)
6252 && !this->symbol_table_
->is_section_folded(object
, shndx
)))
6254 gold_error(_("undefined or discarded local symbol %u from "
6255 " object %s in GOT"),
6256 reloc
.index(), reloc
.relobj()->name().c_str());
6260 value
= psymval
->value(object
, 0);
6264 const Mips_symbol
<size
>* gsym
= reloc
.symbol();
6265 gold_assert(gsym
!= NULL
);
6267 // We are doing static linking. Issue an error and skip this
6268 // relocation if the symbol is undefined or in a discarded_section
6269 // unless it is a weakly_undefined symbol.
6270 if ((gsym
->is_defined_in_discarded_section() || gsym
->is_undefined())
6271 && !gsym
->is_weak_undefined())
6273 gold_error(_("undefined or discarded symbol %s in GOT"),
6278 if (!gsym
->is_weak_undefined())
6279 value
= gsym
->value();
6284 unsigned got_offset
= reloc
.got_offset();
6285 gold_assert(got_offset
< oview_size
);
6287 Valtype
* wv
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6290 switch (reloc
.r_type())
6292 case elfcpp::R_MIPS_TLS_DTPMOD32
:
6293 case elfcpp::R_MIPS_TLS_DTPMOD64
:
6296 case elfcpp::R_MIPS_TLS_DTPREL32
:
6297 case elfcpp::R_MIPS_TLS_DTPREL64
:
6298 x
= value
- elfcpp::DTP_OFFSET
;
6300 case elfcpp::R_MIPS_TLS_TPREL32
:
6301 case elfcpp::R_MIPS_TLS_TPREL64
:
6302 x
= value
- elfcpp::TP_OFFSET
;
6309 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, x
);
6312 of
->write_output_view(offset
, oview_size
, oview
);
6315 // Mips_relobj methods.
6317 // Count the local symbols. The Mips backend needs to know if a symbol
6318 // is a MIPS16 or microMIPS function or not. For global symbols, it is easy
6319 // because the Symbol object keeps the ELF symbol type and st_other field.
6320 // For local symbol it is harder because we cannot access this information.
6321 // So we override the do_count_local_symbol in parent and scan local symbols to
6322 // mark MIPS16 and microMIPS functions. This is not the most efficient way but
6323 // I do not want to slow down other ports by calling a per symbol target hook
6324 // inside Sized_relobj_file<size, big_endian>::do_count_local_symbols.
6326 template<int size
, bool big_endian
>
6328 Mips_relobj
<size
, big_endian
>::do_count_local_symbols(
6329 Stringpool_template
<char>* pool
,
6330 Stringpool_template
<char>* dynpool
)
6332 // Ask parent to count the local symbols.
6333 Sized_relobj_file
<size
, big_endian
>::do_count_local_symbols(pool
, dynpool
);
6334 const unsigned int loccount
= this->local_symbol_count();
6338 // Initialize the mips16 and micromips function bit-vector.
6339 this->local_symbol_is_mips16_
.resize(loccount
, false);
6340 this->local_symbol_is_micromips_
.resize(loccount
, false);
6342 // Read the symbol table section header.
6343 const unsigned int symtab_shndx
= this->symtab_shndx();
6344 elfcpp::Shdr
<size
, big_endian
>
6345 symtabshdr(this, this->elf_file()->section_header(symtab_shndx
));
6346 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
6348 // Read the local symbols.
6349 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
6350 gold_assert(loccount
== symtabshdr
.get_sh_info());
6351 off_t locsize
= loccount
* sym_size
;
6352 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
6353 locsize
, true, true);
6355 // Loop over the local symbols and mark any MIPS16 or microMIPS local symbols.
6357 // Skip the first dummy symbol.
6359 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
6361 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
6362 unsigned char st_other
= sym
.get_st_other();
6363 this->local_symbol_is_mips16_
[i
] = elfcpp::elf_st_is_mips16(st_other
);
6364 this->local_symbol_is_micromips_
[i
] =
6365 elfcpp::elf_st_is_micromips(st_other
);
6369 // Read the symbol information.
6371 template<int size
, bool big_endian
>
6373 Mips_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
6375 // Call parent class to read symbol information.
6376 this->base_read_symbols(sd
);
6378 // Read processor-specific flags in ELF file header.
6379 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
6380 elfcpp::Elf_sizes
<size
>::ehdr_size
,
6382 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
6383 this->processor_specific_flags_
= ehdr
.get_e_flags();
6385 // Get the section names.
6386 const unsigned char* pnamesu
= sd
->section_names
->data();
6387 const char* pnames
= reinterpret_cast<const char*>(pnamesu
);
6389 // Initialize the mips16 stub section bit-vectors.
6390 this->section_is_mips16_fn_stub_
.resize(this->shnum(), false);
6391 this->section_is_mips16_call_stub_
.resize(this->shnum(), false);
6392 this->section_is_mips16_call_fp_stub_
.resize(this->shnum(), false);
6394 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
6395 const unsigned char* pshdrs
= sd
->section_headers
->data();
6396 const unsigned char* ps
= pshdrs
+ shdr_size
;
6397 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
6399 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
6401 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_REGINFO
)
6403 // Read the gp value that was used to create this object. We need the
6404 // gp value while processing relocs. The .reginfo section is not used
6405 // in the 64-bit MIPS ELF ABI.
6406 section_offset_type section_offset
= shdr
.get_sh_offset();
6407 section_size_type section_size
=
6408 convert_to_section_size_type(shdr
.get_sh_size());
6409 const unsigned char* view
=
6410 this->get_view(section_offset
, section_size
, true, false);
6412 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 20);
6414 // Read the rest of .reginfo.
6415 this->gprmask_
= elfcpp::Swap
<size
, big_endian
>::readval(view
);
6416 this->cprmask1_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 4);
6417 this->cprmask2_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 8);
6418 this->cprmask3_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 12);
6419 this->cprmask4_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 16);
6422 // In the 64-bit ABI, .MIPS.options section holds register information.
6423 // A SHT_MIPS_OPTIONS section contains a series of options, each of which
6424 // starts with this header:
6428 // // Type of option.
6429 // unsigned char kind[1];
6430 // // Size of option descriptor, including header.
6431 // unsigned char size[1];
6432 // // Section index of affected section, or 0 for global option.
6433 // unsigned char section[2];
6434 // // Information specific to this kind of option.
6435 // unsigned char info[4];
6438 // For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and set
6439 // the gp value based on what we find. We may see both SHT_MIPS_REGINFO
6440 // and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case, they should agree.
6442 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_OPTIONS
)
6444 section_offset_type section_offset
= shdr
.get_sh_offset();
6445 section_size_type section_size
=
6446 convert_to_section_size_type(shdr
.get_sh_size());
6447 const unsigned char* view
=
6448 this->get_view(section_offset
, section_size
, true, false);
6449 const unsigned char* end
= view
+ section_size
;
6451 while (view
+ 8 <= end
)
6453 unsigned char kind
= elfcpp::Swap
<8, big_endian
>::readval(view
);
6454 unsigned char sz
= elfcpp::Swap
<8, big_endian
>::readval(view
+ 1);
6457 gold_error(_("%s: Warning: bad `%s' option size %u smaller "
6459 this->name().c_str(),
6460 this->mips_elf_options_section_name(), sz
);
6464 if (this->is_n64() && kind
== elfcpp::ODK_REGINFO
)
6466 // In the 64 bit ABI, an ODK_REGINFO option is the following
6467 // structure. The info field of the options header is not
6472 // // Mask of general purpose registers used.
6473 // unsigned char ri_gprmask[4];
6475 // unsigned char ri_pad[4];
6476 // // Mask of co-processor registers used.
6477 // unsigned char ri_cprmask[4][4];
6478 // // GP register value for this object file.
6479 // unsigned char ri_gp_value[8];
6482 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
6485 else if (kind
== elfcpp::ODK_REGINFO
)
6487 // In the 32 bit ABI, an ODK_REGINFO option is the following
6488 // structure. The info field of the options header is not
6489 // used. The same structure is used in .reginfo section.
6493 // unsigned char ri_gprmask[4];
6494 // unsigned char ri_cprmask[4][4];
6495 // unsigned char ri_gp_value[4];
6498 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
6505 const char* name
= pnames
+ shdr
.get_sh_name();
6506 this->section_is_mips16_fn_stub_
[i
] = is_prefix_of(".mips16.fn", name
);
6507 this->section_is_mips16_call_stub_
[i
] =
6508 is_prefix_of(".mips16.call.", name
);
6509 this->section_is_mips16_call_fp_stub_
[i
] =
6510 is_prefix_of(".mips16.call.fp.", name
);
6512 if (strcmp(name
, ".pdr") == 0)
6514 gold_assert(this->pdr_shndx_
== -1U);
6515 this->pdr_shndx_
= i
;
6520 // Discard MIPS16 stub secions that are not needed.
6522 template<int size
, bool big_endian
>
6524 Mips_relobj
<size
, big_endian
>::discard_mips16_stub_sections(Symbol_table
* symtab
)
6526 for (typename
Mips16_stubs_int_map::const_iterator
6527 it
= this->mips16_stub_sections_
.begin();
6528 it
!= this->mips16_stub_sections_
.end(); ++it
)
6530 Mips16_stub_section
<size
, big_endian
>* stub_section
= it
->second
;
6531 if (!stub_section
->is_target_found())
6533 gold_error(_("no relocation found in mips16 stub section '%s'"),
6534 stub_section
->object()
6535 ->section_name(stub_section
->shndx()).c_str());
6538 bool discard
= false;
6539 if (stub_section
->is_for_local_function())
6541 if (stub_section
->is_fn_stub())
6543 // This stub is for a local symbol. This stub will only
6544 // be needed if there is some relocation in this object,
6545 // other than a 16 bit function call, which refers to this
6547 if (!this->has_local_non_16bit_call_relocs(stub_section
->r_sym()))
6550 this->add_local_mips16_fn_stub(stub_section
);
6554 // This stub is for a local symbol. This stub will only
6555 // be needed if there is some relocation (R_MIPS16_26) in
6556 // this object that refers to this symbol.
6557 gold_assert(stub_section
->is_call_stub()
6558 || stub_section
->is_call_fp_stub());
6559 if (!this->has_local_16bit_call_relocs(stub_section
->r_sym()))
6562 this->add_local_mips16_call_stub(stub_section
);
6567 Mips_symbol
<size
>* gsym
= stub_section
->gsym();
6568 if (stub_section
->is_fn_stub())
6570 if (gsym
->has_mips16_fn_stub())
6571 // We already have a stub for this function.
6575 gsym
->set_mips16_fn_stub(stub_section
);
6576 if (gsym
->should_add_dynsym_entry(symtab
))
6578 // If we have a MIPS16 function with a stub, the
6579 // dynamic symbol must refer to the stub, since only
6580 // the stub uses the standard calling conventions.
6581 gsym
->set_need_fn_stub();
6582 if (gsym
->is_from_dynobj())
6583 gsym
->set_needs_dynsym_value();
6586 if (!gsym
->need_fn_stub())
6589 else if (stub_section
->is_call_stub())
6591 if (gsym
->is_mips16())
6592 // We don't need the call_stub; this is a 16 bit
6593 // function, so calls from other 16 bit functions are
6596 else if (gsym
->has_mips16_call_stub())
6597 // We already have a stub for this function.
6600 gsym
->set_mips16_call_stub(stub_section
);
6604 gold_assert(stub_section
->is_call_fp_stub());
6605 if (gsym
->is_mips16())
6606 // We don't need the call_stub; this is a 16 bit
6607 // function, so calls from other 16 bit functions are
6610 else if (gsym
->has_mips16_call_fp_stub())
6611 // We already have a stub for this function.
6614 gsym
->set_mips16_call_fp_stub(stub_section
);
6618 this->set_output_section(stub_section
->shndx(), NULL
);
6622 // Mips_output_data_la25_stub methods.
6624 // Template for standard LA25 stub.
6625 template<int size
, bool big_endian
>
6627 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_entry
[] =
6629 0x3c190000, // lui $25,%hi(func)
6630 0x08000000, // j func
6631 0x27390000, // add $25,$25,%lo(func)
6635 // Template for microMIPS LA25 stub.
6636 template<int size
, bool big_endian
>
6638 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_micromips_entry
[] =
6640 0x41b9, 0x0000, // lui t9,%hi(func)
6641 0xd400, 0x0000, // j func
6642 0x3339, 0x0000, // addiu t9,t9,%lo(func)
6643 0x0000, 0x0000 // nop
6646 // Create la25 stub for a symbol.
6648 template<int size
, bool big_endian
>
6650 Mips_output_data_la25_stub
<size
, big_endian
>::create_la25_stub(
6651 Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
6652 Mips_symbol
<size
>* gsym
)
6654 if (!gsym
->has_la25_stub())
6656 gsym
->set_la25_stub_offset(this->symbols_
.size() * 16);
6657 this->symbols_
.push_back(gsym
);
6658 this->create_stub_symbol(gsym
, symtab
, target
, 16);
6662 // Create a symbol for SYM stub's value and size, to help make the disassembly
6665 template<int size
, bool big_endian
>
6667 Mips_output_data_la25_stub
<size
, big_endian
>::create_stub_symbol(
6668 Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
6669 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
)
6671 std::string
name(".pic.");
6672 name
+= sym
->name();
6674 unsigned int offset
= sym
->la25_stub_offset();
6675 if (sym
->is_micromips())
6678 // Make it a local function.
6679 Symbol
* new_sym
= symtab
->define_in_output_data(name
.c_str(), NULL
,
6680 Symbol_table::PREDEFINED
,
6681 target
->la25_stub_section(),
6682 offset
, symsize
, elfcpp::STT_FUNC
,
6684 elfcpp::STV_DEFAULT
, 0,
6686 new_sym
->set_is_forced_local();
6689 // Write out la25 stubs. This uses the hand-coded instructions above,
6690 // and adjusts them as needed.
6692 template<int size
, bool big_endian
>
6694 Mips_output_data_la25_stub
<size
, big_endian
>::do_write(Output_file
* of
)
6696 const off_t offset
= this->offset();
6697 const section_size_type oview_size
=
6698 convert_to_section_size_type(this->data_size());
6699 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6701 for (typename
std::vector
<Mips_symbol
<size
>*>::iterator
6702 p
= this->symbols_
.begin();
6703 p
!= this->symbols_
.end();
6706 Mips_symbol
<size
>* sym
= *p
;
6707 unsigned char* pov
= oview
+ sym
->la25_stub_offset();
6709 Mips_address target
= sym
->value();
6710 if (!sym
->is_micromips())
6712 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
6713 la25_stub_entry
[0] | (((target
+ 0x8000) >> 16) & 0xffff));
6714 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
6715 la25_stub_entry
[1] | ((target
>> 2) & 0x3ffffff));
6716 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
6717 la25_stub_entry
[2] | (target
& 0xffff));
6718 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12, la25_stub_entry
[3]);
6723 // First stub instruction. Paste high 16-bits of the target.
6724 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
6725 la25_stub_micromips_entry
[0]);
6726 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
6727 ((target
+ 0x8000) >> 16) & 0xffff);
6728 // Second stub instruction. Paste low 26-bits of the target, shifted
6730 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
6731 la25_stub_micromips_entry
[2] | ((target
>> 17) & 0x3ff));
6732 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
6733 la25_stub_micromips_entry
[3] | ((target
>> 1) & 0xffff));
6734 // Third stub instruction. Paste low 16-bits of the target.
6735 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8,
6736 la25_stub_micromips_entry
[4]);
6737 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, target
& 0xffff);
6738 // Fourth stub instruction.
6739 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 12,
6740 la25_stub_micromips_entry
[6]);
6741 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 14,
6742 la25_stub_micromips_entry
[7]);
6746 of
->write_output_view(offset
, oview_size
, oview
);
6749 // Mips_output_data_plt methods.
6751 // The format of the first PLT entry in an O32 executable.
6752 template<int size
, bool big_endian
>
6753 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_o32
[] =
6755 0x3c1c0000, // lui $28, %hi(&GOTPLT[0])
6756 0x8f990000, // lw $25, %lo(&GOTPLT[0])($28)
6757 0x279c0000, // addiu $28, $28, %lo(&GOTPLT[0])
6758 0x031cc023, // subu $24, $24, $28
6759 0x03e07825, // or $15, $31, zero
6760 0x0018c082, // srl $24, $24, 2
6761 0x0320f809, // jalr $25
6762 0x2718fffe // subu $24, $24, 2
6765 // The format of the first PLT entry in an N32 executable. Different
6766 // because gp ($28) is not available; we use t2 ($14) instead.
6767 template<int size
, bool big_endian
>
6768 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n32
[] =
6770 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
6771 0x8dd90000, // lw $25, %lo(&GOTPLT[0])($14)
6772 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
6773 0x030ec023, // subu $24, $24, $14
6774 0x03e07825, // or $15, $31, zero
6775 0x0018c082, // srl $24, $24, 2
6776 0x0320f809, // jalr $25
6777 0x2718fffe // subu $24, $24, 2
6780 // The format of the first PLT entry in an N64 executable. Different
6781 // from N32 because of the increased size of GOT entries.
6782 template<int size
, bool big_endian
>
6783 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n64
[] =
6785 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
6786 0xddd90000, // ld $25, %lo(&GOTPLT[0])($14)
6787 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
6788 0x030ec023, // subu $24, $24, $14
6789 0x03e07825, // or $15, $31, zero
6790 0x0018c0c2, // srl $24, $24, 3
6791 0x0320f809, // jalr $25
6792 0x2718fffe // subu $24, $24, 2
6795 // The format of the microMIPS first PLT entry in an O32 executable.
6796 // We rely on v0 ($2) rather than t8 ($24) to contain the address
6797 // of the GOTPLT entry handled, so this stub may only be used when
6798 // all the subsequent PLT entries are microMIPS code too.
6800 // The trailing NOP is for alignment and correct disassembly only.
6801 template<int size
, bool big_endian
>
6802 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6803 plt0_entry_micromips_o32
[] =
6805 0x7980, 0x0000, // addiupc $3, (&GOTPLT[0]) - .
6806 0xff23, 0x0000, // lw $25, 0($3)
6807 0x0535, // subu $2, $2, $3
6808 0x2525, // srl $2, $2, 2
6809 0x3302, 0xfffe, // subu $24, $2, 2
6810 0x0dff, // move $15, $31
6811 0x45f9, // jalrs $25
6812 0x0f83, // move $28, $3
6816 // The format of the microMIPS first PLT entry in an O32 executable
6817 // in the insn32 mode.
6818 template<int size
, bool big_endian
>
6819 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6820 plt0_entry_micromips32_o32
[] =
6822 0x41bc, 0x0000, // lui $28, %hi(&GOTPLT[0])
6823 0xff3c, 0x0000, // lw $25, %lo(&GOTPLT[0])($28)
6824 0x339c, 0x0000, // addiu $28, $28, %lo(&GOTPLT[0])
6825 0x0398, 0xc1d0, // subu $24, $24, $28
6826 0x001f, 0x7a90, // or $15, $31, zero
6827 0x0318, 0x1040, // srl $24, $24, 2
6828 0x03f9, 0x0f3c, // jalr $25
6829 0x3318, 0xfffe // subu $24, $24, 2
6832 // The format of subsequent standard entries in the PLT.
6833 template<int size
, bool big_endian
>
6834 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry
[] =
6836 0x3c0f0000, // lui $15, %hi(.got.plt entry)
6837 0x01f90000, // l[wd] $25, %lo(.got.plt entry)($15)
6838 0x03200008, // jr $25
6839 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
6842 // The format of subsequent MIPS16 o32 PLT entries. We use v1 ($3) as a
6843 // temporary because t8 ($24) and t9 ($25) are not directly addressable.
6844 // Note that this differs from the GNU ld which uses both v0 ($2) and v1 ($3).
6845 // We cannot use v0 because MIPS16 call stubs from the CS toolchain expect
6846 // target function address in register v0.
6847 template<int size
, bool big_endian
>
6848 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry_mips16_o32
[] =
6850 0xb303, // lw $3, 12($pc)
6851 0x651b, // move $24, $3
6852 0x9b60, // lw $3, 0($3)
6854 0x653b, // move $25, $3
6856 0x0000, 0x0000 // .word (.got.plt entry)
6859 // The format of subsequent microMIPS o32 PLT entries. We use v0 ($2)
6860 // as a temporary because t8 ($24) is not addressable with ADDIUPC.
6861 template<int size
, bool big_endian
>
6862 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6863 plt_entry_micromips_o32
[] =
6865 0x7900, 0x0000, // addiupc $2, (.got.plt entry) - .
6866 0xff22, 0x0000, // lw $25, 0($2)
6868 0x0f02 // move $24, $2
6871 // The format of subsequent microMIPS o32 PLT entries in the insn32 mode.
6872 template<int size
, bool big_endian
>
6873 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6874 plt_entry_micromips32_o32
[] =
6876 0x41af, 0x0000, // lui $15, %hi(.got.plt entry)
6877 0xff2f, 0x0000, // lw $25, %lo(.got.plt entry)($15)
6878 0x0019, 0x0f3c, // jr $25
6879 0x330f, 0x0000 // addiu $24, $15, %lo(.got.plt entry)
6882 // Add an entry to the PLT for a symbol referenced by r_type relocation.
6884 template<int size
, bool big_endian
>
6886 Mips_output_data_plt
<size
, big_endian
>::add_entry(Mips_symbol
<size
>* gsym
,
6887 unsigned int r_type
)
6889 gold_assert(!gsym
->has_plt_offset());
6891 // Final PLT offset for a symbol will be set in method set_plt_offsets().
6892 gsym
->set_plt_offset(this->entry_count() * sizeof(plt_entry
)
6893 + sizeof(plt0_entry_o32
));
6894 this->symbols_
.push_back(gsym
);
6896 // Record whether the relocation requires a standard MIPS
6897 // or a compressed code entry.
6898 if (jal_reloc(r_type
))
6900 if (r_type
== elfcpp::R_MIPS_26
)
6901 gsym
->set_needs_mips_plt(true);
6903 gsym
->set_needs_comp_plt(true);
6906 section_offset_type got_offset
= this->got_plt_
->current_data_size();
6908 // Every PLT entry needs a GOT entry which points back to the PLT
6909 // entry (this will be changed by the dynamic linker, normally
6910 // lazily when the function is called).
6911 this->got_plt_
->set_current_data_size(got_offset
+ size
/8);
6913 gsym
->set_needs_dynsym_entry();
6914 this->rel_
->add_global(gsym
, elfcpp::R_MIPS_JUMP_SLOT
, this->got_plt_
,
6918 // Set final PLT offsets. For each symbol, determine whether standard or
6919 // compressed (MIPS16 or microMIPS) PLT entry is used.
6921 template<int size
, bool big_endian
>
6923 Mips_output_data_plt
<size
, big_endian
>::set_plt_offsets()
6925 // The sizes of individual PLT entries.
6926 unsigned int plt_mips_entry_size
= this->standard_plt_entry_size();
6927 unsigned int plt_comp_entry_size
= (!this->target_
->is_output_newabi()
6928 ? this->compressed_plt_entry_size() : 0);
6930 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
6931 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
6933 Mips_symbol
<size
>* mips_sym
= *p
;
6935 // There are no defined MIPS16 or microMIPS PLT entries for n32 or n64,
6936 // so always use a standard entry there.
6938 // If the symbol has a MIPS16 call stub and gets a PLT entry, then
6939 // all MIPS16 calls will go via that stub, and there is no benefit
6940 // to having a MIPS16 entry. And in the case of call_stub a
6941 // standard entry actually has to be used as the stub ends with a J
6943 if (this->target_
->is_output_newabi()
6944 || mips_sym
->has_mips16_call_stub()
6945 || mips_sym
->has_mips16_call_fp_stub())
6947 mips_sym
->set_needs_mips_plt(true);
6948 mips_sym
->set_needs_comp_plt(false);
6951 // Otherwise, if there are no direct calls to the function, we
6952 // have a free choice of whether to use standard or compressed
6953 // entries. Prefer microMIPS entries if the object is known to
6954 // contain microMIPS code, so that it becomes possible to create
6955 // pure microMIPS binaries. Prefer standard entries otherwise,
6956 // because MIPS16 ones are no smaller and are usually slower.
6957 if (!mips_sym
->needs_mips_plt() && !mips_sym
->needs_comp_plt())
6959 if (this->target_
->is_output_micromips())
6960 mips_sym
->set_needs_comp_plt(true);
6962 mips_sym
->set_needs_mips_plt(true);
6965 if (mips_sym
->needs_mips_plt())
6967 mips_sym
->set_mips_plt_offset(this->plt_mips_offset_
);
6968 this->plt_mips_offset_
+= plt_mips_entry_size
;
6970 if (mips_sym
->needs_comp_plt())
6972 mips_sym
->set_comp_plt_offset(this->plt_comp_offset_
);
6973 this->plt_comp_offset_
+= plt_comp_entry_size
;
6977 // Figure out the size of the PLT header if we know that we are using it.
6978 if (this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0)
6979 this->plt_header_size_
= this->get_plt_header_size();
6982 // Write out the PLT. This uses the hand-coded instructions above,
6983 // and adjusts them as needed.
6985 template<int size
, bool big_endian
>
6987 Mips_output_data_plt
<size
, big_endian
>::do_write(Output_file
* of
)
6989 const off_t offset
= this->offset();
6990 const section_size_type oview_size
=
6991 convert_to_section_size_type(this->data_size());
6992 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6994 const off_t gotplt_file_offset
= this->got_plt_
->offset();
6995 const section_size_type gotplt_size
=
6996 convert_to_section_size_type(this->got_plt_
->data_size());
6997 unsigned char* const gotplt_view
= of
->get_output_view(gotplt_file_offset
,
6999 unsigned char* pov
= oview
;
7001 Mips_address plt_address
= this->address();
7003 // Calculate the address of .got.plt.
7004 Mips_address gotplt_addr
= this->got_plt_
->address();
7005 Mips_address gotplt_addr_high
= ((gotplt_addr
+ 0x8000) >> 16) & 0xffff;
7006 Mips_address gotplt_addr_low
= gotplt_addr
& 0xffff;
7008 // The PLT sequence is not safe for N64 if .got.plt's address can
7009 // not be loaded in two instructions.
7010 gold_assert((gotplt_addr
& ~(Mips_address
) 0x7fffffff) == 0
7011 || ~(gotplt_addr
| 0x7fffffff) == 0);
7013 // Write the PLT header.
7014 const uint32_t* plt0_entry
= this->get_plt_header_entry();
7015 if (plt0_entry
== plt0_entry_micromips_o32
)
7017 // Write microMIPS PLT header.
7018 gold_assert(gotplt_addr
% 4 == 0);
7020 Mips_address gotpc_offset
= gotplt_addr
- ((plt_address
| 3) ^ 3);
7022 // ADDIUPC has a span of +/-16MB, check we're in range.
7023 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
7025 gold_error(_(".got.plt offset of %ld from .plt beyond the range of "
7026 "ADDIUPC"), (long)gotpc_offset
);
7030 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
7031 plt0_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
7032 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7033 (gotpc_offset
>> 2) & 0xffff);
7035 for (unsigned int i
= 2;
7036 i
< (sizeof(plt0_entry_micromips_o32
)
7037 / sizeof(plt0_entry_micromips_o32
[0]));
7040 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7044 else if (plt0_entry
== plt0_entry_micromips32_o32
)
7046 // Write microMIPS PLT header in insn32 mode.
7047 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[0]);
7048 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, gotplt_addr_high
);
7049 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, plt0_entry
[2]);
7050 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, gotplt_addr_low
);
7051 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8, plt0_entry
[4]);
7052 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, gotplt_addr_low
);
7054 for (unsigned int i
= 6;
7055 i
< (sizeof(plt0_entry_micromips32_o32
)
7056 / sizeof(plt0_entry_micromips32_o32
[0]));
7059 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7065 // Write standard PLT header.
7066 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7067 plt0_entry
[0] | gotplt_addr_high
);
7068 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7069 plt0_entry
[1] | gotplt_addr_low
);
7070 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
7071 plt0_entry
[2] | gotplt_addr_low
);
7073 for (int i
= 3; i
< 8; i
++)
7075 elfcpp::Swap
<32, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7081 unsigned char* gotplt_pov
= gotplt_view
;
7082 unsigned int got_entry_size
= size
/8; // TODO(sasa): MIPS_ELF_GOT_SIZE
7084 // The first two entries in .got.plt are reserved.
7085 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
, 0);
7086 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
+ got_entry_size
, 0);
7088 unsigned int gotplt_offset
= 2 * got_entry_size
;
7089 gotplt_pov
+= 2 * got_entry_size
;
7091 // Calculate the address of the PLT header.
7092 Mips_address header_address
= (plt_address
7093 + (this->is_plt_header_compressed() ? 1 : 0));
7095 // Initialize compressed PLT area view.
7096 unsigned char* pov2
= pov
+ this->plt_mips_offset_
;
7098 // Write the PLT entries.
7099 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
7100 p
= this->symbols_
.begin();
7101 p
!= this->symbols_
.end();
7102 ++p
, gotplt_pov
+= got_entry_size
, gotplt_offset
+= got_entry_size
)
7104 Mips_symbol
<size
>* mips_sym
= *p
;
7106 // Calculate the address of the .got.plt entry.
7107 uint32_t gotplt_entry_addr
= (gotplt_addr
+ gotplt_offset
);
7108 uint32_t gotplt_entry_addr_hi
= (((gotplt_entry_addr
+ 0x8000) >> 16)
7110 uint32_t gotplt_entry_addr_lo
= gotplt_entry_addr
& 0xffff;
7112 // Initially point the .got.plt entry at the PLT header.
7113 if (this->target_
->is_output_n64())
7114 elfcpp::Swap
<64, big_endian
>::writeval(gotplt_pov
, header_address
);
7116 elfcpp::Swap
<32, big_endian
>::writeval(gotplt_pov
, header_address
);
7118 // Now handle the PLT itself. First the standard entry.
7119 if (mips_sym
->has_mips_plt_offset())
7121 // Pick the load opcode (LW or LD).
7122 uint64_t load
= this->target_
->is_output_n64() ? 0xdc000000
7125 // Fill in the PLT entry itself.
7126 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7127 plt_entry
[0] | gotplt_entry_addr_hi
);
7128 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7129 plt_entry
[1] | gotplt_entry_addr_lo
| load
);
7130 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8, plt_entry
[2]);
7131 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12,
7132 plt_entry
[3] | gotplt_entry_addr_lo
);
7136 // Now the compressed entry. They come after any standard ones.
7137 if (mips_sym
->has_comp_plt_offset())
7139 if (!this->target_
->is_output_micromips())
7141 // Write MIPS16 PLT entry.
7142 const uint32_t* plt_entry
= plt_entry_mips16_o32
;
7144 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
7145 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2, plt_entry
[1]);
7146 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7147 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
7148 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7149 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7150 elfcpp::Swap
<32, big_endian
>::writeval(pov2
+ 12,
7154 else if (this->target_
->use_32bit_micromips_instructions())
7156 // Write microMIPS PLT entry in insn32 mode.
7157 const uint32_t* plt_entry
= plt_entry_micromips32_o32
;
7159 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
7160 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2,
7161 gotplt_entry_addr_hi
);
7162 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7163 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6,
7164 gotplt_entry_addr_lo
);
7165 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7166 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7167 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 12, plt_entry
[6]);
7168 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 14,
7169 gotplt_entry_addr_lo
);
7174 // Write microMIPS PLT entry.
7175 const uint32_t* plt_entry
= plt_entry_micromips_o32
;
7177 gold_assert(gotplt_entry_addr
% 4 == 0);
7179 Mips_address loc_address
= plt_address
+ pov2
- oview
;
7180 int gotpc_offset
= gotplt_entry_addr
- ((loc_address
| 3) ^ 3);
7182 // ADDIUPC has a span of +/-16MB, check we're in range.
7183 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
7185 gold_error(_(".got.plt offset of %ld from .plt beyond the "
7186 "range of ADDIUPC"), (long)gotpc_offset
);
7190 elfcpp::Swap
<16, big_endian
>::writeval(pov2
,
7191 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
7192 elfcpp::Swap
<16, big_endian
>::writeval(
7193 pov2
+ 2, (gotpc_offset
>> 2) & 0xffff);
7194 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7195 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
7196 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7197 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7203 // Check the number of bytes written for standard entries.
7204 gold_assert(static_cast<section_size_type
>(
7205 pov
- oview
- this->plt_header_size_
) == this->plt_mips_offset_
);
7206 // Check the number of bytes written for compressed entries.
7207 gold_assert((static_cast<section_size_type
>(pov2
- pov
)
7208 == this->plt_comp_offset_
));
7209 // Check the total number of bytes written.
7210 gold_assert(static_cast<section_size_type
>(pov2
- oview
) == oview_size
);
7212 gold_assert(static_cast<section_size_type
>(gotplt_pov
- gotplt_view
)
7215 of
->write_output_view(offset
, oview_size
, oview
);
7216 of
->write_output_view(gotplt_file_offset
, gotplt_size
, gotplt_view
);
7219 // Mips_output_data_mips_stubs methods.
7221 // The format of the lazy binding stub when dynamic symbol count is less than
7222 // 64K, dynamic symbol index is less than 32K, and ABI is not N64.
7223 template<int size
, bool big_endian
>
7225 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1
[4] =
7227 0x8f998010, // lw t9,0x8010(gp)
7228 0x03e07825, // or t7,ra,zero
7229 0x0320f809, // jalr t9,ra
7230 0x24180000 // addiu t8,zero,DYN_INDEX sign extended
7233 // The format of the lazy binding stub when dynamic symbol count is less than
7234 // 64K, dynamic symbol index is less than 32K, and ABI is N64.
7235 template<int size
, bool big_endian
>
7237 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1_n64
[4] =
7239 0xdf998010, // ld t9,0x8010(gp)
7240 0x03e07825, // or t7,ra,zero
7241 0x0320f809, // jalr t9,ra
7242 0x64180000 // daddiu t8,zero,DYN_INDEX sign extended
7245 // The format of the lazy binding stub when dynamic symbol count is less than
7246 // 64K, dynamic symbol index is between 32K and 64K, and ABI is not N64.
7247 template<int size
, bool big_endian
>
7249 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2
[4] =
7251 0x8f998010, // lw t9,0x8010(gp)
7252 0x03e07825, // or t7,ra,zero
7253 0x0320f809, // jalr t9,ra
7254 0x34180000 // ori t8,zero,DYN_INDEX unsigned
7257 // The format of the lazy binding stub when dynamic symbol count is less than
7258 // 64K, dynamic symbol index is between 32K and 64K, and ABI is N64.
7259 template<int size
, bool big_endian
>
7261 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2_n64
[4] =
7263 0xdf998010, // ld t9,0x8010(gp)
7264 0x03e07825, // or t7,ra,zero
7265 0x0320f809, // jalr t9,ra
7266 0x34180000 // ori t8,zero,DYN_INDEX unsigned
7269 // The format of the lazy binding stub when dynamic symbol count is greater than
7270 // 64K, and ABI is not N64.
7271 template<int size
, bool big_endian
>
7272 const uint32_t Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big
[5] =
7274 0x8f998010, // lw t9,0x8010(gp)
7275 0x03e07825, // or t7,ra,zero
7276 0x3c180000, // lui t8,DYN_INDEX
7277 0x0320f809, // jalr t9,ra
7278 0x37180000 // ori t8,t8,DYN_INDEX
7281 // The format of the lazy binding stub when dynamic symbol count is greater than
7282 // 64K, and ABI is N64.
7283 template<int size
, bool big_endian
>
7285 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big_n64
[5] =
7287 0xdf998010, // ld t9,0x8010(gp)
7288 0x03e07825, // or t7,ra,zero
7289 0x3c180000, // lui t8,DYN_INDEX
7290 0x0320f809, // jalr t9,ra
7291 0x37180000 // ori t8,t8,DYN_INDEX
7296 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7297 // less than 64K, dynamic symbol index is less than 32K, and ABI is not N64.
7298 template<int size
, bool big_endian
>
7300 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_1
[] =
7302 0xff3c, 0x8010, // lw t9,0x8010(gp)
7303 0x0dff, // move t7,ra
7305 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
7308 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7309 // less than 64K, dynamic symbol index is less than 32K, and ABI is N64.
7310 template<int size
, bool big_endian
>
7312 Mips_output_data_mips_stubs
<size
, big_endian
>::
7313 lazy_stub_micromips_normal_1_n64
[] =
7315 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7316 0x0dff, // move t7,ra
7318 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
7321 // The format of the microMIPS lazy binding stub when dynamic symbol
7322 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7323 // and ABI is not N64.
7324 template<int size
, bool big_endian
>
7326 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_2
[] =
7328 0xff3c, 0x8010, // lw t9,0x8010(gp)
7329 0x0dff, // move t7,ra
7331 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7334 // The format of the microMIPS lazy binding stub when dynamic symbol
7335 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7337 template<int size
, bool big_endian
>
7339 Mips_output_data_mips_stubs
<size
, big_endian
>::
7340 lazy_stub_micromips_normal_2_n64
[] =
7342 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7343 0x0dff, // move t7,ra
7345 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7348 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7349 // greater than 64K, and ABI is not N64.
7350 template<int size
, bool big_endian
>
7352 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big
[] =
7354 0xff3c, 0x8010, // lw t9,0x8010(gp)
7355 0x0dff, // move t7,ra
7356 0x41b8, 0x0000, // lui t8,DYN_INDEX
7358 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7361 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7362 // greater than 64K, and ABI is N64.
7363 template<int size
, bool big_endian
>
7365 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big_n64
[] =
7367 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7368 0x0dff, // move t7,ra
7369 0x41b8, 0x0000, // lui t8,DYN_INDEX
7371 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7374 // 32-bit microMIPS stubs.
7376 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7377 // less than 64K, dynamic symbol index is less than 32K, ABI is not N64, and we
7378 // can use only 32-bit instructions.
7379 template<int size
, bool big_endian
>
7381 Mips_output_data_mips_stubs
<size
, big_endian
>::
7382 lazy_stub_micromips32_normal_1
[] =
7384 0xff3c, 0x8010, // lw t9,0x8010(gp)
7385 0x001f, 0x7a90, // or t7,ra,zero
7386 0x03f9, 0x0f3c, // jalr ra,t9
7387 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
7390 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7391 // less than 64K, dynamic symbol index is less than 32K, ABI is N64, and we can
7392 // use only 32-bit instructions.
7393 template<int size
, bool big_endian
>
7395 Mips_output_data_mips_stubs
<size
, big_endian
>::
7396 lazy_stub_micromips32_normal_1_n64
[] =
7398 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7399 0x001f, 0x7a90, // or t7,ra,zero
7400 0x03f9, 0x0f3c, // jalr ra,t9
7401 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
7404 // The format of the microMIPS lazy binding stub when dynamic symbol
7405 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7406 // ABI is not N64, and we can use only 32-bit instructions.
7407 template<int size
, bool big_endian
>
7409 Mips_output_data_mips_stubs
<size
, big_endian
>::
7410 lazy_stub_micromips32_normal_2
[] =
7412 0xff3c, 0x8010, // lw t9,0x8010(gp)
7413 0x001f, 0x7a90, // or t7,ra,zero
7414 0x03f9, 0x0f3c, // jalr ra,t9
7415 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7418 // The format of the microMIPS lazy binding stub when dynamic symbol
7419 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7420 // ABI is N64, and we can use only 32-bit instructions.
7421 template<int size
, bool big_endian
>
7423 Mips_output_data_mips_stubs
<size
, big_endian
>::
7424 lazy_stub_micromips32_normal_2_n64
[] =
7426 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7427 0x001f, 0x7a90, // or t7,ra,zero
7428 0x03f9, 0x0f3c, // jalr ra,t9
7429 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7432 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7433 // greater than 64K, ABI is not N64, and we can use only 32-bit instructions.
7434 template<int size
, bool big_endian
>
7436 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big
[] =
7438 0xff3c, 0x8010, // lw t9,0x8010(gp)
7439 0x001f, 0x7a90, // or t7,ra,zero
7440 0x41b8, 0x0000, // lui t8,DYN_INDEX
7441 0x03f9, 0x0f3c, // jalr ra,t9
7442 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7445 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7446 // greater than 64K, ABI is N64, and we can use only 32-bit instructions.
7447 template<int size
, bool big_endian
>
7449 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big_n64
[] =
7451 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7452 0x001f, 0x7a90, // or t7,ra,zero
7453 0x41b8, 0x0000, // lui t8,DYN_INDEX
7454 0x03f9, 0x0f3c, // jalr ra,t9
7455 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7458 // Create entry for a symbol.
7460 template<int size
, bool big_endian
>
7462 Mips_output_data_mips_stubs
<size
, big_endian
>::make_entry(
7463 Mips_symbol
<size
>* gsym
)
7465 if (!gsym
->has_lazy_stub() && !gsym
->has_plt_offset())
7467 this->symbols_
.insert(gsym
);
7468 gsym
->set_has_lazy_stub(true);
7472 // Remove entry for a symbol.
7474 template<int size
, bool big_endian
>
7476 Mips_output_data_mips_stubs
<size
, big_endian
>::remove_entry(
7477 Mips_symbol
<size
>* gsym
)
7479 if (gsym
->has_lazy_stub())
7481 this->symbols_
.erase(gsym
);
7482 gsym
->set_has_lazy_stub(false);
7486 // Set stub offsets for symbols. This method expects that the number of
7487 // entries in dynamic symbol table is set.
7489 template<int size
, bool big_endian
>
7491 Mips_output_data_mips_stubs
<size
, big_endian
>::set_lazy_stub_offsets()
7493 gold_assert(this->dynsym_count_
!= -1U);
7495 if (this->stub_offsets_are_set_
)
7498 unsigned int stub_size
= this->stub_size();
7499 unsigned int offset
= 0;
7500 for (typename
Mips_stubs_entry_set::const_iterator
7501 p
= this->symbols_
.begin();
7502 p
!= this->symbols_
.end();
7503 ++p
, offset
+= stub_size
)
7505 Mips_symbol
<size
>* mips_sym
= *p
;
7506 mips_sym
->set_lazy_stub_offset(offset
);
7508 this->stub_offsets_are_set_
= true;
7511 template<int size
, bool big_endian
>
7513 Mips_output_data_mips_stubs
<size
, big_endian
>::set_needs_dynsym_value()
7515 for (typename
Mips_stubs_entry_set::const_iterator
7516 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
7518 Mips_symbol
<size
>* sym
= *p
;
7519 if (sym
->is_from_dynobj())
7520 sym
->set_needs_dynsym_value();
7524 // Write out the .MIPS.stubs. This uses the hand-coded instructions and
7525 // adjusts them as needed.
7527 template<int size
, bool big_endian
>
7529 Mips_output_data_mips_stubs
<size
, big_endian
>::do_write(Output_file
* of
)
7531 const off_t offset
= this->offset();
7532 const section_size_type oview_size
=
7533 convert_to_section_size_type(this->data_size());
7534 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
7536 bool big_stub
= this->dynsym_count_
> 0x10000;
7538 unsigned char* pov
= oview
;
7539 for (typename
Mips_stubs_entry_set::const_iterator
7540 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
7542 Mips_symbol
<size
>* sym
= *p
;
7543 const uint32_t* lazy_stub
;
7544 bool n64
= this->target_
->is_output_n64();
7546 if (!this->target_
->is_output_micromips())
7548 // Write standard (non-microMIPS) stub.
7551 if (sym
->dynsym_index() & ~0x7fff)
7552 // Dynsym index is between 32K and 64K.
7553 lazy_stub
= n64
? lazy_stub_normal_2_n64
: lazy_stub_normal_2
;
7555 // Dynsym index is less than 32K.
7556 lazy_stub
= n64
? lazy_stub_normal_1_n64
: lazy_stub_normal_1
;
7559 lazy_stub
= n64
? lazy_stub_big_n64
: lazy_stub_big
;
7562 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7563 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 1]);
7569 // LUI instruction of the big stub. Paste high 16 bits of the
7571 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7572 lazy_stub
[i
] | ((sym
->dynsym_index() >> 16) & 0x7fff));
7576 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7577 // Last stub instruction. Paste low 16 bits of the dynsym index.
7578 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7579 lazy_stub
[i
+ 1] | (sym
->dynsym_index() & 0xffff));
7582 else if (this->target_
->use_32bit_micromips_instructions())
7584 // Write microMIPS stub in insn32 mode.
7587 if (sym
->dynsym_index() & ~0x7fff)
7588 // Dynsym index is between 32K and 64K.
7589 lazy_stub
= n64
? lazy_stub_micromips32_normal_2_n64
7590 : lazy_stub_micromips32_normal_2
;
7592 // Dynsym index is less than 32K.
7593 lazy_stub
= n64
? lazy_stub_micromips32_normal_1_n64
7594 : lazy_stub_micromips32_normal_1
;
7597 lazy_stub
= n64
? lazy_stub_micromips32_big_n64
7598 : lazy_stub_micromips32_big
;
7601 // First stub instruction. We emit 32-bit microMIPS instructions by
7602 // emitting two 16-bit parts because on microMIPS the 16-bit part of
7603 // the instruction where the opcode is must always come first, for
7604 // both little and big endian.
7605 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7606 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7607 // Second stub instruction.
7608 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7609 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, lazy_stub
[i
+ 3]);
7614 // LUI instruction of the big stub. Paste high 16 bits of the
7616 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7617 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7618 (sym
->dynsym_index() >> 16) & 0x7fff);
7622 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7623 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7624 // Last stub instruction. Paste low 16 bits of the dynsym index.
7625 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7626 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
7627 sym
->dynsym_index() & 0xffff);
7632 // Write microMIPS stub.
7635 if (sym
->dynsym_index() & ~0x7fff)
7636 // Dynsym index is between 32K and 64K.
7637 lazy_stub
= n64
? lazy_stub_micromips_normal_2_n64
7638 : lazy_stub_micromips_normal_2
;
7640 // Dynsym index is less than 32K.
7641 lazy_stub
= n64
? lazy_stub_micromips_normal_1_n64
7642 : lazy_stub_micromips_normal_1
;
7645 lazy_stub
= n64
? lazy_stub_micromips_big_n64
7646 : lazy_stub_micromips_big
;
7649 // First stub instruction. We emit 32-bit microMIPS instructions by
7650 // emitting two 16-bit parts because on microMIPS the 16-bit part of
7651 // the instruction where the opcode is must always come first, for
7652 // both little and big endian.
7653 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7654 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7655 // Second stub instruction.
7656 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7661 // LUI instruction of the big stub. Paste high 16 bits of the
7663 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7664 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7665 (sym
->dynsym_index() >> 16) & 0x7fff);
7669 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7670 // Last stub instruction. Paste low 16 bits of the dynsym index.
7671 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7672 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
7673 sym
->dynsym_index() & 0xffff);
7678 // We always allocate 20 bytes for every stub, because final dynsym count is
7679 // not known in method do_finalize_sections. There are 4 unused bytes per
7680 // stub if final dynsym count is less than 0x10000.
7681 unsigned int used
= pov
- oview
;
7682 unsigned int unused
= big_stub
? 0 : this->symbols_
.size() * 4;
7683 gold_assert(static_cast<section_size_type
>(used
+ unused
) == oview_size
);
7685 // Fill the unused space with zeroes.
7686 // TODO(sasa): Can we strip unused bytes during the relaxation?
7688 memset(pov
, 0, unused
);
7690 of
->write_output_view(offset
, oview_size
, oview
);
7693 // Mips_output_section_reginfo methods.
7695 template<int size
, bool big_endian
>
7697 Mips_output_section_reginfo
<size
, big_endian
>::do_write(Output_file
* of
)
7699 off_t offset
= this->offset();
7700 off_t data_size
= this->data_size();
7702 unsigned char* view
= of
->get_output_view(offset
, data_size
);
7703 elfcpp::Swap
<size
, big_endian
>::writeval(view
, this->gprmask_
);
7704 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 4, this->cprmask1_
);
7705 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 8, this->cprmask2_
);
7706 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 12, this->cprmask3_
);
7707 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 16, this->cprmask4_
);
7708 // Write the gp value.
7709 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 20,
7710 this->target_
->gp_value());
7712 of
->write_output_view(offset
, data_size
, view
);
7715 // Mips_copy_relocs methods.
7717 // Emit any saved relocs.
7719 template<int sh_type
, int size
, bool big_endian
>
7721 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_mips(
7722 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
7723 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
7725 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
7726 Copy_reloc_entries::iterator p
= this->entries_
.begin();
7727 p
!= this->entries_
.end();
7729 emit_entry(*p
, reloc_section
, symtab
, layout
, target
);
7731 // We no longer need the saved information.
7732 this->entries_
.clear();
7735 // Emit the reloc if appropriate.
7737 template<int sh_type
, int size
, bool big_endian
>
7739 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_entry(
7740 Copy_reloc_entry
& entry
,
7741 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
7742 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
7744 // If the symbol is no longer defined in a dynamic object, then we
7745 // emitted a COPY relocation, and we do not want to emit this
7746 // dynamic relocation.
7747 if (!entry
.sym_
->is_from_dynobj())
7750 bool can_make_dynamic
= (entry
.reloc_type_
== elfcpp::R_MIPS_32
7751 || entry
.reloc_type_
== elfcpp::R_MIPS_REL32
7752 || entry
.reloc_type_
== elfcpp::R_MIPS_64
);
7754 Mips_symbol
<size
>* sym
= Mips_symbol
<size
>::as_mips_sym(entry
.sym_
);
7755 if (can_make_dynamic
&& !sym
->has_static_relocs())
7757 Mips_relobj
<size
, big_endian
>* object
=
7758 Mips_relobj
<size
, big_endian
>::as_mips_relobj(entry
.relobj_
);
7759 target
->got_section(symtab
, layout
)->record_global_got_symbol(
7760 sym
, object
, entry
.reloc_type_
, true, false);
7761 if (!symbol_references_local(sym
, sym
->should_add_dynsym_entry(symtab
)))
7762 target
->rel_dyn_section(layout
)->add_global(sym
, elfcpp::R_MIPS_REL32
,
7763 entry
.output_section_
, entry
.relobj_
, entry
.shndx_
, entry
.address_
);
7765 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
7766 sym
, elfcpp::R_MIPS_REL32
, entry
.output_section_
, entry
.relobj_
,
7767 entry
.shndx_
, entry
.address_
);
7770 this->make_copy_reloc(symtab
, layout
,
7771 static_cast<Sized_symbol
<size
>*>(entry
.sym_
),
7776 // Target_mips methods.
7778 // Return the value to use for a dynamic symbol which requires special
7779 // treatment. This is how we support equality comparisons of function
7780 // pointers across shared library boundaries, as described in the
7781 // processor specific ABI supplement.
7783 template<int size
, bool big_endian
>
7785 Target_mips
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
7788 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
7790 if (!mips_sym
->has_lazy_stub())
7792 if (mips_sym
->has_plt_offset())
7794 // We distinguish between PLT entries and lazy-binding stubs by
7795 // giving the former an st_other value of STO_MIPS_PLT. Set the
7796 // value to the stub address if there are any relocations in the
7797 // binary where pointer equality matters.
7798 if (mips_sym
->pointer_equality_needed())
7800 // Prefer a standard MIPS PLT entry.
7801 if (mips_sym
->has_mips_plt_offset())
7802 value
= this->plt_section()->mips_entry_address(mips_sym
);
7804 value
= this->plt_section()->comp_entry_address(mips_sym
) + 1;
7812 // First, set stub offsets for symbols. This method expects that the
7813 // number of entries in dynamic symbol table is set.
7814 this->mips_stubs_section()->set_lazy_stub_offsets();
7816 // The run-time linker uses the st_value field of the symbol
7817 // to reset the global offset table entry for this external
7818 // to its stub address when unlinking a shared object.
7819 value
= this->mips_stubs_section()->stub_address(mips_sym
);
7822 if (mips_sym
->has_mips16_fn_stub())
7824 // If we have a MIPS16 function with a stub, the dynamic symbol must
7825 // refer to the stub, since only the stub uses the standard calling
7827 value
= mips_sym
->template
7828 get_mips16_fn_stub
<big_endian
>()->output_address();
7834 // Get the dynamic reloc section, creating it if necessary. It's always
7835 // .rel.dyn, even for MIPS64.
7837 template<int size
, bool big_endian
>
7838 typename Target_mips
<size
, big_endian
>::Reloc_section
*
7839 Target_mips
<size
, big_endian
>::rel_dyn_section(Layout
* layout
)
7841 if (this->rel_dyn_
== NULL
)
7843 gold_assert(layout
!= NULL
);
7844 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
7845 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
7846 elfcpp::SHF_ALLOC
, this->rel_dyn_
,
7847 ORDER_DYNAMIC_RELOCS
, false);
7849 // First entry in .rel.dyn has to be null.
7850 // This is hack - we define dummy output data and set its address to 0,
7851 // and define absolute R_MIPS_NONE relocation with offset 0 against it.
7852 // This ensures that the entry is null.
7853 Output_data
* od
= new Output_data_zero_fill(0, 0);
7855 this->rel_dyn_
->add_absolute(elfcpp::R_MIPS_NONE
, od
, 0);
7857 return this->rel_dyn_
;
7860 // Get the GOT section, creating it if necessary.
7862 template<int size
, bool big_endian
>
7863 Mips_output_data_got
<size
, big_endian
>*
7864 Target_mips
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
7867 if (this->got_
== NULL
)
7869 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
7871 this->got_
= new Mips_output_data_got
<size
, big_endian
>(this, symtab
,
7873 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
7874 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
|
7875 elfcpp::SHF_MIPS_GPREL
),
7876 this->got_
, ORDER_DATA
, false);
7878 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
7879 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
7880 Symbol_table::PREDEFINED
,
7882 0, 0, elfcpp::STT_OBJECT
,
7884 elfcpp::STV_DEFAULT
, 0,
7891 // Calculate value of _gp symbol.
7893 template<int size
, bool big_endian
>
7895 Target_mips
<size
, big_endian
>::set_gp(Layout
* layout
, Symbol_table
* symtab
)
7897 if (this->gp_
!= NULL
)
7900 Output_data
* section
= layout
->find_output_section(".got");
7901 if (section
== NULL
)
7903 // If there is no .got section, gp should be based on .sdata.
7904 // TODO(sasa): This is probably not needed. This was needed for older
7905 // MIPS architectures which accessed both GOT and .sdata section using
7906 // gp-relative addressing. Modern Mips Linux ELF architectures don't
7907 // access .sdata using gp-relative addressing.
7908 for (Layout::Section_list::const_iterator
7909 p
= layout
->section_list().begin();
7910 p
!= layout
->section_list().end();
7913 if (strcmp((*p
)->name(), ".sdata") == 0)
7921 Sized_symbol
<size
>* gp
=
7922 static_cast<Sized_symbol
<size
>*>(symtab
->lookup("_gp"));
7925 if (gp
->source() != Symbol::IS_CONSTANT
&& section
!= NULL
)
7926 gp
->init_output_data(gp
->name(), NULL
, section
, MIPS_GP_OFFSET
, 0,
7929 elfcpp::STV_DEFAULT
, 0,
7933 else if (section
!= NULL
)
7935 gp
= static_cast<Sized_symbol
<size
>*>(symtab
->define_in_output_data(
7936 "_gp", NULL
, Symbol_table::PREDEFINED
,
7937 section
, MIPS_GP_OFFSET
, 0,
7940 elfcpp::STV_DEFAULT
,
7946 // Set the dynamic symbol indexes. INDEX is the index of the first
7947 // global dynamic symbol. Pointers to the symbols are stored into the
7948 // vector SYMS. The names are added to DYNPOOL. This returns an
7949 // updated dynamic symbol index.
7951 template<int size
, bool big_endian
>
7953 Target_mips
<size
, big_endian
>::do_set_dynsym_indexes(
7954 std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
7955 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
7956 Versions
* versions
, Symbol_table
* symtab
) const
7958 std::vector
<Symbol
*> non_got_symbols
;
7959 std::vector
<Symbol
*> got_symbols
;
7961 reorder_dyn_symbols
<size
, big_endian
>(dyn_symbols
, &non_got_symbols
,
7964 for (std::vector
<Symbol
*>::iterator p
= non_got_symbols
.begin();
7965 p
!= non_got_symbols
.end();
7970 // Note that SYM may already have a dynamic symbol index, since
7971 // some symbols appear more than once in the symbol table, with
7972 // and without a version.
7974 if (!sym
->has_dynsym_index())
7976 sym
->set_dynsym_index(index
);
7978 syms
->push_back(sym
);
7979 dynpool
->add(sym
->name(), false, NULL
);
7981 // Record any version information.
7982 if (sym
->version() != NULL
)
7983 versions
->record_version(symtab
, dynpool
, sym
);
7985 // If the symbol is defined in a dynamic object and is
7986 // referenced in a regular object, then mark the dynamic
7987 // object as needed. This is used to implement --as-needed.
7988 if (sym
->is_from_dynobj() && sym
->in_reg())
7989 sym
->object()->set_is_needed();
7993 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
7994 p
!= got_symbols
.end();
7998 if (!sym
->has_dynsym_index())
8000 // Record any version information.
8001 if (sym
->version() != NULL
)
8002 versions
->record_version(symtab
, dynpool
, sym
);
8006 index
= versions
->finalize(symtab
, index
, syms
);
8008 int got_sym_count
= 0;
8009 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
8010 p
!= got_symbols
.end();
8015 if (!sym
->has_dynsym_index())
8018 sym
->set_dynsym_index(index
);
8020 syms
->push_back(sym
);
8021 dynpool
->add(sym
->name(), false, NULL
);
8023 // If the symbol is defined in a dynamic object and is
8024 // referenced in a regular object, then mark the dynamic
8025 // object as needed. This is used to implement --as-needed.
8026 if (sym
->is_from_dynobj() && sym
->in_reg())
8027 sym
->object()->set_is_needed();
8031 // Set index of the first symbol that has .got entry.
8032 this->got_
->set_first_global_got_dynsym_index(
8033 got_sym_count
> 0 ? index
- got_sym_count
: -1U);
8035 if (this->mips_stubs_
!= NULL
)
8036 this->mips_stubs_
->set_dynsym_count(index
);
8041 // Create a PLT entry for a global symbol referenced by r_type relocation.
8043 template<int size
, bool big_endian
>
8045 Target_mips
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
8047 Mips_symbol
<size
>* gsym
,
8048 unsigned int r_type
)
8050 if (gsym
->has_lazy_stub() || gsym
->has_plt_offset())
8053 if (this->plt_
== NULL
)
8055 // Create the GOT section first.
8056 this->got_section(symtab
, layout
);
8058 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
8059 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
8060 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
8061 this->got_plt_
, ORDER_DATA
, false);
8063 // The first two entries are reserved.
8064 this->got_plt_
->set_current_data_size(2 * size
/8);
8066 this->plt_
= new Mips_output_data_plt
<size
, big_endian
>(layout
,
8069 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
8071 | elfcpp::SHF_EXECINSTR
),
8072 this->plt_
, ORDER_PLT
, false);
8075 this->plt_
->add_entry(gsym
, r_type
);
8079 // Get the .MIPS.stubs section, creating it if necessary.
8081 template<int size
, bool big_endian
>
8082 Mips_output_data_mips_stubs
<size
, big_endian
>*
8083 Target_mips
<size
, big_endian
>::mips_stubs_section(Layout
* layout
)
8085 if (this->mips_stubs_
== NULL
)
8088 new Mips_output_data_mips_stubs
<size
, big_endian
>(this);
8089 layout
->add_output_section_data(".MIPS.stubs", elfcpp::SHT_PROGBITS
,
8091 | elfcpp::SHF_EXECINSTR
),
8092 this->mips_stubs_
, ORDER_PLT
, false);
8094 return this->mips_stubs_
;
8097 // Get the LA25 stub section, creating it if necessary.
8099 template<int size
, bool big_endian
>
8100 Mips_output_data_la25_stub
<size
, big_endian
>*
8101 Target_mips
<size
, big_endian
>::la25_stub_section(Layout
* layout
)
8103 if (this->la25_stub_
== NULL
)
8105 this->la25_stub_
= new Mips_output_data_la25_stub
<size
, big_endian
>();
8106 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
8108 | elfcpp::SHF_EXECINSTR
),
8109 this->la25_stub_
, ORDER_TEXT
, false);
8111 return this->la25_stub_
;
8114 // Process the relocations to determine unreferenced sections for
8115 // garbage collection.
8117 template<int size
, bool big_endian
>
8119 Target_mips
<size
, big_endian
>::gc_process_relocs(
8120 Symbol_table
* symtab
,
8122 Sized_relobj_file
<size
, big_endian
>* object
,
8123 unsigned int data_shndx
,
8124 unsigned int sh_type
,
8125 const unsigned char* prelocs
,
8127 Output_section
* output_section
,
8128 bool needs_special_offset_handling
,
8129 size_t local_symbol_count
,
8130 const unsigned char* plocal_symbols
)
8132 typedef Target_mips
<size
, big_endian
> Mips
;
8134 if (sh_type
== elfcpp::SHT_REL
)
8136 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8139 gold::gc_process_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8148 needs_special_offset_handling
,
8152 else if (sh_type
== elfcpp::SHT_RELA
)
8154 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8157 gold::gc_process_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8166 needs_special_offset_handling
,
8174 // Scan relocations for a section.
8176 template<int size
, bool big_endian
>
8178 Target_mips
<size
, big_endian
>::scan_relocs(
8179 Symbol_table
* symtab
,
8181 Sized_relobj_file
<size
, big_endian
>* object
,
8182 unsigned int data_shndx
,
8183 unsigned int sh_type
,
8184 const unsigned char* prelocs
,
8186 Output_section
* output_section
,
8187 bool needs_special_offset_handling
,
8188 size_t local_symbol_count
,
8189 const unsigned char* plocal_symbols
)
8191 typedef Target_mips
<size
, big_endian
> Mips
;
8193 if (sh_type
== elfcpp::SHT_REL
)
8195 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8198 gold::scan_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8207 needs_special_offset_handling
,
8211 else if (sh_type
== elfcpp::SHT_RELA
)
8213 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8216 gold::scan_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8225 needs_special_offset_handling
,
8231 template<int size
, bool big_endian
>
8233 Target_mips
<size
, big_endian
>::mips_32bit_flags(elfcpp::Elf_Word flags
)
8235 return ((flags
& elfcpp::EF_MIPS_32BITMODE
) != 0
8236 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_O32
8237 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_EABI32
8238 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_1
8239 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_2
8240 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32
8241 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32R2
);
8244 // Return the MACH for a MIPS e_flags value.
8245 template<int size
, bool big_endian
>
8247 Target_mips
<size
, big_endian
>::elf_mips_mach(elfcpp::Elf_Word flags
)
8249 switch (flags
& elfcpp::EF_MIPS_MACH
)
8251 case elfcpp::E_MIPS_MACH_3900
:
8252 return mach_mips3900
;
8254 case elfcpp::E_MIPS_MACH_4010
:
8255 return mach_mips4010
;
8257 case elfcpp::E_MIPS_MACH_4100
:
8258 return mach_mips4100
;
8260 case elfcpp::E_MIPS_MACH_4111
:
8261 return mach_mips4111
;
8263 case elfcpp::E_MIPS_MACH_4120
:
8264 return mach_mips4120
;
8266 case elfcpp::E_MIPS_MACH_4650
:
8267 return mach_mips4650
;
8269 case elfcpp::E_MIPS_MACH_5400
:
8270 return mach_mips5400
;
8272 case elfcpp::E_MIPS_MACH_5500
:
8273 return mach_mips5500
;
8275 case elfcpp::E_MIPS_MACH_9000
:
8276 return mach_mips9000
;
8278 case elfcpp::E_MIPS_MACH_SB1
:
8279 return mach_mips_sb1
;
8281 case elfcpp::E_MIPS_MACH_LS2E
:
8282 return mach_mips_loongson_2e
;
8284 case elfcpp::E_MIPS_MACH_LS2F
:
8285 return mach_mips_loongson_2f
;
8287 case elfcpp::E_MIPS_MACH_LS3A
:
8288 return mach_mips_loongson_3a
;
8290 case elfcpp::E_MIPS_MACH_OCTEON2
:
8291 return mach_mips_octeon2
;
8293 case elfcpp::E_MIPS_MACH_OCTEON
:
8294 return mach_mips_octeon
;
8296 case elfcpp::E_MIPS_MACH_XLR
:
8297 return mach_mips_xlr
;
8300 switch (flags
& elfcpp::EF_MIPS_ARCH
)
8303 case elfcpp::E_MIPS_ARCH_1
:
8304 return mach_mips3000
;
8306 case elfcpp::E_MIPS_ARCH_2
:
8307 return mach_mips6000
;
8309 case elfcpp::E_MIPS_ARCH_3
:
8310 return mach_mips4000
;
8312 case elfcpp::E_MIPS_ARCH_4
:
8313 return mach_mips8000
;
8315 case elfcpp::E_MIPS_ARCH_5
:
8318 case elfcpp::E_MIPS_ARCH_32
:
8319 return mach_mipsisa32
;
8321 case elfcpp::E_MIPS_ARCH_64
:
8322 return mach_mipsisa64
;
8324 case elfcpp::E_MIPS_ARCH_32R2
:
8325 return mach_mipsisa32r2
;
8327 case elfcpp::E_MIPS_ARCH_64R2
:
8328 return mach_mipsisa64r2
;
8335 // Check whether machine EXTENSION is an extension of machine BASE.
8336 template<int size
, bool big_endian
>
8338 Target_mips
<size
, big_endian
>::mips_mach_extends(unsigned int base
,
8339 unsigned int extension
)
8341 if (extension
== base
)
8344 if ((base
== mach_mipsisa32
)
8345 && this->mips_mach_extends(mach_mipsisa64
, extension
))
8348 if ((base
== mach_mipsisa32r2
)
8349 && this->mips_mach_extends(mach_mipsisa64r2
, extension
))
8352 for (unsigned int i
= 0; i
< this->mips_mach_extensions_
.size(); ++i
)
8353 if (extension
== this->mips_mach_extensions_
[i
].first
)
8355 extension
= this->mips_mach_extensions_
[i
].second
;
8356 if (extension
== base
)
8363 template<int size
, bool big_endian
>
8365 Target_mips
<size
, big_endian
>::merge_processor_specific_flags(
8366 const std::string
& name
, elfcpp::Elf_Word in_flags
, bool dyn_obj
)
8368 // If flags are not set yet, just copy them.
8369 if (!this->are_processor_specific_flags_set())
8371 this->set_processor_specific_flags(in_flags
);
8372 this->mach_
= this->elf_mips_mach(in_flags
);
8376 elfcpp::Elf_Word new_flags
= in_flags
;
8377 elfcpp::Elf_Word old_flags
= this->processor_specific_flags();
8378 elfcpp::Elf_Word merged_flags
= this->processor_specific_flags();
8379 merged_flags
|= new_flags
& elfcpp::EF_MIPS_NOREORDER
;
8381 // Check flag compatibility.
8382 new_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
8383 old_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
8385 // Some IRIX 6 BSD-compatibility objects have this bit set. It
8386 // doesn't seem to matter.
8387 new_flags
&= ~elfcpp::EF_MIPS_XGOT
;
8388 old_flags
&= ~elfcpp::EF_MIPS_XGOT
;
8390 // MIPSpro generates ucode info in n64 objects. Again, we should
8391 // just be able to ignore this.
8392 new_flags
&= ~elfcpp::EF_MIPS_UCODE
;
8393 old_flags
&= ~elfcpp::EF_MIPS_UCODE
;
8395 // DSOs should only be linked with CPIC code.
8397 new_flags
|= elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
;
8399 if (new_flags
== old_flags
)
8401 this->set_processor_specific_flags(merged_flags
);
8405 if (((new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0)
8406 != ((old_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0))
8407 gold_warning(_("%s: linking abicalls files with non-abicalls files"),
8410 if (new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
))
8411 merged_flags
|= elfcpp::EF_MIPS_CPIC
;
8412 if (!(new_flags
& elfcpp::EF_MIPS_PIC
))
8413 merged_flags
&= ~elfcpp::EF_MIPS_PIC
;
8415 new_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
8416 old_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
8418 // Compare the ISAs.
8419 if (mips_32bit_flags(old_flags
) != mips_32bit_flags(new_flags
))
8420 gold_error(_("%s: linking 32-bit code with 64-bit code"), name
.c_str());
8421 else if (!this->mips_mach_extends(this->elf_mips_mach(in_flags
), this->mach_
))
8423 // Output ISA isn't the same as, or an extension of, input ISA.
8424 if (this->mips_mach_extends(this->mach_
, this->elf_mips_mach(in_flags
)))
8426 // Copy the architecture info from input object to output. Also copy
8427 // the 32-bit flag (if set) so that we continue to recognise
8428 // output as a 32-bit binary.
8429 this->mach_
= this->elf_mips_mach(in_flags
);
8430 merged_flags
&= ~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
);
8431 merged_flags
|= (new_flags
& (elfcpp::EF_MIPS_ARCH
8432 | elfcpp::EF_MIPS_MACH
| elfcpp::EF_MIPS_32BITMODE
));
8434 // Copy across the ABI flags if output doesn't use them
8435 // and if that was what caused us to treat input object as 32-bit.
8436 if ((old_flags
& elfcpp::EF_MIPS_ABI
) == 0
8437 && this->mips_32bit_flags(new_flags
)
8438 && !this->mips_32bit_flags(new_flags
& ~elfcpp::EF_MIPS_ABI
))
8439 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ABI
;
8442 // The ISAs aren't compatible.
8443 gold_error(_("%s: linking %s module with previous %s modules"),
8444 name
.c_str(), this->elf_mips_mach_name(in_flags
),
8445 this->elf_mips_mach_name(merged_flags
));
8448 new_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
8449 | elfcpp::EF_MIPS_32BITMODE
));
8450 old_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
8451 | elfcpp::EF_MIPS_32BITMODE
));
8454 if ((new_flags
& elfcpp::EF_MIPS_ABI
) != (old_flags
& elfcpp::EF_MIPS_ABI
))
8456 // Only error if both are set (to different values).
8457 if ((new_flags
& elfcpp::EF_MIPS_ABI
)
8458 && (old_flags
& elfcpp::EF_MIPS_ABI
))
8459 gold_error(_("%s: ABI mismatch: linking %s module with "
8460 "previous %s modules"), name
.c_str(),
8461 this->elf_mips_abi_name(in_flags
),
8462 this->elf_mips_abi_name(merged_flags
));
8464 new_flags
&= ~elfcpp::EF_MIPS_ABI
;
8465 old_flags
&= ~elfcpp::EF_MIPS_ABI
;
8468 // Compare ASEs. Forbid linking MIPS16 and microMIPS ASE modules together
8469 // and allow arbitrary mixing of the remaining ASEs (retain the union).
8470 if ((new_flags
& elfcpp::EF_MIPS_ARCH_ASE
)
8471 != (old_flags
& elfcpp::EF_MIPS_ARCH_ASE
))
8473 int old_micro
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
8474 int new_micro
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
8475 int old_m16
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
8476 int new_m16
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
8477 int micro_mis
= old_m16
&& new_micro
;
8478 int m16_mis
= old_micro
&& new_m16
;
8480 if (m16_mis
|| micro_mis
)
8481 gold_error(_("%s: ASE mismatch: linking %s module with "
8482 "previous %s modules"), name
.c_str(),
8483 m16_mis
? "MIPS16" : "microMIPS",
8484 m16_mis
? "microMIPS" : "MIPS16");
8486 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ARCH_ASE
;
8488 new_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
8489 old_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
8492 // Warn about any other mismatches.
8493 if (new_flags
!= old_flags
)
8494 gold_error(_("%s: uses different e_flags (0x%x) fields than previous "
8495 "modules (0x%x)"), name
.c_str(), new_flags
, old_flags
);
8497 this->set_processor_specific_flags(merged_flags
);
8500 // Adjust ELF file header.
8502 template<int size
, bool big_endian
>
8504 Target_mips
<size
, big_endian
>::do_adjust_elf_header(
8505 unsigned char* view
,
8508 gold_assert(len
== elfcpp::Elf_sizes
<size
>::ehdr_size
);
8510 if (!this->entry_symbol_is_compressed_
)
8513 elfcpp::Ehdr
<size
, big_endian
> ehdr(view
);
8514 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
8516 oehdr
.put_e_entry(ehdr
.get_e_entry() + 1);
8519 // do_make_elf_object to override the same function in the base class.
8520 // We need to use a target-specific sub-class of
8521 // Sized_relobj_file<size, big_endian> to store Mips specific information.
8522 // Hence we need to have our own ELF object creation.
8524 template<int size
, bool big_endian
>
8526 Target_mips
<size
, big_endian
>::do_make_elf_object(
8527 const std::string
& name
,
8528 Input_file
* input_file
,
8529 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
8531 int et
= ehdr
.get_e_type();
8532 // ET_EXEC files are valid input for --just-symbols/-R,
8533 // and we treat them as relocatable objects.
8534 if (et
== elfcpp::ET_REL
8535 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
8537 Mips_relobj
<size
, big_endian
>* obj
=
8538 new Mips_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
8542 else if (et
== elfcpp::ET_DYN
)
8544 // TODO(sasa): Should we create Mips_dynobj?
8545 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
8549 gold_error(_("%s: unsupported ELF file type %d"),
8555 // Finalize the sections.
8557 template <int size
, bool big_endian
>
8559 Target_mips
<size
, big_endian
>::do_finalize_sections(Layout
* layout
,
8560 const Input_objects
* input_objects
,
8561 Symbol_table
* symtab
)
8563 // Add +1 to MIPS16 and microMIPS init_ and _fini symbols so that DT_INIT and
8564 // DT_FINI have correct values.
8565 Mips_symbol
<size
>* init
= static_cast<Mips_symbol
<size
>*>(
8566 symtab
->lookup(parameters
->options().init()));
8567 if (init
!= NULL
&& (init
->is_mips16() || init
->is_micromips()))
8568 init
->set_value(init
->value() | 1);
8569 Mips_symbol
<size
>* fini
= static_cast<Mips_symbol
<size
>*>(
8570 symtab
->lookup(parameters
->options().fini()));
8571 if (fini
!= NULL
&& (fini
->is_mips16() || fini
->is_micromips()))
8572 fini
->set_value(fini
->value() | 1);
8574 // Check whether the entry symbol is mips16 or micromips. This is needed to
8575 // adjust entry address in ELF header.
8576 Mips_symbol
<size
>* entry
=
8577 static_cast<Mips_symbol
<size
>*>(symtab
->lookup(this->entry_symbol_name()));
8578 this->entry_symbol_is_compressed_
= (entry
!= NULL
&& (entry
->is_mips16()
8579 || entry
->is_micromips()));
8581 if (!parameters
->doing_static_link()
8582 && (strcmp(parameters
->options().hash_style(), "gnu") == 0
8583 || strcmp(parameters
->options().hash_style(), "both") == 0))
8585 // .gnu.hash and the MIPS ABI require .dynsym to be sorted in different
8586 // ways. .gnu.hash needs symbols to be grouped by hash code whereas the
8587 // MIPS ABI requires a mapping between the GOT and the symbol table.
8588 gold_error(".gnu.hash is incompatible with the MIPS ABI");
8591 // Check whether the final section that was scanned has HI16 or GOT16
8592 // relocations without the corresponding LO16 part.
8593 if (this->got16_addends_
.size() > 0)
8594 gold_error("Can't find matching LO16 reloc");
8597 this->set_gp(layout
, symtab
);
8599 // Check for any mips16 stub sections that we can discard.
8600 if (!parameters
->options().relocatable())
8602 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8603 p
!= input_objects
->relobj_end();
8606 Mips_relobj
<size
, big_endian
>* object
=
8607 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
8608 object
->discard_mips16_stub_sections(symtab
);
8612 // Merge processor-specific flags.
8613 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8614 p
!= input_objects
->relobj_end();
8617 Mips_relobj
<size
, big_endian
>* relobj
=
8618 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
8620 Input_file::Format format
= relobj
->input_file()->format();
8621 if (format
== Input_file::FORMAT_ELF
)
8623 // Read processor-specific flags in ELF file header.
8624 const unsigned char* pehdr
= relobj
->get_view(
8625 elfcpp::file_header_offset
,
8626 elfcpp::Elf_sizes
<size
>::ehdr_size
,
8629 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
8630 elfcpp::Elf_Word in_flags
= ehdr
.get_e_flags();
8631 // If all input sections will be discarded, don't use this object
8632 // file for merging processor specific flags.
8633 bool should_merge_processor_specific_flags
= false;
8635 for (unsigned int i
= 1; i
< relobj
->shnum(); ++i
)
8636 if (relobj
->output_section(i
) != NULL
)
8638 should_merge_processor_specific_flags
= true;
8642 if (should_merge_processor_specific_flags
)
8643 this->merge_processor_specific_flags(relobj
->name(), in_flags
,
8648 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
8649 p
!= input_objects
->dynobj_end();
8652 Sized_dynobj
<size
, big_endian
>* dynobj
=
8653 static_cast<Sized_dynobj
<size
, big_endian
>*>(*p
);
8655 // Read processor-specific flags.
8656 const unsigned char* pehdr
= dynobj
->get_view(elfcpp::file_header_offset
,
8657 elfcpp::Elf_sizes
<size
>::ehdr_size
,
8660 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
8661 elfcpp::Elf_Word in_flags
= ehdr
.get_e_flags();
8663 this->merge_processor_specific_flags(dynobj
->name(), in_flags
, true);
8666 // Merge .reginfo contents of input objects.
8667 Valtype gprmask
= 0;
8668 Valtype cprmask1
= 0;
8669 Valtype cprmask2
= 0;
8670 Valtype cprmask3
= 0;
8671 Valtype cprmask4
= 0;
8672 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8673 p
!= input_objects
->relobj_end();
8676 Mips_relobj
<size
, big_endian
>* relobj
=
8677 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
8679 gprmask
|= relobj
->gprmask();
8680 cprmask1
|= relobj
->cprmask1();
8681 cprmask2
|= relobj
->cprmask2();
8682 cprmask3
|= relobj
->cprmask3();
8683 cprmask4
|= relobj
->cprmask4();
8686 if (this->plt_
!= NULL
)
8688 // Set final PLT offsets for symbols.
8689 this->plt_section()->set_plt_offsets();
8691 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
8692 // Set STO_MICROMIPS flag if the output has microMIPS code, but only if
8693 // there are no standard PLT entries present.
8694 unsigned char nonvis
= 0;
8695 if (this->is_output_micromips()
8696 && !this->plt_section()->has_standard_entries())
8697 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
8698 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
8699 Symbol_table::PREDEFINED
,
8701 0, 0, elfcpp::STT_FUNC
,
8703 elfcpp::STV_DEFAULT
, nonvis
,
8707 if (this->mips_stubs_
!= NULL
)
8709 // Define _MIPS_STUBS_ at the start of the .MIPS.stubs section.
8710 unsigned char nonvis
= 0;
8711 if (this->is_output_micromips())
8712 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
8713 symtab
->define_in_output_data("_MIPS_STUBS_", NULL
,
8714 Symbol_table::PREDEFINED
,
8716 0, 0, elfcpp::STT_FUNC
,
8718 elfcpp::STV_DEFAULT
, nonvis
,
8722 if (!parameters
->options().relocatable() && !parameters
->doing_static_link())
8723 // In case there is no .got section, create one.
8724 this->got_section(symtab
, layout
);
8726 // Emit any relocs we saved in an attempt to avoid generating COPY
8728 if (this->copy_relocs_
.any_saved_relocs())
8729 this->copy_relocs_
.emit_mips(this->rel_dyn_section(layout
), symtab
, layout
,
8732 // Emit dynamic relocs.
8733 for (typename
std::vector
<Dyn_reloc
>::iterator p
= this->dyn_relocs_
.begin();
8734 p
!= this->dyn_relocs_
.end();
8736 p
->emit(this->rel_dyn_section(layout
), this->got_section(), symtab
);
8738 if (this->has_got_section())
8739 this->got_section()->lay_out_got(layout
, symtab
, input_objects
);
8741 if (this->mips_stubs_
!= NULL
)
8742 this->mips_stubs_
->set_needs_dynsym_value();
8744 // Check for functions that might need $25 to be valid on entry.
8745 // TODO(sasa): Can we do this without iterating over all symbols?
8746 typedef Symbol_visitor_check_symbols
<size
, big_endian
> Symbol_visitor
;
8747 symtab
->for_all_symbols
<size
, Symbol_visitor
>(Symbol_visitor(this, layout
,
8750 // Add NULL segment.
8751 if (!parameters
->options().relocatable())
8752 layout
->make_output_segment(elfcpp::PT_NULL
, 0);
8754 for (Layout::Section_list::const_iterator p
= layout
->section_list().begin();
8755 p
!= layout
->section_list().end();
8758 if ((*p
)->type() == elfcpp::SHT_MIPS_REGINFO
)
8760 Mips_output_section_reginfo
<size
, big_endian
>* reginfo
=
8761 Mips_output_section_reginfo
<size
, big_endian
>::
8762 as_mips_output_section_reginfo(*p
);
8764 reginfo
->set_masks(gprmask
, cprmask1
, cprmask2
, cprmask3
, cprmask4
);
8766 if (!parameters
->options().relocatable())
8768 Output_segment
* reginfo_segment
=
8769 layout
->make_output_segment(elfcpp::PT_MIPS_REGINFO
,
8771 reginfo_segment
->add_output_section_to_nonload(reginfo
,
8777 // Fill in some more dynamic tags.
8778 // TODO(sasa): Add more dynamic tags.
8779 const Reloc_section
* rel_plt
= (this->plt_
== NULL
8780 ? NULL
: this->plt_
->rel_plt());
8781 layout
->add_target_dynamic_tags(true, this->got_
, rel_plt
,
8782 this->rel_dyn_
, true, false);
8784 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
8786 && !parameters
->options().relocatable()
8787 && !parameters
->doing_static_link())
8790 // This element holds a 32-bit version id for the Runtime
8791 // Linker Interface. This will start at integer value 1.
8793 odyn
->add_constant(elfcpp::DT_MIPS_RLD_VERSION
, d_val
);
8796 d_val
= elfcpp::RHF_NOTPOT
;
8797 odyn
->add_constant(elfcpp::DT_MIPS_FLAGS
, d_val
);
8799 // Save layout for using when emiting custom dynamic tags.
8800 this->layout_
= layout
;
8802 // This member holds the base address of the segment.
8803 odyn
->add_custom(elfcpp::DT_MIPS_BASE_ADDRESS
);
8805 // This member holds the number of entries in the .dynsym section.
8806 odyn
->add_custom(elfcpp::DT_MIPS_SYMTABNO
);
8808 // This member holds the index of the first dynamic symbol
8809 // table entry that corresponds to an entry in the global offset table.
8810 odyn
->add_custom(elfcpp::DT_MIPS_GOTSYM
);
8812 // This member holds the number of local GOT entries.
8813 odyn
->add_constant(elfcpp::DT_MIPS_LOCAL_GOTNO
,
8814 this->got_
->get_local_gotno());
8816 if (this->plt_
!= NULL
)
8817 // DT_MIPS_PLTGOT dynamic tag
8818 odyn
->add_section_address(elfcpp::DT_MIPS_PLTGOT
, this->got_plt_
);
8822 // Get the custom dynamic tag value.
8823 template<int size
, bool big_endian
>
8825 Target_mips
<size
, big_endian
>::do_dynamic_tag_custom_value(elfcpp::DT tag
) const
8829 case elfcpp::DT_MIPS_BASE_ADDRESS
:
8831 // The base address of the segment.
8832 // At this point, the segment list has been sorted into final order,
8833 // so just return vaddr of the first readable PT_LOAD segment.
8834 Output_segment
* seg
=
8835 this->layout_
->find_output_segment(elfcpp::PT_LOAD
, elfcpp::PF_R
, 0);
8836 gold_assert(seg
!= NULL
);
8837 return seg
->vaddr();
8840 case elfcpp::DT_MIPS_SYMTABNO
:
8841 // The number of entries in the .dynsym section.
8842 return this->get_dt_mips_symtabno();
8844 case elfcpp::DT_MIPS_GOTSYM
:
8846 // The index of the first dynamic symbol table entry that corresponds
8847 // to an entry in the GOT.
8848 if (this->got_
->first_global_got_dynsym_index() != -1U)
8849 return this->got_
->first_global_got_dynsym_index();
8851 // In case if we don't have global GOT symbols we default to setting
8852 // DT_MIPS_GOTSYM to the same value as DT_MIPS_SYMTABNO.
8853 return this->get_dt_mips_symtabno();
8857 gold_error(_("Unknown dynamic tag 0x%x"), (unsigned int)tag
);
8860 return (unsigned int)-1;
8863 // Relocate section data.
8865 template<int size
, bool big_endian
>
8867 Target_mips
<size
, big_endian
>::relocate_section(
8868 const Relocate_info
<size
, big_endian
>* relinfo
,
8869 unsigned int sh_type
,
8870 const unsigned char* prelocs
,
8872 Output_section
* output_section
,
8873 bool needs_special_offset_handling
,
8874 unsigned char* view
,
8875 Mips_address address
,
8876 section_size_type view_size
,
8877 const Reloc_symbol_changes
* reloc_symbol_changes
)
8879 typedef Target_mips
<size
, big_endian
> Mips
;
8880 typedef typename Target_mips
<size
, big_endian
>::Relocate Mips_relocate
;
8882 if (sh_type
== elfcpp::SHT_REL
)
8884 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8887 gold::relocate_section
<size
, big_endian
, Mips
, Mips_relocate
,
8888 gold::Default_comdat_behavior
, Classify_reloc
>(
8894 needs_special_offset_handling
,
8898 reloc_symbol_changes
);
8900 else if (sh_type
== elfcpp::SHT_RELA
)
8902 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8905 gold::relocate_section
<size
, big_endian
, Mips
, Mips_relocate
,
8906 gold::Default_comdat_behavior
, Classify_reloc
>(
8912 needs_special_offset_handling
,
8916 reloc_symbol_changes
);
8920 // Return the size of a relocation while scanning during a relocatable
8924 mips_get_size_for_reloc(unsigned int r_type
, Relobj
* object
)
8928 case elfcpp::R_MIPS_NONE
:
8929 case elfcpp::R_MIPS_TLS_DTPMOD64
:
8930 case elfcpp::R_MIPS_TLS_DTPREL64
:
8931 case elfcpp::R_MIPS_TLS_TPREL64
:
8934 case elfcpp::R_MIPS_32
:
8935 case elfcpp::R_MIPS_TLS_DTPMOD32
:
8936 case elfcpp::R_MIPS_TLS_DTPREL32
:
8937 case elfcpp::R_MIPS_TLS_TPREL32
:
8938 case elfcpp::R_MIPS_REL32
:
8939 case elfcpp::R_MIPS_PC32
:
8940 case elfcpp::R_MIPS_GPREL32
:
8941 case elfcpp::R_MIPS_JALR
:
8942 case elfcpp::R_MIPS_EH
:
8945 case elfcpp::R_MIPS_16
:
8946 case elfcpp::R_MIPS_HI16
:
8947 case elfcpp::R_MIPS_LO16
:
8948 case elfcpp::R_MIPS_GPREL16
:
8949 case elfcpp::R_MIPS16_HI16
:
8950 case elfcpp::R_MIPS16_LO16
:
8951 case elfcpp::R_MIPS_PC16
:
8952 case elfcpp::R_MIPS_GOT16
:
8953 case elfcpp::R_MIPS16_GOT16
:
8954 case elfcpp::R_MIPS_CALL16
:
8955 case elfcpp::R_MIPS16_CALL16
:
8956 case elfcpp::R_MIPS_GOT_HI16
:
8957 case elfcpp::R_MIPS_CALL_HI16
:
8958 case elfcpp::R_MIPS_GOT_LO16
:
8959 case elfcpp::R_MIPS_CALL_LO16
:
8960 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
8961 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
8962 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
8963 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
8964 case elfcpp::R_MIPS16_GPREL
:
8965 case elfcpp::R_MIPS_GOT_DISP
:
8966 case elfcpp::R_MIPS_LITERAL
:
8967 case elfcpp::R_MIPS_GOT_PAGE
:
8968 case elfcpp::R_MIPS_GOT_OFST
:
8969 case elfcpp::R_MIPS_TLS_GD
:
8970 case elfcpp::R_MIPS_TLS_LDM
:
8971 case elfcpp::R_MIPS_TLS_GOTTPREL
:
8974 // These relocations are not byte sized
8975 case elfcpp::R_MIPS_26
:
8976 case elfcpp::R_MIPS16_26
:
8979 case elfcpp::R_MIPS_COPY
:
8980 case elfcpp::R_MIPS_JUMP_SLOT
:
8981 object
->error(_("unexpected reloc %u in object file"), r_type
);
8985 object
->error(_("unsupported reloc %u in object file"), r_type
);
8990 // Scan the relocs during a relocatable link.
8992 template<int size
, bool big_endian
>
8994 Target_mips
<size
, big_endian
>::scan_relocatable_relocs(
8995 Symbol_table
* symtab
,
8997 Sized_relobj_file
<size
, big_endian
>* object
,
8998 unsigned int data_shndx
,
8999 unsigned int sh_type
,
9000 const unsigned char* prelocs
,
9002 Output_section
* output_section
,
9003 bool needs_special_offset_handling
,
9004 size_t local_symbol_count
,
9005 const unsigned char* plocal_symbols
,
9006 Relocatable_relocs
* rr
)
9008 if (sh_type
== elfcpp::SHT_REL
)
9010 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
9012 typedef Mips_scan_relocatable_relocs
<big_endian
, Classify_reloc
>
9013 Scan_relocatable_relocs
;
9015 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_relocatable_relocs
>(
9023 needs_special_offset_handling
,
9028 else if (sh_type
== elfcpp::SHT_RELA
)
9030 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9032 typedef Mips_scan_relocatable_relocs
<big_endian
, Classify_reloc
>
9033 Scan_relocatable_relocs
;
9035 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_relocatable_relocs
>(
9043 needs_special_offset_handling
,
9052 // Scan the relocs for --emit-relocs.
9054 template<int size
, bool big_endian
>
9056 Target_mips
<size
, big_endian
>::emit_relocs_scan(
9057 Symbol_table
* symtab
,
9059 Sized_relobj_file
<size
, big_endian
>* object
,
9060 unsigned int data_shndx
,
9061 unsigned int sh_type
,
9062 const unsigned char* prelocs
,
9064 Output_section
* output_section
,
9065 bool needs_special_offset_handling
,
9066 size_t local_symbol_count
,
9067 const unsigned char* plocal_syms
,
9068 Relocatable_relocs
* rr
)
9070 if (sh_type
== elfcpp::SHT_REL
)
9072 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
9074 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
9075 Emit_relocs_strategy
;
9077 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
9085 needs_special_offset_handling
,
9090 else if (sh_type
== elfcpp::SHT_RELA
)
9092 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9094 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
9095 Emit_relocs_strategy
;
9097 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
9105 needs_special_offset_handling
,
9114 // Emit relocations for a section.
9116 template<int size
, bool big_endian
>
9118 Target_mips
<size
, big_endian
>::relocate_relocs(
9119 const Relocate_info
<size
, big_endian
>* relinfo
,
9120 unsigned int sh_type
,
9121 const unsigned char* prelocs
,
9123 Output_section
* output_section
,
9124 typename
elfcpp::Elf_types
<size
>::Elf_Off
9125 offset_in_output_section
,
9126 unsigned char* view
,
9127 Mips_address view_address
,
9128 section_size_type view_size
,
9129 unsigned char* reloc_view
,
9130 section_size_type reloc_view_size
)
9132 if (sh_type
== elfcpp::SHT_REL
)
9134 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
9137 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
9142 offset_in_output_section
,
9149 else if (sh_type
== elfcpp::SHT_RELA
)
9151 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9154 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
9159 offset_in_output_section
,
9170 // Perform target-specific processing in a relocatable link. This is
9171 // only used if we use the relocation strategy RELOC_SPECIAL.
9173 template<int size
, bool big_endian
>
9175 Target_mips
<size
, big_endian
>::relocate_special_relocatable(
9176 const Relocate_info
<size
, big_endian
>* relinfo
,
9177 unsigned int sh_type
,
9178 const unsigned char* preloc_in
,
9180 Output_section
* output_section
,
9181 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
9182 unsigned char* view
,
9183 Mips_address view_address
,
9185 unsigned char* preloc_out
)
9187 // We can only handle REL type relocation sections.
9188 gold_assert(sh_type
== elfcpp::SHT_REL
);
9190 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
9192 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc_write
9195 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
9197 const Mips_address invalid_address
= static_cast<Mips_address
>(0) - 1;
9199 Mips_relobj
<size
, big_endian
>* object
=
9200 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
9201 const unsigned int local_count
= object
->local_symbol_count();
9203 Reltype
reloc(preloc_in
);
9204 Reltype_write
reloc_write(preloc_out
);
9206 elfcpp::Elf_types
<32>::Elf_WXword r_info
= reloc
.get_r_info();
9207 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
9208 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
9210 // Get the new symbol index.
9211 // We only use RELOC_SPECIAL strategy in local relocations.
9212 gold_assert(r_sym
< local_count
);
9214 // We are adjusting a section symbol. We need to find
9215 // the symbol table index of the section symbol for
9216 // the output section corresponding to input section
9217 // in which this symbol is defined.
9219 unsigned int shndx
= object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
9220 gold_assert(is_ordinary
);
9221 Output_section
* os
= object
->output_section(shndx
);
9222 gold_assert(os
!= NULL
);
9223 gold_assert(os
->needs_symtab_index());
9224 unsigned int new_symndx
= os
->symtab_index();
9226 // Get the new offset--the location in the output section where
9227 // this relocation should be applied.
9229 Mips_address offset
= reloc
.get_r_offset();
9230 Mips_address new_offset
;
9231 if (offset_in_output_section
!= invalid_address
)
9232 new_offset
= offset
+ offset_in_output_section
;
9235 section_offset_type sot_offset
=
9236 convert_types
<section_offset_type
, Mips_address
>(offset
);
9237 section_offset_type new_sot_offset
=
9238 output_section
->output_offset(object
, relinfo
->data_shndx
,
9240 gold_assert(new_sot_offset
!= -1);
9241 new_offset
= new_sot_offset
;
9244 // In an object file, r_offset is an offset within the section.
9245 // In an executable or dynamic object, generated by
9246 // --emit-relocs, r_offset is an absolute address.
9247 if (!parameters
->options().relocatable())
9249 new_offset
+= view_address
;
9250 if (offset_in_output_section
!= invalid_address
)
9251 new_offset
-= offset_in_output_section
;
9254 reloc_write
.put_r_offset(new_offset
);
9255 reloc_write
.put_r_info(elfcpp::elf_r_info
<32>(new_symndx
, r_type
));
9257 // Handle the reloc addend.
9258 // The relocation uses a section symbol in the input file.
9259 // We are adjusting it to use a section symbol in the output
9260 // file. The input section symbol refers to some address in
9261 // the input section. We need the relocation in the output
9262 // file to refer to that same address. This adjustment to
9263 // the addend is the same calculation we use for a simple
9264 // absolute relocation for the input section symbol.
9265 Valtype calculated_value
= 0;
9266 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
9268 unsigned char* paddend
= view
+ offset
;
9269 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
9272 case elfcpp::R_MIPS_26
:
9273 reloc_status
= Reloc_funcs::rel26(paddend
, object
, psymval
,
9274 offset_in_output_section
, true, 0, sh_type
== elfcpp::SHT_REL
, NULL
,
9275 false /*TODO(sasa): cross mode jump*/, r_type
, this->jal_to_bal(),
9276 false, &calculated_value
);
9283 // Report any errors.
9284 switch (reloc_status
)
9286 case Reloc_funcs::STATUS_OKAY
:
9288 case Reloc_funcs::STATUS_OVERFLOW
:
9289 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
9290 _("relocation overflow"));
9292 case Reloc_funcs::STATUS_BAD_RELOC
:
9293 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
9294 _("unexpected opcode while processing relocation"));
9301 // Optimize the TLS relocation type based on what we know about the
9302 // symbol. IS_FINAL is true if the final address of this symbol is
9303 // known at link time.
9305 template<int size
, bool big_endian
>
9306 tls::Tls_optimization
9307 Target_mips
<size
, big_endian
>::optimize_tls_reloc(bool, int)
9309 // FIXME: Currently we do not do any TLS optimization.
9310 return tls::TLSOPT_NONE
;
9313 // Scan a relocation for a local symbol.
9315 template<int size
, bool big_endian
>
9317 Target_mips
<size
, big_endian
>::Scan::local(
9318 Symbol_table
* symtab
,
9320 Target_mips
<size
, big_endian
>* target
,
9321 Sized_relobj_file
<size
, big_endian
>* object
,
9322 unsigned int data_shndx
,
9323 Output_section
* output_section
,
9324 const Relatype
* rela
,
9326 unsigned int rel_type
,
9327 unsigned int r_type
,
9328 const elfcpp::Sym
<size
, big_endian
>& lsym
,
9334 Mips_address r_offset
;
9336 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
9338 if (rel_type
== elfcpp::SHT_RELA
)
9340 r_offset
= rela
->get_r_offset();
9341 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
9343 r_addend
= rela
->get_r_addend();
9347 r_offset
= rel
->get_r_offset();
9348 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
9353 Mips_relobj
<size
, big_endian
>* mips_obj
=
9354 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
9356 if (mips_obj
->is_mips16_stub_section(data_shndx
))
9358 mips_obj
->get_mips16_stub_section(data_shndx
)
9359 ->new_local_reloc_found(r_type
, r_sym
);
9362 if (r_type
== elfcpp::R_MIPS_NONE
)
9363 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
9367 if (!mips16_call_reloc(r_type
)
9368 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
9369 // This reloc would need to refer to a MIPS16 hard-float stub, if
9370 // there is one. We ignore MIPS16 stub sections and .pdr section when
9371 // looking for relocs that would need to refer to MIPS16 stubs.
9372 mips_obj
->add_local_non_16bit_call(r_sym
);
9374 if (r_type
== elfcpp::R_MIPS16_26
9375 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
9376 mips_obj
->add_local_16bit_call(r_sym
);
9380 case elfcpp::R_MIPS_GOT16
:
9381 case elfcpp::R_MIPS_CALL16
:
9382 case elfcpp::R_MIPS_CALL_HI16
:
9383 case elfcpp::R_MIPS_CALL_LO16
:
9384 case elfcpp::R_MIPS_GOT_HI16
:
9385 case elfcpp::R_MIPS_GOT_LO16
:
9386 case elfcpp::R_MIPS_GOT_PAGE
:
9387 case elfcpp::R_MIPS_GOT_OFST
:
9388 case elfcpp::R_MIPS_GOT_DISP
:
9389 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9390 case elfcpp::R_MIPS_TLS_GD
:
9391 case elfcpp::R_MIPS_TLS_LDM
:
9392 case elfcpp::R_MIPS16_GOT16
:
9393 case elfcpp::R_MIPS16_CALL16
:
9394 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9395 case elfcpp::R_MIPS16_TLS_GD
:
9396 case elfcpp::R_MIPS16_TLS_LDM
:
9397 case elfcpp::R_MICROMIPS_GOT16
:
9398 case elfcpp::R_MICROMIPS_CALL16
:
9399 case elfcpp::R_MICROMIPS_CALL_HI16
:
9400 case elfcpp::R_MICROMIPS_CALL_LO16
:
9401 case elfcpp::R_MICROMIPS_GOT_HI16
:
9402 case elfcpp::R_MICROMIPS_GOT_LO16
:
9403 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9404 case elfcpp::R_MICROMIPS_GOT_OFST
:
9405 case elfcpp::R_MICROMIPS_GOT_DISP
:
9406 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9407 case elfcpp::R_MICROMIPS_TLS_GD
:
9408 case elfcpp::R_MICROMIPS_TLS_LDM
:
9409 case elfcpp::R_MIPS_EH
:
9410 // We need a GOT section.
9411 target
->got_section(symtab
, layout
);
9418 if (call_lo16_reloc(r_type
)
9419 || got_lo16_reloc(r_type
)
9420 || got_disp_reloc(r_type
)
9421 || eh_reloc(r_type
))
9423 // We may need a local GOT entry for this relocation. We
9424 // don't count R_MIPS_GOT_PAGE because we can estimate the
9425 // maximum number of pages needed by looking at the size of
9426 // the segment. Similar comments apply to R_MIPS*_GOT16 and
9427 // R_MIPS*_CALL16. We don't count R_MIPS_GOT_HI16, or
9428 // R_MIPS_CALL_HI16 because these are always followed by an
9429 // R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
9430 Mips_output_data_got
<size
, big_endian
>* got
=
9431 target
->got_section(symtab
, layout
);
9432 bool is_section_symbol
= lsym
.get_st_type() == elfcpp::STT_SECTION
;
9433 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
, -1U,
9439 case elfcpp::R_MIPS_CALL16
:
9440 case elfcpp::R_MIPS16_CALL16
:
9441 case elfcpp::R_MICROMIPS_CALL16
:
9442 gold_error(_("CALL16 reloc at 0x%lx not against global symbol "),
9443 (unsigned long)r_offset
);
9446 case elfcpp::R_MIPS_GOT_PAGE
:
9447 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9448 case elfcpp::R_MIPS16_GOT16
:
9449 case elfcpp::R_MIPS_GOT16
:
9450 case elfcpp::R_MIPS_GOT_HI16
:
9451 case elfcpp::R_MIPS_GOT_LO16
:
9452 case elfcpp::R_MICROMIPS_GOT16
:
9453 case elfcpp::R_MICROMIPS_GOT_HI16
:
9454 case elfcpp::R_MICROMIPS_GOT_LO16
:
9456 // This relocation needs a page entry in the GOT.
9457 // Get the section contents.
9458 section_size_type view_size
= 0;
9459 const unsigned char* view
= object
->section_contents(data_shndx
,
9463 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
9464 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
9467 if (rel_type
== elfcpp::SHT_REL
&& got16_reloc(r_type
))
9468 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
9469 object
, data_shndx
, r_type
, r_sym
, addend
));
9471 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
, addend
);
9475 case elfcpp::R_MIPS_HI16
:
9476 case elfcpp::R_MIPS16_HI16
:
9477 case elfcpp::R_MICROMIPS_HI16
:
9478 // Record the reloc so that we can check whether the corresponding LO16
9480 if (rel_type
== elfcpp::SHT_REL
)
9481 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
9482 object
, data_shndx
, r_type
, r_sym
, 0));
9485 case elfcpp::R_MIPS_LO16
:
9486 case elfcpp::R_MIPS16_LO16
:
9487 case elfcpp::R_MICROMIPS_LO16
:
9489 if (rel_type
!= elfcpp::SHT_REL
)
9492 // Find corresponding GOT16/HI16 relocation.
9494 // According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
9495 // be immediately following. However, for the IRIX6 ABI, the next
9496 // relocation may be a composed relocation consisting of several
9497 // relocations for the same address. In that case, the R_MIPS_LO16
9498 // relocation may occur as one of these. We permit a similar
9499 // extension in general, as that is useful for GCC.
9501 // In some cases GCC dead code elimination removes the LO16 but
9502 // keeps the corresponding HI16. This is strictly speaking a
9503 // violation of the ABI but not immediately harmful.
9505 typename
std::list
<got16_addend
<size
, big_endian
> >::iterator it
=
9506 target
->got16_addends_
.begin();
9507 while (it
!= target
->got16_addends_
.end())
9509 got16_addend
<size
, big_endian
> _got16_addend
= *it
;
9511 // TODO(sasa): Split got16_addends_ list into two lists - one for
9512 // GOT16 relocs and the other for HI16 relocs.
9514 // Report an error if we find HI16 or GOT16 reloc from the
9515 // previous section without the matching LO16 part.
9516 if (_got16_addend
.object
!= object
9517 || _got16_addend
.shndx
!= data_shndx
)
9519 gold_error("Can't find matching LO16 reloc");
9523 if (_got16_addend
.r_sym
!= r_sym
9524 || !is_matching_lo16_reloc(_got16_addend
.r_type
, r_type
))
9530 // We found a matching HI16 or GOT16 reloc for this LO16 reloc.
9531 // For GOT16, we need to calculate combined addend and record GOT page
9533 if (got16_reloc(_got16_addend
.r_type
))
9536 section_size_type view_size
= 0;
9537 const unsigned char* view
= object
->section_contents(data_shndx
,
9542 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
9543 int32_t addend
= Bits
<16>::sign_extend32(val
& 0xffff);
9545 addend
= (_got16_addend
.addend
<< 16) + addend
;
9546 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
,
9550 it
= target
->got16_addends_
.erase(it
);
9558 case elfcpp::R_MIPS_32
:
9559 case elfcpp::R_MIPS_REL32
:
9560 case elfcpp::R_MIPS_64
:
9562 if (parameters
->options().output_is_position_independent())
9564 // If building a shared library (or a position-independent
9565 // executable), we need to create a dynamic relocation for
9567 if (is_readonly_section(output_section
))
9569 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
9570 rel_dyn
->add_symbolless_local_addend(object
, r_sym
,
9571 elfcpp::R_MIPS_REL32
,
9572 output_section
, data_shndx
,
9578 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9579 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9580 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9581 case elfcpp::R_MIPS_TLS_LDM
:
9582 case elfcpp::R_MIPS16_TLS_LDM
:
9583 case elfcpp::R_MICROMIPS_TLS_LDM
:
9584 case elfcpp::R_MIPS_TLS_GD
:
9585 case elfcpp::R_MIPS16_TLS_GD
:
9586 case elfcpp::R_MICROMIPS_TLS_GD
:
9588 bool output_is_shared
= parameters
->options().shared();
9589 const tls::Tls_optimization optimized_type
9590 = Target_mips
<size
, big_endian
>::optimize_tls_reloc(
9591 !output_is_shared
, r_type
);
9594 case elfcpp::R_MIPS_TLS_GD
:
9595 case elfcpp::R_MIPS16_TLS_GD
:
9596 case elfcpp::R_MICROMIPS_TLS_GD
:
9597 if (optimized_type
== tls::TLSOPT_NONE
)
9599 // Create a pair of GOT entries for the module index and
9600 // dtv-relative offset.
9601 Mips_output_data_got
<size
, big_endian
>* got
=
9602 target
->got_section(symtab
, layout
);
9603 unsigned int shndx
= lsym
.get_st_shndx();
9605 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
9608 object
->error(_("local symbol %u has bad shndx %u"),
9612 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
9617 // FIXME: TLS optimization not supported yet.
9622 case elfcpp::R_MIPS_TLS_LDM
:
9623 case elfcpp::R_MIPS16_TLS_LDM
:
9624 case elfcpp::R_MICROMIPS_TLS_LDM
:
9625 if (optimized_type
== tls::TLSOPT_NONE
)
9627 // We always record LDM symbols as local with index 0.
9628 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
9634 // FIXME: TLS optimization not supported yet.
9638 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9639 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9640 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9641 layout
->set_has_static_tls();
9642 if (optimized_type
== tls::TLSOPT_NONE
)
9644 // Create a GOT entry for the tp-relative offset.
9645 Mips_output_data_got
<size
, big_endian
>* got
=
9646 target
->got_section(symtab
, layout
);
9647 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
9652 // FIXME: TLS optimization not supported yet.
9667 // Refuse some position-dependent relocations when creating a
9668 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
9669 // not PIC, but we can create dynamic relocations and the result
9670 // will be fine. Also do not refuse R_MIPS_LO16, which can be
9671 // combined with R_MIPS_GOT16.
9672 if (parameters
->options().shared())
9676 case elfcpp::R_MIPS16_HI16
:
9677 case elfcpp::R_MIPS_HI16
:
9678 case elfcpp::R_MICROMIPS_HI16
:
9679 // Don't refuse a high part relocation if it's against
9680 // no symbol (e.g. part of a compound relocation).
9686 case elfcpp::R_MIPS16_26
:
9687 case elfcpp::R_MIPS_26
:
9688 case elfcpp::R_MICROMIPS_26_S1
:
9689 gold_error(_("%s: relocation %u against `%s' can not be used when "
9690 "making a shared object; recompile with -fPIC"),
9691 object
->name().c_str(), r_type
, "a local symbol");
9698 template<int size
, bool big_endian
>
9700 Target_mips
<size
, big_endian
>::Scan::local(
9701 Symbol_table
* symtab
,
9703 Target_mips
<size
, big_endian
>* target
,
9704 Sized_relobj_file
<size
, big_endian
>* object
,
9705 unsigned int data_shndx
,
9706 Output_section
* output_section
,
9707 const Reltype
& reloc
,
9708 unsigned int r_type
,
9709 const elfcpp::Sym
<size
, big_endian
>& lsym
,
9722 (const Relatype
*) NULL
,
9726 lsym
, is_discarded
);
9730 template<int size
, bool big_endian
>
9732 Target_mips
<size
, big_endian
>::Scan::local(
9733 Symbol_table
* symtab
,
9735 Target_mips
<size
, big_endian
>* target
,
9736 Sized_relobj_file
<size
, big_endian
>* object
,
9737 unsigned int data_shndx
,
9738 Output_section
* output_section
,
9739 const Relatype
& reloc
,
9740 unsigned int r_type
,
9741 const elfcpp::Sym
<size
, big_endian
>& lsym
,
9755 (const Reltype
*) NULL
,
9758 lsym
, is_discarded
);
9761 // Scan a relocation for a global symbol.
9763 template<int size
, bool big_endian
>
9765 Target_mips
<size
, big_endian
>::Scan::global(
9766 Symbol_table
* symtab
,
9768 Target_mips
<size
, big_endian
>* target
,
9769 Sized_relobj_file
<size
, big_endian
>* object
,
9770 unsigned int data_shndx
,
9771 Output_section
* output_section
,
9772 const Relatype
* rela
,
9774 unsigned int rel_type
,
9775 unsigned int r_type
,
9778 Mips_address r_offset
;
9780 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
9782 if (rel_type
== elfcpp::SHT_RELA
)
9784 r_offset
= rela
->get_r_offset();
9785 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
9787 r_addend
= rela
->get_r_addend();
9791 r_offset
= rel
->get_r_offset();
9792 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
9797 Mips_relobj
<size
, big_endian
>* mips_obj
=
9798 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
9799 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
9801 if (mips_obj
->is_mips16_stub_section(data_shndx
))
9803 mips_obj
->get_mips16_stub_section(data_shndx
)
9804 ->new_global_reloc_found(r_type
, mips_sym
);
9807 if (r_type
== elfcpp::R_MIPS_NONE
)
9808 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
9812 if (!mips16_call_reloc(r_type
)
9813 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
9814 // This reloc would need to refer to a MIPS16 hard-float stub, if
9815 // there is one. We ignore MIPS16 stub sections and .pdr section when
9816 // looking for relocs that would need to refer to MIPS16 stubs.
9817 mips_sym
->set_need_fn_stub();
9819 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
9820 // section. We check here to avoid creating a dynamic reloc against
9821 // _GLOBAL_OFFSET_TABLE_.
9822 if (!target
->has_got_section()
9823 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9824 target
->got_section(symtab
, layout
);
9826 // We need PLT entries if there are static-only relocations against
9827 // an externally-defined function. This can technically occur for
9828 // shared libraries if there are branches to the symbol, although it
9829 // is unlikely that this will be used in practice due to the short
9830 // ranges involved. It can occur for any relative or absolute relocation
9831 // in executables; in that case, the PLT entry becomes the function's
9832 // canonical address.
9833 bool static_reloc
= false;
9835 // Set CAN_MAKE_DYNAMIC to true if we can convert this
9836 // relocation into a dynamic one.
9837 bool can_make_dynamic
= false;
9840 case elfcpp::R_MIPS_GOT16
:
9841 case elfcpp::R_MIPS_CALL16
:
9842 case elfcpp::R_MIPS_CALL_HI16
:
9843 case elfcpp::R_MIPS_CALL_LO16
:
9844 case elfcpp::R_MIPS_GOT_HI16
:
9845 case elfcpp::R_MIPS_GOT_LO16
:
9846 case elfcpp::R_MIPS_GOT_PAGE
:
9847 case elfcpp::R_MIPS_GOT_OFST
:
9848 case elfcpp::R_MIPS_GOT_DISP
:
9849 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9850 case elfcpp::R_MIPS_TLS_GD
:
9851 case elfcpp::R_MIPS_TLS_LDM
:
9852 case elfcpp::R_MIPS16_GOT16
:
9853 case elfcpp::R_MIPS16_CALL16
:
9854 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9855 case elfcpp::R_MIPS16_TLS_GD
:
9856 case elfcpp::R_MIPS16_TLS_LDM
:
9857 case elfcpp::R_MICROMIPS_GOT16
:
9858 case elfcpp::R_MICROMIPS_CALL16
:
9859 case elfcpp::R_MICROMIPS_CALL_HI16
:
9860 case elfcpp::R_MICROMIPS_CALL_LO16
:
9861 case elfcpp::R_MICROMIPS_GOT_HI16
:
9862 case elfcpp::R_MICROMIPS_GOT_LO16
:
9863 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9864 case elfcpp::R_MICROMIPS_GOT_OFST
:
9865 case elfcpp::R_MICROMIPS_GOT_DISP
:
9866 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9867 case elfcpp::R_MICROMIPS_TLS_GD
:
9868 case elfcpp::R_MICROMIPS_TLS_LDM
:
9869 case elfcpp::R_MIPS_EH
:
9870 // We need a GOT section.
9871 target
->got_section(symtab
, layout
);
9874 // This is just a hint; it can safely be ignored. Don't set
9875 // has_static_relocs for the corresponding symbol.
9876 case elfcpp::R_MIPS_JALR
:
9877 case elfcpp::R_MICROMIPS_JALR
:
9880 case elfcpp::R_MIPS_GPREL16
:
9881 case elfcpp::R_MIPS_GPREL32
:
9882 case elfcpp::R_MIPS16_GPREL
:
9883 case elfcpp::R_MICROMIPS_GPREL16
:
9885 // GP-relative relocations always resolve to a definition in a
9886 // regular input file, ignoring the one-definition rule. This is
9887 // important for the GP setup sequence in NewABI code, which
9888 // always resolves to a local function even if other relocations
9889 // against the symbol wouldn't.
9890 //constrain_symbol_p = FALSE;
9893 case elfcpp::R_MIPS_32
:
9894 case elfcpp::R_MIPS_REL32
:
9895 case elfcpp::R_MIPS_64
:
9896 if ((parameters
->options().shared()
9897 || (strcmp(gsym
->name(), "__gnu_local_gp") != 0
9898 && (!is_readonly_section(output_section
)
9899 || mips_obj
->is_pic())))
9900 && (output_section
->flags() & elfcpp::SHF_ALLOC
) != 0)
9902 if (r_type
!= elfcpp::R_MIPS_REL32
)
9903 mips_sym
->set_pointer_equality_needed();
9904 can_make_dynamic
= true;
9910 // Most static relocations require pointer equality, except
9912 mips_sym
->set_pointer_equality_needed();
9916 case elfcpp::R_MIPS_26
:
9917 case elfcpp::R_MIPS_PC16
:
9918 case elfcpp::R_MIPS16_26
:
9919 case elfcpp::R_MICROMIPS_26_S1
:
9920 case elfcpp::R_MICROMIPS_PC7_S1
:
9921 case elfcpp::R_MICROMIPS_PC10_S1
:
9922 case elfcpp::R_MICROMIPS_PC16_S1
:
9923 case elfcpp::R_MICROMIPS_PC23_S2
:
9924 static_reloc
= true;
9925 mips_sym
->set_has_static_relocs();
9929 // If there are call relocations against an externally-defined symbol,
9930 // see whether we can create a MIPS lazy-binding stub for it. We can
9931 // only do this if all references to the function are through call
9932 // relocations, and in that case, the traditional lazy-binding stubs
9933 // are much more efficient than PLT entries.
9936 case elfcpp::R_MIPS16_CALL16
:
9937 case elfcpp::R_MIPS_CALL16
:
9938 case elfcpp::R_MIPS_CALL_HI16
:
9939 case elfcpp::R_MIPS_CALL_LO16
:
9940 case elfcpp::R_MIPS_JALR
:
9941 case elfcpp::R_MICROMIPS_CALL16
:
9942 case elfcpp::R_MICROMIPS_CALL_HI16
:
9943 case elfcpp::R_MICROMIPS_CALL_LO16
:
9944 case elfcpp::R_MICROMIPS_JALR
:
9945 if (!mips_sym
->no_lazy_stub())
9947 if ((mips_sym
->needs_plt_entry() && mips_sym
->is_from_dynobj())
9948 // Calls from shared objects to undefined symbols of type
9949 // STT_NOTYPE need lazy-binding stub.
9950 || (mips_sym
->is_undefined() && parameters
->options().shared()))
9951 target
->mips_stubs_section(layout
)->make_entry(mips_sym
);
9956 // We must not create a stub for a symbol that has relocations
9957 // related to taking the function's address.
9958 mips_sym
->set_no_lazy_stub();
9959 target
->remove_lazy_stub_entry(mips_sym
);
9964 if (relocation_needs_la25_stub
<size
, big_endian
>(mips_obj
, r_type
,
9965 mips_sym
->is_mips16()))
9966 mips_sym
->set_has_nonpic_branches();
9968 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
9969 // and has a special meaning.
9970 bool gp_disp_against_hi16
= (!mips_obj
->is_newabi()
9971 && strcmp(gsym
->name(), "_gp_disp") == 0
9972 && (hi16_reloc(r_type
) || lo16_reloc(r_type
)));
9973 if (static_reloc
&& gsym
->needs_plt_entry())
9975 target
->make_plt_entry(symtab
, layout
, mips_sym
, r_type
);
9977 // Since this is not a PC-relative relocation, we may be
9978 // taking the address of a function. In that case we need to
9979 // set the entry in the dynamic symbol table to the address of
9981 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
9983 gsym
->set_needs_dynsym_value();
9984 // We distinguish between PLT entries and lazy-binding stubs by
9985 // giving the former an st_other value of STO_MIPS_PLT. Set the
9986 // flag if there are any relocations in the binary where pointer
9987 // equality matters.
9988 if (mips_sym
->pointer_equality_needed())
9989 mips_sym
->set_mips_plt();
9992 if ((static_reloc
|| can_make_dynamic
) && !gp_disp_against_hi16
)
9994 // Absolute addressing relocations.
9995 // Make a dynamic relocation if necessary.
9996 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
9998 if (gsym
->may_need_copy_reloc())
10000 target
->copy_reloc(symtab
, layout
, object
, data_shndx
,
10001 output_section
, gsym
, r_type
, r_offset
);
10003 else if (can_make_dynamic
)
10005 // Create .rel.dyn section.
10006 target
->rel_dyn_section(layout
);
10007 target
->dynamic_reloc(mips_sym
, elfcpp::R_MIPS_REL32
, mips_obj
,
10008 data_shndx
, output_section
, r_offset
);
10011 gold_error(_("non-dynamic relocations refer to dynamic symbol %s"),
10016 bool for_call
= false;
10019 case elfcpp::R_MIPS_CALL16
:
10020 case elfcpp::R_MIPS16_CALL16
:
10021 case elfcpp::R_MICROMIPS_CALL16
:
10022 case elfcpp::R_MIPS_CALL_HI16
:
10023 case elfcpp::R_MIPS_CALL_LO16
:
10024 case elfcpp::R_MICROMIPS_CALL_HI16
:
10025 case elfcpp::R_MICROMIPS_CALL_LO16
:
10029 case elfcpp::R_MIPS16_GOT16
:
10030 case elfcpp::R_MIPS_GOT16
:
10031 case elfcpp::R_MIPS_GOT_HI16
:
10032 case elfcpp::R_MIPS_GOT_LO16
:
10033 case elfcpp::R_MICROMIPS_GOT16
:
10034 case elfcpp::R_MICROMIPS_GOT_HI16
:
10035 case elfcpp::R_MICROMIPS_GOT_LO16
:
10036 case elfcpp::R_MIPS_GOT_DISP
:
10037 case elfcpp::R_MICROMIPS_GOT_DISP
:
10038 case elfcpp::R_MIPS_EH
:
10040 // The symbol requires a GOT entry.
10041 Mips_output_data_got
<size
, big_endian
>* got
=
10042 target
->got_section(symtab
, layout
);
10043 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10045 mips_sym
->set_global_got_area(GGA_NORMAL
);
10049 case elfcpp::R_MIPS_GOT_PAGE
:
10050 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10052 // This relocation needs a page entry in the GOT.
10053 // Get the section contents.
10054 section_size_type view_size
= 0;
10055 const unsigned char* view
=
10056 object
->section_contents(data_shndx
, &view_size
, false);
10059 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
10060 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
10062 Mips_output_data_got
<size
, big_endian
>* got
=
10063 target
->got_section(symtab
, layout
);
10064 got
->record_got_page_entry(mips_obj
, r_sym
, addend
);
10066 // If this is a global, overridable symbol, GOT_PAGE will
10067 // decay to GOT_DISP, so we'll need a GOT entry for it.
10068 bool def_regular
= (mips_sym
->source() == Symbol::FROM_OBJECT
10069 && !mips_sym
->object()->is_dynamic()
10070 && !mips_sym
->is_undefined());
10072 || (parameters
->options().output_is_position_independent()
10073 && !parameters
->options().Bsymbolic()
10074 && !mips_sym
->is_forced_local()))
10076 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10078 mips_sym
->set_global_got_area(GGA_NORMAL
);
10083 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10084 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10085 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10086 case elfcpp::R_MIPS_TLS_LDM
:
10087 case elfcpp::R_MIPS16_TLS_LDM
:
10088 case elfcpp::R_MICROMIPS_TLS_LDM
:
10089 case elfcpp::R_MIPS_TLS_GD
:
10090 case elfcpp::R_MIPS16_TLS_GD
:
10091 case elfcpp::R_MICROMIPS_TLS_GD
:
10093 const bool is_final
= gsym
->final_value_is_known();
10094 const tls::Tls_optimization optimized_type
=
10095 Target_mips
<size
, big_endian
>::optimize_tls_reloc(is_final
, r_type
);
10099 case elfcpp::R_MIPS_TLS_GD
:
10100 case elfcpp::R_MIPS16_TLS_GD
:
10101 case elfcpp::R_MICROMIPS_TLS_GD
:
10102 if (optimized_type
== tls::TLSOPT_NONE
)
10104 // Create a pair of GOT entries for the module index and
10105 // dtv-relative offset.
10106 Mips_output_data_got
<size
, big_endian
>* got
=
10107 target
->got_section(symtab
, layout
);
10108 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10113 // FIXME: TLS optimization not supported yet.
10114 gold_unreachable();
10118 case elfcpp::R_MIPS_TLS_LDM
:
10119 case elfcpp::R_MIPS16_TLS_LDM
:
10120 case elfcpp::R_MICROMIPS_TLS_LDM
:
10121 if (optimized_type
== tls::TLSOPT_NONE
)
10123 // We always record LDM symbols as local with index 0.
10124 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
10130 // FIXME: TLS optimization not supported yet.
10131 gold_unreachable();
10134 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10135 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10136 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10137 layout
->set_has_static_tls();
10138 if (optimized_type
== tls::TLSOPT_NONE
)
10140 // Create a GOT entry for the tp-relative offset.
10141 Mips_output_data_got
<size
, big_endian
>* got
=
10142 target
->got_section(symtab
, layout
);
10143 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10148 // FIXME: TLS optimization not supported yet.
10149 gold_unreachable();
10154 gold_unreachable();
10158 case elfcpp::R_MIPS_COPY
:
10159 case elfcpp::R_MIPS_JUMP_SLOT
:
10160 // These are relocations which should only be seen by the
10161 // dynamic linker, and should never be seen here.
10162 gold_error(_("%s: unexpected reloc %u in object file"),
10163 object
->name().c_str(), r_type
);
10170 // Refuse some position-dependent relocations when creating a
10171 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
10172 // not PIC, but we can create dynamic relocations and the result
10173 // will be fine. Also do not refuse R_MIPS_LO16, which can be
10174 // combined with R_MIPS_GOT16.
10175 if (parameters
->options().shared())
10179 case elfcpp::R_MIPS16_HI16
:
10180 case elfcpp::R_MIPS_HI16
:
10181 case elfcpp::R_MICROMIPS_HI16
:
10182 // Don't refuse a high part relocation if it's against
10183 // no symbol (e.g. part of a compound relocation).
10187 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
10188 // and has a special meaning.
10189 if (!mips_obj
->is_newabi() && strcmp(gsym
->name(), "_gp_disp") == 0)
10194 case elfcpp::R_MIPS16_26
:
10195 case elfcpp::R_MIPS_26
:
10196 case elfcpp::R_MICROMIPS_26_S1
:
10197 gold_error(_("%s: relocation %u against `%s' can not be used when "
10198 "making a shared object; recompile with -fPIC"),
10199 object
->name().c_str(), r_type
, gsym
->name());
10206 template<int size
, bool big_endian
>
10208 Target_mips
<size
, big_endian
>::Scan::global(
10209 Symbol_table
* symtab
,
10211 Target_mips
<size
, big_endian
>* target
,
10212 Sized_relobj_file
<size
, big_endian
>* object
,
10213 unsigned int data_shndx
,
10214 Output_section
* output_section
,
10215 const Relatype
& reloc
,
10216 unsigned int r_type
,
10227 (const Reltype
*) NULL
,
10233 template<int size
, bool big_endian
>
10235 Target_mips
<size
, big_endian
>::Scan::global(
10236 Symbol_table
* symtab
,
10238 Target_mips
<size
, big_endian
>* target
,
10239 Sized_relobj_file
<size
, big_endian
>* object
,
10240 unsigned int data_shndx
,
10241 Output_section
* output_section
,
10242 const Reltype
& reloc
,
10243 unsigned int r_type
,
10253 (const Relatype
*) NULL
,
10260 // Return whether a R_MIPS_32/R_MIPS64 relocation needs to be applied.
10261 // In cases where Scan::local() or Scan::global() has created
10262 // a dynamic relocation, the addend of the relocation is carried
10263 // in the data, and we must not apply the static relocation.
10265 template<int size
, bool big_endian
>
10267 Target_mips
<size
, big_endian
>::Relocate::should_apply_static_reloc(
10268 const Mips_symbol
<size
>* gsym
,
10269 unsigned int r_type
,
10270 Output_section
* output_section
,
10271 Target_mips
* target
)
10273 // If the output section is not allocated, then we didn't call
10274 // scan_relocs, we didn't create a dynamic reloc, and we must apply
10276 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
10283 // For global symbols, we use the same helper routines used in the
10285 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
))
10286 && !gsym
->may_need_copy_reloc())
10288 // We have generated dynamic reloc (R_MIPS_REL32).
10290 bool multi_got
= false;
10291 if (target
->has_got_section())
10292 multi_got
= target
->got_section()->multi_got();
10293 bool has_got_offset
;
10295 has_got_offset
= gsym
->has_got_offset(GOT_TYPE_STANDARD
);
10297 has_got_offset
= gsym
->global_gotoffset() != -1U;
10298 if (!has_got_offset
)
10301 // Apply the relocation only if the symbol is in the local got.
10302 // Do not apply the relocation if the symbol is in the global
10304 return symbol_references_local(gsym
, gsym
->has_dynsym_index());
10307 // We have not generated dynamic reloc.
10312 // Perform a relocation.
10314 template<int size
, bool big_endian
>
10316 Target_mips
<size
, big_endian
>::Relocate::relocate(
10317 const Relocate_info
<size
, big_endian
>* relinfo
,
10318 unsigned int rel_type
,
10319 Target_mips
* target
,
10320 Output_section
* output_section
,
10322 const unsigned char* preloc
,
10323 const Sized_symbol
<size
>* gsym
,
10324 const Symbol_value
<size
>* psymval
,
10325 unsigned char* view
,
10326 Mips_address address
,
10329 Mips_address r_offset
;
10330 unsigned int r_sym
;
10331 unsigned int r_type
;
10332 unsigned int r_type2
;
10333 unsigned int r_type3
;
10334 unsigned char r_ssym
;
10335 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
10337 if (rel_type
== elfcpp::SHT_RELA
)
10339 const Relatype
rela(preloc
);
10340 r_offset
= rela
.get_r_offset();
10341 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10343 r_type
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10345 r_type2
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10346 get_r_type2(&rela
);
10347 r_type3
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10348 get_r_type3(&rela
);
10349 r_ssym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10351 r_addend
= rela
.get_r_addend();
10355 const Reltype
rel(preloc
);
10356 r_offset
= rel
.get_r_offset();
10357 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
10359 r_type
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
10367 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
10368 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
10370 Mips_relobj
<size
, big_endian
>* object
=
10371 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
10373 bool target_is_16_bit_code
= false;
10374 bool target_is_micromips_code
= false;
10375 bool cross_mode_jump
;
10377 Symbol_value
<size
> symval
;
10379 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
10381 bool changed_symbol_value
= false;
10384 target_is_16_bit_code
= object
->local_symbol_is_mips16(r_sym
);
10385 target_is_micromips_code
= object
->local_symbol_is_micromips(r_sym
);
10386 if (target_is_16_bit_code
|| target_is_micromips_code
)
10388 // MIPS16/microMIPS text labels should be treated as odd.
10389 symval
.set_output_value(psymval
->value(object
, 1));
10391 changed_symbol_value
= true;
10396 target_is_16_bit_code
= mips_sym
->is_mips16();
10397 target_is_micromips_code
= mips_sym
->is_micromips();
10399 // If this is a mips16/microMIPS text symbol, add 1 to the value to make
10400 // it odd. This will cause something like .word SYM to come up with
10401 // the right value when it is loaded into the PC.
10403 if ((mips_sym
->is_mips16() || mips_sym
->is_micromips())
10404 && psymval
->value(object
, 0) != 0)
10406 symval
.set_output_value(psymval
->value(object
, 0) | 1);
10408 changed_symbol_value
= true;
10411 // Pick the value to use for symbols defined in shared objects.
10412 if (mips_sym
->use_plt_offset(Scan::get_reference_flags(r_type
))
10413 || mips_sym
->has_lazy_stub())
10415 Mips_address value
;
10416 if (!mips_sym
->has_lazy_stub())
10418 // Prefer a standard MIPS PLT entry.
10419 if (mips_sym
->has_mips_plt_offset())
10421 value
= target
->plt_section()->mips_entry_address(mips_sym
);
10422 target_is_micromips_code
= false;
10423 target_is_16_bit_code
= false;
10427 value
= (target
->plt_section()->comp_entry_address(mips_sym
)
10429 if (target
->is_output_micromips())
10430 target_is_micromips_code
= true;
10432 target_is_16_bit_code
= true;
10436 value
= target
->mips_stubs_section()->stub_address(mips_sym
);
10438 symval
.set_output_value(value
);
10443 // TRUE if the symbol referred to by this relocation is "_gp_disp".
10444 // Note that such a symbol must always be a global symbol.
10445 bool gp_disp
= (gsym
!= NULL
&& (strcmp(gsym
->name(), "_gp_disp") == 0)
10446 && !object
->is_newabi());
10448 // TRUE if the symbol referred to by this relocation is "__gnu_local_gp".
10449 // Note that such a symbol must always be a global symbol.
10450 bool gnu_local_gp
= gsym
&& (strcmp(gsym
->name(), "__gnu_local_gp") == 0);
10455 if (!hi16_reloc(r_type
) && !lo16_reloc(r_type
))
10456 gold_error_at_location(relinfo
, relnum
, r_offset
,
10457 _("relocations against _gp_disp are permitted only"
10458 " with R_MIPS_HI16 and R_MIPS_LO16 relocations."));
10460 else if (gnu_local_gp
)
10462 // __gnu_local_gp is _gp symbol.
10463 symval
.set_output_value(target
->adjusted_gp_value(object
));
10467 // If this is a reference to a 16-bit function with a stub, we need
10468 // to redirect the relocation to the stub unless:
10470 // (a) the relocation is for a MIPS16 JAL;
10472 // (b) the relocation is for a MIPS16 PIC call, and there are no
10473 // non-MIPS16 uses of the GOT slot; or
10475 // (c) the section allows direct references to MIPS16 functions.
10476 if (r_type
!= elfcpp::R_MIPS16_26
10477 && !parameters
->options().relocatable()
10478 && ((mips_sym
!= NULL
10479 && mips_sym
->has_mips16_fn_stub()
10480 && (r_type
!= elfcpp::R_MIPS16_CALL16
|| mips_sym
->need_fn_stub()))
10481 || (mips_sym
== NULL
10482 && object
->get_local_mips16_fn_stub(r_sym
) != NULL
))
10483 && !object
->section_allows_mips16_refs(relinfo
->data_shndx
))
10485 // This is a 32- or 64-bit call to a 16-bit function. We should
10486 // have already noticed that we were going to need the
10488 Mips_address value
;
10489 if (mips_sym
== NULL
)
10490 value
= object
->get_local_mips16_fn_stub(r_sym
)->output_address();
10493 gold_assert(mips_sym
->need_fn_stub());
10494 if (mips_sym
->has_la25_stub())
10495 value
= target
->la25_stub_section()->stub_address(mips_sym
);
10498 value
= mips_sym
->template
10499 get_mips16_fn_stub
<big_endian
>()->output_address();
10502 symval
.set_output_value(value
);
10504 changed_symbol_value
= true;
10506 // The target is 16-bit, but the stub isn't.
10507 target_is_16_bit_code
= false;
10509 // If this is a MIPS16 call with a stub, that is made through the PLT or
10510 // to a standard MIPS function, we need to redirect the call to the stub.
10511 // Note that we specifically exclude R_MIPS16_CALL16 from this behavior;
10512 // indirect calls should use an indirect stub instead.
10513 else if (r_type
== elfcpp::R_MIPS16_26
&& !parameters
->options().relocatable()
10514 && ((mips_sym
!= NULL
10515 && (mips_sym
->has_mips16_call_stub()
10516 || mips_sym
->has_mips16_call_fp_stub()))
10517 || (mips_sym
== NULL
10518 && object
->get_local_mips16_call_stub(r_sym
) != NULL
))
10519 && ((mips_sym
!= NULL
&& mips_sym
->has_plt_offset())
10520 || !target_is_16_bit_code
))
10522 Mips16_stub_section
<size
, big_endian
>* call_stub
;
10523 if (mips_sym
== NULL
)
10524 call_stub
= object
->get_local_mips16_call_stub(r_sym
);
10527 // If both call_stub and call_fp_stub are defined, we can figure
10528 // out which one to use by checking which one appears in the input
10530 if (mips_sym
->has_mips16_call_stub()
10531 && mips_sym
->has_mips16_call_fp_stub())
10534 for (unsigned int i
= 1; i
< object
->shnum(); ++i
)
10536 if (object
->is_mips16_call_fp_stub_section(i
))
10538 call_stub
= mips_sym
->template
10539 get_mips16_call_fp_stub
<big_endian
>();
10544 if (call_stub
== NULL
)
10546 mips_sym
->template get_mips16_call_stub
<big_endian
>();
10548 else if (mips_sym
->has_mips16_call_stub())
10549 call_stub
= mips_sym
->template get_mips16_call_stub
<big_endian
>();
10551 call_stub
= mips_sym
->template get_mips16_call_fp_stub
<big_endian
>();
10554 symval
.set_output_value(call_stub
->output_address());
10556 changed_symbol_value
= true;
10558 // If this is a direct call to a PIC function, redirect to the
10560 else if (mips_sym
!= NULL
10561 && mips_sym
->has_la25_stub()
10562 && relocation_needs_la25_stub
<size
, big_endian
>(
10563 object
, r_type
, target_is_16_bit_code
))
10565 Mips_address value
= target
->la25_stub_section()->stub_address(mips_sym
);
10566 if (mips_sym
->is_micromips())
10568 symval
.set_output_value(value
);
10571 // For direct MIPS16 and microMIPS calls make sure the compressed PLT
10572 // entry is used if a standard PLT entry has also been made.
10573 else if ((r_type
== elfcpp::R_MIPS16_26
10574 || r_type
== elfcpp::R_MICROMIPS_26_S1
)
10575 && !parameters
->options().relocatable()
10576 && mips_sym
!= NULL
10577 && mips_sym
->has_plt_offset()
10578 && mips_sym
->has_comp_plt_offset()
10579 && mips_sym
->has_mips_plt_offset())
10581 Mips_address value
= (target
->plt_section()->comp_entry_address(mips_sym
)
10583 symval
.set_output_value(value
);
10586 target_is_16_bit_code
= !target
->is_output_micromips();
10587 target_is_micromips_code
= target
->is_output_micromips();
10590 // Make sure MIPS16 and microMIPS are not used together.
10591 if ((r_type
== elfcpp::R_MIPS16_26
&& target_is_micromips_code
)
10592 || (micromips_branch_reloc(r_type
) && target_is_16_bit_code
))
10594 gold_error(_("MIPS16 and microMIPS functions cannot call each other"));
10597 // Calls from 16-bit code to 32-bit code and vice versa require the
10598 // mode change. However, we can ignore calls to undefined weak symbols,
10599 // which should never be executed at runtime. This exception is important
10600 // because the assembly writer may have "known" that any definition of the
10601 // symbol would be 16-bit code, and that direct jumps were therefore
10604 (!parameters
->options().relocatable()
10605 && !(gsym
!= NULL
&& gsym
->is_weak_undefined())
10606 && ((r_type
== elfcpp::R_MIPS16_26
&& !target_is_16_bit_code
)
10607 || (r_type
== elfcpp::R_MICROMIPS_26_S1
&& !target_is_micromips_code
)
10608 || ((r_type
== elfcpp::R_MIPS_26
|| r_type
== elfcpp::R_MIPS_JALR
)
10609 && (target_is_16_bit_code
|| target_is_micromips_code
))));
10611 bool local
= (mips_sym
== NULL
10612 || (mips_sym
->got_only_for_calls()
10613 ? symbol_calls_local(mips_sym
, mips_sym
->has_dynsym_index())
10614 : symbol_references_local(mips_sym
,
10615 mips_sym
->has_dynsym_index())));
10617 // Global R_MIPS_GOT_PAGE/R_MICROMIPS_GOT_PAGE relocations are equivalent
10618 // to R_MIPS_GOT_DISP/R_MICROMIPS_GOT_DISP. The addend is applied by the
10619 // corresponding R_MIPS_GOT_OFST/R_MICROMIPS_GOT_OFST.
10620 if (got_page_reloc(r_type
) && !local
)
10621 r_type
= (micromips_reloc(r_type
) ? elfcpp::R_MICROMIPS_GOT_DISP
10622 : elfcpp::R_MIPS_GOT_DISP
);
10624 unsigned int got_offset
= 0;
10627 bool calculate_only
= false;
10628 Valtype calculated_value
= 0;
10629 bool extract_addend
= rel_type
== elfcpp::SHT_REL
;
10630 unsigned int r_types
[3] = { r_type
, r_type2
, r_type3
};
10632 Reloc_funcs::mips_reloc_unshuffle(view
, r_type
, false);
10634 // For Mips64 N64 ABI, there may be up to three operations specified per
10635 // record, by the fields r_type, r_type2, and r_type3. The first operation
10636 // takes its addend from the relocation record. Each subsequent operation
10637 // takes as its addend the result of the previous operation.
10638 // The first operation in a record which references a symbol uses the symbol
10639 // implied by r_sym. The next operation in a record which references a symbol
10640 // uses the special symbol value given by the r_ssym field. A third operation
10641 // in a record which references a symbol will assume a NULL symbol,
10642 // i.e. value zero.
10645 // Check if a record references to a symbol.
10646 for (unsigned int i
= 0; i
< 3; ++i
)
10648 if (r_types
[i
] == elfcpp::R_MIPS_NONE
)
10652 // Check if the next relocation is for the same instruction.
10653 calculate_only
= i
== 2 ? false
10654 : r_types
[i
+1] != elfcpp::R_MIPS_NONE
;
10656 if (object
->is_n64())
10660 // Handle special symbol for r_type2 relocation type.
10664 symval
.set_output_value(0);
10667 symval
.set_output_value(target
->gp_value());
10670 symval
.set_output_value(object
->gp_value());
10673 symval
.set_output_value(address
);
10676 gold_unreachable();
10682 // For r_type3 symbol value is 0.
10683 symval
.set_output_value(0);
10687 bool update_got_entry
= false;
10688 switch (r_types
[i
])
10690 case elfcpp::R_MIPS_NONE
:
10692 case elfcpp::R_MIPS_16
:
10693 reloc_status
= Reloc_funcs::rel16(view
, object
, psymval
, r_addend
,
10694 extract_addend
, calculate_only
,
10695 &calculated_value
);
10698 case elfcpp::R_MIPS_32
:
10699 if (should_apply_static_reloc(mips_sym
, r_types
[i
], output_section
,
10701 reloc_status
= Reloc_funcs::rel32(view
, object
, psymval
, r_addend
,
10702 extract_addend
, calculate_only
,
10703 &calculated_value
);
10704 if (mips_sym
!= NULL
10705 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
10706 && mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
10708 // If mips_sym->has_mips16_fn_stub() is false, symbol value is
10709 // already updated by adding +1.
10710 if (mips_sym
->has_mips16_fn_stub())
10712 gold_assert(mips_sym
->need_fn_stub());
10713 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
10714 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
10716 symval
.set_output_value(fn_stub
->output_address());
10719 got_offset
= mips_sym
->global_gotoffset();
10720 update_got_entry
= true;
10724 case elfcpp::R_MIPS_64
:
10725 if (should_apply_static_reloc(mips_sym
, r_types
[i
], output_section
,
10727 reloc_status
= Reloc_funcs::rel64(view
, object
, psymval
, r_addend
,
10728 extract_addend
, calculate_only
,
10729 &calculated_value
, false);
10730 else if (target
->is_output_n64() && r_addend
!= 0)
10731 // Only apply the addend. The static relocation was RELA, but the
10732 // dynamic relocation is REL, so we need to apply the addend.
10733 reloc_status
= Reloc_funcs::rel64(view
, object
, psymval
, r_addend
,
10734 extract_addend
, calculate_only
,
10735 &calculated_value
, true);
10737 case elfcpp::R_MIPS_REL32
:
10738 gold_unreachable();
10740 case elfcpp::R_MIPS_PC32
:
10741 reloc_status
= Reloc_funcs::relpc32(view
, object
, psymval
, address
,
10742 r_addend
, extract_addend
,
10744 &calculated_value
);
10747 case elfcpp::R_MIPS16_26
:
10748 // The calculation for R_MIPS16_26 is just the same as for an
10749 // R_MIPS_26. It's only the storage of the relocated field into
10750 // the output file that's different. So, we just fall through to the
10751 // R_MIPS_26 case here.
10752 case elfcpp::R_MIPS_26
:
10753 case elfcpp::R_MICROMIPS_26_S1
:
10754 reloc_status
= Reloc_funcs::rel26(view
, object
, psymval
, address
,
10755 gsym
== NULL
, r_addend
, extract_addend
, gsym
, cross_mode_jump
,
10756 r_types
[i
], target
->jal_to_bal(), calculate_only
,
10757 &calculated_value
);
10760 case elfcpp::R_MIPS_HI16
:
10761 case elfcpp::R_MIPS16_HI16
:
10762 case elfcpp::R_MICROMIPS_HI16
:
10763 if (rel_type
== elfcpp::SHT_RELA
)
10764 reloc_status
= Reloc_funcs::do_relhi16(view
, object
, psymval
,
10766 gp_disp
, r_types
[i
],
10768 target
, calculate_only
,
10769 &calculated_value
);
10770 else if (rel_type
== elfcpp::SHT_REL
)
10771 reloc_status
= Reloc_funcs::relhi16(view
, object
, psymval
, r_addend
,
10772 address
, gp_disp
, r_types
[i
],
10773 r_sym
, extract_addend
);
10775 gold_unreachable();
10778 case elfcpp::R_MIPS_LO16
:
10779 case elfcpp::R_MIPS16_LO16
:
10780 case elfcpp::R_MICROMIPS_LO16
:
10781 case elfcpp::R_MICROMIPS_HI0_LO16
:
10782 reloc_status
= Reloc_funcs::rello16(target
, view
, object
, psymval
,
10783 r_addend
, extract_addend
, address
,
10784 gp_disp
, r_types
[i
], r_sym
,
10785 rel_type
, calculate_only
,
10786 &calculated_value
);
10789 case elfcpp::R_MIPS_LITERAL
:
10790 case elfcpp::R_MICROMIPS_LITERAL
:
10791 // Because we don't merge literal sections, we can handle this
10792 // just like R_MIPS_GPREL16. In the long run, we should merge
10793 // shared literals, and then we will need to additional work
10798 case elfcpp::R_MIPS_GPREL16
:
10799 case elfcpp::R_MIPS16_GPREL
:
10800 case elfcpp::R_MICROMIPS_GPREL7_S2
:
10801 case elfcpp::R_MICROMIPS_GPREL16
:
10802 reloc_status
= Reloc_funcs::relgprel(view
, object
, psymval
,
10803 target
->adjusted_gp_value(object
),
10804 r_addend
, extract_addend
,
10805 gsym
== NULL
, r_types
[i
],
10806 calculate_only
, &calculated_value
);
10809 case elfcpp::R_MIPS_PC16
:
10810 reloc_status
= Reloc_funcs::relpc16(view
, object
, psymval
, address
,
10811 r_addend
, extract_addend
,
10813 &calculated_value
);
10815 case elfcpp::R_MICROMIPS_PC7_S1
:
10816 reloc_status
= Reloc_funcs::relmicromips_pc7_s1(view
, object
, psymval
,
10820 &calculated_value
);
10822 case elfcpp::R_MICROMIPS_PC10_S1
:
10823 reloc_status
= Reloc_funcs::relmicromips_pc10_s1(view
, object
,
10825 r_addend
, extract_addend
,
10827 &calculated_value
);
10829 case elfcpp::R_MICROMIPS_PC16_S1
:
10830 reloc_status
= Reloc_funcs::relmicromips_pc16_s1(view
, object
,
10832 r_addend
, extract_addend
,
10834 &calculated_value
);
10836 case elfcpp::R_MIPS_GPREL32
:
10837 reloc_status
= Reloc_funcs::relgprel32(view
, object
, psymval
,
10838 target
->adjusted_gp_value(object
),
10839 r_addend
, extract_addend
,
10841 &calculated_value
);
10843 case elfcpp::R_MIPS_GOT_HI16
:
10844 case elfcpp::R_MIPS_CALL_HI16
:
10845 case elfcpp::R_MICROMIPS_GOT_HI16
:
10846 case elfcpp::R_MICROMIPS_CALL_HI16
:
10848 got_offset
= target
->got_section()->got_offset(gsym
,
10852 got_offset
= target
->got_section()->got_offset(r_sym
,
10855 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10856 reloc_status
= Reloc_funcs::relgot_hi16(view
, gp_offset
,
10858 &calculated_value
);
10859 update_got_entry
= changed_symbol_value
;
10862 case elfcpp::R_MIPS_GOT_LO16
:
10863 case elfcpp::R_MIPS_CALL_LO16
:
10864 case elfcpp::R_MICROMIPS_GOT_LO16
:
10865 case elfcpp::R_MICROMIPS_CALL_LO16
:
10867 got_offset
= target
->got_section()->got_offset(gsym
,
10871 got_offset
= target
->got_section()->got_offset(r_sym
,
10874 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10875 reloc_status
= Reloc_funcs::relgot_lo16(view
, gp_offset
,
10877 &calculated_value
);
10878 update_got_entry
= changed_symbol_value
;
10881 case elfcpp::R_MIPS_GOT_DISP
:
10882 case elfcpp::R_MICROMIPS_GOT_DISP
:
10883 case elfcpp::R_MIPS_EH
:
10885 got_offset
= target
->got_section()->got_offset(gsym
,
10889 got_offset
= target
->got_section()->got_offset(r_sym
,
10892 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10893 if (eh_reloc(r_types
[i
]))
10894 reloc_status
= Reloc_funcs::releh(view
, gp_offset
,
10896 &calculated_value
);
10898 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
10900 &calculated_value
);
10902 case elfcpp::R_MIPS_CALL16
:
10903 case elfcpp::R_MIPS16_CALL16
:
10904 case elfcpp::R_MICROMIPS_CALL16
:
10905 gold_assert(gsym
!= NULL
);
10906 got_offset
= target
->got_section()->got_offset(gsym
,
10909 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10910 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
10911 calculate_only
, &calculated_value
);
10912 // TODO(sasa): We should also initialize update_got_entry
10913 // in other place swhere relgot is called.
10914 update_got_entry
= changed_symbol_value
;
10917 case elfcpp::R_MIPS_GOT16
:
10918 case elfcpp::R_MIPS16_GOT16
:
10919 case elfcpp::R_MICROMIPS_GOT16
:
10922 got_offset
= target
->got_section()->got_offset(gsym
,
10925 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10926 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
10928 &calculated_value
);
10932 if (rel_type
== elfcpp::SHT_RELA
)
10933 reloc_status
= Reloc_funcs::do_relgot16_local(view
, object
,
10938 &calculated_value
);
10939 else if (rel_type
== elfcpp::SHT_REL
)
10940 reloc_status
= Reloc_funcs::relgot16_local(view
, object
,
10943 r_types
[i
], r_sym
);
10945 gold_unreachable();
10947 update_got_entry
= changed_symbol_value
;
10950 case elfcpp::R_MIPS_TLS_GD
:
10951 case elfcpp::R_MIPS16_TLS_GD
:
10952 case elfcpp::R_MICROMIPS_TLS_GD
:
10954 got_offset
= target
->got_section()->got_offset(gsym
,
10958 got_offset
= target
->got_section()->got_offset(r_sym
,
10961 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10962 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
10963 &calculated_value
);
10966 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10967 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10968 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10970 got_offset
= target
->got_section()->got_offset(gsym
,
10971 GOT_TYPE_TLS_OFFSET
,
10974 got_offset
= target
->got_section()->got_offset(r_sym
,
10975 GOT_TYPE_TLS_OFFSET
,
10977 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10978 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
10979 &calculated_value
);
10982 case elfcpp::R_MIPS_TLS_LDM
:
10983 case elfcpp::R_MIPS16_TLS_LDM
:
10984 case elfcpp::R_MICROMIPS_TLS_LDM
:
10985 // Relocate the field with the offset of the GOT entry for
10986 // the module index.
10987 got_offset
= target
->got_section()->tls_ldm_offset(object
);
10988 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10989 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
10990 &calculated_value
);
10993 case elfcpp::R_MIPS_GOT_PAGE
:
10994 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10995 reloc_status
= Reloc_funcs::relgotpage(target
, view
, object
, psymval
,
10996 r_addend
, extract_addend
,
10998 &calculated_value
);
11001 case elfcpp::R_MIPS_GOT_OFST
:
11002 case elfcpp::R_MICROMIPS_GOT_OFST
:
11003 reloc_status
= Reloc_funcs::relgotofst(target
, view
, object
, psymval
,
11004 r_addend
, extract_addend
,
11005 local
, calculate_only
,
11006 &calculated_value
);
11009 case elfcpp::R_MIPS_JALR
:
11010 case elfcpp::R_MICROMIPS_JALR
:
11011 // This relocation is only a hint. In some cases, we optimize
11012 // it into a bal instruction. But we don't try to optimize
11013 // when the symbol does not resolve locally.
11015 || symbol_calls_local(gsym
, gsym
->has_dynsym_index()))
11016 reloc_status
= Reloc_funcs::reljalr(view
, object
, psymval
, address
,
11017 r_addend
, extract_addend
,
11018 cross_mode_jump
, r_types
[i
],
11019 target
->jalr_to_bal(),
11022 &calculated_value
);
11025 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
11026 case elfcpp::R_MIPS16_TLS_DTPREL_HI16
:
11027 case elfcpp::R_MICROMIPS_TLS_DTPREL_HI16
:
11028 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
11029 elfcpp::DTP_OFFSET
, r_addend
,
11030 extract_addend
, calculate_only
,
11031 &calculated_value
);
11033 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
11034 case elfcpp::R_MIPS16_TLS_DTPREL_LO16
:
11035 case elfcpp::R_MICROMIPS_TLS_DTPREL_LO16
:
11036 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
11037 elfcpp::DTP_OFFSET
, r_addend
,
11038 extract_addend
, calculate_only
,
11039 &calculated_value
);
11041 case elfcpp::R_MIPS_TLS_DTPREL32
:
11042 case elfcpp::R_MIPS_TLS_DTPREL64
:
11043 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
11044 elfcpp::DTP_OFFSET
, r_addend
,
11045 extract_addend
, calculate_only
,
11046 &calculated_value
);
11048 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
11049 case elfcpp::R_MIPS16_TLS_TPREL_HI16
:
11050 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
11051 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
11052 elfcpp::TP_OFFSET
, r_addend
,
11053 extract_addend
, calculate_only
,
11054 &calculated_value
);
11056 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
11057 case elfcpp::R_MIPS16_TLS_TPREL_LO16
:
11058 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
11059 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
11060 elfcpp::TP_OFFSET
, r_addend
,
11061 extract_addend
, calculate_only
,
11062 &calculated_value
);
11064 case elfcpp::R_MIPS_TLS_TPREL32
:
11065 case elfcpp::R_MIPS_TLS_TPREL64
:
11066 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
11067 elfcpp::TP_OFFSET
, r_addend
,
11068 extract_addend
, calculate_only
,
11069 &calculated_value
);
11071 case elfcpp::R_MIPS_SUB
:
11072 case elfcpp::R_MICROMIPS_SUB
:
11073 reloc_status
= Reloc_funcs::relsub(view
, object
, psymval
, r_addend
,
11075 calculate_only
, &calculated_value
);
11078 gold_error_at_location(relinfo
, relnum
, r_offset
,
11079 _("unsupported reloc %u"), r_types
[i
]);
11083 if (update_got_entry
)
11085 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
11086 if (mips_sym
!= NULL
&& mips_sym
->get_applied_secondary_got_fixup())
11087 got
->update_got_entry(got
->get_primary_got_offset(mips_sym
),
11088 psymval
->value(object
, 0));
11090 got
->update_got_entry(got_offset
, psymval
->value(object
, 0));
11093 r_addend
= calculated_value
;
11096 bool jal_shuffle
= jal_reloc(r_type
) ? !parameters
->options().relocatable()
11098 Reloc_funcs::mips_reloc_shuffle(view
, r_type
, jal_shuffle
);
11100 // Report any errors.
11101 switch (reloc_status
)
11103 case Reloc_funcs::STATUS_OKAY
:
11105 case Reloc_funcs::STATUS_OVERFLOW
:
11106 gold_error_at_location(relinfo
, relnum
, r_offset
,
11107 _("relocation overflow"));
11109 case Reloc_funcs::STATUS_BAD_RELOC
:
11110 gold_error_at_location(relinfo
, relnum
, r_offset
,
11111 _("unexpected opcode while processing relocation"));
11114 gold_unreachable();
11120 // Get the Reference_flags for a particular relocation.
11122 template<int size
, bool big_endian
>
11124 Target_mips
<size
, big_endian
>::Scan::get_reference_flags(
11125 unsigned int r_type
)
11129 case elfcpp::R_MIPS_NONE
:
11130 // No symbol reference.
11133 case elfcpp::R_MIPS_16
:
11134 case elfcpp::R_MIPS_32
:
11135 case elfcpp::R_MIPS_64
:
11136 case elfcpp::R_MIPS_HI16
:
11137 case elfcpp::R_MIPS_LO16
:
11138 case elfcpp::R_MIPS16_HI16
:
11139 case elfcpp::R_MIPS16_LO16
:
11140 case elfcpp::R_MICROMIPS_HI16
:
11141 case elfcpp::R_MICROMIPS_LO16
:
11142 return Symbol::ABSOLUTE_REF
;
11144 case elfcpp::R_MIPS_26
:
11145 case elfcpp::R_MIPS16_26
:
11146 case elfcpp::R_MICROMIPS_26_S1
:
11147 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
11149 case elfcpp::R_MIPS_GPREL32
:
11150 case elfcpp::R_MIPS_GPREL16
:
11151 case elfcpp::R_MIPS_REL32
:
11152 case elfcpp::R_MIPS16_GPREL
:
11153 return Symbol::RELATIVE_REF
;
11155 case elfcpp::R_MIPS_PC16
:
11156 case elfcpp::R_MIPS_PC32
:
11157 case elfcpp::R_MIPS_JALR
:
11158 case elfcpp::R_MICROMIPS_JALR
:
11159 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
11161 case elfcpp::R_MIPS_GOT16
:
11162 case elfcpp::R_MIPS_CALL16
:
11163 case elfcpp::R_MIPS_GOT_DISP
:
11164 case elfcpp::R_MIPS_GOT_HI16
:
11165 case elfcpp::R_MIPS_GOT_LO16
:
11166 case elfcpp::R_MIPS_CALL_HI16
:
11167 case elfcpp::R_MIPS_CALL_LO16
:
11168 case elfcpp::R_MIPS_LITERAL
:
11169 case elfcpp::R_MIPS_GOT_PAGE
:
11170 case elfcpp::R_MIPS_GOT_OFST
:
11171 case elfcpp::R_MIPS16_GOT16
:
11172 case elfcpp::R_MIPS16_CALL16
:
11173 case elfcpp::R_MICROMIPS_GOT16
:
11174 case elfcpp::R_MICROMIPS_CALL16
:
11175 case elfcpp::R_MICROMIPS_GOT_HI16
:
11176 case elfcpp::R_MICROMIPS_GOT_LO16
:
11177 case elfcpp::R_MICROMIPS_CALL_HI16
:
11178 case elfcpp::R_MICROMIPS_CALL_LO16
:
11179 case elfcpp::R_MIPS_EH
:
11180 // Absolute in GOT.
11181 return Symbol::RELATIVE_REF
;
11183 case elfcpp::R_MIPS_TLS_DTPMOD32
:
11184 case elfcpp::R_MIPS_TLS_DTPREL32
:
11185 case elfcpp::R_MIPS_TLS_DTPMOD64
:
11186 case elfcpp::R_MIPS_TLS_DTPREL64
:
11187 case elfcpp::R_MIPS_TLS_GD
:
11188 case elfcpp::R_MIPS_TLS_LDM
:
11189 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
11190 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
11191 case elfcpp::R_MIPS_TLS_GOTTPREL
:
11192 case elfcpp::R_MIPS_TLS_TPREL32
:
11193 case elfcpp::R_MIPS_TLS_TPREL64
:
11194 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
11195 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
11196 case elfcpp::R_MIPS16_TLS_GD
:
11197 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
11198 case elfcpp::R_MICROMIPS_TLS_GD
:
11199 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
11200 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
11201 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
11202 return Symbol::TLS_REF
;
11204 case elfcpp::R_MIPS_COPY
:
11205 case elfcpp::R_MIPS_JUMP_SLOT
:
11207 gold_unreachable();
11208 // Not expected. We will give an error later.
11213 // Report an unsupported relocation against a local symbol.
11215 template<int size
, bool big_endian
>
11217 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_local(
11218 Sized_relobj_file
<size
, big_endian
>* object
,
11219 unsigned int r_type
)
11221 gold_error(_("%s: unsupported reloc %u against local symbol"),
11222 object
->name().c_str(), r_type
);
11225 // Report an unsupported relocation against a global symbol.
11227 template<int size
, bool big_endian
>
11229 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_global(
11230 Sized_relobj_file
<size
, big_endian
>* object
,
11231 unsigned int r_type
,
11234 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
11235 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
11238 // Return printable name for ABI.
11239 template<int size
, bool big_endian
>
11241 Target_mips
<size
, big_endian
>::elf_mips_abi_name(elfcpp::Elf_Word e_flags
)
11243 switch (e_flags
& elfcpp::EF_MIPS_ABI
)
11246 if ((e_flags
& elfcpp::EF_MIPS_ABI2
) != 0)
11248 else if (size
== 64)
11252 case elfcpp::E_MIPS_ABI_O32
:
11254 case elfcpp::E_MIPS_ABI_O64
:
11256 case elfcpp::E_MIPS_ABI_EABI32
:
11258 case elfcpp::E_MIPS_ABI_EABI64
:
11261 return "unknown abi";
11265 template<int size
, bool big_endian
>
11267 Target_mips
<size
, big_endian
>::elf_mips_mach_name(elfcpp::Elf_Word e_flags
)
11269 switch (e_flags
& elfcpp::EF_MIPS_MACH
)
11271 case elfcpp::E_MIPS_MACH_3900
:
11272 return "mips:3900";
11273 case elfcpp::E_MIPS_MACH_4010
:
11274 return "mips:4010";
11275 case elfcpp::E_MIPS_MACH_4100
:
11276 return "mips:4100";
11277 case elfcpp::E_MIPS_MACH_4111
:
11278 return "mips:4111";
11279 case elfcpp::E_MIPS_MACH_4120
:
11280 return "mips:4120";
11281 case elfcpp::E_MIPS_MACH_4650
:
11282 return "mips:4650";
11283 case elfcpp::E_MIPS_MACH_5400
:
11284 return "mips:5400";
11285 case elfcpp::E_MIPS_MACH_5500
:
11286 return "mips:5500";
11287 case elfcpp::E_MIPS_MACH_SB1
:
11289 case elfcpp::E_MIPS_MACH_9000
:
11290 return "mips:9000";
11291 case elfcpp::E_MIPS_MACH_LS2E
:
11292 return "mips:loongson-2e";
11293 case elfcpp::E_MIPS_MACH_LS2F
:
11294 return "mips:loongson-2f";
11295 case elfcpp::E_MIPS_MACH_LS3A
:
11296 return "mips:loongson-3a";
11297 case elfcpp::E_MIPS_MACH_OCTEON
:
11298 return "mips:octeon";
11299 case elfcpp::E_MIPS_MACH_OCTEON2
:
11300 return "mips:octeon2";
11301 case elfcpp::E_MIPS_MACH_XLR
:
11304 switch (e_flags
& elfcpp::EF_MIPS_ARCH
)
11307 case elfcpp::E_MIPS_ARCH_1
:
11308 return "mips:3000";
11310 case elfcpp::E_MIPS_ARCH_2
:
11311 return "mips:6000";
11313 case elfcpp::E_MIPS_ARCH_3
:
11314 return "mips:4000";
11316 case elfcpp::E_MIPS_ARCH_4
:
11317 return "mips:8000";
11319 case elfcpp::E_MIPS_ARCH_5
:
11320 return "mips:mips5";
11322 case elfcpp::E_MIPS_ARCH_32
:
11323 return "mips:isa32";
11325 case elfcpp::E_MIPS_ARCH_64
:
11326 return "mips:isa64";
11328 case elfcpp::E_MIPS_ARCH_32R2
:
11329 return "mips:isa32r2";
11331 case elfcpp::E_MIPS_ARCH_64R2
:
11332 return "mips:isa64r2";
11335 return "unknown CPU";
11338 template<int size
, bool big_endian
>
11339 const Target::Target_info Target_mips
<size
, big_endian
>::mips_info
=
11342 big_endian
, // is_big_endian
11343 elfcpp::EM_MIPS
, // machine_code
11344 true, // has_make_symbol
11345 false, // has_resolve
11346 false, // has_code_fill
11347 true, // is_default_stack_executable
11348 false, // can_icf_inline_merge_sections
11350 size
== 32 ? "/lib/ld.so.1" : "/lib64/ld.so.1", // dynamic_linker
11351 0x400000, // default_text_segment_address
11352 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
11353 4 * 1024, // common_pagesize (overridable by -z common-page-size)
11354 false, // isolate_execinstr
11355 0, // rosegment_gap
11356 elfcpp::SHN_UNDEF
, // small_common_shndx
11357 elfcpp::SHN_UNDEF
, // large_common_shndx
11358 0, // small_common_section_flags
11359 0, // large_common_section_flags
11360 NULL
, // attributes_section
11361 NULL
, // attributes_vendor
11362 "__start", // entry_symbol_name
11363 32, // hash_entry_size
11366 template<int size
, bool big_endian
>
11367 class Target_mips_nacl
: public Target_mips
<size
, big_endian
>
11371 : Target_mips
<size
, big_endian
>(&mips_nacl_info
)
11375 static const Target::Target_info mips_nacl_info
;
11378 template<int size
, bool big_endian
>
11379 const Target::Target_info Target_mips_nacl
<size
, big_endian
>::mips_nacl_info
=
11382 big_endian
, // is_big_endian
11383 elfcpp::EM_MIPS
, // machine_code
11384 true, // has_make_symbol
11385 false, // has_resolve
11386 false, // has_code_fill
11387 true, // is_default_stack_executable
11388 false, // can_icf_inline_merge_sections
11390 "/lib/ld.so.1", // dynamic_linker
11391 0x20000, // default_text_segment_address
11392 0x10000, // abi_pagesize (overridable by -z max-page-size)
11393 0x10000, // common_pagesize (overridable by -z common-page-size)
11394 true, // isolate_execinstr
11395 0x10000000, // rosegment_gap
11396 elfcpp::SHN_UNDEF
, // small_common_shndx
11397 elfcpp::SHN_UNDEF
, // large_common_shndx
11398 0, // small_common_section_flags
11399 0, // large_common_section_flags
11400 NULL
, // attributes_section
11401 NULL
, // attributes_vendor
11402 "_start", // entry_symbol_name
11403 32, // hash_entry_size
11406 // Target selector for Mips. Note this is never instantiated directly.
11407 // It's only used in Target_selector_mips_nacl, below.
11409 template<int size
, bool big_endian
>
11410 class Target_selector_mips
: public Target_selector
11413 Target_selector_mips()
11414 : Target_selector(elfcpp::EM_MIPS
, size
, big_endian
,
11416 (big_endian
? "elf64-tradbigmips" : "elf64-tradlittlemips") :
11417 (big_endian
? "elf32-tradbigmips" : "elf32-tradlittlemips")),
11419 (big_endian
? "elf64btsmip" : "elf64ltsmip") :
11420 (big_endian
? "elf32btsmip" : "elf32ltsmip")))
11423 Target
* do_instantiate_target()
11424 { return new Target_mips
<size
, big_endian
>(); }
11427 template<int size
, bool big_endian
>
11428 class Target_selector_mips_nacl
11429 : public Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
11430 Target_mips_nacl
<size
, big_endian
> >
11433 Target_selector_mips_nacl()
11434 : Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
11435 Target_mips_nacl
<size
, big_endian
> >(
11436 // NaCl currently supports only MIPS32 little-endian.
11437 "mipsel", "elf32-tradlittlemips-nacl", "elf32-tradlittlemips-nacl")
11441 Target_selector_mips_nacl
<32, true> target_selector_mips32
;
11442 Target_selector_mips_nacl
<32, false> target_selector_mips32el
;
11443 Target_selector_mips_nacl
<64, true> target_selector_mips64
;
11444 Target_selector_mips_nacl
<64, false> target_selector_mips64el
;
11446 } // End anonymous namespace.