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 // Call parent to write out GOT.
6134 Output_data_got
<size
, big_endian
>::do_write(of
);
6136 const off_t offset
= this->offset();
6137 const section_size_type oview_size
=
6138 convert_to_section_size_type(this->data_size());
6139 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6141 // Needed for fixing values of .got section.
6142 this->got_view_
= oview
;
6144 // Write lazy stub addresses.
6145 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
6146 p
= this->master_got_info_
->global_got_symbols().begin();
6147 p
!= this->master_got_info_
->global_got_symbols().end();
6150 Mips_symbol
<size
>* mips_sym
= *p
;
6151 if (mips_sym
->has_lazy_stub())
6153 Valtype
* wv
= reinterpret_cast<Valtype
*>(
6154 oview
+ this->get_primary_got_offset(mips_sym
));
6156 this->target_
->mips_stubs_section()->stub_address(mips_sym
);
6157 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
6161 // Add +1 to GGA_NONE nonzero MIPS16 and microMIPS entries.
6162 for (typename Unordered_set
<Mips_symbol
<size
>*>::iterator
6163 p
= this->master_got_info_
->global_got_symbols().begin();
6164 p
!= this->master_got_info_
->global_got_symbols().end();
6167 Mips_symbol
<size
>* mips_sym
= *p
;
6168 if (!this->multi_got()
6169 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
6170 && mips_sym
->global_got_area() == GGA_NONE
6171 && mips_sym
->has_got_offset(GOT_TYPE_STANDARD
))
6173 Valtype
* wv
= reinterpret_cast<Valtype
*>(
6174 oview
+ mips_sym
->got_offset(GOT_TYPE_STANDARD
));
6175 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv
);
6179 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, value
);
6184 if (!this->secondary_got_relocs_
.empty())
6186 // Fixup for the secondary GOT R_MIPS_REL32 relocs. For global
6187 // secondary GOT entries with non-zero initial value copy the value
6188 // to the corresponding primary GOT entry, and set the secondary GOT
6190 // TODO(sasa): This is workaround. It needs to be investigated further.
6192 for (size_t i
= 0; i
< this->secondary_got_relocs_
.size(); ++i
)
6194 Static_reloc
& reloc(this->secondary_got_relocs_
[i
]);
6195 if (reloc
.symbol_is_global())
6197 Mips_symbol
<size
>* gsym
= reloc
.symbol();
6198 gold_assert(gsym
!= NULL
);
6200 unsigned got_offset
= reloc
.got_offset();
6201 gold_assert(got_offset
< oview_size
);
6203 // Find primary GOT entry.
6204 Valtype
* wv_prim
= reinterpret_cast<Valtype
*>(
6205 oview
+ this->get_primary_got_offset(gsym
));
6207 // Find secondary GOT entry.
6208 Valtype
* wv_sec
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6210 Valtype value
= elfcpp::Swap
<size
, big_endian
>::readval(wv_sec
);
6213 elfcpp::Swap
<size
, big_endian
>::writeval(wv_prim
, value
);
6214 elfcpp::Swap
<size
, big_endian
>::writeval(wv_sec
, 0);
6215 gsym
->set_applied_secondary_got_fixup();
6220 of
->write_output_view(offset
, oview_size
, oview
);
6223 // We are done if there is no fix up.
6224 if (this->static_relocs_
.empty())
6227 Output_segment
* tls_segment
= this->layout_
->tls_segment();
6228 gold_assert(tls_segment
!= NULL
);
6230 for (size_t i
= 0; i
< this->static_relocs_
.size(); ++i
)
6232 Static_reloc
& reloc(this->static_relocs_
[i
]);
6235 if (!reloc
.symbol_is_global())
6237 Sized_relobj_file
<size
, big_endian
>* object
= reloc
.relobj();
6238 const Symbol_value
<size
>* psymval
=
6239 object
->local_symbol(reloc
.index());
6241 // We are doing static linking. Issue an error and skip this
6242 // relocation if the symbol is undefined or in a discarded_section.
6244 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
6245 if ((shndx
== elfcpp::SHN_UNDEF
)
6247 && shndx
!= elfcpp::SHN_UNDEF
6248 && !object
->is_section_included(shndx
)
6249 && !this->symbol_table_
->is_section_folded(object
, shndx
)))
6251 gold_error(_("undefined or discarded local symbol %u from "
6252 " object %s in GOT"),
6253 reloc
.index(), reloc
.relobj()->name().c_str());
6257 value
= psymval
->value(object
, 0);
6261 const Mips_symbol
<size
>* gsym
= reloc
.symbol();
6262 gold_assert(gsym
!= NULL
);
6264 // We are doing static linking. Issue an error and skip this
6265 // relocation if the symbol is undefined or in a discarded_section
6266 // unless it is a weakly_undefined symbol.
6267 if ((gsym
->is_defined_in_discarded_section() || gsym
->is_undefined())
6268 && !gsym
->is_weak_undefined())
6270 gold_error(_("undefined or discarded symbol %s in GOT"),
6275 if (!gsym
->is_weak_undefined())
6276 value
= gsym
->value();
6281 unsigned got_offset
= reloc
.got_offset();
6282 gold_assert(got_offset
< oview_size
);
6284 Valtype
* wv
= reinterpret_cast<Valtype
*>(oview
+ got_offset
);
6287 switch (reloc
.r_type())
6289 case elfcpp::R_MIPS_TLS_DTPMOD32
:
6290 case elfcpp::R_MIPS_TLS_DTPMOD64
:
6293 case elfcpp::R_MIPS_TLS_DTPREL32
:
6294 case elfcpp::R_MIPS_TLS_DTPREL64
:
6295 x
= value
- elfcpp::DTP_OFFSET
;
6297 case elfcpp::R_MIPS_TLS_TPREL32
:
6298 case elfcpp::R_MIPS_TLS_TPREL64
:
6299 x
= value
- elfcpp::TP_OFFSET
;
6306 elfcpp::Swap
<size
, big_endian
>::writeval(wv
, x
);
6309 of
->write_output_view(offset
, oview_size
, oview
);
6312 // Mips_relobj methods.
6314 // Count the local symbols. The Mips backend needs to know if a symbol
6315 // is a MIPS16 or microMIPS function or not. For global symbols, it is easy
6316 // because the Symbol object keeps the ELF symbol type and st_other field.
6317 // For local symbol it is harder because we cannot access this information.
6318 // So we override the do_count_local_symbol in parent and scan local symbols to
6319 // mark MIPS16 and microMIPS functions. This is not the most efficient way but
6320 // I do not want to slow down other ports by calling a per symbol target hook
6321 // inside Sized_relobj_file<size, big_endian>::do_count_local_symbols.
6323 template<int size
, bool big_endian
>
6325 Mips_relobj
<size
, big_endian
>::do_count_local_symbols(
6326 Stringpool_template
<char>* pool
,
6327 Stringpool_template
<char>* dynpool
)
6329 // Ask parent to count the local symbols.
6330 Sized_relobj_file
<size
, big_endian
>::do_count_local_symbols(pool
, dynpool
);
6331 const unsigned int loccount
= this->local_symbol_count();
6335 // Initialize the mips16 and micromips function bit-vector.
6336 this->local_symbol_is_mips16_
.resize(loccount
, false);
6337 this->local_symbol_is_micromips_
.resize(loccount
, false);
6339 // Read the symbol table section header.
6340 const unsigned int symtab_shndx
= this->symtab_shndx();
6341 elfcpp::Shdr
<size
, big_endian
>
6342 symtabshdr(this, this->elf_file()->section_header(symtab_shndx
));
6343 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
6345 // Read the local symbols.
6346 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
6347 gold_assert(loccount
== symtabshdr
.get_sh_info());
6348 off_t locsize
= loccount
* sym_size
;
6349 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
6350 locsize
, true, true);
6352 // Loop over the local symbols and mark any MIPS16 or microMIPS local symbols.
6354 // Skip the first dummy symbol.
6356 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
6358 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
6359 unsigned char st_other
= sym
.get_st_other();
6360 this->local_symbol_is_mips16_
[i
] = elfcpp::elf_st_is_mips16(st_other
);
6361 this->local_symbol_is_micromips_
[i
] =
6362 elfcpp::elf_st_is_micromips(st_other
);
6366 // Read the symbol information.
6368 template<int size
, bool big_endian
>
6370 Mips_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
6372 // Call parent class to read symbol information.
6373 this->base_read_symbols(sd
);
6375 // Read processor-specific flags in ELF file header.
6376 const unsigned char* pehdr
= this->get_view(elfcpp::file_header_offset
,
6377 elfcpp::Elf_sizes
<size
>::ehdr_size
,
6379 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
6380 this->processor_specific_flags_
= ehdr
.get_e_flags();
6382 // Get the section names.
6383 const unsigned char* pnamesu
= sd
->section_names
->data();
6384 const char* pnames
= reinterpret_cast<const char*>(pnamesu
);
6386 // Initialize the mips16 stub section bit-vectors.
6387 this->section_is_mips16_fn_stub_
.resize(this->shnum(), false);
6388 this->section_is_mips16_call_stub_
.resize(this->shnum(), false);
6389 this->section_is_mips16_call_fp_stub_
.resize(this->shnum(), false);
6391 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
6392 const unsigned char* pshdrs
= sd
->section_headers
->data();
6393 const unsigned char* ps
= pshdrs
+ shdr_size
;
6394 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
6396 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
6398 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_REGINFO
)
6400 // Read the gp value that was used to create this object. We need the
6401 // gp value while processing relocs. The .reginfo section is not used
6402 // in the 64-bit MIPS ELF ABI.
6403 section_offset_type section_offset
= shdr
.get_sh_offset();
6404 section_size_type section_size
=
6405 convert_to_section_size_type(shdr
.get_sh_size());
6406 const unsigned char* view
=
6407 this->get_view(section_offset
, section_size
, true, false);
6409 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 20);
6411 // Read the rest of .reginfo.
6412 this->gprmask_
= elfcpp::Swap
<size
, big_endian
>::readval(view
);
6413 this->cprmask1_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 4);
6414 this->cprmask2_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 8);
6415 this->cprmask3_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 12);
6416 this->cprmask4_
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ 16);
6419 // In the 64-bit ABI, .MIPS.options section holds register information.
6420 // A SHT_MIPS_OPTIONS section contains a series of options, each of which
6421 // starts with this header:
6425 // // Type of option.
6426 // unsigned char kind[1];
6427 // // Size of option descriptor, including header.
6428 // unsigned char size[1];
6429 // // Section index of affected section, or 0 for global option.
6430 // unsigned char section[2];
6431 // // Information specific to this kind of option.
6432 // unsigned char info[4];
6435 // For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and set
6436 // the gp value based on what we find. We may see both SHT_MIPS_REGINFO
6437 // and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case, they should agree.
6439 if (shdr
.get_sh_type() == elfcpp::SHT_MIPS_OPTIONS
)
6441 section_offset_type section_offset
= shdr
.get_sh_offset();
6442 section_size_type section_size
=
6443 convert_to_section_size_type(shdr
.get_sh_size());
6444 const unsigned char* view
=
6445 this->get_view(section_offset
, section_size
, true, false);
6446 const unsigned char* end
= view
+ section_size
;
6448 while (view
+ 8 <= end
)
6450 unsigned char kind
= elfcpp::Swap
<8, big_endian
>::readval(view
);
6451 unsigned char sz
= elfcpp::Swap
<8, big_endian
>::readval(view
+ 1);
6454 gold_error(_("%s: Warning: bad `%s' option size %u smaller "
6456 this->name().c_str(),
6457 this->mips_elf_options_section_name(), sz
);
6461 if (this->is_n64() && kind
== elfcpp::ODK_REGINFO
)
6463 // In the 64 bit ABI, an ODK_REGINFO option is the following
6464 // structure. The info field of the options header is not
6469 // // Mask of general purpose registers used.
6470 // unsigned char ri_gprmask[4];
6472 // unsigned char ri_pad[4];
6473 // // Mask of co-processor registers used.
6474 // unsigned char ri_cprmask[4][4];
6475 // // GP register value for this object file.
6476 // unsigned char ri_gp_value[8];
6479 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
6482 else if (kind
== elfcpp::ODK_REGINFO
)
6484 // In the 32 bit ABI, an ODK_REGINFO option is the following
6485 // structure. The info field of the options header is not
6486 // used. The same structure is used in .reginfo section.
6490 // unsigned char ri_gprmask[4];
6491 // unsigned char ri_cprmask[4][4];
6492 // unsigned char ri_gp_value[4];
6495 this->gp_
= elfcpp::Swap
<size
, big_endian
>::readval(view
6502 const char* name
= pnames
+ shdr
.get_sh_name();
6503 this->section_is_mips16_fn_stub_
[i
] = is_prefix_of(".mips16.fn", name
);
6504 this->section_is_mips16_call_stub_
[i
] =
6505 is_prefix_of(".mips16.call.", name
);
6506 this->section_is_mips16_call_fp_stub_
[i
] =
6507 is_prefix_of(".mips16.call.fp.", name
);
6509 if (strcmp(name
, ".pdr") == 0)
6511 gold_assert(this->pdr_shndx_
== -1U);
6512 this->pdr_shndx_
= i
;
6517 // Discard MIPS16 stub secions that are not needed.
6519 template<int size
, bool big_endian
>
6521 Mips_relobj
<size
, big_endian
>::discard_mips16_stub_sections(Symbol_table
* symtab
)
6523 for (typename
Mips16_stubs_int_map::const_iterator
6524 it
= this->mips16_stub_sections_
.begin();
6525 it
!= this->mips16_stub_sections_
.end(); ++it
)
6527 Mips16_stub_section
<size
, big_endian
>* stub_section
= it
->second
;
6528 if (!stub_section
->is_target_found())
6530 gold_error(_("no relocation found in mips16 stub section '%s'"),
6531 stub_section
->object()
6532 ->section_name(stub_section
->shndx()).c_str());
6535 bool discard
= false;
6536 if (stub_section
->is_for_local_function())
6538 if (stub_section
->is_fn_stub())
6540 // This stub is for a local symbol. This stub will only
6541 // be needed if there is some relocation in this object,
6542 // other than a 16 bit function call, which refers to this
6544 if (!this->has_local_non_16bit_call_relocs(stub_section
->r_sym()))
6547 this->add_local_mips16_fn_stub(stub_section
);
6551 // This stub is for a local symbol. This stub will only
6552 // be needed if there is some relocation (R_MIPS16_26) in
6553 // this object that refers to this symbol.
6554 gold_assert(stub_section
->is_call_stub()
6555 || stub_section
->is_call_fp_stub());
6556 if (!this->has_local_16bit_call_relocs(stub_section
->r_sym()))
6559 this->add_local_mips16_call_stub(stub_section
);
6564 Mips_symbol
<size
>* gsym
= stub_section
->gsym();
6565 if (stub_section
->is_fn_stub())
6567 if (gsym
->has_mips16_fn_stub())
6568 // We already have a stub for this function.
6572 gsym
->set_mips16_fn_stub(stub_section
);
6573 if (gsym
->should_add_dynsym_entry(symtab
))
6575 // If we have a MIPS16 function with a stub, the
6576 // dynamic symbol must refer to the stub, since only
6577 // the stub uses the standard calling conventions.
6578 gsym
->set_need_fn_stub();
6579 if (gsym
->is_from_dynobj())
6580 gsym
->set_needs_dynsym_value();
6583 if (!gsym
->need_fn_stub())
6586 else if (stub_section
->is_call_stub())
6588 if (gsym
->is_mips16())
6589 // We don't need the call_stub; this is a 16 bit
6590 // function, so calls from other 16 bit functions are
6593 else if (gsym
->has_mips16_call_stub())
6594 // We already have a stub for this function.
6597 gsym
->set_mips16_call_stub(stub_section
);
6601 gold_assert(stub_section
->is_call_fp_stub());
6602 if (gsym
->is_mips16())
6603 // We don't need the call_stub; this is a 16 bit
6604 // function, so calls from other 16 bit functions are
6607 else if (gsym
->has_mips16_call_fp_stub())
6608 // We already have a stub for this function.
6611 gsym
->set_mips16_call_fp_stub(stub_section
);
6615 this->set_output_section(stub_section
->shndx(), NULL
);
6619 // Mips_output_data_la25_stub methods.
6621 // Template for standard LA25 stub.
6622 template<int size
, bool big_endian
>
6624 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_entry
[] =
6626 0x3c190000, // lui $25,%hi(func)
6627 0x08000000, // j func
6628 0x27390000, // add $25,$25,%lo(func)
6632 // Template for microMIPS LA25 stub.
6633 template<int size
, bool big_endian
>
6635 Mips_output_data_la25_stub
<size
, big_endian
>::la25_stub_micromips_entry
[] =
6637 0x41b9, 0x0000, // lui t9,%hi(func)
6638 0xd400, 0x0000, // j func
6639 0x3339, 0x0000, // addiu t9,t9,%lo(func)
6640 0x0000, 0x0000 // nop
6643 // Create la25 stub for a symbol.
6645 template<int size
, bool big_endian
>
6647 Mips_output_data_la25_stub
<size
, big_endian
>::create_la25_stub(
6648 Symbol_table
* symtab
, Target_mips
<size
, big_endian
>* target
,
6649 Mips_symbol
<size
>* gsym
)
6651 if (!gsym
->has_la25_stub())
6653 gsym
->set_la25_stub_offset(this->symbols_
.size() * 16);
6654 this->symbols_
.push_back(gsym
);
6655 this->create_stub_symbol(gsym
, symtab
, target
, 16);
6659 // Create a symbol for SYM stub's value and size, to help make the disassembly
6662 template<int size
, bool big_endian
>
6664 Mips_output_data_la25_stub
<size
, big_endian
>::create_stub_symbol(
6665 Mips_symbol
<size
>* sym
, Symbol_table
* symtab
,
6666 Target_mips
<size
, big_endian
>* target
, uint64_t symsize
)
6668 std::string
name(".pic.");
6669 name
+= sym
->name();
6671 unsigned int offset
= sym
->la25_stub_offset();
6672 if (sym
->is_micromips())
6675 // Make it a local function.
6676 Symbol
* new_sym
= symtab
->define_in_output_data(name
.c_str(), NULL
,
6677 Symbol_table::PREDEFINED
,
6678 target
->la25_stub_section(),
6679 offset
, symsize
, elfcpp::STT_FUNC
,
6681 elfcpp::STV_DEFAULT
, 0,
6683 new_sym
->set_is_forced_local();
6686 // Write out la25 stubs. This uses the hand-coded instructions above,
6687 // and adjusts them as needed.
6689 template<int size
, bool big_endian
>
6691 Mips_output_data_la25_stub
<size
, big_endian
>::do_write(Output_file
* of
)
6693 const off_t offset
= this->offset();
6694 const section_size_type oview_size
=
6695 convert_to_section_size_type(this->data_size());
6696 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6698 for (typename
std::vector
<Mips_symbol
<size
>*>::iterator
6699 p
= this->symbols_
.begin();
6700 p
!= this->symbols_
.end();
6703 Mips_symbol
<size
>* sym
= *p
;
6704 unsigned char* pov
= oview
+ sym
->la25_stub_offset();
6706 Mips_address target
= sym
->value();
6707 if (!sym
->is_micromips())
6709 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
6710 la25_stub_entry
[0] | (((target
+ 0x8000) >> 16) & 0xffff));
6711 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
6712 la25_stub_entry
[1] | ((target
>> 2) & 0x3ffffff));
6713 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
6714 la25_stub_entry
[2] | (target
& 0xffff));
6715 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12, la25_stub_entry
[3]);
6720 // First stub instruction. Paste high 16-bits of the target.
6721 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
6722 la25_stub_micromips_entry
[0]);
6723 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
6724 ((target
+ 0x8000) >> 16) & 0xffff);
6725 // Second stub instruction. Paste low 26-bits of the target, shifted
6727 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
6728 la25_stub_micromips_entry
[2] | ((target
>> 17) & 0x3ff));
6729 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
6730 la25_stub_micromips_entry
[3] | ((target
>> 1) & 0xffff));
6731 // Third stub instruction. Paste low 16-bits of the target.
6732 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8,
6733 la25_stub_micromips_entry
[4]);
6734 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, target
& 0xffff);
6735 // Fourth stub instruction.
6736 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 12,
6737 la25_stub_micromips_entry
[6]);
6738 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 14,
6739 la25_stub_micromips_entry
[7]);
6743 of
->write_output_view(offset
, oview_size
, oview
);
6746 // Mips_output_data_plt methods.
6748 // The format of the first PLT entry in an O32 executable.
6749 template<int size
, bool big_endian
>
6750 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_o32
[] =
6752 0x3c1c0000, // lui $28, %hi(&GOTPLT[0])
6753 0x8f990000, // lw $25, %lo(&GOTPLT[0])($28)
6754 0x279c0000, // addiu $28, $28, %lo(&GOTPLT[0])
6755 0x031cc023, // subu $24, $24, $28
6756 0x03e07825, // or $15, $31, zero
6757 0x0018c082, // srl $24, $24, 2
6758 0x0320f809, // jalr $25
6759 0x2718fffe // subu $24, $24, 2
6762 // The format of the first PLT entry in an N32 executable. Different
6763 // because gp ($28) is not available; we use t2 ($14) instead.
6764 template<int size
, bool big_endian
>
6765 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n32
[] =
6767 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
6768 0x8dd90000, // lw $25, %lo(&GOTPLT[0])($14)
6769 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
6770 0x030ec023, // subu $24, $24, $14
6771 0x03e07825, // or $15, $31, zero
6772 0x0018c082, // srl $24, $24, 2
6773 0x0320f809, // jalr $25
6774 0x2718fffe // subu $24, $24, 2
6777 // The format of the first PLT entry in an N64 executable. Different
6778 // from N32 because of the increased size of GOT entries.
6779 template<int size
, bool big_endian
>
6780 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt0_entry_n64
[] =
6782 0x3c0e0000, // lui $14, %hi(&GOTPLT[0])
6783 0xddd90000, // ld $25, %lo(&GOTPLT[0])($14)
6784 0x25ce0000, // addiu $14, $14, %lo(&GOTPLT[0])
6785 0x030ec023, // subu $24, $24, $14
6786 0x03e07825, // or $15, $31, zero
6787 0x0018c0c2, // srl $24, $24, 3
6788 0x0320f809, // jalr $25
6789 0x2718fffe // subu $24, $24, 2
6792 // The format of the microMIPS first PLT entry in an O32 executable.
6793 // We rely on v0 ($2) rather than t8 ($24) to contain the address
6794 // of the GOTPLT entry handled, so this stub may only be used when
6795 // all the subsequent PLT entries are microMIPS code too.
6797 // The trailing NOP is for alignment and correct disassembly only.
6798 template<int size
, bool big_endian
>
6799 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6800 plt0_entry_micromips_o32
[] =
6802 0x7980, 0x0000, // addiupc $3, (&GOTPLT[0]) - .
6803 0xff23, 0x0000, // lw $25, 0($3)
6804 0x0535, // subu $2, $2, $3
6805 0x2525, // srl $2, $2, 2
6806 0x3302, 0xfffe, // subu $24, $2, 2
6807 0x0dff, // move $15, $31
6808 0x45f9, // jalrs $25
6809 0x0f83, // move $28, $3
6813 // The format of the microMIPS first PLT entry in an O32 executable
6814 // in the insn32 mode.
6815 template<int size
, bool big_endian
>
6816 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6817 plt0_entry_micromips32_o32
[] =
6819 0x41bc, 0x0000, // lui $28, %hi(&GOTPLT[0])
6820 0xff3c, 0x0000, // lw $25, %lo(&GOTPLT[0])($28)
6821 0x339c, 0x0000, // addiu $28, $28, %lo(&GOTPLT[0])
6822 0x0398, 0xc1d0, // subu $24, $24, $28
6823 0x001f, 0x7a90, // or $15, $31, zero
6824 0x0318, 0x1040, // srl $24, $24, 2
6825 0x03f9, 0x0f3c, // jalr $25
6826 0x3318, 0xfffe // subu $24, $24, 2
6829 // The format of subsequent standard entries in the PLT.
6830 template<int size
, bool big_endian
>
6831 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry
[] =
6833 0x3c0f0000, // lui $15, %hi(.got.plt entry)
6834 0x01f90000, // l[wd] $25, %lo(.got.plt entry)($15)
6835 0x03200008, // jr $25
6836 0x25f80000 // addiu $24, $15, %lo(.got.plt entry)
6839 // The format of subsequent MIPS16 o32 PLT entries. We use v1 ($3) as a
6840 // temporary because t8 ($24) and t9 ($25) are not directly addressable.
6841 // Note that this differs from the GNU ld which uses both v0 ($2) and v1 ($3).
6842 // We cannot use v0 because MIPS16 call stubs from the CS toolchain expect
6843 // target function address in register v0.
6844 template<int size
, bool big_endian
>
6845 const uint32_t Mips_output_data_plt
<size
, big_endian
>::plt_entry_mips16_o32
[] =
6847 0xb303, // lw $3, 12($pc)
6848 0x651b, // move $24, $3
6849 0x9b60, // lw $3, 0($3)
6851 0x653b, // move $25, $3
6853 0x0000, 0x0000 // .word (.got.plt entry)
6856 // The format of subsequent microMIPS o32 PLT entries. We use v0 ($2)
6857 // as a temporary because t8 ($24) is not addressable with ADDIUPC.
6858 template<int size
, bool big_endian
>
6859 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6860 plt_entry_micromips_o32
[] =
6862 0x7900, 0x0000, // addiupc $2, (.got.plt entry) - .
6863 0xff22, 0x0000, // lw $25, 0($2)
6865 0x0f02 // move $24, $2
6868 // The format of subsequent microMIPS o32 PLT entries in the insn32 mode.
6869 template<int size
, bool big_endian
>
6870 const uint32_t Mips_output_data_plt
<size
, big_endian
>::
6871 plt_entry_micromips32_o32
[] =
6873 0x41af, 0x0000, // lui $15, %hi(.got.plt entry)
6874 0xff2f, 0x0000, // lw $25, %lo(.got.plt entry)($15)
6875 0x0019, 0x0f3c, // jr $25
6876 0x330f, 0x0000 // addiu $24, $15, %lo(.got.plt entry)
6879 // Add an entry to the PLT for a symbol referenced by r_type relocation.
6881 template<int size
, bool big_endian
>
6883 Mips_output_data_plt
<size
, big_endian
>::add_entry(Mips_symbol
<size
>* gsym
,
6884 unsigned int r_type
)
6886 gold_assert(!gsym
->has_plt_offset());
6888 // Final PLT offset for a symbol will be set in method set_plt_offsets().
6889 gsym
->set_plt_offset(this->entry_count() * sizeof(plt_entry
)
6890 + sizeof(plt0_entry_o32
));
6891 this->symbols_
.push_back(gsym
);
6893 // Record whether the relocation requires a standard MIPS
6894 // or a compressed code entry.
6895 if (jal_reloc(r_type
))
6897 if (r_type
== elfcpp::R_MIPS_26
)
6898 gsym
->set_needs_mips_plt(true);
6900 gsym
->set_needs_comp_plt(true);
6903 section_offset_type got_offset
= this->got_plt_
->current_data_size();
6905 // Every PLT entry needs a GOT entry which points back to the PLT
6906 // entry (this will be changed by the dynamic linker, normally
6907 // lazily when the function is called).
6908 this->got_plt_
->set_current_data_size(got_offset
+ size
/8);
6910 gsym
->set_needs_dynsym_entry();
6911 this->rel_
->add_global(gsym
, elfcpp::R_MIPS_JUMP_SLOT
, this->got_plt_
,
6915 // Set final PLT offsets. For each symbol, determine whether standard or
6916 // compressed (MIPS16 or microMIPS) PLT entry is used.
6918 template<int size
, bool big_endian
>
6920 Mips_output_data_plt
<size
, big_endian
>::set_plt_offsets()
6922 // The sizes of individual PLT entries.
6923 unsigned int plt_mips_entry_size
= this->standard_plt_entry_size();
6924 unsigned int plt_comp_entry_size
= (!this->target_
->is_output_newabi()
6925 ? this->compressed_plt_entry_size() : 0);
6927 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
6928 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
6930 Mips_symbol
<size
>* mips_sym
= *p
;
6932 // There are no defined MIPS16 or microMIPS PLT entries for n32 or n64,
6933 // so always use a standard entry there.
6935 // If the symbol has a MIPS16 call stub and gets a PLT entry, then
6936 // all MIPS16 calls will go via that stub, and there is no benefit
6937 // to having a MIPS16 entry. And in the case of call_stub a
6938 // standard entry actually has to be used as the stub ends with a J
6940 if (this->target_
->is_output_newabi()
6941 || mips_sym
->has_mips16_call_stub()
6942 || mips_sym
->has_mips16_call_fp_stub())
6944 mips_sym
->set_needs_mips_plt(true);
6945 mips_sym
->set_needs_comp_plt(false);
6948 // Otherwise, if there are no direct calls to the function, we
6949 // have a free choice of whether to use standard or compressed
6950 // entries. Prefer microMIPS entries if the object is known to
6951 // contain microMIPS code, so that it becomes possible to create
6952 // pure microMIPS binaries. Prefer standard entries otherwise,
6953 // because MIPS16 ones are no smaller and are usually slower.
6954 if (!mips_sym
->needs_mips_plt() && !mips_sym
->needs_comp_plt())
6956 if (this->target_
->is_output_micromips())
6957 mips_sym
->set_needs_comp_plt(true);
6959 mips_sym
->set_needs_mips_plt(true);
6962 if (mips_sym
->needs_mips_plt())
6964 mips_sym
->set_mips_plt_offset(this->plt_mips_offset_
);
6965 this->plt_mips_offset_
+= plt_mips_entry_size
;
6967 if (mips_sym
->needs_comp_plt())
6969 mips_sym
->set_comp_plt_offset(this->plt_comp_offset_
);
6970 this->plt_comp_offset_
+= plt_comp_entry_size
;
6974 // Figure out the size of the PLT header if we know that we are using it.
6975 if (this->plt_mips_offset_
+ this->plt_comp_offset_
!= 0)
6976 this->plt_header_size_
= this->get_plt_header_size();
6979 // Write out the PLT. This uses the hand-coded instructions above,
6980 // and adjusts them as needed.
6982 template<int size
, bool big_endian
>
6984 Mips_output_data_plt
<size
, big_endian
>::do_write(Output_file
* of
)
6986 const off_t offset
= this->offset();
6987 const section_size_type oview_size
=
6988 convert_to_section_size_type(this->data_size());
6989 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
6991 const off_t gotplt_file_offset
= this->got_plt_
->offset();
6992 const section_size_type gotplt_size
=
6993 convert_to_section_size_type(this->got_plt_
->data_size());
6994 unsigned char* const gotplt_view
= of
->get_output_view(gotplt_file_offset
,
6996 unsigned char* pov
= oview
;
6998 Mips_address plt_address
= this->address();
7000 // Calculate the address of .got.plt.
7001 Mips_address gotplt_addr
= this->got_plt_
->address();
7002 Mips_address gotplt_addr_high
= ((gotplt_addr
+ 0x8000) >> 16) & 0xffff;
7003 Mips_address gotplt_addr_low
= gotplt_addr
& 0xffff;
7005 // The PLT sequence is not safe for N64 if .got.plt's address can
7006 // not be loaded in two instructions.
7007 gold_assert((gotplt_addr
& ~(Mips_address
) 0x7fffffff) == 0
7008 || ~(gotplt_addr
| 0x7fffffff) == 0);
7010 // Write the PLT header.
7011 const uint32_t* plt0_entry
= this->get_plt_header_entry();
7012 if (plt0_entry
== plt0_entry_micromips_o32
)
7014 // Write microMIPS PLT header.
7015 gold_assert(gotplt_addr
% 4 == 0);
7017 Mips_address gotpc_offset
= gotplt_addr
- ((plt_address
| 3) ^ 3);
7019 // ADDIUPC has a span of +/-16MB, check we're in range.
7020 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
7022 gold_error(_(".got.plt offset of %ld from .plt beyond the range of "
7023 "ADDIUPC"), (long)gotpc_offset
);
7027 elfcpp::Swap
<16, big_endian
>::writeval(pov
,
7028 plt0_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
7029 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7030 (gotpc_offset
>> 2) & 0xffff);
7032 for (unsigned int i
= 2;
7033 i
< (sizeof(plt0_entry_micromips_o32
)
7034 / sizeof(plt0_entry_micromips_o32
[0]));
7037 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7041 else if (plt0_entry
== plt0_entry_micromips32_o32
)
7043 // Write microMIPS PLT header in insn32 mode.
7044 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[0]);
7045 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, gotplt_addr_high
);
7046 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, plt0_entry
[2]);
7047 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, gotplt_addr_low
);
7048 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 8, plt0_entry
[4]);
7049 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 10, gotplt_addr_low
);
7051 for (unsigned int i
= 6;
7052 i
< (sizeof(plt0_entry_micromips32_o32
)
7053 / sizeof(plt0_entry_micromips32_o32
[0]));
7056 elfcpp::Swap
<16, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7062 // Write standard PLT header.
7063 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7064 plt0_entry
[0] | gotplt_addr_high
);
7065 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7066 plt0_entry
[1] | gotplt_addr_low
);
7067 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8,
7068 plt0_entry
[2] | gotplt_addr_low
);
7070 for (int i
= 3; i
< 8; i
++)
7072 elfcpp::Swap
<32, big_endian
>::writeval(pov
, plt0_entry
[i
]);
7078 unsigned char* gotplt_pov
= gotplt_view
;
7079 unsigned int got_entry_size
= size
/8; // TODO(sasa): MIPS_ELF_GOT_SIZE
7081 // The first two entries in .got.plt are reserved.
7082 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
, 0);
7083 elfcpp::Swap
<size
, big_endian
>::writeval(gotplt_pov
+ got_entry_size
, 0);
7085 unsigned int gotplt_offset
= 2 * got_entry_size
;
7086 gotplt_pov
+= 2 * got_entry_size
;
7088 // Calculate the address of the PLT header.
7089 Mips_address header_address
= (plt_address
7090 + (this->is_plt_header_compressed() ? 1 : 0));
7092 // Initialize compressed PLT area view.
7093 unsigned char* pov2
= pov
+ this->plt_mips_offset_
;
7095 // Write the PLT entries.
7096 for (typename
std::vector
<Mips_symbol
<size
>*>::const_iterator
7097 p
= this->symbols_
.begin();
7098 p
!= this->symbols_
.end();
7099 ++p
, gotplt_pov
+= got_entry_size
, gotplt_offset
+= got_entry_size
)
7101 Mips_symbol
<size
>* mips_sym
= *p
;
7103 // Calculate the address of the .got.plt entry.
7104 uint32_t gotplt_entry_addr
= (gotplt_addr
+ gotplt_offset
);
7105 uint32_t gotplt_entry_addr_hi
= (((gotplt_entry_addr
+ 0x8000) >> 16)
7107 uint32_t gotplt_entry_addr_lo
= gotplt_entry_addr
& 0xffff;
7109 // Initially point the .got.plt entry at the PLT header.
7110 if (this->target_
->is_output_n64())
7111 elfcpp::Swap
<64, big_endian
>::writeval(gotplt_pov
, header_address
);
7113 elfcpp::Swap
<32, big_endian
>::writeval(gotplt_pov
, header_address
);
7115 // Now handle the PLT itself. First the standard entry.
7116 if (mips_sym
->has_mips_plt_offset())
7118 // Pick the load opcode (LW or LD).
7119 uint64_t load
= this->target_
->is_output_n64() ? 0xdc000000
7122 // Fill in the PLT entry itself.
7123 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7124 plt_entry
[0] | gotplt_entry_addr_hi
);
7125 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7126 plt_entry
[1] | gotplt_entry_addr_lo
| load
);
7127 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 8, plt_entry
[2]);
7128 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 12,
7129 plt_entry
[3] | gotplt_entry_addr_lo
);
7133 // Now the compressed entry. They come after any standard ones.
7134 if (mips_sym
->has_comp_plt_offset())
7136 if (!this->target_
->is_output_micromips())
7138 // Write MIPS16 PLT entry.
7139 const uint32_t* plt_entry
= plt_entry_mips16_o32
;
7141 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
7142 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2, plt_entry
[1]);
7143 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7144 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
7145 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7146 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7147 elfcpp::Swap
<32, big_endian
>::writeval(pov2
+ 12,
7151 else if (this->target_
->use_32bit_micromips_instructions())
7153 // Write microMIPS PLT entry in insn32 mode.
7154 const uint32_t* plt_entry
= plt_entry_micromips32_o32
;
7156 elfcpp::Swap
<16, big_endian
>::writeval(pov2
, plt_entry
[0]);
7157 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 2,
7158 gotplt_entry_addr_hi
);
7159 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7160 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6,
7161 gotplt_entry_addr_lo
);
7162 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7163 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7164 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 12, plt_entry
[6]);
7165 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 14,
7166 gotplt_entry_addr_lo
);
7171 // Write microMIPS PLT entry.
7172 const uint32_t* plt_entry
= plt_entry_micromips_o32
;
7174 gold_assert(gotplt_entry_addr
% 4 == 0);
7176 Mips_address loc_address
= plt_address
+ pov2
- oview
;
7177 int gotpc_offset
= gotplt_entry_addr
- ((loc_address
| 3) ^ 3);
7179 // ADDIUPC has a span of +/-16MB, check we're in range.
7180 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
7182 gold_error(_(".got.plt offset of %ld from .plt beyond the "
7183 "range of ADDIUPC"), (long)gotpc_offset
);
7187 elfcpp::Swap
<16, big_endian
>::writeval(pov2
,
7188 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f));
7189 elfcpp::Swap
<16, big_endian
>::writeval(
7190 pov2
+ 2, (gotpc_offset
>> 2) & 0xffff);
7191 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 4, plt_entry
[2]);
7192 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 6, plt_entry
[3]);
7193 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 8, plt_entry
[4]);
7194 elfcpp::Swap
<16, big_endian
>::writeval(pov2
+ 10, plt_entry
[5]);
7200 // Check the number of bytes written for standard entries.
7201 gold_assert(static_cast<section_size_type
>(
7202 pov
- oview
- this->plt_header_size_
) == this->plt_mips_offset_
);
7203 // Check the number of bytes written for compressed entries.
7204 gold_assert((static_cast<section_size_type
>(pov2
- pov
)
7205 == this->plt_comp_offset_
));
7206 // Check the total number of bytes written.
7207 gold_assert(static_cast<section_size_type
>(pov2
- oview
) == oview_size
);
7209 gold_assert(static_cast<section_size_type
>(gotplt_pov
- gotplt_view
)
7212 of
->write_output_view(offset
, oview_size
, oview
);
7213 of
->write_output_view(gotplt_file_offset
, gotplt_size
, gotplt_view
);
7216 // Mips_output_data_mips_stubs methods.
7218 // The format of the lazy binding stub when dynamic symbol count is less than
7219 // 64K, dynamic symbol index is less than 32K, and ABI is not N64.
7220 template<int size
, bool big_endian
>
7222 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1
[4] =
7224 0x8f998010, // lw t9,0x8010(gp)
7225 0x03e07825, // or t7,ra,zero
7226 0x0320f809, // jalr t9,ra
7227 0x24180000 // addiu t8,zero,DYN_INDEX sign extended
7230 // The format of the lazy binding stub when dynamic symbol count is less than
7231 // 64K, dynamic symbol index is less than 32K, and ABI is N64.
7232 template<int size
, bool big_endian
>
7234 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_1_n64
[4] =
7236 0xdf998010, // ld t9,0x8010(gp)
7237 0x03e07825, // or t7,ra,zero
7238 0x0320f809, // jalr t9,ra
7239 0x64180000 // daddiu t8,zero,DYN_INDEX sign extended
7242 // The format of the lazy binding stub when dynamic symbol count is less than
7243 // 64K, dynamic symbol index is between 32K and 64K, and ABI is not N64.
7244 template<int size
, bool big_endian
>
7246 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2
[4] =
7248 0x8f998010, // lw t9,0x8010(gp)
7249 0x03e07825, // or t7,ra,zero
7250 0x0320f809, // jalr t9,ra
7251 0x34180000 // ori t8,zero,DYN_INDEX unsigned
7254 // The format of the lazy binding stub when dynamic symbol count is less than
7255 // 64K, dynamic symbol index is between 32K and 64K, and ABI is N64.
7256 template<int size
, bool big_endian
>
7258 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_normal_2_n64
[4] =
7260 0xdf998010, // ld t9,0x8010(gp)
7261 0x03e07825, // or t7,ra,zero
7262 0x0320f809, // jalr t9,ra
7263 0x34180000 // ori t8,zero,DYN_INDEX unsigned
7266 // The format of the lazy binding stub when dynamic symbol count is greater than
7267 // 64K, and ABI is not N64.
7268 template<int size
, bool big_endian
>
7269 const uint32_t Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big
[5] =
7271 0x8f998010, // lw t9,0x8010(gp)
7272 0x03e07825, // or t7,ra,zero
7273 0x3c180000, // lui t8,DYN_INDEX
7274 0x0320f809, // jalr t9,ra
7275 0x37180000 // ori t8,t8,DYN_INDEX
7278 // The format of the lazy binding stub when dynamic symbol count is greater than
7279 // 64K, and ABI is N64.
7280 template<int size
, bool big_endian
>
7282 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_big_n64
[5] =
7284 0xdf998010, // ld t9,0x8010(gp)
7285 0x03e07825, // or t7,ra,zero
7286 0x3c180000, // lui t8,DYN_INDEX
7287 0x0320f809, // jalr t9,ra
7288 0x37180000 // ori t8,t8,DYN_INDEX
7293 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7294 // less than 64K, dynamic symbol index is less than 32K, and ABI is not N64.
7295 template<int size
, bool big_endian
>
7297 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_1
[] =
7299 0xff3c, 0x8010, // lw t9,0x8010(gp)
7300 0x0dff, // move t7,ra
7302 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
7305 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7306 // less than 64K, dynamic symbol index is less than 32K, and ABI is N64.
7307 template<int size
, bool big_endian
>
7309 Mips_output_data_mips_stubs
<size
, big_endian
>::
7310 lazy_stub_micromips_normal_1_n64
[] =
7312 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7313 0x0dff, // move t7,ra
7315 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
7318 // The format of the microMIPS lazy binding stub when dynamic symbol
7319 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7320 // and ABI is not N64.
7321 template<int size
, bool big_endian
>
7323 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_normal_2
[] =
7325 0xff3c, 0x8010, // lw t9,0x8010(gp)
7326 0x0dff, // move t7,ra
7328 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7331 // The format of the microMIPS lazy binding stub when dynamic symbol
7332 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7334 template<int size
, bool big_endian
>
7336 Mips_output_data_mips_stubs
<size
, big_endian
>::
7337 lazy_stub_micromips_normal_2_n64
[] =
7339 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7340 0x0dff, // move t7,ra
7342 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7345 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7346 // greater than 64K, and ABI is not N64.
7347 template<int size
, bool big_endian
>
7349 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big
[] =
7351 0xff3c, 0x8010, // lw t9,0x8010(gp)
7352 0x0dff, // move t7,ra
7353 0x41b8, 0x0000, // lui t8,DYN_INDEX
7355 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7358 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7359 // greater than 64K, and ABI is N64.
7360 template<int size
, bool big_endian
>
7362 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips_big_n64
[] =
7364 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7365 0x0dff, // move t7,ra
7366 0x41b8, 0x0000, // lui t8,DYN_INDEX
7368 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7371 // 32-bit microMIPS stubs.
7373 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7374 // less than 64K, dynamic symbol index is less than 32K, ABI is not N64, and we
7375 // can use only 32-bit instructions.
7376 template<int size
, bool big_endian
>
7378 Mips_output_data_mips_stubs
<size
, big_endian
>::
7379 lazy_stub_micromips32_normal_1
[] =
7381 0xff3c, 0x8010, // lw t9,0x8010(gp)
7382 0x001f, 0x7a90, // or t7,ra,zero
7383 0x03f9, 0x0f3c, // jalr ra,t9
7384 0x3300, 0x0000 // addiu t8,zero,DYN_INDEX sign extended
7387 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7388 // less than 64K, dynamic symbol index is less than 32K, ABI is N64, and we can
7389 // use only 32-bit instructions.
7390 template<int size
, bool big_endian
>
7392 Mips_output_data_mips_stubs
<size
, big_endian
>::
7393 lazy_stub_micromips32_normal_1_n64
[] =
7395 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7396 0x001f, 0x7a90, // or t7,ra,zero
7397 0x03f9, 0x0f3c, // jalr ra,t9
7398 0x5f00, 0x0000 // daddiu t8,zero,DYN_INDEX sign extended
7401 // The format of the microMIPS lazy binding stub when dynamic symbol
7402 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7403 // ABI is not N64, and we can use only 32-bit instructions.
7404 template<int size
, bool big_endian
>
7406 Mips_output_data_mips_stubs
<size
, big_endian
>::
7407 lazy_stub_micromips32_normal_2
[] =
7409 0xff3c, 0x8010, // lw t9,0x8010(gp)
7410 0x001f, 0x7a90, // or t7,ra,zero
7411 0x03f9, 0x0f3c, // jalr ra,t9
7412 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7415 // The format of the microMIPS lazy binding stub when dynamic symbol
7416 // count is less than 64K, dynamic symbol index is between 32K and 64K,
7417 // ABI is N64, and we can use only 32-bit instructions.
7418 template<int size
, bool big_endian
>
7420 Mips_output_data_mips_stubs
<size
, big_endian
>::
7421 lazy_stub_micromips32_normal_2_n64
[] =
7423 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7424 0x001f, 0x7a90, // or t7,ra,zero
7425 0x03f9, 0x0f3c, // jalr ra,t9
7426 0x5300, 0x0000 // ori t8,zero,DYN_INDEX unsigned
7429 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7430 // greater than 64K, ABI is not N64, and we can use only 32-bit instructions.
7431 template<int size
, bool big_endian
>
7433 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big
[] =
7435 0xff3c, 0x8010, // lw t9,0x8010(gp)
7436 0x001f, 0x7a90, // or t7,ra,zero
7437 0x41b8, 0x0000, // lui t8,DYN_INDEX
7438 0x03f9, 0x0f3c, // jalr ra,t9
7439 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7442 // The format of the microMIPS lazy binding stub when dynamic symbol count is
7443 // greater than 64K, ABI is N64, and we can use only 32-bit instructions.
7444 template<int size
, bool big_endian
>
7446 Mips_output_data_mips_stubs
<size
, big_endian
>::lazy_stub_micromips32_big_n64
[] =
7448 0xdf3c, 0x8010, // ld t9,0x8010(gp)
7449 0x001f, 0x7a90, // or t7,ra,zero
7450 0x41b8, 0x0000, // lui t8,DYN_INDEX
7451 0x03f9, 0x0f3c, // jalr ra,t9
7452 0x5318, 0x0000 // ori t8,t8,DYN_INDEX
7455 // Create entry for a symbol.
7457 template<int size
, bool big_endian
>
7459 Mips_output_data_mips_stubs
<size
, big_endian
>::make_entry(
7460 Mips_symbol
<size
>* gsym
)
7462 if (!gsym
->has_lazy_stub() && !gsym
->has_plt_offset())
7464 this->symbols_
.insert(gsym
);
7465 gsym
->set_has_lazy_stub(true);
7469 // Remove entry for a symbol.
7471 template<int size
, bool big_endian
>
7473 Mips_output_data_mips_stubs
<size
, big_endian
>::remove_entry(
7474 Mips_symbol
<size
>* gsym
)
7476 if (gsym
->has_lazy_stub())
7478 this->symbols_
.erase(gsym
);
7479 gsym
->set_has_lazy_stub(false);
7483 // Set stub offsets for symbols. This method expects that the number of
7484 // entries in dynamic symbol table is set.
7486 template<int size
, bool big_endian
>
7488 Mips_output_data_mips_stubs
<size
, big_endian
>::set_lazy_stub_offsets()
7490 gold_assert(this->dynsym_count_
!= -1U);
7492 if (this->stub_offsets_are_set_
)
7495 unsigned int stub_size
= this->stub_size();
7496 unsigned int offset
= 0;
7497 for (typename
Mips_stubs_entry_set::const_iterator
7498 p
= this->symbols_
.begin();
7499 p
!= this->symbols_
.end();
7500 ++p
, offset
+= stub_size
)
7502 Mips_symbol
<size
>* mips_sym
= *p
;
7503 mips_sym
->set_lazy_stub_offset(offset
);
7505 this->stub_offsets_are_set_
= true;
7508 template<int size
, bool big_endian
>
7510 Mips_output_data_mips_stubs
<size
, big_endian
>::set_needs_dynsym_value()
7512 for (typename
Mips_stubs_entry_set::const_iterator
7513 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
7515 Mips_symbol
<size
>* sym
= *p
;
7516 if (sym
->is_from_dynobj())
7517 sym
->set_needs_dynsym_value();
7521 // Write out the .MIPS.stubs. This uses the hand-coded instructions and
7522 // adjusts them as needed.
7524 template<int size
, bool big_endian
>
7526 Mips_output_data_mips_stubs
<size
, big_endian
>::do_write(Output_file
* of
)
7528 const off_t offset
= this->offset();
7529 const section_size_type oview_size
=
7530 convert_to_section_size_type(this->data_size());
7531 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
7533 bool big_stub
= this->dynsym_count_
> 0x10000;
7535 unsigned char* pov
= oview
;
7536 for (typename
Mips_stubs_entry_set::const_iterator
7537 p
= this->symbols_
.begin(); p
!= this->symbols_
.end(); ++p
)
7539 Mips_symbol
<size
>* sym
= *p
;
7540 const uint32_t* lazy_stub
;
7541 bool n64
= this->target_
->is_output_n64();
7543 if (!this->target_
->is_output_micromips())
7545 // Write standard (non-microMIPS) stub.
7548 if (sym
->dynsym_index() & ~0x7fff)
7549 // Dynsym index is between 32K and 64K.
7550 lazy_stub
= n64
? lazy_stub_normal_2_n64
: lazy_stub_normal_2
;
7552 // Dynsym index is less than 32K.
7553 lazy_stub
= n64
? lazy_stub_normal_1_n64
: lazy_stub_normal_1
;
7556 lazy_stub
= n64
? lazy_stub_big_n64
: lazy_stub_big
;
7559 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7560 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 1]);
7566 // LUI instruction of the big stub. Paste high 16 bits of the
7568 elfcpp::Swap
<32, big_endian
>::writeval(pov
,
7569 lazy_stub
[i
] | ((sym
->dynsym_index() >> 16) & 0x7fff));
7573 elfcpp::Swap
<32, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7574 // Last stub instruction. Paste low 16 bits of the dynsym index.
7575 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4,
7576 lazy_stub
[i
+ 1] | (sym
->dynsym_index() & 0xffff));
7579 else if (this->target_
->use_32bit_micromips_instructions())
7581 // Write microMIPS stub in insn32 mode.
7584 if (sym
->dynsym_index() & ~0x7fff)
7585 // Dynsym index is between 32K and 64K.
7586 lazy_stub
= n64
? lazy_stub_micromips32_normal_2_n64
7587 : lazy_stub_micromips32_normal_2
;
7589 // Dynsym index is less than 32K.
7590 lazy_stub
= n64
? lazy_stub_micromips32_normal_1_n64
7591 : lazy_stub_micromips32_normal_1
;
7594 lazy_stub
= n64
? lazy_stub_micromips32_big_n64
7595 : lazy_stub_micromips32_big
;
7598 // First stub instruction. We emit 32-bit microMIPS instructions by
7599 // emitting two 16-bit parts because on microMIPS the 16-bit part of
7600 // the instruction where the opcode is must always come first, for
7601 // both little and big endian.
7602 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7603 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7604 // Second stub instruction.
7605 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7606 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6, lazy_stub
[i
+ 3]);
7611 // LUI instruction of the big stub. Paste high 16 bits of the
7613 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7614 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7615 (sym
->dynsym_index() >> 16) & 0x7fff);
7619 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7620 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7621 // Last stub instruction. Paste low 16 bits of the dynsym index.
7622 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7623 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 6,
7624 sym
->dynsym_index() & 0xffff);
7629 // Write microMIPS stub.
7632 if (sym
->dynsym_index() & ~0x7fff)
7633 // Dynsym index is between 32K and 64K.
7634 lazy_stub
= n64
? lazy_stub_micromips_normal_2_n64
7635 : lazy_stub_micromips_normal_2
;
7637 // Dynsym index is less than 32K.
7638 lazy_stub
= n64
? lazy_stub_micromips_normal_1_n64
7639 : lazy_stub_micromips_normal_1
;
7642 lazy_stub
= n64
? lazy_stub_micromips_big_n64
7643 : lazy_stub_micromips_big
;
7646 // First stub instruction. We emit 32-bit microMIPS instructions by
7647 // emitting two 16-bit parts because on microMIPS the 16-bit part of
7648 // the instruction where the opcode is must always come first, for
7649 // both little and big endian.
7650 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7651 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7652 // Second stub instruction.
7653 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4, lazy_stub
[i
+ 2]);
7658 // LUI instruction of the big stub. Paste high 16 bits of the
7660 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7661 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2,
7662 (sym
->dynsym_index() >> 16) & 0x7fff);
7666 elfcpp::Swap
<16, big_endian
>::writeval(pov
, lazy_stub
[i
]);
7667 // Last stub instruction. Paste low 16 bits of the dynsym index.
7668 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 2, lazy_stub
[i
+ 1]);
7669 elfcpp::Swap
<16, big_endian
>::writeval(pov
+ 4,
7670 sym
->dynsym_index() & 0xffff);
7675 // We always allocate 20 bytes for every stub, because final dynsym count is
7676 // not known in method do_finalize_sections. There are 4 unused bytes per
7677 // stub if final dynsym count is less than 0x10000.
7678 unsigned int used
= pov
- oview
;
7679 unsigned int unused
= big_stub
? 0 : this->symbols_
.size() * 4;
7680 gold_assert(static_cast<section_size_type
>(used
+ unused
) == oview_size
);
7682 // Fill the unused space with zeroes.
7683 // TODO(sasa): Can we strip unused bytes during the relaxation?
7685 memset(pov
, 0, unused
);
7687 of
->write_output_view(offset
, oview_size
, oview
);
7690 // Mips_output_section_reginfo methods.
7692 template<int size
, bool big_endian
>
7694 Mips_output_section_reginfo
<size
, big_endian
>::do_write(Output_file
* of
)
7696 off_t offset
= this->offset();
7697 off_t data_size
= this->data_size();
7699 unsigned char* view
= of
->get_output_view(offset
, data_size
);
7700 elfcpp::Swap
<size
, big_endian
>::writeval(view
, this->gprmask_
);
7701 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 4, this->cprmask1_
);
7702 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 8, this->cprmask2_
);
7703 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 12, this->cprmask3_
);
7704 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 16, this->cprmask4_
);
7705 // Write the gp value.
7706 elfcpp::Swap
<size
, big_endian
>::writeval(view
+ 20,
7707 this->target_
->gp_value());
7709 of
->write_output_view(offset
, data_size
, view
);
7712 // Mips_copy_relocs methods.
7714 // Emit any saved relocs.
7716 template<int sh_type
, int size
, bool big_endian
>
7718 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_mips(
7719 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
7720 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
7722 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
7723 Copy_reloc_entries::iterator p
= this->entries_
.begin();
7724 p
!= this->entries_
.end();
7726 emit_entry(*p
, reloc_section
, symtab
, layout
, target
);
7728 // We no longer need the saved information.
7729 this->entries_
.clear();
7732 // Emit the reloc if appropriate.
7734 template<int sh_type
, int size
, bool big_endian
>
7736 Mips_copy_relocs
<sh_type
, size
, big_endian
>::emit_entry(
7737 Copy_reloc_entry
& entry
,
7738 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
,
7739 Symbol_table
* symtab
, Layout
* layout
, Target_mips
<size
, big_endian
>* target
)
7741 // If the symbol is no longer defined in a dynamic object, then we
7742 // emitted a COPY relocation, and we do not want to emit this
7743 // dynamic relocation.
7744 if (!entry
.sym_
->is_from_dynobj())
7747 bool can_make_dynamic
= (entry
.reloc_type_
== elfcpp::R_MIPS_32
7748 || entry
.reloc_type_
== elfcpp::R_MIPS_REL32
7749 || entry
.reloc_type_
== elfcpp::R_MIPS_64
);
7751 Mips_symbol
<size
>* sym
= Mips_symbol
<size
>::as_mips_sym(entry
.sym_
);
7752 if (can_make_dynamic
&& !sym
->has_static_relocs())
7754 Mips_relobj
<size
, big_endian
>* object
=
7755 Mips_relobj
<size
, big_endian
>::as_mips_relobj(entry
.relobj_
);
7756 target
->got_section(symtab
, layout
)->record_global_got_symbol(
7757 sym
, object
, entry
.reloc_type_
, true, false);
7758 if (!symbol_references_local(sym
, sym
->should_add_dynsym_entry(symtab
)))
7759 target
->rel_dyn_section(layout
)->add_global(sym
, elfcpp::R_MIPS_REL32
,
7760 entry
.output_section_
, entry
.relobj_
, entry
.shndx_
, entry
.address_
);
7762 target
->rel_dyn_section(layout
)->add_symbolless_global_addend(
7763 sym
, elfcpp::R_MIPS_REL32
, entry
.output_section_
, entry
.relobj_
,
7764 entry
.shndx_
, entry
.address_
);
7767 this->make_copy_reloc(symtab
, layout
,
7768 static_cast<Sized_symbol
<size
>*>(entry
.sym_
),
7773 // Target_mips methods.
7775 // Return the value to use for a dynamic symbol which requires special
7776 // treatment. This is how we support equality comparisons of function
7777 // pointers across shared library boundaries, as described in the
7778 // processor specific ABI supplement.
7780 template<int size
, bool big_endian
>
7782 Target_mips
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
7785 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
7787 if (!mips_sym
->has_lazy_stub())
7789 if (mips_sym
->has_plt_offset())
7791 // We distinguish between PLT entries and lazy-binding stubs by
7792 // giving the former an st_other value of STO_MIPS_PLT. Set the
7793 // value to the stub address if there are any relocations in the
7794 // binary where pointer equality matters.
7795 if (mips_sym
->pointer_equality_needed())
7797 // Prefer a standard MIPS PLT entry.
7798 if (mips_sym
->has_mips_plt_offset())
7799 value
= this->plt_section()->mips_entry_address(mips_sym
);
7801 value
= this->plt_section()->comp_entry_address(mips_sym
) + 1;
7809 // First, set stub offsets for symbols. This method expects that the
7810 // number of entries in dynamic symbol table is set.
7811 this->mips_stubs_section()->set_lazy_stub_offsets();
7813 // The run-time linker uses the st_value field of the symbol
7814 // to reset the global offset table entry for this external
7815 // to its stub address when unlinking a shared object.
7816 value
= this->mips_stubs_section()->stub_address(mips_sym
);
7819 if (mips_sym
->has_mips16_fn_stub())
7821 // If we have a MIPS16 function with a stub, the dynamic symbol must
7822 // refer to the stub, since only the stub uses the standard calling
7824 value
= mips_sym
->template
7825 get_mips16_fn_stub
<big_endian
>()->output_address();
7831 // Get the dynamic reloc section, creating it if necessary. It's always
7832 // .rel.dyn, even for MIPS64.
7834 template<int size
, bool big_endian
>
7835 typename Target_mips
<size
, big_endian
>::Reloc_section
*
7836 Target_mips
<size
, big_endian
>::rel_dyn_section(Layout
* layout
)
7838 if (this->rel_dyn_
== NULL
)
7840 gold_assert(layout
!= NULL
);
7841 this->rel_dyn_
= new Reloc_section(parameters
->options().combreloc());
7842 layout
->add_output_section_data(".rel.dyn", elfcpp::SHT_REL
,
7843 elfcpp::SHF_ALLOC
, this->rel_dyn_
,
7844 ORDER_DYNAMIC_RELOCS
, false);
7846 // First entry in .rel.dyn has to be null.
7847 // This is hack - we define dummy output data and set its address to 0,
7848 // and define absolute R_MIPS_NONE relocation with offset 0 against it.
7849 // This ensures that the entry is null.
7850 Output_data
* od
= new Output_data_zero_fill(0, 0);
7852 this->rel_dyn_
->add_absolute(elfcpp::R_MIPS_NONE
, od
, 0);
7854 return this->rel_dyn_
;
7857 // Get the GOT section, creating it if necessary.
7859 template<int size
, bool big_endian
>
7860 Mips_output_data_got
<size
, big_endian
>*
7861 Target_mips
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
7864 if (this->got_
== NULL
)
7866 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
7868 this->got_
= new Mips_output_data_got
<size
, big_endian
>(this, symtab
,
7870 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
7871 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
|
7872 elfcpp::SHF_MIPS_GPREL
),
7873 this->got_
, ORDER_DATA
, false);
7875 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
7876 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
7877 Symbol_table::PREDEFINED
,
7879 0, 0, elfcpp::STT_OBJECT
,
7881 elfcpp::STV_DEFAULT
, 0,
7888 // Calculate value of _gp symbol.
7890 template<int size
, bool big_endian
>
7892 Target_mips
<size
, big_endian
>::set_gp(Layout
* layout
, Symbol_table
* symtab
)
7894 if (this->gp_
!= NULL
)
7897 Output_data
* section
= layout
->find_output_section(".got");
7898 if (section
== NULL
)
7900 // If there is no .got section, gp should be based on .sdata.
7901 // TODO(sasa): This is probably not needed. This was needed for older
7902 // MIPS architectures which accessed both GOT and .sdata section using
7903 // gp-relative addressing. Modern Mips Linux ELF architectures don't
7904 // access .sdata using gp-relative addressing.
7905 for (Layout::Section_list::const_iterator
7906 p
= layout
->section_list().begin();
7907 p
!= layout
->section_list().end();
7910 if (strcmp((*p
)->name(), ".sdata") == 0)
7918 Sized_symbol
<size
>* gp
=
7919 static_cast<Sized_symbol
<size
>*>(symtab
->lookup("_gp"));
7922 if (gp
->source() != Symbol::IS_CONSTANT
&& section
!= NULL
)
7923 gp
->init_output_data(gp
->name(), NULL
, section
, MIPS_GP_OFFSET
, 0,
7926 elfcpp::STV_DEFAULT
, 0,
7930 else if (section
!= NULL
)
7932 gp
= static_cast<Sized_symbol
<size
>*>(symtab
->define_in_output_data(
7933 "_gp", NULL
, Symbol_table::PREDEFINED
,
7934 section
, MIPS_GP_OFFSET
, 0,
7937 elfcpp::STV_DEFAULT
,
7943 // Set the dynamic symbol indexes. INDEX is the index of the first
7944 // global dynamic symbol. Pointers to the symbols are stored into the
7945 // vector SYMS. The names are added to DYNPOOL. This returns an
7946 // updated dynamic symbol index.
7948 template<int size
, bool big_endian
>
7950 Target_mips
<size
, big_endian
>::do_set_dynsym_indexes(
7951 std::vector
<Symbol
*>* dyn_symbols
, unsigned int index
,
7952 std::vector
<Symbol
*>* syms
, Stringpool
* dynpool
,
7953 Versions
* versions
, Symbol_table
* symtab
) const
7955 std::vector
<Symbol
*> non_got_symbols
;
7956 std::vector
<Symbol
*> got_symbols
;
7958 reorder_dyn_symbols
<size
, big_endian
>(dyn_symbols
, &non_got_symbols
,
7961 for (std::vector
<Symbol
*>::iterator p
= non_got_symbols
.begin();
7962 p
!= non_got_symbols
.end();
7967 // Note that SYM may already have a dynamic symbol index, since
7968 // some symbols appear more than once in the symbol table, with
7969 // and without a version.
7971 if (!sym
->has_dynsym_index())
7973 sym
->set_dynsym_index(index
);
7975 syms
->push_back(sym
);
7976 dynpool
->add(sym
->name(), false, NULL
);
7978 // Record any version information.
7979 if (sym
->version() != NULL
)
7980 versions
->record_version(symtab
, dynpool
, sym
);
7982 // If the symbol is defined in a dynamic object and is
7983 // referenced in a regular object, then mark the dynamic
7984 // object as needed. This is used to implement --as-needed.
7985 if (sym
->is_from_dynobj() && sym
->in_reg())
7986 sym
->object()->set_is_needed();
7990 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
7991 p
!= got_symbols
.end();
7995 if (!sym
->has_dynsym_index())
7997 // Record any version information.
7998 if (sym
->version() != NULL
)
7999 versions
->record_version(symtab
, dynpool
, sym
);
8003 index
= versions
->finalize(symtab
, index
, syms
);
8005 int got_sym_count
= 0;
8006 for (std::vector
<Symbol
*>::iterator p
= got_symbols
.begin();
8007 p
!= got_symbols
.end();
8012 if (!sym
->has_dynsym_index())
8015 sym
->set_dynsym_index(index
);
8017 syms
->push_back(sym
);
8018 dynpool
->add(sym
->name(), false, NULL
);
8020 // If the symbol is defined in a dynamic object and is
8021 // referenced in a regular object, then mark the dynamic
8022 // object as needed. This is used to implement --as-needed.
8023 if (sym
->is_from_dynobj() && sym
->in_reg())
8024 sym
->object()->set_is_needed();
8028 // Set index of the first symbol that has .got entry.
8029 this->got_
->set_first_global_got_dynsym_index(
8030 got_sym_count
> 0 ? index
- got_sym_count
: -1U);
8032 if (this->mips_stubs_
!= NULL
)
8033 this->mips_stubs_
->set_dynsym_count(index
);
8038 // Create a PLT entry for a global symbol referenced by r_type relocation.
8040 template<int size
, bool big_endian
>
8042 Target_mips
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
8044 Mips_symbol
<size
>* gsym
,
8045 unsigned int r_type
)
8047 if (gsym
->has_lazy_stub() || gsym
->has_plt_offset())
8050 if (this->plt_
== NULL
)
8052 // Create the GOT section first.
8053 this->got_section(symtab
, layout
);
8055 this->got_plt_
= new Output_data_space(4, "** GOT PLT");
8056 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
8057 (elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
),
8058 this->got_plt_
, ORDER_DATA
, false);
8060 // The first two entries are reserved.
8061 this->got_plt_
->set_current_data_size(2 * size
/8);
8063 this->plt_
= new Mips_output_data_plt
<size
, big_endian
>(layout
,
8066 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
8068 | elfcpp::SHF_EXECINSTR
),
8069 this->plt_
, ORDER_PLT
, false);
8072 this->plt_
->add_entry(gsym
, r_type
);
8076 // Get the .MIPS.stubs section, creating it if necessary.
8078 template<int size
, bool big_endian
>
8079 Mips_output_data_mips_stubs
<size
, big_endian
>*
8080 Target_mips
<size
, big_endian
>::mips_stubs_section(Layout
* layout
)
8082 if (this->mips_stubs_
== NULL
)
8085 new Mips_output_data_mips_stubs
<size
, big_endian
>(this);
8086 layout
->add_output_section_data(".MIPS.stubs", elfcpp::SHT_PROGBITS
,
8088 | elfcpp::SHF_EXECINSTR
),
8089 this->mips_stubs_
, ORDER_PLT
, false);
8091 return this->mips_stubs_
;
8094 // Get the LA25 stub section, creating it if necessary.
8096 template<int size
, bool big_endian
>
8097 Mips_output_data_la25_stub
<size
, big_endian
>*
8098 Target_mips
<size
, big_endian
>::la25_stub_section(Layout
* layout
)
8100 if (this->la25_stub_
== NULL
)
8102 this->la25_stub_
= new Mips_output_data_la25_stub
<size
, big_endian
>();
8103 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
8105 | elfcpp::SHF_EXECINSTR
),
8106 this->la25_stub_
, ORDER_TEXT
, false);
8108 return this->la25_stub_
;
8111 // Process the relocations to determine unreferenced sections for
8112 // garbage collection.
8114 template<int size
, bool big_endian
>
8116 Target_mips
<size
, big_endian
>::gc_process_relocs(
8117 Symbol_table
* symtab
,
8119 Sized_relobj_file
<size
, big_endian
>* object
,
8120 unsigned int data_shndx
,
8121 unsigned int sh_type
,
8122 const unsigned char* prelocs
,
8124 Output_section
* output_section
,
8125 bool needs_special_offset_handling
,
8126 size_t local_symbol_count
,
8127 const unsigned char* plocal_symbols
)
8129 typedef Target_mips
<size
, big_endian
> Mips
;
8131 if (sh_type
== elfcpp::SHT_REL
)
8133 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8136 gold::gc_process_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8145 needs_special_offset_handling
,
8149 else if (sh_type
== elfcpp::SHT_RELA
)
8151 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8154 gold::gc_process_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8163 needs_special_offset_handling
,
8171 // Scan relocations for a section.
8173 template<int size
, bool big_endian
>
8175 Target_mips
<size
, big_endian
>::scan_relocs(
8176 Symbol_table
* symtab
,
8178 Sized_relobj_file
<size
, big_endian
>* object
,
8179 unsigned int data_shndx
,
8180 unsigned int sh_type
,
8181 const unsigned char* prelocs
,
8183 Output_section
* output_section
,
8184 bool needs_special_offset_handling
,
8185 size_t local_symbol_count
,
8186 const unsigned char* plocal_symbols
)
8188 typedef Target_mips
<size
, big_endian
> Mips
;
8190 if (sh_type
== elfcpp::SHT_REL
)
8192 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8195 gold::scan_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8204 needs_special_offset_handling
,
8208 else if (sh_type
== elfcpp::SHT_RELA
)
8210 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8213 gold::scan_relocs
<size
, big_endian
, Mips
, Scan
, Classify_reloc
>(
8222 needs_special_offset_handling
,
8228 template<int size
, bool big_endian
>
8230 Target_mips
<size
, big_endian
>::mips_32bit_flags(elfcpp::Elf_Word flags
)
8232 return ((flags
& elfcpp::EF_MIPS_32BITMODE
) != 0
8233 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_O32
8234 || (flags
& elfcpp::EF_MIPS_ABI
) == elfcpp::E_MIPS_ABI_EABI32
8235 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_1
8236 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_2
8237 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32
8238 || (flags
& elfcpp::EF_MIPS_ARCH
) == elfcpp::E_MIPS_ARCH_32R2
);
8241 // Return the MACH for a MIPS e_flags value.
8242 template<int size
, bool big_endian
>
8244 Target_mips
<size
, big_endian
>::elf_mips_mach(elfcpp::Elf_Word flags
)
8246 switch (flags
& elfcpp::EF_MIPS_MACH
)
8248 case elfcpp::E_MIPS_MACH_3900
:
8249 return mach_mips3900
;
8251 case elfcpp::E_MIPS_MACH_4010
:
8252 return mach_mips4010
;
8254 case elfcpp::E_MIPS_MACH_4100
:
8255 return mach_mips4100
;
8257 case elfcpp::E_MIPS_MACH_4111
:
8258 return mach_mips4111
;
8260 case elfcpp::E_MIPS_MACH_4120
:
8261 return mach_mips4120
;
8263 case elfcpp::E_MIPS_MACH_4650
:
8264 return mach_mips4650
;
8266 case elfcpp::E_MIPS_MACH_5400
:
8267 return mach_mips5400
;
8269 case elfcpp::E_MIPS_MACH_5500
:
8270 return mach_mips5500
;
8272 case elfcpp::E_MIPS_MACH_9000
:
8273 return mach_mips9000
;
8275 case elfcpp::E_MIPS_MACH_SB1
:
8276 return mach_mips_sb1
;
8278 case elfcpp::E_MIPS_MACH_LS2E
:
8279 return mach_mips_loongson_2e
;
8281 case elfcpp::E_MIPS_MACH_LS2F
:
8282 return mach_mips_loongson_2f
;
8284 case elfcpp::E_MIPS_MACH_LS3A
:
8285 return mach_mips_loongson_3a
;
8287 case elfcpp::E_MIPS_MACH_OCTEON2
:
8288 return mach_mips_octeon2
;
8290 case elfcpp::E_MIPS_MACH_OCTEON
:
8291 return mach_mips_octeon
;
8293 case elfcpp::E_MIPS_MACH_XLR
:
8294 return mach_mips_xlr
;
8297 switch (flags
& elfcpp::EF_MIPS_ARCH
)
8300 case elfcpp::E_MIPS_ARCH_1
:
8301 return mach_mips3000
;
8303 case elfcpp::E_MIPS_ARCH_2
:
8304 return mach_mips6000
;
8306 case elfcpp::E_MIPS_ARCH_3
:
8307 return mach_mips4000
;
8309 case elfcpp::E_MIPS_ARCH_4
:
8310 return mach_mips8000
;
8312 case elfcpp::E_MIPS_ARCH_5
:
8315 case elfcpp::E_MIPS_ARCH_32
:
8316 return mach_mipsisa32
;
8318 case elfcpp::E_MIPS_ARCH_64
:
8319 return mach_mipsisa64
;
8321 case elfcpp::E_MIPS_ARCH_32R2
:
8322 return mach_mipsisa32r2
;
8324 case elfcpp::E_MIPS_ARCH_64R2
:
8325 return mach_mipsisa64r2
;
8332 // Check whether machine EXTENSION is an extension of machine BASE.
8333 template<int size
, bool big_endian
>
8335 Target_mips
<size
, big_endian
>::mips_mach_extends(unsigned int base
,
8336 unsigned int extension
)
8338 if (extension
== base
)
8341 if ((base
== mach_mipsisa32
)
8342 && this->mips_mach_extends(mach_mipsisa64
, extension
))
8345 if ((base
== mach_mipsisa32r2
)
8346 && this->mips_mach_extends(mach_mipsisa64r2
, extension
))
8349 for (unsigned int i
= 0; i
< this->mips_mach_extensions_
.size(); ++i
)
8350 if (extension
== this->mips_mach_extensions_
[i
].first
)
8352 extension
= this->mips_mach_extensions_
[i
].second
;
8353 if (extension
== base
)
8360 template<int size
, bool big_endian
>
8362 Target_mips
<size
, big_endian
>::merge_processor_specific_flags(
8363 const std::string
& name
, elfcpp::Elf_Word in_flags
, bool dyn_obj
)
8365 // If flags are not set yet, just copy them.
8366 if (!this->are_processor_specific_flags_set())
8368 this->set_processor_specific_flags(in_flags
);
8369 this->mach_
= this->elf_mips_mach(in_flags
);
8373 elfcpp::Elf_Word new_flags
= in_flags
;
8374 elfcpp::Elf_Word old_flags
= this->processor_specific_flags();
8375 elfcpp::Elf_Word merged_flags
= this->processor_specific_flags();
8376 merged_flags
|= new_flags
& elfcpp::EF_MIPS_NOREORDER
;
8378 // Check flag compatibility.
8379 new_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
8380 old_flags
&= ~elfcpp::EF_MIPS_NOREORDER
;
8382 // Some IRIX 6 BSD-compatibility objects have this bit set. It
8383 // doesn't seem to matter.
8384 new_flags
&= ~elfcpp::EF_MIPS_XGOT
;
8385 old_flags
&= ~elfcpp::EF_MIPS_XGOT
;
8387 // MIPSpro generates ucode info in n64 objects. Again, we should
8388 // just be able to ignore this.
8389 new_flags
&= ~elfcpp::EF_MIPS_UCODE
;
8390 old_flags
&= ~elfcpp::EF_MIPS_UCODE
;
8392 // DSOs should only be linked with CPIC code.
8394 new_flags
|= elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
;
8396 if (new_flags
== old_flags
)
8398 this->set_processor_specific_flags(merged_flags
);
8402 if (((new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0)
8403 != ((old_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
)) != 0))
8404 gold_warning(_("%s: linking abicalls files with non-abicalls files"),
8407 if (new_flags
& (elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
))
8408 merged_flags
|= elfcpp::EF_MIPS_CPIC
;
8409 if (!(new_flags
& elfcpp::EF_MIPS_PIC
))
8410 merged_flags
&= ~elfcpp::EF_MIPS_PIC
;
8412 new_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
8413 old_flags
&= ~(elfcpp::EF_MIPS_PIC
| elfcpp::EF_MIPS_CPIC
);
8415 // Compare the ISAs.
8416 if (mips_32bit_flags(old_flags
) != mips_32bit_flags(new_flags
))
8417 gold_error(_("%s: linking 32-bit code with 64-bit code"), name
.c_str());
8418 else if (!this->mips_mach_extends(this->elf_mips_mach(in_flags
), this->mach_
))
8420 // Output ISA isn't the same as, or an extension of, input ISA.
8421 if (this->mips_mach_extends(this->mach_
, this->elf_mips_mach(in_flags
)))
8423 // Copy the architecture info from input object to output. Also copy
8424 // the 32-bit flag (if set) so that we continue to recognise
8425 // output as a 32-bit binary.
8426 this->mach_
= this->elf_mips_mach(in_flags
);
8427 merged_flags
&= ~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
);
8428 merged_flags
|= (new_flags
& (elfcpp::EF_MIPS_ARCH
8429 | elfcpp::EF_MIPS_MACH
| elfcpp::EF_MIPS_32BITMODE
));
8431 // Copy across the ABI flags if output doesn't use them
8432 // and if that was what caused us to treat input object as 32-bit.
8433 if ((old_flags
& elfcpp::EF_MIPS_ABI
) == 0
8434 && this->mips_32bit_flags(new_flags
)
8435 && !this->mips_32bit_flags(new_flags
& ~elfcpp::EF_MIPS_ABI
))
8436 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ABI
;
8439 // The ISAs aren't compatible.
8440 gold_error(_("%s: linking %s module with previous %s modules"),
8441 name
.c_str(), this->elf_mips_mach_name(in_flags
),
8442 this->elf_mips_mach_name(merged_flags
));
8445 new_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
8446 | elfcpp::EF_MIPS_32BITMODE
));
8447 old_flags
&= (~(elfcpp::EF_MIPS_ARCH
| elfcpp::EF_MIPS_MACH
8448 | elfcpp::EF_MIPS_32BITMODE
));
8451 if ((new_flags
& elfcpp::EF_MIPS_ABI
) != (old_flags
& elfcpp::EF_MIPS_ABI
))
8453 // Only error if both are set (to different values).
8454 if ((new_flags
& elfcpp::EF_MIPS_ABI
)
8455 && (old_flags
& elfcpp::EF_MIPS_ABI
))
8456 gold_error(_("%s: ABI mismatch: linking %s module with "
8457 "previous %s modules"), name
.c_str(),
8458 this->elf_mips_abi_name(in_flags
),
8459 this->elf_mips_abi_name(merged_flags
));
8461 new_flags
&= ~elfcpp::EF_MIPS_ABI
;
8462 old_flags
&= ~elfcpp::EF_MIPS_ABI
;
8465 // Compare ASEs. Forbid linking MIPS16 and microMIPS ASE modules together
8466 // and allow arbitrary mixing of the remaining ASEs (retain the union).
8467 if ((new_flags
& elfcpp::EF_MIPS_ARCH_ASE
)
8468 != (old_flags
& elfcpp::EF_MIPS_ARCH_ASE
))
8470 int old_micro
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
8471 int new_micro
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_MICROMIPS
;
8472 int old_m16
= old_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
8473 int new_m16
= new_flags
& elfcpp::EF_MIPS_ARCH_ASE_M16
;
8474 int micro_mis
= old_m16
&& new_micro
;
8475 int m16_mis
= old_micro
&& new_m16
;
8477 if (m16_mis
|| micro_mis
)
8478 gold_error(_("%s: ASE mismatch: linking %s module with "
8479 "previous %s modules"), name
.c_str(),
8480 m16_mis
? "MIPS16" : "microMIPS",
8481 m16_mis
? "microMIPS" : "MIPS16");
8483 merged_flags
|= new_flags
& elfcpp::EF_MIPS_ARCH_ASE
;
8485 new_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
8486 old_flags
&= ~ elfcpp::EF_MIPS_ARCH_ASE
;
8489 // Warn about any other mismatches.
8490 if (new_flags
!= old_flags
)
8491 gold_error(_("%s: uses different e_flags (0x%x) fields than previous "
8492 "modules (0x%x)"), name
.c_str(), new_flags
, old_flags
);
8494 this->set_processor_specific_flags(merged_flags
);
8497 // Adjust ELF file header.
8499 template<int size
, bool big_endian
>
8501 Target_mips
<size
, big_endian
>::do_adjust_elf_header(
8502 unsigned char* view
,
8505 gold_assert(len
== elfcpp::Elf_sizes
<size
>::ehdr_size
);
8507 if (!this->entry_symbol_is_compressed_
)
8510 elfcpp::Ehdr
<size
, big_endian
> ehdr(view
);
8511 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
8513 oehdr
.put_e_entry(ehdr
.get_e_entry() + 1);
8516 // do_make_elf_object to override the same function in the base class.
8517 // We need to use a target-specific sub-class of
8518 // Sized_relobj_file<size, big_endian> to store Mips specific information.
8519 // Hence we need to have our own ELF object creation.
8521 template<int size
, bool big_endian
>
8523 Target_mips
<size
, big_endian
>::do_make_elf_object(
8524 const std::string
& name
,
8525 Input_file
* input_file
,
8526 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
8528 int et
= ehdr
.get_e_type();
8529 // ET_EXEC files are valid input for --just-symbols/-R,
8530 // and we treat them as relocatable objects.
8531 if (et
== elfcpp::ET_REL
8532 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
8534 Mips_relobj
<size
, big_endian
>* obj
=
8535 new Mips_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
8539 else if (et
== elfcpp::ET_DYN
)
8541 // TODO(sasa): Should we create Mips_dynobj?
8542 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
8546 gold_error(_("%s: unsupported ELF file type %d"),
8552 // Finalize the sections.
8554 template <int size
, bool big_endian
>
8556 Target_mips
<size
, big_endian
>::do_finalize_sections(Layout
* layout
,
8557 const Input_objects
* input_objects
,
8558 Symbol_table
* symtab
)
8560 // Add +1 to MIPS16 and microMIPS init_ and _fini symbols so that DT_INIT and
8561 // DT_FINI have correct values.
8562 Mips_symbol
<size
>* init
= static_cast<Mips_symbol
<size
>*>(
8563 symtab
->lookup(parameters
->options().init()));
8564 if (init
!= NULL
&& (init
->is_mips16() || init
->is_micromips()))
8565 init
->set_value(init
->value() | 1);
8566 Mips_symbol
<size
>* fini
= static_cast<Mips_symbol
<size
>*>(
8567 symtab
->lookup(parameters
->options().fini()));
8568 if (fini
!= NULL
&& (fini
->is_mips16() || fini
->is_micromips()))
8569 fini
->set_value(fini
->value() | 1);
8571 // Check whether the entry symbol is mips16 or micromips. This is needed to
8572 // adjust entry address in ELF header.
8573 Mips_symbol
<size
>* entry
=
8574 static_cast<Mips_symbol
<size
>*>(symtab
->lookup(this->entry_symbol_name()));
8575 this->entry_symbol_is_compressed_
= (entry
!= NULL
&& (entry
->is_mips16()
8576 || entry
->is_micromips()));
8578 if (!parameters
->doing_static_link()
8579 && (strcmp(parameters
->options().hash_style(), "gnu") == 0
8580 || strcmp(parameters
->options().hash_style(), "both") == 0))
8582 // .gnu.hash and the MIPS ABI require .dynsym to be sorted in different
8583 // ways. .gnu.hash needs symbols to be grouped by hash code whereas the
8584 // MIPS ABI requires a mapping between the GOT and the symbol table.
8585 gold_error(".gnu.hash is incompatible with the MIPS ABI");
8588 // Check whether the final section that was scanned has HI16 or GOT16
8589 // relocations without the corresponding LO16 part.
8590 if (this->got16_addends_
.size() > 0)
8591 gold_error("Can't find matching LO16 reloc");
8594 this->set_gp(layout
, symtab
);
8596 // Check for any mips16 stub sections that we can discard.
8597 if (!parameters
->options().relocatable())
8599 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8600 p
!= input_objects
->relobj_end();
8603 Mips_relobj
<size
, big_endian
>* object
=
8604 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
8605 object
->discard_mips16_stub_sections(symtab
);
8609 // Merge processor-specific flags.
8610 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8611 p
!= input_objects
->relobj_end();
8614 Mips_relobj
<size
, big_endian
>* relobj
=
8615 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
8617 Input_file::Format format
= relobj
->input_file()->format();
8618 if (format
== Input_file::FORMAT_ELF
)
8620 // Read processor-specific flags in ELF file header.
8621 const unsigned char* pehdr
= relobj
->get_view(
8622 elfcpp::file_header_offset
,
8623 elfcpp::Elf_sizes
<size
>::ehdr_size
,
8626 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
8627 elfcpp::Elf_Word in_flags
= ehdr
.get_e_flags();
8628 // If all input sections will be discarded, don't use this object
8629 // file for merging processor specific flags.
8630 bool should_merge_processor_specific_flags
= false;
8632 for (unsigned int i
= 1; i
< relobj
->shnum(); ++i
)
8633 if (relobj
->output_section(i
) != NULL
)
8635 should_merge_processor_specific_flags
= true;
8639 if (should_merge_processor_specific_flags
)
8640 this->merge_processor_specific_flags(relobj
->name(), in_flags
,
8645 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
8646 p
!= input_objects
->dynobj_end();
8649 Sized_dynobj
<size
, big_endian
>* dynobj
=
8650 static_cast<Sized_dynobj
<size
, big_endian
>*>(*p
);
8652 // Read processor-specific flags.
8653 const unsigned char* pehdr
= dynobj
->get_view(elfcpp::file_header_offset
,
8654 elfcpp::Elf_sizes
<size
>::ehdr_size
,
8657 elfcpp::Ehdr
<size
, big_endian
> ehdr(pehdr
);
8658 elfcpp::Elf_Word in_flags
= ehdr
.get_e_flags();
8660 this->merge_processor_specific_flags(dynobj
->name(), in_flags
, true);
8663 // Merge .reginfo contents of input objects.
8664 Valtype gprmask
= 0;
8665 Valtype cprmask1
= 0;
8666 Valtype cprmask2
= 0;
8667 Valtype cprmask3
= 0;
8668 Valtype cprmask4
= 0;
8669 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
8670 p
!= input_objects
->relobj_end();
8673 Mips_relobj
<size
, big_endian
>* relobj
=
8674 Mips_relobj
<size
, big_endian
>::as_mips_relobj(*p
);
8676 gprmask
|= relobj
->gprmask();
8677 cprmask1
|= relobj
->cprmask1();
8678 cprmask2
|= relobj
->cprmask2();
8679 cprmask3
|= relobj
->cprmask3();
8680 cprmask4
|= relobj
->cprmask4();
8683 if (this->plt_
!= NULL
)
8685 // Set final PLT offsets for symbols.
8686 this->plt_section()->set_plt_offsets();
8688 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
8689 // Set STO_MICROMIPS flag if the output has microMIPS code, but only if
8690 // there are no standard PLT entries present.
8691 unsigned char nonvis
= 0;
8692 if (this->is_output_micromips()
8693 && !this->plt_section()->has_standard_entries())
8694 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
8695 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
8696 Symbol_table::PREDEFINED
,
8698 0, 0, elfcpp::STT_FUNC
,
8700 elfcpp::STV_DEFAULT
, nonvis
,
8704 if (this->mips_stubs_
!= NULL
)
8706 // Define _MIPS_STUBS_ at the start of the .MIPS.stubs section.
8707 unsigned char nonvis
= 0;
8708 if (this->is_output_micromips())
8709 nonvis
= elfcpp::STO_MICROMIPS
>> 2;
8710 symtab
->define_in_output_data("_MIPS_STUBS_", NULL
,
8711 Symbol_table::PREDEFINED
,
8713 0, 0, elfcpp::STT_FUNC
,
8715 elfcpp::STV_DEFAULT
, nonvis
,
8719 if (!parameters
->options().relocatable() && !parameters
->doing_static_link())
8720 // In case there is no .got section, create one.
8721 this->got_section(symtab
, layout
);
8723 // Emit any relocs we saved in an attempt to avoid generating COPY
8725 if (this->copy_relocs_
.any_saved_relocs())
8726 this->copy_relocs_
.emit_mips(this->rel_dyn_section(layout
), symtab
, layout
,
8729 // Emit dynamic relocs.
8730 for (typename
std::vector
<Dyn_reloc
>::iterator p
= this->dyn_relocs_
.begin();
8731 p
!= this->dyn_relocs_
.end();
8733 p
->emit(this->rel_dyn_section(layout
), this->got_section(), symtab
);
8735 if (this->has_got_section())
8736 this->got_section()->lay_out_got(layout
, symtab
, input_objects
);
8738 if (this->mips_stubs_
!= NULL
)
8739 this->mips_stubs_
->set_needs_dynsym_value();
8741 // Check for functions that might need $25 to be valid on entry.
8742 // TODO(sasa): Can we do this without iterating over all symbols?
8743 typedef Symbol_visitor_check_symbols
<size
, big_endian
> Symbol_visitor
;
8744 symtab
->for_all_symbols
<size
, Symbol_visitor
>(Symbol_visitor(this, layout
,
8747 // Add NULL segment.
8748 if (!parameters
->options().relocatable())
8749 layout
->make_output_segment(elfcpp::PT_NULL
, 0);
8751 for (Layout::Section_list::const_iterator p
= layout
->section_list().begin();
8752 p
!= layout
->section_list().end();
8755 if ((*p
)->type() == elfcpp::SHT_MIPS_REGINFO
)
8757 Mips_output_section_reginfo
<size
, big_endian
>* reginfo
=
8758 Mips_output_section_reginfo
<size
, big_endian
>::
8759 as_mips_output_section_reginfo(*p
);
8761 reginfo
->set_masks(gprmask
, cprmask1
, cprmask2
, cprmask3
, cprmask4
);
8763 if (!parameters
->options().relocatable())
8765 Output_segment
* reginfo_segment
=
8766 layout
->make_output_segment(elfcpp::PT_MIPS_REGINFO
,
8768 reginfo_segment
->add_output_section_to_nonload(reginfo
,
8774 // Fill in some more dynamic tags.
8775 // TODO(sasa): Add more dynamic tags.
8776 const Reloc_section
* rel_plt
= (this->plt_
== NULL
8777 ? NULL
: this->plt_
->rel_plt());
8778 layout
->add_target_dynamic_tags(true, this->got_
, rel_plt
,
8779 this->rel_dyn_
, true, false);
8781 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
8783 && !parameters
->options().relocatable()
8784 && !parameters
->doing_static_link())
8787 // This element holds a 32-bit version id for the Runtime
8788 // Linker Interface. This will start at integer value 1.
8790 odyn
->add_constant(elfcpp::DT_MIPS_RLD_VERSION
, d_val
);
8793 d_val
= elfcpp::RHF_NOTPOT
;
8794 odyn
->add_constant(elfcpp::DT_MIPS_FLAGS
, d_val
);
8796 // Save layout for using when emiting custom dynamic tags.
8797 this->layout_
= layout
;
8799 // This member holds the base address of the segment.
8800 odyn
->add_custom(elfcpp::DT_MIPS_BASE_ADDRESS
);
8802 // This member holds the number of entries in the .dynsym section.
8803 odyn
->add_custom(elfcpp::DT_MIPS_SYMTABNO
);
8805 // This member holds the index of the first dynamic symbol
8806 // table entry that corresponds to an entry in the global offset table.
8807 odyn
->add_custom(elfcpp::DT_MIPS_GOTSYM
);
8809 // This member holds the number of local GOT entries.
8810 odyn
->add_constant(elfcpp::DT_MIPS_LOCAL_GOTNO
,
8811 this->got_
->get_local_gotno());
8813 if (this->plt_
!= NULL
)
8814 // DT_MIPS_PLTGOT dynamic tag
8815 odyn
->add_section_address(elfcpp::DT_MIPS_PLTGOT
, this->got_plt_
);
8819 // Get the custom dynamic tag value.
8820 template<int size
, bool big_endian
>
8822 Target_mips
<size
, big_endian
>::do_dynamic_tag_custom_value(elfcpp::DT tag
) const
8826 case elfcpp::DT_MIPS_BASE_ADDRESS
:
8828 // The base address of the segment.
8829 // At this point, the segment list has been sorted into final order,
8830 // so just return vaddr of the first readable PT_LOAD segment.
8831 Output_segment
* seg
=
8832 this->layout_
->find_output_segment(elfcpp::PT_LOAD
, elfcpp::PF_R
, 0);
8833 gold_assert(seg
!= NULL
);
8834 return seg
->vaddr();
8837 case elfcpp::DT_MIPS_SYMTABNO
:
8838 // The number of entries in the .dynsym section.
8839 return this->get_dt_mips_symtabno();
8841 case elfcpp::DT_MIPS_GOTSYM
:
8843 // The index of the first dynamic symbol table entry that corresponds
8844 // to an entry in the GOT.
8845 if (this->got_
->first_global_got_dynsym_index() != -1U)
8846 return this->got_
->first_global_got_dynsym_index();
8848 // In case if we don't have global GOT symbols we default to setting
8849 // DT_MIPS_GOTSYM to the same value as DT_MIPS_SYMTABNO.
8850 return this->get_dt_mips_symtabno();
8854 gold_error(_("Unknown dynamic tag 0x%x"), (unsigned int)tag
);
8857 return (unsigned int)-1;
8860 // Relocate section data.
8862 template<int size
, bool big_endian
>
8864 Target_mips
<size
, big_endian
>::relocate_section(
8865 const Relocate_info
<size
, big_endian
>* relinfo
,
8866 unsigned int sh_type
,
8867 const unsigned char* prelocs
,
8869 Output_section
* output_section
,
8870 bool needs_special_offset_handling
,
8871 unsigned char* view
,
8872 Mips_address address
,
8873 section_size_type view_size
,
8874 const Reloc_symbol_changes
* reloc_symbol_changes
)
8876 typedef Target_mips
<size
, big_endian
> Mips
;
8877 typedef typename Target_mips
<size
, big_endian
>::Relocate Mips_relocate
;
8879 if (sh_type
== elfcpp::SHT_REL
)
8881 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
8884 gold::relocate_section
<size
, big_endian
, Mips
, Mips_relocate
,
8885 gold::Default_comdat_behavior
, Classify_reloc
>(
8891 needs_special_offset_handling
,
8895 reloc_symbol_changes
);
8897 else if (sh_type
== elfcpp::SHT_RELA
)
8899 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8902 gold::relocate_section
<size
, big_endian
, Mips
, Mips_relocate
,
8903 gold::Default_comdat_behavior
, Classify_reloc
>(
8909 needs_special_offset_handling
,
8913 reloc_symbol_changes
);
8917 // Return the size of a relocation while scanning during a relocatable
8921 mips_get_size_for_reloc(unsigned int r_type
, Relobj
* object
)
8925 case elfcpp::R_MIPS_NONE
:
8926 case elfcpp::R_MIPS_TLS_DTPMOD64
:
8927 case elfcpp::R_MIPS_TLS_DTPREL64
:
8928 case elfcpp::R_MIPS_TLS_TPREL64
:
8931 case elfcpp::R_MIPS_32
:
8932 case elfcpp::R_MIPS_TLS_DTPMOD32
:
8933 case elfcpp::R_MIPS_TLS_DTPREL32
:
8934 case elfcpp::R_MIPS_TLS_TPREL32
:
8935 case elfcpp::R_MIPS_REL32
:
8936 case elfcpp::R_MIPS_PC32
:
8937 case elfcpp::R_MIPS_GPREL32
:
8938 case elfcpp::R_MIPS_JALR
:
8939 case elfcpp::R_MIPS_EH
:
8942 case elfcpp::R_MIPS_16
:
8943 case elfcpp::R_MIPS_HI16
:
8944 case elfcpp::R_MIPS_LO16
:
8945 case elfcpp::R_MIPS_GPREL16
:
8946 case elfcpp::R_MIPS16_HI16
:
8947 case elfcpp::R_MIPS16_LO16
:
8948 case elfcpp::R_MIPS_PC16
:
8949 case elfcpp::R_MIPS_GOT16
:
8950 case elfcpp::R_MIPS16_GOT16
:
8951 case elfcpp::R_MIPS_CALL16
:
8952 case elfcpp::R_MIPS16_CALL16
:
8953 case elfcpp::R_MIPS_GOT_HI16
:
8954 case elfcpp::R_MIPS_CALL_HI16
:
8955 case elfcpp::R_MIPS_GOT_LO16
:
8956 case elfcpp::R_MIPS_CALL_LO16
:
8957 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
8958 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
8959 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
8960 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
8961 case elfcpp::R_MIPS16_GPREL
:
8962 case elfcpp::R_MIPS_GOT_DISP
:
8963 case elfcpp::R_MIPS_LITERAL
:
8964 case elfcpp::R_MIPS_GOT_PAGE
:
8965 case elfcpp::R_MIPS_GOT_OFST
:
8966 case elfcpp::R_MIPS_TLS_GD
:
8967 case elfcpp::R_MIPS_TLS_LDM
:
8968 case elfcpp::R_MIPS_TLS_GOTTPREL
:
8971 // These relocations are not byte sized
8972 case elfcpp::R_MIPS_26
:
8973 case elfcpp::R_MIPS16_26
:
8976 case elfcpp::R_MIPS_COPY
:
8977 case elfcpp::R_MIPS_JUMP_SLOT
:
8978 object
->error(_("unexpected reloc %u in object file"), r_type
);
8982 object
->error(_("unsupported reloc %u in object file"), r_type
);
8987 // Scan the relocs during a relocatable link.
8989 template<int size
, bool big_endian
>
8991 Target_mips
<size
, big_endian
>::scan_relocatable_relocs(
8992 Symbol_table
* symtab
,
8994 Sized_relobj_file
<size
, big_endian
>* object
,
8995 unsigned int data_shndx
,
8996 unsigned int sh_type
,
8997 const unsigned char* prelocs
,
8999 Output_section
* output_section
,
9000 bool needs_special_offset_handling
,
9001 size_t local_symbol_count
,
9002 const unsigned char* plocal_symbols
,
9003 Relocatable_relocs
* rr
)
9005 if (sh_type
== elfcpp::SHT_REL
)
9007 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
9009 typedef Mips_scan_relocatable_relocs
<big_endian
, Classify_reloc
>
9010 Scan_relocatable_relocs
;
9012 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_relocatable_relocs
>(
9020 needs_special_offset_handling
,
9025 else if (sh_type
== elfcpp::SHT_RELA
)
9027 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9029 typedef Mips_scan_relocatable_relocs
<big_endian
, Classify_reloc
>
9030 Scan_relocatable_relocs
;
9032 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_relocatable_relocs
>(
9040 needs_special_offset_handling
,
9049 // Scan the relocs for --emit-relocs.
9051 template<int size
, bool big_endian
>
9053 Target_mips
<size
, big_endian
>::emit_relocs_scan(
9054 Symbol_table
* symtab
,
9056 Sized_relobj_file
<size
, big_endian
>* object
,
9057 unsigned int data_shndx
,
9058 unsigned int sh_type
,
9059 const unsigned char* prelocs
,
9061 Output_section
* output_section
,
9062 bool needs_special_offset_handling
,
9063 size_t local_symbol_count
,
9064 const unsigned char* plocal_syms
,
9065 Relocatable_relocs
* rr
)
9067 if (sh_type
== elfcpp::SHT_REL
)
9069 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
9071 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
9072 Emit_relocs_strategy
;
9074 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
9082 needs_special_offset_handling
,
9087 else if (sh_type
== elfcpp::SHT_RELA
)
9089 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9091 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
9092 Emit_relocs_strategy
;
9094 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
9102 needs_special_offset_handling
,
9111 // Emit relocations for a section.
9113 template<int size
, bool big_endian
>
9115 Target_mips
<size
, big_endian
>::relocate_relocs(
9116 const Relocate_info
<size
, big_endian
>* relinfo
,
9117 unsigned int sh_type
,
9118 const unsigned char* prelocs
,
9120 Output_section
* output_section
,
9121 typename
elfcpp::Elf_types
<size
>::Elf_Off
9122 offset_in_output_section
,
9123 unsigned char* view
,
9124 Mips_address view_address
,
9125 section_size_type view_size
,
9126 unsigned char* reloc_view
,
9127 section_size_type reloc_view_size
)
9129 if (sh_type
== elfcpp::SHT_REL
)
9131 typedef Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>
9134 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
9139 offset_in_output_section
,
9146 else if (sh_type
== elfcpp::SHT_RELA
)
9148 typedef Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9151 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
9156 offset_in_output_section
,
9167 // Perform target-specific processing in a relocatable link. This is
9168 // only used if we use the relocation strategy RELOC_SPECIAL.
9170 template<int size
, bool big_endian
>
9172 Target_mips
<size
, big_endian
>::relocate_special_relocatable(
9173 const Relocate_info
<size
, big_endian
>* relinfo
,
9174 unsigned int sh_type
,
9175 const unsigned char* preloc_in
,
9177 Output_section
* output_section
,
9178 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
9179 unsigned char* view
,
9180 Mips_address view_address
,
9182 unsigned char* preloc_out
)
9184 // We can only handle REL type relocation sections.
9185 gold_assert(sh_type
== elfcpp::SHT_REL
);
9187 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc
9189 typedef typename Reloc_types
<elfcpp::SHT_REL
, size
, big_endian
>::Reloc_write
9192 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
9194 const Mips_address invalid_address
= static_cast<Mips_address
>(0) - 1;
9196 Mips_relobj
<size
, big_endian
>* object
=
9197 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
9198 const unsigned int local_count
= object
->local_symbol_count();
9200 Reltype
reloc(preloc_in
);
9201 Reltype_write
reloc_write(preloc_out
);
9203 elfcpp::Elf_types
<32>::Elf_WXword r_info
= reloc
.get_r_info();
9204 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
9205 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
9207 // Get the new symbol index.
9208 // We only use RELOC_SPECIAL strategy in local relocations.
9209 gold_assert(r_sym
< local_count
);
9211 // We are adjusting a section symbol. We need to find
9212 // the symbol table index of the section symbol for
9213 // the output section corresponding to input section
9214 // in which this symbol is defined.
9216 unsigned int shndx
= object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
9217 gold_assert(is_ordinary
);
9218 Output_section
* os
= object
->output_section(shndx
);
9219 gold_assert(os
!= NULL
);
9220 gold_assert(os
->needs_symtab_index());
9221 unsigned int new_symndx
= os
->symtab_index();
9223 // Get the new offset--the location in the output section where
9224 // this relocation should be applied.
9226 Mips_address offset
= reloc
.get_r_offset();
9227 Mips_address new_offset
;
9228 if (offset_in_output_section
!= invalid_address
)
9229 new_offset
= offset
+ offset_in_output_section
;
9232 section_offset_type sot_offset
=
9233 convert_types
<section_offset_type
, Mips_address
>(offset
);
9234 section_offset_type new_sot_offset
=
9235 output_section
->output_offset(object
, relinfo
->data_shndx
,
9237 gold_assert(new_sot_offset
!= -1);
9238 new_offset
= new_sot_offset
;
9241 // In an object file, r_offset is an offset within the section.
9242 // In an executable or dynamic object, generated by
9243 // --emit-relocs, r_offset is an absolute address.
9244 if (!parameters
->options().relocatable())
9246 new_offset
+= view_address
;
9247 if (offset_in_output_section
!= invalid_address
)
9248 new_offset
-= offset_in_output_section
;
9251 reloc_write
.put_r_offset(new_offset
);
9252 reloc_write
.put_r_info(elfcpp::elf_r_info
<32>(new_symndx
, r_type
));
9254 // Handle the reloc addend.
9255 // The relocation uses a section symbol in the input file.
9256 // We are adjusting it to use a section symbol in the output
9257 // file. The input section symbol refers to some address in
9258 // the input section. We need the relocation in the output
9259 // file to refer to that same address. This adjustment to
9260 // the addend is the same calculation we use for a simple
9261 // absolute relocation for the input section symbol.
9262 Valtype calculated_value
= 0;
9263 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
9265 unsigned char* paddend
= view
+ offset
;
9266 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
9269 case elfcpp::R_MIPS_26
:
9270 reloc_status
= Reloc_funcs::rel26(paddend
, object
, psymval
,
9271 offset_in_output_section
, true, 0, sh_type
== elfcpp::SHT_REL
, NULL
,
9272 false /*TODO(sasa): cross mode jump*/, r_type
, this->jal_to_bal(),
9273 false, &calculated_value
);
9280 // Report any errors.
9281 switch (reloc_status
)
9283 case Reloc_funcs::STATUS_OKAY
:
9285 case Reloc_funcs::STATUS_OVERFLOW
:
9286 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
9287 _("relocation overflow"));
9289 case Reloc_funcs::STATUS_BAD_RELOC
:
9290 gold_error_at_location(relinfo
, relnum
, reloc
.get_r_offset(),
9291 _("unexpected opcode while processing relocation"));
9298 // Optimize the TLS relocation type based on what we know about the
9299 // symbol. IS_FINAL is true if the final address of this symbol is
9300 // known at link time.
9302 template<int size
, bool big_endian
>
9303 tls::Tls_optimization
9304 Target_mips
<size
, big_endian
>::optimize_tls_reloc(bool, int)
9306 // FIXME: Currently we do not do any TLS optimization.
9307 return tls::TLSOPT_NONE
;
9310 // Scan a relocation for a local symbol.
9312 template<int size
, bool big_endian
>
9314 Target_mips
<size
, big_endian
>::Scan::local(
9315 Symbol_table
* symtab
,
9317 Target_mips
<size
, big_endian
>* target
,
9318 Sized_relobj_file
<size
, big_endian
>* object
,
9319 unsigned int data_shndx
,
9320 Output_section
* output_section
,
9321 const Relatype
* rela
,
9323 unsigned int rel_type
,
9324 unsigned int r_type
,
9325 const elfcpp::Sym
<size
, big_endian
>& lsym
,
9331 Mips_address r_offset
;
9333 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
9335 if (rel_type
== elfcpp::SHT_RELA
)
9337 r_offset
= rela
->get_r_offset();
9338 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
9340 r_addend
= rela
->get_r_addend();
9344 r_offset
= rel
->get_r_offset();
9345 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
9350 Mips_relobj
<size
, big_endian
>* mips_obj
=
9351 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
9353 if (mips_obj
->is_mips16_stub_section(data_shndx
))
9355 mips_obj
->get_mips16_stub_section(data_shndx
)
9356 ->new_local_reloc_found(r_type
, r_sym
);
9359 if (r_type
== elfcpp::R_MIPS_NONE
)
9360 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
9364 if (!mips16_call_reloc(r_type
)
9365 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
9366 // This reloc would need to refer to a MIPS16 hard-float stub, if
9367 // there is one. We ignore MIPS16 stub sections and .pdr section when
9368 // looking for relocs that would need to refer to MIPS16 stubs.
9369 mips_obj
->add_local_non_16bit_call(r_sym
);
9371 if (r_type
== elfcpp::R_MIPS16_26
9372 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
9373 mips_obj
->add_local_16bit_call(r_sym
);
9377 case elfcpp::R_MIPS_GOT16
:
9378 case elfcpp::R_MIPS_CALL16
:
9379 case elfcpp::R_MIPS_CALL_HI16
:
9380 case elfcpp::R_MIPS_CALL_LO16
:
9381 case elfcpp::R_MIPS_GOT_HI16
:
9382 case elfcpp::R_MIPS_GOT_LO16
:
9383 case elfcpp::R_MIPS_GOT_PAGE
:
9384 case elfcpp::R_MIPS_GOT_OFST
:
9385 case elfcpp::R_MIPS_GOT_DISP
:
9386 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9387 case elfcpp::R_MIPS_TLS_GD
:
9388 case elfcpp::R_MIPS_TLS_LDM
:
9389 case elfcpp::R_MIPS16_GOT16
:
9390 case elfcpp::R_MIPS16_CALL16
:
9391 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9392 case elfcpp::R_MIPS16_TLS_GD
:
9393 case elfcpp::R_MIPS16_TLS_LDM
:
9394 case elfcpp::R_MICROMIPS_GOT16
:
9395 case elfcpp::R_MICROMIPS_CALL16
:
9396 case elfcpp::R_MICROMIPS_CALL_HI16
:
9397 case elfcpp::R_MICROMIPS_CALL_LO16
:
9398 case elfcpp::R_MICROMIPS_GOT_HI16
:
9399 case elfcpp::R_MICROMIPS_GOT_LO16
:
9400 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9401 case elfcpp::R_MICROMIPS_GOT_OFST
:
9402 case elfcpp::R_MICROMIPS_GOT_DISP
:
9403 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9404 case elfcpp::R_MICROMIPS_TLS_GD
:
9405 case elfcpp::R_MICROMIPS_TLS_LDM
:
9406 case elfcpp::R_MIPS_EH
:
9407 // We need a GOT section.
9408 target
->got_section(symtab
, layout
);
9415 if (call_lo16_reloc(r_type
)
9416 || got_lo16_reloc(r_type
)
9417 || got_disp_reloc(r_type
)
9418 || eh_reloc(r_type
))
9420 // We may need a local GOT entry for this relocation. We
9421 // don't count R_MIPS_GOT_PAGE because we can estimate the
9422 // maximum number of pages needed by looking at the size of
9423 // the segment. Similar comments apply to R_MIPS*_GOT16 and
9424 // R_MIPS*_CALL16. We don't count R_MIPS_GOT_HI16, or
9425 // R_MIPS_CALL_HI16 because these are always followed by an
9426 // R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
9427 Mips_output_data_got
<size
, big_endian
>* got
=
9428 target
->got_section(symtab
, layout
);
9429 bool is_section_symbol
= lsym
.get_st_type() == elfcpp::STT_SECTION
;
9430 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
, -1U,
9436 case elfcpp::R_MIPS_CALL16
:
9437 case elfcpp::R_MIPS16_CALL16
:
9438 case elfcpp::R_MICROMIPS_CALL16
:
9439 gold_error(_("CALL16 reloc at 0x%lx not against global symbol "),
9440 (unsigned long)r_offset
);
9443 case elfcpp::R_MIPS_GOT_PAGE
:
9444 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9445 case elfcpp::R_MIPS16_GOT16
:
9446 case elfcpp::R_MIPS_GOT16
:
9447 case elfcpp::R_MIPS_GOT_HI16
:
9448 case elfcpp::R_MIPS_GOT_LO16
:
9449 case elfcpp::R_MICROMIPS_GOT16
:
9450 case elfcpp::R_MICROMIPS_GOT_HI16
:
9451 case elfcpp::R_MICROMIPS_GOT_LO16
:
9453 // This relocation needs a page entry in the GOT.
9454 // Get the section contents.
9455 section_size_type view_size
= 0;
9456 const unsigned char* view
= object
->section_contents(data_shndx
,
9460 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
9461 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
9464 if (rel_type
== elfcpp::SHT_REL
&& got16_reloc(r_type
))
9465 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
9466 object
, data_shndx
, r_type
, r_sym
, addend
));
9468 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
, addend
);
9472 case elfcpp::R_MIPS_HI16
:
9473 case elfcpp::R_MIPS16_HI16
:
9474 case elfcpp::R_MICROMIPS_HI16
:
9475 // Record the reloc so that we can check whether the corresponding LO16
9477 if (rel_type
== elfcpp::SHT_REL
)
9478 target
->got16_addends_
.push_back(got16_addend
<size
, big_endian
>(
9479 object
, data_shndx
, r_type
, r_sym
, 0));
9482 case elfcpp::R_MIPS_LO16
:
9483 case elfcpp::R_MIPS16_LO16
:
9484 case elfcpp::R_MICROMIPS_LO16
:
9486 if (rel_type
!= elfcpp::SHT_REL
)
9489 // Find corresponding GOT16/HI16 relocation.
9491 // According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
9492 // be immediately following. However, for the IRIX6 ABI, the next
9493 // relocation may be a composed relocation consisting of several
9494 // relocations for the same address. In that case, the R_MIPS_LO16
9495 // relocation may occur as one of these. We permit a similar
9496 // extension in general, as that is useful for GCC.
9498 // In some cases GCC dead code elimination removes the LO16 but
9499 // keeps the corresponding HI16. This is strictly speaking a
9500 // violation of the ABI but not immediately harmful.
9502 typename
std::list
<got16_addend
<size
, big_endian
> >::iterator it
=
9503 target
->got16_addends_
.begin();
9504 while (it
!= target
->got16_addends_
.end())
9506 got16_addend
<size
, big_endian
> _got16_addend
= *it
;
9508 // TODO(sasa): Split got16_addends_ list into two lists - one for
9509 // GOT16 relocs and the other for HI16 relocs.
9511 // Report an error if we find HI16 or GOT16 reloc from the
9512 // previous section without the matching LO16 part.
9513 if (_got16_addend
.object
!= object
9514 || _got16_addend
.shndx
!= data_shndx
)
9516 gold_error("Can't find matching LO16 reloc");
9520 if (_got16_addend
.r_sym
!= r_sym
9521 || !is_matching_lo16_reloc(_got16_addend
.r_type
, r_type
))
9527 // We found a matching HI16 or GOT16 reloc for this LO16 reloc.
9528 // For GOT16, we need to calculate combined addend and record GOT page
9530 if (got16_reloc(_got16_addend
.r_type
))
9533 section_size_type view_size
= 0;
9534 const unsigned char* view
= object
->section_contents(data_shndx
,
9539 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
9540 int32_t addend
= Bits
<16>::sign_extend32(val
& 0xffff);
9542 addend
= (_got16_addend
.addend
<< 16) + addend
;
9543 target
->got_section()->record_got_page_entry(mips_obj
, r_sym
,
9547 it
= target
->got16_addends_
.erase(it
);
9555 case elfcpp::R_MIPS_32
:
9556 case elfcpp::R_MIPS_REL32
:
9557 case elfcpp::R_MIPS_64
:
9559 if (parameters
->options().output_is_position_independent())
9561 // If building a shared library (or a position-independent
9562 // executable), we need to create a dynamic relocation for
9564 if (is_readonly_section(output_section
))
9566 Reloc_section
* rel_dyn
= target
->rel_dyn_section(layout
);
9567 rel_dyn
->add_symbolless_local_addend(object
, r_sym
,
9568 elfcpp::R_MIPS_REL32
,
9569 output_section
, data_shndx
,
9575 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9576 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9577 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9578 case elfcpp::R_MIPS_TLS_LDM
:
9579 case elfcpp::R_MIPS16_TLS_LDM
:
9580 case elfcpp::R_MICROMIPS_TLS_LDM
:
9581 case elfcpp::R_MIPS_TLS_GD
:
9582 case elfcpp::R_MIPS16_TLS_GD
:
9583 case elfcpp::R_MICROMIPS_TLS_GD
:
9585 bool output_is_shared
= parameters
->options().shared();
9586 const tls::Tls_optimization optimized_type
9587 = Target_mips
<size
, big_endian
>::optimize_tls_reloc(
9588 !output_is_shared
, r_type
);
9591 case elfcpp::R_MIPS_TLS_GD
:
9592 case elfcpp::R_MIPS16_TLS_GD
:
9593 case elfcpp::R_MICROMIPS_TLS_GD
:
9594 if (optimized_type
== tls::TLSOPT_NONE
)
9596 // Create a pair of GOT entries for the module index and
9597 // dtv-relative offset.
9598 Mips_output_data_got
<size
, big_endian
>* got
=
9599 target
->got_section(symtab
, layout
);
9600 unsigned int shndx
= lsym
.get_st_shndx();
9602 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
9605 object
->error(_("local symbol %u has bad shndx %u"),
9609 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
9614 // FIXME: TLS optimization not supported yet.
9619 case elfcpp::R_MIPS_TLS_LDM
:
9620 case elfcpp::R_MIPS16_TLS_LDM
:
9621 case elfcpp::R_MICROMIPS_TLS_LDM
:
9622 if (optimized_type
== tls::TLSOPT_NONE
)
9624 // We always record LDM symbols as local with index 0.
9625 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
9631 // FIXME: TLS optimization not supported yet.
9635 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9636 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9637 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9638 layout
->set_has_static_tls();
9639 if (optimized_type
== tls::TLSOPT_NONE
)
9641 // Create a GOT entry for the tp-relative offset.
9642 Mips_output_data_got
<size
, big_endian
>* got
=
9643 target
->got_section(symtab
, layout
);
9644 got
->record_local_got_symbol(mips_obj
, r_sym
, r_addend
, r_type
,
9649 // FIXME: TLS optimization not supported yet.
9664 // Refuse some position-dependent relocations when creating a
9665 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
9666 // not PIC, but we can create dynamic relocations and the result
9667 // will be fine. Also do not refuse R_MIPS_LO16, which can be
9668 // combined with R_MIPS_GOT16.
9669 if (parameters
->options().shared())
9673 case elfcpp::R_MIPS16_HI16
:
9674 case elfcpp::R_MIPS_HI16
:
9675 case elfcpp::R_MICROMIPS_HI16
:
9676 // Don't refuse a high part relocation if it's against
9677 // no symbol (e.g. part of a compound relocation).
9683 case elfcpp::R_MIPS16_26
:
9684 case elfcpp::R_MIPS_26
:
9685 case elfcpp::R_MICROMIPS_26_S1
:
9686 gold_error(_("%s: relocation %u against `%s' can not be used when "
9687 "making a shared object; recompile with -fPIC"),
9688 object
->name().c_str(), r_type
, "a local symbol");
9695 template<int size
, bool big_endian
>
9697 Target_mips
<size
, big_endian
>::Scan::local(
9698 Symbol_table
* symtab
,
9700 Target_mips
<size
, big_endian
>* target
,
9701 Sized_relobj_file
<size
, big_endian
>* object
,
9702 unsigned int data_shndx
,
9703 Output_section
* output_section
,
9704 const Reltype
& reloc
,
9705 unsigned int r_type
,
9706 const elfcpp::Sym
<size
, big_endian
>& lsym
,
9719 (const Relatype
*) NULL
,
9723 lsym
, is_discarded
);
9727 template<int size
, bool big_endian
>
9729 Target_mips
<size
, big_endian
>::Scan::local(
9730 Symbol_table
* symtab
,
9732 Target_mips
<size
, big_endian
>* target
,
9733 Sized_relobj_file
<size
, big_endian
>* object
,
9734 unsigned int data_shndx
,
9735 Output_section
* output_section
,
9736 const Relatype
& reloc
,
9737 unsigned int r_type
,
9738 const elfcpp::Sym
<size
, big_endian
>& lsym
,
9752 (const Reltype
*) NULL
,
9755 lsym
, is_discarded
);
9758 // Scan a relocation for a global symbol.
9760 template<int size
, bool big_endian
>
9762 Target_mips
<size
, big_endian
>::Scan::global(
9763 Symbol_table
* symtab
,
9765 Target_mips
<size
, big_endian
>* target
,
9766 Sized_relobj_file
<size
, big_endian
>* object
,
9767 unsigned int data_shndx
,
9768 Output_section
* output_section
,
9769 const Relatype
* rela
,
9771 unsigned int rel_type
,
9772 unsigned int r_type
,
9775 Mips_address r_offset
;
9777 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
9779 if (rel_type
== elfcpp::SHT_RELA
)
9781 r_offset
= rela
->get_r_offset();
9782 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
9784 r_addend
= rela
->get_r_addend();
9788 r_offset
= rel
->get_r_offset();
9789 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
9794 Mips_relobj
<size
, big_endian
>* mips_obj
=
9795 Mips_relobj
<size
, big_endian
>::as_mips_relobj(object
);
9796 Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
9798 if (mips_obj
->is_mips16_stub_section(data_shndx
))
9800 mips_obj
->get_mips16_stub_section(data_shndx
)
9801 ->new_global_reloc_found(r_type
, mips_sym
);
9804 if (r_type
== elfcpp::R_MIPS_NONE
)
9805 // R_MIPS_NONE is used in mips16 stub sections, to define the target of the
9809 if (!mips16_call_reloc(r_type
)
9810 && !mips_obj
->section_allows_mips16_refs(data_shndx
))
9811 // This reloc would need to refer to a MIPS16 hard-float stub, if
9812 // there is one. We ignore MIPS16 stub sections and .pdr section when
9813 // looking for relocs that would need to refer to MIPS16 stubs.
9814 mips_sym
->set_need_fn_stub();
9816 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
9817 // section. We check here to avoid creating a dynamic reloc against
9818 // _GLOBAL_OFFSET_TABLE_.
9819 if (!target
->has_got_section()
9820 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9821 target
->got_section(symtab
, layout
);
9823 // We need PLT entries if there are static-only relocations against
9824 // an externally-defined function. This can technically occur for
9825 // shared libraries if there are branches to the symbol, although it
9826 // is unlikely that this will be used in practice due to the short
9827 // ranges involved. It can occur for any relative or absolute relocation
9828 // in executables; in that case, the PLT entry becomes the function's
9829 // canonical address.
9830 bool static_reloc
= false;
9832 // Set CAN_MAKE_DYNAMIC to true if we can convert this
9833 // relocation into a dynamic one.
9834 bool can_make_dynamic
= false;
9837 case elfcpp::R_MIPS_GOT16
:
9838 case elfcpp::R_MIPS_CALL16
:
9839 case elfcpp::R_MIPS_CALL_HI16
:
9840 case elfcpp::R_MIPS_CALL_LO16
:
9841 case elfcpp::R_MIPS_GOT_HI16
:
9842 case elfcpp::R_MIPS_GOT_LO16
:
9843 case elfcpp::R_MIPS_GOT_PAGE
:
9844 case elfcpp::R_MIPS_GOT_OFST
:
9845 case elfcpp::R_MIPS_GOT_DISP
:
9846 case elfcpp::R_MIPS_TLS_GOTTPREL
:
9847 case elfcpp::R_MIPS_TLS_GD
:
9848 case elfcpp::R_MIPS_TLS_LDM
:
9849 case elfcpp::R_MIPS16_GOT16
:
9850 case elfcpp::R_MIPS16_CALL16
:
9851 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
9852 case elfcpp::R_MIPS16_TLS_GD
:
9853 case elfcpp::R_MIPS16_TLS_LDM
:
9854 case elfcpp::R_MICROMIPS_GOT16
:
9855 case elfcpp::R_MICROMIPS_CALL16
:
9856 case elfcpp::R_MICROMIPS_CALL_HI16
:
9857 case elfcpp::R_MICROMIPS_CALL_LO16
:
9858 case elfcpp::R_MICROMIPS_GOT_HI16
:
9859 case elfcpp::R_MICROMIPS_GOT_LO16
:
9860 case elfcpp::R_MICROMIPS_GOT_PAGE
:
9861 case elfcpp::R_MICROMIPS_GOT_OFST
:
9862 case elfcpp::R_MICROMIPS_GOT_DISP
:
9863 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
9864 case elfcpp::R_MICROMIPS_TLS_GD
:
9865 case elfcpp::R_MICROMIPS_TLS_LDM
:
9866 case elfcpp::R_MIPS_EH
:
9867 // We need a GOT section.
9868 target
->got_section(symtab
, layout
);
9871 // This is just a hint; it can safely be ignored. Don't set
9872 // has_static_relocs for the corresponding symbol.
9873 case elfcpp::R_MIPS_JALR
:
9874 case elfcpp::R_MICROMIPS_JALR
:
9877 case elfcpp::R_MIPS_GPREL16
:
9878 case elfcpp::R_MIPS_GPREL32
:
9879 case elfcpp::R_MIPS16_GPREL
:
9880 case elfcpp::R_MICROMIPS_GPREL16
:
9882 // GP-relative relocations always resolve to a definition in a
9883 // regular input file, ignoring the one-definition rule. This is
9884 // important for the GP setup sequence in NewABI code, which
9885 // always resolves to a local function even if other relocations
9886 // against the symbol wouldn't.
9887 //constrain_symbol_p = FALSE;
9890 case elfcpp::R_MIPS_32
:
9891 case elfcpp::R_MIPS_REL32
:
9892 case elfcpp::R_MIPS_64
:
9893 if ((parameters
->options().shared()
9894 || (strcmp(gsym
->name(), "__gnu_local_gp") != 0
9895 && (!is_readonly_section(output_section
)
9896 || mips_obj
->is_pic())))
9897 && (output_section
->flags() & elfcpp::SHF_ALLOC
) != 0)
9899 if (r_type
!= elfcpp::R_MIPS_REL32
)
9900 mips_sym
->set_pointer_equality_needed();
9901 can_make_dynamic
= true;
9907 // Most static relocations require pointer equality, except
9909 mips_sym
->set_pointer_equality_needed();
9913 case elfcpp::R_MIPS_26
:
9914 case elfcpp::R_MIPS_PC16
:
9915 case elfcpp::R_MIPS16_26
:
9916 case elfcpp::R_MICROMIPS_26_S1
:
9917 case elfcpp::R_MICROMIPS_PC7_S1
:
9918 case elfcpp::R_MICROMIPS_PC10_S1
:
9919 case elfcpp::R_MICROMIPS_PC16_S1
:
9920 case elfcpp::R_MICROMIPS_PC23_S2
:
9921 static_reloc
= true;
9922 mips_sym
->set_has_static_relocs();
9926 // If there are call relocations against an externally-defined symbol,
9927 // see whether we can create a MIPS lazy-binding stub for it. We can
9928 // only do this if all references to the function are through call
9929 // relocations, and in that case, the traditional lazy-binding stubs
9930 // are much more efficient than PLT entries.
9933 case elfcpp::R_MIPS16_CALL16
:
9934 case elfcpp::R_MIPS_CALL16
:
9935 case elfcpp::R_MIPS_CALL_HI16
:
9936 case elfcpp::R_MIPS_CALL_LO16
:
9937 case elfcpp::R_MIPS_JALR
:
9938 case elfcpp::R_MICROMIPS_CALL16
:
9939 case elfcpp::R_MICROMIPS_CALL_HI16
:
9940 case elfcpp::R_MICROMIPS_CALL_LO16
:
9941 case elfcpp::R_MICROMIPS_JALR
:
9942 if (!mips_sym
->no_lazy_stub())
9944 if ((mips_sym
->needs_plt_entry() && mips_sym
->is_from_dynobj())
9945 // Calls from shared objects to undefined symbols of type
9946 // STT_NOTYPE need lazy-binding stub.
9947 || (mips_sym
->is_undefined() && parameters
->options().shared()))
9948 target
->mips_stubs_section(layout
)->make_entry(mips_sym
);
9953 // We must not create a stub for a symbol that has relocations
9954 // related to taking the function's address.
9955 mips_sym
->set_no_lazy_stub();
9956 target
->remove_lazy_stub_entry(mips_sym
);
9961 if (relocation_needs_la25_stub
<size
, big_endian
>(mips_obj
, r_type
,
9962 mips_sym
->is_mips16()))
9963 mips_sym
->set_has_nonpic_branches();
9965 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
9966 // and has a special meaning.
9967 bool gp_disp_against_hi16
= (!mips_obj
->is_newabi()
9968 && strcmp(gsym
->name(), "_gp_disp") == 0
9969 && (hi16_reloc(r_type
) || lo16_reloc(r_type
)));
9970 if (static_reloc
&& gsym
->needs_plt_entry())
9972 target
->make_plt_entry(symtab
, layout
, mips_sym
, r_type
);
9974 // Since this is not a PC-relative relocation, we may be
9975 // taking the address of a function. In that case we need to
9976 // set the entry in the dynamic symbol table to the address of
9978 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
9980 gsym
->set_needs_dynsym_value();
9981 // We distinguish between PLT entries and lazy-binding stubs by
9982 // giving the former an st_other value of STO_MIPS_PLT. Set the
9983 // flag if there are any relocations in the binary where pointer
9984 // equality matters.
9985 if (mips_sym
->pointer_equality_needed())
9986 mips_sym
->set_mips_plt();
9989 if ((static_reloc
|| can_make_dynamic
) && !gp_disp_against_hi16
)
9991 // Absolute addressing relocations.
9992 // Make a dynamic relocation if necessary.
9993 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
9995 if (gsym
->may_need_copy_reloc())
9997 target
->copy_reloc(symtab
, layout
, object
, data_shndx
,
9998 output_section
, gsym
, r_type
, r_offset
);
10000 else if (can_make_dynamic
)
10002 // Create .rel.dyn section.
10003 target
->rel_dyn_section(layout
);
10004 target
->dynamic_reloc(mips_sym
, elfcpp::R_MIPS_REL32
, mips_obj
,
10005 data_shndx
, output_section
, r_offset
);
10008 gold_error(_("non-dynamic relocations refer to dynamic symbol %s"),
10013 bool for_call
= false;
10016 case elfcpp::R_MIPS_CALL16
:
10017 case elfcpp::R_MIPS16_CALL16
:
10018 case elfcpp::R_MICROMIPS_CALL16
:
10019 case elfcpp::R_MIPS_CALL_HI16
:
10020 case elfcpp::R_MIPS_CALL_LO16
:
10021 case elfcpp::R_MICROMIPS_CALL_HI16
:
10022 case elfcpp::R_MICROMIPS_CALL_LO16
:
10026 case elfcpp::R_MIPS16_GOT16
:
10027 case elfcpp::R_MIPS_GOT16
:
10028 case elfcpp::R_MIPS_GOT_HI16
:
10029 case elfcpp::R_MIPS_GOT_LO16
:
10030 case elfcpp::R_MICROMIPS_GOT16
:
10031 case elfcpp::R_MICROMIPS_GOT_HI16
:
10032 case elfcpp::R_MICROMIPS_GOT_LO16
:
10033 case elfcpp::R_MIPS_GOT_DISP
:
10034 case elfcpp::R_MICROMIPS_GOT_DISP
:
10035 case elfcpp::R_MIPS_EH
:
10037 // The symbol requires a GOT entry.
10038 Mips_output_data_got
<size
, big_endian
>* got
=
10039 target
->got_section(symtab
, layout
);
10040 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10042 mips_sym
->set_global_got_area(GGA_NORMAL
);
10046 case elfcpp::R_MIPS_GOT_PAGE
:
10047 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10049 // This relocation needs a page entry in the GOT.
10050 // Get the section contents.
10051 section_size_type view_size
= 0;
10052 const unsigned char* view
=
10053 object
->section_contents(data_shndx
, &view_size
, false);
10056 Valtype32 val
= elfcpp::Swap
<32, big_endian
>::readval(view
);
10057 Valtype32 addend
= (rel_type
== elfcpp::SHT_REL
? val
& 0xffff
10059 Mips_output_data_got
<size
, big_endian
>* got
=
10060 target
->got_section(symtab
, layout
);
10061 got
->record_got_page_entry(mips_obj
, r_sym
, addend
);
10063 // If this is a global, overridable symbol, GOT_PAGE will
10064 // decay to GOT_DISP, so we'll need a GOT entry for it.
10065 bool def_regular
= (mips_sym
->source() == Symbol::FROM_OBJECT
10066 && !mips_sym
->object()->is_dynamic()
10067 && !mips_sym
->is_undefined());
10069 || (parameters
->options().output_is_position_independent()
10070 && !parameters
->options().Bsymbolic()
10071 && !mips_sym
->is_forced_local()))
10073 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10075 mips_sym
->set_global_got_area(GGA_NORMAL
);
10080 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10081 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10082 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10083 case elfcpp::R_MIPS_TLS_LDM
:
10084 case elfcpp::R_MIPS16_TLS_LDM
:
10085 case elfcpp::R_MICROMIPS_TLS_LDM
:
10086 case elfcpp::R_MIPS_TLS_GD
:
10087 case elfcpp::R_MIPS16_TLS_GD
:
10088 case elfcpp::R_MICROMIPS_TLS_GD
:
10090 const bool is_final
= gsym
->final_value_is_known();
10091 const tls::Tls_optimization optimized_type
=
10092 Target_mips
<size
, big_endian
>::optimize_tls_reloc(is_final
, r_type
);
10096 case elfcpp::R_MIPS_TLS_GD
:
10097 case elfcpp::R_MIPS16_TLS_GD
:
10098 case elfcpp::R_MICROMIPS_TLS_GD
:
10099 if (optimized_type
== tls::TLSOPT_NONE
)
10101 // Create a pair of GOT entries for the module index and
10102 // dtv-relative offset.
10103 Mips_output_data_got
<size
, big_endian
>* got
=
10104 target
->got_section(symtab
, layout
);
10105 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10110 // FIXME: TLS optimization not supported yet.
10111 gold_unreachable();
10115 case elfcpp::R_MIPS_TLS_LDM
:
10116 case elfcpp::R_MIPS16_TLS_LDM
:
10117 case elfcpp::R_MICROMIPS_TLS_LDM
:
10118 if (optimized_type
== tls::TLSOPT_NONE
)
10120 // We always record LDM symbols as local with index 0.
10121 target
->got_section()->record_local_got_symbol(mips_obj
, 0,
10127 // FIXME: TLS optimization not supported yet.
10128 gold_unreachable();
10131 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10132 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10133 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10134 layout
->set_has_static_tls();
10135 if (optimized_type
== tls::TLSOPT_NONE
)
10137 // Create a GOT entry for the tp-relative offset.
10138 Mips_output_data_got
<size
, big_endian
>* got
=
10139 target
->got_section(symtab
, layout
);
10140 got
->record_global_got_symbol(mips_sym
, mips_obj
, r_type
, false,
10145 // FIXME: TLS optimization not supported yet.
10146 gold_unreachable();
10151 gold_unreachable();
10155 case elfcpp::R_MIPS_COPY
:
10156 case elfcpp::R_MIPS_JUMP_SLOT
:
10157 // These are relocations which should only be seen by the
10158 // dynamic linker, and should never be seen here.
10159 gold_error(_("%s: unexpected reloc %u in object file"),
10160 object
->name().c_str(), r_type
);
10167 // Refuse some position-dependent relocations when creating a
10168 // shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
10169 // not PIC, but we can create dynamic relocations and the result
10170 // will be fine. Also do not refuse R_MIPS_LO16, which can be
10171 // combined with R_MIPS_GOT16.
10172 if (parameters
->options().shared())
10176 case elfcpp::R_MIPS16_HI16
:
10177 case elfcpp::R_MIPS_HI16
:
10178 case elfcpp::R_MICROMIPS_HI16
:
10179 // Don't refuse a high part relocation if it's against
10180 // no symbol (e.g. part of a compound relocation).
10184 // R_MIPS_HI16 against _gp_disp is used for $gp setup,
10185 // and has a special meaning.
10186 if (!mips_obj
->is_newabi() && strcmp(gsym
->name(), "_gp_disp") == 0)
10191 case elfcpp::R_MIPS16_26
:
10192 case elfcpp::R_MIPS_26
:
10193 case elfcpp::R_MICROMIPS_26_S1
:
10194 gold_error(_("%s: relocation %u against `%s' can not be used when "
10195 "making a shared object; recompile with -fPIC"),
10196 object
->name().c_str(), r_type
, gsym
->name());
10203 template<int size
, bool big_endian
>
10205 Target_mips
<size
, big_endian
>::Scan::global(
10206 Symbol_table
* symtab
,
10208 Target_mips
<size
, big_endian
>* target
,
10209 Sized_relobj_file
<size
, big_endian
>* object
,
10210 unsigned int data_shndx
,
10211 Output_section
* output_section
,
10212 const Relatype
& reloc
,
10213 unsigned int r_type
,
10224 (const Reltype
*) NULL
,
10230 template<int size
, bool big_endian
>
10232 Target_mips
<size
, big_endian
>::Scan::global(
10233 Symbol_table
* symtab
,
10235 Target_mips
<size
, big_endian
>* target
,
10236 Sized_relobj_file
<size
, big_endian
>* object
,
10237 unsigned int data_shndx
,
10238 Output_section
* output_section
,
10239 const Reltype
& reloc
,
10240 unsigned int r_type
,
10250 (const Relatype
*) NULL
,
10257 // Return whether a R_MIPS_32/R_MIPS64 relocation needs to be applied.
10258 // In cases where Scan::local() or Scan::global() has created
10259 // a dynamic relocation, the addend of the relocation is carried
10260 // in the data, and we must not apply the static relocation.
10262 template<int size
, bool big_endian
>
10264 Target_mips
<size
, big_endian
>::Relocate::should_apply_static_reloc(
10265 const Mips_symbol
<size
>* gsym
,
10266 unsigned int r_type
,
10267 Output_section
* output_section
,
10268 Target_mips
* target
)
10270 // If the output section is not allocated, then we didn't call
10271 // scan_relocs, we didn't create a dynamic reloc, and we must apply
10273 if ((output_section
->flags() & elfcpp::SHF_ALLOC
) == 0)
10280 // For global symbols, we use the same helper routines used in the
10282 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
))
10283 && !gsym
->may_need_copy_reloc())
10285 // We have generated dynamic reloc (R_MIPS_REL32).
10287 bool multi_got
= false;
10288 if (target
->has_got_section())
10289 multi_got
= target
->got_section()->multi_got();
10290 bool has_got_offset
;
10292 has_got_offset
= gsym
->has_got_offset(GOT_TYPE_STANDARD
);
10294 has_got_offset
= gsym
->global_gotoffset() != -1U;
10295 if (!has_got_offset
)
10298 // Apply the relocation only if the symbol is in the local got.
10299 // Do not apply the relocation if the symbol is in the global
10301 return symbol_references_local(gsym
, gsym
->has_dynsym_index());
10304 // We have not generated dynamic reloc.
10309 // Perform a relocation.
10311 template<int size
, bool big_endian
>
10313 Target_mips
<size
, big_endian
>::Relocate::relocate(
10314 const Relocate_info
<size
, big_endian
>* relinfo
,
10315 unsigned int rel_type
,
10316 Target_mips
* target
,
10317 Output_section
* output_section
,
10319 const unsigned char* preloc
,
10320 const Sized_symbol
<size
>* gsym
,
10321 const Symbol_value
<size
>* psymval
,
10322 unsigned char* view
,
10323 Mips_address address
,
10326 Mips_address r_offset
;
10327 unsigned int r_sym
;
10328 unsigned int r_type
;
10329 unsigned int r_type2
;
10330 unsigned int r_type3
;
10331 unsigned char r_ssym
;
10332 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
;
10334 if (rel_type
== elfcpp::SHT_RELA
)
10336 const Relatype
rela(preloc
);
10337 r_offset
= rela
.get_r_offset();
10338 r_sym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10340 r_type
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10342 r_type2
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10343 get_r_type2(&rela
);
10344 r_type3
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10345 get_r_type3(&rela
);
10346 r_ssym
= Mips_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>::
10348 r_addend
= rela
.get_r_addend();
10352 const Reltype
rel(preloc
);
10353 r_offset
= rel
.get_r_offset();
10354 r_sym
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
10356 r_type
= Mips_classify_reloc
<elfcpp::SHT_REL
, size
, big_endian
>::
10364 typedef Mips_relocate_functions
<size
, big_endian
> Reloc_funcs
;
10365 typename
Reloc_funcs::Status reloc_status
= Reloc_funcs::STATUS_OKAY
;
10367 Mips_relobj
<size
, big_endian
>* object
=
10368 Mips_relobj
<size
, big_endian
>::as_mips_relobj(relinfo
->object
);
10370 bool target_is_16_bit_code
= false;
10371 bool target_is_micromips_code
= false;
10372 bool cross_mode_jump
;
10374 Symbol_value
<size
> symval
;
10376 const Mips_symbol
<size
>* mips_sym
= Mips_symbol
<size
>::as_mips_sym(gsym
);
10378 bool changed_symbol_value
= false;
10381 target_is_16_bit_code
= object
->local_symbol_is_mips16(r_sym
);
10382 target_is_micromips_code
= object
->local_symbol_is_micromips(r_sym
);
10383 if (target_is_16_bit_code
|| target_is_micromips_code
)
10385 // MIPS16/microMIPS text labels should be treated as odd.
10386 symval
.set_output_value(psymval
->value(object
, 1));
10388 changed_symbol_value
= true;
10393 target_is_16_bit_code
= mips_sym
->is_mips16();
10394 target_is_micromips_code
= mips_sym
->is_micromips();
10396 // If this is a mips16/microMIPS text symbol, add 1 to the value to make
10397 // it odd. This will cause something like .word SYM to come up with
10398 // the right value when it is loaded into the PC.
10400 if ((mips_sym
->is_mips16() || mips_sym
->is_micromips())
10401 && psymval
->value(object
, 0) != 0)
10403 symval
.set_output_value(psymval
->value(object
, 0) | 1);
10405 changed_symbol_value
= true;
10408 // Pick the value to use for symbols defined in shared objects.
10409 if (mips_sym
->use_plt_offset(Scan::get_reference_flags(r_type
))
10410 || mips_sym
->has_lazy_stub())
10412 Mips_address value
;
10413 if (!mips_sym
->has_lazy_stub())
10415 // Prefer a standard MIPS PLT entry.
10416 if (mips_sym
->has_mips_plt_offset())
10418 value
= target
->plt_section()->mips_entry_address(mips_sym
);
10419 target_is_micromips_code
= false;
10420 target_is_16_bit_code
= false;
10424 value
= (target
->plt_section()->comp_entry_address(mips_sym
)
10426 if (target
->is_output_micromips())
10427 target_is_micromips_code
= true;
10429 target_is_16_bit_code
= true;
10433 value
= target
->mips_stubs_section()->stub_address(mips_sym
);
10435 symval
.set_output_value(value
);
10440 // TRUE if the symbol referred to by this relocation is "_gp_disp".
10441 // Note that such a symbol must always be a global symbol.
10442 bool gp_disp
= (gsym
!= NULL
&& (strcmp(gsym
->name(), "_gp_disp") == 0)
10443 && !object
->is_newabi());
10445 // TRUE if the symbol referred to by this relocation is "__gnu_local_gp".
10446 // Note that such a symbol must always be a global symbol.
10447 bool gnu_local_gp
= gsym
&& (strcmp(gsym
->name(), "__gnu_local_gp") == 0);
10452 if (!hi16_reloc(r_type
) && !lo16_reloc(r_type
))
10453 gold_error_at_location(relinfo
, relnum
, r_offset
,
10454 _("relocations against _gp_disp are permitted only"
10455 " with R_MIPS_HI16 and R_MIPS_LO16 relocations."));
10457 else if (gnu_local_gp
)
10459 // __gnu_local_gp is _gp symbol.
10460 symval
.set_output_value(target
->adjusted_gp_value(object
));
10464 // If this is a reference to a 16-bit function with a stub, we need
10465 // to redirect the relocation to the stub unless:
10467 // (a) the relocation is for a MIPS16 JAL;
10469 // (b) the relocation is for a MIPS16 PIC call, and there are no
10470 // non-MIPS16 uses of the GOT slot; or
10472 // (c) the section allows direct references to MIPS16 functions.
10473 if (r_type
!= elfcpp::R_MIPS16_26
10474 && !parameters
->options().relocatable()
10475 && ((mips_sym
!= NULL
10476 && mips_sym
->has_mips16_fn_stub()
10477 && (r_type
!= elfcpp::R_MIPS16_CALL16
|| mips_sym
->need_fn_stub()))
10478 || (mips_sym
== NULL
10479 && object
->get_local_mips16_fn_stub(r_sym
) != NULL
))
10480 && !object
->section_allows_mips16_refs(relinfo
->data_shndx
))
10482 // This is a 32- or 64-bit call to a 16-bit function. We should
10483 // have already noticed that we were going to need the
10485 Mips_address value
;
10486 if (mips_sym
== NULL
)
10487 value
= object
->get_local_mips16_fn_stub(r_sym
)->output_address();
10490 gold_assert(mips_sym
->need_fn_stub());
10491 if (mips_sym
->has_la25_stub())
10492 value
= target
->la25_stub_section()->stub_address(mips_sym
);
10495 value
= mips_sym
->template
10496 get_mips16_fn_stub
<big_endian
>()->output_address();
10499 symval
.set_output_value(value
);
10501 changed_symbol_value
= true;
10503 // The target is 16-bit, but the stub isn't.
10504 target_is_16_bit_code
= false;
10506 // If this is a MIPS16 call with a stub, that is made through the PLT or
10507 // to a standard MIPS function, we need to redirect the call to the stub.
10508 // Note that we specifically exclude R_MIPS16_CALL16 from this behavior;
10509 // indirect calls should use an indirect stub instead.
10510 else if (r_type
== elfcpp::R_MIPS16_26
&& !parameters
->options().relocatable()
10511 && ((mips_sym
!= NULL
10512 && (mips_sym
->has_mips16_call_stub()
10513 || mips_sym
->has_mips16_call_fp_stub()))
10514 || (mips_sym
== NULL
10515 && object
->get_local_mips16_call_stub(r_sym
) != NULL
))
10516 && ((mips_sym
!= NULL
&& mips_sym
->has_plt_offset())
10517 || !target_is_16_bit_code
))
10519 Mips16_stub_section
<size
, big_endian
>* call_stub
;
10520 if (mips_sym
== NULL
)
10521 call_stub
= object
->get_local_mips16_call_stub(r_sym
);
10524 // If both call_stub and call_fp_stub are defined, we can figure
10525 // out which one to use by checking which one appears in the input
10527 if (mips_sym
->has_mips16_call_stub()
10528 && mips_sym
->has_mips16_call_fp_stub())
10531 for (unsigned int i
= 1; i
< object
->shnum(); ++i
)
10533 if (object
->is_mips16_call_fp_stub_section(i
))
10535 call_stub
= mips_sym
->template
10536 get_mips16_call_fp_stub
<big_endian
>();
10541 if (call_stub
== NULL
)
10543 mips_sym
->template get_mips16_call_stub
<big_endian
>();
10545 else if (mips_sym
->has_mips16_call_stub())
10546 call_stub
= mips_sym
->template get_mips16_call_stub
<big_endian
>();
10548 call_stub
= mips_sym
->template get_mips16_call_fp_stub
<big_endian
>();
10551 symval
.set_output_value(call_stub
->output_address());
10553 changed_symbol_value
= true;
10555 // If this is a direct call to a PIC function, redirect to the
10557 else if (mips_sym
!= NULL
10558 && mips_sym
->has_la25_stub()
10559 && relocation_needs_la25_stub
<size
, big_endian
>(
10560 object
, r_type
, target_is_16_bit_code
))
10562 Mips_address value
= target
->la25_stub_section()->stub_address(mips_sym
);
10563 if (mips_sym
->is_micromips())
10565 symval
.set_output_value(value
);
10568 // For direct MIPS16 and microMIPS calls make sure the compressed PLT
10569 // entry is used if a standard PLT entry has also been made.
10570 else if ((r_type
== elfcpp::R_MIPS16_26
10571 || r_type
== elfcpp::R_MICROMIPS_26_S1
)
10572 && !parameters
->options().relocatable()
10573 && mips_sym
!= NULL
10574 && mips_sym
->has_plt_offset()
10575 && mips_sym
->has_comp_plt_offset()
10576 && mips_sym
->has_mips_plt_offset())
10578 Mips_address value
= (target
->plt_section()->comp_entry_address(mips_sym
)
10580 symval
.set_output_value(value
);
10583 target_is_16_bit_code
= !target
->is_output_micromips();
10584 target_is_micromips_code
= target
->is_output_micromips();
10587 // Make sure MIPS16 and microMIPS are not used together.
10588 if ((r_type
== elfcpp::R_MIPS16_26
&& target_is_micromips_code
)
10589 || (micromips_branch_reloc(r_type
) && target_is_16_bit_code
))
10591 gold_error(_("MIPS16 and microMIPS functions cannot call each other"));
10594 // Calls from 16-bit code to 32-bit code and vice versa require the
10595 // mode change. However, we can ignore calls to undefined weak symbols,
10596 // which should never be executed at runtime. This exception is important
10597 // because the assembly writer may have "known" that any definition of the
10598 // symbol would be 16-bit code, and that direct jumps were therefore
10601 (!parameters
->options().relocatable()
10602 && !(gsym
!= NULL
&& gsym
->is_weak_undefined())
10603 && ((r_type
== elfcpp::R_MIPS16_26
&& !target_is_16_bit_code
)
10604 || (r_type
== elfcpp::R_MICROMIPS_26_S1
&& !target_is_micromips_code
)
10605 || ((r_type
== elfcpp::R_MIPS_26
|| r_type
== elfcpp::R_MIPS_JALR
)
10606 && (target_is_16_bit_code
|| target_is_micromips_code
))));
10608 bool local
= (mips_sym
== NULL
10609 || (mips_sym
->got_only_for_calls()
10610 ? symbol_calls_local(mips_sym
, mips_sym
->has_dynsym_index())
10611 : symbol_references_local(mips_sym
,
10612 mips_sym
->has_dynsym_index())));
10614 // Global R_MIPS_GOT_PAGE/R_MICROMIPS_GOT_PAGE relocations are equivalent
10615 // to R_MIPS_GOT_DISP/R_MICROMIPS_GOT_DISP. The addend is applied by the
10616 // corresponding R_MIPS_GOT_OFST/R_MICROMIPS_GOT_OFST.
10617 if (got_page_reloc(r_type
) && !local
)
10618 r_type
= (micromips_reloc(r_type
) ? elfcpp::R_MICROMIPS_GOT_DISP
10619 : elfcpp::R_MIPS_GOT_DISP
);
10621 unsigned int got_offset
= 0;
10624 bool calculate_only
= false;
10625 Valtype calculated_value
= 0;
10626 bool extract_addend
= rel_type
== elfcpp::SHT_REL
;
10627 unsigned int r_types
[3] = { r_type
, r_type2
, r_type3
};
10629 Reloc_funcs::mips_reloc_unshuffle(view
, r_type
, false);
10631 // For Mips64 N64 ABI, there may be up to three operations specified per
10632 // record, by the fields r_type, r_type2, and r_type3. The first operation
10633 // takes its addend from the relocation record. Each subsequent operation
10634 // takes as its addend the result of the previous operation.
10635 // The first operation in a record which references a symbol uses the symbol
10636 // implied by r_sym. The next operation in a record which references a symbol
10637 // uses the special symbol value given by the r_ssym field. A third operation
10638 // in a record which references a symbol will assume a NULL symbol,
10639 // i.e. value zero.
10642 // Check if a record references to a symbol.
10643 for (unsigned int i
= 0; i
< 3; ++i
)
10645 if (r_types
[i
] == elfcpp::R_MIPS_NONE
)
10649 // Check if the next relocation is for the same instruction.
10650 calculate_only
= i
== 2 ? false
10651 : r_types
[i
+1] != elfcpp::R_MIPS_NONE
;
10653 if (object
->is_n64())
10657 // Handle special symbol for r_type2 relocation type.
10661 symval
.set_output_value(0);
10664 symval
.set_output_value(target
->gp_value());
10667 symval
.set_output_value(object
->gp_value());
10670 symval
.set_output_value(address
);
10673 gold_unreachable();
10679 // For r_type3 symbol value is 0.
10680 symval
.set_output_value(0);
10684 bool update_got_entry
= false;
10685 switch (r_types
[i
])
10687 case elfcpp::R_MIPS_NONE
:
10689 case elfcpp::R_MIPS_16
:
10690 reloc_status
= Reloc_funcs::rel16(view
, object
, psymval
, r_addend
,
10691 extract_addend
, calculate_only
,
10692 &calculated_value
);
10695 case elfcpp::R_MIPS_32
:
10696 if (should_apply_static_reloc(mips_sym
, r_types
[i
], output_section
,
10698 reloc_status
= Reloc_funcs::rel32(view
, object
, psymval
, r_addend
,
10699 extract_addend
, calculate_only
,
10700 &calculated_value
);
10701 if (mips_sym
!= NULL
10702 && (mips_sym
->is_mips16() || mips_sym
->is_micromips())
10703 && mips_sym
->global_got_area() == GGA_RELOC_ONLY
)
10705 // If mips_sym->has_mips16_fn_stub() is false, symbol value is
10706 // already updated by adding +1.
10707 if (mips_sym
->has_mips16_fn_stub())
10709 gold_assert(mips_sym
->need_fn_stub());
10710 Mips16_stub_section
<size
, big_endian
>* fn_stub
=
10711 mips_sym
->template get_mips16_fn_stub
<big_endian
>();
10713 symval
.set_output_value(fn_stub
->output_address());
10716 got_offset
= mips_sym
->global_gotoffset();
10717 update_got_entry
= true;
10721 case elfcpp::R_MIPS_64
:
10722 if (should_apply_static_reloc(mips_sym
, r_types
[i
], output_section
,
10724 reloc_status
= Reloc_funcs::rel64(view
, object
, psymval
, r_addend
,
10725 extract_addend
, calculate_only
,
10726 &calculated_value
, false);
10727 else if (target
->is_output_n64() && r_addend
!= 0)
10728 // Only apply the addend. The static relocation was RELA, but the
10729 // dynamic relocation is REL, so we need to apply the addend.
10730 reloc_status
= Reloc_funcs::rel64(view
, object
, psymval
, r_addend
,
10731 extract_addend
, calculate_only
,
10732 &calculated_value
, true);
10734 case elfcpp::R_MIPS_REL32
:
10735 gold_unreachable();
10737 case elfcpp::R_MIPS_PC32
:
10738 reloc_status
= Reloc_funcs::relpc32(view
, object
, psymval
, address
,
10739 r_addend
, extract_addend
,
10741 &calculated_value
);
10744 case elfcpp::R_MIPS16_26
:
10745 // The calculation for R_MIPS16_26 is just the same as for an
10746 // R_MIPS_26. It's only the storage of the relocated field into
10747 // the output file that's different. So, we just fall through to the
10748 // R_MIPS_26 case here.
10749 case elfcpp::R_MIPS_26
:
10750 case elfcpp::R_MICROMIPS_26_S1
:
10751 reloc_status
= Reloc_funcs::rel26(view
, object
, psymval
, address
,
10752 gsym
== NULL
, r_addend
, extract_addend
, gsym
, cross_mode_jump
,
10753 r_types
[i
], target
->jal_to_bal(), calculate_only
,
10754 &calculated_value
);
10757 case elfcpp::R_MIPS_HI16
:
10758 case elfcpp::R_MIPS16_HI16
:
10759 case elfcpp::R_MICROMIPS_HI16
:
10760 if (rel_type
== elfcpp::SHT_RELA
)
10761 reloc_status
= Reloc_funcs::do_relhi16(view
, object
, psymval
,
10763 gp_disp
, r_types
[i
],
10765 target
, calculate_only
,
10766 &calculated_value
);
10767 else if (rel_type
== elfcpp::SHT_REL
)
10768 reloc_status
= Reloc_funcs::relhi16(view
, object
, psymval
, r_addend
,
10769 address
, gp_disp
, r_types
[i
],
10770 r_sym
, extract_addend
);
10772 gold_unreachable();
10775 case elfcpp::R_MIPS_LO16
:
10776 case elfcpp::R_MIPS16_LO16
:
10777 case elfcpp::R_MICROMIPS_LO16
:
10778 case elfcpp::R_MICROMIPS_HI0_LO16
:
10779 reloc_status
= Reloc_funcs::rello16(target
, view
, object
, psymval
,
10780 r_addend
, extract_addend
, address
,
10781 gp_disp
, r_types
[i
], r_sym
,
10782 rel_type
, calculate_only
,
10783 &calculated_value
);
10786 case elfcpp::R_MIPS_LITERAL
:
10787 case elfcpp::R_MICROMIPS_LITERAL
:
10788 // Because we don't merge literal sections, we can handle this
10789 // just like R_MIPS_GPREL16. In the long run, we should merge
10790 // shared literals, and then we will need to additional work
10795 case elfcpp::R_MIPS_GPREL16
:
10796 case elfcpp::R_MIPS16_GPREL
:
10797 case elfcpp::R_MICROMIPS_GPREL7_S2
:
10798 case elfcpp::R_MICROMIPS_GPREL16
:
10799 reloc_status
= Reloc_funcs::relgprel(view
, object
, psymval
,
10800 target
->adjusted_gp_value(object
),
10801 r_addend
, extract_addend
,
10802 gsym
== NULL
, r_types
[i
],
10803 calculate_only
, &calculated_value
);
10806 case elfcpp::R_MIPS_PC16
:
10807 reloc_status
= Reloc_funcs::relpc16(view
, object
, psymval
, address
,
10808 r_addend
, extract_addend
,
10810 &calculated_value
);
10812 case elfcpp::R_MICROMIPS_PC7_S1
:
10813 reloc_status
= Reloc_funcs::relmicromips_pc7_s1(view
, object
, psymval
,
10817 &calculated_value
);
10819 case elfcpp::R_MICROMIPS_PC10_S1
:
10820 reloc_status
= Reloc_funcs::relmicromips_pc10_s1(view
, object
,
10822 r_addend
, extract_addend
,
10824 &calculated_value
);
10826 case elfcpp::R_MICROMIPS_PC16_S1
:
10827 reloc_status
= Reloc_funcs::relmicromips_pc16_s1(view
, object
,
10829 r_addend
, extract_addend
,
10831 &calculated_value
);
10833 case elfcpp::R_MIPS_GPREL32
:
10834 reloc_status
= Reloc_funcs::relgprel32(view
, object
, psymval
,
10835 target
->adjusted_gp_value(object
),
10836 r_addend
, extract_addend
,
10838 &calculated_value
);
10840 case elfcpp::R_MIPS_GOT_HI16
:
10841 case elfcpp::R_MIPS_CALL_HI16
:
10842 case elfcpp::R_MICROMIPS_GOT_HI16
:
10843 case elfcpp::R_MICROMIPS_CALL_HI16
:
10845 got_offset
= target
->got_section()->got_offset(gsym
,
10849 got_offset
= target
->got_section()->got_offset(r_sym
,
10852 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10853 reloc_status
= Reloc_funcs::relgot_hi16(view
, gp_offset
,
10855 &calculated_value
);
10856 update_got_entry
= changed_symbol_value
;
10859 case elfcpp::R_MIPS_GOT_LO16
:
10860 case elfcpp::R_MIPS_CALL_LO16
:
10861 case elfcpp::R_MICROMIPS_GOT_LO16
:
10862 case elfcpp::R_MICROMIPS_CALL_LO16
:
10864 got_offset
= target
->got_section()->got_offset(gsym
,
10868 got_offset
= target
->got_section()->got_offset(r_sym
,
10871 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10872 reloc_status
= Reloc_funcs::relgot_lo16(view
, gp_offset
,
10874 &calculated_value
);
10875 update_got_entry
= changed_symbol_value
;
10878 case elfcpp::R_MIPS_GOT_DISP
:
10879 case elfcpp::R_MICROMIPS_GOT_DISP
:
10880 case elfcpp::R_MIPS_EH
:
10882 got_offset
= target
->got_section()->got_offset(gsym
,
10886 got_offset
= target
->got_section()->got_offset(r_sym
,
10889 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10890 if (eh_reloc(r_types
[i
]))
10891 reloc_status
= Reloc_funcs::releh(view
, gp_offset
,
10893 &calculated_value
);
10895 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
10897 &calculated_value
);
10899 case elfcpp::R_MIPS_CALL16
:
10900 case elfcpp::R_MIPS16_CALL16
:
10901 case elfcpp::R_MICROMIPS_CALL16
:
10902 gold_assert(gsym
!= NULL
);
10903 got_offset
= target
->got_section()->got_offset(gsym
,
10906 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10907 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
10908 calculate_only
, &calculated_value
);
10909 // TODO(sasa): We should also initialize update_got_entry
10910 // in other place swhere relgot is called.
10911 update_got_entry
= changed_symbol_value
;
10914 case elfcpp::R_MIPS_GOT16
:
10915 case elfcpp::R_MIPS16_GOT16
:
10916 case elfcpp::R_MICROMIPS_GOT16
:
10919 got_offset
= target
->got_section()->got_offset(gsym
,
10922 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10923 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
,
10925 &calculated_value
);
10929 if (rel_type
== elfcpp::SHT_RELA
)
10930 reloc_status
= Reloc_funcs::do_relgot16_local(view
, object
,
10935 &calculated_value
);
10936 else if (rel_type
== elfcpp::SHT_REL
)
10937 reloc_status
= Reloc_funcs::relgot16_local(view
, object
,
10940 r_types
[i
], r_sym
);
10942 gold_unreachable();
10944 update_got_entry
= changed_symbol_value
;
10947 case elfcpp::R_MIPS_TLS_GD
:
10948 case elfcpp::R_MIPS16_TLS_GD
:
10949 case elfcpp::R_MICROMIPS_TLS_GD
:
10951 got_offset
= target
->got_section()->got_offset(gsym
,
10955 got_offset
= target
->got_section()->got_offset(r_sym
,
10958 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10959 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
10960 &calculated_value
);
10963 case elfcpp::R_MIPS_TLS_GOTTPREL
:
10964 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
10965 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
10967 got_offset
= target
->got_section()->got_offset(gsym
,
10968 GOT_TYPE_TLS_OFFSET
,
10971 got_offset
= target
->got_section()->got_offset(r_sym
,
10972 GOT_TYPE_TLS_OFFSET
,
10974 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10975 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
10976 &calculated_value
);
10979 case elfcpp::R_MIPS_TLS_LDM
:
10980 case elfcpp::R_MIPS16_TLS_LDM
:
10981 case elfcpp::R_MICROMIPS_TLS_LDM
:
10982 // Relocate the field with the offset of the GOT entry for
10983 // the module index.
10984 got_offset
= target
->got_section()->tls_ldm_offset(object
);
10985 gp_offset
= target
->got_section()->gp_offset(got_offset
, object
);
10986 reloc_status
= Reloc_funcs::relgot(view
, gp_offset
, calculate_only
,
10987 &calculated_value
);
10990 case elfcpp::R_MIPS_GOT_PAGE
:
10991 case elfcpp::R_MICROMIPS_GOT_PAGE
:
10992 reloc_status
= Reloc_funcs::relgotpage(target
, view
, object
, psymval
,
10993 r_addend
, extract_addend
,
10995 &calculated_value
);
10998 case elfcpp::R_MIPS_GOT_OFST
:
10999 case elfcpp::R_MICROMIPS_GOT_OFST
:
11000 reloc_status
= Reloc_funcs::relgotofst(target
, view
, object
, psymval
,
11001 r_addend
, extract_addend
,
11002 local
, calculate_only
,
11003 &calculated_value
);
11006 case elfcpp::R_MIPS_JALR
:
11007 case elfcpp::R_MICROMIPS_JALR
:
11008 // This relocation is only a hint. In some cases, we optimize
11009 // it into a bal instruction. But we don't try to optimize
11010 // when the symbol does not resolve locally.
11012 || symbol_calls_local(gsym
, gsym
->has_dynsym_index()))
11013 reloc_status
= Reloc_funcs::reljalr(view
, object
, psymval
, address
,
11014 r_addend
, extract_addend
,
11015 cross_mode_jump
, r_types
[i
],
11016 target
->jalr_to_bal(),
11019 &calculated_value
);
11022 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
11023 case elfcpp::R_MIPS16_TLS_DTPREL_HI16
:
11024 case elfcpp::R_MICROMIPS_TLS_DTPREL_HI16
:
11025 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
11026 elfcpp::DTP_OFFSET
, r_addend
,
11027 extract_addend
, calculate_only
,
11028 &calculated_value
);
11030 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
11031 case elfcpp::R_MIPS16_TLS_DTPREL_LO16
:
11032 case elfcpp::R_MICROMIPS_TLS_DTPREL_LO16
:
11033 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
11034 elfcpp::DTP_OFFSET
, r_addend
,
11035 extract_addend
, calculate_only
,
11036 &calculated_value
);
11038 case elfcpp::R_MIPS_TLS_DTPREL32
:
11039 case elfcpp::R_MIPS_TLS_DTPREL64
:
11040 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
11041 elfcpp::DTP_OFFSET
, r_addend
,
11042 extract_addend
, calculate_only
,
11043 &calculated_value
);
11045 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
11046 case elfcpp::R_MIPS16_TLS_TPREL_HI16
:
11047 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
11048 reloc_status
= Reloc_funcs::tlsrelhi16(view
, object
, psymval
,
11049 elfcpp::TP_OFFSET
, r_addend
,
11050 extract_addend
, calculate_only
,
11051 &calculated_value
);
11053 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
11054 case elfcpp::R_MIPS16_TLS_TPREL_LO16
:
11055 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
11056 reloc_status
= Reloc_funcs::tlsrello16(view
, object
, psymval
,
11057 elfcpp::TP_OFFSET
, r_addend
,
11058 extract_addend
, calculate_only
,
11059 &calculated_value
);
11061 case elfcpp::R_MIPS_TLS_TPREL32
:
11062 case elfcpp::R_MIPS_TLS_TPREL64
:
11063 reloc_status
= Reloc_funcs::tlsrel32(view
, object
, psymval
,
11064 elfcpp::TP_OFFSET
, r_addend
,
11065 extract_addend
, calculate_only
,
11066 &calculated_value
);
11068 case elfcpp::R_MIPS_SUB
:
11069 case elfcpp::R_MICROMIPS_SUB
:
11070 reloc_status
= Reloc_funcs::relsub(view
, object
, psymval
, r_addend
,
11072 calculate_only
, &calculated_value
);
11075 gold_error_at_location(relinfo
, relnum
, r_offset
,
11076 _("unsupported reloc %u"), r_types
[i
]);
11080 if (update_got_entry
)
11082 Mips_output_data_got
<size
, big_endian
>* got
= target
->got_section();
11083 if (mips_sym
!= NULL
&& mips_sym
->get_applied_secondary_got_fixup())
11084 got
->update_got_entry(got
->get_primary_got_offset(mips_sym
),
11085 psymval
->value(object
, 0));
11087 got
->update_got_entry(got_offset
, psymval
->value(object
, 0));
11090 r_addend
= calculated_value
;
11093 bool jal_shuffle
= jal_reloc(r_type
) ? !parameters
->options().relocatable()
11095 Reloc_funcs::mips_reloc_shuffle(view
, r_type
, jal_shuffle
);
11097 // Report any errors.
11098 switch (reloc_status
)
11100 case Reloc_funcs::STATUS_OKAY
:
11102 case Reloc_funcs::STATUS_OVERFLOW
:
11103 gold_error_at_location(relinfo
, relnum
, r_offset
,
11104 _("relocation overflow"));
11106 case Reloc_funcs::STATUS_BAD_RELOC
:
11107 gold_error_at_location(relinfo
, relnum
, r_offset
,
11108 _("unexpected opcode while processing relocation"));
11111 gold_unreachable();
11117 // Get the Reference_flags for a particular relocation.
11119 template<int size
, bool big_endian
>
11121 Target_mips
<size
, big_endian
>::Scan::get_reference_flags(
11122 unsigned int r_type
)
11126 case elfcpp::R_MIPS_NONE
:
11127 // No symbol reference.
11130 case elfcpp::R_MIPS_16
:
11131 case elfcpp::R_MIPS_32
:
11132 case elfcpp::R_MIPS_64
:
11133 case elfcpp::R_MIPS_HI16
:
11134 case elfcpp::R_MIPS_LO16
:
11135 case elfcpp::R_MIPS16_HI16
:
11136 case elfcpp::R_MIPS16_LO16
:
11137 case elfcpp::R_MICROMIPS_HI16
:
11138 case elfcpp::R_MICROMIPS_LO16
:
11139 return Symbol::ABSOLUTE_REF
;
11141 case elfcpp::R_MIPS_26
:
11142 case elfcpp::R_MIPS16_26
:
11143 case elfcpp::R_MICROMIPS_26_S1
:
11144 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
11146 case elfcpp::R_MIPS_GPREL32
:
11147 case elfcpp::R_MIPS_GPREL16
:
11148 case elfcpp::R_MIPS_REL32
:
11149 case elfcpp::R_MIPS16_GPREL
:
11150 return Symbol::RELATIVE_REF
;
11152 case elfcpp::R_MIPS_PC16
:
11153 case elfcpp::R_MIPS_PC32
:
11154 case elfcpp::R_MIPS_JALR
:
11155 case elfcpp::R_MICROMIPS_JALR
:
11156 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
11158 case elfcpp::R_MIPS_GOT16
:
11159 case elfcpp::R_MIPS_CALL16
:
11160 case elfcpp::R_MIPS_GOT_DISP
:
11161 case elfcpp::R_MIPS_GOT_HI16
:
11162 case elfcpp::R_MIPS_GOT_LO16
:
11163 case elfcpp::R_MIPS_CALL_HI16
:
11164 case elfcpp::R_MIPS_CALL_LO16
:
11165 case elfcpp::R_MIPS_LITERAL
:
11166 case elfcpp::R_MIPS_GOT_PAGE
:
11167 case elfcpp::R_MIPS_GOT_OFST
:
11168 case elfcpp::R_MIPS16_GOT16
:
11169 case elfcpp::R_MIPS16_CALL16
:
11170 case elfcpp::R_MICROMIPS_GOT16
:
11171 case elfcpp::R_MICROMIPS_CALL16
:
11172 case elfcpp::R_MICROMIPS_GOT_HI16
:
11173 case elfcpp::R_MICROMIPS_GOT_LO16
:
11174 case elfcpp::R_MICROMIPS_CALL_HI16
:
11175 case elfcpp::R_MICROMIPS_CALL_LO16
:
11176 case elfcpp::R_MIPS_EH
:
11177 // Absolute in GOT.
11178 return Symbol::RELATIVE_REF
;
11180 case elfcpp::R_MIPS_TLS_DTPMOD32
:
11181 case elfcpp::R_MIPS_TLS_DTPREL32
:
11182 case elfcpp::R_MIPS_TLS_DTPMOD64
:
11183 case elfcpp::R_MIPS_TLS_DTPREL64
:
11184 case elfcpp::R_MIPS_TLS_GD
:
11185 case elfcpp::R_MIPS_TLS_LDM
:
11186 case elfcpp::R_MIPS_TLS_DTPREL_HI16
:
11187 case elfcpp::R_MIPS_TLS_DTPREL_LO16
:
11188 case elfcpp::R_MIPS_TLS_GOTTPREL
:
11189 case elfcpp::R_MIPS_TLS_TPREL32
:
11190 case elfcpp::R_MIPS_TLS_TPREL64
:
11191 case elfcpp::R_MIPS_TLS_TPREL_HI16
:
11192 case elfcpp::R_MIPS_TLS_TPREL_LO16
:
11193 case elfcpp::R_MIPS16_TLS_GD
:
11194 case elfcpp::R_MIPS16_TLS_GOTTPREL
:
11195 case elfcpp::R_MICROMIPS_TLS_GD
:
11196 case elfcpp::R_MICROMIPS_TLS_GOTTPREL
:
11197 case elfcpp::R_MICROMIPS_TLS_TPREL_HI16
:
11198 case elfcpp::R_MICROMIPS_TLS_TPREL_LO16
:
11199 return Symbol::TLS_REF
;
11201 case elfcpp::R_MIPS_COPY
:
11202 case elfcpp::R_MIPS_JUMP_SLOT
:
11204 gold_unreachable();
11205 // Not expected. We will give an error later.
11210 // Report an unsupported relocation against a local symbol.
11212 template<int size
, bool big_endian
>
11214 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_local(
11215 Sized_relobj_file
<size
, big_endian
>* object
,
11216 unsigned int r_type
)
11218 gold_error(_("%s: unsupported reloc %u against local symbol"),
11219 object
->name().c_str(), r_type
);
11222 // Report an unsupported relocation against a global symbol.
11224 template<int size
, bool big_endian
>
11226 Target_mips
<size
, big_endian
>::Scan::unsupported_reloc_global(
11227 Sized_relobj_file
<size
, big_endian
>* object
,
11228 unsigned int r_type
,
11231 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
11232 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
11235 // Return printable name for ABI.
11236 template<int size
, bool big_endian
>
11238 Target_mips
<size
, big_endian
>::elf_mips_abi_name(elfcpp::Elf_Word e_flags
)
11240 switch (e_flags
& elfcpp::EF_MIPS_ABI
)
11243 if ((e_flags
& elfcpp::EF_MIPS_ABI2
) != 0)
11245 else if (size
== 64)
11249 case elfcpp::E_MIPS_ABI_O32
:
11251 case elfcpp::E_MIPS_ABI_O64
:
11253 case elfcpp::E_MIPS_ABI_EABI32
:
11255 case elfcpp::E_MIPS_ABI_EABI64
:
11258 return "unknown abi";
11262 template<int size
, bool big_endian
>
11264 Target_mips
<size
, big_endian
>::elf_mips_mach_name(elfcpp::Elf_Word e_flags
)
11266 switch (e_flags
& elfcpp::EF_MIPS_MACH
)
11268 case elfcpp::E_MIPS_MACH_3900
:
11269 return "mips:3900";
11270 case elfcpp::E_MIPS_MACH_4010
:
11271 return "mips:4010";
11272 case elfcpp::E_MIPS_MACH_4100
:
11273 return "mips:4100";
11274 case elfcpp::E_MIPS_MACH_4111
:
11275 return "mips:4111";
11276 case elfcpp::E_MIPS_MACH_4120
:
11277 return "mips:4120";
11278 case elfcpp::E_MIPS_MACH_4650
:
11279 return "mips:4650";
11280 case elfcpp::E_MIPS_MACH_5400
:
11281 return "mips:5400";
11282 case elfcpp::E_MIPS_MACH_5500
:
11283 return "mips:5500";
11284 case elfcpp::E_MIPS_MACH_SB1
:
11286 case elfcpp::E_MIPS_MACH_9000
:
11287 return "mips:9000";
11288 case elfcpp::E_MIPS_MACH_LS2E
:
11289 return "mips:loongson-2e";
11290 case elfcpp::E_MIPS_MACH_LS2F
:
11291 return "mips:loongson-2f";
11292 case elfcpp::E_MIPS_MACH_LS3A
:
11293 return "mips:loongson-3a";
11294 case elfcpp::E_MIPS_MACH_OCTEON
:
11295 return "mips:octeon";
11296 case elfcpp::E_MIPS_MACH_OCTEON2
:
11297 return "mips:octeon2";
11298 case elfcpp::E_MIPS_MACH_XLR
:
11301 switch (e_flags
& elfcpp::EF_MIPS_ARCH
)
11304 case elfcpp::E_MIPS_ARCH_1
:
11305 return "mips:3000";
11307 case elfcpp::E_MIPS_ARCH_2
:
11308 return "mips:6000";
11310 case elfcpp::E_MIPS_ARCH_3
:
11311 return "mips:4000";
11313 case elfcpp::E_MIPS_ARCH_4
:
11314 return "mips:8000";
11316 case elfcpp::E_MIPS_ARCH_5
:
11317 return "mips:mips5";
11319 case elfcpp::E_MIPS_ARCH_32
:
11320 return "mips:isa32";
11322 case elfcpp::E_MIPS_ARCH_64
:
11323 return "mips:isa64";
11325 case elfcpp::E_MIPS_ARCH_32R2
:
11326 return "mips:isa32r2";
11328 case elfcpp::E_MIPS_ARCH_64R2
:
11329 return "mips:isa64r2";
11332 return "unknown CPU";
11335 template<int size
, bool big_endian
>
11336 const Target::Target_info Target_mips
<size
, big_endian
>::mips_info
=
11339 big_endian
, // is_big_endian
11340 elfcpp::EM_MIPS
, // machine_code
11341 true, // has_make_symbol
11342 false, // has_resolve
11343 false, // has_code_fill
11344 true, // is_default_stack_executable
11345 false, // can_icf_inline_merge_sections
11347 size
== 32 ? "/lib/ld.so.1" : "/lib64/ld.so.1", // dynamic_linker
11348 0x400000, // default_text_segment_address
11349 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
11350 4 * 1024, // common_pagesize (overridable by -z common-page-size)
11351 false, // isolate_execinstr
11352 0, // rosegment_gap
11353 elfcpp::SHN_UNDEF
, // small_common_shndx
11354 elfcpp::SHN_UNDEF
, // large_common_shndx
11355 0, // small_common_section_flags
11356 0, // large_common_section_flags
11357 NULL
, // attributes_section
11358 NULL
, // attributes_vendor
11359 "__start", // entry_symbol_name
11360 32, // hash_entry_size
11363 template<int size
, bool big_endian
>
11364 class Target_mips_nacl
: public Target_mips
<size
, big_endian
>
11368 : Target_mips
<size
, big_endian
>(&mips_nacl_info
)
11372 static const Target::Target_info mips_nacl_info
;
11375 template<int size
, bool big_endian
>
11376 const Target::Target_info Target_mips_nacl
<size
, big_endian
>::mips_nacl_info
=
11379 big_endian
, // is_big_endian
11380 elfcpp::EM_MIPS
, // machine_code
11381 true, // has_make_symbol
11382 false, // has_resolve
11383 false, // has_code_fill
11384 true, // is_default_stack_executable
11385 false, // can_icf_inline_merge_sections
11387 "/lib/ld.so.1", // dynamic_linker
11388 0x20000, // default_text_segment_address
11389 0x10000, // abi_pagesize (overridable by -z max-page-size)
11390 0x10000, // common_pagesize (overridable by -z common-page-size)
11391 true, // isolate_execinstr
11392 0x10000000, // rosegment_gap
11393 elfcpp::SHN_UNDEF
, // small_common_shndx
11394 elfcpp::SHN_UNDEF
, // large_common_shndx
11395 0, // small_common_section_flags
11396 0, // large_common_section_flags
11397 NULL
, // attributes_section
11398 NULL
, // attributes_vendor
11399 "_start", // entry_symbol_name
11400 32, // hash_entry_size
11403 // Target selector for Mips. Note this is never instantiated directly.
11404 // It's only used in Target_selector_mips_nacl, below.
11406 template<int size
, bool big_endian
>
11407 class Target_selector_mips
: public Target_selector
11410 Target_selector_mips()
11411 : Target_selector(elfcpp::EM_MIPS
, size
, big_endian
,
11413 (big_endian
? "elf64-tradbigmips" : "elf64-tradlittlemips") :
11414 (big_endian
? "elf32-tradbigmips" : "elf32-tradlittlemips")),
11416 (big_endian
? "elf64btsmip" : "elf64ltsmip") :
11417 (big_endian
? "elf32btsmip" : "elf32ltsmip")))
11420 Target
* do_instantiate_target()
11421 { return new Target_mips
<size
, big_endian
>(); }
11424 template<int size
, bool big_endian
>
11425 class Target_selector_mips_nacl
11426 : public Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
11427 Target_mips_nacl
<size
, big_endian
> >
11430 Target_selector_mips_nacl()
11431 : Target_selector_nacl
<Target_selector_mips
<size
, big_endian
>,
11432 Target_mips_nacl
<size
, big_endian
> >(
11433 // NaCl currently supports only MIPS32 little-endian.
11434 "mipsel", "elf32-tradlittlemips-nacl", "elf32-tradlittlemips-nacl")
11438 Target_selector_mips_nacl
<32, true> target_selector_mips32
;
11439 Target_selector_mips_nacl
<32, false> target_selector_mips32el
;
11440 Target_selector_mips_nacl
<64, true> target_selector_mips64
;
11441 Target_selector_mips_nacl
<64, false> target_selector_mips64el
;
11443 } // End anonymous namespace.