1 /* MIPS-specific support for ELF
2 Copyright (C) 1993-2018 Free Software Foundation, Inc.
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
6 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
7 <mark@codesourcery.com>
8 Traditional MIPS targets support added by Koundinya.K, Dansk Data
9 Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
11 This file is part of BFD, the Binary File Descriptor library.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
26 MA 02110-1301, USA. */
29 /* This file handles functionality common to the different MIPS ABI's. */
34 #include "libiberty.h"
36 #include "elfxx-mips.h"
38 #include "elf-vxworks.h"
41 /* Get the ECOFF swapping routines. */
43 #include "coff/symconst.h"
44 #include "coff/ecoff.h"
45 #include "coff/mips.h"
49 /* Types of TLS GOT entry. */
50 enum mips_got_tls_type
{
57 /* This structure is used to hold information about one GOT entry.
58 There are four types of entry:
60 (1) an absolute address
61 requires: abfd == NULL
64 (2) a SYMBOL + OFFSET address, where SYMBOL is local to an input bfd
65 requires: abfd != NULL, symndx >= 0, tls_type != GOT_TLS_LDM
66 fields: abfd, symndx, d.addend, tls_type
68 (3) a SYMBOL address, where SYMBOL is not local to an input bfd
69 requires: abfd != NULL, symndx == -1
73 requires: abfd != NULL, symndx == 0, tls_type == GOT_TLS_LDM
74 fields: none; there's only one of these per GOT. */
77 /* One input bfd that needs the GOT entry. */
79 /* The index of the symbol, as stored in the relocation r_info, if
80 we have a local symbol; -1 otherwise. */
84 /* If abfd == NULL, an address that must be stored in the got. */
86 /* If abfd != NULL && symndx != -1, the addend of the relocation
87 that should be added to the symbol value. */
89 /* If abfd != NULL && symndx == -1, the hash table entry
90 corresponding to a symbol in the GOT. The symbol's entry
91 is in the local area if h->global_got_area is GGA_NONE,
92 otherwise it is in the global area. */
93 struct mips_elf_link_hash_entry
*h
;
96 /* The TLS type of this GOT entry. An LDM GOT entry will be a local
97 symbol entry with r_symndx == 0. */
98 unsigned char tls_type
;
100 /* True if we have filled in the GOT contents for a TLS entry,
101 and created the associated relocations. */
102 unsigned char tls_initialized
;
104 /* The offset from the beginning of the .got section to the entry
105 corresponding to this symbol+addend. If it's a global symbol
106 whose offset is yet to be decided, it's going to be -1. */
110 /* This structure represents a GOT page reference from an input bfd.
111 Each instance represents a symbol + ADDEND, where the representation
112 of the symbol depends on whether it is local to the input bfd.
113 If it is, then SYMNDX >= 0, and the symbol has index SYMNDX in U.ABFD.
114 Otherwise, SYMNDX < 0 and U.H points to the symbol's hash table entry.
116 Page references with SYMNDX >= 0 always become page references
117 in the output. Page references with SYMNDX < 0 only become page
118 references if the symbol binds locally; in other cases, the page
119 reference decays to a global GOT reference. */
120 struct mips_got_page_ref
125 struct mips_elf_link_hash_entry
*h
;
131 /* This structure describes a range of addends: [MIN_ADDEND, MAX_ADDEND].
132 The structures form a non-overlapping list that is sorted by increasing
134 struct mips_got_page_range
136 struct mips_got_page_range
*next
;
137 bfd_signed_vma min_addend
;
138 bfd_signed_vma max_addend
;
141 /* This structure describes the range of addends that are applied to page
142 relocations against a given section. */
143 struct mips_got_page_entry
145 /* The section that these entries are based on. */
147 /* The ranges for this page entry. */
148 struct mips_got_page_range
*ranges
;
149 /* The maximum number of page entries needed for RANGES. */
153 /* This structure is used to hold .got information when linking. */
157 /* The number of global .got entries. */
158 unsigned int global_gotno
;
159 /* The number of global .got entries that are in the GGA_RELOC_ONLY area. */
160 unsigned int reloc_only_gotno
;
161 /* The number of .got slots used for TLS. */
162 unsigned int tls_gotno
;
163 /* The first unused TLS .got entry. Used only during
164 mips_elf_initialize_tls_index. */
165 unsigned int tls_assigned_gotno
;
166 /* The number of local .got entries, eventually including page entries. */
167 unsigned int local_gotno
;
168 /* The maximum number of page entries needed. */
169 unsigned int page_gotno
;
170 /* The number of relocations needed for the GOT entries. */
172 /* The first unused local .got entry. */
173 unsigned int assigned_low_gotno
;
174 /* The last unused local .got entry. */
175 unsigned int assigned_high_gotno
;
176 /* A hash table holding members of the got. */
177 struct htab
*got_entries
;
178 /* A hash table holding mips_got_page_ref structures. */
179 struct htab
*got_page_refs
;
180 /* A hash table of mips_got_page_entry structures. */
181 struct htab
*got_page_entries
;
182 /* In multi-got links, a pointer to the next got (err, rather, most
183 of the time, it points to the previous got). */
184 struct mips_got_info
*next
;
187 /* Structure passed when merging bfds' gots. */
189 struct mips_elf_got_per_bfd_arg
191 /* The output bfd. */
193 /* The link information. */
194 struct bfd_link_info
*info
;
195 /* A pointer to the primary got, i.e., the one that's going to get
196 the implicit relocations from DT_MIPS_LOCAL_GOTNO and
198 struct mips_got_info
*primary
;
199 /* A non-primary got we're trying to merge with other input bfd's
201 struct mips_got_info
*current
;
202 /* The maximum number of got entries that can be addressed with a
204 unsigned int max_count
;
205 /* The maximum number of page entries needed by each got. */
206 unsigned int max_pages
;
207 /* The total number of global entries which will live in the
208 primary got and be automatically relocated. This includes
209 those not referenced by the primary GOT but included in
211 unsigned int global_count
;
214 /* A structure used to pass information to htab_traverse callbacks
215 when laying out the GOT. */
217 struct mips_elf_traverse_got_arg
219 struct bfd_link_info
*info
;
220 struct mips_got_info
*g
;
224 struct _mips_elf_section_data
226 struct bfd_elf_section_data elf
;
233 #define mips_elf_section_data(sec) \
234 ((struct _mips_elf_section_data *) elf_section_data (sec))
236 #define is_mips_elf(bfd) \
237 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
238 && elf_tdata (bfd) != NULL \
239 && elf_object_id (bfd) == MIPS_ELF_DATA)
241 /* The ABI says that every symbol used by dynamic relocations must have
242 a global GOT entry. Among other things, this provides the dynamic
243 linker with a free, directly-indexed cache. The GOT can therefore
244 contain symbols that are not referenced by GOT relocations themselves
245 (in other words, it may have symbols that are not referenced by things
246 like R_MIPS_GOT16 and R_MIPS_GOT_PAGE).
248 GOT relocations are less likely to overflow if we put the associated
249 GOT entries towards the beginning. We therefore divide the global
250 GOT entries into two areas: "normal" and "reloc-only". Entries in
251 the first area can be used for both dynamic relocations and GP-relative
252 accesses, while those in the "reloc-only" area are for dynamic
255 These GGA_* ("Global GOT Area") values are organised so that lower
256 values are more general than higher values. Also, non-GGA_NONE
257 values are ordered by the position of the area in the GOT. */
259 #define GGA_RELOC_ONLY 1
262 /* Information about a non-PIC interface to a PIC function. There are
263 two ways of creating these interfaces. The first is to add:
266 addiu $25,$25,%lo(func)
268 immediately before a PIC function "func". The second is to add:
272 addiu $25,$25,%lo(func)
274 to a separate trampoline section.
276 Stubs of the first kind go in a new section immediately before the
277 target function. Stubs of the second kind go in a single section
278 pointed to by the hash table's "strampoline" field. */
279 struct mips_elf_la25_stub
{
280 /* The generated section that contains this stub. */
281 asection
*stub_section
;
283 /* The offset of the stub from the start of STUB_SECTION. */
286 /* One symbol for the original function. Its location is available
287 in H->root.root.u.def. */
288 struct mips_elf_link_hash_entry
*h
;
291 /* Macros for populating a mips_elf_la25_stub. */
293 #define LA25_LUI(VAL) (0x3c190000 | (VAL)) /* lui t9,VAL */
294 #define LA25_J(VAL) (0x08000000 | (((VAL) >> 2) & 0x3ffffff)) /* j VAL */
295 #define LA25_ADDIU(VAL) (0x27390000 | (VAL)) /* addiu t9,t9,VAL */
296 #define LA25_LUI_MICROMIPS(VAL) \
297 (0x41b90000 | (VAL)) /* lui t9,VAL */
298 #define LA25_J_MICROMIPS(VAL) \
299 (0xd4000000 | (((VAL) >> 1) & 0x3ffffff)) /* j VAL */
300 #define LA25_ADDIU_MICROMIPS(VAL) \
301 (0x33390000 | (VAL)) /* addiu t9,t9,VAL */
303 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
304 the dynamic symbols. */
306 struct mips_elf_hash_sort_data
308 /* The symbol in the global GOT with the lowest dynamic symbol table
310 struct elf_link_hash_entry
*low
;
311 /* The least dynamic symbol table index corresponding to a non-TLS
312 symbol with a GOT entry. */
313 bfd_size_type min_got_dynindx
;
314 /* The greatest dynamic symbol table index corresponding to a symbol
315 with a GOT entry that is not referenced (e.g., a dynamic symbol
316 with dynamic relocations pointing to it from non-primary GOTs). */
317 bfd_size_type max_unref_got_dynindx
;
318 /* The greatest dynamic symbol table index corresponding to a local
320 bfd_size_type max_local_dynindx
;
321 /* The greatest dynamic symbol table index corresponding to an external
322 symbol without a GOT entry. */
323 bfd_size_type max_non_got_dynindx
;
326 /* We make up to two PLT entries if needed, one for standard MIPS code
327 and one for compressed code, either a MIPS16 or microMIPS one. We
328 keep a separate record of traditional lazy-binding stubs, for easier
333 /* Traditional SVR4 stub offset, or -1 if none. */
336 /* Standard PLT entry offset, or -1 if none. */
339 /* Compressed PLT entry offset, or -1 if none. */
342 /* The corresponding .got.plt index, or -1 if none. */
343 bfd_vma gotplt_index
;
345 /* Whether we need a standard PLT entry. */
346 unsigned int need_mips
: 1;
348 /* Whether we need a compressed PLT entry. */
349 unsigned int need_comp
: 1;
352 /* The MIPS ELF linker needs additional information for each symbol in
353 the global hash table. */
355 struct mips_elf_link_hash_entry
357 struct elf_link_hash_entry root
;
359 /* External symbol information. */
362 /* The la25 stub we have created for ths symbol, if any. */
363 struct mips_elf_la25_stub
*la25_stub
;
365 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
367 unsigned int possibly_dynamic_relocs
;
369 /* If there is a stub that 32 bit functions should use to call this
370 16 bit function, this points to the section containing the stub. */
373 /* If there is a stub that 16 bit functions should use to call this
374 32 bit function, this points to the section containing the stub. */
377 /* This is like the call_stub field, but it is used if the function
378 being called returns a floating point value. */
379 asection
*call_fp_stub
;
381 /* The highest GGA_* value that satisfies all references to this symbol. */
382 unsigned int global_got_area
: 2;
384 /* True if all GOT relocations against this symbol are for calls. This is
385 a looser condition than no_fn_stub below, because there may be other
386 non-call non-GOT relocations against the symbol. */
387 unsigned int got_only_for_calls
: 1;
389 /* True if one of the relocations described by possibly_dynamic_relocs
390 is against a readonly section. */
391 unsigned int readonly_reloc
: 1;
393 /* True if there is a relocation against this symbol that must be
394 resolved by the static linker (in other words, if the relocation
395 cannot possibly be made dynamic). */
396 unsigned int has_static_relocs
: 1;
398 /* True if we must not create a .MIPS.stubs entry for this symbol.
399 This is set, for example, if there are relocations related to
400 taking the function's address, i.e. any but R_MIPS_CALL*16 ones.
401 See "MIPS ABI Supplement, 3rd Edition", p. 4-20. */
402 unsigned int no_fn_stub
: 1;
404 /* Whether we need the fn_stub; this is true if this symbol appears
405 in any relocs other than a 16 bit call. */
406 unsigned int need_fn_stub
: 1;
408 /* True if this symbol is referenced by branch relocations from
409 any non-PIC input file. This is used to determine whether an
410 la25 stub is required. */
411 unsigned int has_nonpic_branches
: 1;
413 /* Does this symbol need a traditional MIPS lazy-binding stub
414 (as opposed to a PLT entry)? */
415 unsigned int needs_lazy_stub
: 1;
417 /* Does this symbol resolve to a PLT entry? */
418 unsigned int use_plt_entry
: 1;
421 /* MIPS ELF linker hash table. */
423 struct mips_elf_link_hash_table
425 struct elf_link_hash_table root
;
427 /* The number of .rtproc entries. */
428 bfd_size_type procedure_count
;
430 /* The size of the .compact_rel section (if SGI_COMPAT). */
431 bfd_size_type compact_rel_size
;
433 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic entry
434 is set to the address of __rld_obj_head as in IRIX5 and IRIX6. */
435 bfd_boolean use_rld_obj_head
;
437 /* The __rld_map or __rld_obj_head symbol. */
438 struct elf_link_hash_entry
*rld_symbol
;
440 /* This is set if we see any mips16 stub sections. */
441 bfd_boolean mips16_stubs_seen
;
443 /* True if we can generate copy relocs and PLTs. */
444 bfd_boolean use_plts_and_copy_relocs
;
446 /* True if we can only use 32-bit microMIPS instructions. */
449 /* True if we suppress checks for invalid branches between ISA modes. */
450 bfd_boolean ignore_branch_isa
;
452 /* True if we're generating code for VxWorks. */
453 bfd_boolean is_vxworks
;
455 /* True if we already reported the small-data section overflow. */
456 bfd_boolean small_data_overflow_reported
;
458 /* True if we use the special `__gnu_absolute_zero' symbol. */
459 bfd_boolean use_absolute_zero
;
461 /* True if we have been configured for a GNU target. */
462 bfd_boolean gnu_target
;
464 /* Shortcuts to some dynamic sections, or NULL if they are not
469 /* The master GOT information. */
470 struct mips_got_info
*got_info
;
472 /* The global symbol in the GOT with the lowest index in the dynamic
474 struct elf_link_hash_entry
*global_gotsym
;
476 /* The size of the PLT header in bytes. */
477 bfd_vma plt_header_size
;
479 /* The size of a standard PLT entry in bytes. */
480 bfd_vma plt_mips_entry_size
;
482 /* The size of a compressed PLT entry in bytes. */
483 bfd_vma plt_comp_entry_size
;
485 /* The offset of the next standard PLT entry to create. */
486 bfd_vma plt_mips_offset
;
488 /* The offset of the next compressed PLT entry to create. */
489 bfd_vma plt_comp_offset
;
491 /* The index of the next .got.plt entry to create. */
492 bfd_vma plt_got_index
;
494 /* The number of functions that need a lazy-binding stub. */
495 bfd_vma lazy_stub_count
;
497 /* The size of a function stub entry in bytes. */
498 bfd_vma function_stub_size
;
500 /* The number of reserved entries at the beginning of the GOT. */
501 unsigned int reserved_gotno
;
503 /* The section used for mips_elf_la25_stub trampolines.
504 See the comment above that structure for details. */
505 asection
*strampoline
;
507 /* A table of mips_elf_la25_stubs, indexed by (input_section, offset)
511 /* A function FN (NAME, IS, OS) that creates a new input section
512 called NAME and links it to output section OS. If IS is nonnull,
513 the new section should go immediately before it, otherwise it
514 should go at the (current) beginning of OS.
516 The function returns the new section on success, otherwise it
518 asection
*(*add_stub_section
) (const char *, asection
*, asection
*);
520 /* Small local sym cache. */
521 struct sym_cache sym_cache
;
523 /* Is the PLT header compressed? */
524 unsigned int plt_header_is_comp
: 1;
527 /* Get the MIPS ELF linker hash table from a link_info structure. */
529 #define mips_elf_hash_table(p) \
530 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
531 == MIPS_ELF_DATA ? ((struct mips_elf_link_hash_table *) ((p)->hash)) : NULL)
533 /* A structure used to communicate with htab_traverse callbacks. */
534 struct mips_htab_traverse_info
536 /* The usual link-wide information. */
537 struct bfd_link_info
*info
;
540 /* Starts off FALSE and is set to TRUE if the link should be aborted. */
544 /* MIPS ELF private object data. */
546 struct mips_elf_obj_tdata
548 /* Generic ELF private object data. */
549 struct elf_obj_tdata root
;
551 /* Input BFD providing Tag_GNU_MIPS_ABI_FP attribute for output. */
554 /* Input BFD providing Tag_GNU_MIPS_ABI_MSA attribute for output. */
557 /* The abiflags for this object. */
558 Elf_Internal_ABIFlags_v0 abiflags
;
559 bfd_boolean abiflags_valid
;
561 /* The GOT requirements of input bfds. */
562 struct mips_got_info
*got
;
564 /* Used by _bfd_mips_elf_find_nearest_line. The structure could be
565 included directly in this one, but there's no point to wasting
566 the memory just for the infrequently called find_nearest_line. */
567 struct mips_elf_find_line
*find_line_info
;
569 /* An array of stub sections indexed by symbol number. */
570 asection
**local_stubs
;
571 asection
**local_call_stubs
;
573 /* The Irix 5 support uses two virtual sections, which represent
574 text/data symbols defined in dynamic objects. */
575 asymbol
*elf_data_symbol
;
576 asymbol
*elf_text_symbol
;
577 asection
*elf_data_section
;
578 asection
*elf_text_section
;
581 /* Get MIPS ELF private object data from BFD's tdata. */
583 #define mips_elf_tdata(bfd) \
584 ((struct mips_elf_obj_tdata *) (bfd)->tdata.any)
586 #define TLS_RELOC_P(r_type) \
587 (r_type == R_MIPS_TLS_DTPMOD32 \
588 || r_type == R_MIPS_TLS_DTPMOD64 \
589 || r_type == R_MIPS_TLS_DTPREL32 \
590 || r_type == R_MIPS_TLS_DTPREL64 \
591 || r_type == R_MIPS_TLS_GD \
592 || r_type == R_MIPS_TLS_LDM \
593 || r_type == R_MIPS_TLS_DTPREL_HI16 \
594 || r_type == R_MIPS_TLS_DTPREL_LO16 \
595 || r_type == R_MIPS_TLS_GOTTPREL \
596 || r_type == R_MIPS_TLS_TPREL32 \
597 || r_type == R_MIPS_TLS_TPREL64 \
598 || r_type == R_MIPS_TLS_TPREL_HI16 \
599 || r_type == R_MIPS_TLS_TPREL_LO16 \
600 || r_type == R_MIPS16_TLS_GD \
601 || r_type == R_MIPS16_TLS_LDM \
602 || r_type == R_MIPS16_TLS_DTPREL_HI16 \
603 || r_type == R_MIPS16_TLS_DTPREL_LO16 \
604 || r_type == R_MIPS16_TLS_GOTTPREL \
605 || r_type == R_MIPS16_TLS_TPREL_HI16 \
606 || r_type == R_MIPS16_TLS_TPREL_LO16 \
607 || r_type == R_MICROMIPS_TLS_GD \
608 || r_type == R_MICROMIPS_TLS_LDM \
609 || r_type == R_MICROMIPS_TLS_DTPREL_HI16 \
610 || r_type == R_MICROMIPS_TLS_DTPREL_LO16 \
611 || r_type == R_MICROMIPS_TLS_GOTTPREL \
612 || r_type == R_MICROMIPS_TLS_TPREL_HI16 \
613 || r_type == R_MICROMIPS_TLS_TPREL_LO16)
615 /* Structure used to pass information to mips_elf_output_extsym. */
620 struct bfd_link_info
*info
;
621 struct ecoff_debug_info
*debug
;
622 const struct ecoff_debug_swap
*swap
;
626 /* The names of the runtime procedure table symbols used on IRIX5. */
628 static const char * const mips_elf_dynsym_rtproc_names
[] =
631 "_procedure_string_table",
632 "_procedure_table_size",
636 /* These structures are used to generate the .compact_rel section on
641 unsigned long id1
; /* Always one? */
642 unsigned long num
; /* Number of compact relocation entries. */
643 unsigned long id2
; /* Always two? */
644 unsigned long offset
; /* The file offset of the first relocation. */
645 unsigned long reserved0
; /* Zero? */
646 unsigned long reserved1
; /* Zero? */
655 bfd_byte reserved0
[4];
656 bfd_byte reserved1
[4];
657 } Elf32_External_compact_rel
;
661 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
662 unsigned int rtype
: 4; /* Relocation types. See below. */
663 unsigned int dist2to
: 8;
664 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
665 unsigned long konst
; /* KONST field. See below. */
666 unsigned long vaddr
; /* VADDR to be relocated. */
671 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
672 unsigned int rtype
: 4; /* Relocation types. See below. */
673 unsigned int dist2to
: 8;
674 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
675 unsigned long konst
; /* KONST field. See below. */
683 } Elf32_External_crinfo
;
689 } Elf32_External_crinfo2
;
691 /* These are the constants used to swap the bitfields in a crinfo. */
693 #define CRINFO_CTYPE (0x1)
694 #define CRINFO_CTYPE_SH (31)
695 #define CRINFO_RTYPE (0xf)
696 #define CRINFO_RTYPE_SH (27)
697 #define CRINFO_DIST2TO (0xff)
698 #define CRINFO_DIST2TO_SH (19)
699 #define CRINFO_RELVADDR (0x7ffff)
700 #define CRINFO_RELVADDR_SH (0)
702 /* A compact relocation info has long (3 words) or short (2 words)
703 formats. A short format doesn't have VADDR field and relvaddr
704 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
705 #define CRF_MIPS_LONG 1
706 #define CRF_MIPS_SHORT 0
708 /* There are 4 types of compact relocation at least. The value KONST
709 has different meaning for each type:
712 CT_MIPS_REL32 Address in data
713 CT_MIPS_WORD Address in word (XXX)
714 CT_MIPS_GPHI_LO GP - vaddr
715 CT_MIPS_JMPAD Address to jump
718 #define CRT_MIPS_REL32 0xa
719 #define CRT_MIPS_WORD 0xb
720 #define CRT_MIPS_GPHI_LO 0xc
721 #define CRT_MIPS_JMPAD 0xd
723 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
724 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
725 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
726 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
728 /* The structure of the runtime procedure descriptor created by the
729 loader for use by the static exception system. */
731 typedef struct runtime_pdr
{
732 bfd_vma adr
; /* Memory address of start of procedure. */
733 long regmask
; /* Save register mask. */
734 long regoffset
; /* Save register offset. */
735 long fregmask
; /* Save floating point register mask. */
736 long fregoffset
; /* Save floating point register offset. */
737 long frameoffset
; /* Frame size. */
738 short framereg
; /* Frame pointer register. */
739 short pcreg
; /* Offset or reg of return pc. */
740 long irpss
; /* Index into the runtime string table. */
742 struct exception_info
*exception_info
;/* Pointer to exception array. */
744 #define cbRPDR sizeof (RPDR)
745 #define rpdNil ((pRPDR) 0)
747 static struct mips_got_entry
*mips_elf_create_local_got_entry
748 (bfd
*, struct bfd_link_info
*, bfd
*, bfd_vma
, unsigned long,
749 struct mips_elf_link_hash_entry
*, int);
750 static bfd_boolean mips_elf_sort_hash_table_f
751 (struct mips_elf_link_hash_entry
*, void *);
752 static bfd_vma mips_elf_high
754 static bfd_boolean mips_elf_create_dynamic_relocation
755 (bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
756 struct mips_elf_link_hash_entry
*, asection
*, bfd_vma
,
757 bfd_vma
*, asection
*);
758 static bfd_vma mips_elf_adjust_gp
759 (bfd
*, struct mips_got_info
*, bfd
*);
761 /* This will be used when we sort the dynamic relocation records. */
762 static bfd
*reldyn_sorting_bfd
;
764 /* True if ABFD is for CPUs with load interlocking that include
765 non-MIPS1 CPUs and R3900. */
766 #define LOAD_INTERLOCKS_P(abfd) \
767 ( ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) != E_MIPS_ARCH_1) \
768 || ((elf_elfheader (abfd)->e_flags & EF_MIPS_MACH) == E_MIPS_MACH_3900))
770 /* True if ABFD is for CPUs that are faster if JAL is converted to BAL.
771 This should be safe for all architectures. We enable this predicate
772 for RM9000 for now. */
773 #define JAL_TO_BAL_P(abfd) \
774 ((elf_elfheader (abfd)->e_flags & EF_MIPS_MACH) == E_MIPS_MACH_9000)
776 /* True if ABFD is for CPUs that are faster if JALR is converted to BAL.
777 This should be safe for all architectures. We enable this predicate for
779 #define JALR_TO_BAL_P(abfd) 1
781 /* True if ABFD is for CPUs that are faster if JR is converted to B.
782 This should be safe for all architectures. We enable this predicate for
784 #define JR_TO_B_P(abfd) 1
786 /* True if ABFD is a PIC object. */
787 #define PIC_OBJECT_P(abfd) \
788 ((elf_elfheader (abfd)->e_flags & EF_MIPS_PIC) != 0)
790 /* Nonzero if ABFD is using the O32 ABI. */
791 #define ABI_O32_P(abfd) \
792 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_O32)
794 /* Nonzero if ABFD is using the N32 ABI. */
795 #define ABI_N32_P(abfd) \
796 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
798 /* Nonzero if ABFD is using the N64 ABI. */
799 #define ABI_64_P(abfd) \
800 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
802 /* Nonzero if ABFD is using NewABI conventions. */
803 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
805 /* Nonzero if ABFD has microMIPS code. */
806 #define MICROMIPS_P(abfd) \
807 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH_ASE_MICROMIPS) != 0)
809 /* Nonzero if ABFD is MIPS R6. */
810 #define MIPSR6_P(abfd) \
811 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32R6 \
812 || (elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64R6)
814 /* The IRIX compatibility level we are striving for. */
815 #define IRIX_COMPAT(abfd) \
816 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
818 /* Whether we are trying to be compatible with IRIX at all. */
819 #define SGI_COMPAT(abfd) \
820 (IRIX_COMPAT (abfd) != ict_none)
822 /* The name of the options section. */
823 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
824 (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
826 /* True if NAME is the recognized name of any SHT_MIPS_OPTIONS section.
827 Some IRIX system files do not use MIPS_ELF_OPTIONS_SECTION_NAME. */
828 #define MIPS_ELF_OPTIONS_SECTION_NAME_P(NAME) \
829 (strcmp (NAME, ".MIPS.options") == 0 || strcmp (NAME, ".options") == 0)
831 /* True if NAME is the recognized name of any SHT_MIPS_ABIFLAGS section. */
832 #define MIPS_ELF_ABIFLAGS_SECTION_NAME_P(NAME) \
833 (strcmp (NAME, ".MIPS.abiflags") == 0)
835 /* Whether the section is readonly. */
836 #define MIPS_ELF_READONLY_SECTION(sec) \
837 ((sec->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) \
838 == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
840 /* The name of the stub section. */
841 #define MIPS_ELF_STUB_SECTION_NAME(abfd) ".MIPS.stubs"
843 /* The size of an external REL relocation. */
844 #define MIPS_ELF_REL_SIZE(abfd) \
845 (get_elf_backend_data (abfd)->s->sizeof_rel)
847 /* The size of an external RELA relocation. */
848 #define MIPS_ELF_RELA_SIZE(abfd) \
849 (get_elf_backend_data (abfd)->s->sizeof_rela)
851 /* The size of an external dynamic table entry. */
852 #define MIPS_ELF_DYN_SIZE(abfd) \
853 (get_elf_backend_data (abfd)->s->sizeof_dyn)
855 /* The size of a GOT entry. */
856 #define MIPS_ELF_GOT_SIZE(abfd) \
857 (get_elf_backend_data (abfd)->s->arch_size / 8)
859 /* The size of the .rld_map section. */
860 #define MIPS_ELF_RLD_MAP_SIZE(abfd) \
861 (get_elf_backend_data (abfd)->s->arch_size / 8)
863 /* The size of a symbol-table entry. */
864 #define MIPS_ELF_SYM_SIZE(abfd) \
865 (get_elf_backend_data (abfd)->s->sizeof_sym)
867 /* The default alignment for sections, as a power of two. */
868 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
869 (get_elf_backend_data (abfd)->s->log_file_align)
871 /* Get word-sized data. */
872 #define MIPS_ELF_GET_WORD(abfd, ptr) \
873 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
875 /* Put out word-sized data. */
876 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
878 ? bfd_put_64 (abfd, val, ptr) \
879 : bfd_put_32 (abfd, val, ptr))
881 /* The opcode for word-sized loads (LW or LD). */
882 #define MIPS_ELF_LOAD_WORD(abfd) \
883 (ABI_64_P (abfd) ? 0xdc000000 : 0x8c000000)
885 /* Add a dynamic symbol table-entry. */
886 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
887 _bfd_elf_add_dynamic_entry (info, tag, val)
889 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
890 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (abfd, rtype, rela))
892 /* The name of the dynamic relocation section. */
893 #define MIPS_ELF_REL_DYN_NAME(INFO) \
894 (mips_elf_hash_table (INFO)->is_vxworks ? ".rela.dyn" : ".rel.dyn")
896 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
897 from smaller values. Start with zero, widen, *then* decrement. */
898 #define MINUS_ONE (((bfd_vma)0) - 1)
899 #define MINUS_TWO (((bfd_vma)0) - 2)
901 /* The value to write into got[1] for SVR4 targets, to identify it is
902 a GNU object. The dynamic linker can then use got[1] to store the
904 #define MIPS_ELF_GNU_GOT1_MASK(abfd) \
905 ((bfd_vma) 1 << (ABI_64_P (abfd) ? 63 : 31))
907 /* The offset of $gp from the beginning of the .got section. */
908 #define ELF_MIPS_GP_OFFSET(INFO) \
909 (mips_elf_hash_table (INFO)->is_vxworks ? 0x0 : 0x7ff0)
911 /* The maximum size of the GOT for it to be addressable using 16-bit
913 #define MIPS_ELF_GOT_MAX_SIZE(INFO) (ELF_MIPS_GP_OFFSET (INFO) + 0x7fff)
915 /* Instructions which appear in a stub. */
916 #define STUB_LW(abfd) \
918 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
919 : 0x8f998010)) /* lw t9,0x8010(gp) */
920 #define STUB_MOVE 0x03e07825 /* or t7,ra,zero */
921 #define STUB_LUI(VAL) (0x3c180000 + (VAL)) /* lui t8,VAL */
922 #define STUB_JALR 0x0320f809 /* jalr ra,t9 */
923 #define STUB_ORI(VAL) (0x37180000 + (VAL)) /* ori t8,t8,VAL */
924 #define STUB_LI16U(VAL) (0x34180000 + (VAL)) /* ori t8,zero,VAL unsigned */
925 #define STUB_LI16S(abfd, VAL) \
927 ? (0x64180000 + (VAL)) /* daddiu t8,zero,VAL sign extended */ \
928 : (0x24180000 + (VAL)))) /* addiu t8,zero,VAL sign extended */
930 /* Likewise for the microMIPS ASE. */
931 #define STUB_LW_MICROMIPS(abfd) \
933 ? 0xdf3c8010 /* ld t9,0x8010(gp) */ \
934 : 0xff3c8010) /* lw t9,0x8010(gp) */
935 #define STUB_MOVE_MICROMIPS 0x0dff /* move t7,ra */
936 #define STUB_MOVE32_MICROMIPS 0x001f7a90 /* or t7,ra,zero */
937 #define STUB_LUI_MICROMIPS(VAL) \
938 (0x41b80000 + (VAL)) /* lui t8,VAL */
939 #define STUB_JALR_MICROMIPS 0x45d9 /* jalr t9 */
940 #define STUB_JALR32_MICROMIPS 0x03f90f3c /* jalr ra,t9 */
941 #define STUB_ORI_MICROMIPS(VAL) \
942 (0x53180000 + (VAL)) /* ori t8,t8,VAL */
943 #define STUB_LI16U_MICROMIPS(VAL) \
944 (0x53000000 + (VAL)) /* ori t8,zero,VAL unsigned */
945 #define STUB_LI16S_MICROMIPS(abfd, VAL) \
947 ? 0x5f000000 + (VAL) /* daddiu t8,zero,VAL sign extended */ \
948 : 0x33000000 + (VAL)) /* addiu t8,zero,VAL sign extended */
950 #define MIPS_FUNCTION_STUB_NORMAL_SIZE 16
951 #define MIPS_FUNCTION_STUB_BIG_SIZE 20
952 #define MICROMIPS_FUNCTION_STUB_NORMAL_SIZE 12
953 #define MICROMIPS_FUNCTION_STUB_BIG_SIZE 16
954 #define MICROMIPS_INSN32_FUNCTION_STUB_NORMAL_SIZE 16
955 #define MICROMIPS_INSN32_FUNCTION_STUB_BIG_SIZE 20
957 /* The name of the dynamic interpreter. This is put in the .interp
960 #define ELF_DYNAMIC_INTERPRETER(abfd) \
961 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
962 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
963 : "/usr/lib/libc.so.1")
966 #define MNAME(bfd,pre,pos) \
967 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
968 #define ELF_R_SYM(bfd, i) \
969 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
970 #define ELF_R_TYPE(bfd, i) \
971 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
972 #define ELF_R_INFO(bfd, s, t) \
973 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
975 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
976 #define ELF_R_SYM(bfd, i) \
978 #define ELF_R_TYPE(bfd, i) \
980 #define ELF_R_INFO(bfd, s, t) \
981 (ELF32_R_INFO (s, t))
984 /* The mips16 compiler uses a couple of special sections to handle
985 floating point arguments.
987 Section names that look like .mips16.fn.FNNAME contain stubs that
988 copy floating point arguments from the fp regs to the gp regs and
989 then jump to FNNAME. If any 32 bit function calls FNNAME, the
990 call should be redirected to the stub instead. If no 32 bit
991 function calls FNNAME, the stub should be discarded. We need to
992 consider any reference to the function, not just a call, because
993 if the address of the function is taken we will need the stub,
994 since the address might be passed to a 32 bit function.
996 Section names that look like .mips16.call.FNNAME contain stubs
997 that copy floating point arguments from the gp regs to the fp
998 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
999 then any 16 bit function that calls FNNAME should be redirected
1000 to the stub instead. If FNNAME is not a 32 bit function, the
1001 stub should be discarded.
1003 .mips16.call.fp.FNNAME sections are similar, but contain stubs
1004 which call FNNAME and then copy the return value from the fp regs
1005 to the gp regs. These stubs store the return value in $18 while
1006 calling FNNAME; any function which might call one of these stubs
1007 must arrange to save $18 around the call. (This case is not
1008 needed for 32 bit functions that call 16 bit functions, because
1009 16 bit functions always return floating point values in both
1012 Note that in all cases FNNAME might be defined statically.
1013 Therefore, FNNAME is not used literally. Instead, the relocation
1014 information will indicate which symbol the section is for.
1016 We record any stubs that we find in the symbol table. */
1018 #define FN_STUB ".mips16.fn."
1019 #define CALL_STUB ".mips16.call."
1020 #define CALL_FP_STUB ".mips16.call.fp."
1022 #define FN_STUB_P(name) CONST_STRNEQ (name, FN_STUB)
1023 #define CALL_STUB_P(name) CONST_STRNEQ (name, CALL_STUB)
1024 #define CALL_FP_STUB_P(name) CONST_STRNEQ (name, CALL_FP_STUB)
1026 /* The format of the first PLT entry in an O32 executable. */
1027 static const bfd_vma mips_o32_exec_plt0_entry
[] =
1029 0x3c1c0000, /* lui $28, %hi(&GOTPLT[0]) */
1030 0x8f990000, /* lw $25, %lo(&GOTPLT[0])($28) */
1031 0x279c0000, /* addiu $28, $28, %lo(&GOTPLT[0]) */
1032 0x031cc023, /* subu $24, $24, $28 */
1033 0x03e07825, /* or t7, ra, zero */
1034 0x0018c082, /* srl $24, $24, 2 */
1035 0x0320f809, /* jalr $25 */
1036 0x2718fffe /* subu $24, $24, 2 */
1039 /* The format of the first PLT entry in an N32 executable. Different
1040 because gp ($28) is not available; we use t2 ($14) instead. */
1041 static const bfd_vma mips_n32_exec_plt0_entry
[] =
1043 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
1044 0x8dd90000, /* lw $25, %lo(&GOTPLT[0])($14) */
1045 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
1046 0x030ec023, /* subu $24, $24, $14 */
1047 0x03e07825, /* or t7, ra, zero */
1048 0x0018c082, /* srl $24, $24, 2 */
1049 0x0320f809, /* jalr $25 */
1050 0x2718fffe /* subu $24, $24, 2 */
1053 /* The format of the first PLT entry in an N64 executable. Different
1054 from N32 because of the increased size of GOT entries. */
1055 static const bfd_vma mips_n64_exec_plt0_entry
[] =
1057 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
1058 0xddd90000, /* ld $25, %lo(&GOTPLT[0])($14) */
1059 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
1060 0x030ec023, /* subu $24, $24, $14 */
1061 0x03e07825, /* or t7, ra, zero */
1062 0x0018c0c2, /* srl $24, $24, 3 */
1063 0x0320f809, /* jalr $25 */
1064 0x2718fffe /* subu $24, $24, 2 */
1067 /* The format of the microMIPS first PLT entry in an O32 executable.
1068 We rely on v0 ($2) rather than t8 ($24) to contain the address
1069 of the GOTPLT entry handled, so this stub may only be used when
1070 all the subsequent PLT entries are microMIPS code too.
1072 The trailing NOP is for alignment and correct disassembly only. */
1073 static const bfd_vma micromips_o32_exec_plt0_entry
[] =
1075 0x7980, 0x0000, /* addiupc $3, (&GOTPLT[0]) - . */
1076 0xff23, 0x0000, /* lw $25, 0($3) */
1077 0x0535, /* subu $2, $2, $3 */
1078 0x2525, /* srl $2, $2, 2 */
1079 0x3302, 0xfffe, /* subu $24, $2, 2 */
1080 0x0dff, /* move $15, $31 */
1081 0x45f9, /* jalrs $25 */
1082 0x0f83, /* move $28, $3 */
1086 /* The format of the microMIPS first PLT entry in an O32 executable
1087 in the insn32 mode. */
1088 static const bfd_vma micromips_insn32_o32_exec_plt0_entry
[] =
1090 0x41bc, 0x0000, /* lui $28, %hi(&GOTPLT[0]) */
1091 0xff3c, 0x0000, /* lw $25, %lo(&GOTPLT[0])($28) */
1092 0x339c, 0x0000, /* addiu $28, $28, %lo(&GOTPLT[0]) */
1093 0x0398, 0xc1d0, /* subu $24, $24, $28 */
1094 0x001f, 0x7a90, /* or $15, $31, zero */
1095 0x0318, 0x1040, /* srl $24, $24, 2 */
1096 0x03f9, 0x0f3c, /* jalr $25 */
1097 0x3318, 0xfffe /* subu $24, $24, 2 */
1100 /* The format of subsequent standard PLT entries. */
1101 static const bfd_vma mips_exec_plt_entry
[] =
1103 0x3c0f0000, /* lui $15, %hi(.got.plt entry) */
1104 0x01f90000, /* l[wd] $25, %lo(.got.plt entry)($15) */
1105 0x25f80000, /* addiu $24, $15, %lo(.got.plt entry) */
1106 0x03200008 /* jr $25 */
1109 /* In the following PLT entry the JR and ADDIU instructions will
1110 be swapped in _bfd_mips_elf_finish_dynamic_symbol because
1111 LOAD_INTERLOCKS_P will be true for MIPS R6. */
1112 static const bfd_vma mipsr6_exec_plt_entry
[] =
1114 0x3c0f0000, /* lui $15, %hi(.got.plt entry) */
1115 0x01f90000, /* l[wd] $25, %lo(.got.plt entry)($15) */
1116 0x25f80000, /* addiu $24, $15, %lo(.got.plt entry) */
1117 0x03200009 /* jr $25 */
1120 /* The format of subsequent MIPS16 o32 PLT entries. We use v0 ($2)
1121 and v1 ($3) as temporaries because t8 ($24) and t9 ($25) are not
1122 directly addressable. */
1123 static const bfd_vma mips16_o32_exec_plt_entry
[] =
1125 0xb203, /* lw $2, 12($pc) */
1126 0x9a60, /* lw $3, 0($2) */
1127 0x651a, /* move $24, $2 */
1129 0x653b, /* move $25, $3 */
1131 0x0000, 0x0000 /* .word (.got.plt entry) */
1134 /* The format of subsequent microMIPS o32 PLT entries. We use v0 ($2)
1135 as a temporary because t8 ($24) is not addressable with ADDIUPC. */
1136 static const bfd_vma micromips_o32_exec_plt_entry
[] =
1138 0x7900, 0x0000, /* addiupc $2, (.got.plt entry) - . */
1139 0xff22, 0x0000, /* lw $25, 0($2) */
1140 0x4599, /* jr $25 */
1141 0x0f02 /* move $24, $2 */
1144 /* The format of subsequent microMIPS o32 PLT entries in the insn32 mode. */
1145 static const bfd_vma micromips_insn32_o32_exec_plt_entry
[] =
1147 0x41af, 0x0000, /* lui $15, %hi(.got.plt entry) */
1148 0xff2f, 0x0000, /* lw $25, %lo(.got.plt entry)($15) */
1149 0x0019, 0x0f3c, /* jr $25 */
1150 0x330f, 0x0000 /* addiu $24, $15, %lo(.got.plt entry) */
1153 /* The format of the first PLT entry in a VxWorks executable. */
1154 static const bfd_vma mips_vxworks_exec_plt0_entry
[] =
1156 0x3c190000, /* lui t9, %hi(_GLOBAL_OFFSET_TABLE_) */
1157 0x27390000, /* addiu t9, t9, %lo(_GLOBAL_OFFSET_TABLE_) */
1158 0x8f390008, /* lw t9, 8(t9) */
1159 0x00000000, /* nop */
1160 0x03200008, /* jr t9 */
1161 0x00000000 /* nop */
1164 /* The format of subsequent PLT entries. */
1165 static const bfd_vma mips_vxworks_exec_plt_entry
[] =
1167 0x10000000, /* b .PLT_resolver */
1168 0x24180000, /* li t8, <pltindex> */
1169 0x3c190000, /* lui t9, %hi(<.got.plt slot>) */
1170 0x27390000, /* addiu t9, t9, %lo(<.got.plt slot>) */
1171 0x8f390000, /* lw t9, 0(t9) */
1172 0x00000000, /* nop */
1173 0x03200008, /* jr t9 */
1174 0x00000000 /* nop */
1177 /* The format of the first PLT entry in a VxWorks shared object. */
1178 static const bfd_vma mips_vxworks_shared_plt0_entry
[] =
1180 0x8f990008, /* lw t9, 8(gp) */
1181 0x00000000, /* nop */
1182 0x03200008, /* jr t9 */
1183 0x00000000, /* nop */
1184 0x00000000, /* nop */
1185 0x00000000 /* nop */
1188 /* The format of subsequent PLT entries. */
1189 static const bfd_vma mips_vxworks_shared_plt_entry
[] =
1191 0x10000000, /* b .PLT_resolver */
1192 0x24180000 /* li t8, <pltindex> */
1195 /* microMIPS 32-bit opcode helper installer. */
1198 bfd_put_micromips_32 (const bfd
*abfd
, bfd_vma opcode
, bfd_byte
*ptr
)
1200 bfd_put_16 (abfd
, (opcode
>> 16) & 0xffff, ptr
);
1201 bfd_put_16 (abfd
, opcode
& 0xffff, ptr
+ 2);
1204 /* microMIPS 32-bit opcode helper retriever. */
1207 bfd_get_micromips_32 (const bfd
*abfd
, const bfd_byte
*ptr
)
1209 return (bfd_get_16 (abfd
, ptr
) << 16) | bfd_get_16 (abfd
, ptr
+ 2);
1212 /* Look up an entry in a MIPS ELF linker hash table. */
1214 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
1215 ((struct mips_elf_link_hash_entry *) \
1216 elf_link_hash_lookup (&(table)->root, (string), (create), \
1219 /* Traverse a MIPS ELF linker hash table. */
1221 #define mips_elf_link_hash_traverse(table, func, info) \
1222 (elf_link_hash_traverse \
1224 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1227 /* Find the base offsets for thread-local storage in this object,
1228 for GD/LD and IE/LE respectively. */
1230 #define TP_OFFSET 0x7000
1231 #define DTP_OFFSET 0x8000
1234 dtprel_base (struct bfd_link_info
*info
)
1236 /* If tls_sec is NULL, we should have signalled an error already. */
1237 if (elf_hash_table (info
)->tls_sec
== NULL
)
1239 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
1243 tprel_base (struct bfd_link_info
*info
)
1245 /* If tls_sec is NULL, we should have signalled an error already. */
1246 if (elf_hash_table (info
)->tls_sec
== NULL
)
1248 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
1251 /* Create an entry in a MIPS ELF linker hash table. */
1253 static struct bfd_hash_entry
*
1254 mips_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1255 struct bfd_hash_table
*table
, const char *string
)
1257 struct mips_elf_link_hash_entry
*ret
=
1258 (struct mips_elf_link_hash_entry
*) entry
;
1260 /* Allocate the structure if it has not already been allocated by a
1263 ret
= bfd_hash_allocate (table
, sizeof (struct mips_elf_link_hash_entry
));
1265 return (struct bfd_hash_entry
*) ret
;
1267 /* Call the allocation method of the superclass. */
1268 ret
= ((struct mips_elf_link_hash_entry
*)
1269 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1273 /* Set local fields. */
1274 memset (&ret
->esym
, 0, sizeof (EXTR
));
1275 /* We use -2 as a marker to indicate that the information has
1276 not been set. -1 means there is no associated ifd. */
1279 ret
->possibly_dynamic_relocs
= 0;
1280 ret
->fn_stub
= NULL
;
1281 ret
->call_stub
= NULL
;
1282 ret
->call_fp_stub
= NULL
;
1283 ret
->global_got_area
= GGA_NONE
;
1284 ret
->got_only_for_calls
= TRUE
;
1285 ret
->readonly_reloc
= FALSE
;
1286 ret
->has_static_relocs
= FALSE
;
1287 ret
->no_fn_stub
= FALSE
;
1288 ret
->need_fn_stub
= FALSE
;
1289 ret
->has_nonpic_branches
= FALSE
;
1290 ret
->needs_lazy_stub
= FALSE
;
1291 ret
->use_plt_entry
= FALSE
;
1294 return (struct bfd_hash_entry
*) ret
;
1297 /* Allocate MIPS ELF private object data. */
1300 _bfd_mips_elf_mkobject (bfd
*abfd
)
1302 return bfd_elf_allocate_object (abfd
, sizeof (struct mips_elf_obj_tdata
),
1307 _bfd_mips_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
1309 if (!sec
->used_by_bfd
)
1311 struct _mips_elf_section_data
*sdata
;
1312 bfd_size_type amt
= sizeof (*sdata
);
1314 sdata
= bfd_zalloc (abfd
, amt
);
1317 sec
->used_by_bfd
= sdata
;
1320 return _bfd_elf_new_section_hook (abfd
, sec
);
1323 /* Read ECOFF debugging information from a .mdebug section into a
1324 ecoff_debug_info structure. */
1327 _bfd_mips_elf_read_ecoff_info (bfd
*abfd
, asection
*section
,
1328 struct ecoff_debug_info
*debug
)
1331 const struct ecoff_debug_swap
*swap
;
1334 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1335 memset (debug
, 0, sizeof (*debug
));
1337 ext_hdr
= bfd_malloc (swap
->external_hdr_size
);
1338 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
1341 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, 0,
1342 swap
->external_hdr_size
))
1345 symhdr
= &debug
->symbolic_header
;
1346 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
1348 /* The symbolic header contains absolute file offsets and sizes to
1350 #define READ(ptr, offset, count, size, type) \
1351 if (symhdr->count == 0) \
1352 debug->ptr = NULL; \
1355 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
1356 debug->ptr = bfd_malloc (amt); \
1357 if (debug->ptr == NULL) \
1358 goto error_return; \
1359 if (bfd_seek (abfd, symhdr->offset, SEEK_SET) != 0 \
1360 || bfd_bread (debug->ptr, amt, abfd) != amt) \
1361 goto error_return; \
1364 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
1365 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
1366 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
1367 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
1368 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
1369 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
1371 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
1372 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
1373 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
1374 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
1375 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, void *);
1383 if (ext_hdr
!= NULL
)
1385 if (debug
->line
!= NULL
)
1387 if (debug
->external_dnr
!= NULL
)
1388 free (debug
->external_dnr
);
1389 if (debug
->external_pdr
!= NULL
)
1390 free (debug
->external_pdr
);
1391 if (debug
->external_sym
!= NULL
)
1392 free (debug
->external_sym
);
1393 if (debug
->external_opt
!= NULL
)
1394 free (debug
->external_opt
);
1395 if (debug
->external_aux
!= NULL
)
1396 free (debug
->external_aux
);
1397 if (debug
->ss
!= NULL
)
1399 if (debug
->ssext
!= NULL
)
1400 free (debug
->ssext
);
1401 if (debug
->external_fdr
!= NULL
)
1402 free (debug
->external_fdr
);
1403 if (debug
->external_rfd
!= NULL
)
1404 free (debug
->external_rfd
);
1405 if (debug
->external_ext
!= NULL
)
1406 free (debug
->external_ext
);
1410 /* Swap RPDR (runtime procedure table entry) for output. */
1413 ecoff_swap_rpdr_out (bfd
*abfd
, const RPDR
*in
, struct rpdr_ext
*ex
)
1415 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
1416 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
1417 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
1418 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
1419 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
1420 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
1422 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
1423 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
1425 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
1428 /* Create a runtime procedure table from the .mdebug section. */
1431 mips_elf_create_procedure_table (void *handle
, bfd
*abfd
,
1432 struct bfd_link_info
*info
, asection
*s
,
1433 struct ecoff_debug_info
*debug
)
1435 const struct ecoff_debug_swap
*swap
;
1436 HDRR
*hdr
= &debug
->symbolic_header
;
1438 struct rpdr_ext
*erp
;
1440 struct pdr_ext
*epdr
;
1441 struct sym_ext
*esym
;
1445 bfd_size_type count
;
1446 unsigned long sindex
;
1450 const char *no_name_func
= _("static procedure (no name)");
1458 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1460 sindex
= strlen (no_name_func
) + 1;
1461 count
= hdr
->ipdMax
;
1464 size
= swap
->external_pdr_size
;
1466 epdr
= bfd_malloc (size
* count
);
1470 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (bfd_byte
*) epdr
))
1473 size
= sizeof (RPDR
);
1474 rp
= rpdr
= bfd_malloc (size
* count
);
1478 size
= sizeof (char *);
1479 sv
= bfd_malloc (size
* count
);
1483 count
= hdr
->isymMax
;
1484 size
= swap
->external_sym_size
;
1485 esym
= bfd_malloc (size
* count
);
1489 if (! _bfd_ecoff_get_accumulated_sym (handle
, (bfd_byte
*) esym
))
1492 count
= hdr
->issMax
;
1493 ss
= bfd_malloc (count
);
1496 if (! _bfd_ecoff_get_accumulated_ss (handle
, (bfd_byte
*) ss
))
1499 count
= hdr
->ipdMax
;
1500 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
1502 (*swap
->swap_pdr_in
) (abfd
, epdr
+ i
, &pdr
);
1503 (*swap
->swap_sym_in
) (abfd
, &esym
[pdr
.isym
], &sym
);
1504 rp
->adr
= sym
.value
;
1505 rp
->regmask
= pdr
.regmask
;
1506 rp
->regoffset
= pdr
.regoffset
;
1507 rp
->fregmask
= pdr
.fregmask
;
1508 rp
->fregoffset
= pdr
.fregoffset
;
1509 rp
->frameoffset
= pdr
.frameoffset
;
1510 rp
->framereg
= pdr
.framereg
;
1511 rp
->pcreg
= pdr
.pcreg
;
1513 sv
[i
] = ss
+ sym
.iss
;
1514 sindex
+= strlen (sv
[i
]) + 1;
1518 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
1519 size
= BFD_ALIGN (size
, 16);
1520 rtproc
= bfd_alloc (abfd
, size
);
1523 mips_elf_hash_table (info
)->procedure_count
= 0;
1527 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
1530 memset (erp
, 0, sizeof (struct rpdr_ext
));
1532 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
1533 strcpy (str
, no_name_func
);
1534 str
+= strlen (no_name_func
) + 1;
1535 for (i
= 0; i
< count
; i
++)
1537 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
1538 strcpy (str
, sv
[i
]);
1539 str
+= strlen (sv
[i
]) + 1;
1541 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
1543 /* Set the size and contents of .rtproc section. */
1545 s
->contents
= rtproc
;
1547 /* Skip this section later on (I don't think this currently
1548 matters, but someday it might). */
1549 s
->map_head
.link_order
= NULL
;
1578 /* We're going to create a stub for H. Create a symbol for the stub's
1579 value and size, to help make the disassembly easier to read. */
1582 mips_elf_create_stub_symbol (struct bfd_link_info
*info
,
1583 struct mips_elf_link_hash_entry
*h
,
1584 const char *prefix
, asection
*s
, bfd_vma value
,
1587 bfd_boolean micromips_p
= ELF_ST_IS_MICROMIPS (h
->root
.other
);
1588 struct bfd_link_hash_entry
*bh
;
1589 struct elf_link_hash_entry
*elfh
;
1596 /* Create a new symbol. */
1597 name
= concat (prefix
, h
->root
.root
.root
.string
, NULL
);
1599 res
= _bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1600 BSF_LOCAL
, s
, value
, NULL
,
1606 /* Make it a local function. */
1607 elfh
= (struct elf_link_hash_entry
*) bh
;
1608 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
1610 elfh
->forced_local
= 1;
1612 elfh
->other
= ELF_ST_SET_MICROMIPS (elfh
->other
);
1616 /* We're about to redefine H. Create a symbol to represent H's
1617 current value and size, to help make the disassembly easier
1621 mips_elf_create_shadow_symbol (struct bfd_link_info
*info
,
1622 struct mips_elf_link_hash_entry
*h
,
1625 struct bfd_link_hash_entry
*bh
;
1626 struct elf_link_hash_entry
*elfh
;
1632 /* Read the symbol's value. */
1633 BFD_ASSERT (h
->root
.root
.type
== bfd_link_hash_defined
1634 || h
->root
.root
.type
== bfd_link_hash_defweak
);
1635 s
= h
->root
.root
.u
.def
.section
;
1636 value
= h
->root
.root
.u
.def
.value
;
1638 /* Create a new symbol. */
1639 name
= concat (prefix
, h
->root
.root
.root
.string
, NULL
);
1641 res
= _bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1642 BSF_LOCAL
, s
, value
, NULL
,
1648 /* Make it local and copy the other attributes from H. */
1649 elfh
= (struct elf_link_hash_entry
*) bh
;
1650 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (h
->root
.type
));
1651 elfh
->other
= h
->root
.other
;
1652 elfh
->size
= h
->root
.size
;
1653 elfh
->forced_local
= 1;
1657 /* Return TRUE if relocations in SECTION can refer directly to a MIPS16
1658 function rather than to a hard-float stub. */
1661 section_allows_mips16_refs_p (asection
*section
)
1665 name
= bfd_get_section_name (section
->owner
, section
);
1666 return (FN_STUB_P (name
)
1667 || CALL_STUB_P (name
)
1668 || CALL_FP_STUB_P (name
)
1669 || strcmp (name
, ".pdr") == 0);
1672 /* [RELOCS, RELEND) are the relocations against SEC, which is a MIPS16
1673 stub section of some kind. Return the R_SYMNDX of the target
1674 function, or 0 if we can't decide which function that is. */
1676 static unsigned long
1677 mips16_stub_symndx (const struct elf_backend_data
*bed
,
1678 asection
*sec ATTRIBUTE_UNUSED
,
1679 const Elf_Internal_Rela
*relocs
,
1680 const Elf_Internal_Rela
*relend
)
1682 int int_rels_per_ext_rel
= bed
->s
->int_rels_per_ext_rel
;
1683 const Elf_Internal_Rela
*rel
;
1685 /* Trust the first R_MIPS_NONE relocation, if any, but not a subsequent
1686 one in a compound relocation. */
1687 for (rel
= relocs
; rel
< relend
; rel
+= int_rels_per_ext_rel
)
1688 if (ELF_R_TYPE (sec
->owner
, rel
->r_info
) == R_MIPS_NONE
)
1689 return ELF_R_SYM (sec
->owner
, rel
->r_info
);
1691 /* Otherwise trust the first relocation, whatever its kind. This is
1692 the traditional behavior. */
1693 if (relocs
< relend
)
1694 return ELF_R_SYM (sec
->owner
, relocs
->r_info
);
1699 /* Check the mips16 stubs for a particular symbol, and see if we can
1703 mips_elf_check_mips16_stubs (struct bfd_link_info
*info
,
1704 struct mips_elf_link_hash_entry
*h
)
1706 /* Dynamic symbols must use the standard call interface, in case other
1707 objects try to call them. */
1708 if (h
->fn_stub
!= NULL
1709 && h
->root
.dynindx
!= -1)
1711 mips_elf_create_shadow_symbol (info
, h
, ".mips16.");
1712 h
->need_fn_stub
= TRUE
;
1715 if (h
->fn_stub
!= NULL
1716 && ! h
->need_fn_stub
)
1718 /* We don't need the fn_stub; the only references to this symbol
1719 are 16 bit calls. Clobber the size to 0 to prevent it from
1720 being included in the link. */
1721 h
->fn_stub
->size
= 0;
1722 h
->fn_stub
->flags
&= ~SEC_RELOC
;
1723 h
->fn_stub
->reloc_count
= 0;
1724 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
1725 h
->fn_stub
->output_section
= bfd_abs_section_ptr
;
1728 if (h
->call_stub
!= NULL
1729 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1731 /* We don't need the call_stub; this is a 16 bit function, so
1732 calls from other 16 bit functions are OK. Clobber the size
1733 to 0 to prevent it from being included in the link. */
1734 h
->call_stub
->size
= 0;
1735 h
->call_stub
->flags
&= ~SEC_RELOC
;
1736 h
->call_stub
->reloc_count
= 0;
1737 h
->call_stub
->flags
|= SEC_EXCLUDE
;
1738 h
->call_stub
->output_section
= bfd_abs_section_ptr
;
1741 if (h
->call_fp_stub
!= NULL
1742 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1744 /* We don't need the call_stub; this is a 16 bit function, so
1745 calls from other 16 bit functions are OK. Clobber the size
1746 to 0 to prevent it from being included in the link. */
1747 h
->call_fp_stub
->size
= 0;
1748 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
1749 h
->call_fp_stub
->reloc_count
= 0;
1750 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
1751 h
->call_fp_stub
->output_section
= bfd_abs_section_ptr
;
1755 /* Hashtable callbacks for mips_elf_la25_stubs. */
1758 mips_elf_la25_stub_hash (const void *entry_
)
1760 const struct mips_elf_la25_stub
*entry
;
1762 entry
= (struct mips_elf_la25_stub
*) entry_
;
1763 return entry
->h
->root
.root
.u
.def
.section
->id
1764 + entry
->h
->root
.root
.u
.def
.value
;
1768 mips_elf_la25_stub_eq (const void *entry1_
, const void *entry2_
)
1770 const struct mips_elf_la25_stub
*entry1
, *entry2
;
1772 entry1
= (struct mips_elf_la25_stub
*) entry1_
;
1773 entry2
= (struct mips_elf_la25_stub
*) entry2_
;
1774 return ((entry1
->h
->root
.root
.u
.def
.section
1775 == entry2
->h
->root
.root
.u
.def
.section
)
1776 && (entry1
->h
->root
.root
.u
.def
.value
1777 == entry2
->h
->root
.root
.u
.def
.value
));
1780 /* Called by the linker to set up the la25 stub-creation code. FN is
1781 the linker's implementation of add_stub_function. Return true on
1785 _bfd_mips_elf_init_stubs (struct bfd_link_info
*info
,
1786 asection
*(*fn
) (const char *, asection
*,
1789 struct mips_elf_link_hash_table
*htab
;
1791 htab
= mips_elf_hash_table (info
);
1795 htab
->add_stub_section
= fn
;
1796 htab
->la25_stubs
= htab_try_create (1, mips_elf_la25_stub_hash
,
1797 mips_elf_la25_stub_eq
, NULL
);
1798 if (htab
->la25_stubs
== NULL
)
1804 /* Return true if H is a locally-defined PIC function, in the sense
1805 that it or its fn_stub might need $25 to be valid on entry.
1806 Note that MIPS16 functions set up $gp using PC-relative instructions,
1807 so they themselves never need $25 to be valid. Only non-MIPS16
1808 entry points are of interest here. */
1811 mips_elf_local_pic_function_p (struct mips_elf_link_hash_entry
*h
)
1813 return ((h
->root
.root
.type
== bfd_link_hash_defined
1814 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1815 && h
->root
.def_regular
1816 && !bfd_is_abs_section (h
->root
.root
.u
.def
.section
)
1817 && !bfd_is_und_section (h
->root
.root
.u
.def
.section
)
1818 && (!ELF_ST_IS_MIPS16 (h
->root
.other
)
1819 || (h
->fn_stub
&& h
->need_fn_stub
))
1820 && (PIC_OBJECT_P (h
->root
.root
.u
.def
.section
->owner
)
1821 || ELF_ST_IS_MIPS_PIC (h
->root
.other
)));
1824 /* Set *SEC to the input section that contains the target of STUB.
1825 Return the offset of the target from the start of that section. */
1828 mips_elf_get_la25_target (struct mips_elf_la25_stub
*stub
,
1831 if (ELF_ST_IS_MIPS16 (stub
->h
->root
.other
))
1833 BFD_ASSERT (stub
->h
->need_fn_stub
);
1834 *sec
= stub
->h
->fn_stub
;
1839 *sec
= stub
->h
->root
.root
.u
.def
.section
;
1840 return stub
->h
->root
.root
.u
.def
.value
;
1844 /* STUB describes an la25 stub that we have decided to implement
1845 by inserting an LUI/ADDIU pair before the target function.
1846 Create the section and redirect the function symbol to it. */
1849 mips_elf_add_la25_intro (struct mips_elf_la25_stub
*stub
,
1850 struct bfd_link_info
*info
)
1852 struct mips_elf_link_hash_table
*htab
;
1854 asection
*s
, *input_section
;
1857 htab
= mips_elf_hash_table (info
);
1861 /* Create a unique name for the new section. */
1862 name
= bfd_malloc (11 + sizeof (".text.stub."));
1865 sprintf (name
, ".text.stub.%d", (int) htab_elements (htab
->la25_stubs
));
1867 /* Create the section. */
1868 mips_elf_get_la25_target (stub
, &input_section
);
1869 s
= htab
->add_stub_section (name
, input_section
,
1870 input_section
->output_section
);
1874 /* Make sure that any padding goes before the stub. */
1875 align
= input_section
->alignment_power
;
1876 if (!bfd_set_section_alignment (s
->owner
, s
, align
))
1879 s
->size
= (1 << align
) - 8;
1881 /* Create a symbol for the stub. */
1882 mips_elf_create_stub_symbol (info
, stub
->h
, ".pic.", s
, s
->size
, 8);
1883 stub
->stub_section
= s
;
1884 stub
->offset
= s
->size
;
1886 /* Allocate room for it. */
1891 /* STUB describes an la25 stub that we have decided to implement
1892 with a separate trampoline. Allocate room for it and redirect
1893 the function symbol to it. */
1896 mips_elf_add_la25_trampoline (struct mips_elf_la25_stub
*stub
,
1897 struct bfd_link_info
*info
)
1899 struct mips_elf_link_hash_table
*htab
;
1902 htab
= mips_elf_hash_table (info
);
1906 /* Create a trampoline section, if we haven't already. */
1907 s
= htab
->strampoline
;
1910 asection
*input_section
= stub
->h
->root
.root
.u
.def
.section
;
1911 s
= htab
->add_stub_section (".text", NULL
,
1912 input_section
->output_section
);
1913 if (s
== NULL
|| !bfd_set_section_alignment (s
->owner
, s
, 4))
1915 htab
->strampoline
= s
;
1918 /* Create a symbol for the stub. */
1919 mips_elf_create_stub_symbol (info
, stub
->h
, ".pic.", s
, s
->size
, 16);
1920 stub
->stub_section
= s
;
1921 stub
->offset
= s
->size
;
1923 /* Allocate room for it. */
1928 /* H describes a symbol that needs an la25 stub. Make sure that an
1929 appropriate stub exists and point H at it. */
1932 mips_elf_add_la25_stub (struct bfd_link_info
*info
,
1933 struct mips_elf_link_hash_entry
*h
)
1935 struct mips_elf_link_hash_table
*htab
;
1936 struct mips_elf_la25_stub search
, *stub
;
1937 bfd_boolean use_trampoline_p
;
1942 /* Describe the stub we want. */
1943 search
.stub_section
= NULL
;
1947 /* See if we've already created an equivalent stub. */
1948 htab
= mips_elf_hash_table (info
);
1952 slot
= htab_find_slot (htab
->la25_stubs
, &search
, INSERT
);
1956 stub
= (struct mips_elf_la25_stub
*) *slot
;
1959 /* We can reuse the existing stub. */
1960 h
->la25_stub
= stub
;
1964 /* Create a permanent copy of ENTRY and add it to the hash table. */
1965 stub
= bfd_malloc (sizeof (search
));
1971 /* Prefer to use LUI/ADDIU stubs if the function is at the beginning
1972 of the section and if we would need no more than 2 nops. */
1973 value
= mips_elf_get_la25_target (stub
, &s
);
1974 if (ELF_ST_IS_MICROMIPS (stub
->h
->root
.other
))
1976 use_trampoline_p
= (value
!= 0 || s
->alignment_power
> 4);
1978 h
->la25_stub
= stub
;
1979 return (use_trampoline_p
1980 ? mips_elf_add_la25_trampoline (stub
, info
)
1981 : mips_elf_add_la25_intro (stub
, info
));
1984 /* A mips_elf_link_hash_traverse callback that is called before sizing
1985 sections. DATA points to a mips_htab_traverse_info structure. */
1988 mips_elf_check_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
1990 struct mips_htab_traverse_info
*hti
;
1992 hti
= (struct mips_htab_traverse_info
*) data
;
1993 if (!bfd_link_relocatable (hti
->info
))
1994 mips_elf_check_mips16_stubs (hti
->info
, h
);
1996 if (mips_elf_local_pic_function_p (h
))
1998 /* PR 12845: If H is in a section that has been garbage
1999 collected it will have its output section set to *ABS*. */
2000 if (bfd_is_abs_section (h
->root
.root
.u
.def
.section
->output_section
))
2003 /* H is a function that might need $25 to be valid on entry.
2004 If we're creating a non-PIC relocatable object, mark H as
2005 being PIC. If we're creating a non-relocatable object with
2006 non-PIC branches and jumps to H, make sure that H has an la25
2008 if (bfd_link_relocatable (hti
->info
))
2010 if (!PIC_OBJECT_P (hti
->output_bfd
))
2011 h
->root
.other
= ELF_ST_SET_MIPS_PIC (h
->root
.other
);
2013 else if (h
->has_nonpic_branches
&& !mips_elf_add_la25_stub (hti
->info
, h
))
2022 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
2023 Most mips16 instructions are 16 bits, but these instructions
2026 The format of these instructions is:
2028 +--------------+--------------------------------+
2029 | JALX | X| Imm 20:16 | Imm 25:21 |
2030 +--------------+--------------------------------+
2032 +-----------------------------------------------+
2034 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
2035 Note that the immediate value in the first word is swapped.
2037 When producing a relocatable object file, R_MIPS16_26 is
2038 handled mostly like R_MIPS_26. In particular, the addend is
2039 stored as a straight 26-bit value in a 32-bit instruction.
2040 (gas makes life simpler for itself by never adjusting a
2041 R_MIPS16_26 reloc to be against a section, so the addend is
2042 always zero). However, the 32 bit instruction is stored as 2
2043 16-bit values, rather than a single 32-bit value. In a
2044 big-endian file, the result is the same; in a little-endian
2045 file, the two 16-bit halves of the 32 bit value are swapped.
2046 This is so that a disassembler can recognize the jal
2049 When doing a final link, R_MIPS16_26 is treated as a 32 bit
2050 instruction stored as two 16-bit values. The addend A is the
2051 contents of the targ26 field. The calculation is the same as
2052 R_MIPS_26. When storing the calculated value, reorder the
2053 immediate value as shown above, and don't forget to store the
2054 value as two 16-bit values.
2056 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
2060 +--------+----------------------+
2064 +--------+----------------------+
2067 +----------+------+-------------+
2071 +----------+--------------------+
2072 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
2073 ((sub1 << 16) | sub2)).
2075 When producing a relocatable object file, the calculation is
2076 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
2077 When producing a fully linked file, the calculation is
2078 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
2079 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
2081 The table below lists the other MIPS16 instruction relocations.
2082 Each one is calculated in the same way as the non-MIPS16 relocation
2083 given on the right, but using the extended MIPS16 layout of 16-bit
2086 R_MIPS16_GPREL R_MIPS_GPREL16
2087 R_MIPS16_GOT16 R_MIPS_GOT16
2088 R_MIPS16_CALL16 R_MIPS_CALL16
2089 R_MIPS16_HI16 R_MIPS_HI16
2090 R_MIPS16_LO16 R_MIPS_LO16
2092 A typical instruction will have a format like this:
2094 +--------------+--------------------------------+
2095 | EXTEND | Imm 10:5 | Imm 15:11 |
2096 +--------------+--------------------------------+
2097 | Major | rx | ry | Imm 4:0 |
2098 +--------------+--------------------------------+
2100 EXTEND is the five bit value 11110. Major is the instruction
2103 All we need to do here is shuffle the bits appropriately.
2104 As above, the two 16-bit halves must be swapped on a
2105 little-endian system.
2107 Finally R_MIPS16_PC16_S1 corresponds to R_MIPS_PC16, however the
2108 relocatable field is shifted by 1 rather than 2 and the same bit
2109 shuffling is done as with the relocations above. */
2111 static inline bfd_boolean
2112 mips16_reloc_p (int r_type
)
2117 case R_MIPS16_GPREL
:
2118 case R_MIPS16_GOT16
:
2119 case R_MIPS16_CALL16
:
2122 case R_MIPS16_TLS_GD
:
2123 case R_MIPS16_TLS_LDM
:
2124 case R_MIPS16_TLS_DTPREL_HI16
:
2125 case R_MIPS16_TLS_DTPREL_LO16
:
2126 case R_MIPS16_TLS_GOTTPREL
:
2127 case R_MIPS16_TLS_TPREL_HI16
:
2128 case R_MIPS16_TLS_TPREL_LO16
:
2129 case R_MIPS16_PC16_S1
:
2137 /* Check if a microMIPS reloc. */
2139 static inline bfd_boolean
2140 micromips_reloc_p (unsigned int r_type
)
2142 return r_type
>= R_MICROMIPS_min
&& r_type
< R_MICROMIPS_max
;
2145 /* Similar to MIPS16, the two 16-bit halves in microMIPS must be swapped
2146 on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1
2147 and R_MICROMIPS_PC10_S1 relocs that apply to 16-bit instructions. */
2149 static inline bfd_boolean
2150 micromips_reloc_shuffle_p (unsigned int r_type
)
2152 return (micromips_reloc_p (r_type
)
2153 && r_type
!= R_MICROMIPS_PC7_S1
2154 && r_type
!= R_MICROMIPS_PC10_S1
);
2157 static inline bfd_boolean
2158 got16_reloc_p (int r_type
)
2160 return (r_type
== R_MIPS_GOT16
2161 || r_type
== R_MIPS16_GOT16
2162 || r_type
== R_MICROMIPS_GOT16
);
2165 static inline bfd_boolean
2166 call16_reloc_p (int r_type
)
2168 return (r_type
== R_MIPS_CALL16
2169 || r_type
== R_MIPS16_CALL16
2170 || r_type
== R_MICROMIPS_CALL16
);
2173 static inline bfd_boolean
2174 got_disp_reloc_p (unsigned int r_type
)
2176 return r_type
== R_MIPS_GOT_DISP
|| r_type
== R_MICROMIPS_GOT_DISP
;
2179 static inline bfd_boolean
2180 got_page_reloc_p (unsigned int r_type
)
2182 return r_type
== R_MIPS_GOT_PAGE
|| r_type
== R_MICROMIPS_GOT_PAGE
;
2185 static inline bfd_boolean
2186 got_lo16_reloc_p (unsigned int r_type
)
2188 return r_type
== R_MIPS_GOT_LO16
|| r_type
== R_MICROMIPS_GOT_LO16
;
2191 static inline bfd_boolean
2192 call_hi16_reloc_p (unsigned int r_type
)
2194 return r_type
== R_MIPS_CALL_HI16
|| r_type
== R_MICROMIPS_CALL_HI16
;
2197 static inline bfd_boolean
2198 call_lo16_reloc_p (unsigned int r_type
)
2200 return r_type
== R_MIPS_CALL_LO16
|| r_type
== R_MICROMIPS_CALL_LO16
;
2203 static inline bfd_boolean
2204 hi16_reloc_p (int r_type
)
2206 return (r_type
== R_MIPS_HI16
2207 || r_type
== R_MIPS16_HI16
2208 || r_type
== R_MICROMIPS_HI16
2209 || r_type
== R_MIPS_PCHI16
);
2212 static inline bfd_boolean
2213 lo16_reloc_p (int r_type
)
2215 return (r_type
== R_MIPS_LO16
2216 || r_type
== R_MIPS16_LO16
2217 || r_type
== R_MICROMIPS_LO16
2218 || r_type
== R_MIPS_PCLO16
);
2221 static inline bfd_boolean
2222 mips16_call_reloc_p (int r_type
)
2224 return r_type
== R_MIPS16_26
|| r_type
== R_MIPS16_CALL16
;
2227 static inline bfd_boolean
2228 jal_reloc_p (int r_type
)
2230 return (r_type
== R_MIPS_26
2231 || r_type
== R_MIPS16_26
2232 || r_type
== R_MICROMIPS_26_S1
);
2235 static inline bfd_boolean
2236 b_reloc_p (int r_type
)
2238 return (r_type
== R_MIPS_PC26_S2
2239 || r_type
== R_MIPS_PC21_S2
2240 || r_type
== R_MIPS_PC16
2241 || r_type
== R_MIPS_GNU_REL16_S2
2242 || r_type
== R_MIPS16_PC16_S1
2243 || r_type
== R_MICROMIPS_PC16_S1
2244 || r_type
== R_MICROMIPS_PC10_S1
2245 || r_type
== R_MICROMIPS_PC7_S1
);
2248 static inline bfd_boolean
2249 aligned_pcrel_reloc_p (int r_type
)
2251 return (r_type
== R_MIPS_PC18_S3
2252 || r_type
== R_MIPS_PC19_S2
);
2255 static inline bfd_boolean
2256 branch_reloc_p (int r_type
)
2258 return (r_type
== R_MIPS_26
2259 || r_type
== R_MIPS_PC26_S2
2260 || r_type
== R_MIPS_PC21_S2
2261 || r_type
== R_MIPS_PC16
2262 || r_type
== R_MIPS_GNU_REL16_S2
);
2265 static inline bfd_boolean
2266 mips16_branch_reloc_p (int r_type
)
2268 return (r_type
== R_MIPS16_26
2269 || r_type
== R_MIPS16_PC16_S1
);
2272 static inline bfd_boolean
2273 micromips_branch_reloc_p (int r_type
)
2275 return (r_type
== R_MICROMIPS_26_S1
2276 || r_type
== R_MICROMIPS_PC16_S1
2277 || r_type
== R_MICROMIPS_PC10_S1
2278 || r_type
== R_MICROMIPS_PC7_S1
);
2281 static inline bfd_boolean
2282 tls_gd_reloc_p (unsigned int r_type
)
2284 return (r_type
== R_MIPS_TLS_GD
2285 || r_type
== R_MIPS16_TLS_GD
2286 || r_type
== R_MICROMIPS_TLS_GD
);
2289 static inline bfd_boolean
2290 tls_ldm_reloc_p (unsigned int r_type
)
2292 return (r_type
== R_MIPS_TLS_LDM
2293 || r_type
== R_MIPS16_TLS_LDM
2294 || r_type
== R_MICROMIPS_TLS_LDM
);
2297 static inline bfd_boolean
2298 tls_gottprel_reloc_p (unsigned int r_type
)
2300 return (r_type
== R_MIPS_TLS_GOTTPREL
2301 || r_type
== R_MIPS16_TLS_GOTTPREL
2302 || r_type
== R_MICROMIPS_TLS_GOTTPREL
);
2306 _bfd_mips_elf_reloc_unshuffle (bfd
*abfd
, int r_type
,
2307 bfd_boolean jal_shuffle
, bfd_byte
*data
)
2309 bfd_vma first
, second
, val
;
2311 if (!mips16_reloc_p (r_type
) && !micromips_reloc_shuffle_p (r_type
))
2314 /* Pick up the first and second halfwords of the instruction. */
2315 first
= bfd_get_16 (abfd
, data
);
2316 second
= bfd_get_16 (abfd
, data
+ 2);
2317 if (micromips_reloc_p (r_type
) || (r_type
== R_MIPS16_26
&& !jal_shuffle
))
2318 val
= first
<< 16 | second
;
2319 else if (r_type
!= R_MIPS16_26
)
2320 val
= (((first
& 0xf800) << 16) | ((second
& 0xffe0) << 11)
2321 | ((first
& 0x1f) << 11) | (first
& 0x7e0) | (second
& 0x1f));
2323 val
= (((first
& 0xfc00) << 16) | ((first
& 0x3e0) << 11)
2324 | ((first
& 0x1f) << 21) | second
);
2325 bfd_put_32 (abfd
, val
, data
);
2329 _bfd_mips_elf_reloc_shuffle (bfd
*abfd
, int r_type
,
2330 bfd_boolean jal_shuffle
, bfd_byte
*data
)
2332 bfd_vma first
, second
, val
;
2334 if (!mips16_reloc_p (r_type
) && !micromips_reloc_shuffle_p (r_type
))
2337 val
= bfd_get_32 (abfd
, data
);
2338 if (micromips_reloc_p (r_type
) || (r_type
== R_MIPS16_26
&& !jal_shuffle
))
2340 second
= val
& 0xffff;
2343 else if (r_type
!= R_MIPS16_26
)
2345 second
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
2346 first
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
2350 second
= val
& 0xffff;
2351 first
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
2352 | ((val
>> 21) & 0x1f);
2354 bfd_put_16 (abfd
, second
, data
+ 2);
2355 bfd_put_16 (abfd
, first
, data
);
2358 bfd_reloc_status_type
2359 _bfd_mips_elf_gprel16_with_gp (bfd
*abfd
, asymbol
*symbol
,
2360 arelent
*reloc_entry
, asection
*input_section
,
2361 bfd_boolean relocatable
, void *data
, bfd_vma gp
)
2365 bfd_reloc_status_type status
;
2367 if (bfd_is_com_section (symbol
->section
))
2370 relocation
= symbol
->value
;
2372 relocation
+= symbol
->section
->output_section
->vma
;
2373 relocation
+= symbol
->section
->output_offset
;
2375 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2376 return bfd_reloc_outofrange
;
2378 /* Set val to the offset into the section or symbol. */
2379 val
= reloc_entry
->addend
;
2381 _bfd_mips_elf_sign_extend (val
, 16);
2383 /* Adjust val for the final section location and GP value. If we
2384 are producing relocatable output, we don't want to do this for
2385 an external symbol. */
2387 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2388 val
+= relocation
- gp
;
2390 if (reloc_entry
->howto
->partial_inplace
)
2392 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
2394 + reloc_entry
->address
);
2395 if (status
!= bfd_reloc_ok
)
2399 reloc_entry
->addend
= val
;
2402 reloc_entry
->address
+= input_section
->output_offset
;
2404 return bfd_reloc_ok
;
2407 /* Used to store a REL high-part relocation such as R_MIPS_HI16 or
2408 R_MIPS_GOT16. REL is the relocation, INPUT_SECTION is the section
2409 that contains the relocation field and DATA points to the start of
2414 struct mips_hi16
*next
;
2416 asection
*input_section
;
2420 /* FIXME: This should not be a static variable. */
2422 static struct mips_hi16
*mips_hi16_list
;
2424 /* A howto special_function for REL *HI16 relocations. We can only
2425 calculate the correct value once we've seen the partnering
2426 *LO16 relocation, so just save the information for later.
2428 The ABI requires that the *LO16 immediately follow the *HI16.
2429 However, as a GNU extension, we permit an arbitrary number of
2430 *HI16s to be associated with a single *LO16. This significantly
2431 simplies the relocation handling in gcc. */
2433 bfd_reloc_status_type
2434 _bfd_mips_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2435 asymbol
*symbol ATTRIBUTE_UNUSED
, void *data
,
2436 asection
*input_section
, bfd
*output_bfd
,
2437 char **error_message ATTRIBUTE_UNUSED
)
2439 struct mips_hi16
*n
;
2441 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2442 return bfd_reloc_outofrange
;
2444 n
= bfd_malloc (sizeof *n
);
2446 return bfd_reloc_outofrange
;
2448 n
->next
= mips_hi16_list
;
2450 n
->input_section
= input_section
;
2451 n
->rel
= *reloc_entry
;
2454 if (output_bfd
!= NULL
)
2455 reloc_entry
->address
+= input_section
->output_offset
;
2457 return bfd_reloc_ok
;
2460 /* A howto special_function for REL R_MIPS*_GOT16 relocations. This is just
2461 like any other 16-bit relocation when applied to global symbols, but is
2462 treated in the same as R_MIPS_HI16 when applied to local symbols. */
2464 bfd_reloc_status_type
2465 _bfd_mips_elf_got16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2466 void *data
, asection
*input_section
,
2467 bfd
*output_bfd
, char **error_message
)
2469 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
2470 || bfd_is_und_section (bfd_get_section (symbol
))
2471 || bfd_is_com_section (bfd_get_section (symbol
)))
2472 /* The relocation is against a global symbol. */
2473 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2474 input_section
, output_bfd
,
2477 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
2478 input_section
, output_bfd
, error_message
);
2481 /* A howto special_function for REL *LO16 relocations. The *LO16 itself
2482 is a straightforward 16 bit inplace relocation, but we must deal with
2483 any partnering high-part relocations as well. */
2485 bfd_reloc_status_type
2486 _bfd_mips_elf_lo16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2487 void *data
, asection
*input_section
,
2488 bfd
*output_bfd
, char **error_message
)
2491 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
2493 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2494 return bfd_reloc_outofrange
;
2496 _bfd_mips_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2498 vallo
= bfd_get_32 (abfd
, location
);
2499 _bfd_mips_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2502 while (mips_hi16_list
!= NULL
)
2504 bfd_reloc_status_type ret
;
2505 struct mips_hi16
*hi
;
2507 hi
= mips_hi16_list
;
2509 /* R_MIPS*_GOT16 relocations are something of a special case. We
2510 want to install the addend in the same way as for a R_MIPS*_HI16
2511 relocation (with a rightshift of 16). However, since GOT16
2512 relocations can also be used with global symbols, their howto
2513 has a rightshift of 0. */
2514 if (hi
->rel
.howto
->type
== R_MIPS_GOT16
)
2515 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS_HI16
, FALSE
);
2516 else if (hi
->rel
.howto
->type
== R_MIPS16_GOT16
)
2517 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS16_HI16
, FALSE
);
2518 else if (hi
->rel
.howto
->type
== R_MICROMIPS_GOT16
)
2519 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MICROMIPS_HI16
, FALSE
);
2521 /* VALLO is a signed 16-bit number. Bias it by 0x8000 so that any
2522 carry or borrow will induce a change of +1 or -1 in the high part. */
2523 hi
->rel
.addend
+= (vallo
+ 0x8000) & 0xffff;
2525 ret
= _bfd_mips_elf_generic_reloc (abfd
, &hi
->rel
, symbol
, hi
->data
,
2526 hi
->input_section
, output_bfd
,
2528 if (ret
!= bfd_reloc_ok
)
2531 mips_hi16_list
= hi
->next
;
2535 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2536 input_section
, output_bfd
,
2540 /* A generic howto special_function. This calculates and installs the
2541 relocation itself, thus avoiding the oft-discussed problems in
2542 bfd_perform_relocation and bfd_install_relocation. */
2544 bfd_reloc_status_type
2545 _bfd_mips_elf_generic_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2546 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
2547 asection
*input_section
, bfd
*output_bfd
,
2548 char **error_message ATTRIBUTE_UNUSED
)
2551 bfd_reloc_status_type status
;
2552 bfd_boolean relocatable
;
2554 relocatable
= (output_bfd
!= NULL
);
2556 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2557 return bfd_reloc_outofrange
;
2559 /* Build up the field adjustment in VAL. */
2561 if (!relocatable
|| (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2563 /* Either we're calculating the final field value or we have a
2564 relocation against a section symbol. Add in the section's
2565 offset or address. */
2566 val
+= symbol
->section
->output_section
->vma
;
2567 val
+= symbol
->section
->output_offset
;
2572 /* We're calculating the final field value. Add in the symbol's value
2573 and, if pc-relative, subtract the address of the field itself. */
2574 val
+= symbol
->value
;
2575 if (reloc_entry
->howto
->pc_relative
)
2577 val
-= input_section
->output_section
->vma
;
2578 val
-= input_section
->output_offset
;
2579 val
-= reloc_entry
->address
;
2583 /* VAL is now the final adjustment. If we're keeping this relocation
2584 in the output file, and if the relocation uses a separate addend,
2585 we just need to add VAL to that addend. Otherwise we need to add
2586 VAL to the relocation field itself. */
2587 if (relocatable
&& !reloc_entry
->howto
->partial_inplace
)
2588 reloc_entry
->addend
+= val
;
2591 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
2593 /* Add in the separate addend, if any. */
2594 val
+= reloc_entry
->addend
;
2596 /* Add VAL to the relocation field. */
2597 _bfd_mips_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2599 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
2601 _bfd_mips_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2604 if (status
!= bfd_reloc_ok
)
2609 reloc_entry
->address
+= input_section
->output_offset
;
2611 return bfd_reloc_ok
;
2614 /* Swap an entry in a .gptab section. Note that these routines rely
2615 on the equivalence of the two elements of the union. */
2618 bfd_mips_elf32_swap_gptab_in (bfd
*abfd
, const Elf32_External_gptab
*ex
,
2621 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
2622 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
2626 bfd_mips_elf32_swap_gptab_out (bfd
*abfd
, const Elf32_gptab
*in
,
2627 Elf32_External_gptab
*ex
)
2629 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
2630 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
2634 bfd_elf32_swap_compact_rel_out (bfd
*abfd
, const Elf32_compact_rel
*in
,
2635 Elf32_External_compact_rel
*ex
)
2637 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
2638 H_PUT_32 (abfd
, in
->num
, ex
->num
);
2639 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
2640 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
2641 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
2642 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
2646 bfd_elf32_swap_crinfo_out (bfd
*abfd
, const Elf32_crinfo
*in
,
2647 Elf32_External_crinfo
*ex
)
2651 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2652 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2653 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2654 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2655 H_PUT_32 (abfd
, l
, ex
->info
);
2656 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
2657 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
2660 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2661 routines swap this structure in and out. They are used outside of
2662 BFD, so they are globally visible. */
2665 bfd_mips_elf32_swap_reginfo_in (bfd
*abfd
, const Elf32_External_RegInfo
*ex
,
2668 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2669 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2670 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2671 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2672 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2673 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
2677 bfd_mips_elf32_swap_reginfo_out (bfd
*abfd
, const Elf32_RegInfo
*in
,
2678 Elf32_External_RegInfo
*ex
)
2680 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2681 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2682 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2683 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2684 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2685 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2688 /* In the 64 bit ABI, the .MIPS.options section holds register
2689 information in an Elf64_Reginfo structure. These routines swap
2690 them in and out. They are globally visible because they are used
2691 outside of BFD. These routines are here so that gas can call them
2692 without worrying about whether the 64 bit ABI has been included. */
2695 bfd_mips_elf64_swap_reginfo_in (bfd
*abfd
, const Elf64_External_RegInfo
*ex
,
2696 Elf64_Internal_RegInfo
*in
)
2698 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2699 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
2700 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2701 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2702 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2703 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2704 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
2708 bfd_mips_elf64_swap_reginfo_out (bfd
*abfd
, const Elf64_Internal_RegInfo
*in
,
2709 Elf64_External_RegInfo
*ex
)
2711 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2712 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
2713 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2714 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2715 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2716 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2717 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2720 /* Swap in an options header. */
2723 bfd_mips_elf_swap_options_in (bfd
*abfd
, const Elf_External_Options
*ex
,
2724 Elf_Internal_Options
*in
)
2726 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
2727 in
->size
= H_GET_8 (abfd
, ex
->size
);
2728 in
->section
= H_GET_16 (abfd
, ex
->section
);
2729 in
->info
= H_GET_32 (abfd
, ex
->info
);
2732 /* Swap out an options header. */
2735 bfd_mips_elf_swap_options_out (bfd
*abfd
, const Elf_Internal_Options
*in
,
2736 Elf_External_Options
*ex
)
2738 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
2739 H_PUT_8 (abfd
, in
->size
, ex
->size
);
2740 H_PUT_16 (abfd
, in
->section
, ex
->section
);
2741 H_PUT_32 (abfd
, in
->info
, ex
->info
);
2744 /* Swap in an abiflags structure. */
2747 bfd_mips_elf_swap_abiflags_v0_in (bfd
*abfd
,
2748 const Elf_External_ABIFlags_v0
*ex
,
2749 Elf_Internal_ABIFlags_v0
*in
)
2751 in
->version
= H_GET_16 (abfd
, ex
->version
);
2752 in
->isa_level
= H_GET_8 (abfd
, ex
->isa_level
);
2753 in
->isa_rev
= H_GET_8 (abfd
, ex
->isa_rev
);
2754 in
->gpr_size
= H_GET_8 (abfd
, ex
->gpr_size
);
2755 in
->cpr1_size
= H_GET_8 (abfd
, ex
->cpr1_size
);
2756 in
->cpr2_size
= H_GET_8 (abfd
, ex
->cpr2_size
);
2757 in
->fp_abi
= H_GET_8 (abfd
, ex
->fp_abi
);
2758 in
->isa_ext
= H_GET_32 (abfd
, ex
->isa_ext
);
2759 in
->ases
= H_GET_32 (abfd
, ex
->ases
);
2760 in
->flags1
= H_GET_32 (abfd
, ex
->flags1
);
2761 in
->flags2
= H_GET_32 (abfd
, ex
->flags2
);
2764 /* Swap out an abiflags structure. */
2767 bfd_mips_elf_swap_abiflags_v0_out (bfd
*abfd
,
2768 const Elf_Internal_ABIFlags_v0
*in
,
2769 Elf_External_ABIFlags_v0
*ex
)
2771 H_PUT_16 (abfd
, in
->version
, ex
->version
);
2772 H_PUT_8 (abfd
, in
->isa_level
, ex
->isa_level
);
2773 H_PUT_8 (abfd
, in
->isa_rev
, ex
->isa_rev
);
2774 H_PUT_8 (abfd
, in
->gpr_size
, ex
->gpr_size
);
2775 H_PUT_8 (abfd
, in
->cpr1_size
, ex
->cpr1_size
);
2776 H_PUT_8 (abfd
, in
->cpr2_size
, ex
->cpr2_size
);
2777 H_PUT_8 (abfd
, in
->fp_abi
, ex
->fp_abi
);
2778 H_PUT_32 (abfd
, in
->isa_ext
, ex
->isa_ext
);
2779 H_PUT_32 (abfd
, in
->ases
, ex
->ases
);
2780 H_PUT_32 (abfd
, in
->flags1
, ex
->flags1
);
2781 H_PUT_32 (abfd
, in
->flags2
, ex
->flags2
);
2784 /* This function is called via qsort() to sort the dynamic relocation
2785 entries by increasing r_symndx value. */
2788 sort_dynamic_relocs (const void *arg1
, const void *arg2
)
2790 Elf_Internal_Rela int_reloc1
;
2791 Elf_Internal_Rela int_reloc2
;
2794 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
2795 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
2797 diff
= ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
2801 if (int_reloc1
.r_offset
< int_reloc2
.r_offset
)
2803 if (int_reloc1
.r_offset
> int_reloc2
.r_offset
)
2808 /* Like sort_dynamic_relocs, but used for elf64 relocations. */
2811 sort_dynamic_relocs_64 (const void *arg1 ATTRIBUTE_UNUSED
,
2812 const void *arg2 ATTRIBUTE_UNUSED
)
2815 Elf_Internal_Rela int_reloc1
[3];
2816 Elf_Internal_Rela int_reloc2
[3];
2818 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
2819 (reldyn_sorting_bfd
, arg1
, int_reloc1
);
2820 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
2821 (reldyn_sorting_bfd
, arg2
, int_reloc2
);
2823 if (ELF64_R_SYM (int_reloc1
[0].r_info
) < ELF64_R_SYM (int_reloc2
[0].r_info
))
2825 if (ELF64_R_SYM (int_reloc1
[0].r_info
) > ELF64_R_SYM (int_reloc2
[0].r_info
))
2828 if (int_reloc1
[0].r_offset
< int_reloc2
[0].r_offset
)
2830 if (int_reloc1
[0].r_offset
> int_reloc2
[0].r_offset
)
2839 /* This routine is used to write out ECOFF debugging external symbol
2840 information. It is called via mips_elf_link_hash_traverse. The
2841 ECOFF external symbol information must match the ELF external
2842 symbol information. Unfortunately, at this point we don't know
2843 whether a symbol is required by reloc information, so the two
2844 tables may wind up being different. We must sort out the external
2845 symbol information before we can set the final size of the .mdebug
2846 section, and we must set the size of the .mdebug section before we
2847 can relocate any sections, and we can't know which symbols are
2848 required by relocation until we relocate the sections.
2849 Fortunately, it is relatively unlikely that any symbol will be
2850 stripped but required by a reloc. In particular, it can not happen
2851 when generating a final executable. */
2854 mips_elf_output_extsym (struct mips_elf_link_hash_entry
*h
, void *data
)
2856 struct extsym_info
*einfo
= data
;
2858 asection
*sec
, *output_section
;
2860 if (h
->root
.indx
== -2)
2862 else if ((h
->root
.def_dynamic
2863 || h
->root
.ref_dynamic
2864 || h
->root
.type
== bfd_link_hash_new
)
2865 && !h
->root
.def_regular
2866 && !h
->root
.ref_regular
)
2868 else if (einfo
->info
->strip
== strip_all
2869 || (einfo
->info
->strip
== strip_some
2870 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2871 h
->root
.root
.root
.string
,
2872 FALSE
, FALSE
) == NULL
))
2880 if (h
->esym
.ifd
== -2)
2883 h
->esym
.cobol_main
= 0;
2884 h
->esym
.weakext
= 0;
2885 h
->esym
.reserved
= 0;
2886 h
->esym
.ifd
= ifdNil
;
2887 h
->esym
.asym
.value
= 0;
2888 h
->esym
.asym
.st
= stGlobal
;
2890 if (h
->root
.root
.type
== bfd_link_hash_undefined
2891 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
2895 /* Use undefined class. Also, set class and type for some
2897 name
= h
->root
.root
.root
.string
;
2898 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
2899 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
2901 h
->esym
.asym
.sc
= scData
;
2902 h
->esym
.asym
.st
= stLabel
;
2903 h
->esym
.asym
.value
= 0;
2905 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
2907 h
->esym
.asym
.sc
= scAbs
;
2908 h
->esym
.asym
.st
= stLabel
;
2909 h
->esym
.asym
.value
=
2910 mips_elf_hash_table (einfo
->info
)->procedure_count
;
2913 h
->esym
.asym
.sc
= scUndefined
;
2915 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2916 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2917 h
->esym
.asym
.sc
= scAbs
;
2922 sec
= h
->root
.root
.u
.def
.section
;
2923 output_section
= sec
->output_section
;
2925 /* When making a shared library and symbol h is the one from
2926 the another shared library, OUTPUT_SECTION may be null. */
2927 if (output_section
== NULL
)
2928 h
->esym
.asym
.sc
= scUndefined
;
2931 name
= bfd_section_name (output_section
->owner
, output_section
);
2933 if (strcmp (name
, ".text") == 0)
2934 h
->esym
.asym
.sc
= scText
;
2935 else if (strcmp (name
, ".data") == 0)
2936 h
->esym
.asym
.sc
= scData
;
2937 else if (strcmp (name
, ".sdata") == 0)
2938 h
->esym
.asym
.sc
= scSData
;
2939 else if (strcmp (name
, ".rodata") == 0
2940 || strcmp (name
, ".rdata") == 0)
2941 h
->esym
.asym
.sc
= scRData
;
2942 else if (strcmp (name
, ".bss") == 0)
2943 h
->esym
.asym
.sc
= scBss
;
2944 else if (strcmp (name
, ".sbss") == 0)
2945 h
->esym
.asym
.sc
= scSBss
;
2946 else if (strcmp (name
, ".init") == 0)
2947 h
->esym
.asym
.sc
= scInit
;
2948 else if (strcmp (name
, ".fini") == 0)
2949 h
->esym
.asym
.sc
= scFini
;
2951 h
->esym
.asym
.sc
= scAbs
;
2955 h
->esym
.asym
.reserved
= 0;
2956 h
->esym
.asym
.index
= indexNil
;
2959 if (h
->root
.root
.type
== bfd_link_hash_common
)
2960 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2961 else if (h
->root
.root
.type
== bfd_link_hash_defined
2962 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2964 if (h
->esym
.asym
.sc
== scCommon
)
2965 h
->esym
.asym
.sc
= scBss
;
2966 else if (h
->esym
.asym
.sc
== scSCommon
)
2967 h
->esym
.asym
.sc
= scSBss
;
2969 sec
= h
->root
.root
.u
.def
.section
;
2970 output_section
= sec
->output_section
;
2971 if (output_section
!= NULL
)
2972 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2973 + sec
->output_offset
2974 + output_section
->vma
);
2976 h
->esym
.asym
.value
= 0;
2980 struct mips_elf_link_hash_entry
*hd
= h
;
2982 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
2983 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2985 if (hd
->needs_lazy_stub
)
2987 BFD_ASSERT (hd
->root
.plt
.plist
!= NULL
);
2988 BFD_ASSERT (hd
->root
.plt
.plist
->stub_offset
!= MINUS_ONE
);
2989 /* Set type and value for a symbol with a function stub. */
2990 h
->esym
.asym
.st
= stProc
;
2991 sec
= hd
->root
.root
.u
.def
.section
;
2993 h
->esym
.asym
.value
= 0;
2996 output_section
= sec
->output_section
;
2997 if (output_section
!= NULL
)
2998 h
->esym
.asym
.value
= (hd
->root
.plt
.plist
->stub_offset
2999 + sec
->output_offset
3000 + output_section
->vma
);
3002 h
->esym
.asym
.value
= 0;
3007 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3008 h
->root
.root
.root
.string
,
3011 einfo
->failed
= TRUE
;
3018 /* A comparison routine used to sort .gptab entries. */
3021 gptab_compare (const void *p1
, const void *p2
)
3023 const Elf32_gptab
*a1
= p1
;
3024 const Elf32_gptab
*a2
= p2
;
3026 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
3029 /* Functions to manage the got entry hash table. */
3031 /* Use all 64 bits of a bfd_vma for the computation of a 32-bit
3034 static INLINE hashval_t
3035 mips_elf_hash_bfd_vma (bfd_vma addr
)
3038 return addr
+ (addr
>> 32);
3045 mips_elf_got_entry_hash (const void *entry_
)
3047 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
3049 return (entry
->symndx
3050 + ((entry
->tls_type
== GOT_TLS_LDM
) << 18)
3051 + (entry
->tls_type
== GOT_TLS_LDM
? 0
3052 : !entry
->abfd
? mips_elf_hash_bfd_vma (entry
->d
.address
)
3053 : entry
->symndx
>= 0 ? (entry
->abfd
->id
3054 + mips_elf_hash_bfd_vma (entry
->d
.addend
))
3055 : entry
->d
.h
->root
.root
.root
.hash
));
3059 mips_elf_got_entry_eq (const void *entry1
, const void *entry2
)
3061 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
3062 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
3064 return (e1
->symndx
== e2
->symndx
3065 && e1
->tls_type
== e2
->tls_type
3066 && (e1
->tls_type
== GOT_TLS_LDM
? TRUE
3067 : !e1
->abfd
? !e2
->abfd
&& e1
->d
.address
== e2
->d
.address
3068 : e1
->symndx
>= 0 ? (e1
->abfd
== e2
->abfd
3069 && e1
->d
.addend
== e2
->d
.addend
)
3070 : e2
->abfd
&& e1
->d
.h
== e2
->d
.h
));
3074 mips_got_page_ref_hash (const void *ref_
)
3076 const struct mips_got_page_ref
*ref
;
3078 ref
= (const struct mips_got_page_ref
*) ref_
;
3079 return ((ref
->symndx
>= 0
3080 ? (hashval_t
) (ref
->u
.abfd
->id
+ ref
->symndx
)
3081 : ref
->u
.h
->root
.root
.root
.hash
)
3082 + mips_elf_hash_bfd_vma (ref
->addend
));
3086 mips_got_page_ref_eq (const void *ref1_
, const void *ref2_
)
3088 const struct mips_got_page_ref
*ref1
, *ref2
;
3090 ref1
= (const struct mips_got_page_ref
*) ref1_
;
3091 ref2
= (const struct mips_got_page_ref
*) ref2_
;
3092 return (ref1
->symndx
== ref2
->symndx
3093 && (ref1
->symndx
< 0
3094 ? ref1
->u
.h
== ref2
->u
.h
3095 : ref1
->u
.abfd
== ref2
->u
.abfd
)
3096 && ref1
->addend
== ref2
->addend
);
3100 mips_got_page_entry_hash (const void *entry_
)
3102 const struct mips_got_page_entry
*entry
;
3104 entry
= (const struct mips_got_page_entry
*) entry_
;
3105 return entry
->sec
->id
;
3109 mips_got_page_entry_eq (const void *entry1_
, const void *entry2_
)
3111 const struct mips_got_page_entry
*entry1
, *entry2
;
3113 entry1
= (const struct mips_got_page_entry
*) entry1_
;
3114 entry2
= (const struct mips_got_page_entry
*) entry2_
;
3115 return entry1
->sec
== entry2
->sec
;
3118 /* Create and return a new mips_got_info structure. */
3120 static struct mips_got_info
*
3121 mips_elf_create_got_info (bfd
*abfd
)
3123 struct mips_got_info
*g
;
3125 g
= bfd_zalloc (abfd
, sizeof (struct mips_got_info
));
3129 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
3130 mips_elf_got_entry_eq
, NULL
);
3131 if (g
->got_entries
== NULL
)
3134 g
->got_page_refs
= htab_try_create (1, mips_got_page_ref_hash
,
3135 mips_got_page_ref_eq
, NULL
);
3136 if (g
->got_page_refs
== NULL
)
3142 /* Return the GOT info for input bfd ABFD, trying to create a new one if
3143 CREATE_P and if ABFD doesn't already have a GOT. */
3145 static struct mips_got_info
*
3146 mips_elf_bfd_got (bfd
*abfd
, bfd_boolean create_p
)
3148 struct mips_elf_obj_tdata
*tdata
;
3150 if (!is_mips_elf (abfd
))
3153 tdata
= mips_elf_tdata (abfd
);
3154 if (!tdata
->got
&& create_p
)
3155 tdata
->got
= mips_elf_create_got_info (abfd
);
3159 /* Record that ABFD should use output GOT G. */
3162 mips_elf_replace_bfd_got (bfd
*abfd
, struct mips_got_info
*g
)
3164 struct mips_elf_obj_tdata
*tdata
;
3166 BFD_ASSERT (is_mips_elf (abfd
));
3167 tdata
= mips_elf_tdata (abfd
);
3170 /* The GOT structure itself and the hash table entries are
3171 allocated to a bfd, but the hash tables aren't. */
3172 htab_delete (tdata
->got
->got_entries
);
3173 htab_delete (tdata
->got
->got_page_refs
);
3174 if (tdata
->got
->got_page_entries
)
3175 htab_delete (tdata
->got
->got_page_entries
);
3180 /* Return the dynamic relocation section. If it doesn't exist, try to
3181 create a new it if CREATE_P, otherwise return NULL. Also return NULL
3182 if creation fails. */
3185 mips_elf_rel_dyn_section (struct bfd_link_info
*info
, bfd_boolean create_p
)
3191 dname
= MIPS_ELF_REL_DYN_NAME (info
);
3192 dynobj
= elf_hash_table (info
)->dynobj
;
3193 sreloc
= bfd_get_linker_section (dynobj
, dname
);
3194 if (sreloc
== NULL
&& create_p
)
3196 sreloc
= bfd_make_section_anyway_with_flags (dynobj
, dname
,
3201 | SEC_LINKER_CREATED
3204 || ! bfd_set_section_alignment (dynobj
, sreloc
,
3205 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
3211 /* Return the GOT_TLS_* type required by relocation type R_TYPE. */
3214 mips_elf_reloc_tls_type (unsigned int r_type
)
3216 if (tls_gd_reloc_p (r_type
))
3219 if (tls_ldm_reloc_p (r_type
))
3222 if (tls_gottprel_reloc_p (r_type
))
3225 return GOT_TLS_NONE
;
3228 /* Return the number of GOT slots needed for GOT TLS type TYPE. */
3231 mips_tls_got_entries (unsigned int type
)
3248 /* Count the number of relocations needed for a TLS GOT entry, with
3249 access types from TLS_TYPE, and symbol H (or a local symbol if H
3253 mips_tls_got_relocs (struct bfd_link_info
*info
, unsigned char tls_type
,
3254 struct elf_link_hash_entry
*h
)
3257 bfd_boolean need_relocs
= FALSE
;
3258 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
3262 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
3263 && (bfd_link_dll (info
) || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
3266 if ((bfd_link_dll (info
) || indx
!= 0)
3268 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3269 || h
->root
.type
!= bfd_link_hash_undefweak
))
3278 return indx
!= 0 ? 2 : 1;
3284 return bfd_link_dll (info
) ? 1 : 0;
3291 /* Add the number of GOT entries and TLS relocations required by ENTRY
3295 mips_elf_count_got_entry (struct bfd_link_info
*info
,
3296 struct mips_got_info
*g
,
3297 struct mips_got_entry
*entry
)
3299 if (entry
->tls_type
)
3301 g
->tls_gotno
+= mips_tls_got_entries (entry
->tls_type
);
3302 g
->relocs
+= mips_tls_got_relocs (info
, entry
->tls_type
,
3304 ? &entry
->d
.h
->root
: NULL
);
3306 else if (entry
->symndx
>= 0 || entry
->d
.h
->global_got_area
== GGA_NONE
)
3307 g
->local_gotno
+= 1;
3309 g
->global_gotno
+= 1;
3312 /* Output a simple dynamic relocation into SRELOC. */
3315 mips_elf_output_dynamic_relocation (bfd
*output_bfd
,
3317 unsigned long reloc_index
,
3322 Elf_Internal_Rela rel
[3];
3324 memset (rel
, 0, sizeof (rel
));
3326 rel
[0].r_info
= ELF_R_INFO (output_bfd
, indx
, r_type
);
3327 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
3329 if (ABI_64_P (output_bfd
))
3331 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
3332 (output_bfd
, &rel
[0],
3334 + reloc_index
* sizeof (Elf64_Mips_External_Rel
)));
3337 bfd_elf32_swap_reloc_out
3338 (output_bfd
, &rel
[0],
3340 + reloc_index
* sizeof (Elf32_External_Rel
)));
3343 /* Initialize a set of TLS GOT entries for one symbol. */
3346 mips_elf_initialize_tls_slots (bfd
*abfd
, struct bfd_link_info
*info
,
3347 struct mips_got_entry
*entry
,
3348 struct mips_elf_link_hash_entry
*h
,
3351 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
3352 struct mips_elf_link_hash_table
*htab
;
3354 asection
*sreloc
, *sgot
;
3355 bfd_vma got_offset
, got_offset2
;
3356 bfd_boolean need_relocs
= FALSE
;
3358 htab
= mips_elf_hash_table (info
);
3362 sgot
= htab
->root
.sgot
;
3366 && h
->root
.dynindx
!= -1
3367 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), &h
->root
)
3368 && (bfd_link_dll (info
) || !SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
3369 indx
= h
->root
.dynindx
;
3371 if (entry
->tls_initialized
)
3374 if ((bfd_link_dll (info
) || indx
!= 0)
3376 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
3377 || h
->root
.type
!= bfd_link_hash_undefweak
))
3380 /* MINUS_ONE means the symbol is not defined in this object. It may not
3381 be defined at all; assume that the value doesn't matter in that
3382 case. Otherwise complain if we would use the value. */
3383 BFD_ASSERT (value
!= MINUS_ONE
|| (indx
!= 0 && need_relocs
)
3384 || h
->root
.root
.type
== bfd_link_hash_undefweak
);
3386 /* Emit necessary relocations. */
3387 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
3388 got_offset
= entry
->gotidx
;
3390 switch (entry
->tls_type
)
3393 /* General Dynamic. */
3394 got_offset2
= got_offset
+ MIPS_ELF_GOT_SIZE (abfd
);
3398 mips_elf_output_dynamic_relocation
3399 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
3400 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
3401 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
3404 mips_elf_output_dynamic_relocation
3405 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
3406 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPREL64
: R_MIPS_TLS_DTPREL32
,
3407 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset2
);
3409 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
3410 sgot
->contents
+ got_offset2
);
3414 MIPS_ELF_PUT_WORD (abfd
, 1,
3415 sgot
->contents
+ got_offset
);
3416 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
3417 sgot
->contents
+ got_offset2
);
3422 /* Initial Exec model. */
3426 MIPS_ELF_PUT_WORD (abfd
, value
- elf_hash_table (info
)->tls_sec
->vma
,
3427 sgot
->contents
+ got_offset
);
3429 MIPS_ELF_PUT_WORD (abfd
, 0,
3430 sgot
->contents
+ got_offset
);
3432 mips_elf_output_dynamic_relocation
3433 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
3434 ABI_64_P (abfd
) ? R_MIPS_TLS_TPREL64
: R_MIPS_TLS_TPREL32
,
3435 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
3438 MIPS_ELF_PUT_WORD (abfd
, value
- tprel_base (info
),
3439 sgot
->contents
+ got_offset
);
3443 /* The initial offset is zero, and the LD offsets will include the
3444 bias by DTP_OFFSET. */
3445 MIPS_ELF_PUT_WORD (abfd
, 0,
3446 sgot
->contents
+ got_offset
3447 + MIPS_ELF_GOT_SIZE (abfd
));
3449 if (!bfd_link_dll (info
))
3450 MIPS_ELF_PUT_WORD (abfd
, 1,
3451 sgot
->contents
+ got_offset
);
3453 mips_elf_output_dynamic_relocation
3454 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
3455 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
3456 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
3463 entry
->tls_initialized
= TRUE
;
3466 /* Return the offset from _GLOBAL_OFFSET_TABLE_ of the .got.plt entry
3467 for global symbol H. .got.plt comes before the GOT, so the offset
3468 will be negative. */
3471 mips_elf_gotplt_index (struct bfd_link_info
*info
,
3472 struct elf_link_hash_entry
*h
)
3474 bfd_vma got_address
, got_value
;
3475 struct mips_elf_link_hash_table
*htab
;
3477 htab
= mips_elf_hash_table (info
);
3478 BFD_ASSERT (htab
!= NULL
);
3480 BFD_ASSERT (h
->plt
.plist
!= NULL
);
3481 BFD_ASSERT (h
->plt
.plist
->gotplt_index
!= MINUS_ONE
);
3483 /* Calculate the address of the associated .got.plt entry. */
3484 got_address
= (htab
->root
.sgotplt
->output_section
->vma
3485 + htab
->root
.sgotplt
->output_offset
3486 + (h
->plt
.plist
->gotplt_index
3487 * MIPS_ELF_GOT_SIZE (info
->output_bfd
)));
3489 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
3490 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
3491 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
3492 + htab
->root
.hgot
->root
.u
.def
.value
);
3494 return got_address
- got_value
;
3497 /* Return the GOT offset for address VALUE. If there is not yet a GOT
3498 entry for this value, create one. If R_SYMNDX refers to a TLS symbol,
3499 create a TLS GOT entry instead. Return -1 if no satisfactory GOT
3500 offset can be found. */
3503 mips_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3504 bfd_vma value
, unsigned long r_symndx
,
3505 struct mips_elf_link_hash_entry
*h
, int r_type
)
3507 struct mips_elf_link_hash_table
*htab
;
3508 struct mips_got_entry
*entry
;
3510 htab
= mips_elf_hash_table (info
);
3511 BFD_ASSERT (htab
!= NULL
);
3513 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
,
3514 r_symndx
, h
, r_type
);
3518 if (entry
->tls_type
)
3519 mips_elf_initialize_tls_slots (abfd
, info
, entry
, h
, value
);
3520 return entry
->gotidx
;
3523 /* Return the GOT index of global symbol H in the primary GOT. */
3526 mips_elf_primary_global_got_index (bfd
*obfd
, struct bfd_link_info
*info
,
3527 struct elf_link_hash_entry
*h
)
3529 struct mips_elf_link_hash_table
*htab
;
3530 long global_got_dynindx
;
3531 struct mips_got_info
*g
;
3534 htab
= mips_elf_hash_table (info
);
3535 BFD_ASSERT (htab
!= NULL
);
3537 global_got_dynindx
= 0;
3538 if (htab
->global_gotsym
!= NULL
)
3539 global_got_dynindx
= htab
->global_gotsym
->dynindx
;
3541 /* Once we determine the global GOT entry with the lowest dynamic
3542 symbol table index, we must put all dynamic symbols with greater
3543 indices into the primary GOT. That makes it easy to calculate the
3545 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
3546 g
= mips_elf_bfd_got (obfd
, FALSE
);
3547 got_index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
3548 * MIPS_ELF_GOT_SIZE (obfd
));
3549 BFD_ASSERT (got_index
< htab
->root
.sgot
->size
);
3554 /* Return the GOT index for the global symbol indicated by H, which is
3555 referenced by a relocation of type R_TYPE in IBFD. */
3558 mips_elf_global_got_index (bfd
*obfd
, struct bfd_link_info
*info
, bfd
*ibfd
,
3559 struct elf_link_hash_entry
*h
, int r_type
)
3561 struct mips_elf_link_hash_table
*htab
;
3562 struct mips_got_info
*g
;
3563 struct mips_got_entry lookup
, *entry
;
3566 htab
= mips_elf_hash_table (info
);
3567 BFD_ASSERT (htab
!= NULL
);
3569 g
= mips_elf_bfd_got (ibfd
, FALSE
);
3572 lookup
.tls_type
= mips_elf_reloc_tls_type (r_type
);
3573 if (!lookup
.tls_type
&& g
== mips_elf_bfd_got (obfd
, FALSE
))
3574 return mips_elf_primary_global_got_index (obfd
, info
, h
);
3578 lookup
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
3579 entry
= htab_find (g
->got_entries
, &lookup
);
3582 gotidx
= entry
->gotidx
;
3583 BFD_ASSERT (gotidx
> 0 && gotidx
< htab
->root
.sgot
->size
);
3585 if (lookup
.tls_type
)
3587 bfd_vma value
= MINUS_ONE
;
3589 if ((h
->root
.type
== bfd_link_hash_defined
3590 || h
->root
.type
== bfd_link_hash_defweak
)
3591 && h
->root
.u
.def
.section
->output_section
)
3592 value
= (h
->root
.u
.def
.value
3593 + h
->root
.u
.def
.section
->output_offset
3594 + h
->root
.u
.def
.section
->output_section
->vma
);
3596 mips_elf_initialize_tls_slots (obfd
, info
, entry
, lookup
.d
.h
, value
);
3601 /* Find a GOT page entry that points to within 32KB of VALUE. These
3602 entries are supposed to be placed at small offsets in the GOT, i.e.,
3603 within 32KB of GP. Return the index of the GOT entry, or -1 if no
3604 entry could be created. If OFFSETP is nonnull, use it to return the
3605 offset of the GOT entry from VALUE. */
3608 mips_elf_got_page (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3609 bfd_vma value
, bfd_vma
*offsetp
)
3611 bfd_vma page
, got_index
;
3612 struct mips_got_entry
*entry
;
3614 page
= (value
+ 0x8000) & ~(bfd_vma
) 0xffff;
3615 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, page
, 0,
3616 NULL
, R_MIPS_GOT_PAGE
);
3621 got_index
= entry
->gotidx
;
3624 *offsetp
= value
- entry
->d
.address
;
3629 /* Find a local GOT entry for an R_MIPS*_GOT16 relocation against VALUE.
3630 EXTERNAL is true if the relocation was originally against a global
3631 symbol that binds locally. */
3634 mips_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3635 bfd_vma value
, bfd_boolean external
)
3637 struct mips_got_entry
*entry
;
3639 /* GOT16 relocations against local symbols are followed by a LO16
3640 relocation; those against global symbols are not. Thus if the
3641 symbol was originally local, the GOT16 relocation should load the
3642 equivalent of %hi(VALUE), otherwise it should load VALUE itself. */
3644 value
= mips_elf_high (value
) << 16;
3646 /* It doesn't matter whether the original relocation was R_MIPS_GOT16,
3647 R_MIPS16_GOT16, R_MIPS_CALL16, etc. The format of the entry is the
3648 same in all cases. */
3649 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
, 0,
3650 NULL
, R_MIPS_GOT16
);
3652 return entry
->gotidx
;
3657 /* Returns the offset for the entry at the INDEXth position
3661 mips_elf_got_offset_from_index (struct bfd_link_info
*info
, bfd
*output_bfd
,
3662 bfd
*input_bfd
, bfd_vma got_index
)
3664 struct mips_elf_link_hash_table
*htab
;
3668 htab
= mips_elf_hash_table (info
);
3669 BFD_ASSERT (htab
!= NULL
);
3671 sgot
= htab
->root
.sgot
;
3672 gp
= _bfd_get_gp_value (output_bfd
)
3673 + mips_elf_adjust_gp (output_bfd
, htab
->got_info
, input_bfd
);
3675 return sgot
->output_section
->vma
+ sgot
->output_offset
+ got_index
- gp
;
3678 /* Create and return a local GOT entry for VALUE, which was calculated
3679 from a symbol belonging to INPUT_SECTON. Return NULL if it could not
3680 be created. If R_SYMNDX refers to a TLS symbol, create a TLS entry
3683 static struct mips_got_entry
*
3684 mips_elf_create_local_got_entry (bfd
*abfd
, struct bfd_link_info
*info
,
3685 bfd
*ibfd
, bfd_vma value
,
3686 unsigned long r_symndx
,
3687 struct mips_elf_link_hash_entry
*h
,
3690 struct mips_got_entry lookup
, *entry
;
3692 struct mips_got_info
*g
;
3693 struct mips_elf_link_hash_table
*htab
;
3696 htab
= mips_elf_hash_table (info
);
3697 BFD_ASSERT (htab
!= NULL
);
3699 g
= mips_elf_bfd_got (ibfd
, FALSE
);
3702 g
= mips_elf_bfd_got (abfd
, FALSE
);
3703 BFD_ASSERT (g
!= NULL
);
3706 /* This function shouldn't be called for symbols that live in the global
3708 BFD_ASSERT (h
== NULL
|| h
->global_got_area
== GGA_NONE
);
3710 lookup
.tls_type
= mips_elf_reloc_tls_type (r_type
);
3711 if (lookup
.tls_type
)
3714 if (tls_ldm_reloc_p (r_type
))
3717 lookup
.d
.addend
= 0;
3721 lookup
.symndx
= r_symndx
;
3722 lookup
.d
.addend
= 0;
3730 entry
= (struct mips_got_entry
*) htab_find (g
->got_entries
, &lookup
);
3733 gotidx
= entry
->gotidx
;
3734 BFD_ASSERT (gotidx
> 0 && gotidx
< htab
->root
.sgot
->size
);
3741 lookup
.d
.address
= value
;
3742 loc
= htab_find_slot (g
->got_entries
, &lookup
, INSERT
);
3746 entry
= (struct mips_got_entry
*) *loc
;
3750 if (g
->assigned_low_gotno
> g
->assigned_high_gotno
)
3752 /* We didn't allocate enough space in the GOT. */
3754 (_("not enough GOT space for local GOT entries"));
3755 bfd_set_error (bfd_error_bad_value
);
3759 entry
= (struct mips_got_entry
*) bfd_alloc (abfd
, sizeof (*entry
));
3763 if (got16_reloc_p (r_type
)
3764 || call16_reloc_p (r_type
)
3765 || got_page_reloc_p (r_type
)
3766 || got_disp_reloc_p (r_type
))
3767 lookup
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_low_gotno
++;
3769 lookup
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_high_gotno
--;
3774 MIPS_ELF_PUT_WORD (abfd
, value
, htab
->root
.sgot
->contents
+ entry
->gotidx
);
3776 /* These GOT entries need a dynamic relocation on VxWorks. */
3777 if (htab
->is_vxworks
)
3779 Elf_Internal_Rela outrel
;
3782 bfd_vma got_address
;
3784 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3785 got_address
= (htab
->root
.sgot
->output_section
->vma
3786 + htab
->root
.sgot
->output_offset
3789 rloc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
3790 outrel
.r_offset
= got_address
;
3791 outrel
.r_info
= ELF32_R_INFO (STN_UNDEF
, R_MIPS_32
);
3792 outrel
.r_addend
= value
;
3793 bfd_elf32_swap_reloca_out (abfd
, &outrel
, rloc
);
3799 /* Return the number of dynamic section symbols required by OUTPUT_BFD.
3800 The number might be exact or a worst-case estimate, depending on how
3801 much information is available to elf_backend_omit_section_dynsym at
3802 the current linking stage. */
3804 static bfd_size_type
3805 count_section_dynsyms (bfd
*output_bfd
, struct bfd_link_info
*info
)
3807 bfd_size_type count
;
3810 if (bfd_link_pic (info
)
3811 || elf_hash_table (info
)->is_relocatable_executable
)
3814 const struct elf_backend_data
*bed
;
3816 bed
= get_elf_backend_data (output_bfd
);
3817 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
3818 if ((p
->flags
& SEC_EXCLUDE
) == 0
3819 && (p
->flags
& SEC_ALLOC
) != 0
3820 && elf_hash_table (info
)->dynamic_relocs
3821 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
3827 /* Sort the dynamic symbol table so that symbols that need GOT entries
3828 appear towards the end. */
3831 mips_elf_sort_hash_table (bfd
*abfd
, struct bfd_link_info
*info
)
3833 struct mips_elf_link_hash_table
*htab
;
3834 struct mips_elf_hash_sort_data hsd
;
3835 struct mips_got_info
*g
;
3837 htab
= mips_elf_hash_table (info
);
3838 BFD_ASSERT (htab
!= NULL
);
3840 if (htab
->root
.dynsymcount
== 0)
3848 hsd
.max_unref_got_dynindx
3849 = hsd
.min_got_dynindx
3850 = (htab
->root
.dynsymcount
- g
->reloc_only_gotno
);
3851 /* Add 1 to local symbol indices to account for the mandatory NULL entry
3852 at the head of the table; see `_bfd_elf_link_renumber_dynsyms'. */
3853 hsd
.max_local_dynindx
= count_section_dynsyms (abfd
, info
) + 1;
3854 hsd
.max_non_got_dynindx
= htab
->root
.local_dynsymcount
+ 1;
3855 mips_elf_link_hash_traverse (htab
, mips_elf_sort_hash_table_f
, &hsd
);
3857 /* There should have been enough room in the symbol table to
3858 accommodate both the GOT and non-GOT symbols. */
3859 BFD_ASSERT (hsd
.max_local_dynindx
<= htab
->root
.local_dynsymcount
+ 1);
3860 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
3861 BFD_ASSERT (hsd
.max_unref_got_dynindx
== htab
->root
.dynsymcount
);
3862 BFD_ASSERT (htab
->root
.dynsymcount
- hsd
.min_got_dynindx
== g
->global_gotno
);
3864 /* Now we know which dynamic symbol has the lowest dynamic symbol
3865 table index in the GOT. */
3866 htab
->global_gotsym
= hsd
.low
;
3871 /* If H needs a GOT entry, assign it the highest available dynamic
3872 index. Otherwise, assign it the lowest available dynamic
3876 mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry
*h
, void *data
)
3878 struct mips_elf_hash_sort_data
*hsd
= data
;
3880 /* Symbols without dynamic symbol table entries aren't interesting
3882 if (h
->root
.dynindx
== -1)
3885 switch (h
->global_got_area
)
3888 if (h
->root
.forced_local
)
3889 h
->root
.dynindx
= hsd
->max_local_dynindx
++;
3891 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
3895 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
3896 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3899 case GGA_RELOC_ONLY
:
3900 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
3901 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3902 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
3909 /* Record that input bfd ABFD requires a GOT entry like *LOOKUP
3910 (which is owned by the caller and shouldn't be added to the
3911 hash table directly). */
3914 mips_elf_record_got_entry (struct bfd_link_info
*info
, bfd
*abfd
,
3915 struct mips_got_entry
*lookup
)
3917 struct mips_elf_link_hash_table
*htab
;
3918 struct mips_got_entry
*entry
;
3919 struct mips_got_info
*g
;
3920 void **loc
, **bfd_loc
;
3922 /* Make sure there's a slot for this entry in the master GOT. */
3923 htab
= mips_elf_hash_table (info
);
3925 loc
= htab_find_slot (g
->got_entries
, lookup
, INSERT
);
3929 /* Populate the entry if it isn't already. */
3930 entry
= (struct mips_got_entry
*) *loc
;
3933 entry
= (struct mips_got_entry
*) bfd_alloc (abfd
, sizeof (*entry
));
3937 lookup
->tls_initialized
= FALSE
;
3938 lookup
->gotidx
= -1;
3943 /* Reuse the same GOT entry for the BFD's GOT. */
3944 g
= mips_elf_bfd_got (abfd
, TRUE
);
3948 bfd_loc
= htab_find_slot (g
->got_entries
, lookup
, INSERT
);
3957 /* ABFD has a GOT relocation of type R_TYPE against H. Reserve a GOT
3958 entry for it. FOR_CALL is true if the caller is only interested in
3959 using the GOT entry for calls. */
3962 mips_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
3963 bfd
*abfd
, struct bfd_link_info
*info
,
3964 bfd_boolean for_call
, int r_type
)
3966 struct mips_elf_link_hash_table
*htab
;
3967 struct mips_elf_link_hash_entry
*hmips
;
3968 struct mips_got_entry entry
;
3969 unsigned char tls_type
;
3971 htab
= mips_elf_hash_table (info
);
3972 BFD_ASSERT (htab
!= NULL
);
3974 hmips
= (struct mips_elf_link_hash_entry
*) h
;
3976 hmips
->got_only_for_calls
= FALSE
;
3978 /* A global symbol in the GOT must also be in the dynamic symbol
3980 if (h
->dynindx
== -1)
3982 switch (ELF_ST_VISIBILITY (h
->other
))
3986 _bfd_mips_elf_hide_symbol (info
, h
, TRUE
);
3989 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3993 tls_type
= mips_elf_reloc_tls_type (r_type
);
3994 if (tls_type
== GOT_TLS_NONE
&& hmips
->global_got_area
> GGA_NORMAL
)
3995 hmips
->global_got_area
= GGA_NORMAL
;
3999 entry
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
4000 entry
.tls_type
= tls_type
;
4001 return mips_elf_record_got_entry (info
, abfd
, &entry
);
4004 /* ABFD has a GOT relocation of type R_TYPE against symbol SYMNDX + ADDEND,
4005 where SYMNDX is a local symbol. Reserve a GOT entry for it. */
4008 mips_elf_record_local_got_symbol (bfd
*abfd
, long symndx
, bfd_vma addend
,
4009 struct bfd_link_info
*info
, int r_type
)
4011 struct mips_elf_link_hash_table
*htab
;
4012 struct mips_got_info
*g
;
4013 struct mips_got_entry entry
;
4015 htab
= mips_elf_hash_table (info
);
4016 BFD_ASSERT (htab
!= NULL
);
4019 BFD_ASSERT (g
!= NULL
);
4022 entry
.symndx
= symndx
;
4023 entry
.d
.addend
= addend
;
4024 entry
.tls_type
= mips_elf_reloc_tls_type (r_type
);
4025 return mips_elf_record_got_entry (info
, abfd
, &entry
);
4028 /* Record that ABFD has a page relocation against SYMNDX + ADDEND.
4029 H is the symbol's hash table entry, or null if SYMNDX is local
4033 mips_elf_record_got_page_ref (struct bfd_link_info
*info
, bfd
*abfd
,
4034 long symndx
, struct elf_link_hash_entry
*h
,
4035 bfd_signed_vma addend
)
4037 struct mips_elf_link_hash_table
*htab
;
4038 struct mips_got_info
*g1
, *g2
;
4039 struct mips_got_page_ref lookup
, *entry
;
4040 void **loc
, **bfd_loc
;
4042 htab
= mips_elf_hash_table (info
);
4043 BFD_ASSERT (htab
!= NULL
);
4045 g1
= htab
->got_info
;
4046 BFD_ASSERT (g1
!= NULL
);
4051 lookup
.u
.h
= (struct mips_elf_link_hash_entry
*) h
;
4055 lookup
.symndx
= symndx
;
4056 lookup
.u
.abfd
= abfd
;
4058 lookup
.addend
= addend
;
4059 loc
= htab_find_slot (g1
->got_page_refs
, &lookup
, INSERT
);
4063 entry
= (struct mips_got_page_ref
*) *loc
;
4066 entry
= bfd_alloc (abfd
, sizeof (*entry
));
4074 /* Add the same entry to the BFD's GOT. */
4075 g2
= mips_elf_bfd_got (abfd
, TRUE
);
4079 bfd_loc
= htab_find_slot (g2
->got_page_refs
, &lookup
, INSERT
);
4089 /* Add room for N relocations to the .rel(a).dyn section in ABFD. */
4092 mips_elf_allocate_dynamic_relocations (bfd
*abfd
, struct bfd_link_info
*info
,
4096 struct mips_elf_link_hash_table
*htab
;
4098 htab
= mips_elf_hash_table (info
);
4099 BFD_ASSERT (htab
!= NULL
);
4101 s
= mips_elf_rel_dyn_section (info
, FALSE
);
4102 BFD_ASSERT (s
!= NULL
);
4104 if (htab
->is_vxworks
)
4105 s
->size
+= n
* MIPS_ELF_RELA_SIZE (abfd
);
4110 /* Make room for a null element. */
4111 s
->size
+= MIPS_ELF_REL_SIZE (abfd
);
4114 s
->size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
4118 /* A htab_traverse callback for GOT entries, with DATA pointing to a
4119 mips_elf_traverse_got_arg structure. Count the number of GOT
4120 entries and TLS relocs. Set DATA->value to true if we need
4121 to resolve indirect or warning symbols and then recreate the GOT. */
4124 mips_elf_check_recreate_got (void **entryp
, void *data
)
4126 struct mips_got_entry
*entry
;
4127 struct mips_elf_traverse_got_arg
*arg
;
4129 entry
= (struct mips_got_entry
*) *entryp
;
4130 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4131 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
4133 struct mips_elf_link_hash_entry
*h
;
4136 if (h
->root
.root
.type
== bfd_link_hash_indirect
4137 || h
->root
.root
.type
== bfd_link_hash_warning
)
4143 mips_elf_count_got_entry (arg
->info
, arg
->g
, entry
);
4147 /* A htab_traverse callback for GOT entries, with DATA pointing to a
4148 mips_elf_traverse_got_arg structure. Add all entries to DATA->g,
4149 converting entries for indirect and warning symbols into entries
4150 for the target symbol. Set DATA->g to null on error. */
4153 mips_elf_recreate_got (void **entryp
, void *data
)
4155 struct mips_got_entry new_entry
, *entry
;
4156 struct mips_elf_traverse_got_arg
*arg
;
4159 entry
= (struct mips_got_entry
*) *entryp
;
4160 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4161 if (entry
->abfd
!= NULL
4162 && entry
->symndx
== -1
4163 && (entry
->d
.h
->root
.root
.type
== bfd_link_hash_indirect
4164 || entry
->d
.h
->root
.root
.type
== bfd_link_hash_warning
))
4166 struct mips_elf_link_hash_entry
*h
;
4173 BFD_ASSERT (h
->global_got_area
== GGA_NONE
);
4174 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4176 while (h
->root
.root
.type
== bfd_link_hash_indirect
4177 || h
->root
.root
.type
== bfd_link_hash_warning
);
4180 slot
= htab_find_slot (arg
->g
->got_entries
, entry
, INSERT
);
4188 if (entry
== &new_entry
)
4190 entry
= bfd_alloc (entry
->abfd
, sizeof (*entry
));
4199 mips_elf_count_got_entry (arg
->info
, arg
->g
, entry
);
4204 /* Return the maximum number of GOT page entries required for RANGE. */
4207 mips_elf_pages_for_range (const struct mips_got_page_range
*range
)
4209 return (range
->max_addend
- range
->min_addend
+ 0x1ffff) >> 16;
4212 /* Record that G requires a page entry that can reach SEC + ADDEND. */
4215 mips_elf_record_got_page_entry (struct mips_elf_traverse_got_arg
*arg
,
4216 asection
*sec
, bfd_signed_vma addend
)
4218 struct mips_got_info
*g
= arg
->g
;
4219 struct mips_got_page_entry lookup
, *entry
;
4220 struct mips_got_page_range
**range_ptr
, *range
;
4221 bfd_vma old_pages
, new_pages
;
4224 /* Find the mips_got_page_entry hash table entry for this section. */
4226 loc
= htab_find_slot (g
->got_page_entries
, &lookup
, INSERT
);
4230 /* Create a mips_got_page_entry if this is the first time we've
4231 seen the section. */
4232 entry
= (struct mips_got_page_entry
*) *loc
;
4235 entry
= bfd_zalloc (arg
->info
->output_bfd
, sizeof (*entry
));
4243 /* Skip over ranges whose maximum extent cannot share a page entry
4245 range_ptr
= &entry
->ranges
;
4246 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
4247 range_ptr
= &(*range_ptr
)->next
;
4249 /* If we scanned to the end of the list, or found a range whose
4250 minimum extent cannot share a page entry with ADDEND, create
4251 a new singleton range. */
4253 if (!range
|| addend
< range
->min_addend
- 0xffff)
4255 range
= bfd_zalloc (arg
->info
->output_bfd
, sizeof (*range
));
4259 range
->next
= *range_ptr
;
4260 range
->min_addend
= addend
;
4261 range
->max_addend
= addend
;
4269 /* Remember how many pages the old range contributed. */
4270 old_pages
= mips_elf_pages_for_range (range
);
4272 /* Update the ranges. */
4273 if (addend
< range
->min_addend
)
4274 range
->min_addend
= addend
;
4275 else if (addend
> range
->max_addend
)
4277 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
4279 old_pages
+= mips_elf_pages_for_range (range
->next
);
4280 range
->max_addend
= range
->next
->max_addend
;
4281 range
->next
= range
->next
->next
;
4284 range
->max_addend
= addend
;
4287 /* Record any change in the total estimate. */
4288 new_pages
= mips_elf_pages_for_range (range
);
4289 if (old_pages
!= new_pages
)
4291 entry
->num_pages
+= new_pages
- old_pages
;
4292 g
->page_gotno
+= new_pages
- old_pages
;
4298 /* A htab_traverse callback for which *REFP points to a mips_got_page_ref
4299 and for which DATA points to a mips_elf_traverse_got_arg. Work out
4300 whether the page reference described by *REFP needs a GOT page entry,
4301 and record that entry in DATA->g if so. Set DATA->g to null on failure. */
4304 mips_elf_resolve_got_page_ref (void **refp
, void *data
)
4306 struct mips_got_page_ref
*ref
;
4307 struct mips_elf_traverse_got_arg
*arg
;
4308 struct mips_elf_link_hash_table
*htab
;
4312 ref
= (struct mips_got_page_ref
*) *refp
;
4313 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4314 htab
= mips_elf_hash_table (arg
->info
);
4316 if (ref
->symndx
< 0)
4318 struct mips_elf_link_hash_entry
*h
;
4320 /* Global GOT_PAGEs decay to GOT_DISP and so don't need page entries. */
4322 if (!SYMBOL_REFERENCES_LOCAL (arg
->info
, &h
->root
))
4325 /* Ignore undefined symbols; we'll issue an error later if
4327 if (!((h
->root
.root
.type
== bfd_link_hash_defined
4328 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4329 && h
->root
.root
.u
.def
.section
))
4332 sec
= h
->root
.root
.u
.def
.section
;
4333 addend
= h
->root
.root
.u
.def
.value
+ ref
->addend
;
4337 Elf_Internal_Sym
*isym
;
4339 /* Read in the symbol. */
4340 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, ref
->u
.abfd
,
4348 /* Get the associated input section. */
4349 sec
= bfd_section_from_elf_index (ref
->u
.abfd
, isym
->st_shndx
);
4356 /* If this is a mergable section, work out the section and offset
4357 of the merged data. For section symbols, the addend specifies
4358 of the offset _of_ the first byte in the data, otherwise it
4359 specifies the offset _from_ the first byte. */
4360 if (sec
->flags
& SEC_MERGE
)
4364 secinfo
= elf_section_data (sec
)->sec_info
;
4365 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
4366 addend
= _bfd_merged_section_offset (ref
->u
.abfd
, &sec
, secinfo
,
4367 isym
->st_value
+ ref
->addend
);
4369 addend
= _bfd_merged_section_offset (ref
->u
.abfd
, &sec
, secinfo
,
4370 isym
->st_value
) + ref
->addend
;
4373 addend
= isym
->st_value
+ ref
->addend
;
4375 if (!mips_elf_record_got_page_entry (arg
, sec
, addend
))
4383 /* If any entries in G->got_entries are for indirect or warning symbols,
4384 replace them with entries for the target symbol. Convert g->got_page_refs
4385 into got_page_entry structures and estimate the number of page entries
4386 that they require. */
4389 mips_elf_resolve_final_got_entries (struct bfd_link_info
*info
,
4390 struct mips_got_info
*g
)
4392 struct mips_elf_traverse_got_arg tga
;
4393 struct mips_got_info oldg
;
4400 htab_traverse (g
->got_entries
, mips_elf_check_recreate_got
, &tga
);
4404 g
->got_entries
= htab_create (htab_size (oldg
.got_entries
),
4405 mips_elf_got_entry_hash
,
4406 mips_elf_got_entry_eq
, NULL
);
4407 if (!g
->got_entries
)
4410 htab_traverse (oldg
.got_entries
, mips_elf_recreate_got
, &tga
);
4414 htab_delete (oldg
.got_entries
);
4417 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4418 mips_got_page_entry_eq
, NULL
);
4419 if (g
->got_page_entries
== NULL
)
4424 htab_traverse (g
->got_page_refs
, mips_elf_resolve_got_page_ref
, &tga
);
4429 /* Return true if a GOT entry for H should live in the local rather than
4433 mips_use_local_got_p (struct bfd_link_info
*info
,
4434 struct mips_elf_link_hash_entry
*h
)
4436 /* Symbols that aren't in the dynamic symbol table must live in the
4437 local GOT. This includes symbols that are completely undefined
4438 and which therefore don't bind locally. We'll report undefined
4439 symbols later if appropriate. */
4440 if (h
->root
.dynindx
== -1)
4443 /* Absolute symbols, if ever they need a GOT entry, cannot ever go
4444 to the local GOT, as they would be implicitly relocated by the
4445 base address by the dynamic loader. */
4446 if (bfd_is_abs_symbol (&h
->root
.root
))
4449 /* Symbols that bind locally can (and in the case of forced-local
4450 symbols, must) live in the local GOT. */
4451 if (h
->got_only_for_calls
4452 ? SYMBOL_CALLS_LOCAL (info
, &h
->root
)
4453 : SYMBOL_REFERENCES_LOCAL (info
, &h
->root
))
4456 /* If this is an executable that must provide a definition of the symbol,
4457 either though PLTs or copy relocations, then that address should go in
4458 the local rather than global GOT. */
4459 if (bfd_link_executable (info
) && h
->has_static_relocs
)
4465 /* A mips_elf_link_hash_traverse callback for which DATA points to the
4466 link_info structure. Decide whether the hash entry needs an entry in
4467 the global part of the primary GOT, setting global_got_area accordingly.
4468 Count the number of global symbols that are in the primary GOT only
4469 because they have relocations against them (reloc_only_gotno). */
4472 mips_elf_count_got_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
4474 struct bfd_link_info
*info
;
4475 struct mips_elf_link_hash_table
*htab
;
4476 struct mips_got_info
*g
;
4478 info
= (struct bfd_link_info
*) data
;
4479 htab
= mips_elf_hash_table (info
);
4481 if (h
->global_got_area
!= GGA_NONE
)
4483 /* Make a final decision about whether the symbol belongs in the
4484 local or global GOT. */
4485 if (mips_use_local_got_p (info
, h
))
4486 /* The symbol belongs in the local GOT. We no longer need this
4487 entry if it was only used for relocations; those relocations
4488 will be against the null or section symbol instead of H. */
4489 h
->global_got_area
= GGA_NONE
;
4490 else if (htab
->is_vxworks
4491 && h
->got_only_for_calls
4492 && h
->root
.plt
.plist
->mips_offset
!= MINUS_ONE
)
4493 /* On VxWorks, calls can refer directly to the .got.plt entry;
4494 they don't need entries in the regular GOT. .got.plt entries
4495 will be allocated by _bfd_mips_elf_adjust_dynamic_symbol. */
4496 h
->global_got_area
= GGA_NONE
;
4497 else if (h
->global_got_area
== GGA_RELOC_ONLY
)
4499 g
->reloc_only_gotno
++;
4506 /* A htab_traverse callback for GOT entries. Add each one to the GOT
4507 given in mips_elf_traverse_got_arg DATA. Clear DATA->G on error. */
4510 mips_elf_add_got_entry (void **entryp
, void *data
)
4512 struct mips_got_entry
*entry
;
4513 struct mips_elf_traverse_got_arg
*arg
;
4516 entry
= (struct mips_got_entry
*) *entryp
;
4517 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4518 slot
= htab_find_slot (arg
->g
->got_entries
, entry
, INSERT
);
4527 mips_elf_count_got_entry (arg
->info
, arg
->g
, entry
);
4532 /* A htab_traverse callback for GOT page entries. Add each one to the GOT
4533 given in mips_elf_traverse_got_arg DATA. Clear DATA->G on error. */
4536 mips_elf_add_got_page_entry (void **entryp
, void *data
)
4538 struct mips_got_page_entry
*entry
;
4539 struct mips_elf_traverse_got_arg
*arg
;
4542 entry
= (struct mips_got_page_entry
*) *entryp
;
4543 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4544 slot
= htab_find_slot (arg
->g
->got_page_entries
, entry
, INSERT
);
4553 arg
->g
->page_gotno
+= entry
->num_pages
;
4558 /* Consider merging FROM, which is ABFD's GOT, into TO. Return -1 if
4559 this would lead to overflow, 1 if they were merged successfully,
4560 and 0 if a merge failed due to lack of memory. (These values are chosen
4561 so that nonnegative return values can be returned by a htab_traverse
4565 mips_elf_merge_got_with (bfd
*abfd
, struct mips_got_info
*from
,
4566 struct mips_got_info
*to
,
4567 struct mips_elf_got_per_bfd_arg
*arg
)
4569 struct mips_elf_traverse_got_arg tga
;
4570 unsigned int estimate
;
4572 /* Work out how many page entries we would need for the combined GOT. */
4573 estimate
= arg
->max_pages
;
4574 if (estimate
>= from
->page_gotno
+ to
->page_gotno
)
4575 estimate
= from
->page_gotno
+ to
->page_gotno
;
4577 /* And conservatively estimate how many local and TLS entries
4579 estimate
+= from
->local_gotno
+ to
->local_gotno
;
4580 estimate
+= from
->tls_gotno
+ to
->tls_gotno
;
4582 /* If we're merging with the primary got, any TLS relocations will
4583 come after the full set of global entries. Otherwise estimate those
4584 conservatively as well. */
4585 if (to
== arg
->primary
&& from
->tls_gotno
+ to
->tls_gotno
)
4586 estimate
+= arg
->global_count
;
4588 estimate
+= from
->global_gotno
+ to
->global_gotno
;
4590 /* Bail out if the combined GOT might be too big. */
4591 if (estimate
> arg
->max_count
)
4594 /* Transfer the bfd's got information from FROM to TO. */
4595 tga
.info
= arg
->info
;
4597 htab_traverse (from
->got_entries
, mips_elf_add_got_entry
, &tga
);
4601 htab_traverse (from
->got_page_entries
, mips_elf_add_got_page_entry
, &tga
);
4605 mips_elf_replace_bfd_got (abfd
, to
);
4609 /* Attempt to merge GOT G, which belongs to ABFD. Try to use as much
4610 as possible of the primary got, since it doesn't require explicit
4611 dynamic relocations, but don't use bfds that would reference global
4612 symbols out of the addressable range. Failing the primary got,
4613 attempt to merge with the current got, or finish the current got
4614 and then make make the new got current. */
4617 mips_elf_merge_got (bfd
*abfd
, struct mips_got_info
*g
,
4618 struct mips_elf_got_per_bfd_arg
*arg
)
4620 unsigned int estimate
;
4623 if (!mips_elf_resolve_final_got_entries (arg
->info
, g
))
4626 /* Work out the number of page, local and TLS entries. */
4627 estimate
= arg
->max_pages
;
4628 if (estimate
> g
->page_gotno
)
4629 estimate
= g
->page_gotno
;
4630 estimate
+= g
->local_gotno
+ g
->tls_gotno
;
4632 /* We place TLS GOT entries after both locals and globals. The globals
4633 for the primary GOT may overflow the normal GOT size limit, so be
4634 sure not to merge a GOT which requires TLS with the primary GOT in that
4635 case. This doesn't affect non-primary GOTs. */
4636 estimate
+= (g
->tls_gotno
> 0 ? arg
->global_count
: g
->global_gotno
);
4638 if (estimate
<= arg
->max_count
)
4640 /* If we don't have a primary GOT, use it as
4641 a starting point for the primary GOT. */
4648 /* Try merging with the primary GOT. */
4649 result
= mips_elf_merge_got_with (abfd
, g
, arg
->primary
, arg
);
4654 /* If we can merge with the last-created got, do it. */
4657 result
= mips_elf_merge_got_with (abfd
, g
, arg
->current
, arg
);
4662 /* Well, we couldn't merge, so create a new GOT. Don't check if it
4663 fits; if it turns out that it doesn't, we'll get relocation
4664 overflows anyway. */
4665 g
->next
= arg
->current
;
4671 /* ENTRYP is a hash table entry for a mips_got_entry. Set its gotidx
4672 to GOTIDX, duplicating the entry if it has already been assigned
4673 an index in a different GOT. */
4676 mips_elf_set_gotidx (void **entryp
, long gotidx
)
4678 struct mips_got_entry
*entry
;
4680 entry
= (struct mips_got_entry
*) *entryp
;
4681 if (entry
->gotidx
> 0)
4683 struct mips_got_entry
*new_entry
;
4685 new_entry
= bfd_alloc (entry
->abfd
, sizeof (*entry
));
4689 *new_entry
= *entry
;
4690 *entryp
= new_entry
;
4693 entry
->gotidx
= gotidx
;
4697 /* Set the TLS GOT index for the GOT entry in ENTRYP. DATA points to a
4698 mips_elf_traverse_got_arg in which DATA->value is the size of one
4699 GOT entry. Set DATA->g to null on failure. */
4702 mips_elf_initialize_tls_index (void **entryp
, void *data
)
4704 struct mips_got_entry
*entry
;
4705 struct mips_elf_traverse_got_arg
*arg
;
4707 /* We're only interested in TLS symbols. */
4708 entry
= (struct mips_got_entry
*) *entryp
;
4709 if (entry
->tls_type
== GOT_TLS_NONE
)
4712 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4713 if (!mips_elf_set_gotidx (entryp
, arg
->value
* arg
->g
->tls_assigned_gotno
))
4719 /* Account for the entries we've just allocated. */
4720 arg
->g
->tls_assigned_gotno
+= mips_tls_got_entries (entry
->tls_type
);
4724 /* A htab_traverse callback for GOT entries, where DATA points to a
4725 mips_elf_traverse_got_arg. Set the global_got_area of each global
4726 symbol to DATA->value. */
4729 mips_elf_set_global_got_area (void **entryp
, void *data
)
4731 struct mips_got_entry
*entry
;
4732 struct mips_elf_traverse_got_arg
*arg
;
4734 entry
= (struct mips_got_entry
*) *entryp
;
4735 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4736 if (entry
->abfd
!= NULL
4737 && entry
->symndx
== -1
4738 && entry
->d
.h
->global_got_area
!= GGA_NONE
)
4739 entry
->d
.h
->global_got_area
= arg
->value
;
4743 /* A htab_traverse callback for secondary GOT entries, where DATA points
4744 to a mips_elf_traverse_got_arg. Assign GOT indices to global entries
4745 and record the number of relocations they require. DATA->value is
4746 the size of one GOT entry. Set DATA->g to null on failure. */
4749 mips_elf_set_global_gotidx (void **entryp
, void *data
)
4751 struct mips_got_entry
*entry
;
4752 struct mips_elf_traverse_got_arg
*arg
;
4754 entry
= (struct mips_got_entry
*) *entryp
;
4755 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4756 if (entry
->abfd
!= NULL
4757 && entry
->symndx
== -1
4758 && entry
->d
.h
->global_got_area
!= GGA_NONE
)
4760 if (!mips_elf_set_gotidx (entryp
, arg
->value
* arg
->g
->assigned_low_gotno
))
4765 arg
->g
->assigned_low_gotno
+= 1;
4767 if (bfd_link_pic (arg
->info
)
4768 || (elf_hash_table (arg
->info
)->dynamic_sections_created
4769 && entry
->d
.h
->root
.def_dynamic
4770 && !entry
->d
.h
->root
.def_regular
))
4771 arg
->g
->relocs
+= 1;
4777 /* A htab_traverse callback for GOT entries for which DATA is the
4778 bfd_link_info. Forbid any global symbols from having traditional
4779 lazy-binding stubs. */
4782 mips_elf_forbid_lazy_stubs (void **entryp
, void *data
)
4784 struct bfd_link_info
*info
;
4785 struct mips_elf_link_hash_table
*htab
;
4786 struct mips_got_entry
*entry
;
4788 entry
= (struct mips_got_entry
*) *entryp
;
4789 info
= (struct bfd_link_info
*) data
;
4790 htab
= mips_elf_hash_table (info
);
4791 BFD_ASSERT (htab
!= NULL
);
4793 if (entry
->abfd
!= NULL
4794 && entry
->symndx
== -1
4795 && entry
->d
.h
->needs_lazy_stub
)
4797 entry
->d
.h
->needs_lazy_stub
= FALSE
;
4798 htab
->lazy_stub_count
--;
4804 /* Return the offset of an input bfd IBFD's GOT from the beginning of
4807 mips_elf_adjust_gp (bfd
*abfd
, struct mips_got_info
*g
, bfd
*ibfd
)
4812 g
= mips_elf_bfd_got (ibfd
, FALSE
);
4816 BFD_ASSERT (g
->next
);
4820 return (g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
)
4821 * MIPS_ELF_GOT_SIZE (abfd
);
4824 /* Turn a single GOT that is too big for 16-bit addressing into
4825 a sequence of GOTs, each one 16-bit addressable. */
4828 mips_elf_multi_got (bfd
*abfd
, struct bfd_link_info
*info
,
4829 asection
*got
, bfd_size_type pages
)
4831 struct mips_elf_link_hash_table
*htab
;
4832 struct mips_elf_got_per_bfd_arg got_per_bfd_arg
;
4833 struct mips_elf_traverse_got_arg tga
;
4834 struct mips_got_info
*g
, *gg
;
4835 unsigned int assign
, needed_relocs
;
4838 dynobj
= elf_hash_table (info
)->dynobj
;
4839 htab
= mips_elf_hash_table (info
);
4840 BFD_ASSERT (htab
!= NULL
);
4844 got_per_bfd_arg
.obfd
= abfd
;
4845 got_per_bfd_arg
.info
= info
;
4846 got_per_bfd_arg
.current
= NULL
;
4847 got_per_bfd_arg
.primary
= NULL
;
4848 got_per_bfd_arg
.max_count
= ((MIPS_ELF_GOT_MAX_SIZE (info
)
4849 / MIPS_ELF_GOT_SIZE (abfd
))
4850 - htab
->reserved_gotno
);
4851 got_per_bfd_arg
.max_pages
= pages
;
4852 /* The number of globals that will be included in the primary GOT.
4853 See the calls to mips_elf_set_global_got_area below for more
4855 got_per_bfd_arg
.global_count
= g
->global_gotno
;
4857 /* Try to merge the GOTs of input bfds together, as long as they
4858 don't seem to exceed the maximum GOT size, choosing one of them
4859 to be the primary GOT. */
4860 for (ibfd
= info
->input_bfds
; ibfd
; ibfd
= ibfd
->link
.next
)
4862 gg
= mips_elf_bfd_got (ibfd
, FALSE
);
4863 if (gg
&& !mips_elf_merge_got (ibfd
, gg
, &got_per_bfd_arg
))
4867 /* If we do not find any suitable primary GOT, create an empty one. */
4868 if (got_per_bfd_arg
.primary
== NULL
)
4869 g
->next
= mips_elf_create_got_info (abfd
);
4871 g
->next
= got_per_bfd_arg
.primary
;
4872 g
->next
->next
= got_per_bfd_arg
.current
;
4874 /* GG is now the master GOT, and G is the primary GOT. */
4878 /* Map the output bfd to the primary got. That's what we're going
4879 to use for bfds that use GOT16 or GOT_PAGE relocations that we
4880 didn't mark in check_relocs, and we want a quick way to find it.
4881 We can't just use gg->next because we're going to reverse the
4883 mips_elf_replace_bfd_got (abfd
, g
);
4885 /* Every symbol that is referenced in a dynamic relocation must be
4886 present in the primary GOT, so arrange for them to appear after
4887 those that are actually referenced. */
4888 gg
->reloc_only_gotno
= gg
->global_gotno
- g
->global_gotno
;
4889 g
->global_gotno
= gg
->global_gotno
;
4892 tga
.value
= GGA_RELOC_ONLY
;
4893 htab_traverse (gg
->got_entries
, mips_elf_set_global_got_area
, &tga
);
4894 tga
.value
= GGA_NORMAL
;
4895 htab_traverse (g
->got_entries
, mips_elf_set_global_got_area
, &tga
);
4897 /* Now go through the GOTs assigning them offset ranges.
4898 [assigned_low_gotno, local_gotno[ will be set to the range of local
4899 entries in each GOT. We can then compute the end of a GOT by
4900 adding local_gotno to global_gotno. We reverse the list and make
4901 it circular since then we'll be able to quickly compute the
4902 beginning of a GOT, by computing the end of its predecessor. To
4903 avoid special cases for the primary GOT, while still preserving
4904 assertions that are valid for both single- and multi-got links,
4905 we arrange for the main got struct to have the right number of
4906 global entries, but set its local_gotno such that the initial
4907 offset of the primary GOT is zero. Remember that the primary GOT
4908 will become the last item in the circular linked list, so it
4909 points back to the master GOT. */
4910 gg
->local_gotno
= -g
->global_gotno
;
4911 gg
->global_gotno
= g
->global_gotno
;
4918 struct mips_got_info
*gn
;
4920 assign
+= htab
->reserved_gotno
;
4921 g
->assigned_low_gotno
= assign
;
4922 g
->local_gotno
+= assign
;
4923 g
->local_gotno
+= (pages
< g
->page_gotno
? pages
: g
->page_gotno
);
4924 g
->assigned_high_gotno
= g
->local_gotno
- 1;
4925 assign
= g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
;
4927 /* Take g out of the direct list, and push it onto the reversed
4928 list that gg points to. g->next is guaranteed to be nonnull after
4929 this operation, as required by mips_elf_initialize_tls_index. */
4934 /* Set up any TLS entries. We always place the TLS entries after
4935 all non-TLS entries. */
4936 g
->tls_assigned_gotno
= g
->local_gotno
+ g
->global_gotno
;
4938 tga
.value
= MIPS_ELF_GOT_SIZE (abfd
);
4939 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, &tga
);
4942 BFD_ASSERT (g
->tls_assigned_gotno
== assign
);
4944 /* Move onto the next GOT. It will be a secondary GOT if nonull. */
4947 /* Forbid global symbols in every non-primary GOT from having
4948 lazy-binding stubs. */
4950 htab_traverse (g
->got_entries
, mips_elf_forbid_lazy_stubs
, info
);
4954 got
->size
= assign
* MIPS_ELF_GOT_SIZE (abfd
);
4957 for (g
= gg
->next
; g
&& g
->next
!= gg
; g
= g
->next
)
4959 unsigned int save_assign
;
4961 /* Assign offsets to global GOT entries and count how many
4962 relocations they need. */
4963 save_assign
= g
->assigned_low_gotno
;
4964 g
->assigned_low_gotno
= g
->local_gotno
;
4966 tga
.value
= MIPS_ELF_GOT_SIZE (abfd
);
4968 htab_traverse (g
->got_entries
, mips_elf_set_global_gotidx
, &tga
);
4971 BFD_ASSERT (g
->assigned_low_gotno
== g
->local_gotno
+ g
->global_gotno
);
4972 g
->assigned_low_gotno
= save_assign
;
4974 if (bfd_link_pic (info
))
4976 g
->relocs
+= g
->local_gotno
- g
->assigned_low_gotno
;
4977 BFD_ASSERT (g
->assigned_low_gotno
== g
->next
->local_gotno
4978 + g
->next
->global_gotno
4979 + g
->next
->tls_gotno
4980 + htab
->reserved_gotno
);
4982 needed_relocs
+= g
->relocs
;
4984 needed_relocs
+= g
->relocs
;
4987 mips_elf_allocate_dynamic_relocations (dynobj
, info
,
4994 /* Returns the first relocation of type r_type found, beginning with
4995 RELOCATION. RELEND is one-past-the-end of the relocation table. */
4997 static const Elf_Internal_Rela
*
4998 mips_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
4999 const Elf_Internal_Rela
*relocation
,
5000 const Elf_Internal_Rela
*relend
)
5002 unsigned long r_symndx
= ELF_R_SYM (abfd
, relocation
->r_info
);
5004 while (relocation
< relend
)
5006 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
5007 && ELF_R_SYM (abfd
, relocation
->r_info
) == r_symndx
)
5013 /* We didn't find it. */
5017 /* Return whether an input relocation is against a local symbol. */
5020 mips_elf_local_relocation_p (bfd
*input_bfd
,
5021 const Elf_Internal_Rela
*relocation
,
5022 asection
**local_sections
)
5024 unsigned long r_symndx
;
5025 Elf_Internal_Shdr
*symtab_hdr
;
5028 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
5029 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5030 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
5032 if (r_symndx
< extsymoff
)
5034 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
5040 /* Sign-extend VALUE, which has the indicated number of BITS. */
5043 _bfd_mips_elf_sign_extend (bfd_vma value
, int bits
)
5045 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
5046 /* VALUE is negative. */
5047 value
|= ((bfd_vma
) - 1) << bits
;
5052 /* Return non-zero if the indicated VALUE has overflowed the maximum
5053 range expressible by a signed number with the indicated number of
5057 mips_elf_overflow_p (bfd_vma value
, int bits
)
5059 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
5061 if (svalue
> (1 << (bits
- 1)) - 1)
5062 /* The value is too big. */
5064 else if (svalue
< -(1 << (bits
- 1)))
5065 /* The value is too small. */
5072 /* Calculate the %high function. */
5075 mips_elf_high (bfd_vma value
)
5077 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
5080 /* Calculate the %higher function. */
5083 mips_elf_higher (bfd_vma value ATTRIBUTE_UNUSED
)
5086 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
5093 /* Calculate the %highest function. */
5096 mips_elf_highest (bfd_vma value ATTRIBUTE_UNUSED
)
5099 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
5106 /* Create the .compact_rel section. */
5109 mips_elf_create_compact_rel_section
5110 (bfd
*abfd
, struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5113 register asection
*s
;
5115 if (bfd_get_linker_section (abfd
, ".compact_rel") == NULL
)
5117 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
5120 s
= bfd_make_section_anyway_with_flags (abfd
, ".compact_rel", flags
);
5122 || ! bfd_set_section_alignment (abfd
, s
,
5123 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
5126 s
->size
= sizeof (Elf32_External_compact_rel
);
5132 /* Create the .got section to hold the global offset table. */
5135 mips_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
5138 register asection
*s
;
5139 struct elf_link_hash_entry
*h
;
5140 struct bfd_link_hash_entry
*bh
;
5141 struct mips_elf_link_hash_table
*htab
;
5143 htab
= mips_elf_hash_table (info
);
5144 BFD_ASSERT (htab
!= NULL
);
5146 /* This function may be called more than once. */
5147 if (htab
->root
.sgot
)
5150 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5151 | SEC_LINKER_CREATED
);
5153 /* We have to use an alignment of 2**4 here because this is hardcoded
5154 in the function stub generation and in the linker script. */
5155 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
5157 || ! bfd_set_section_alignment (abfd
, s
, 4))
5159 htab
->root
.sgot
= s
;
5161 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
5162 linker script because we don't want to define the symbol if we
5163 are not creating a global offset table. */
5165 if (! (_bfd_generic_link_add_one_symbol
5166 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
5167 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
5170 h
= (struct elf_link_hash_entry
*) bh
;
5173 h
->type
= STT_OBJECT
;
5174 h
->other
= (h
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
5175 elf_hash_table (info
)->hgot
= h
;
5177 if (bfd_link_pic (info
)
5178 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
5181 htab
->got_info
= mips_elf_create_got_info (abfd
);
5182 mips_elf_section_data (s
)->elf
.this_hdr
.sh_flags
5183 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5185 /* We also need a .got.plt section when generating PLTs. */
5186 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt",
5187 SEC_ALLOC
| SEC_LOAD
5190 | SEC_LINKER_CREATED
);
5193 htab
->root
.sgotplt
= s
;
5198 /* Return true if H refers to the special VxWorks __GOTT_BASE__ or
5199 __GOTT_INDEX__ symbols. These symbols are only special for
5200 shared objects; they are not used in executables. */
5203 is_gott_symbol (struct bfd_link_info
*info
, struct elf_link_hash_entry
*h
)
5205 return (mips_elf_hash_table (info
)->is_vxworks
5206 && bfd_link_pic (info
)
5207 && (strcmp (h
->root
.root
.string
, "__GOTT_BASE__") == 0
5208 || strcmp (h
->root
.root
.string
, "__GOTT_INDEX__") == 0));
5211 /* Return TRUE if a relocation of type R_TYPE from INPUT_BFD might
5212 require an la25 stub. See also mips_elf_local_pic_function_p,
5213 which determines whether the destination function ever requires a
5217 mips_elf_relocation_needs_la25_stub (bfd
*input_bfd
, int r_type
,
5218 bfd_boolean target_is_16_bit_code_p
)
5220 /* We specifically ignore branches and jumps from EF_PIC objects,
5221 where the onus is on the compiler or programmer to perform any
5222 necessary initialization of $25. Sometimes such initialization
5223 is unnecessary; for example, -mno-shared functions do not use
5224 the incoming value of $25, and may therefore be called directly. */
5225 if (PIC_OBJECT_P (input_bfd
))
5232 case R_MIPS_PC21_S2
:
5233 case R_MIPS_PC26_S2
:
5234 case R_MICROMIPS_26_S1
:
5235 case R_MICROMIPS_PC7_S1
:
5236 case R_MICROMIPS_PC10_S1
:
5237 case R_MICROMIPS_PC16_S1
:
5238 case R_MICROMIPS_PC23_S2
:
5242 return !target_is_16_bit_code_p
;
5249 /* Obtain the field relocated by RELOCATION. */
5252 mips_elf_obtain_contents (reloc_howto_type
*howto
,
5253 const Elf_Internal_Rela
*relocation
,
5254 bfd
*input_bfd
, bfd_byte
*contents
)
5257 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5258 unsigned int size
= bfd_get_reloc_size (howto
);
5260 /* Obtain the bytes. */
5262 x
= bfd_get (8 * size
, input_bfd
, location
);
5267 /* Store the field relocated by RELOCATION. */
5270 mips_elf_store_contents (reloc_howto_type
*howto
,
5271 const Elf_Internal_Rela
*relocation
,
5272 bfd
*input_bfd
, bfd_byte
*contents
, bfd_vma x
)
5274 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5275 unsigned int size
= bfd_get_reloc_size (howto
);
5277 /* Put the value into the output. */
5279 bfd_put (8 * size
, input_bfd
, x
, location
);
5282 /* Try to patch a load from GOT instruction in CONTENTS pointed to by
5283 RELOCATION described by HOWTO, with a move of 0 to the load target
5284 register, returning TRUE if that is successful and FALSE otherwise.
5285 If DOIT is FALSE, then only determine it patching is possible and
5286 return status without actually changing CONTENTS.
5290 mips_elf_nullify_got_load (bfd
*input_bfd
, bfd_byte
*contents
,
5291 const Elf_Internal_Rela
*relocation
,
5292 reloc_howto_type
*howto
, bfd_boolean doit
)
5294 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
5295 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5296 bfd_boolean nullified
= TRUE
;
5299 _bfd_mips_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
5301 /* Obtain the current value. */
5302 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
5304 /* Note that in the unshuffled MIPS16 encoding RX is at bits [21:19]
5305 while RY is at bits [18:16] of the combined 32-bit instruction word. */
5306 if (mips16_reloc_p (r_type
)
5307 && (((x
>> 22) & 0x3ff) == 0x3d3 /* LW */
5308 || ((x
>> 22) & 0x3ff) == 0x3c7)) /* LD */
5309 x
= (0x3cd << 22) | (x
& (7 << 16)) << 3; /* LI */
5310 else if (micromips_reloc_p (r_type
)
5311 && ((x
>> 26) & 0x37) == 0x37) /* LW/LD */
5312 x
= (0xc << 26) | (x
& (0x1f << 21)); /* ADDIU */
5313 else if (((x
>> 26) & 0x3f) == 0x23 /* LW */
5314 || ((x
>> 26) & 0x3f) == 0x37) /* LD */
5315 x
= (0x9 << 26) | (x
& (0x1f << 16)); /* ADDIU */
5319 /* Put the value into the output. */
5320 if (doit
&& nullified
)
5321 mips_elf_store_contents (howto
, relocation
, input_bfd
, contents
, x
);
5323 _bfd_mips_elf_reloc_shuffle (input_bfd
, r_type
, FALSE
, location
);
5328 /* Calculate the value produced by the RELOCATION (which comes from
5329 the INPUT_BFD). The ADDEND is the addend to use for this
5330 RELOCATION; RELOCATION->R_ADDEND is ignored.
5332 The result of the relocation calculation is stored in VALUEP.
5333 On exit, set *CROSS_MODE_JUMP_P to true if the relocation field
5334 is a MIPS16 or microMIPS jump to standard MIPS code, or vice versa.
5336 This function returns bfd_reloc_continue if the caller need take no
5337 further action regarding this relocation, bfd_reloc_notsupported if
5338 something goes dramatically wrong, bfd_reloc_overflow if an
5339 overflow occurs, and bfd_reloc_ok to indicate success. */
5341 static bfd_reloc_status_type
5342 mips_elf_calculate_relocation (bfd
*abfd
, bfd
*input_bfd
,
5343 asection
*input_section
, bfd_byte
*contents
,
5344 struct bfd_link_info
*info
,
5345 const Elf_Internal_Rela
*relocation
,
5346 bfd_vma addend
, reloc_howto_type
*howto
,
5347 Elf_Internal_Sym
*local_syms
,
5348 asection
**local_sections
, bfd_vma
*valuep
,
5350 bfd_boolean
*cross_mode_jump_p
,
5351 bfd_boolean save_addend
)
5353 /* The eventual value we will return. */
5355 /* The address of the symbol against which the relocation is
5358 /* The final GP value to be used for the relocatable, executable, or
5359 shared object file being produced. */
5361 /* The place (section offset or address) of the storage unit being
5364 /* The value of GP used to create the relocatable object. */
5366 /* The offset into the global offset table at which the address of
5367 the relocation entry symbol, adjusted by the addend, resides
5368 during execution. */
5369 bfd_vma g
= MINUS_ONE
;
5370 /* The section in which the symbol referenced by the relocation is
5372 asection
*sec
= NULL
;
5373 struct mips_elf_link_hash_entry
*h
= NULL
;
5374 /* TRUE if the symbol referred to by this relocation is a local
5376 bfd_boolean local_p
, was_local_p
;
5377 /* TRUE if the symbol referred to by this relocation is a section
5379 bfd_boolean section_p
= FALSE
;
5380 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
5381 bfd_boolean gp_disp_p
= FALSE
;
5382 /* TRUE if the symbol referred to by this relocation is
5383 "__gnu_local_gp". */
5384 bfd_boolean gnu_local_gp_p
= FALSE
;
5385 Elf_Internal_Shdr
*symtab_hdr
;
5387 unsigned long r_symndx
;
5389 /* TRUE if overflow occurred during the calculation of the
5390 relocation value. */
5391 bfd_boolean overflowed_p
;
5392 /* TRUE if this relocation refers to a MIPS16 function. */
5393 bfd_boolean target_is_16_bit_code_p
= FALSE
;
5394 bfd_boolean target_is_micromips_code_p
= FALSE
;
5395 struct mips_elf_link_hash_table
*htab
;
5397 bfd_boolean resolved_to_zero
;
5399 dynobj
= elf_hash_table (info
)->dynobj
;
5400 htab
= mips_elf_hash_table (info
);
5401 BFD_ASSERT (htab
!= NULL
);
5403 /* Parse the relocation. */
5404 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
5405 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
5406 p
= (input_section
->output_section
->vma
5407 + input_section
->output_offset
5408 + relocation
->r_offset
);
5410 /* Assume that there will be no overflow. */
5411 overflowed_p
= FALSE
;
5413 /* Figure out whether or not the symbol is local, and get the offset
5414 used in the array of hash table entries. */
5415 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5416 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
5418 was_local_p
= local_p
;
5419 if (! elf_bad_symtab (input_bfd
))
5420 extsymoff
= symtab_hdr
->sh_info
;
5423 /* The symbol table does not follow the rule that local symbols
5424 must come before globals. */
5428 /* Figure out the value of the symbol. */
5431 bfd_boolean micromips_p
= MICROMIPS_P (abfd
);
5432 Elf_Internal_Sym
*sym
;
5434 sym
= local_syms
+ r_symndx
;
5435 sec
= local_sections
[r_symndx
];
5437 section_p
= ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
;
5439 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5440 if (!section_p
|| (sec
->flags
& SEC_MERGE
))
5441 symbol
+= sym
->st_value
;
5442 if ((sec
->flags
& SEC_MERGE
) && section_p
)
5444 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
5446 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
5449 /* MIPS16/microMIPS text labels should be treated as odd. */
5450 if (ELF_ST_IS_COMPRESSED (sym
->st_other
))
5453 /* Record the name of this symbol, for our caller. */
5454 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
5455 symtab_hdr
->sh_link
,
5457 if (*namep
== NULL
|| **namep
== '\0')
5458 *namep
= bfd_section_name (input_bfd
, sec
);
5460 /* For relocations against a section symbol and ones against no
5461 symbol (absolute relocations) infer the ISA mode from the addend. */
5462 if (section_p
|| r_symndx
== STN_UNDEF
)
5464 target_is_16_bit_code_p
= (addend
& 1) && !micromips_p
;
5465 target_is_micromips_code_p
= (addend
& 1) && micromips_p
;
5467 /* For relocations against an absolute symbol infer the ISA mode
5468 from the value of the symbol plus addend. */
5469 else if (bfd_is_abs_section (sec
))
5471 target_is_16_bit_code_p
= ((symbol
+ addend
) & 1) && !micromips_p
;
5472 target_is_micromips_code_p
= ((symbol
+ addend
) & 1) && micromips_p
;
5474 /* Otherwise just use the regular symbol annotation available. */
5477 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (sym
->st_other
);
5478 target_is_micromips_code_p
= ELF_ST_IS_MICROMIPS (sym
->st_other
);
5483 /* ??? Could we use RELOC_FOR_GLOBAL_SYMBOL here ? */
5485 /* For global symbols we look up the symbol in the hash-table. */
5486 h
= ((struct mips_elf_link_hash_entry
*)
5487 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
5488 /* Find the real hash-table entry for this symbol. */
5489 while (h
->root
.root
.type
== bfd_link_hash_indirect
5490 || h
->root
.root
.type
== bfd_link_hash_warning
)
5491 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5493 /* Record the name of this symbol, for our caller. */
5494 *namep
= h
->root
.root
.root
.string
;
5496 /* See if this is the special _gp_disp symbol. Note that such a
5497 symbol must always be a global symbol. */
5498 if (strcmp (*namep
, "_gp_disp") == 0
5499 && ! NEWABI_P (input_bfd
))
5501 /* Relocations against _gp_disp are permitted only with
5502 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
5503 if (!hi16_reloc_p (r_type
) && !lo16_reloc_p (r_type
))
5504 return bfd_reloc_notsupported
;
5508 /* See if this is the special _gp symbol. Note that such a
5509 symbol must always be a global symbol. */
5510 else if (strcmp (*namep
, "__gnu_local_gp") == 0)
5511 gnu_local_gp_p
= TRUE
;
5514 /* If this symbol is defined, calculate its address. Note that
5515 _gp_disp is a magic symbol, always implicitly defined by the
5516 linker, so it's inappropriate to check to see whether or not
5518 else if ((h
->root
.root
.type
== bfd_link_hash_defined
5519 || h
->root
.root
.type
== bfd_link_hash_defweak
)
5520 && h
->root
.root
.u
.def
.section
)
5522 sec
= h
->root
.root
.u
.def
.section
;
5523 if (sec
->output_section
)
5524 symbol
= (h
->root
.root
.u
.def
.value
5525 + sec
->output_section
->vma
5526 + sec
->output_offset
);
5528 symbol
= h
->root
.root
.u
.def
.value
;
5530 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
5531 /* We allow relocations against undefined weak symbols, giving
5532 it the value zero, so that you can undefined weak functions
5533 and check to see if they exist by looking at their
5536 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
5537 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
5539 else if (strcmp (*namep
, SGI_COMPAT (input_bfd
)
5540 ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING") == 0)
5542 /* If this is a dynamic link, we should have created a
5543 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
5544 in _bfd_mips_elf_create_dynamic_sections.
5545 Otherwise, we should define the symbol with a value of 0.
5546 FIXME: It should probably get into the symbol table
5548 BFD_ASSERT (! bfd_link_pic (info
));
5549 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
5552 else if (ELF_MIPS_IS_OPTIONAL (h
->root
.other
))
5554 /* This is an optional symbol - an Irix specific extension to the
5555 ELF spec. Ignore it for now.
5556 XXX - FIXME - there is more to the spec for OPTIONAL symbols
5557 than simply ignoring them, but we do not handle this for now.
5558 For information see the "64-bit ELF Object File Specification"
5559 which is available from here:
5560 http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf */
5565 bfd_boolean reject_undefined
5566 = (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
5567 || ELF_ST_VISIBILITY (h
->root
.other
) != STV_DEFAULT
);
5569 (*info
->callbacks
->undefined_symbol
)
5570 (info
, h
->root
.root
.root
.string
, input_bfd
,
5571 input_section
, relocation
->r_offset
, reject_undefined
);
5573 if (reject_undefined
)
5574 return bfd_reloc_undefined
;
5579 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (h
->root
.other
);
5580 target_is_micromips_code_p
= ELF_ST_IS_MICROMIPS (h
->root
.other
);
5583 /* If this is a reference to a 16-bit function with a stub, we need
5584 to redirect the relocation to the stub unless:
5586 (a) the relocation is for a MIPS16 JAL;
5588 (b) the relocation is for a MIPS16 PIC call, and there are no
5589 non-MIPS16 uses of the GOT slot; or
5591 (c) the section allows direct references to MIPS16 functions. */
5592 if (r_type
!= R_MIPS16_26
5593 && !bfd_link_relocatable (info
)
5595 && h
->fn_stub
!= NULL
5596 && (r_type
!= R_MIPS16_CALL16
|| h
->need_fn_stub
))
5598 && mips_elf_tdata (input_bfd
)->local_stubs
!= NULL
5599 && mips_elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5600 && !section_allows_mips16_refs_p (input_section
))
5602 /* This is a 32- or 64-bit call to a 16-bit function. We should
5603 have already noticed that we were going to need the
5607 sec
= mips_elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5612 BFD_ASSERT (h
->need_fn_stub
);
5615 /* If a LA25 header for the stub itself exists, point to the
5616 prepended LUI/ADDIU sequence. */
5617 sec
= h
->la25_stub
->stub_section
;
5618 value
= h
->la25_stub
->offset
;
5627 symbol
= sec
->output_section
->vma
+ sec
->output_offset
+ value
;
5628 /* The target is 16-bit, but the stub isn't. */
5629 target_is_16_bit_code_p
= FALSE
;
5631 /* If this is a MIPS16 call with a stub, that is made through the PLT or
5632 to a standard MIPS function, we need to redirect the call to the stub.
5633 Note that we specifically exclude R_MIPS16_CALL16 from this behavior;
5634 indirect calls should use an indirect stub instead. */
5635 else if (r_type
== R_MIPS16_26
&& !bfd_link_relocatable (info
)
5636 && ((h
!= NULL
&& (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
))
5638 && mips_elf_tdata (input_bfd
)->local_call_stubs
!= NULL
5639 && mips_elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
] != NULL
))
5640 && ((h
!= NULL
&& h
->use_plt_entry
) || !target_is_16_bit_code_p
))
5643 sec
= mips_elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
];
5646 /* If both call_stub and call_fp_stub are defined, we can figure
5647 out which one to use by checking which one appears in the input
5649 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
5654 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5656 if (CALL_FP_STUB_P (bfd_get_section_name (input_bfd
, o
)))
5658 sec
= h
->call_fp_stub
;
5665 else if (h
->call_stub
!= NULL
)
5668 sec
= h
->call_fp_stub
;
5671 BFD_ASSERT (sec
->size
> 0);
5672 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5674 /* If this is a direct call to a PIC function, redirect to the
5676 else if (h
!= NULL
&& h
->la25_stub
5677 && mips_elf_relocation_needs_la25_stub (input_bfd
, r_type
,
5678 target_is_16_bit_code_p
))
5680 symbol
= (h
->la25_stub
->stub_section
->output_section
->vma
5681 + h
->la25_stub
->stub_section
->output_offset
5682 + h
->la25_stub
->offset
);
5683 if (ELF_ST_IS_MICROMIPS (h
->root
.other
))
5686 /* For direct MIPS16 and microMIPS calls make sure the compressed PLT
5687 entry is used if a standard PLT entry has also been made. In this
5688 case the symbol will have been set by mips_elf_set_plt_sym_value
5689 to point to the standard PLT entry, so redirect to the compressed
5691 else if ((mips16_branch_reloc_p (r_type
)
5692 || micromips_branch_reloc_p (r_type
))
5693 && !bfd_link_relocatable (info
)
5696 && h
->root
.plt
.plist
->comp_offset
!= MINUS_ONE
5697 && h
->root
.plt
.plist
->mips_offset
!= MINUS_ONE
)
5699 bfd_boolean micromips_p
= MICROMIPS_P (abfd
);
5701 sec
= htab
->root
.splt
;
5702 symbol
= (sec
->output_section
->vma
5703 + sec
->output_offset
5704 + htab
->plt_header_size
5705 + htab
->plt_mips_offset
5706 + h
->root
.plt
.plist
->comp_offset
5709 target_is_16_bit_code_p
= !micromips_p
;
5710 target_is_micromips_code_p
= micromips_p
;
5713 /* Make sure MIPS16 and microMIPS are not used together. */
5714 if ((mips16_branch_reloc_p (r_type
) && target_is_micromips_code_p
)
5715 || (micromips_branch_reloc_p (r_type
) && target_is_16_bit_code_p
))
5718 (_("MIPS16 and microMIPS functions cannot call each other"));
5719 return bfd_reloc_notsupported
;
5722 /* Calls from 16-bit code to 32-bit code and vice versa require the
5723 mode change. However, we can ignore calls to undefined weak symbols,
5724 which should never be executed at runtime. This exception is important
5725 because the assembly writer may have "known" that any definition of the
5726 symbol would be 16-bit code, and that direct jumps were therefore
5728 *cross_mode_jump_p
= (!bfd_link_relocatable (info
)
5729 && !(h
&& h
->root
.root
.type
== bfd_link_hash_undefweak
)
5730 && ((mips16_branch_reloc_p (r_type
)
5731 && !target_is_16_bit_code_p
)
5732 || (micromips_branch_reloc_p (r_type
)
5733 && !target_is_micromips_code_p
)
5734 || ((branch_reloc_p (r_type
)
5735 || r_type
== R_MIPS_JALR
)
5736 && (target_is_16_bit_code_p
5737 || target_is_micromips_code_p
))));
5739 resolved_to_zero
= (h
!= NULL
5740 && UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->root
));
5744 case R_MIPS16_CALL16
:
5745 case R_MIPS16_GOT16
:
5748 case R_MIPS_GOT_PAGE
:
5749 case R_MIPS_GOT_DISP
:
5750 case R_MIPS_GOT_LO16
:
5751 case R_MIPS_CALL_LO16
:
5752 case R_MICROMIPS_CALL16
:
5753 case R_MICROMIPS_GOT16
:
5754 case R_MICROMIPS_GOT_PAGE
:
5755 case R_MICROMIPS_GOT_DISP
:
5756 case R_MICROMIPS_GOT_LO16
:
5757 case R_MICROMIPS_CALL_LO16
:
5758 if (resolved_to_zero
5759 && !bfd_link_relocatable (info
)
5760 && mips_elf_nullify_got_load (input_bfd
, contents
,
5761 relocation
, howto
, TRUE
))
5762 return bfd_reloc_continue
;
5765 case R_MIPS_GOT_HI16
:
5766 case R_MIPS_CALL_HI16
:
5767 case R_MICROMIPS_GOT_HI16
:
5768 case R_MICROMIPS_CALL_HI16
:
5769 if (resolved_to_zero
5770 && htab
->use_absolute_zero
5771 && bfd_link_pic (info
))
5773 /* Redirect to the special `__gnu_absolute_zero' symbol. */
5774 h
= mips_elf_link_hash_lookup (htab
, "__gnu_absolute_zero",
5775 FALSE
, FALSE
, FALSE
);
5776 BFD_ASSERT (h
!= NULL
);
5781 local_p
= (h
== NULL
|| mips_use_local_got_p (info
, h
));
5783 gp0
= _bfd_get_gp_value (input_bfd
);
5784 gp
= _bfd_get_gp_value (abfd
);
5786 gp
+= mips_elf_adjust_gp (abfd
, htab
->got_info
, input_bfd
);
5791 /* Global R_MIPS_GOT_PAGE/R_MICROMIPS_GOT_PAGE relocations are equivalent
5792 to R_MIPS_GOT_DISP/R_MICROMIPS_GOT_DISP. The addend is applied by the
5793 corresponding R_MIPS_GOT_OFST/R_MICROMIPS_GOT_OFST. */
5794 if (got_page_reloc_p (r_type
) && !local_p
)
5796 r_type
= (micromips_reloc_p (r_type
)
5797 ? R_MICROMIPS_GOT_DISP
: R_MIPS_GOT_DISP
);
5801 /* If we haven't already determined the GOT offset, and we're going
5802 to need it, get it now. */
5805 case R_MIPS16_CALL16
:
5806 case R_MIPS16_GOT16
:
5809 case R_MIPS_GOT_DISP
:
5810 case R_MIPS_GOT_HI16
:
5811 case R_MIPS_CALL_HI16
:
5812 case R_MIPS_GOT_LO16
:
5813 case R_MIPS_CALL_LO16
:
5814 case R_MICROMIPS_CALL16
:
5815 case R_MICROMIPS_GOT16
:
5816 case R_MICROMIPS_GOT_DISP
:
5817 case R_MICROMIPS_GOT_HI16
:
5818 case R_MICROMIPS_CALL_HI16
:
5819 case R_MICROMIPS_GOT_LO16
:
5820 case R_MICROMIPS_CALL_LO16
:
5822 case R_MIPS_TLS_GOTTPREL
:
5823 case R_MIPS_TLS_LDM
:
5824 case R_MIPS16_TLS_GD
:
5825 case R_MIPS16_TLS_GOTTPREL
:
5826 case R_MIPS16_TLS_LDM
:
5827 case R_MICROMIPS_TLS_GD
:
5828 case R_MICROMIPS_TLS_GOTTPREL
:
5829 case R_MICROMIPS_TLS_LDM
:
5830 /* Find the index into the GOT where this value is located. */
5831 if (tls_ldm_reloc_p (r_type
))
5833 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
5834 0, 0, NULL
, r_type
);
5836 return bfd_reloc_outofrange
;
5840 /* On VxWorks, CALL relocations should refer to the .got.plt
5841 entry, which is initialized to point at the PLT stub. */
5842 if (htab
->is_vxworks
5843 && (call_hi16_reloc_p (r_type
)
5844 || call_lo16_reloc_p (r_type
)
5845 || call16_reloc_p (r_type
)))
5847 BFD_ASSERT (addend
== 0);
5848 BFD_ASSERT (h
->root
.needs_plt
);
5849 g
= mips_elf_gotplt_index (info
, &h
->root
);
5853 BFD_ASSERT (addend
== 0);
5854 g
= mips_elf_global_got_index (abfd
, info
, input_bfd
,
5856 if (!TLS_RELOC_P (r_type
)
5857 && !elf_hash_table (info
)->dynamic_sections_created
)
5858 /* This is a static link. We must initialize the GOT entry. */
5859 MIPS_ELF_PUT_WORD (dynobj
, symbol
, htab
->root
.sgot
->contents
+ g
);
5862 else if (!htab
->is_vxworks
5863 && (call16_reloc_p (r_type
) || got16_reloc_p (r_type
)))
5864 /* The calculation below does not involve "g". */
5868 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
5869 symbol
+ addend
, r_symndx
, h
, r_type
);
5871 return bfd_reloc_outofrange
;
5874 /* Convert GOT indices to actual offsets. */
5875 g
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, g
);
5879 /* Relocations against the VxWorks __GOTT_BASE__ and __GOTT_INDEX__
5880 symbols are resolved by the loader. Add them to .rela.dyn. */
5881 if (h
!= NULL
&& is_gott_symbol (info
, &h
->root
))
5883 Elf_Internal_Rela outrel
;
5887 s
= mips_elf_rel_dyn_section (info
, FALSE
);
5888 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5890 outrel
.r_offset
= (input_section
->output_section
->vma
5891 + input_section
->output_offset
5892 + relocation
->r_offset
);
5893 outrel
.r_info
= ELF32_R_INFO (h
->root
.dynindx
, r_type
);
5894 outrel
.r_addend
= addend
;
5895 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
5897 /* If we've written this relocation for a readonly section,
5898 we need to set DF_TEXTREL again, so that we do not delete the
5900 if (MIPS_ELF_READONLY_SECTION (input_section
))
5901 info
->flags
|= DF_TEXTREL
;
5904 return bfd_reloc_ok
;
5907 /* Figure out what kind of relocation is being performed. */
5911 return bfd_reloc_continue
;
5914 if (howto
->partial_inplace
)
5915 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
5916 value
= symbol
+ addend
;
5917 overflowed_p
= mips_elf_overflow_p (value
, 16);
5923 if ((bfd_link_pic (info
)
5924 || (htab
->root
.dynamic_sections_created
5926 && h
->root
.def_dynamic
5927 && !h
->root
.def_regular
5928 && !h
->has_static_relocs
))
5929 && r_symndx
!= STN_UNDEF
5931 || h
->root
.root
.type
!= bfd_link_hash_undefweak
5932 || (ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
5933 && !resolved_to_zero
))
5934 && (input_section
->flags
& SEC_ALLOC
) != 0)
5936 /* If we're creating a shared library, then we can't know
5937 where the symbol will end up. So, we create a relocation
5938 record in the output, and leave the job up to the dynamic
5939 linker. We must do the same for executable references to
5940 shared library symbols, unless we've decided to use copy
5941 relocs or PLTs instead. */
5943 if (!mips_elf_create_dynamic_relocation (abfd
,
5951 return bfd_reloc_undefined
;
5955 if (r_type
!= R_MIPS_REL32
)
5956 value
= symbol
+ addend
;
5960 value
&= howto
->dst_mask
;
5964 value
= symbol
+ addend
- p
;
5965 value
&= howto
->dst_mask
;
5969 /* The calculation for R_MIPS16_26 is just the same as for an
5970 R_MIPS_26. It's only the storage of the relocated field into
5971 the output file that's different. That's handled in
5972 mips_elf_perform_relocation. So, we just fall through to the
5973 R_MIPS_26 case here. */
5975 case R_MICROMIPS_26_S1
:
5979 /* Shift is 2, unusually, for microMIPS JALX. */
5980 shift
= (!*cross_mode_jump_p
&& r_type
== R_MICROMIPS_26_S1
) ? 1 : 2;
5982 if (howto
->partial_inplace
&& !section_p
)
5983 value
= _bfd_mips_elf_sign_extend (addend
, 26 + shift
);
5988 /* Make sure the target of a jump is suitably aligned. Bit 0 must
5989 be the correct ISA mode selector except for weak undefined
5991 if ((was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
5992 && (*cross_mode_jump_p
5993 ? (value
& 3) != (r_type
== R_MIPS_26
)
5994 : (value
& ((1 << shift
) - 1)) != (r_type
!= R_MIPS_26
)))
5995 return bfd_reloc_outofrange
;
5998 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
5999 overflowed_p
= (value
>> 26) != ((p
+ 4) >> (26 + shift
));
6000 value
&= howto
->dst_mask
;
6004 case R_MIPS_TLS_DTPREL_HI16
:
6005 case R_MIPS16_TLS_DTPREL_HI16
:
6006 case R_MICROMIPS_TLS_DTPREL_HI16
:
6007 value
= (mips_elf_high (addend
+ symbol
- dtprel_base (info
))
6011 case R_MIPS_TLS_DTPREL_LO16
:
6012 case R_MIPS_TLS_DTPREL32
:
6013 case R_MIPS_TLS_DTPREL64
:
6014 case R_MIPS16_TLS_DTPREL_LO16
:
6015 case R_MICROMIPS_TLS_DTPREL_LO16
:
6016 value
= (symbol
+ addend
- dtprel_base (info
)) & howto
->dst_mask
;
6019 case R_MIPS_TLS_TPREL_HI16
:
6020 case R_MIPS16_TLS_TPREL_HI16
:
6021 case R_MICROMIPS_TLS_TPREL_HI16
:
6022 value
= (mips_elf_high (addend
+ symbol
- tprel_base (info
))
6026 case R_MIPS_TLS_TPREL_LO16
:
6027 case R_MIPS_TLS_TPREL32
:
6028 case R_MIPS_TLS_TPREL64
:
6029 case R_MIPS16_TLS_TPREL_LO16
:
6030 case R_MICROMIPS_TLS_TPREL_LO16
:
6031 value
= (symbol
+ addend
- tprel_base (info
)) & howto
->dst_mask
;
6036 case R_MICROMIPS_HI16
:
6039 value
= mips_elf_high (addend
+ symbol
);
6040 value
&= howto
->dst_mask
;
6044 /* For MIPS16 ABI code we generate this sequence
6045 0: li $v0,%hi(_gp_disp)
6046 4: addiupc $v1,%lo(_gp_disp)
6050 So the offsets of hi and lo relocs are the same, but the
6051 base $pc is that used by the ADDIUPC instruction at $t9 + 4.
6052 ADDIUPC clears the low two bits of the instruction address,
6053 so the base is ($t9 + 4) & ~3. */
6054 if (r_type
== R_MIPS16_HI16
)
6055 value
= mips_elf_high (addend
+ gp
- ((p
+ 4) & ~(bfd_vma
) 0x3));
6056 /* The microMIPS .cpload sequence uses the same assembly
6057 instructions as the traditional psABI version, but the
6058 incoming $t9 has the low bit set. */
6059 else if (r_type
== R_MICROMIPS_HI16
)
6060 value
= mips_elf_high (addend
+ gp
- p
- 1);
6062 value
= mips_elf_high (addend
+ gp
- p
);
6068 case R_MICROMIPS_LO16
:
6069 case R_MICROMIPS_HI0_LO16
:
6071 value
= (symbol
+ addend
) & howto
->dst_mask
;
6074 /* See the comment for R_MIPS16_HI16 above for the reason
6075 for this conditional. */
6076 if (r_type
== R_MIPS16_LO16
)
6077 value
= addend
+ gp
- (p
& ~(bfd_vma
) 0x3);
6078 else if (r_type
== R_MICROMIPS_LO16
6079 || r_type
== R_MICROMIPS_HI0_LO16
)
6080 value
= addend
+ gp
- p
+ 3;
6082 value
= addend
+ gp
- p
+ 4;
6083 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
6084 for overflow. But, on, say, IRIX5, relocations against
6085 _gp_disp are normally generated from the .cpload
6086 pseudo-op. It generates code that normally looks like
6089 lui $gp,%hi(_gp_disp)
6090 addiu $gp,$gp,%lo(_gp_disp)
6093 Here $t9 holds the address of the function being called,
6094 as required by the MIPS ELF ABI. The R_MIPS_LO16
6095 relocation can easily overflow in this situation, but the
6096 R_MIPS_HI16 relocation will handle the overflow.
6097 Therefore, we consider this a bug in the MIPS ABI, and do
6098 not check for overflow here. */
6102 case R_MIPS_LITERAL
:
6103 case R_MICROMIPS_LITERAL
:
6104 /* Because we don't merge literal sections, we can handle this
6105 just like R_MIPS_GPREL16. In the long run, we should merge
6106 shared literals, and then we will need to additional work
6111 case R_MIPS16_GPREL
:
6112 /* The R_MIPS16_GPREL performs the same calculation as
6113 R_MIPS_GPREL16, but stores the relocated bits in a different
6114 order. We don't need to do anything special here; the
6115 differences are handled in mips_elf_perform_relocation. */
6116 case R_MIPS_GPREL16
:
6117 case R_MICROMIPS_GPREL7_S2
:
6118 case R_MICROMIPS_GPREL16
:
6119 /* Only sign-extend the addend if it was extracted from the
6120 instruction. If the addend was separate, leave it alone,
6121 otherwise we may lose significant bits. */
6122 if (howto
->partial_inplace
)
6123 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
6124 value
= symbol
+ addend
- gp
;
6125 /* If the symbol was local, any earlier relocatable links will
6126 have adjusted its addend with the gp offset, so compensate
6127 for that now. Don't do it for symbols forced local in this
6128 link, though, since they won't have had the gp offset applied
6132 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6133 overflowed_p
= mips_elf_overflow_p (value
, 16);
6136 case R_MIPS16_GOT16
:
6137 case R_MIPS16_CALL16
:
6140 case R_MICROMIPS_GOT16
:
6141 case R_MICROMIPS_CALL16
:
6142 /* VxWorks does not have separate local and global semantics for
6143 R_MIPS*_GOT16; every relocation evaluates to "G". */
6144 if (!htab
->is_vxworks
&& local_p
)
6146 value
= mips_elf_got16_entry (abfd
, input_bfd
, info
,
6147 symbol
+ addend
, !was_local_p
);
6148 if (value
== MINUS_ONE
)
6149 return bfd_reloc_outofrange
;
6151 = mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
6152 overflowed_p
= mips_elf_overflow_p (value
, 16);
6159 case R_MIPS_TLS_GOTTPREL
:
6160 case R_MIPS_TLS_LDM
:
6161 case R_MIPS_GOT_DISP
:
6162 case R_MIPS16_TLS_GD
:
6163 case R_MIPS16_TLS_GOTTPREL
:
6164 case R_MIPS16_TLS_LDM
:
6165 case R_MICROMIPS_TLS_GD
:
6166 case R_MICROMIPS_TLS_GOTTPREL
:
6167 case R_MICROMIPS_TLS_LDM
:
6168 case R_MICROMIPS_GOT_DISP
:
6170 overflowed_p
= mips_elf_overflow_p (value
, 16);
6173 case R_MIPS_GPREL32
:
6174 value
= (addend
+ symbol
+ gp0
- gp
);
6176 value
&= howto
->dst_mask
;
6180 case R_MIPS_GNU_REL16_S2
:
6181 if (howto
->partial_inplace
)
6182 addend
= _bfd_mips_elf_sign_extend (addend
, 18);
6184 /* No need to exclude weak undefined symbols here as they resolve
6185 to 0 and never set `*cross_mode_jump_p', so this alignment check
6186 will never trigger for them. */
6187 if (*cross_mode_jump_p
6188 ? ((symbol
+ addend
) & 3) != 1
6189 : ((symbol
+ addend
) & 3) != 0)
6190 return bfd_reloc_outofrange
;
6192 value
= symbol
+ addend
- p
;
6193 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6194 overflowed_p
= mips_elf_overflow_p (value
, 18);
6195 value
>>= howto
->rightshift
;
6196 value
&= howto
->dst_mask
;
6199 case R_MIPS16_PC16_S1
:
6200 if (howto
->partial_inplace
)
6201 addend
= _bfd_mips_elf_sign_extend (addend
, 17);
6203 if ((was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6204 && (*cross_mode_jump_p
6205 ? ((symbol
+ addend
) & 3) != 0
6206 : ((symbol
+ addend
) & 1) == 0))
6207 return bfd_reloc_outofrange
;
6209 value
= symbol
+ addend
- p
;
6210 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6211 overflowed_p
= mips_elf_overflow_p (value
, 17);
6212 value
>>= howto
->rightshift
;
6213 value
&= howto
->dst_mask
;
6216 case R_MIPS_PC21_S2
:
6217 if (howto
->partial_inplace
)
6218 addend
= _bfd_mips_elf_sign_extend (addend
, 23);
6220 if ((symbol
+ addend
) & 3)
6221 return bfd_reloc_outofrange
;
6223 value
= symbol
+ addend
- p
;
6224 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6225 overflowed_p
= mips_elf_overflow_p (value
, 23);
6226 value
>>= howto
->rightshift
;
6227 value
&= howto
->dst_mask
;
6230 case R_MIPS_PC26_S2
:
6231 if (howto
->partial_inplace
)
6232 addend
= _bfd_mips_elf_sign_extend (addend
, 28);
6234 if ((symbol
+ addend
) & 3)
6235 return bfd_reloc_outofrange
;
6237 value
= symbol
+ addend
- p
;
6238 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6239 overflowed_p
= mips_elf_overflow_p (value
, 28);
6240 value
>>= howto
->rightshift
;
6241 value
&= howto
->dst_mask
;
6244 case R_MIPS_PC18_S3
:
6245 if (howto
->partial_inplace
)
6246 addend
= _bfd_mips_elf_sign_extend (addend
, 21);
6248 if ((symbol
+ addend
) & 7)
6249 return bfd_reloc_outofrange
;
6251 value
= symbol
+ addend
- ((p
| 7) ^ 7);
6252 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6253 overflowed_p
= mips_elf_overflow_p (value
, 21);
6254 value
>>= howto
->rightshift
;
6255 value
&= howto
->dst_mask
;
6258 case R_MIPS_PC19_S2
:
6259 if (howto
->partial_inplace
)
6260 addend
= _bfd_mips_elf_sign_extend (addend
, 21);
6262 if ((symbol
+ addend
) & 3)
6263 return bfd_reloc_outofrange
;
6265 value
= symbol
+ addend
- p
;
6266 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6267 overflowed_p
= mips_elf_overflow_p (value
, 21);
6268 value
>>= howto
->rightshift
;
6269 value
&= howto
->dst_mask
;
6273 value
= mips_elf_high (symbol
+ addend
- p
);
6274 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6275 overflowed_p
= mips_elf_overflow_p (value
, 16);
6276 value
&= howto
->dst_mask
;
6280 if (howto
->partial_inplace
)
6281 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
6282 value
= symbol
+ addend
- p
;
6283 value
&= howto
->dst_mask
;
6286 case R_MICROMIPS_PC7_S1
:
6287 if (howto
->partial_inplace
)
6288 addend
= _bfd_mips_elf_sign_extend (addend
, 8);
6290 if ((was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6291 && (*cross_mode_jump_p
6292 ? ((symbol
+ addend
+ 2) & 3) != 0
6293 : ((symbol
+ addend
+ 2) & 1) == 0))
6294 return bfd_reloc_outofrange
;
6296 value
= symbol
+ addend
- p
;
6297 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6298 overflowed_p
= mips_elf_overflow_p (value
, 8);
6299 value
>>= howto
->rightshift
;
6300 value
&= howto
->dst_mask
;
6303 case R_MICROMIPS_PC10_S1
:
6304 if (howto
->partial_inplace
)
6305 addend
= _bfd_mips_elf_sign_extend (addend
, 11);
6307 if ((was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6308 && (*cross_mode_jump_p
6309 ? ((symbol
+ addend
+ 2) & 3) != 0
6310 : ((symbol
+ addend
+ 2) & 1) == 0))
6311 return bfd_reloc_outofrange
;
6313 value
= symbol
+ addend
- p
;
6314 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6315 overflowed_p
= mips_elf_overflow_p (value
, 11);
6316 value
>>= howto
->rightshift
;
6317 value
&= howto
->dst_mask
;
6320 case R_MICROMIPS_PC16_S1
:
6321 if (howto
->partial_inplace
)
6322 addend
= _bfd_mips_elf_sign_extend (addend
, 17);
6324 if ((was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6325 && (*cross_mode_jump_p
6326 ? ((symbol
+ addend
) & 3) != 0
6327 : ((symbol
+ addend
) & 1) == 0))
6328 return bfd_reloc_outofrange
;
6330 value
= symbol
+ addend
- p
;
6331 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6332 overflowed_p
= mips_elf_overflow_p (value
, 17);
6333 value
>>= howto
->rightshift
;
6334 value
&= howto
->dst_mask
;
6337 case R_MICROMIPS_PC23_S2
:
6338 if (howto
->partial_inplace
)
6339 addend
= _bfd_mips_elf_sign_extend (addend
, 25);
6340 value
= symbol
+ addend
- ((p
| 3) ^ 3);
6341 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6342 overflowed_p
= mips_elf_overflow_p (value
, 25);
6343 value
>>= howto
->rightshift
;
6344 value
&= howto
->dst_mask
;
6347 case R_MIPS_GOT_HI16
:
6348 case R_MIPS_CALL_HI16
:
6349 case R_MICROMIPS_GOT_HI16
:
6350 case R_MICROMIPS_CALL_HI16
:
6351 /* We're allowed to handle these two relocations identically.
6352 The dynamic linker is allowed to handle the CALL relocations
6353 differently by creating a lazy evaluation stub. */
6355 value
= mips_elf_high (value
);
6356 value
&= howto
->dst_mask
;
6359 case R_MIPS_GOT_LO16
:
6360 case R_MIPS_CALL_LO16
:
6361 case R_MICROMIPS_GOT_LO16
:
6362 case R_MICROMIPS_CALL_LO16
:
6363 value
= g
& howto
->dst_mask
;
6366 case R_MIPS_GOT_PAGE
:
6367 case R_MICROMIPS_GOT_PAGE
:
6368 value
= mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, NULL
);
6369 if (value
== MINUS_ONE
)
6370 return bfd_reloc_outofrange
;
6371 value
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
6372 overflowed_p
= mips_elf_overflow_p (value
, 16);
6375 case R_MIPS_GOT_OFST
:
6376 case R_MICROMIPS_GOT_OFST
:
6378 mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, &value
);
6381 overflowed_p
= mips_elf_overflow_p (value
, 16);
6385 case R_MICROMIPS_SUB
:
6386 value
= symbol
- addend
;
6387 value
&= howto
->dst_mask
;
6391 case R_MICROMIPS_HIGHER
:
6392 value
= mips_elf_higher (addend
+ symbol
);
6393 value
&= howto
->dst_mask
;
6396 case R_MIPS_HIGHEST
:
6397 case R_MICROMIPS_HIGHEST
:
6398 value
= mips_elf_highest (addend
+ symbol
);
6399 value
&= howto
->dst_mask
;
6402 case R_MIPS_SCN_DISP
:
6403 case R_MICROMIPS_SCN_DISP
:
6404 value
= symbol
+ addend
- sec
->output_offset
;
6405 value
&= howto
->dst_mask
;
6409 case R_MICROMIPS_JALR
:
6410 /* This relocation is only a hint. In some cases, we optimize
6411 it into a bal instruction. But we don't try to optimize
6412 when the symbol does not resolve locally. */
6413 if (h
!= NULL
&& !SYMBOL_CALLS_LOCAL (info
, &h
->root
))
6414 return bfd_reloc_continue
;
6415 /* We can't optimize cross-mode jumps either. */
6416 if (*cross_mode_jump_p
)
6417 return bfd_reloc_continue
;
6418 value
= symbol
+ addend
;
6419 /* Neither we can non-instruction-aligned targets. */
6420 if (r_type
== R_MIPS_JALR
? (value
& 3) != 0 : (value
& 1) == 0)
6421 return bfd_reloc_continue
;
6425 case R_MIPS_GNU_VTINHERIT
:
6426 case R_MIPS_GNU_VTENTRY
:
6427 /* We don't do anything with these at present. */
6428 return bfd_reloc_continue
;
6431 /* An unrecognized relocation type. */
6432 return bfd_reloc_notsupported
;
6435 /* Store the VALUE for our caller. */
6437 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
6440 /* It has been determined that the result of the RELOCATION is the
6441 VALUE. Use HOWTO to place VALUE into the output file at the
6442 appropriate position. The SECTION is the section to which the
6444 CROSS_MODE_JUMP_P is true if the relocation field
6445 is a MIPS16 or microMIPS jump to standard MIPS code, or vice versa.
6447 Returns FALSE if anything goes wrong. */
6450 mips_elf_perform_relocation (struct bfd_link_info
*info
,
6451 reloc_howto_type
*howto
,
6452 const Elf_Internal_Rela
*relocation
,
6453 bfd_vma value
, bfd
*input_bfd
,
6454 asection
*input_section
, bfd_byte
*contents
,
6455 bfd_boolean cross_mode_jump_p
)
6459 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
6461 /* Figure out where the relocation is occurring. */
6462 location
= contents
+ relocation
->r_offset
;
6464 _bfd_mips_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
6466 /* Obtain the current value. */
6467 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
6469 /* Clear the field we are setting. */
6470 x
&= ~howto
->dst_mask
;
6472 /* Set the field. */
6473 x
|= (value
& howto
->dst_mask
);
6475 /* Detect incorrect JALX usage. If required, turn JAL or BAL into JALX. */
6476 if (!cross_mode_jump_p
&& jal_reloc_p (r_type
))
6478 bfd_vma opcode
= x
>> 26;
6480 if (r_type
== R_MIPS16_26
? opcode
== 0x7
6481 : r_type
== R_MICROMIPS_26_S1
? opcode
== 0x3c
6484 info
->callbacks
->einfo
6485 (_("%X%H: unsupported JALX to the same ISA mode\n"),
6486 input_bfd
, input_section
, relocation
->r_offset
);
6490 if (cross_mode_jump_p
&& jal_reloc_p (r_type
))
6493 bfd_vma opcode
= x
>> 26;
6494 bfd_vma jalx_opcode
;
6496 /* Check to see if the opcode is already JAL or JALX. */
6497 if (r_type
== R_MIPS16_26
)
6499 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
6502 else if (r_type
== R_MICROMIPS_26_S1
)
6504 ok
= ((opcode
== 0x3d) || (opcode
== 0x3c));
6509 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
6513 /* If the opcode is not JAL or JALX, there's a problem. We cannot
6514 convert J or JALS to JALX. */
6517 info
->callbacks
->einfo
6518 (_("%X%H: unsupported jump between ISA modes; "
6519 "consider recompiling with interlinking enabled\n"),
6520 input_bfd
, input_section
, relocation
->r_offset
);
6524 /* Make this the JALX opcode. */
6525 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
6527 else if (cross_mode_jump_p
&& b_reloc_p (r_type
))
6529 bfd_boolean ok
= FALSE
;
6530 bfd_vma opcode
= x
>> 16;
6531 bfd_vma jalx_opcode
= 0;
6532 bfd_vma sign_bit
= 0;
6536 if (r_type
== R_MICROMIPS_PC16_S1
)
6538 ok
= opcode
== 0x4060;
6543 else if (r_type
== R_MIPS_PC16
|| r_type
== R_MIPS_GNU_REL16_S2
)
6545 ok
= opcode
== 0x411;
6551 if (ok
&& !bfd_link_pic (info
))
6553 addr
= (input_section
->output_section
->vma
6554 + input_section
->output_offset
6555 + relocation
->r_offset
6558 + (((value
& ((sign_bit
<< 1) - 1)) ^ sign_bit
) - sign_bit
));
6560 if ((addr
>> 28) << 28 != (dest
>> 28) << 28)
6562 info
->callbacks
->einfo
6563 (_("%X%H: cannot convert branch between ISA modes "
6564 "to JALX: relocation out of range\n"),
6565 input_bfd
, input_section
, relocation
->r_offset
);
6569 /* Make this the JALX opcode. */
6570 x
= ((dest
>> 2) & 0x3ffffff) | jalx_opcode
<< 26;
6572 else if (!mips_elf_hash_table (info
)->ignore_branch_isa
)
6574 info
->callbacks
->einfo
6575 (_("%X%H: unsupported branch between ISA modes\n"),
6576 input_bfd
, input_section
, relocation
->r_offset
);
6581 /* Try converting JAL to BAL and J(AL)R to B(AL), if the target is in
6583 if (!bfd_link_relocatable (info
)
6584 && !cross_mode_jump_p
6585 && ((JAL_TO_BAL_P (input_bfd
)
6586 && r_type
== R_MIPS_26
6587 && (x
>> 26) == 0x3) /* jal addr */
6588 || (JALR_TO_BAL_P (input_bfd
)
6589 && r_type
== R_MIPS_JALR
6590 && x
== 0x0320f809) /* jalr t9 */
6591 || (JR_TO_B_P (input_bfd
)
6592 && r_type
== R_MIPS_JALR
6593 && (x
& ~1) == 0x03200008))) /* jr t9 / jalr zero, t9 */
6599 addr
= (input_section
->output_section
->vma
6600 + input_section
->output_offset
6601 + relocation
->r_offset
6603 if (r_type
== R_MIPS_26
)
6604 dest
= (value
<< 2) | ((addr
>> 28) << 28);
6608 if (off
<= 0x1ffff && off
>= -0x20000)
6610 if ((x
& ~1) == 0x03200008) /* jr t9 / jalr zero, t9 */
6611 x
= 0x10000000 | (((bfd_vma
) off
>> 2) & 0xffff); /* b addr */
6613 x
= 0x04110000 | (((bfd_vma
) off
>> 2) & 0xffff); /* bal addr */
6617 /* Put the value into the output. */
6618 mips_elf_store_contents (howto
, relocation
, input_bfd
, contents
, x
);
6620 _bfd_mips_elf_reloc_shuffle (input_bfd
, r_type
, !bfd_link_relocatable (info
),
6626 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
6627 is the original relocation, which is now being transformed into a
6628 dynamic relocation. The ADDENDP is adjusted if necessary; the
6629 caller should store the result in place of the original addend. */
6632 mips_elf_create_dynamic_relocation (bfd
*output_bfd
,
6633 struct bfd_link_info
*info
,
6634 const Elf_Internal_Rela
*rel
,
6635 struct mips_elf_link_hash_entry
*h
,
6636 asection
*sec
, bfd_vma symbol
,
6637 bfd_vma
*addendp
, asection
*input_section
)
6639 Elf_Internal_Rela outrel
[3];
6644 bfd_boolean defined_p
;
6645 struct mips_elf_link_hash_table
*htab
;
6647 htab
= mips_elf_hash_table (info
);
6648 BFD_ASSERT (htab
!= NULL
);
6650 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
6651 dynobj
= elf_hash_table (info
)->dynobj
;
6652 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
6653 BFD_ASSERT (sreloc
!= NULL
);
6654 BFD_ASSERT (sreloc
->contents
!= NULL
);
6655 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
6658 outrel
[0].r_offset
=
6659 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
6660 if (ABI_64_P (output_bfd
))
6662 outrel
[1].r_offset
=
6663 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
6664 outrel
[2].r_offset
=
6665 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
6668 if (outrel
[0].r_offset
== MINUS_ONE
)
6669 /* The relocation field has been deleted. */
6672 if (outrel
[0].r_offset
== MINUS_TWO
)
6674 /* The relocation field has been converted into a relative value of
6675 some sort. Functions like _bfd_elf_write_section_eh_frame expect
6676 the field to be fully relocated, so add in the symbol's value. */
6681 /* We must now calculate the dynamic symbol table index to use
6682 in the relocation. */
6683 if (h
!= NULL
&& ! SYMBOL_REFERENCES_LOCAL (info
, &h
->root
))
6685 BFD_ASSERT (htab
->is_vxworks
|| h
->global_got_area
!= GGA_NONE
);
6686 indx
= h
->root
.dynindx
;
6687 if (SGI_COMPAT (output_bfd
))
6688 defined_p
= h
->root
.def_regular
;
6690 /* ??? glibc's ld.so just adds the final GOT entry to the
6691 relocation field. It therefore treats relocs against
6692 defined symbols in the same way as relocs against
6693 undefined symbols. */
6698 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
6700 else if (sec
== NULL
|| sec
->owner
== NULL
)
6702 bfd_set_error (bfd_error_bad_value
);
6707 indx
= elf_section_data (sec
->output_section
)->dynindx
;
6710 asection
*osec
= htab
->root
.text_index_section
;
6711 indx
= elf_section_data (osec
)->dynindx
;
6717 /* Instead of generating a relocation using the section
6718 symbol, we may as well make it a fully relative
6719 relocation. We want to avoid generating relocations to
6720 local symbols because we used to generate them
6721 incorrectly, without adding the original symbol value,
6722 which is mandated by the ABI for section symbols. In
6723 order to give dynamic loaders and applications time to
6724 phase out the incorrect use, we refrain from emitting
6725 section-relative relocations. It's not like they're
6726 useful, after all. This should be a bit more efficient
6728 /* ??? Although this behavior is compatible with glibc's ld.so,
6729 the ABI says that relocations against STN_UNDEF should have
6730 a symbol value of 0. Irix rld honors this, so relocations
6731 against STN_UNDEF have no effect. */
6732 if (!SGI_COMPAT (output_bfd
))
6737 /* If the relocation was previously an absolute relocation and
6738 this symbol will not be referred to by the relocation, we must
6739 adjust it by the value we give it in the dynamic symbol table.
6740 Otherwise leave the job up to the dynamic linker. */
6741 if (defined_p
&& r_type
!= R_MIPS_REL32
)
6744 if (htab
->is_vxworks
)
6745 /* VxWorks uses non-relative relocations for this. */
6746 outrel
[0].r_info
= ELF32_R_INFO (indx
, R_MIPS_32
);
6748 /* The relocation is always an REL32 relocation because we don't
6749 know where the shared library will wind up at load-time. */
6750 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
6753 /* For strict adherence to the ABI specification, we should
6754 generate a R_MIPS_64 relocation record by itself before the
6755 _REL32/_64 record as well, such that the addend is read in as
6756 a 64-bit value (REL32 is a 32-bit relocation, after all).
6757 However, since none of the existing ELF64 MIPS dynamic
6758 loaders seems to care, we don't waste space with these
6759 artificial relocations. If this turns out to not be true,
6760 mips_elf_allocate_dynamic_relocation() should be tweaked so
6761 as to make room for a pair of dynamic relocations per
6762 invocation if ABI_64_P, and here we should generate an
6763 additional relocation record with R_MIPS_64 by itself for a
6764 NULL symbol before this relocation record. */
6765 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, 0,
6766 ABI_64_P (output_bfd
)
6769 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_NONE
);
6771 /* Adjust the output offset of the relocation to reference the
6772 correct location in the output file. */
6773 outrel
[0].r_offset
+= (input_section
->output_section
->vma
6774 + input_section
->output_offset
);
6775 outrel
[1].r_offset
+= (input_section
->output_section
->vma
6776 + input_section
->output_offset
);
6777 outrel
[2].r_offset
+= (input_section
->output_section
->vma
6778 + input_section
->output_offset
);
6780 /* Put the relocation back out. We have to use the special
6781 relocation outputter in the 64-bit case since the 64-bit
6782 relocation format is non-standard. */
6783 if (ABI_64_P (output_bfd
))
6785 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
6786 (output_bfd
, &outrel
[0],
6788 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
6790 else if (htab
->is_vxworks
)
6792 /* VxWorks uses RELA rather than REL dynamic relocations. */
6793 outrel
[0].r_addend
= *addendp
;
6794 bfd_elf32_swap_reloca_out
6795 (output_bfd
, &outrel
[0],
6797 + sreloc
->reloc_count
* sizeof (Elf32_External_Rela
)));
6800 bfd_elf32_swap_reloc_out
6801 (output_bfd
, &outrel
[0],
6802 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
6804 /* We've now added another relocation. */
6805 ++sreloc
->reloc_count
;
6807 /* Make sure the output section is writable. The dynamic linker
6808 will be writing to it. */
6809 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
6812 /* On IRIX5, make an entry of compact relocation info. */
6813 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
6815 asection
*scpt
= bfd_get_linker_section (dynobj
, ".compact_rel");
6820 Elf32_crinfo cptrel
;
6822 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
6823 cptrel
.vaddr
= (rel
->r_offset
6824 + input_section
->output_section
->vma
6825 + input_section
->output_offset
);
6826 if (r_type
== R_MIPS_REL32
)
6827 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
6829 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
6830 mips_elf_set_cr_dist2to (cptrel
, 0);
6831 cptrel
.konst
= *addendp
;
6833 cr
= (scpt
->contents
6834 + sizeof (Elf32_External_compact_rel
));
6835 mips_elf_set_cr_relvaddr (cptrel
, 0);
6836 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
6837 ((Elf32_External_crinfo
*) cr
6838 + scpt
->reloc_count
));
6839 ++scpt
->reloc_count
;
6843 /* If we've written this relocation for a readonly section,
6844 we need to set DF_TEXTREL again, so that we do not delete the
6846 if (MIPS_ELF_READONLY_SECTION (input_section
))
6847 info
->flags
|= DF_TEXTREL
;
6852 /* Return the MACH for a MIPS e_flags value. */
6855 _bfd_elf_mips_mach (flagword flags
)
6857 switch (flags
& EF_MIPS_MACH
)
6859 case E_MIPS_MACH_3900
:
6860 return bfd_mach_mips3900
;
6862 case E_MIPS_MACH_4010
:
6863 return bfd_mach_mips4010
;
6865 case E_MIPS_MACH_4100
:
6866 return bfd_mach_mips4100
;
6868 case E_MIPS_MACH_4111
:
6869 return bfd_mach_mips4111
;
6871 case E_MIPS_MACH_4120
:
6872 return bfd_mach_mips4120
;
6874 case E_MIPS_MACH_4650
:
6875 return bfd_mach_mips4650
;
6877 case E_MIPS_MACH_5400
:
6878 return bfd_mach_mips5400
;
6880 case E_MIPS_MACH_5500
:
6881 return bfd_mach_mips5500
;
6883 case E_MIPS_MACH_5900
:
6884 return bfd_mach_mips5900
;
6886 case E_MIPS_MACH_9000
:
6887 return bfd_mach_mips9000
;
6889 case E_MIPS_MACH_SB1
:
6890 return bfd_mach_mips_sb1
;
6892 case E_MIPS_MACH_LS2E
:
6893 return bfd_mach_mips_loongson_2e
;
6895 case E_MIPS_MACH_LS2F
:
6896 return bfd_mach_mips_loongson_2f
;
6898 case E_MIPS_MACH_GS464
:
6899 return bfd_mach_mips_gs464
;
6901 case E_MIPS_MACH_GS464E
:
6902 return bfd_mach_mips_gs464e
;
6904 case E_MIPS_MACH_GS264E
:
6905 return bfd_mach_mips_gs264e
;
6907 case E_MIPS_MACH_OCTEON3
:
6908 return bfd_mach_mips_octeon3
;
6910 case E_MIPS_MACH_OCTEON2
:
6911 return bfd_mach_mips_octeon2
;
6913 case E_MIPS_MACH_OCTEON
:
6914 return bfd_mach_mips_octeon
;
6916 case E_MIPS_MACH_XLR
:
6917 return bfd_mach_mips_xlr
;
6919 case E_MIPS_MACH_IAMR2
:
6920 return bfd_mach_mips_interaptiv_mr2
;
6923 switch (flags
& EF_MIPS_ARCH
)
6927 return bfd_mach_mips3000
;
6930 return bfd_mach_mips6000
;
6933 return bfd_mach_mips4000
;
6936 return bfd_mach_mips8000
;
6939 return bfd_mach_mips5
;
6941 case E_MIPS_ARCH_32
:
6942 return bfd_mach_mipsisa32
;
6944 case E_MIPS_ARCH_64
:
6945 return bfd_mach_mipsisa64
;
6947 case E_MIPS_ARCH_32R2
:
6948 return bfd_mach_mipsisa32r2
;
6950 case E_MIPS_ARCH_64R2
:
6951 return bfd_mach_mipsisa64r2
;
6953 case E_MIPS_ARCH_32R6
:
6954 return bfd_mach_mipsisa32r6
;
6956 case E_MIPS_ARCH_64R6
:
6957 return bfd_mach_mipsisa64r6
;
6964 /* Return printable name for ABI. */
6966 static INLINE
char *
6967 elf_mips_abi_name (bfd
*abfd
)
6971 flags
= elf_elfheader (abfd
)->e_flags
;
6972 switch (flags
& EF_MIPS_ABI
)
6975 if (ABI_N32_P (abfd
))
6977 else if (ABI_64_P (abfd
))
6981 case E_MIPS_ABI_O32
:
6983 case E_MIPS_ABI_O64
:
6985 case E_MIPS_ABI_EABI32
:
6987 case E_MIPS_ABI_EABI64
:
6990 return "unknown abi";
6994 /* MIPS ELF uses two common sections. One is the usual one, and the
6995 other is for small objects. All the small objects are kept
6996 together, and then referenced via the gp pointer, which yields
6997 faster assembler code. This is what we use for the small common
6998 section. This approach is copied from ecoff.c. */
6999 static asection mips_elf_scom_section
;
7000 static asymbol mips_elf_scom_symbol
;
7001 static asymbol
*mips_elf_scom_symbol_ptr
;
7003 /* MIPS ELF also uses an acommon section, which represents an
7004 allocated common symbol which may be overridden by a
7005 definition in a shared library. */
7006 static asection mips_elf_acom_section
;
7007 static asymbol mips_elf_acom_symbol
;
7008 static asymbol
*mips_elf_acom_symbol_ptr
;
7010 /* This is used for both the 32-bit and the 64-bit ABI. */
7013 _bfd_mips_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
7015 elf_symbol_type
*elfsym
;
7017 /* Handle the special MIPS section numbers that a symbol may use. */
7018 elfsym
= (elf_symbol_type
*) asym
;
7019 switch (elfsym
->internal_elf_sym
.st_shndx
)
7021 case SHN_MIPS_ACOMMON
:
7022 /* This section is used in a dynamically linked executable file.
7023 It is an allocated common section. The dynamic linker can
7024 either resolve these symbols to something in a shared
7025 library, or it can just leave them here. For our purposes,
7026 we can consider these symbols to be in a new section. */
7027 if (mips_elf_acom_section
.name
== NULL
)
7029 /* Initialize the acommon section. */
7030 mips_elf_acom_section
.name
= ".acommon";
7031 mips_elf_acom_section
.flags
= SEC_ALLOC
;
7032 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
7033 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
7034 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
7035 mips_elf_acom_symbol
.name
= ".acommon";
7036 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
7037 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
7038 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
7040 asym
->section
= &mips_elf_acom_section
;
7044 /* Common symbols less than the GP size are automatically
7045 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
7046 if (asym
->value
> elf_gp_size (abfd
)
7047 || ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_TLS
7048 || IRIX_COMPAT (abfd
) == ict_irix6
)
7051 case SHN_MIPS_SCOMMON
:
7052 if (mips_elf_scom_section
.name
== NULL
)
7054 /* Initialize the small common section. */
7055 mips_elf_scom_section
.name
= ".scommon";
7056 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
7057 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
7058 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
7059 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
7060 mips_elf_scom_symbol
.name
= ".scommon";
7061 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
7062 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
7063 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
7065 asym
->section
= &mips_elf_scom_section
;
7066 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
7069 case SHN_MIPS_SUNDEFINED
:
7070 asym
->section
= bfd_und_section_ptr
;
7075 asection
*section
= bfd_get_section_by_name (abfd
, ".text");
7077 if (section
!= NULL
)
7079 asym
->section
= section
;
7080 /* MIPS_TEXT is a bit special, the address is not an offset
7081 to the base of the .text section. So subtract the section
7082 base address to make it an offset. */
7083 asym
->value
-= section
->vma
;
7090 asection
*section
= bfd_get_section_by_name (abfd
, ".data");
7092 if (section
!= NULL
)
7094 asym
->section
= section
;
7095 /* MIPS_DATA is a bit special, the address is not an offset
7096 to the base of the .data section. So subtract the section
7097 base address to make it an offset. */
7098 asym
->value
-= section
->vma
;
7104 /* If this is an odd-valued function symbol, assume it's a MIPS16
7105 or microMIPS one. */
7106 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_FUNC
7107 && (asym
->value
& 1) != 0)
7110 if (MICROMIPS_P (abfd
))
7111 elfsym
->internal_elf_sym
.st_other
7112 = ELF_ST_SET_MICROMIPS (elfsym
->internal_elf_sym
.st_other
);
7114 elfsym
->internal_elf_sym
.st_other
7115 = ELF_ST_SET_MIPS16 (elfsym
->internal_elf_sym
.st_other
);
7119 /* Implement elf_backend_eh_frame_address_size. This differs from
7120 the default in the way it handles EABI64.
7122 EABI64 was originally specified as an LP64 ABI, and that is what
7123 -mabi=eabi normally gives on a 64-bit target. However, gcc has
7124 historically accepted the combination of -mabi=eabi and -mlong32,
7125 and this ILP32 variation has become semi-official over time.
7126 Both forms use elf32 and have pointer-sized FDE addresses.
7128 If an EABI object was generated by GCC 4.0 or above, it will have
7129 an empty .gcc_compiled_longXX section, where XX is the size of longs
7130 in bits. Unfortunately, ILP32 objects generated by earlier compilers
7131 have no special marking to distinguish them from LP64 objects.
7133 We don't want users of the official LP64 ABI to be punished for the
7134 existence of the ILP32 variant, but at the same time, we don't want
7135 to mistakenly interpret pre-4.0 ILP32 objects as being LP64 objects.
7136 We therefore take the following approach:
7138 - If ABFD contains a .gcc_compiled_longXX section, use it to
7139 determine the pointer size.
7141 - Otherwise check the type of the first relocation. Assume that
7142 the LP64 ABI is being used if the relocation is of type R_MIPS_64.
7146 The second check is enough to detect LP64 objects generated by pre-4.0
7147 compilers because, in the kind of output generated by those compilers,
7148 the first relocation will be associated with either a CIE personality
7149 routine or an FDE start address. Furthermore, the compilers never
7150 used a special (non-pointer) encoding for this ABI.
7152 Checking the relocation type should also be safe because there is no
7153 reason to use R_MIPS_64 in an ILP32 object. Pre-4.0 compilers never
7157 _bfd_mips_elf_eh_frame_address_size (bfd
*abfd
, const asection
*sec
)
7159 if (elf_elfheader (abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
7161 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
7163 bfd_boolean long32_p
, long64_p
;
7165 long32_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long32") != 0;
7166 long64_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long64") != 0;
7167 if (long32_p
&& long64_p
)
7174 if (sec
->reloc_count
> 0
7175 && elf_section_data (sec
)->relocs
!= NULL
7176 && (ELF32_R_TYPE (elf_section_data (sec
)->relocs
[0].r_info
)
7185 /* There appears to be a bug in the MIPSpro linker that causes GOT_DISP
7186 relocations against two unnamed section symbols to resolve to the
7187 same address. For example, if we have code like:
7189 lw $4,%got_disp(.data)($gp)
7190 lw $25,%got_disp(.text)($gp)
7193 then the linker will resolve both relocations to .data and the program
7194 will jump there rather than to .text.
7196 We can work around this problem by giving names to local section symbols.
7197 This is also what the MIPSpro tools do. */
7200 _bfd_mips_elf_name_local_section_symbols (bfd
*abfd
)
7202 return SGI_COMPAT (abfd
);
7205 /* Work over a section just before writing it out. This routine is
7206 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
7207 sections that need the SHF_MIPS_GPREL flag by name; there has to be
7211 _bfd_mips_elf_section_processing (bfd
*abfd
, Elf_Internal_Shdr
*hdr
)
7213 if (hdr
->sh_type
== SHT_MIPS_REGINFO
7214 && hdr
->sh_size
> 0)
7218 BFD_ASSERT (hdr
->contents
== NULL
);
7220 if (hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
7223 (_("%pB: incorrect `.reginfo' section size; "
7224 "expected %" PRIu64
", got %" PRIu64
),
7225 abfd
, (uint64_t) sizeof (Elf32_External_RegInfo
),
7226 (uint64_t) hdr
->sh_size
);
7227 bfd_set_error (bfd_error_bad_value
);
7232 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
7235 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
7236 if (bfd_bwrite (buf
, 4, abfd
) != 4)
7240 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
7241 && hdr
->bfd_section
!= NULL
7242 && mips_elf_section_data (hdr
->bfd_section
) != NULL
7243 && mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
!= NULL
)
7245 bfd_byte
*contents
, *l
, *lend
;
7247 /* We stored the section contents in the tdata field in the
7248 set_section_contents routine. We save the section contents
7249 so that we don't have to read them again.
7250 At this point we know that elf_gp is set, so we can look
7251 through the section contents to see if there is an
7252 ODK_REGINFO structure. */
7254 contents
= mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
;
7256 lend
= contents
+ hdr
->sh_size
;
7257 while (l
+ sizeof (Elf_External_Options
) <= lend
)
7259 Elf_Internal_Options intopt
;
7261 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
7263 if (intopt
.size
< sizeof (Elf_External_Options
))
7266 /* xgettext:c-format */
7267 (_("%pB: warning: bad `%s' option size %u smaller than"
7269 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
7272 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
7279 + sizeof (Elf_External_Options
)
7280 + (sizeof (Elf64_External_RegInfo
) - 8)),
7283 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
7284 if (bfd_bwrite (buf
, 8, abfd
) != 8)
7287 else if (intopt
.kind
== ODK_REGINFO
)
7294 + sizeof (Elf_External_Options
)
7295 + (sizeof (Elf32_External_RegInfo
) - 4)),
7298 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
7299 if (bfd_bwrite (buf
, 4, abfd
) != 4)
7306 if (hdr
->bfd_section
!= NULL
)
7308 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
7310 /* .sbss is not handled specially here because the GNU/Linux
7311 prelinker can convert .sbss from NOBITS to PROGBITS and
7312 changing it back to NOBITS breaks the binary. The entry in
7313 _bfd_mips_elf_special_sections will ensure the correct flags
7314 are set on .sbss if BFD creates it without reading it from an
7315 input file, and without special handling here the flags set
7316 on it in an input file will be followed. */
7317 if (strcmp (name
, ".sdata") == 0
7318 || strcmp (name
, ".lit8") == 0
7319 || strcmp (name
, ".lit4") == 0)
7320 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
7321 else if (strcmp (name
, ".srdata") == 0)
7322 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
7323 else if (strcmp (name
, ".compact_rel") == 0)
7325 else if (strcmp (name
, ".rtproc") == 0)
7327 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
7329 unsigned int adjust
;
7331 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
7333 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
7341 /* Handle a MIPS specific section when reading an object file. This
7342 is called when elfcode.h finds a section with an unknown type.
7343 This routine supports both the 32-bit and 64-bit ELF ABI.
7345 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
7349 _bfd_mips_elf_section_from_shdr (bfd
*abfd
,
7350 Elf_Internal_Shdr
*hdr
,
7356 /* There ought to be a place to keep ELF backend specific flags, but
7357 at the moment there isn't one. We just keep track of the
7358 sections by their name, instead. Fortunately, the ABI gives
7359 suggested names for all the MIPS specific sections, so we will
7360 probably get away with this. */
7361 switch (hdr
->sh_type
)
7363 case SHT_MIPS_LIBLIST
:
7364 if (strcmp (name
, ".liblist") != 0)
7368 if (strcmp (name
, ".msym") != 0)
7371 case SHT_MIPS_CONFLICT
:
7372 if (strcmp (name
, ".conflict") != 0)
7375 case SHT_MIPS_GPTAB
:
7376 if (! CONST_STRNEQ (name
, ".gptab."))
7379 case SHT_MIPS_UCODE
:
7380 if (strcmp (name
, ".ucode") != 0)
7383 case SHT_MIPS_DEBUG
:
7384 if (strcmp (name
, ".mdebug") != 0)
7386 flags
= SEC_DEBUGGING
;
7388 case SHT_MIPS_REGINFO
:
7389 if (strcmp (name
, ".reginfo") != 0
7390 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
7392 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
7394 case SHT_MIPS_IFACE
:
7395 if (strcmp (name
, ".MIPS.interfaces") != 0)
7398 case SHT_MIPS_CONTENT
:
7399 if (! CONST_STRNEQ (name
, ".MIPS.content"))
7402 case SHT_MIPS_OPTIONS
:
7403 if (!MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
7406 case SHT_MIPS_ABIFLAGS
:
7407 if (!MIPS_ELF_ABIFLAGS_SECTION_NAME_P (name
))
7409 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
7411 case SHT_MIPS_DWARF
:
7412 if (! CONST_STRNEQ (name
, ".debug_")
7413 && ! CONST_STRNEQ (name
, ".zdebug_"))
7416 case SHT_MIPS_SYMBOL_LIB
:
7417 if (strcmp (name
, ".MIPS.symlib") != 0)
7420 case SHT_MIPS_EVENTS
:
7421 if (! CONST_STRNEQ (name
, ".MIPS.events")
7422 && ! CONST_STRNEQ (name
, ".MIPS.post_rel"))
7429 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
7434 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
7435 (bfd_get_section_flags (abfd
,
7441 if (hdr
->sh_type
== SHT_MIPS_ABIFLAGS
)
7443 Elf_External_ABIFlags_v0 ext
;
7445 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
7446 &ext
, 0, sizeof ext
))
7448 bfd_mips_elf_swap_abiflags_v0_in (abfd
, &ext
,
7449 &mips_elf_tdata (abfd
)->abiflags
);
7450 if (mips_elf_tdata (abfd
)->abiflags
.version
!= 0)
7452 mips_elf_tdata (abfd
)->abiflags_valid
= TRUE
;
7455 /* FIXME: We should record sh_info for a .gptab section. */
7457 /* For a .reginfo section, set the gp value in the tdata information
7458 from the contents of this section. We need the gp value while
7459 processing relocs, so we just get it now. The .reginfo section
7460 is not used in the 64-bit MIPS ELF ABI. */
7461 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
7463 Elf32_External_RegInfo ext
;
7466 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
7467 &ext
, 0, sizeof ext
))
7469 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
7470 elf_gp (abfd
) = s
.ri_gp_value
;
7473 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
7474 set the gp value based on what we find. We may see both
7475 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
7476 they should agree. */
7477 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
7479 bfd_byte
*contents
, *l
, *lend
;
7481 contents
= bfd_malloc (hdr
->sh_size
);
7482 if (contents
== NULL
)
7484 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
7491 lend
= contents
+ hdr
->sh_size
;
7492 while (l
+ sizeof (Elf_External_Options
) <= lend
)
7494 Elf_Internal_Options intopt
;
7496 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
7498 if (intopt
.size
< sizeof (Elf_External_Options
))
7501 /* xgettext:c-format */
7502 (_("%pB: warning: bad `%s' option size %u smaller than"
7504 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
7507 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
7509 Elf64_Internal_RegInfo intreg
;
7511 bfd_mips_elf64_swap_reginfo_in
7513 ((Elf64_External_RegInfo
*)
7514 (l
+ sizeof (Elf_External_Options
))),
7516 elf_gp (abfd
) = intreg
.ri_gp_value
;
7518 else if (intopt
.kind
== ODK_REGINFO
)
7520 Elf32_RegInfo intreg
;
7522 bfd_mips_elf32_swap_reginfo_in
7524 ((Elf32_External_RegInfo
*)
7525 (l
+ sizeof (Elf_External_Options
))),
7527 elf_gp (abfd
) = intreg
.ri_gp_value
;
7537 /* Set the correct type for a MIPS ELF section. We do this by the
7538 section name, which is a hack, but ought to work. This routine is
7539 used by both the 32-bit and the 64-bit ABI. */
7542 _bfd_mips_elf_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
7544 const char *name
= bfd_get_section_name (abfd
, sec
);
7546 if (strcmp (name
, ".liblist") == 0)
7548 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
7549 hdr
->sh_info
= sec
->size
/ sizeof (Elf32_Lib
);
7550 /* The sh_link field is set in final_write_processing. */
7552 else if (strcmp (name
, ".conflict") == 0)
7553 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
7554 else if (CONST_STRNEQ (name
, ".gptab."))
7556 hdr
->sh_type
= SHT_MIPS_GPTAB
;
7557 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
7558 /* The sh_info field is set in final_write_processing. */
7560 else if (strcmp (name
, ".ucode") == 0)
7561 hdr
->sh_type
= SHT_MIPS_UCODE
;
7562 else if (strcmp (name
, ".mdebug") == 0)
7564 hdr
->sh_type
= SHT_MIPS_DEBUG
;
7565 /* In a shared object on IRIX 5.3, the .mdebug section has an
7566 entsize of 0. FIXME: Does this matter? */
7567 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
7568 hdr
->sh_entsize
= 0;
7570 hdr
->sh_entsize
= 1;
7572 else if (strcmp (name
, ".reginfo") == 0)
7574 hdr
->sh_type
= SHT_MIPS_REGINFO
;
7575 /* In a shared object on IRIX 5.3, the .reginfo section has an
7576 entsize of 0x18. FIXME: Does this matter? */
7577 if (SGI_COMPAT (abfd
))
7579 if ((abfd
->flags
& DYNAMIC
) != 0)
7580 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
7582 hdr
->sh_entsize
= 1;
7585 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
7587 else if (SGI_COMPAT (abfd
)
7588 && (strcmp (name
, ".hash") == 0
7589 || strcmp (name
, ".dynamic") == 0
7590 || strcmp (name
, ".dynstr") == 0))
7592 if (SGI_COMPAT (abfd
))
7593 hdr
->sh_entsize
= 0;
7595 /* This isn't how the IRIX6 linker behaves. */
7596 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
7599 else if (strcmp (name
, ".got") == 0
7600 || strcmp (name
, ".srdata") == 0
7601 || strcmp (name
, ".sdata") == 0
7602 || strcmp (name
, ".sbss") == 0
7603 || strcmp (name
, ".lit4") == 0
7604 || strcmp (name
, ".lit8") == 0)
7605 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
7606 else if (strcmp (name
, ".MIPS.interfaces") == 0)
7608 hdr
->sh_type
= SHT_MIPS_IFACE
;
7609 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7611 else if (CONST_STRNEQ (name
, ".MIPS.content"))
7613 hdr
->sh_type
= SHT_MIPS_CONTENT
;
7614 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7615 /* The sh_info field is set in final_write_processing. */
7617 else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
7619 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
7620 hdr
->sh_entsize
= 1;
7621 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7623 else if (CONST_STRNEQ (name
, ".MIPS.abiflags"))
7625 hdr
->sh_type
= SHT_MIPS_ABIFLAGS
;
7626 hdr
->sh_entsize
= sizeof (Elf_External_ABIFlags_v0
);
7628 else if (CONST_STRNEQ (name
, ".debug_")
7629 || CONST_STRNEQ (name
, ".zdebug_"))
7631 hdr
->sh_type
= SHT_MIPS_DWARF
;
7633 /* Irix facilities such as libexc expect a single .debug_frame
7634 per executable, the system ones have NOSTRIP set and the linker
7635 doesn't merge sections with different flags so ... */
7636 if (SGI_COMPAT (abfd
) && CONST_STRNEQ (name
, ".debug_frame"))
7637 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7639 else if (strcmp (name
, ".MIPS.symlib") == 0)
7641 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
7642 /* The sh_link and sh_info fields are set in
7643 final_write_processing. */
7645 else if (CONST_STRNEQ (name
, ".MIPS.events")
7646 || CONST_STRNEQ (name
, ".MIPS.post_rel"))
7648 hdr
->sh_type
= SHT_MIPS_EVENTS
;
7649 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7650 /* The sh_link field is set in final_write_processing. */
7652 else if (strcmp (name
, ".msym") == 0)
7654 hdr
->sh_type
= SHT_MIPS_MSYM
;
7655 hdr
->sh_flags
|= SHF_ALLOC
;
7656 hdr
->sh_entsize
= 8;
7659 /* The generic elf_fake_sections will set up REL_HDR using the default
7660 kind of relocations. We used to set up a second header for the
7661 non-default kind of relocations here, but only NewABI would use
7662 these, and the IRIX ld doesn't like resulting empty RELA sections.
7663 Thus we create those header only on demand now. */
7668 /* Given a BFD section, try to locate the corresponding ELF section
7669 index. This is used by both the 32-bit and the 64-bit ABI.
7670 Actually, it's not clear to me that the 64-bit ABI supports these,
7671 but for non-PIC objects we will certainly want support for at least
7672 the .scommon section. */
7675 _bfd_mips_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
7676 asection
*sec
, int *retval
)
7678 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
7680 *retval
= SHN_MIPS_SCOMMON
;
7683 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
7685 *retval
= SHN_MIPS_ACOMMON
;
7691 /* Hook called by the linker routine which adds symbols from an object
7692 file. We must handle the special MIPS section numbers here. */
7695 _bfd_mips_elf_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
7696 Elf_Internal_Sym
*sym
, const char **namep
,
7697 flagword
*flagsp ATTRIBUTE_UNUSED
,
7698 asection
**secp
, bfd_vma
*valp
)
7700 if (SGI_COMPAT (abfd
)
7701 && (abfd
->flags
& DYNAMIC
) != 0
7702 && strcmp (*namep
, "_rld_new_interface") == 0)
7704 /* Skip IRIX5 rld entry name. */
7709 /* Shared objects may have a dynamic symbol '_gp_disp' defined as
7710 a SECTION *ABS*. This causes ld to think it can resolve _gp_disp
7711 by setting a DT_NEEDED for the shared object. Since _gp_disp is
7712 a magic symbol resolved by the linker, we ignore this bogus definition
7713 of _gp_disp. New ABI objects do not suffer from this problem so this
7714 is not done for them. */
7716 && (sym
->st_shndx
== SHN_ABS
)
7717 && (strcmp (*namep
, "_gp_disp") == 0))
7723 switch (sym
->st_shndx
)
7726 /* Common symbols less than the GP size are automatically
7727 treated as SHN_MIPS_SCOMMON symbols. */
7728 if (sym
->st_size
> elf_gp_size (abfd
)
7729 || ELF_ST_TYPE (sym
->st_info
) == STT_TLS
7730 || IRIX_COMPAT (abfd
) == ict_irix6
)
7733 case SHN_MIPS_SCOMMON
:
7734 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
7735 (*secp
)->flags
|= SEC_IS_COMMON
;
7736 *valp
= sym
->st_size
;
7740 /* This section is used in a shared object. */
7741 if (mips_elf_tdata (abfd
)->elf_text_section
== NULL
)
7743 asymbol
*elf_text_symbol
;
7744 asection
*elf_text_section
;
7745 bfd_size_type amt
= sizeof (asection
);
7747 elf_text_section
= bfd_zalloc (abfd
, amt
);
7748 if (elf_text_section
== NULL
)
7751 amt
= sizeof (asymbol
);
7752 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
7753 if (elf_text_symbol
== NULL
)
7756 /* Initialize the section. */
7758 mips_elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
7759 mips_elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
7761 elf_text_section
->symbol
= elf_text_symbol
;
7762 elf_text_section
->symbol_ptr_ptr
= &mips_elf_tdata (abfd
)->elf_text_symbol
;
7764 elf_text_section
->name
= ".text";
7765 elf_text_section
->flags
= SEC_NO_FLAGS
;
7766 elf_text_section
->output_section
= NULL
;
7767 elf_text_section
->owner
= abfd
;
7768 elf_text_symbol
->name
= ".text";
7769 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
7770 elf_text_symbol
->section
= elf_text_section
;
7772 /* This code used to do *secp = bfd_und_section_ptr if
7773 bfd_link_pic (info). I don't know why, and that doesn't make sense,
7774 so I took it out. */
7775 *secp
= mips_elf_tdata (abfd
)->elf_text_section
;
7778 case SHN_MIPS_ACOMMON
:
7779 /* Fall through. XXX Can we treat this as allocated data? */
7781 /* This section is used in a shared object. */
7782 if (mips_elf_tdata (abfd
)->elf_data_section
== NULL
)
7784 asymbol
*elf_data_symbol
;
7785 asection
*elf_data_section
;
7786 bfd_size_type amt
= sizeof (asection
);
7788 elf_data_section
= bfd_zalloc (abfd
, amt
);
7789 if (elf_data_section
== NULL
)
7792 amt
= sizeof (asymbol
);
7793 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
7794 if (elf_data_symbol
== NULL
)
7797 /* Initialize the section. */
7799 mips_elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
7800 mips_elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
7802 elf_data_section
->symbol
= elf_data_symbol
;
7803 elf_data_section
->symbol_ptr_ptr
= &mips_elf_tdata (abfd
)->elf_data_symbol
;
7805 elf_data_section
->name
= ".data";
7806 elf_data_section
->flags
= SEC_NO_FLAGS
;
7807 elf_data_section
->output_section
= NULL
;
7808 elf_data_section
->owner
= abfd
;
7809 elf_data_symbol
->name
= ".data";
7810 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
7811 elf_data_symbol
->section
= elf_data_section
;
7813 /* This code used to do *secp = bfd_und_section_ptr if
7814 bfd_link_pic (info). I don't know why, and that doesn't make sense,
7815 so I took it out. */
7816 *secp
= mips_elf_tdata (abfd
)->elf_data_section
;
7819 case SHN_MIPS_SUNDEFINED
:
7820 *secp
= bfd_und_section_ptr
;
7824 if (SGI_COMPAT (abfd
)
7825 && ! bfd_link_pic (info
)
7826 && info
->output_bfd
->xvec
== abfd
->xvec
7827 && strcmp (*namep
, "__rld_obj_head") == 0)
7829 struct elf_link_hash_entry
*h
;
7830 struct bfd_link_hash_entry
*bh
;
7832 /* Mark __rld_obj_head as dynamic. */
7834 if (! (_bfd_generic_link_add_one_symbol
7835 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
, *valp
, NULL
, FALSE
,
7836 get_elf_backend_data (abfd
)->collect
, &bh
)))
7839 h
= (struct elf_link_hash_entry
*) bh
;
7842 h
->type
= STT_OBJECT
;
7844 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7847 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
7848 mips_elf_hash_table (info
)->rld_symbol
= h
;
7851 /* If this is a mips16 text symbol, add 1 to the value to make it
7852 odd. This will cause something like .word SYM to come up with
7853 the right value when it is loaded into the PC. */
7854 if (ELF_ST_IS_COMPRESSED (sym
->st_other
))
7860 /* This hook function is called before the linker writes out a global
7861 symbol. We mark symbols as small common if appropriate. This is
7862 also where we undo the increment of the value for a mips16 symbol. */
7865 _bfd_mips_elf_link_output_symbol_hook
7866 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
7867 const char *name ATTRIBUTE_UNUSED
, Elf_Internal_Sym
*sym
,
7868 asection
*input_sec
, struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
7870 /* If we see a common symbol, which implies a relocatable link, then
7871 if a symbol was small common in an input file, mark it as small
7872 common in the output file. */
7873 if (sym
->st_shndx
== SHN_COMMON
7874 && strcmp (input_sec
->name
, ".scommon") == 0)
7875 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
7877 if (ELF_ST_IS_COMPRESSED (sym
->st_other
))
7878 sym
->st_value
&= ~1;
7883 /* Functions for the dynamic linker. */
7885 /* Create dynamic sections when linking against a dynamic object. */
7888 _bfd_mips_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
7890 struct elf_link_hash_entry
*h
;
7891 struct bfd_link_hash_entry
*bh
;
7893 register asection
*s
;
7894 const char * const *namep
;
7895 struct mips_elf_link_hash_table
*htab
;
7897 htab
= mips_elf_hash_table (info
);
7898 BFD_ASSERT (htab
!= NULL
);
7900 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7901 | SEC_LINKER_CREATED
| SEC_READONLY
);
7903 /* The psABI requires a read-only .dynamic section, but the VxWorks
7905 if (!htab
->is_vxworks
)
7907 s
= bfd_get_linker_section (abfd
, ".dynamic");
7910 if (! bfd_set_section_flags (abfd
, s
, flags
))
7915 /* We need to create .got section. */
7916 if (!mips_elf_create_got_section (abfd
, info
))
7919 if (! mips_elf_rel_dyn_section (info
, TRUE
))
7922 /* Create .stub section. */
7923 s
= bfd_make_section_anyway_with_flags (abfd
,
7924 MIPS_ELF_STUB_SECTION_NAME (abfd
),
7927 || ! bfd_set_section_alignment (abfd
, s
,
7928 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7932 if (!mips_elf_hash_table (info
)->use_rld_obj_head
7933 && bfd_link_executable (info
)
7934 && bfd_get_linker_section (abfd
, ".rld_map") == NULL
)
7936 s
= bfd_make_section_anyway_with_flags (abfd
, ".rld_map",
7937 flags
&~ (flagword
) SEC_READONLY
);
7939 || ! bfd_set_section_alignment (abfd
, s
,
7940 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7944 /* On IRIX5, we adjust add some additional symbols and change the
7945 alignments of several sections. There is no ABI documentation
7946 indicating that this is necessary on IRIX6, nor any evidence that
7947 the linker takes such action. */
7948 if (IRIX_COMPAT (abfd
) == ict_irix5
)
7950 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
7953 if (! (_bfd_generic_link_add_one_symbol
7954 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
, 0,
7955 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
7958 h
= (struct elf_link_hash_entry
*) bh
;
7962 h
->type
= STT_SECTION
;
7964 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7968 /* We need to create a .compact_rel section. */
7969 if (SGI_COMPAT (abfd
))
7971 if (!mips_elf_create_compact_rel_section (abfd
, info
))
7975 /* Change alignments of some sections. */
7976 s
= bfd_get_linker_section (abfd
, ".hash");
7978 (void) bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
7980 s
= bfd_get_linker_section (abfd
, ".dynsym");
7982 (void) bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
7984 s
= bfd_get_linker_section (abfd
, ".dynstr");
7986 (void) bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
7989 s
= bfd_get_section_by_name (abfd
, ".reginfo");
7991 (void) bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
7993 s
= bfd_get_linker_section (abfd
, ".dynamic");
7995 (void) bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
7998 if (bfd_link_executable (info
))
8002 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
8004 if (!(_bfd_generic_link_add_one_symbol
8005 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
8006 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
8009 h
= (struct elf_link_hash_entry
*) bh
;
8012 h
->type
= STT_SECTION
;
8014 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8017 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
8019 /* __rld_map is a four byte word located in the .data section
8020 and is filled in by the rtld to contain a pointer to
8021 the _r_debug structure. Its symbol value will be set in
8022 _bfd_mips_elf_finish_dynamic_symbol. */
8023 s
= bfd_get_linker_section (abfd
, ".rld_map");
8024 BFD_ASSERT (s
!= NULL
);
8026 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
8028 if (!(_bfd_generic_link_add_one_symbol
8029 (info
, abfd
, name
, BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
8030 get_elf_backend_data (abfd
)->collect
, &bh
)))
8033 h
= (struct elf_link_hash_entry
*) bh
;
8036 h
->type
= STT_OBJECT
;
8038 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8040 mips_elf_hash_table (info
)->rld_symbol
= h
;
8044 /* Create the .plt, .rel(a).plt, .dynbss and .rel(a).bss sections.
8045 Also, on VxWorks, create the _PROCEDURE_LINKAGE_TABLE_ symbol. */
8046 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
8049 /* Do the usual VxWorks handling. */
8050 if (htab
->is_vxworks
8051 && !elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
8057 /* Return true if relocation REL against section SEC is a REL rather than
8058 RELA relocation. RELOCS is the first relocation in the section and
8059 ABFD is the bfd that contains SEC. */
8062 mips_elf_rel_relocation_p (bfd
*abfd
, asection
*sec
,
8063 const Elf_Internal_Rela
*relocs
,
8064 const Elf_Internal_Rela
*rel
)
8066 Elf_Internal_Shdr
*rel_hdr
;
8067 const struct elf_backend_data
*bed
;
8069 /* To determine which flavor of relocation this is, we depend on the
8070 fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR. */
8071 rel_hdr
= elf_section_data (sec
)->rel
.hdr
;
8072 if (rel_hdr
== NULL
)
8074 bed
= get_elf_backend_data (abfd
);
8075 return ((size_t) (rel
- relocs
)
8076 < NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
);
8079 /* Read the addend for REL relocation REL, which belongs to bfd ABFD.
8080 HOWTO is the relocation's howto and CONTENTS points to the contents
8081 of the section that REL is against. */
8084 mips_elf_read_rel_addend (bfd
*abfd
, const Elf_Internal_Rela
*rel
,
8085 reloc_howto_type
*howto
, bfd_byte
*contents
)
8088 unsigned int r_type
;
8092 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
8093 location
= contents
+ rel
->r_offset
;
8095 /* Get the addend, which is stored in the input file. */
8096 _bfd_mips_elf_reloc_unshuffle (abfd
, r_type
, FALSE
, location
);
8097 bytes
= mips_elf_obtain_contents (howto
, rel
, abfd
, contents
);
8098 _bfd_mips_elf_reloc_shuffle (abfd
, r_type
, FALSE
, location
);
8100 addend
= bytes
& howto
->src_mask
;
8102 /* Shift is 2, unusually, for microMIPS JALX. Adjust the addend
8104 if (r_type
== R_MICROMIPS_26_S1
&& (bytes
>> 26) == 0x3c)
8110 /* REL is a relocation in ABFD that needs a partnering LO16 relocation
8111 and *ADDEND is the addend for REL itself. Look for the LO16 relocation
8112 and update *ADDEND with the final addend. Return true on success
8113 or false if the LO16 could not be found. RELEND is the exclusive
8114 upper bound on the relocations for REL's section. */
8117 mips_elf_add_lo16_rel_addend (bfd
*abfd
,
8118 const Elf_Internal_Rela
*rel
,
8119 const Elf_Internal_Rela
*relend
,
8120 bfd_byte
*contents
, bfd_vma
*addend
)
8122 unsigned int r_type
, lo16_type
;
8123 const Elf_Internal_Rela
*lo16_relocation
;
8124 reloc_howto_type
*lo16_howto
;
8127 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
8128 if (mips16_reloc_p (r_type
))
8129 lo16_type
= R_MIPS16_LO16
;
8130 else if (micromips_reloc_p (r_type
))
8131 lo16_type
= R_MICROMIPS_LO16
;
8132 else if (r_type
== R_MIPS_PCHI16
)
8133 lo16_type
= R_MIPS_PCLO16
;
8135 lo16_type
= R_MIPS_LO16
;
8137 /* The combined value is the sum of the HI16 addend, left-shifted by
8138 sixteen bits, and the LO16 addend, sign extended. (Usually, the
8139 code does a `lui' of the HI16 value, and then an `addiu' of the
8142 Scan ahead to find a matching LO16 relocation.
8144 According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
8145 be immediately following. However, for the IRIX6 ABI, the next
8146 relocation may be a composed relocation consisting of several
8147 relocations for the same address. In that case, the R_MIPS_LO16
8148 relocation may occur as one of these. We permit a similar
8149 extension in general, as that is useful for GCC.
8151 In some cases GCC dead code elimination removes the LO16 but keeps
8152 the corresponding HI16. This is strictly speaking a violation of
8153 the ABI but not immediately harmful. */
8154 lo16_relocation
= mips_elf_next_relocation (abfd
, lo16_type
, rel
, relend
);
8155 if (lo16_relocation
== NULL
)
8158 /* Obtain the addend kept there. */
8159 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, lo16_type
, FALSE
);
8160 l
= mips_elf_read_rel_addend (abfd
, lo16_relocation
, lo16_howto
, contents
);
8162 l
<<= lo16_howto
->rightshift
;
8163 l
= _bfd_mips_elf_sign_extend (l
, 16);
8170 /* Try to read the contents of section SEC in bfd ABFD. Return true and
8171 store the contents in *CONTENTS on success. Assume that *CONTENTS
8172 already holds the contents if it is nonull on entry. */
8175 mips_elf_get_section_contents (bfd
*abfd
, asection
*sec
, bfd_byte
**contents
)
8180 /* Get cached copy if it exists. */
8181 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
8183 *contents
= elf_section_data (sec
)->this_hdr
.contents
;
8187 return bfd_malloc_and_get_section (abfd
, sec
, contents
);
8190 /* Make a new PLT record to keep internal data. */
8192 static struct plt_entry
*
8193 mips_elf_make_plt_record (bfd
*abfd
)
8195 struct plt_entry
*entry
;
8197 entry
= bfd_zalloc (abfd
, sizeof (*entry
));
8201 entry
->stub_offset
= MINUS_ONE
;
8202 entry
->mips_offset
= MINUS_ONE
;
8203 entry
->comp_offset
= MINUS_ONE
;
8204 entry
->gotplt_index
= MINUS_ONE
;
8208 /* Define the special `__gnu_absolute_zero' symbol. We only need this
8209 for PIC code, as otherwise there is no load-time relocation involved
8210 and local GOT entries whose value is zero at static link time will
8211 retain their value at load time. */
8214 mips_elf_define_absolute_zero (bfd
*abfd
, struct bfd_link_info
*info
,
8215 struct mips_elf_link_hash_table
*htab
,
8216 unsigned int r_type
)
8220 struct elf_link_hash_entry
*eh
;
8221 struct bfd_link_hash_entry
*bh
;
8225 BFD_ASSERT (!htab
->use_absolute_zero
);
8226 BFD_ASSERT (bfd_link_pic (info
));
8229 if (!_bfd_generic_link_add_one_symbol (info
, abfd
, "__gnu_absolute_zero",
8230 BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
8231 NULL
, FALSE
, FALSE
, &hzero
.bh
))
8234 BFD_ASSERT (hzero
.bh
!= NULL
);
8236 hzero
.eh
->type
= STT_NOTYPE
;
8237 hzero
.eh
->other
= STV_PROTECTED
;
8238 hzero
.eh
->def_regular
= 1;
8239 hzero
.eh
->non_elf
= 0;
8241 if (!mips_elf_record_global_got_symbol (hzero
.eh
, abfd
, info
, TRUE
, r_type
))
8244 htab
->use_absolute_zero
= TRUE
;
8249 /* Look through the relocs for a section during the first phase, and
8250 allocate space in the global offset table and record the need for
8251 standard MIPS and compressed procedure linkage table entries. */
8254 _bfd_mips_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
8255 asection
*sec
, const Elf_Internal_Rela
*relocs
)
8259 Elf_Internal_Shdr
*symtab_hdr
;
8260 struct elf_link_hash_entry
**sym_hashes
;
8262 const Elf_Internal_Rela
*rel
;
8263 const Elf_Internal_Rela
*rel_end
;
8265 const struct elf_backend_data
*bed
;
8266 struct mips_elf_link_hash_table
*htab
;
8269 reloc_howto_type
*howto
;
8271 if (bfd_link_relocatable (info
))
8274 htab
= mips_elf_hash_table (info
);
8275 BFD_ASSERT (htab
!= NULL
);
8277 dynobj
= elf_hash_table (info
)->dynobj
;
8278 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
8279 sym_hashes
= elf_sym_hashes (abfd
);
8280 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
8282 bed
= get_elf_backend_data (abfd
);
8283 rel_end
= relocs
+ sec
->reloc_count
;
8285 /* Check for the mips16 stub sections. */
8287 name
= bfd_get_section_name (abfd
, sec
);
8288 if (FN_STUB_P (name
))
8290 unsigned long r_symndx
;
8292 /* Look at the relocation information to figure out which symbol
8295 r_symndx
= mips16_stub_symndx (bed
, sec
, relocs
, rel_end
);
8299 /* xgettext:c-format */
8300 (_("%pB: warning: cannot determine the target function for"
8301 " stub section `%s'"),
8303 bfd_set_error (bfd_error_bad_value
);
8307 if (r_symndx
< extsymoff
8308 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
8312 /* This stub is for a local symbol. This stub will only be
8313 needed if there is some relocation in this BFD, other
8314 than a 16 bit function call, which refers to this symbol. */
8315 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
8317 Elf_Internal_Rela
*sec_relocs
;
8318 const Elf_Internal_Rela
*r
, *rend
;
8320 /* We can ignore stub sections when looking for relocs. */
8321 if ((o
->flags
& SEC_RELOC
) == 0
8322 || o
->reloc_count
== 0
8323 || section_allows_mips16_refs_p (o
))
8327 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
8329 if (sec_relocs
== NULL
)
8332 rend
= sec_relocs
+ o
->reloc_count
;
8333 for (r
= sec_relocs
; r
< rend
; r
++)
8334 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
8335 && !mips16_call_reloc_p (ELF_R_TYPE (abfd
, r
->r_info
)))
8338 if (elf_section_data (o
)->relocs
!= sec_relocs
)
8347 /* There is no non-call reloc for this stub, so we do
8348 not need it. Since this function is called before
8349 the linker maps input sections to output sections, we
8350 can easily discard it by setting the SEC_EXCLUDE
8352 sec
->flags
|= SEC_EXCLUDE
;
8356 /* Record this stub in an array of local symbol stubs for
8358 if (mips_elf_tdata (abfd
)->local_stubs
== NULL
)
8360 unsigned long symcount
;
8364 if (elf_bad_symtab (abfd
))
8365 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
8367 symcount
= symtab_hdr
->sh_info
;
8368 amt
= symcount
* sizeof (asection
*);
8369 n
= bfd_zalloc (abfd
, amt
);
8372 mips_elf_tdata (abfd
)->local_stubs
= n
;
8375 sec
->flags
|= SEC_KEEP
;
8376 mips_elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
8378 /* We don't need to set mips16_stubs_seen in this case.
8379 That flag is used to see whether we need to look through
8380 the global symbol table for stubs. We don't need to set
8381 it here, because we just have a local stub. */
8385 struct mips_elf_link_hash_entry
*h
;
8387 h
= ((struct mips_elf_link_hash_entry
*)
8388 sym_hashes
[r_symndx
- extsymoff
]);
8390 while (h
->root
.root
.type
== bfd_link_hash_indirect
8391 || h
->root
.root
.type
== bfd_link_hash_warning
)
8392 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
8394 /* H is the symbol this stub is for. */
8396 /* If we already have an appropriate stub for this function, we
8397 don't need another one, so we can discard this one. Since
8398 this function is called before the linker maps input sections
8399 to output sections, we can easily discard it by setting the
8400 SEC_EXCLUDE flag. */
8401 if (h
->fn_stub
!= NULL
)
8403 sec
->flags
|= SEC_EXCLUDE
;
8407 sec
->flags
|= SEC_KEEP
;
8409 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
8412 else if (CALL_STUB_P (name
) || CALL_FP_STUB_P (name
))
8414 unsigned long r_symndx
;
8415 struct mips_elf_link_hash_entry
*h
;
8418 /* Look at the relocation information to figure out which symbol
8421 r_symndx
= mips16_stub_symndx (bed
, sec
, relocs
, rel_end
);
8425 /* xgettext:c-format */
8426 (_("%pB: warning: cannot determine the target function for"
8427 " stub section `%s'"),
8429 bfd_set_error (bfd_error_bad_value
);
8433 if (r_symndx
< extsymoff
8434 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
8438 /* This stub is for a local symbol. This stub will only be
8439 needed if there is some relocation (R_MIPS16_26) in this BFD
8440 that refers to this symbol. */
8441 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
8443 Elf_Internal_Rela
*sec_relocs
;
8444 const Elf_Internal_Rela
*r
, *rend
;
8446 /* We can ignore stub sections when looking for relocs. */
8447 if ((o
->flags
& SEC_RELOC
) == 0
8448 || o
->reloc_count
== 0
8449 || section_allows_mips16_refs_p (o
))
8453 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
8455 if (sec_relocs
== NULL
)
8458 rend
= sec_relocs
+ o
->reloc_count
;
8459 for (r
= sec_relocs
; r
< rend
; r
++)
8460 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
8461 && ELF_R_TYPE (abfd
, r
->r_info
) == R_MIPS16_26
)
8464 if (elf_section_data (o
)->relocs
!= sec_relocs
)
8473 /* There is no non-call reloc for this stub, so we do
8474 not need it. Since this function is called before
8475 the linker maps input sections to output sections, we
8476 can easily discard it by setting the SEC_EXCLUDE
8478 sec
->flags
|= SEC_EXCLUDE
;
8482 /* Record this stub in an array of local symbol call_stubs for
8484 if (mips_elf_tdata (abfd
)->local_call_stubs
== NULL
)
8486 unsigned long symcount
;
8490 if (elf_bad_symtab (abfd
))
8491 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
8493 symcount
= symtab_hdr
->sh_info
;
8494 amt
= symcount
* sizeof (asection
*);
8495 n
= bfd_zalloc (abfd
, amt
);
8498 mips_elf_tdata (abfd
)->local_call_stubs
= n
;
8501 sec
->flags
|= SEC_KEEP
;
8502 mips_elf_tdata (abfd
)->local_call_stubs
[r_symndx
] = sec
;
8504 /* We don't need to set mips16_stubs_seen in this case.
8505 That flag is used to see whether we need to look through
8506 the global symbol table for stubs. We don't need to set
8507 it here, because we just have a local stub. */
8511 h
= ((struct mips_elf_link_hash_entry
*)
8512 sym_hashes
[r_symndx
- extsymoff
]);
8514 /* H is the symbol this stub is for. */
8516 if (CALL_FP_STUB_P (name
))
8517 loc
= &h
->call_fp_stub
;
8519 loc
= &h
->call_stub
;
8521 /* If we already have an appropriate stub for this function, we
8522 don't need another one, so we can discard this one. Since
8523 this function is called before the linker maps input sections
8524 to output sections, we can easily discard it by setting the
8525 SEC_EXCLUDE flag. */
8528 sec
->flags
|= SEC_EXCLUDE
;
8532 sec
->flags
|= SEC_KEEP
;
8534 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
8540 for (rel
= relocs
; rel
< rel_end
; ++rel
)
8542 unsigned long r_symndx
;
8543 unsigned int r_type
;
8544 struct elf_link_hash_entry
*h
;
8545 bfd_boolean can_make_dynamic_p
;
8546 bfd_boolean call_reloc_p
;
8547 bfd_boolean constrain_symbol_p
;
8549 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
8550 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
8552 if (r_symndx
< extsymoff
)
8554 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
8557 /* xgettext:c-format */
8558 (_("%pB: malformed reloc detected for section %s"),
8560 bfd_set_error (bfd_error_bad_value
);
8565 h
= sym_hashes
[r_symndx
- extsymoff
];
8568 while (h
->root
.type
== bfd_link_hash_indirect
8569 || h
->root
.type
== bfd_link_hash_warning
)
8570 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8574 /* Set CAN_MAKE_DYNAMIC_P to true if we can convert this
8575 relocation into a dynamic one. */
8576 can_make_dynamic_p
= FALSE
;
8578 /* Set CALL_RELOC_P to true if the relocation is for a call,
8579 and if pointer equality therefore doesn't matter. */
8580 call_reloc_p
= FALSE
;
8582 /* Set CONSTRAIN_SYMBOL_P if we need to take the relocation
8583 into account when deciding how to define the symbol.
8584 Relocations in nonallocatable sections such as .pdr and
8585 .debug* should have no effect. */
8586 constrain_symbol_p
= ((sec
->flags
& SEC_ALLOC
) != 0);
8591 case R_MIPS_CALL_HI16
:
8592 case R_MIPS_CALL_LO16
:
8593 case R_MIPS16_CALL16
:
8594 case R_MICROMIPS_CALL16
:
8595 case R_MICROMIPS_CALL_HI16
:
8596 case R_MICROMIPS_CALL_LO16
:
8597 call_reloc_p
= TRUE
;
8601 case R_MIPS_GOT_LO16
:
8602 case R_MIPS_GOT_PAGE
:
8603 case R_MIPS_GOT_DISP
:
8604 case R_MIPS16_GOT16
:
8605 case R_MICROMIPS_GOT16
:
8606 case R_MICROMIPS_GOT_LO16
:
8607 case R_MICROMIPS_GOT_PAGE
:
8608 case R_MICROMIPS_GOT_DISP
:
8609 /* If we have a symbol that will resolve to zero at static link
8610 time and it is used by a GOT relocation applied to code we
8611 cannot relax to an immediate zero load, then we will be using
8612 the special `__gnu_absolute_zero' symbol whose value is zero
8613 at dynamic load time. We ignore HI16-type GOT relocations at
8614 this stage, because their handling will depend entirely on
8615 the corresponding LO16-type GOT relocation. */
8616 if (!call_hi16_reloc_p (r_type
)
8618 && bfd_link_pic (info
)
8619 && !htab
->use_absolute_zero
8620 && UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
8622 bfd_boolean rel_reloc
;
8624 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
8627 rel_reloc
= mips_elf_rel_relocation_p (abfd
, sec
, relocs
, rel
);
8628 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, !rel_reloc
);
8630 if (!mips_elf_nullify_got_load (abfd
, contents
, rel
, howto
,
8632 if (!mips_elf_define_absolute_zero (abfd
, info
, htab
, r_type
))
8637 case R_MIPS_GOT_HI16
:
8638 case R_MIPS_GOT_OFST
:
8639 case R_MIPS_TLS_GOTTPREL
:
8641 case R_MIPS_TLS_LDM
:
8642 case R_MIPS16_TLS_GOTTPREL
:
8643 case R_MIPS16_TLS_GD
:
8644 case R_MIPS16_TLS_LDM
:
8645 case R_MICROMIPS_GOT_HI16
:
8646 case R_MICROMIPS_GOT_OFST
:
8647 case R_MICROMIPS_TLS_GOTTPREL
:
8648 case R_MICROMIPS_TLS_GD
:
8649 case R_MICROMIPS_TLS_LDM
:
8651 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
8652 if (!mips_elf_create_got_section (dynobj
, info
))
8654 if (htab
->is_vxworks
&& !bfd_link_pic (info
))
8657 /* xgettext:c-format */
8658 (_("%pB: GOT reloc at %#" PRIx64
" not expected in executables"),
8659 abfd
, (uint64_t) rel
->r_offset
);
8660 bfd_set_error (bfd_error_bad_value
);
8663 can_make_dynamic_p
= TRUE
;
8668 case R_MICROMIPS_JALR
:
8669 /* These relocations have empty fields and are purely there to
8670 provide link information. The symbol value doesn't matter. */
8671 constrain_symbol_p
= FALSE
;
8674 case R_MIPS_GPREL16
:
8675 case R_MIPS_GPREL32
:
8676 case R_MIPS16_GPREL
:
8677 case R_MICROMIPS_GPREL16
:
8678 /* GP-relative relocations always resolve to a definition in a
8679 regular input file, ignoring the one-definition rule. This is
8680 important for the GP setup sequence in NewABI code, which
8681 always resolves to a local function even if other relocations
8682 against the symbol wouldn't. */
8683 constrain_symbol_p
= FALSE
;
8689 /* In VxWorks executables, references to external symbols
8690 must be handled using copy relocs or PLT entries; it is not
8691 possible to convert this relocation into a dynamic one.
8693 For executables that use PLTs and copy-relocs, we have a
8694 choice between converting the relocation into a dynamic
8695 one or using copy relocations or PLT entries. It is
8696 usually better to do the former, unless the relocation is
8697 against a read-only section. */
8698 if ((bfd_link_pic (info
)
8700 && !htab
->is_vxworks
8701 && strcmp (h
->root
.root
.string
, "__gnu_local_gp") != 0
8702 && !(!info
->nocopyreloc
8703 && !PIC_OBJECT_P (abfd
)
8704 && MIPS_ELF_READONLY_SECTION (sec
))))
8705 && (sec
->flags
& SEC_ALLOC
) != 0)
8707 can_make_dynamic_p
= TRUE
;
8709 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
8715 case R_MIPS_PC21_S2
:
8716 case R_MIPS_PC26_S2
:
8718 case R_MIPS16_PC16_S1
:
8719 case R_MICROMIPS_26_S1
:
8720 case R_MICROMIPS_PC7_S1
:
8721 case R_MICROMIPS_PC10_S1
:
8722 case R_MICROMIPS_PC16_S1
:
8723 case R_MICROMIPS_PC23_S2
:
8724 call_reloc_p
= TRUE
;
8730 if (constrain_symbol_p
)
8732 if (!can_make_dynamic_p
)
8733 ((struct mips_elf_link_hash_entry
*) h
)->has_static_relocs
= 1;
8736 h
->pointer_equality_needed
= 1;
8738 /* We must not create a stub for a symbol that has
8739 relocations related to taking the function's address.
8740 This doesn't apply to VxWorks, where CALL relocs refer
8741 to a .got.plt entry instead of a normal .got entry. */
8742 if (!htab
->is_vxworks
&& (!can_make_dynamic_p
|| !call_reloc_p
))
8743 ((struct mips_elf_link_hash_entry
*) h
)->no_fn_stub
= TRUE
;
8746 /* Relocations against the special VxWorks __GOTT_BASE__ and
8747 __GOTT_INDEX__ symbols must be left to the loader. Allocate
8748 room for them in .rela.dyn. */
8749 if (is_gott_symbol (info
, h
))
8753 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
8757 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
8758 if (MIPS_ELF_READONLY_SECTION (sec
))
8759 /* We tell the dynamic linker that there are
8760 relocations against the text segment. */
8761 info
->flags
|= DF_TEXTREL
;
8764 else if (call_lo16_reloc_p (r_type
)
8765 || got_lo16_reloc_p (r_type
)
8766 || got_disp_reloc_p (r_type
)
8767 || (got16_reloc_p (r_type
) && htab
->is_vxworks
))
8769 /* We may need a local GOT entry for this relocation. We
8770 don't count R_MIPS_GOT_PAGE because we can estimate the
8771 maximum number of pages needed by looking at the size of
8772 the segment. Similar comments apply to R_MIPS*_GOT16 and
8773 R_MIPS*_CALL16, except on VxWorks, where GOT relocations
8774 always evaluate to "G". We don't count R_MIPS_GOT_HI16, or
8775 R_MIPS_CALL_HI16 because these are always followed by an
8776 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
8777 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
8778 rel
->r_addend
, info
, r_type
))
8783 && mips_elf_relocation_needs_la25_stub (abfd
, r_type
,
8784 ELF_ST_IS_MIPS16 (h
->other
)))
8785 ((struct mips_elf_link_hash_entry
*) h
)->has_nonpic_branches
= TRUE
;
8790 case R_MIPS16_CALL16
:
8791 case R_MICROMIPS_CALL16
:
8795 /* xgettext:c-format */
8796 (_("%pB: CALL16 reloc at %#" PRIx64
" not against global symbol"),
8797 abfd
, (uint64_t) rel
->r_offset
);
8798 bfd_set_error (bfd_error_bad_value
);
8803 case R_MIPS_CALL_HI16
:
8804 case R_MIPS_CALL_LO16
:
8805 case R_MICROMIPS_CALL_HI16
:
8806 case R_MICROMIPS_CALL_LO16
:
8809 /* Make sure there is room in the regular GOT to hold the
8810 function's address. We may eliminate it in favour of
8811 a .got.plt entry later; see mips_elf_count_got_symbols. */
8812 if (!mips_elf_record_global_got_symbol (h
, abfd
, info
, TRUE
,
8816 /* We need a stub, not a plt entry for the undefined
8817 function. But we record it as if it needs plt. See
8818 _bfd_elf_adjust_dynamic_symbol. */
8824 case R_MIPS_GOT_PAGE
:
8825 case R_MICROMIPS_GOT_PAGE
:
8826 case R_MIPS16_GOT16
:
8828 case R_MIPS_GOT_HI16
:
8829 case R_MIPS_GOT_LO16
:
8830 case R_MICROMIPS_GOT16
:
8831 case R_MICROMIPS_GOT_HI16
:
8832 case R_MICROMIPS_GOT_LO16
:
8833 if (!h
|| got_page_reloc_p (r_type
))
8835 /* This relocation needs (or may need, if h != NULL) a
8836 page entry in the GOT. For R_MIPS_GOT_PAGE we do not
8837 know for sure until we know whether the symbol is
8839 if (mips_elf_rel_relocation_p (abfd
, sec
, relocs
, rel
))
8841 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
8843 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
8844 addend
= mips_elf_read_rel_addend (abfd
, rel
,
8846 if (got16_reloc_p (r_type
))
8847 mips_elf_add_lo16_rel_addend (abfd
, rel
, rel_end
,
8850 addend
<<= howto
->rightshift
;
8853 addend
= rel
->r_addend
;
8854 if (!mips_elf_record_got_page_ref (info
, abfd
, r_symndx
,
8860 struct mips_elf_link_hash_entry
*hmips
=
8861 (struct mips_elf_link_hash_entry
*) h
;
8863 /* This symbol is definitely not overridable. */
8864 if (hmips
->root
.def_regular
8865 && ! (bfd_link_pic (info
) && ! info
->symbolic
8866 && ! hmips
->root
.forced_local
))
8870 /* If this is a global, overridable symbol, GOT_PAGE will
8871 decay to GOT_DISP, so we'll need a GOT entry for it. */
8874 case R_MIPS_GOT_DISP
:
8875 case R_MICROMIPS_GOT_DISP
:
8876 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
, info
,
8881 case R_MIPS_TLS_GOTTPREL
:
8882 case R_MIPS16_TLS_GOTTPREL
:
8883 case R_MICROMIPS_TLS_GOTTPREL
:
8884 if (bfd_link_pic (info
))
8885 info
->flags
|= DF_STATIC_TLS
;
8888 case R_MIPS_TLS_LDM
:
8889 case R_MIPS16_TLS_LDM
:
8890 case R_MICROMIPS_TLS_LDM
:
8891 if (tls_ldm_reloc_p (r_type
))
8893 r_symndx
= STN_UNDEF
;
8899 case R_MIPS16_TLS_GD
:
8900 case R_MICROMIPS_TLS_GD
:
8901 /* This symbol requires a global offset table entry, or two
8902 for TLS GD relocations. */
8905 if (!mips_elf_record_global_got_symbol (h
, abfd
, info
,
8911 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
8921 /* In VxWorks executables, references to external symbols
8922 are handled using copy relocs or PLT stubs, so there's
8923 no need to add a .rela.dyn entry for this relocation. */
8924 if (can_make_dynamic_p
)
8928 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
8932 if (bfd_link_pic (info
) && h
== NULL
)
8934 /* When creating a shared object, we must copy these
8935 reloc types into the output file as R_MIPS_REL32
8936 relocs. Make room for this reloc in .rel(a).dyn. */
8937 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
8938 if (MIPS_ELF_READONLY_SECTION (sec
))
8939 /* We tell the dynamic linker that there are
8940 relocations against the text segment. */
8941 info
->flags
|= DF_TEXTREL
;
8945 struct mips_elf_link_hash_entry
*hmips
;
8947 /* For a shared object, we must copy this relocation
8948 unless the symbol turns out to be undefined and
8949 weak with non-default visibility, in which case
8950 it will be left as zero.
8952 We could elide R_MIPS_REL32 for locally binding symbols
8953 in shared libraries, but do not yet do so.
8955 For an executable, we only need to copy this
8956 reloc if the symbol is defined in a dynamic
8958 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8959 ++hmips
->possibly_dynamic_relocs
;
8960 if (MIPS_ELF_READONLY_SECTION (sec
))
8961 /* We need it to tell the dynamic linker if there
8962 are relocations against the text segment. */
8963 hmips
->readonly_reloc
= TRUE
;
8967 if (SGI_COMPAT (abfd
))
8968 mips_elf_hash_table (info
)->compact_rel_size
+=
8969 sizeof (Elf32_External_crinfo
);
8973 case R_MIPS_GPREL16
:
8974 case R_MIPS_LITERAL
:
8975 case R_MIPS_GPREL32
:
8976 case R_MICROMIPS_26_S1
:
8977 case R_MICROMIPS_GPREL16
:
8978 case R_MICROMIPS_LITERAL
:
8979 case R_MICROMIPS_GPREL7_S2
:
8980 if (SGI_COMPAT (abfd
))
8981 mips_elf_hash_table (info
)->compact_rel_size
+=
8982 sizeof (Elf32_External_crinfo
);
8985 /* This relocation describes the C++ object vtable hierarchy.
8986 Reconstruct it for later use during GC. */
8987 case R_MIPS_GNU_VTINHERIT
:
8988 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
8992 /* This relocation describes which C++ vtable entries are actually
8993 used. Record for later use during GC. */
8994 case R_MIPS_GNU_VTENTRY
:
8995 BFD_ASSERT (h
!= NULL
);
8997 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
9005 /* Record the need for a PLT entry. At this point we don't know
9006 yet if we are going to create a PLT in the first place, but
9007 we only record whether the relocation requires a standard MIPS
9008 or a compressed code entry anyway. If we don't make a PLT after
9009 all, then we'll just ignore these arrangements. Likewise if
9010 a PLT entry is not created because the symbol is satisfied
9013 && (branch_reloc_p (r_type
)
9014 || mips16_branch_reloc_p (r_type
)
9015 || micromips_branch_reloc_p (r_type
))
9016 && !SYMBOL_CALLS_LOCAL (info
, h
))
9018 if (h
->plt
.plist
== NULL
)
9019 h
->plt
.plist
= mips_elf_make_plt_record (abfd
);
9020 if (h
->plt
.plist
== NULL
)
9023 if (branch_reloc_p (r_type
))
9024 h
->plt
.plist
->need_mips
= TRUE
;
9026 h
->plt
.plist
->need_comp
= TRUE
;
9029 /* See if this reloc would need to refer to a MIPS16 hard-float stub,
9030 if there is one. We only need to handle global symbols here;
9031 we decide whether to keep or delete stubs for local symbols
9032 when processing the stub's relocations. */
9034 && !mips16_call_reloc_p (r_type
)
9035 && !section_allows_mips16_refs_p (sec
))
9037 struct mips_elf_link_hash_entry
*mh
;
9039 mh
= (struct mips_elf_link_hash_entry
*) h
;
9040 mh
->need_fn_stub
= TRUE
;
9043 /* Refuse some position-dependent relocations when creating a
9044 shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
9045 not PIC, but we can create dynamic relocations and the result
9046 will be fine. Also do not refuse R_MIPS_LO16, which can be
9047 combined with R_MIPS_GOT16. */
9048 if (bfd_link_pic (info
))
9055 case R_MIPS_HIGHEST
:
9056 case R_MICROMIPS_HI16
:
9057 case R_MICROMIPS_HIGHER
:
9058 case R_MICROMIPS_HIGHEST
:
9059 /* Don't refuse a high part relocation if it's against
9060 no symbol (e.g. part of a compound relocation). */
9061 if (r_symndx
== STN_UNDEF
)
9064 /* R_MIPS_HI16 against _gp_disp is used for $gp setup,
9065 and has a special meaning. */
9066 if (!NEWABI_P (abfd
) && h
!= NULL
9067 && strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
9070 /* Likewise __GOTT_BASE__ and __GOTT_INDEX__ on VxWorks. */
9071 if (is_gott_symbol (info
, h
))
9078 case R_MICROMIPS_26_S1
:
9079 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
9080 info
->callbacks
->einfo
9081 /* xgettext:c-format */
9082 (_("%X%H: relocation %s against `%s' cannot be used"
9083 " when making a shared object; recompile with -fPIC\n"),
9084 abfd
, sec
, rel
->r_offset
, howto
->name
,
9085 (h
) ? h
->root
.root
.string
: "a local symbol");
9096 /* Allocate space for global sym dynamic relocs. */
9099 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
9101 struct bfd_link_info
*info
= inf
;
9103 struct mips_elf_link_hash_entry
*hmips
;
9104 struct mips_elf_link_hash_table
*htab
;
9106 htab
= mips_elf_hash_table (info
);
9107 BFD_ASSERT (htab
!= NULL
);
9109 dynobj
= elf_hash_table (info
)->dynobj
;
9110 hmips
= (struct mips_elf_link_hash_entry
*) h
;
9112 /* VxWorks executables are handled elsewhere; we only need to
9113 allocate relocations in shared objects. */
9114 if (htab
->is_vxworks
&& !bfd_link_pic (info
))
9117 /* Ignore indirect symbols. All relocations against such symbols
9118 will be redirected to the target symbol. */
9119 if (h
->root
.type
== bfd_link_hash_indirect
)
9122 /* If this symbol is defined in a dynamic object, or we are creating
9123 a shared library, we will need to copy any R_MIPS_32 or
9124 R_MIPS_REL32 relocs against it into the output file. */
9125 if (! bfd_link_relocatable (info
)
9126 && hmips
->possibly_dynamic_relocs
!= 0
9127 && (h
->root
.type
== bfd_link_hash_defweak
9128 || (!h
->def_regular
&& !ELF_COMMON_DEF_P (h
))
9129 || bfd_link_pic (info
)))
9131 bfd_boolean do_copy
= TRUE
;
9133 if (h
->root
.type
== bfd_link_hash_undefweak
)
9135 /* Do not copy relocations for undefined weak symbols that
9136 we are not going to export. */
9137 if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9140 /* Make sure undefined weak symbols are output as a dynamic
9142 else if (h
->dynindx
== -1 && !h
->forced_local
)
9144 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
9151 /* Even though we don't directly need a GOT entry for this symbol,
9152 the SVR4 psABI requires it to have a dynamic symbol table
9153 index greater that DT_MIPS_GOTSYM if there are dynamic
9154 relocations against it.
9156 VxWorks does not enforce the same mapping between the GOT
9157 and the symbol table, so the same requirement does not
9159 if (!htab
->is_vxworks
)
9161 if (hmips
->global_got_area
> GGA_RELOC_ONLY
)
9162 hmips
->global_got_area
= GGA_RELOC_ONLY
;
9163 hmips
->got_only_for_calls
= FALSE
;
9166 mips_elf_allocate_dynamic_relocations
9167 (dynobj
, info
, hmips
->possibly_dynamic_relocs
);
9168 if (hmips
->readonly_reloc
)
9169 /* We tell the dynamic linker that there are relocations
9170 against the text segment. */
9171 info
->flags
|= DF_TEXTREL
;
9178 /* Adjust a symbol defined by a dynamic object and referenced by a
9179 regular object. The current definition is in some section of the
9180 dynamic object, but we're not including those sections. We have to
9181 change the definition to something the rest of the link can
9185 _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
9186 struct elf_link_hash_entry
*h
)
9189 struct mips_elf_link_hash_entry
*hmips
;
9190 struct mips_elf_link_hash_table
*htab
;
9193 htab
= mips_elf_hash_table (info
);
9194 BFD_ASSERT (htab
!= NULL
);
9196 dynobj
= elf_hash_table (info
)->dynobj
;
9197 hmips
= (struct mips_elf_link_hash_entry
*) h
;
9199 /* Make sure we know what is going on here. */
9200 BFD_ASSERT (dynobj
!= NULL
9205 && !h
->def_regular
)));
9207 hmips
= (struct mips_elf_link_hash_entry
*) h
;
9209 /* If there are call relocations against an externally-defined symbol,
9210 see whether we can create a MIPS lazy-binding stub for it. We can
9211 only do this if all references to the function are through call
9212 relocations, and in that case, the traditional lazy-binding stubs
9213 are much more efficient than PLT entries.
9215 Traditional stubs are only available on SVR4 psABI-based systems;
9216 VxWorks always uses PLTs instead. */
9217 if (!htab
->is_vxworks
&& h
->needs_plt
&& !hmips
->no_fn_stub
)
9219 if (! elf_hash_table (info
)->dynamic_sections_created
)
9222 /* If this symbol is not defined in a regular file, then set
9223 the symbol to the stub location. This is required to make
9224 function pointers compare as equal between the normal
9225 executable and the shared library. */
9227 && !bfd_is_abs_section (htab
->sstubs
->output_section
))
9229 hmips
->needs_lazy_stub
= TRUE
;
9230 htab
->lazy_stub_count
++;
9234 /* As above, VxWorks requires PLT entries for externally-defined
9235 functions that are only accessed through call relocations.
9237 Both VxWorks and non-VxWorks targets also need PLT entries if there
9238 are static-only relocations against an externally-defined function.
9239 This can technically occur for shared libraries if there are
9240 branches to the symbol, although it is unlikely that this will be
9241 used in practice due to the short ranges involved. It can occur
9242 for any relative or absolute relocation in executables; in that
9243 case, the PLT entry becomes the function's canonical address. */
9244 else if (((h
->needs_plt
&& !hmips
->no_fn_stub
)
9245 || (h
->type
== STT_FUNC
&& hmips
->has_static_relocs
))
9246 && htab
->use_plts_and_copy_relocs
9247 && !SYMBOL_CALLS_LOCAL (info
, h
)
9248 && !(ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
9249 && h
->root
.type
== bfd_link_hash_undefweak
))
9251 bfd_boolean micromips_p
= MICROMIPS_P (info
->output_bfd
);
9252 bfd_boolean newabi_p
= NEWABI_P (info
->output_bfd
);
9254 /* If this is the first symbol to need a PLT entry, then make some
9255 basic setup. Also work out PLT entry sizes. We'll need them
9256 for PLT offset calculations. */
9257 if (htab
->plt_mips_offset
+ htab
->plt_comp_offset
== 0)
9259 BFD_ASSERT (htab
->root
.sgotplt
->size
== 0);
9260 BFD_ASSERT (htab
->plt_got_index
== 0);
9262 /* If we're using the PLT additions to the psABI, each PLT
9263 entry is 16 bytes and the PLT0 entry is 32 bytes.
9264 Encourage better cache usage by aligning. We do this
9265 lazily to avoid pessimizing traditional objects. */
9266 if (!htab
->is_vxworks
9267 && !bfd_set_section_alignment (dynobj
, htab
->root
.splt
, 5))
9270 /* Make sure that .got.plt is word-aligned. We do this lazily
9271 for the same reason as above. */
9272 if (!bfd_set_section_alignment (dynobj
, htab
->root
.sgotplt
,
9273 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
9276 /* On non-VxWorks targets, the first two entries in .got.plt
9278 if (!htab
->is_vxworks
)
9280 += (get_elf_backend_data (dynobj
)->got_header_size
9281 / MIPS_ELF_GOT_SIZE (dynobj
));
9283 /* On VxWorks, also allocate room for the header's
9284 .rela.plt.unloaded entries. */
9285 if (htab
->is_vxworks
&& !bfd_link_pic (info
))
9286 htab
->srelplt2
->size
+= 2 * sizeof (Elf32_External_Rela
);
9288 /* Now work out the sizes of individual PLT entries. */
9289 if (htab
->is_vxworks
&& bfd_link_pic (info
))
9290 htab
->plt_mips_entry_size
9291 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt_entry
);
9292 else if (htab
->is_vxworks
)
9293 htab
->plt_mips_entry_size
9294 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt_entry
);
9296 htab
->plt_mips_entry_size
9297 = 4 * ARRAY_SIZE (mips_exec_plt_entry
);
9298 else if (!micromips_p
)
9300 htab
->plt_mips_entry_size
9301 = 4 * ARRAY_SIZE (mips_exec_plt_entry
);
9302 htab
->plt_comp_entry_size
9303 = 2 * ARRAY_SIZE (mips16_o32_exec_plt_entry
);
9305 else if (htab
->insn32
)
9307 htab
->plt_mips_entry_size
9308 = 4 * ARRAY_SIZE (mips_exec_plt_entry
);
9309 htab
->plt_comp_entry_size
9310 = 2 * ARRAY_SIZE (micromips_insn32_o32_exec_plt_entry
);
9314 htab
->plt_mips_entry_size
9315 = 4 * ARRAY_SIZE (mips_exec_plt_entry
);
9316 htab
->plt_comp_entry_size
9317 = 2 * ARRAY_SIZE (micromips_o32_exec_plt_entry
);
9321 if (h
->plt
.plist
== NULL
)
9322 h
->plt
.plist
= mips_elf_make_plt_record (dynobj
);
9323 if (h
->plt
.plist
== NULL
)
9326 /* There are no defined MIPS16 or microMIPS PLT entries for VxWorks,
9327 n32 or n64, so always use a standard entry there.
9329 If the symbol has a MIPS16 call stub and gets a PLT entry, then
9330 all MIPS16 calls will go via that stub, and there is no benefit
9331 to having a MIPS16 entry. And in the case of call_stub a
9332 standard entry actually has to be used as the stub ends with a J
9337 || hmips
->call_fp_stub
)
9339 h
->plt
.plist
->need_mips
= TRUE
;
9340 h
->plt
.plist
->need_comp
= FALSE
;
9343 /* Otherwise, if there are no direct calls to the function, we
9344 have a free choice of whether to use standard or compressed
9345 entries. Prefer microMIPS entries if the object is known to
9346 contain microMIPS code, so that it becomes possible to create
9347 pure microMIPS binaries. Prefer standard entries otherwise,
9348 because MIPS16 ones are no smaller and are usually slower. */
9349 if (!h
->plt
.plist
->need_mips
&& !h
->plt
.plist
->need_comp
)
9352 h
->plt
.plist
->need_comp
= TRUE
;
9354 h
->plt
.plist
->need_mips
= TRUE
;
9357 if (h
->plt
.plist
->need_mips
)
9359 h
->plt
.plist
->mips_offset
= htab
->plt_mips_offset
;
9360 htab
->plt_mips_offset
+= htab
->plt_mips_entry_size
;
9362 if (h
->plt
.plist
->need_comp
)
9364 h
->plt
.plist
->comp_offset
= htab
->plt_comp_offset
;
9365 htab
->plt_comp_offset
+= htab
->plt_comp_entry_size
;
9368 /* Reserve the corresponding .got.plt entry now too. */
9369 h
->plt
.plist
->gotplt_index
= htab
->plt_got_index
++;
9371 /* If the output file has no definition of the symbol, set the
9372 symbol's value to the address of the stub. */
9373 if (!bfd_link_pic (info
) && !h
->def_regular
)
9374 hmips
->use_plt_entry
= TRUE
;
9376 /* Make room for the R_MIPS_JUMP_SLOT relocation. */
9377 htab
->root
.srelplt
->size
+= (htab
->is_vxworks
9378 ? MIPS_ELF_RELA_SIZE (dynobj
)
9379 : MIPS_ELF_REL_SIZE (dynobj
));
9381 /* Make room for the .rela.plt.unloaded relocations. */
9382 if (htab
->is_vxworks
&& !bfd_link_pic (info
))
9383 htab
->srelplt2
->size
+= 3 * sizeof (Elf32_External_Rela
);
9385 /* All relocations against this symbol that could have been made
9386 dynamic will now refer to the PLT entry instead. */
9387 hmips
->possibly_dynamic_relocs
= 0;
9392 /* If this is a weak symbol, and there is a real definition, the
9393 processor independent code will have arranged for us to see the
9394 real definition first, and we can just use the same value. */
9395 if (h
->is_weakalias
)
9397 struct elf_link_hash_entry
*def
= weakdef (h
);
9398 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
9399 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
9400 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
9404 /* Otherwise, there is nothing further to do for symbols defined
9405 in regular objects. */
9409 /* There's also nothing more to do if we'll convert all relocations
9410 against this symbol into dynamic relocations. */
9411 if (!hmips
->has_static_relocs
)
9414 /* We're now relying on copy relocations. Complain if we have
9415 some that we can't convert. */
9416 if (!htab
->use_plts_and_copy_relocs
|| bfd_link_pic (info
))
9418 _bfd_error_handler (_("non-dynamic relocations refer to "
9419 "dynamic symbol %s"),
9420 h
->root
.root
.string
);
9421 bfd_set_error (bfd_error_bad_value
);
9425 /* We must allocate the symbol in our .dynbss section, which will
9426 become part of the .bss section of the executable. There will be
9427 an entry for this symbol in the .dynsym section. The dynamic
9428 object will contain position independent code, so all references
9429 from the dynamic object to this symbol will go through the global
9430 offset table. The dynamic linker will use the .dynsym entry to
9431 determine the address it must put in the global offset table, so
9432 both the dynamic object and the regular object will refer to the
9433 same memory location for the variable. */
9435 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
9437 s
= htab
->root
.sdynrelro
;
9438 srel
= htab
->root
.sreldynrelro
;
9442 s
= htab
->root
.sdynbss
;
9443 srel
= htab
->root
.srelbss
;
9445 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
9447 if (htab
->is_vxworks
)
9448 srel
->size
+= sizeof (Elf32_External_Rela
);
9450 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
9454 /* All relocations against this symbol that could have been made
9455 dynamic will now refer to the local copy instead. */
9456 hmips
->possibly_dynamic_relocs
= 0;
9458 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
9461 /* This function is called after all the input files have been read,
9462 and the input sections have been assigned to output sections. We
9463 check for any mips16 stub sections that we can discard. */
9466 _bfd_mips_elf_always_size_sections (bfd
*output_bfd
,
9467 struct bfd_link_info
*info
)
9470 struct mips_elf_link_hash_table
*htab
;
9471 struct mips_htab_traverse_info hti
;
9473 htab
= mips_elf_hash_table (info
);
9474 BFD_ASSERT (htab
!= NULL
);
9476 /* The .reginfo section has a fixed size. */
9477 sect
= bfd_get_section_by_name (output_bfd
, ".reginfo");
9480 bfd_set_section_size (output_bfd
, sect
, sizeof (Elf32_External_RegInfo
));
9481 sect
->flags
|= SEC_FIXED_SIZE
| SEC_HAS_CONTENTS
;
9484 /* The .MIPS.abiflags section has a fixed size. */
9485 sect
= bfd_get_section_by_name (output_bfd
, ".MIPS.abiflags");
9488 bfd_set_section_size (output_bfd
, sect
,
9489 sizeof (Elf_External_ABIFlags_v0
));
9490 sect
->flags
|= SEC_FIXED_SIZE
| SEC_HAS_CONTENTS
;
9494 hti
.output_bfd
= output_bfd
;
9496 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
9497 mips_elf_check_symbols
, &hti
);
9504 /* If the link uses a GOT, lay it out and work out its size. */
9507 mips_elf_lay_out_got (bfd
*output_bfd
, struct bfd_link_info
*info
)
9511 struct mips_got_info
*g
;
9512 bfd_size_type loadable_size
= 0;
9513 bfd_size_type page_gotno
;
9515 struct mips_elf_traverse_got_arg tga
;
9516 struct mips_elf_link_hash_table
*htab
;
9518 htab
= mips_elf_hash_table (info
);
9519 BFD_ASSERT (htab
!= NULL
);
9521 s
= htab
->root
.sgot
;
9525 dynobj
= elf_hash_table (info
)->dynobj
;
9528 /* Allocate room for the reserved entries. VxWorks always reserves
9529 3 entries; other objects only reserve 2 entries. */
9530 BFD_ASSERT (g
->assigned_low_gotno
== 0);
9531 if (htab
->is_vxworks
)
9532 htab
->reserved_gotno
= 3;
9534 htab
->reserved_gotno
= 2;
9535 g
->local_gotno
+= htab
->reserved_gotno
;
9536 g
->assigned_low_gotno
= htab
->reserved_gotno
;
9538 /* Decide which symbols need to go in the global part of the GOT and
9539 count the number of reloc-only GOT symbols. */
9540 mips_elf_link_hash_traverse (htab
, mips_elf_count_got_symbols
, info
);
9542 if (!mips_elf_resolve_final_got_entries (info
, g
))
9545 /* Calculate the total loadable size of the output. That
9546 will give us the maximum number of GOT_PAGE entries
9548 for (ibfd
= info
->input_bfds
; ibfd
; ibfd
= ibfd
->link
.next
)
9550 asection
*subsection
;
9552 for (subsection
= ibfd
->sections
;
9554 subsection
= subsection
->next
)
9556 if ((subsection
->flags
& SEC_ALLOC
) == 0)
9558 loadable_size
+= ((subsection
->size
+ 0xf)
9559 &~ (bfd_size_type
) 0xf);
9563 if (htab
->is_vxworks
)
9564 /* There's no need to allocate page entries for VxWorks; R_MIPS*_GOT16
9565 relocations against local symbols evaluate to "G", and the EABI does
9566 not include R_MIPS_GOT_PAGE. */
9569 /* Assume there are two loadable segments consisting of contiguous
9570 sections. Is 5 enough? */
9571 page_gotno
= (loadable_size
>> 16) + 5;
9573 /* Choose the smaller of the two page estimates; both are intended to be
9575 if (page_gotno
> g
->page_gotno
)
9576 page_gotno
= g
->page_gotno
;
9578 g
->local_gotno
+= page_gotno
;
9579 g
->assigned_high_gotno
= g
->local_gotno
- 1;
9581 s
->size
+= g
->local_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
9582 s
->size
+= g
->global_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
9583 s
->size
+= g
->tls_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
9585 /* VxWorks does not support multiple GOTs. It initializes $gp to
9586 __GOTT_BASE__[__GOTT_INDEX__], the value of which is set by the
9588 if (!htab
->is_vxworks
&& s
->size
> MIPS_ELF_GOT_MAX_SIZE (info
))
9590 if (!mips_elf_multi_got (output_bfd
, info
, s
, page_gotno
))
9595 /* Record that all bfds use G. This also has the effect of freeing
9596 the per-bfd GOTs, which we no longer need. */
9597 for (ibfd
= info
->input_bfds
; ibfd
; ibfd
= ibfd
->link
.next
)
9598 if (mips_elf_bfd_got (ibfd
, FALSE
))
9599 mips_elf_replace_bfd_got (ibfd
, g
);
9600 mips_elf_replace_bfd_got (output_bfd
, g
);
9602 /* Set up TLS entries. */
9603 g
->tls_assigned_gotno
= g
->global_gotno
+ g
->local_gotno
;
9606 tga
.value
= MIPS_ELF_GOT_SIZE (output_bfd
);
9607 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, &tga
);
9610 BFD_ASSERT (g
->tls_assigned_gotno
9611 == g
->global_gotno
+ g
->local_gotno
+ g
->tls_gotno
);
9613 /* Each VxWorks GOT entry needs an explicit relocation. */
9614 if (htab
->is_vxworks
&& bfd_link_pic (info
))
9615 g
->relocs
+= g
->global_gotno
+ g
->local_gotno
- htab
->reserved_gotno
;
9617 /* Allocate room for the TLS relocations. */
9619 mips_elf_allocate_dynamic_relocations (dynobj
, info
, g
->relocs
);
9625 /* Estimate the size of the .MIPS.stubs section. */
9628 mips_elf_estimate_stub_size (bfd
*output_bfd
, struct bfd_link_info
*info
)
9630 struct mips_elf_link_hash_table
*htab
;
9631 bfd_size_type dynsymcount
;
9633 htab
= mips_elf_hash_table (info
);
9634 BFD_ASSERT (htab
!= NULL
);
9636 if (htab
->lazy_stub_count
== 0)
9639 /* IRIX rld assumes that a function stub isn't at the end of the .text
9640 section, so add a dummy entry to the end. */
9641 htab
->lazy_stub_count
++;
9643 /* Get a worst-case estimate of the number of dynamic symbols needed.
9644 At this point, dynsymcount does not account for section symbols
9645 and count_section_dynsyms may overestimate the number that will
9647 dynsymcount
= (elf_hash_table (info
)->dynsymcount
9648 + count_section_dynsyms (output_bfd
, info
));
9650 /* Determine the size of one stub entry. There's no disadvantage
9651 from using microMIPS code here, so for the sake of pure-microMIPS
9652 binaries we prefer it whenever there's any microMIPS code in
9653 output produced at all. This has a benefit of stubs being
9654 shorter by 4 bytes each too, unless in the insn32 mode. */
9655 if (!MICROMIPS_P (output_bfd
))
9656 htab
->function_stub_size
= (dynsymcount
> 0x10000
9657 ? MIPS_FUNCTION_STUB_BIG_SIZE
9658 : MIPS_FUNCTION_STUB_NORMAL_SIZE
);
9659 else if (htab
->insn32
)
9660 htab
->function_stub_size
= (dynsymcount
> 0x10000
9661 ? MICROMIPS_INSN32_FUNCTION_STUB_BIG_SIZE
9662 : MICROMIPS_INSN32_FUNCTION_STUB_NORMAL_SIZE
);
9664 htab
->function_stub_size
= (dynsymcount
> 0x10000
9665 ? MICROMIPS_FUNCTION_STUB_BIG_SIZE
9666 : MICROMIPS_FUNCTION_STUB_NORMAL_SIZE
);
9668 htab
->sstubs
->size
= htab
->lazy_stub_count
* htab
->function_stub_size
;
9671 /* A mips_elf_link_hash_traverse callback for which DATA points to a
9672 mips_htab_traverse_info. If H needs a traditional MIPS lazy-binding
9673 stub, allocate an entry in the stubs section. */
9676 mips_elf_allocate_lazy_stub (struct mips_elf_link_hash_entry
*h
, void *data
)
9678 struct mips_htab_traverse_info
*hti
= data
;
9679 struct mips_elf_link_hash_table
*htab
;
9680 struct bfd_link_info
*info
;
9684 output_bfd
= hti
->output_bfd
;
9685 htab
= mips_elf_hash_table (info
);
9686 BFD_ASSERT (htab
!= NULL
);
9688 if (h
->needs_lazy_stub
)
9690 bfd_boolean micromips_p
= MICROMIPS_P (output_bfd
);
9691 unsigned int other
= micromips_p
? STO_MICROMIPS
: 0;
9692 bfd_vma isa_bit
= micromips_p
;
9694 BFD_ASSERT (htab
->root
.dynobj
!= NULL
);
9695 if (h
->root
.plt
.plist
== NULL
)
9696 h
->root
.plt
.plist
= mips_elf_make_plt_record (htab
->sstubs
->owner
);
9697 if (h
->root
.plt
.plist
== NULL
)
9702 h
->root
.root
.u
.def
.section
= htab
->sstubs
;
9703 h
->root
.root
.u
.def
.value
= htab
->sstubs
->size
+ isa_bit
;
9704 h
->root
.plt
.plist
->stub_offset
= htab
->sstubs
->size
;
9705 h
->root
.other
= other
;
9706 htab
->sstubs
->size
+= htab
->function_stub_size
;
9711 /* Allocate offsets in the stubs section to each symbol that needs one.
9712 Set the final size of the .MIPS.stub section. */
9715 mips_elf_lay_out_lazy_stubs (struct bfd_link_info
*info
)
9717 bfd
*output_bfd
= info
->output_bfd
;
9718 bfd_boolean micromips_p
= MICROMIPS_P (output_bfd
);
9719 unsigned int other
= micromips_p
? STO_MICROMIPS
: 0;
9720 bfd_vma isa_bit
= micromips_p
;
9721 struct mips_elf_link_hash_table
*htab
;
9722 struct mips_htab_traverse_info hti
;
9723 struct elf_link_hash_entry
*h
;
9726 htab
= mips_elf_hash_table (info
);
9727 BFD_ASSERT (htab
!= NULL
);
9729 if (htab
->lazy_stub_count
== 0)
9732 htab
->sstubs
->size
= 0;
9734 hti
.output_bfd
= output_bfd
;
9736 mips_elf_link_hash_traverse (htab
, mips_elf_allocate_lazy_stub
, &hti
);
9739 htab
->sstubs
->size
+= htab
->function_stub_size
;
9740 BFD_ASSERT (htab
->sstubs
->size
9741 == htab
->lazy_stub_count
* htab
->function_stub_size
);
9743 dynobj
= elf_hash_table (info
)->dynobj
;
9744 BFD_ASSERT (dynobj
!= NULL
);
9745 h
= _bfd_elf_define_linkage_sym (dynobj
, info
, htab
->sstubs
, "_MIPS_STUBS_");
9748 h
->root
.u
.def
.value
= isa_bit
;
9755 /* A mips_elf_link_hash_traverse callback for which DATA points to a
9756 bfd_link_info. If H uses the address of a PLT entry as the value
9757 of the symbol, then set the entry in the symbol table now. Prefer
9758 a standard MIPS PLT entry. */
9761 mips_elf_set_plt_sym_value (struct mips_elf_link_hash_entry
*h
, void *data
)
9763 struct bfd_link_info
*info
= data
;
9764 bfd_boolean micromips_p
= MICROMIPS_P (info
->output_bfd
);
9765 struct mips_elf_link_hash_table
*htab
;
9770 htab
= mips_elf_hash_table (info
);
9771 BFD_ASSERT (htab
!= NULL
);
9773 if (h
->use_plt_entry
)
9775 BFD_ASSERT (h
->root
.plt
.plist
!= NULL
);
9776 BFD_ASSERT (h
->root
.plt
.plist
->mips_offset
!= MINUS_ONE
9777 || h
->root
.plt
.plist
->comp_offset
!= MINUS_ONE
);
9779 val
= htab
->plt_header_size
;
9780 if (h
->root
.plt
.plist
->mips_offset
!= MINUS_ONE
)
9783 val
+= h
->root
.plt
.plist
->mips_offset
;
9789 val
+= htab
->plt_mips_offset
+ h
->root
.plt
.plist
->comp_offset
;
9790 other
= micromips_p
? STO_MICROMIPS
: STO_MIPS16
;
9793 /* For VxWorks, point at the PLT load stub rather than the lazy
9794 resolution stub; this stub will become the canonical function
9796 if (htab
->is_vxworks
)
9799 h
->root
.root
.u
.def
.section
= htab
->root
.splt
;
9800 h
->root
.root
.u
.def
.value
= val
;
9801 h
->root
.other
= other
;
9807 /* Set the sizes of the dynamic sections. */
9810 _bfd_mips_elf_size_dynamic_sections (bfd
*output_bfd
,
9811 struct bfd_link_info
*info
)
9814 asection
*s
, *sreldyn
;
9815 bfd_boolean reltext
;
9816 struct mips_elf_link_hash_table
*htab
;
9818 htab
= mips_elf_hash_table (info
);
9819 BFD_ASSERT (htab
!= NULL
);
9820 dynobj
= elf_hash_table (info
)->dynobj
;
9821 BFD_ASSERT (dynobj
!= NULL
);
9823 if (elf_hash_table (info
)->dynamic_sections_created
)
9825 /* Set the contents of the .interp section to the interpreter. */
9826 if (bfd_link_executable (info
) && !info
->nointerp
)
9828 s
= bfd_get_linker_section (dynobj
, ".interp");
9829 BFD_ASSERT (s
!= NULL
);
9831 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
9833 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
9836 /* Figure out the size of the PLT header if we know that we
9837 are using it. For the sake of cache alignment always use
9838 a standard header whenever any standard entries are present
9839 even if microMIPS entries are present as well. This also
9840 lets the microMIPS header rely on the value of $v0 only set
9841 by microMIPS entries, for a small size reduction.
9843 Set symbol table entry values for symbols that use the
9844 address of their PLT entry now that we can calculate it.
9846 Also create the _PROCEDURE_LINKAGE_TABLE_ symbol if we
9847 haven't already in _bfd_elf_create_dynamic_sections. */
9848 if (htab
->root
.splt
&& htab
->plt_mips_offset
+ htab
->plt_comp_offset
!= 0)
9850 bfd_boolean micromips_p
= (MICROMIPS_P (output_bfd
)
9851 && !htab
->plt_mips_offset
);
9852 unsigned int other
= micromips_p
? STO_MICROMIPS
: 0;
9853 bfd_vma isa_bit
= micromips_p
;
9854 struct elf_link_hash_entry
*h
;
9857 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
9858 BFD_ASSERT (htab
->root
.sgotplt
->size
== 0);
9859 BFD_ASSERT (htab
->root
.splt
->size
== 0);
9861 if (htab
->is_vxworks
&& bfd_link_pic (info
))
9862 size
= 4 * ARRAY_SIZE (mips_vxworks_shared_plt0_entry
);
9863 else if (htab
->is_vxworks
)
9864 size
= 4 * ARRAY_SIZE (mips_vxworks_exec_plt0_entry
);
9865 else if (ABI_64_P (output_bfd
))
9866 size
= 4 * ARRAY_SIZE (mips_n64_exec_plt0_entry
);
9867 else if (ABI_N32_P (output_bfd
))
9868 size
= 4 * ARRAY_SIZE (mips_n32_exec_plt0_entry
);
9869 else if (!micromips_p
)
9870 size
= 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
);
9871 else if (htab
->insn32
)
9872 size
= 2 * ARRAY_SIZE (micromips_insn32_o32_exec_plt0_entry
);
9874 size
= 2 * ARRAY_SIZE (micromips_o32_exec_plt0_entry
);
9876 htab
->plt_header_is_comp
= micromips_p
;
9877 htab
->plt_header_size
= size
;
9878 htab
->root
.splt
->size
= (size
9879 + htab
->plt_mips_offset
9880 + htab
->plt_comp_offset
);
9881 htab
->root
.sgotplt
->size
= (htab
->plt_got_index
9882 * MIPS_ELF_GOT_SIZE (dynobj
));
9884 mips_elf_link_hash_traverse (htab
, mips_elf_set_plt_sym_value
, info
);
9886 if (htab
->root
.hplt
== NULL
)
9888 h
= _bfd_elf_define_linkage_sym (dynobj
, info
, htab
->root
.splt
,
9889 "_PROCEDURE_LINKAGE_TABLE_");
9890 htab
->root
.hplt
= h
;
9895 h
= htab
->root
.hplt
;
9896 h
->root
.u
.def
.value
= isa_bit
;
9902 /* Allocate space for global sym dynamic relocs. */
9903 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, info
);
9905 mips_elf_estimate_stub_size (output_bfd
, info
);
9907 if (!mips_elf_lay_out_got (output_bfd
, info
))
9910 mips_elf_lay_out_lazy_stubs (info
);
9912 /* The check_relocs and adjust_dynamic_symbol entry points have
9913 determined the sizes of the various dynamic sections. Allocate
9916 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
9920 /* It's OK to base decisions on the section name, because none
9921 of the dynobj section names depend upon the input files. */
9922 name
= bfd_get_section_name (dynobj
, s
);
9924 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
9927 if (CONST_STRNEQ (name
, ".rel"))
9931 const char *outname
;
9934 /* If this relocation section applies to a read only
9935 section, then we probably need a DT_TEXTREL entry.
9936 If the relocation section is .rel(a).dyn, we always
9937 assert a DT_TEXTREL entry rather than testing whether
9938 there exists a relocation to a read only section or
9940 outname
= bfd_get_section_name (output_bfd
,
9942 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
9944 && (target
->flags
& SEC_READONLY
) != 0
9945 && (target
->flags
& SEC_ALLOC
) != 0)
9946 || strcmp (outname
, MIPS_ELF_REL_DYN_NAME (info
)) == 0)
9949 /* We use the reloc_count field as a counter if we need
9950 to copy relocs into the output file. */
9951 if (strcmp (name
, MIPS_ELF_REL_DYN_NAME (info
)) != 0)
9954 /* If combreloc is enabled, elf_link_sort_relocs() will
9955 sort relocations, but in a different way than we do,
9956 and before we're done creating relocations. Also, it
9957 will move them around between input sections'
9958 relocation's contents, so our sorting would be
9959 broken, so don't let it run. */
9960 info
->combreloc
= 0;
9963 else if (bfd_link_executable (info
)
9964 && ! mips_elf_hash_table (info
)->use_rld_obj_head
9965 && CONST_STRNEQ (name
, ".rld_map"))
9967 /* We add a room for __rld_map. It will be filled in by the
9968 rtld to contain a pointer to the _r_debug structure. */
9969 s
->size
+= MIPS_ELF_RLD_MAP_SIZE (output_bfd
);
9971 else if (SGI_COMPAT (output_bfd
)
9972 && CONST_STRNEQ (name
, ".compact_rel"))
9973 s
->size
+= mips_elf_hash_table (info
)->compact_rel_size
;
9974 else if (s
== htab
->root
.splt
)
9976 /* If the last PLT entry has a branch delay slot, allocate
9977 room for an extra nop to fill the delay slot. This is
9978 for CPUs without load interlocking. */
9979 if (! LOAD_INTERLOCKS_P (output_bfd
)
9980 && ! htab
->is_vxworks
&& s
->size
> 0)
9983 else if (! CONST_STRNEQ (name
, ".init")
9984 && s
!= htab
->root
.sgot
9985 && s
!= htab
->root
.sgotplt
9986 && s
!= htab
->sstubs
9987 && s
!= htab
->root
.sdynbss
9988 && s
!= htab
->root
.sdynrelro
)
9990 /* It's not one of our sections, so don't allocate space. */
9996 s
->flags
|= SEC_EXCLUDE
;
10000 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
10003 /* Allocate memory for the section contents. */
10004 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
10005 if (s
->contents
== NULL
)
10007 bfd_set_error (bfd_error_no_memory
);
10012 if (elf_hash_table (info
)->dynamic_sections_created
)
10014 /* Add some entries to the .dynamic section. We fill in the
10015 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
10016 must add the entries now so that we get the correct size for
10017 the .dynamic section. */
10019 /* SGI object has the equivalence of DT_DEBUG in the
10020 DT_MIPS_RLD_MAP entry. This must come first because glibc
10021 only fills in DT_MIPS_RLD_MAP (not DT_DEBUG) and some tools
10022 may only look at the first one they see. */
10023 if (!bfd_link_pic (info
)
10024 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
10027 if (bfd_link_executable (info
)
10028 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP_REL
, 0))
10031 /* The DT_DEBUG entry may be filled in by the dynamic linker and
10032 used by the debugger. */
10033 if (bfd_link_executable (info
)
10034 && !SGI_COMPAT (output_bfd
)
10035 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
10038 if (reltext
&& (SGI_COMPAT (output_bfd
) || htab
->is_vxworks
))
10039 info
->flags
|= DF_TEXTREL
;
10041 if ((info
->flags
& DF_TEXTREL
) != 0)
10043 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
10046 /* Clear the DF_TEXTREL flag. It will be set again if we
10047 write out an actual text relocation; we may not, because
10048 at this point we do not know whether e.g. any .eh_frame
10049 absolute relocations have been converted to PC-relative. */
10050 info
->flags
&= ~DF_TEXTREL
;
10053 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
10056 sreldyn
= mips_elf_rel_dyn_section (info
, FALSE
);
10057 if (htab
->is_vxworks
)
10059 /* VxWorks uses .rela.dyn instead of .rel.dyn. It does not
10060 use any of the DT_MIPS_* tags. */
10061 if (sreldyn
&& sreldyn
->size
> 0)
10063 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELA
, 0))
10066 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELASZ
, 0))
10069 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELAENT
, 0))
10075 if (sreldyn
&& sreldyn
->size
> 0
10076 && !bfd_is_abs_section (sreldyn
->output_section
))
10078 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
10081 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
10084 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
10088 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
10091 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
10094 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
10097 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
10100 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
10103 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
10106 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
10109 if (IRIX_COMPAT (dynobj
) == ict_irix5
10110 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
10113 if (IRIX_COMPAT (dynobj
) == ict_irix6
10114 && (bfd_get_section_by_name
10115 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
10116 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
10119 if (htab
->root
.splt
->size
> 0)
10121 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTREL
, 0))
10124 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_JMPREL
, 0))
10127 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTRELSZ
, 0))
10130 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_PLTGOT
, 0))
10133 if (htab
->is_vxworks
10134 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
10141 /* REL is a relocation in INPUT_BFD that is being copied to OUTPUT_BFD.
10142 Adjust its R_ADDEND field so that it is correct for the output file.
10143 LOCAL_SYMS and LOCAL_SECTIONS are arrays of INPUT_BFD's local symbols
10144 and sections respectively; both use symbol indexes. */
10147 mips_elf_adjust_addend (bfd
*output_bfd
, struct bfd_link_info
*info
,
10148 bfd
*input_bfd
, Elf_Internal_Sym
*local_syms
,
10149 asection
**local_sections
, Elf_Internal_Rela
*rel
)
10151 unsigned int r_type
, r_symndx
;
10152 Elf_Internal_Sym
*sym
;
10155 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
))
10157 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
10158 if (gprel16_reloc_p (r_type
)
10159 || r_type
== R_MIPS_GPREL32
10160 || literal_reloc_p (r_type
))
10162 rel
->r_addend
+= _bfd_get_gp_value (input_bfd
);
10163 rel
->r_addend
-= _bfd_get_gp_value (output_bfd
);
10166 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
10167 sym
= local_syms
+ r_symndx
;
10169 /* Adjust REL's addend to account for section merging. */
10170 if (!bfd_link_relocatable (info
))
10172 sec
= local_sections
[r_symndx
];
10173 _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
10176 /* This would normally be done by the rela_normal code in elflink.c. */
10177 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
10178 rel
->r_addend
+= local_sections
[r_symndx
]->output_offset
;
10182 /* Handle relocations against symbols from removed linkonce sections,
10183 or sections discarded by a linker script. We use this wrapper around
10184 RELOC_AGAINST_DISCARDED_SECTION to handle triplets of compound relocs
10185 on 64-bit ELF targets. In this case for any relocation handled, which
10186 always be the first in a triplet, the remaining two have to be processed
10187 together with the first, even if they are R_MIPS_NONE. It is the symbol
10188 index referred by the first reloc that applies to all the three and the
10189 remaining two never refer to an object symbol. And it is the final
10190 relocation (the last non-null one) that determines the output field of
10191 the whole relocation so retrieve the corresponding howto structure for
10192 the relocatable field to be cleared by RELOC_AGAINST_DISCARDED_SECTION.
10194 Note that RELOC_AGAINST_DISCARDED_SECTION is a macro that uses "continue"
10195 and therefore requires to be pasted in a loop. It also defines a block
10196 and does not protect any of its arguments, hence the extra brackets. */
10199 mips_reloc_against_discarded_section (bfd
*output_bfd
,
10200 struct bfd_link_info
*info
,
10201 bfd
*input_bfd
, asection
*input_section
,
10202 Elf_Internal_Rela
**rel
,
10203 const Elf_Internal_Rela
**relend
,
10204 bfd_boolean rel_reloc
,
10205 reloc_howto_type
*howto
,
10206 bfd_byte
*contents
)
10208 const struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
10209 int count
= bed
->s
->int_rels_per_ext_rel
;
10210 unsigned int r_type
;
10213 for (i
= count
- 1; i
> 0; i
--)
10215 r_type
= ELF_R_TYPE (output_bfd
, (*rel
)[i
].r_info
);
10216 if (r_type
!= R_MIPS_NONE
)
10218 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
, !rel_reloc
);
10224 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
10225 (*rel
), count
, (*relend
),
10226 howto
, i
, contents
);
10231 /* Relocate a MIPS ELF section. */
10234 _bfd_mips_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
10235 bfd
*input_bfd
, asection
*input_section
,
10236 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
10237 Elf_Internal_Sym
*local_syms
,
10238 asection
**local_sections
)
10240 Elf_Internal_Rela
*rel
;
10241 const Elf_Internal_Rela
*relend
;
10242 bfd_vma addend
= 0;
10243 bfd_boolean use_saved_addend_p
= FALSE
;
10245 relend
= relocs
+ input_section
->reloc_count
;
10246 for (rel
= relocs
; rel
< relend
; ++rel
)
10250 reloc_howto_type
*howto
;
10251 bfd_boolean cross_mode_jump_p
= FALSE
;
10252 /* TRUE if the relocation is a RELA relocation, rather than a
10254 bfd_boolean rela_relocation_p
= TRUE
;
10255 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
10257 unsigned long r_symndx
;
10259 Elf_Internal_Shdr
*symtab_hdr
;
10260 struct elf_link_hash_entry
*h
;
10261 bfd_boolean rel_reloc
;
10263 rel_reloc
= (NEWABI_P (input_bfd
)
10264 && mips_elf_rel_relocation_p (input_bfd
, input_section
,
10266 /* Find the relocation howto for this relocation. */
10267 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
, !rel_reloc
);
10269 r_symndx
= ELF_R_SYM (input_bfd
, rel
->r_info
);
10270 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
10271 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
))
10273 sec
= local_sections
[r_symndx
];
10278 unsigned long extsymoff
;
10281 if (!elf_bad_symtab (input_bfd
))
10282 extsymoff
= symtab_hdr
->sh_info
;
10283 h
= elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
10284 while (h
->root
.type
== bfd_link_hash_indirect
10285 || h
->root
.type
== bfd_link_hash_warning
)
10286 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
10289 if (h
->root
.type
== bfd_link_hash_defined
10290 || h
->root
.type
== bfd_link_hash_defweak
)
10291 sec
= h
->root
.u
.def
.section
;
10294 if (sec
!= NULL
&& discarded_section (sec
))
10296 mips_reloc_against_discarded_section (output_bfd
, info
, input_bfd
,
10297 input_section
, &rel
, &relend
,
10298 rel_reloc
, howto
, contents
);
10302 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
10304 /* Some 32-bit code uses R_MIPS_64. In particular, people use
10305 64-bit code, but make sure all their addresses are in the
10306 lowermost or uppermost 32-bit section of the 64-bit address
10307 space. Thus, when they use an R_MIPS_64 they mean what is
10308 usually meant by R_MIPS_32, with the exception that the
10309 stored value is sign-extended to 64 bits. */
10310 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
10312 /* On big-endian systems, we need to lie about the position
10314 if (bfd_big_endian (input_bfd
))
10315 rel
->r_offset
+= 4;
10318 if (!use_saved_addend_p
)
10320 /* If these relocations were originally of the REL variety,
10321 we must pull the addend out of the field that will be
10322 relocated. Otherwise, we simply use the contents of the
10323 RELA relocation. */
10324 if (mips_elf_rel_relocation_p (input_bfd
, input_section
,
10327 rela_relocation_p
= FALSE
;
10328 addend
= mips_elf_read_rel_addend (input_bfd
, rel
,
10330 if (hi16_reloc_p (r_type
)
10331 || (got16_reloc_p (r_type
)
10332 && mips_elf_local_relocation_p (input_bfd
, rel
,
10335 if (!mips_elf_add_lo16_rel_addend (input_bfd
, rel
, relend
,
10336 contents
, &addend
))
10339 name
= h
->root
.root
.string
;
10341 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
10342 local_syms
+ r_symndx
,
10345 /* xgettext:c-format */
10346 (_("%pB: can't find matching LO16 reloc against `%s'"
10347 " for %s at %#" PRIx64
" in section `%pA'"),
10349 howto
->name
, (uint64_t) rel
->r_offset
, input_section
);
10353 addend
<<= howto
->rightshift
;
10356 addend
= rel
->r_addend
;
10357 mips_elf_adjust_addend (output_bfd
, info
, input_bfd
,
10358 local_syms
, local_sections
, rel
);
10361 if (bfd_link_relocatable (info
))
10363 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
10364 && bfd_big_endian (input_bfd
))
10365 rel
->r_offset
-= 4;
10367 if (!rela_relocation_p
&& rel
->r_addend
)
10369 addend
+= rel
->r_addend
;
10370 if (hi16_reloc_p (r_type
) || got16_reloc_p (r_type
))
10371 addend
= mips_elf_high (addend
);
10372 else if (r_type
== R_MIPS_HIGHER
)
10373 addend
= mips_elf_higher (addend
);
10374 else if (r_type
== R_MIPS_HIGHEST
)
10375 addend
= mips_elf_highest (addend
);
10377 addend
>>= howto
->rightshift
;
10379 /* We use the source mask, rather than the destination
10380 mask because the place to which we are writing will be
10381 source of the addend in the final link. */
10382 addend
&= howto
->src_mask
;
10384 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
10385 /* See the comment above about using R_MIPS_64 in the 32-bit
10386 ABI. Here, we need to update the addend. It would be
10387 possible to get away with just using the R_MIPS_32 reloc
10388 but for endianness. */
10394 if (addend
& ((bfd_vma
) 1 << 31))
10396 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
10403 /* If we don't know that we have a 64-bit type,
10404 do two separate stores. */
10405 if (bfd_big_endian (input_bfd
))
10407 /* Store the sign-bits (which are most significant)
10409 low_bits
= sign_bits
;
10410 high_bits
= addend
;
10415 high_bits
= sign_bits
;
10417 bfd_put_32 (input_bfd
, low_bits
,
10418 contents
+ rel
->r_offset
);
10419 bfd_put_32 (input_bfd
, high_bits
,
10420 contents
+ rel
->r_offset
+ 4);
10424 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
10425 input_bfd
, input_section
,
10430 /* Go on to the next relocation. */
10434 /* In the N32 and 64-bit ABIs there may be multiple consecutive
10435 relocations for the same offset. In that case we are
10436 supposed to treat the output of each relocation as the addend
10438 if (rel
+ 1 < relend
10439 && rel
->r_offset
== rel
[1].r_offset
10440 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
10441 use_saved_addend_p
= TRUE
;
10443 use_saved_addend_p
= FALSE
;
10445 /* Figure out what value we are supposed to relocate. */
10446 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
10447 input_section
, contents
,
10448 info
, rel
, addend
, howto
,
10449 local_syms
, local_sections
,
10450 &value
, &name
, &cross_mode_jump_p
,
10451 use_saved_addend_p
))
10453 case bfd_reloc_continue
:
10454 /* There's nothing to do. */
10457 case bfd_reloc_undefined
:
10458 /* mips_elf_calculate_relocation already called the
10459 undefined_symbol callback. There's no real point in
10460 trying to perform the relocation at this point, so we
10461 just skip ahead to the next relocation. */
10464 case bfd_reloc_notsupported
:
10465 msg
= _("internal error: unsupported relocation error");
10466 info
->callbacks
->warning
10467 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
10470 case bfd_reloc_overflow
:
10471 if (use_saved_addend_p
)
10472 /* Ignore overflow until we reach the last relocation for
10473 a given location. */
10477 struct mips_elf_link_hash_table
*htab
;
10479 htab
= mips_elf_hash_table (info
);
10480 BFD_ASSERT (htab
!= NULL
);
10481 BFD_ASSERT (name
!= NULL
);
10482 if (!htab
->small_data_overflow_reported
10483 && (gprel16_reloc_p (howto
->type
)
10484 || literal_reloc_p (howto
->type
)))
10486 msg
= _("small-data section exceeds 64KB;"
10487 " lower small-data size limit (see option -G)");
10489 htab
->small_data_overflow_reported
= TRUE
;
10490 (*info
->callbacks
->einfo
) ("%P: %s\n", msg
);
10492 (*info
->callbacks
->reloc_overflow
)
10493 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
10494 input_bfd
, input_section
, rel
->r_offset
);
10501 case bfd_reloc_outofrange
:
10503 if (jal_reloc_p (howto
->type
))
10504 msg
= (cross_mode_jump_p
10505 ? _("cannot convert a jump to JALX "
10506 "for a non-word-aligned address")
10507 : (howto
->type
== R_MIPS16_26
10508 ? _("jump to a non-word-aligned address")
10509 : _("jump to a non-instruction-aligned address")));
10510 else if (b_reloc_p (howto
->type
))
10511 msg
= (cross_mode_jump_p
10512 ? _("cannot convert a branch to JALX "
10513 "for a non-word-aligned address")
10514 : _("branch to a non-instruction-aligned address"));
10515 else if (aligned_pcrel_reloc_p (howto
->type
))
10516 msg
= _("PC-relative load from unaligned address");
10519 info
->callbacks
->einfo
10520 ("%X%H: %s\n", input_bfd
, input_section
, rel
->r_offset
, msg
);
10523 /* Fall through. */
10530 /* If we've got another relocation for the address, keep going
10531 until we reach the last one. */
10532 if (use_saved_addend_p
)
10538 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
10539 /* See the comment above about using R_MIPS_64 in the 32-bit
10540 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
10541 that calculated the right value. Now, however, we
10542 sign-extend the 32-bit result to 64-bits, and store it as a
10543 64-bit value. We are especially generous here in that we
10544 go to extreme lengths to support this usage on systems with
10545 only a 32-bit VMA. */
10551 if (value
& ((bfd_vma
) 1 << 31))
10553 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
10560 /* If we don't know that we have a 64-bit type,
10561 do two separate stores. */
10562 if (bfd_big_endian (input_bfd
))
10564 /* Undo what we did above. */
10565 rel
->r_offset
-= 4;
10566 /* Store the sign-bits (which are most significant)
10568 low_bits
= sign_bits
;
10574 high_bits
= sign_bits
;
10576 bfd_put_32 (input_bfd
, low_bits
,
10577 contents
+ rel
->r_offset
);
10578 bfd_put_32 (input_bfd
, high_bits
,
10579 contents
+ rel
->r_offset
+ 4);
10583 /* Actually perform the relocation. */
10584 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
10585 input_bfd
, input_section
,
10586 contents
, cross_mode_jump_p
))
10593 /* A function that iterates over each entry in la25_stubs and fills
10594 in the code for each one. DATA points to a mips_htab_traverse_info. */
10597 mips_elf_create_la25_stub (void **slot
, void *data
)
10599 struct mips_htab_traverse_info
*hti
;
10600 struct mips_elf_link_hash_table
*htab
;
10601 struct mips_elf_la25_stub
*stub
;
10604 bfd_vma offset
, target
, target_high
, target_low
;
10606 stub
= (struct mips_elf_la25_stub
*) *slot
;
10607 hti
= (struct mips_htab_traverse_info
*) data
;
10608 htab
= mips_elf_hash_table (hti
->info
);
10609 BFD_ASSERT (htab
!= NULL
);
10611 /* Create the section contents, if we haven't already. */
10612 s
= stub
->stub_section
;
10616 loc
= bfd_malloc (s
->size
);
10625 /* Work out where in the section this stub should go. */
10626 offset
= stub
->offset
;
10628 /* Work out the target address. */
10629 target
= mips_elf_get_la25_target (stub
, &s
);
10630 target
+= s
->output_section
->vma
+ s
->output_offset
;
10632 target_high
= ((target
+ 0x8000) >> 16) & 0xffff;
10633 target_low
= (target
& 0xffff);
10635 if (stub
->stub_section
!= htab
->strampoline
)
10637 /* This is a simple LUI/ADDIU stub. Zero out the beginning
10638 of the section and write the two instructions at the end. */
10639 memset (loc
, 0, offset
);
10641 if (ELF_ST_IS_MICROMIPS (stub
->h
->root
.other
))
10643 bfd_put_micromips_32 (hti
->output_bfd
,
10644 LA25_LUI_MICROMIPS (target_high
),
10646 bfd_put_micromips_32 (hti
->output_bfd
,
10647 LA25_ADDIU_MICROMIPS (target_low
),
10652 bfd_put_32 (hti
->output_bfd
, LA25_LUI (target_high
), loc
);
10653 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 4);
10658 /* This is trampoline. */
10660 if (ELF_ST_IS_MICROMIPS (stub
->h
->root
.other
))
10662 bfd_put_micromips_32 (hti
->output_bfd
,
10663 LA25_LUI_MICROMIPS (target_high
), loc
);
10664 bfd_put_micromips_32 (hti
->output_bfd
,
10665 LA25_J_MICROMIPS (target
), loc
+ 4);
10666 bfd_put_micromips_32 (hti
->output_bfd
,
10667 LA25_ADDIU_MICROMIPS (target_low
), loc
+ 8);
10668 bfd_put_32 (hti
->output_bfd
, 0, loc
+ 12);
10672 bfd_put_32 (hti
->output_bfd
, LA25_LUI (target_high
), loc
);
10673 bfd_put_32 (hti
->output_bfd
, LA25_J (target
), loc
+ 4);
10674 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 8);
10675 bfd_put_32 (hti
->output_bfd
, 0, loc
+ 12);
10681 /* If NAME is one of the special IRIX6 symbols defined by the linker,
10682 adjust it appropriately now. */
10685 mips_elf_irix6_finish_dynamic_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
10686 const char *name
, Elf_Internal_Sym
*sym
)
10688 /* The linker script takes care of providing names and values for
10689 these, but we must place them into the right sections. */
10690 static const char* const text_section_symbols
[] = {
10693 "__dso_displacement",
10695 "__program_header_table",
10699 static const char* const data_section_symbols
[] = {
10707 const char* const *p
;
10710 for (i
= 0; i
< 2; ++i
)
10711 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
10714 if (strcmp (*p
, name
) == 0)
10716 /* All of these symbols are given type STT_SECTION by the
10718 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
10719 sym
->st_other
= STO_PROTECTED
;
10721 /* The IRIX linker puts these symbols in special sections. */
10723 sym
->st_shndx
= SHN_MIPS_TEXT
;
10725 sym
->st_shndx
= SHN_MIPS_DATA
;
10731 /* Finish up dynamic symbol handling. We set the contents of various
10732 dynamic sections here. */
10735 _bfd_mips_elf_finish_dynamic_symbol (bfd
*output_bfd
,
10736 struct bfd_link_info
*info
,
10737 struct elf_link_hash_entry
*h
,
10738 Elf_Internal_Sym
*sym
)
10742 struct mips_got_info
*g
, *gg
;
10745 struct mips_elf_link_hash_table
*htab
;
10746 struct mips_elf_link_hash_entry
*hmips
;
10748 htab
= mips_elf_hash_table (info
);
10749 BFD_ASSERT (htab
!= NULL
);
10750 dynobj
= elf_hash_table (info
)->dynobj
;
10751 hmips
= (struct mips_elf_link_hash_entry
*) h
;
10753 BFD_ASSERT (!htab
->is_vxworks
);
10755 if (h
->plt
.plist
!= NULL
10756 && (h
->plt
.plist
->mips_offset
!= MINUS_ONE
10757 || h
->plt
.plist
->comp_offset
!= MINUS_ONE
))
10759 /* We've decided to create a PLT entry for this symbol. */
10761 bfd_vma header_address
, got_address
;
10762 bfd_vma got_address_high
, got_address_low
, load
;
10766 got_index
= h
->plt
.plist
->gotplt_index
;
10768 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10769 BFD_ASSERT (h
->dynindx
!= -1);
10770 BFD_ASSERT (htab
->root
.splt
!= NULL
);
10771 BFD_ASSERT (got_index
!= MINUS_ONE
);
10772 BFD_ASSERT (!h
->def_regular
);
10774 /* Calculate the address of the PLT header. */
10775 isa_bit
= htab
->plt_header_is_comp
;
10776 header_address
= (htab
->root
.splt
->output_section
->vma
10777 + htab
->root
.splt
->output_offset
+ isa_bit
);
10779 /* Calculate the address of the .got.plt entry. */
10780 got_address
= (htab
->root
.sgotplt
->output_section
->vma
10781 + htab
->root
.sgotplt
->output_offset
10782 + got_index
* MIPS_ELF_GOT_SIZE (dynobj
));
10784 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
10785 got_address_low
= got_address
& 0xffff;
10787 /* The PLT sequence is not safe for N64 if .got.plt entry's address
10788 cannot be loaded in two instructions. */
10789 if (ABI_64_P (output_bfd
)
10790 && ((got_address
+ 0x80008000) & ~(bfd_vma
) 0xffffffff) != 0)
10793 /* xgettext:c-format */
10794 (_("%pB: `%pA' entry VMA of %#" PRIx64
" outside the 32-bit range "
10795 "supported; consider using `-Ttext-segment=...'"),
10797 htab
->root
.sgotplt
->output_section
,
10798 (int64_t) got_address
);
10799 bfd_set_error (bfd_error_no_error
);
10803 /* Initially point the .got.plt entry at the PLT header. */
10804 loc
= (htab
->root
.sgotplt
->contents
10805 + got_index
* MIPS_ELF_GOT_SIZE (dynobj
));
10806 if (ABI_64_P (output_bfd
))
10807 bfd_put_64 (output_bfd
, header_address
, loc
);
10809 bfd_put_32 (output_bfd
, header_address
, loc
);
10811 /* Now handle the PLT itself. First the standard entry (the order
10812 does not matter, we just have to pick one). */
10813 if (h
->plt
.plist
->mips_offset
!= MINUS_ONE
)
10815 const bfd_vma
*plt_entry
;
10816 bfd_vma plt_offset
;
10818 plt_offset
= htab
->plt_header_size
+ h
->plt
.plist
->mips_offset
;
10820 BFD_ASSERT (plt_offset
<= htab
->root
.splt
->size
);
10822 /* Find out where the .plt entry should go. */
10823 loc
= htab
->root
.splt
->contents
+ plt_offset
;
10825 /* Pick the load opcode. */
10826 load
= MIPS_ELF_LOAD_WORD (output_bfd
);
10828 /* Fill in the PLT entry itself. */
10830 if (MIPSR6_P (output_bfd
))
10831 plt_entry
= mipsr6_exec_plt_entry
;
10833 plt_entry
= mips_exec_plt_entry
;
10834 bfd_put_32 (output_bfd
, plt_entry
[0] | got_address_high
, loc
);
10835 bfd_put_32 (output_bfd
, plt_entry
[1] | got_address_low
| load
,
10838 if (! LOAD_INTERLOCKS_P (output_bfd
))
10840 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_low
, loc
+ 8);
10841 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
10845 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 8);
10846 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_low
,
10851 /* Now the compressed entry. They come after any standard ones. */
10852 if (h
->plt
.plist
->comp_offset
!= MINUS_ONE
)
10854 bfd_vma plt_offset
;
10856 plt_offset
= (htab
->plt_header_size
+ htab
->plt_mips_offset
10857 + h
->plt
.plist
->comp_offset
);
10859 BFD_ASSERT (plt_offset
<= htab
->root
.splt
->size
);
10861 /* Find out where the .plt entry should go. */
10862 loc
= htab
->root
.splt
->contents
+ plt_offset
;
10864 /* Fill in the PLT entry itself. */
10865 if (!MICROMIPS_P (output_bfd
))
10867 const bfd_vma
*plt_entry
= mips16_o32_exec_plt_entry
;
10869 bfd_put_16 (output_bfd
, plt_entry
[0], loc
);
10870 bfd_put_16 (output_bfd
, plt_entry
[1], loc
+ 2);
10871 bfd_put_16 (output_bfd
, plt_entry
[2], loc
+ 4);
10872 bfd_put_16 (output_bfd
, plt_entry
[3], loc
+ 6);
10873 bfd_put_16 (output_bfd
, plt_entry
[4], loc
+ 8);
10874 bfd_put_16 (output_bfd
, plt_entry
[5], loc
+ 10);
10875 bfd_put_32 (output_bfd
, got_address
, loc
+ 12);
10877 else if (htab
->insn32
)
10879 const bfd_vma
*plt_entry
= micromips_insn32_o32_exec_plt_entry
;
10881 bfd_put_16 (output_bfd
, plt_entry
[0], loc
);
10882 bfd_put_16 (output_bfd
, got_address_high
, loc
+ 2);
10883 bfd_put_16 (output_bfd
, plt_entry
[2], loc
+ 4);
10884 bfd_put_16 (output_bfd
, got_address_low
, loc
+ 6);
10885 bfd_put_16 (output_bfd
, plt_entry
[4], loc
+ 8);
10886 bfd_put_16 (output_bfd
, plt_entry
[5], loc
+ 10);
10887 bfd_put_16 (output_bfd
, plt_entry
[6], loc
+ 12);
10888 bfd_put_16 (output_bfd
, got_address_low
, loc
+ 14);
10892 const bfd_vma
*plt_entry
= micromips_o32_exec_plt_entry
;
10893 bfd_signed_vma gotpc_offset
;
10894 bfd_vma loc_address
;
10896 BFD_ASSERT (got_address
% 4 == 0);
10898 loc_address
= (htab
->root
.splt
->output_section
->vma
10899 + htab
->root
.splt
->output_offset
+ plt_offset
);
10900 gotpc_offset
= got_address
- ((loc_address
| 3) ^ 3);
10902 /* ADDIUPC has a span of +/-16MB, check we're in range. */
10903 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
10906 /* xgettext:c-format */
10907 (_("%pB: `%pA' offset of %" PRId64
" from `%pA' "
10908 "beyond the range of ADDIUPC"),
10910 htab
->root
.sgotplt
->output_section
,
10911 (int64_t) gotpc_offset
,
10912 htab
->root
.splt
->output_section
);
10913 bfd_set_error (bfd_error_no_error
);
10916 bfd_put_16 (output_bfd
,
10917 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f), loc
);
10918 bfd_put_16 (output_bfd
, (gotpc_offset
>> 2) & 0xffff, loc
+ 2);
10919 bfd_put_16 (output_bfd
, plt_entry
[2], loc
+ 4);
10920 bfd_put_16 (output_bfd
, plt_entry
[3], loc
+ 6);
10921 bfd_put_16 (output_bfd
, plt_entry
[4], loc
+ 8);
10922 bfd_put_16 (output_bfd
, plt_entry
[5], loc
+ 10);
10926 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
10927 mips_elf_output_dynamic_relocation (output_bfd
, htab
->root
.srelplt
,
10928 got_index
- 2, h
->dynindx
,
10929 R_MIPS_JUMP_SLOT
, got_address
);
10931 /* We distinguish between PLT entries and lazy-binding stubs by
10932 giving the former an st_other value of STO_MIPS_PLT. Set the
10933 flag and leave the value if there are any relocations in the
10934 binary where pointer equality matters. */
10935 sym
->st_shndx
= SHN_UNDEF
;
10936 if (h
->pointer_equality_needed
)
10937 sym
->st_other
= ELF_ST_SET_MIPS_PLT (sym
->st_other
);
10945 if (h
->plt
.plist
!= NULL
&& h
->plt
.plist
->stub_offset
!= MINUS_ONE
)
10947 /* We've decided to create a lazy-binding stub. */
10948 bfd_boolean micromips_p
= MICROMIPS_P (output_bfd
);
10949 unsigned int other
= micromips_p
? STO_MICROMIPS
: 0;
10950 bfd_vma stub_size
= htab
->function_stub_size
;
10951 bfd_byte stub
[MIPS_FUNCTION_STUB_BIG_SIZE
];
10952 bfd_vma isa_bit
= micromips_p
;
10953 bfd_vma stub_big_size
;
10956 stub_big_size
= MIPS_FUNCTION_STUB_BIG_SIZE
;
10957 else if (htab
->insn32
)
10958 stub_big_size
= MICROMIPS_INSN32_FUNCTION_STUB_BIG_SIZE
;
10960 stub_big_size
= MICROMIPS_FUNCTION_STUB_BIG_SIZE
;
10962 /* This symbol has a stub. Set it up. */
10964 BFD_ASSERT (h
->dynindx
!= -1);
10966 BFD_ASSERT (stub_size
== stub_big_size
|| h
->dynindx
<= 0xffff);
10968 /* Values up to 2^31 - 1 are allowed. Larger values would cause
10969 sign extension at runtime in the stub, resulting in a negative
10971 if (h
->dynindx
& ~0x7fffffff)
10974 /* Fill the stub. */
10978 bfd_put_micromips_32 (output_bfd
, STUB_LW_MICROMIPS (output_bfd
),
10983 bfd_put_micromips_32 (output_bfd
,
10984 STUB_MOVE32_MICROMIPS
, stub
+ idx
);
10989 bfd_put_16 (output_bfd
, STUB_MOVE_MICROMIPS
, stub
+ idx
);
10992 if (stub_size
== stub_big_size
)
10994 long dynindx_hi
= (h
->dynindx
>> 16) & 0x7fff;
10996 bfd_put_micromips_32 (output_bfd
,
10997 STUB_LUI_MICROMIPS (dynindx_hi
),
11003 bfd_put_micromips_32 (output_bfd
, STUB_JALR32_MICROMIPS
,
11009 bfd_put_16 (output_bfd
, STUB_JALR_MICROMIPS
, stub
+ idx
);
11013 /* If a large stub is not required and sign extension is not a
11014 problem, then use legacy code in the stub. */
11015 if (stub_size
== stub_big_size
)
11016 bfd_put_micromips_32 (output_bfd
,
11017 STUB_ORI_MICROMIPS (h
->dynindx
& 0xffff),
11019 else if (h
->dynindx
& ~0x7fff)
11020 bfd_put_micromips_32 (output_bfd
,
11021 STUB_LI16U_MICROMIPS (h
->dynindx
& 0xffff),
11024 bfd_put_micromips_32 (output_bfd
,
11025 STUB_LI16S_MICROMIPS (output_bfd
,
11032 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
+ idx
);
11034 bfd_put_32 (output_bfd
, STUB_MOVE
, stub
+ idx
);
11036 if (stub_size
== stub_big_size
)
11038 bfd_put_32 (output_bfd
, STUB_LUI ((h
->dynindx
>> 16) & 0x7fff),
11042 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ idx
);
11045 /* If a large stub is not required and sign extension is not a
11046 problem, then use legacy code in the stub. */
11047 if (stub_size
== stub_big_size
)
11048 bfd_put_32 (output_bfd
, STUB_ORI (h
->dynindx
& 0xffff),
11050 else if (h
->dynindx
& ~0x7fff)
11051 bfd_put_32 (output_bfd
, STUB_LI16U (h
->dynindx
& 0xffff),
11054 bfd_put_32 (output_bfd
, STUB_LI16S (output_bfd
, h
->dynindx
),
11058 BFD_ASSERT (h
->plt
.plist
->stub_offset
<= htab
->sstubs
->size
);
11059 memcpy (htab
->sstubs
->contents
+ h
->plt
.plist
->stub_offset
,
11062 /* Mark the symbol as undefined. stub_offset != -1 occurs
11063 only for the referenced symbol. */
11064 sym
->st_shndx
= SHN_UNDEF
;
11066 /* The run-time linker uses the st_value field of the symbol
11067 to reset the global offset table entry for this external
11068 to its stub address when unlinking a shared object. */
11069 sym
->st_value
= (htab
->sstubs
->output_section
->vma
11070 + htab
->sstubs
->output_offset
11071 + h
->plt
.plist
->stub_offset
11073 sym
->st_other
= other
;
11076 /* If we have a MIPS16 function with a stub, the dynamic symbol must
11077 refer to the stub, since only the stub uses the standard calling
11079 if (h
->dynindx
!= -1 && hmips
->fn_stub
!= NULL
)
11081 BFD_ASSERT (hmips
->need_fn_stub
);
11082 sym
->st_value
= (hmips
->fn_stub
->output_section
->vma
11083 + hmips
->fn_stub
->output_offset
);
11084 sym
->st_size
= hmips
->fn_stub
->size
;
11085 sym
->st_other
= ELF_ST_VISIBILITY (sym
->st_other
);
11088 BFD_ASSERT (h
->dynindx
!= -1
11089 || h
->forced_local
);
11091 sgot
= htab
->root
.sgot
;
11092 g
= htab
->got_info
;
11093 BFD_ASSERT (g
!= NULL
);
11095 /* Run through the global symbol table, creating GOT entries for all
11096 the symbols that need them. */
11097 if (hmips
->global_got_area
!= GGA_NONE
)
11102 value
= sym
->st_value
;
11103 offset
= mips_elf_primary_global_got_index (output_bfd
, info
, h
);
11104 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
11107 if (hmips
->global_got_area
!= GGA_NONE
&& g
->next
)
11109 struct mips_got_entry e
, *p
;
11115 e
.abfd
= output_bfd
;
11118 e
.tls_type
= GOT_TLS_NONE
;
11120 for (g
= g
->next
; g
->next
!= gg
; g
= g
->next
)
11123 && (p
= (struct mips_got_entry
*) htab_find (g
->got_entries
,
11126 offset
= p
->gotidx
;
11127 BFD_ASSERT (offset
> 0 && offset
< htab
->root
.sgot
->size
);
11128 if (bfd_link_pic (info
)
11129 || (elf_hash_table (info
)->dynamic_sections_created
11131 && p
->d
.h
->root
.def_dynamic
11132 && !p
->d
.h
->root
.def_regular
))
11134 /* Create an R_MIPS_REL32 relocation for this entry. Due to
11135 the various compatibility problems, it's easier to mock
11136 up an R_MIPS_32 or R_MIPS_64 relocation and leave
11137 mips_elf_create_dynamic_relocation to calculate the
11138 appropriate addend. */
11139 Elf_Internal_Rela rel
[3];
11141 memset (rel
, 0, sizeof (rel
));
11142 if (ABI_64_P (output_bfd
))
11143 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_64
);
11145 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_32
);
11146 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
11149 if (! (mips_elf_create_dynamic_relocation
11150 (output_bfd
, info
, rel
,
11151 e
.d
.h
, NULL
, sym
->st_value
, &entry
, sgot
)))
11155 entry
= sym
->st_value
;
11156 MIPS_ELF_PUT_WORD (output_bfd
, entry
, sgot
->contents
+ offset
);
11161 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
11162 name
= h
->root
.root
.string
;
11163 if (h
== elf_hash_table (info
)->hdynamic
11164 || h
== elf_hash_table (info
)->hgot
)
11165 sym
->st_shndx
= SHN_ABS
;
11166 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
11167 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
11169 sym
->st_shndx
= SHN_ABS
;
11170 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
11173 else if (SGI_COMPAT (output_bfd
))
11175 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
11176 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
11178 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
11179 sym
->st_other
= STO_PROTECTED
;
11181 sym
->st_shndx
= SHN_MIPS_DATA
;
11183 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
11185 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
11186 sym
->st_other
= STO_PROTECTED
;
11187 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
11188 sym
->st_shndx
= SHN_ABS
;
11190 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
11192 if (h
->type
== STT_FUNC
)
11193 sym
->st_shndx
= SHN_MIPS_TEXT
;
11194 else if (h
->type
== STT_OBJECT
)
11195 sym
->st_shndx
= SHN_MIPS_DATA
;
11199 /* Emit a copy reloc, if needed. */
11205 BFD_ASSERT (h
->dynindx
!= -1);
11206 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
11208 s
= mips_elf_rel_dyn_section (info
, FALSE
);
11209 symval
= (h
->root
.u
.def
.section
->output_section
->vma
11210 + h
->root
.u
.def
.section
->output_offset
11211 + h
->root
.u
.def
.value
);
11212 mips_elf_output_dynamic_relocation (output_bfd
, s
, s
->reloc_count
++,
11213 h
->dynindx
, R_MIPS_COPY
, symval
);
11216 /* Handle the IRIX6-specific symbols. */
11217 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
11218 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
11220 /* Keep dynamic compressed symbols odd. This allows the dynamic linker
11221 to treat compressed symbols like any other. */
11222 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
11224 BFD_ASSERT (sym
->st_value
& 1);
11225 sym
->st_other
-= STO_MIPS16
;
11227 else if (ELF_ST_IS_MICROMIPS (sym
->st_other
))
11229 BFD_ASSERT (sym
->st_value
& 1);
11230 sym
->st_other
-= STO_MICROMIPS
;
11236 /* Likewise, for VxWorks. */
11239 _bfd_mips_vxworks_finish_dynamic_symbol (bfd
*output_bfd
,
11240 struct bfd_link_info
*info
,
11241 struct elf_link_hash_entry
*h
,
11242 Elf_Internal_Sym
*sym
)
11246 struct mips_got_info
*g
;
11247 struct mips_elf_link_hash_table
*htab
;
11248 struct mips_elf_link_hash_entry
*hmips
;
11250 htab
= mips_elf_hash_table (info
);
11251 BFD_ASSERT (htab
!= NULL
);
11252 dynobj
= elf_hash_table (info
)->dynobj
;
11253 hmips
= (struct mips_elf_link_hash_entry
*) h
;
11255 if (h
->plt
.plist
!= NULL
&& h
->plt
.plist
->mips_offset
!= MINUS_ONE
)
11258 bfd_vma plt_address
, got_address
, got_offset
, branch_offset
;
11259 Elf_Internal_Rela rel
;
11260 static const bfd_vma
*plt_entry
;
11261 bfd_vma gotplt_index
;
11262 bfd_vma plt_offset
;
11264 plt_offset
= htab
->plt_header_size
+ h
->plt
.plist
->mips_offset
;
11265 gotplt_index
= h
->plt
.plist
->gotplt_index
;
11267 BFD_ASSERT (h
->dynindx
!= -1);
11268 BFD_ASSERT (htab
->root
.splt
!= NULL
);
11269 BFD_ASSERT (gotplt_index
!= MINUS_ONE
);
11270 BFD_ASSERT (plt_offset
<= htab
->root
.splt
->size
);
11272 /* Calculate the address of the .plt entry. */
11273 plt_address
= (htab
->root
.splt
->output_section
->vma
11274 + htab
->root
.splt
->output_offset
11277 /* Calculate the address of the .got.plt entry. */
11278 got_address
= (htab
->root
.sgotplt
->output_section
->vma
11279 + htab
->root
.sgotplt
->output_offset
11280 + gotplt_index
* MIPS_ELF_GOT_SIZE (output_bfd
));
11282 /* Calculate the offset of the .got.plt entry from
11283 _GLOBAL_OFFSET_TABLE_. */
11284 got_offset
= mips_elf_gotplt_index (info
, h
);
11286 /* Calculate the offset for the branch at the start of the PLT
11287 entry. The branch jumps to the beginning of .plt. */
11288 branch_offset
= -(plt_offset
/ 4 + 1) & 0xffff;
11290 /* Fill in the initial value of the .got.plt entry. */
11291 bfd_put_32 (output_bfd
, plt_address
,
11292 (htab
->root
.sgotplt
->contents
11293 + gotplt_index
* MIPS_ELF_GOT_SIZE (output_bfd
)));
11295 /* Find out where the .plt entry should go. */
11296 loc
= htab
->root
.splt
->contents
+ plt_offset
;
11298 if (bfd_link_pic (info
))
11300 plt_entry
= mips_vxworks_shared_plt_entry
;
11301 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
11302 bfd_put_32 (output_bfd
, plt_entry
[1] | gotplt_index
, loc
+ 4);
11306 bfd_vma got_address_high
, got_address_low
;
11308 plt_entry
= mips_vxworks_exec_plt_entry
;
11309 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
11310 got_address_low
= got_address
& 0xffff;
11312 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
11313 bfd_put_32 (output_bfd
, plt_entry
[1] | gotplt_index
, loc
+ 4);
11314 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_high
, loc
+ 8);
11315 bfd_put_32 (output_bfd
, plt_entry
[3] | got_address_low
, loc
+ 12);
11316 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
11317 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
11318 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
11319 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
11321 loc
= (htab
->srelplt2
->contents
11322 + (gotplt_index
* 3 + 2) * sizeof (Elf32_External_Rela
));
11324 /* Emit a relocation for the .got.plt entry. */
11325 rel
.r_offset
= got_address
;
11326 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
11327 rel
.r_addend
= plt_offset
;
11328 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11330 /* Emit a relocation for the lui of %hi(<.got.plt slot>). */
11331 loc
+= sizeof (Elf32_External_Rela
);
11332 rel
.r_offset
= plt_address
+ 8;
11333 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
11334 rel
.r_addend
= got_offset
;
11335 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11337 /* Emit a relocation for the addiu of %lo(<.got.plt slot>). */
11338 loc
+= sizeof (Elf32_External_Rela
);
11340 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
11341 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11344 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
11345 loc
= (htab
->root
.srelplt
->contents
11346 + gotplt_index
* sizeof (Elf32_External_Rela
));
11347 rel
.r_offset
= got_address
;
11348 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_JUMP_SLOT
);
11350 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11352 if (!h
->def_regular
)
11353 sym
->st_shndx
= SHN_UNDEF
;
11356 BFD_ASSERT (h
->dynindx
!= -1 || h
->forced_local
);
11358 sgot
= htab
->root
.sgot
;
11359 g
= htab
->got_info
;
11360 BFD_ASSERT (g
!= NULL
);
11362 /* See if this symbol has an entry in the GOT. */
11363 if (hmips
->global_got_area
!= GGA_NONE
)
11366 Elf_Internal_Rela outrel
;
11370 /* Install the symbol value in the GOT. */
11371 offset
= mips_elf_primary_global_got_index (output_bfd
, info
, h
);
11372 MIPS_ELF_PUT_WORD (output_bfd
, sym
->st_value
, sgot
->contents
+ offset
);
11374 /* Add a dynamic relocation for it. */
11375 s
= mips_elf_rel_dyn_section (info
, FALSE
);
11376 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
11377 outrel
.r_offset
= (sgot
->output_section
->vma
11378 + sgot
->output_offset
11380 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_32
);
11381 outrel
.r_addend
= 0;
11382 bfd_elf32_swap_reloca_out (dynobj
, &outrel
, loc
);
11385 /* Emit a copy reloc, if needed. */
11388 Elf_Internal_Rela rel
;
11392 BFD_ASSERT (h
->dynindx
!= -1);
11394 rel
.r_offset
= (h
->root
.u
.def
.section
->output_section
->vma
11395 + h
->root
.u
.def
.section
->output_offset
11396 + h
->root
.u
.def
.value
);
11397 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_COPY
);
11399 if (h
->root
.u
.def
.section
== htab
->root
.sdynrelro
)
11400 srel
= htab
->root
.sreldynrelro
;
11402 srel
= htab
->root
.srelbss
;
11403 loc
= srel
->contents
+ srel
->reloc_count
* sizeof (Elf32_External_Rela
);
11404 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11405 ++srel
->reloc_count
;
11408 /* If this is a mips16/microMIPS symbol, force the value to be even. */
11409 if (ELF_ST_IS_COMPRESSED (sym
->st_other
))
11410 sym
->st_value
&= ~1;
11415 /* Write out a plt0 entry to the beginning of .plt. */
11418 mips_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
11421 bfd_vma gotplt_value
, gotplt_value_high
, gotplt_value_low
;
11422 static const bfd_vma
*plt_entry
;
11423 struct mips_elf_link_hash_table
*htab
;
11425 htab
= mips_elf_hash_table (info
);
11426 BFD_ASSERT (htab
!= NULL
);
11428 if (ABI_64_P (output_bfd
))
11429 plt_entry
= mips_n64_exec_plt0_entry
;
11430 else if (ABI_N32_P (output_bfd
))
11431 plt_entry
= mips_n32_exec_plt0_entry
;
11432 else if (!htab
->plt_header_is_comp
)
11433 plt_entry
= mips_o32_exec_plt0_entry
;
11434 else if (htab
->insn32
)
11435 plt_entry
= micromips_insn32_o32_exec_plt0_entry
;
11437 plt_entry
= micromips_o32_exec_plt0_entry
;
11439 /* Calculate the value of .got.plt. */
11440 gotplt_value
= (htab
->root
.sgotplt
->output_section
->vma
11441 + htab
->root
.sgotplt
->output_offset
);
11442 gotplt_value_high
= ((gotplt_value
+ 0x8000) >> 16) & 0xffff;
11443 gotplt_value_low
= gotplt_value
& 0xffff;
11445 /* The PLT sequence is not safe for N64 if .got.plt's address can
11446 not be loaded in two instructions. */
11447 if (ABI_64_P (output_bfd
)
11448 && ((gotplt_value
+ 0x80008000) & ~(bfd_vma
) 0xffffffff) != 0)
11451 /* xgettext:c-format */
11452 (_("%pB: `%pA' start VMA of %#" PRIx64
" outside the 32-bit range "
11453 "supported; consider using `-Ttext-segment=...'"),
11455 htab
->root
.sgotplt
->output_section
,
11456 (int64_t) gotplt_value
);
11457 bfd_set_error (bfd_error_no_error
);
11461 /* Install the PLT header. */
11462 loc
= htab
->root
.splt
->contents
;
11463 if (plt_entry
== micromips_o32_exec_plt0_entry
)
11465 bfd_vma gotpc_offset
;
11466 bfd_vma loc_address
;
11469 BFD_ASSERT (gotplt_value
% 4 == 0);
11471 loc_address
= (htab
->root
.splt
->output_section
->vma
11472 + htab
->root
.splt
->output_offset
);
11473 gotpc_offset
= gotplt_value
- ((loc_address
| 3) ^ 3);
11475 /* ADDIUPC has a span of +/-16MB, check we're in range. */
11476 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
11479 /* xgettext:c-format */
11480 (_("%pB: `%pA' offset of %" PRId64
" from `%pA' "
11481 "beyond the range of ADDIUPC"),
11483 htab
->root
.sgotplt
->output_section
,
11484 (int64_t) gotpc_offset
,
11485 htab
->root
.splt
->output_section
);
11486 bfd_set_error (bfd_error_no_error
);
11489 bfd_put_16 (output_bfd
,
11490 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f), loc
);
11491 bfd_put_16 (output_bfd
, (gotpc_offset
>> 2) & 0xffff, loc
+ 2);
11492 for (i
= 2; i
< ARRAY_SIZE (micromips_o32_exec_plt0_entry
); i
++)
11493 bfd_put_16 (output_bfd
, plt_entry
[i
], loc
+ (i
* 2));
11495 else if (plt_entry
== micromips_insn32_o32_exec_plt0_entry
)
11499 bfd_put_16 (output_bfd
, plt_entry
[0], loc
);
11500 bfd_put_16 (output_bfd
, gotplt_value_high
, loc
+ 2);
11501 bfd_put_16 (output_bfd
, plt_entry
[2], loc
+ 4);
11502 bfd_put_16 (output_bfd
, gotplt_value_low
, loc
+ 6);
11503 bfd_put_16 (output_bfd
, plt_entry
[4], loc
+ 8);
11504 bfd_put_16 (output_bfd
, gotplt_value_low
, loc
+ 10);
11505 for (i
= 6; i
< ARRAY_SIZE (micromips_insn32_o32_exec_plt0_entry
); i
++)
11506 bfd_put_16 (output_bfd
, plt_entry
[i
], loc
+ (i
* 2));
11510 bfd_put_32 (output_bfd
, plt_entry
[0] | gotplt_value_high
, loc
);
11511 bfd_put_32 (output_bfd
, plt_entry
[1] | gotplt_value_low
, loc
+ 4);
11512 bfd_put_32 (output_bfd
, plt_entry
[2] | gotplt_value_low
, loc
+ 8);
11513 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
11514 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
11515 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
11516 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
11517 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
11523 /* Install the PLT header for a VxWorks executable and finalize the
11524 contents of .rela.plt.unloaded. */
11527 mips_vxworks_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
11529 Elf_Internal_Rela rela
;
11531 bfd_vma got_value
, got_value_high
, got_value_low
, plt_address
;
11532 static const bfd_vma
*plt_entry
;
11533 struct mips_elf_link_hash_table
*htab
;
11535 htab
= mips_elf_hash_table (info
);
11536 BFD_ASSERT (htab
!= NULL
);
11538 plt_entry
= mips_vxworks_exec_plt0_entry
;
11540 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
11541 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
11542 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
11543 + htab
->root
.hgot
->root
.u
.def
.value
);
11545 got_value_high
= ((got_value
+ 0x8000) >> 16) & 0xffff;
11546 got_value_low
= got_value
& 0xffff;
11548 /* Calculate the address of the PLT header. */
11549 plt_address
= (htab
->root
.splt
->output_section
->vma
11550 + htab
->root
.splt
->output_offset
);
11552 /* Install the PLT header. */
11553 loc
= htab
->root
.splt
->contents
;
11554 bfd_put_32 (output_bfd
, plt_entry
[0] | got_value_high
, loc
);
11555 bfd_put_32 (output_bfd
, plt_entry
[1] | got_value_low
, loc
+ 4);
11556 bfd_put_32 (output_bfd
, plt_entry
[2], loc
+ 8);
11557 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
11558 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
11559 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
11561 /* Output the relocation for the lui of %hi(_GLOBAL_OFFSET_TABLE_). */
11562 loc
= htab
->srelplt2
->contents
;
11563 rela
.r_offset
= plt_address
;
11564 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
11566 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
11567 loc
+= sizeof (Elf32_External_Rela
);
11569 /* Output the relocation for the following addiu of
11570 %lo(_GLOBAL_OFFSET_TABLE_). */
11571 rela
.r_offset
+= 4;
11572 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
11573 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
11574 loc
+= sizeof (Elf32_External_Rela
);
11576 /* Fix up the remaining relocations. They may have the wrong
11577 symbol index for _G_O_T_ or _P_L_T_ depending on the order
11578 in which symbols were output. */
11579 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
11581 Elf_Internal_Rela rel
;
11583 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
11584 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
11585 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11586 loc
+= sizeof (Elf32_External_Rela
);
11588 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
11589 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
11590 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11591 loc
+= sizeof (Elf32_External_Rela
);
11593 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
11594 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
11595 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11596 loc
+= sizeof (Elf32_External_Rela
);
11600 /* Install the PLT header for a VxWorks shared library. */
11603 mips_vxworks_finish_shared_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
11606 struct mips_elf_link_hash_table
*htab
;
11608 htab
= mips_elf_hash_table (info
);
11609 BFD_ASSERT (htab
!= NULL
);
11611 /* We just need to copy the entry byte-by-byte. */
11612 for (i
= 0; i
< ARRAY_SIZE (mips_vxworks_shared_plt0_entry
); i
++)
11613 bfd_put_32 (output_bfd
, mips_vxworks_shared_plt0_entry
[i
],
11614 htab
->root
.splt
->contents
+ i
* 4);
11617 /* Finish up the dynamic sections. */
11620 _bfd_mips_elf_finish_dynamic_sections (bfd
*output_bfd
,
11621 struct bfd_link_info
*info
)
11626 struct mips_got_info
*gg
, *g
;
11627 struct mips_elf_link_hash_table
*htab
;
11629 htab
= mips_elf_hash_table (info
);
11630 BFD_ASSERT (htab
!= NULL
);
11632 dynobj
= elf_hash_table (info
)->dynobj
;
11634 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
11636 sgot
= htab
->root
.sgot
;
11637 gg
= htab
->got_info
;
11639 if (elf_hash_table (info
)->dynamic_sections_created
)
11642 int dyn_to_skip
= 0, dyn_skipped
= 0;
11644 BFD_ASSERT (sdyn
!= NULL
);
11645 BFD_ASSERT (gg
!= NULL
);
11647 g
= mips_elf_bfd_got (output_bfd
, FALSE
);
11648 BFD_ASSERT (g
!= NULL
);
11650 for (b
= sdyn
->contents
;
11651 b
< sdyn
->contents
+ sdyn
->size
;
11652 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
11654 Elf_Internal_Dyn dyn
;
11658 bfd_boolean swap_out_p
;
11660 /* Read in the current dynamic entry. */
11661 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
11663 /* Assume that we're going to modify it and write it out. */
11669 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
11673 BFD_ASSERT (htab
->is_vxworks
);
11674 dyn
.d_un
.d_val
= MIPS_ELF_RELA_SIZE (dynobj
);
11678 /* Rewrite DT_STRSZ. */
11680 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
11684 s
= htab
->root
.sgot
;
11685 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11688 case DT_MIPS_PLTGOT
:
11689 s
= htab
->root
.sgotplt
;
11690 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11693 case DT_MIPS_RLD_VERSION
:
11694 dyn
.d_un
.d_val
= 1; /* XXX */
11697 case DT_MIPS_FLAGS
:
11698 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
11701 case DT_MIPS_TIME_STAMP
:
11705 dyn
.d_un
.d_val
= t
;
11709 case DT_MIPS_ICHECKSUM
:
11711 swap_out_p
= FALSE
;
11714 case DT_MIPS_IVERSION
:
11716 swap_out_p
= FALSE
;
11719 case DT_MIPS_BASE_ADDRESS
:
11720 s
= output_bfd
->sections
;
11721 BFD_ASSERT (s
!= NULL
);
11722 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
11725 case DT_MIPS_LOCAL_GOTNO
:
11726 dyn
.d_un
.d_val
= g
->local_gotno
;
11729 case DT_MIPS_UNREFEXTNO
:
11730 /* The index into the dynamic symbol table which is the
11731 entry of the first external symbol that is not
11732 referenced within the same object. */
11733 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
11736 case DT_MIPS_GOTSYM
:
11737 if (htab
->global_gotsym
)
11739 dyn
.d_un
.d_val
= htab
->global_gotsym
->dynindx
;
11742 /* In case if we don't have global got symbols we default
11743 to setting DT_MIPS_GOTSYM to the same value as
11744 DT_MIPS_SYMTABNO. */
11745 /* Fall through. */
11747 case DT_MIPS_SYMTABNO
:
11749 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
11750 s
= bfd_get_linker_section (dynobj
, name
);
11753 dyn
.d_un
.d_val
= s
->size
/ elemsize
;
11755 dyn
.d_un
.d_val
= 0;
11758 case DT_MIPS_HIPAGENO
:
11759 dyn
.d_un
.d_val
= g
->local_gotno
- htab
->reserved_gotno
;
11762 case DT_MIPS_RLD_MAP
:
11764 struct elf_link_hash_entry
*h
;
11765 h
= mips_elf_hash_table (info
)->rld_symbol
;
11768 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
11769 swap_out_p
= FALSE
;
11772 s
= h
->root
.u
.def
.section
;
11774 /* The MIPS_RLD_MAP tag stores the absolute address of the
11776 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
11777 + h
->root
.u
.def
.value
);
11781 case DT_MIPS_RLD_MAP_REL
:
11783 struct elf_link_hash_entry
*h
;
11784 bfd_vma dt_addr
, rld_addr
;
11785 h
= mips_elf_hash_table (info
)->rld_symbol
;
11788 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
11789 swap_out_p
= FALSE
;
11792 s
= h
->root
.u
.def
.section
;
11794 /* The MIPS_RLD_MAP_REL tag stores the offset to the debug
11795 pointer, relative to the address of the tag. */
11796 dt_addr
= (sdyn
->output_section
->vma
+ sdyn
->output_offset
11797 + (b
- sdyn
->contents
));
11798 rld_addr
= (s
->output_section
->vma
+ s
->output_offset
11799 + h
->root
.u
.def
.value
);
11800 dyn
.d_un
.d_ptr
= rld_addr
- dt_addr
;
11804 case DT_MIPS_OPTIONS
:
11805 s
= (bfd_get_section_by_name
11806 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
11807 dyn
.d_un
.d_ptr
= s
->vma
;
11811 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
11812 if (htab
->is_vxworks
)
11813 dyn
.d_un
.d_val
= DT_RELA
;
11815 dyn
.d_un
.d_val
= DT_REL
;
11819 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
11820 dyn
.d_un
.d_val
= htab
->root
.srelplt
->size
;
11824 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
11825 dyn
.d_un
.d_ptr
= (htab
->root
.srelplt
->output_section
->vma
11826 + htab
->root
.srelplt
->output_offset
);
11830 /* If we didn't need any text relocations after all, delete
11831 the dynamic tag. */
11832 if (!(info
->flags
& DF_TEXTREL
))
11834 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
11835 swap_out_p
= FALSE
;
11840 /* If we didn't need any text relocations after all, clear
11841 DF_TEXTREL from DT_FLAGS. */
11842 if (!(info
->flags
& DF_TEXTREL
))
11843 dyn
.d_un
.d_val
&= ~DF_TEXTREL
;
11845 swap_out_p
= FALSE
;
11849 swap_out_p
= FALSE
;
11850 if (htab
->is_vxworks
11851 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
11856 if (swap_out_p
|| dyn_skipped
)
11857 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
11858 (dynobj
, &dyn
, b
- dyn_skipped
);
11862 dyn_skipped
+= dyn_to_skip
;
11867 /* Wipe out any trailing entries if we shifted down a dynamic tag. */
11868 if (dyn_skipped
> 0)
11869 memset (b
- dyn_skipped
, 0, dyn_skipped
);
11872 if (sgot
!= NULL
&& sgot
->size
> 0
11873 && !bfd_is_abs_section (sgot
->output_section
))
11875 if (htab
->is_vxworks
)
11877 /* The first entry of the global offset table points to the
11878 ".dynamic" section. The second is initialized by the
11879 loader and contains the shared library identifier.
11880 The third is also initialized by the loader and points
11881 to the lazy resolution stub. */
11882 MIPS_ELF_PUT_WORD (output_bfd
,
11883 sdyn
->output_offset
+ sdyn
->output_section
->vma
,
11885 MIPS_ELF_PUT_WORD (output_bfd
, 0,
11886 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
11887 MIPS_ELF_PUT_WORD (output_bfd
, 0,
11889 + 2 * MIPS_ELF_GOT_SIZE (output_bfd
));
11893 /* The first entry of the global offset table will be filled at
11894 runtime. The second entry will be used by some runtime loaders.
11895 This isn't the case of IRIX rld. */
11896 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
11897 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
11898 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
11901 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
11902 = MIPS_ELF_GOT_SIZE (output_bfd
);
11905 /* Generate dynamic relocations for the non-primary gots. */
11906 if (gg
!= NULL
&& gg
->next
)
11908 Elf_Internal_Rela rel
[3];
11909 bfd_vma addend
= 0;
11911 memset (rel
, 0, sizeof (rel
));
11912 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_REL32
);
11914 for (g
= gg
->next
; g
->next
!= gg
; g
= g
->next
)
11916 bfd_vma got_index
= g
->next
->local_gotno
+ g
->next
->global_gotno
11917 + g
->next
->tls_gotno
;
11919 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
11920 + got_index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
11921 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
11923 + got_index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
11925 if (! bfd_link_pic (info
))
11928 for (; got_index
< g
->local_gotno
; got_index
++)
11930 if (got_index
>= g
->assigned_low_gotno
11931 && got_index
<= g
->assigned_high_gotno
)
11934 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
11935 = got_index
* MIPS_ELF_GOT_SIZE (output_bfd
);
11936 if (!(mips_elf_create_dynamic_relocation
11937 (output_bfd
, info
, rel
, NULL
,
11938 bfd_abs_section_ptr
,
11939 0, &addend
, sgot
)))
11941 BFD_ASSERT (addend
== 0);
11946 /* The generation of dynamic relocations for the non-primary gots
11947 adds more dynamic relocations. We cannot count them until
11950 if (elf_hash_table (info
)->dynamic_sections_created
)
11953 bfd_boolean swap_out_p
;
11955 BFD_ASSERT (sdyn
!= NULL
);
11957 for (b
= sdyn
->contents
;
11958 b
< sdyn
->contents
+ sdyn
->size
;
11959 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
11961 Elf_Internal_Dyn dyn
;
11964 /* Read in the current dynamic entry. */
11965 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
11967 /* Assume that we're going to modify it and write it out. */
11973 /* Reduce DT_RELSZ to account for any relocations we
11974 decided not to make. This is for the n64 irix rld,
11975 which doesn't seem to apply any relocations if there
11976 are trailing null entries. */
11977 s
= mips_elf_rel_dyn_section (info
, FALSE
);
11978 dyn
.d_un
.d_val
= (s
->reloc_count
11979 * (ABI_64_P (output_bfd
)
11980 ? sizeof (Elf64_Mips_External_Rel
)
11981 : sizeof (Elf32_External_Rel
)));
11982 /* Adjust the section size too. Tools like the prelinker
11983 can reasonably expect the values to the same. */
11984 BFD_ASSERT (!bfd_is_abs_section (s
->output_section
));
11985 elf_section_data (s
->output_section
)->this_hdr
.sh_size
11990 swap_out_p
= FALSE
;
11995 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
12002 Elf32_compact_rel cpt
;
12004 if (SGI_COMPAT (output_bfd
))
12006 /* Write .compact_rel section out. */
12007 s
= bfd_get_linker_section (dynobj
, ".compact_rel");
12011 cpt
.num
= s
->reloc_count
;
12013 cpt
.offset
= (s
->output_section
->filepos
12014 + sizeof (Elf32_External_compact_rel
));
12017 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
12018 ((Elf32_External_compact_rel
*)
12021 /* Clean up a dummy stub function entry in .text. */
12022 if (htab
->sstubs
!= NULL
)
12024 file_ptr dummy_offset
;
12026 BFD_ASSERT (htab
->sstubs
->size
>= htab
->function_stub_size
);
12027 dummy_offset
= htab
->sstubs
->size
- htab
->function_stub_size
;
12028 memset (htab
->sstubs
->contents
+ dummy_offset
, 0,
12029 htab
->function_stub_size
);
12034 /* The psABI says that the dynamic relocations must be sorted in
12035 increasing order of r_symndx. The VxWorks EABI doesn't require
12036 this, and because the code below handles REL rather than RELA
12037 relocations, using it for VxWorks would be outright harmful. */
12038 if (!htab
->is_vxworks
)
12040 s
= mips_elf_rel_dyn_section (info
, FALSE
);
12042 && s
->size
> (bfd_vma
)2 * MIPS_ELF_REL_SIZE (output_bfd
))
12044 reldyn_sorting_bfd
= output_bfd
;
12046 if (ABI_64_P (output_bfd
))
12047 qsort ((Elf64_External_Rel
*) s
->contents
+ 1,
12048 s
->reloc_count
- 1, sizeof (Elf64_Mips_External_Rel
),
12049 sort_dynamic_relocs_64
);
12051 qsort ((Elf32_External_Rel
*) s
->contents
+ 1,
12052 s
->reloc_count
- 1, sizeof (Elf32_External_Rel
),
12053 sort_dynamic_relocs
);
12058 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
12060 if (htab
->is_vxworks
)
12062 if (bfd_link_pic (info
))
12063 mips_vxworks_finish_shared_plt (output_bfd
, info
);
12065 mips_vxworks_finish_exec_plt (output_bfd
, info
);
12069 BFD_ASSERT (!bfd_link_pic (info
));
12070 if (!mips_finish_exec_plt (output_bfd
, info
))
12078 /* Set ABFD's EF_MIPS_ARCH and EF_MIPS_MACH flags. */
12081 mips_set_isa_flags (bfd
*abfd
)
12085 switch (bfd_get_mach (abfd
))
12088 case bfd_mach_mips3000
:
12089 val
= E_MIPS_ARCH_1
;
12092 case bfd_mach_mips3900
:
12093 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
12096 case bfd_mach_mips6000
:
12097 val
= E_MIPS_ARCH_2
;
12100 case bfd_mach_mips4010
:
12101 val
= E_MIPS_ARCH_2
| E_MIPS_MACH_4010
;
12104 case bfd_mach_mips4000
:
12105 case bfd_mach_mips4300
:
12106 case bfd_mach_mips4400
:
12107 case bfd_mach_mips4600
:
12108 val
= E_MIPS_ARCH_3
;
12111 case bfd_mach_mips4100
:
12112 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
12115 case bfd_mach_mips4111
:
12116 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
12119 case bfd_mach_mips4120
:
12120 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
12123 case bfd_mach_mips4650
:
12124 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
12127 case bfd_mach_mips5400
:
12128 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
12131 case bfd_mach_mips5500
:
12132 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
12135 case bfd_mach_mips5900
:
12136 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5900
;
12139 case bfd_mach_mips9000
:
12140 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_9000
;
12143 case bfd_mach_mips5000
:
12144 case bfd_mach_mips7000
:
12145 case bfd_mach_mips8000
:
12146 case bfd_mach_mips10000
:
12147 case bfd_mach_mips12000
:
12148 case bfd_mach_mips14000
:
12149 case bfd_mach_mips16000
:
12150 val
= E_MIPS_ARCH_4
;
12153 case bfd_mach_mips5
:
12154 val
= E_MIPS_ARCH_5
;
12157 case bfd_mach_mips_loongson_2e
:
12158 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2E
;
12161 case bfd_mach_mips_loongson_2f
:
12162 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2F
;
12165 case bfd_mach_mips_sb1
:
12166 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
12169 case bfd_mach_mips_gs464
:
12170 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_GS464
;
12173 case bfd_mach_mips_gs464e
:
12174 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_GS464E
;
12177 case bfd_mach_mips_gs264e
:
12178 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_GS264E
;
12181 case bfd_mach_mips_octeon
:
12182 case bfd_mach_mips_octeonp
:
12183 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON
;
12186 case bfd_mach_mips_octeon3
:
12187 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON3
;
12190 case bfd_mach_mips_xlr
:
12191 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_XLR
;
12194 case bfd_mach_mips_octeon2
:
12195 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON2
;
12198 case bfd_mach_mipsisa32
:
12199 val
= E_MIPS_ARCH_32
;
12202 case bfd_mach_mipsisa64
:
12203 val
= E_MIPS_ARCH_64
;
12206 case bfd_mach_mipsisa32r2
:
12207 case bfd_mach_mipsisa32r3
:
12208 case bfd_mach_mipsisa32r5
:
12209 val
= E_MIPS_ARCH_32R2
;
12212 case bfd_mach_mips_interaptiv_mr2
:
12213 val
= E_MIPS_ARCH_32R2
| E_MIPS_MACH_IAMR2
;
12216 case bfd_mach_mipsisa64r2
:
12217 case bfd_mach_mipsisa64r3
:
12218 case bfd_mach_mipsisa64r5
:
12219 val
= E_MIPS_ARCH_64R2
;
12222 case bfd_mach_mipsisa32r6
:
12223 val
= E_MIPS_ARCH_32R6
;
12226 case bfd_mach_mipsisa64r6
:
12227 val
= E_MIPS_ARCH_64R6
;
12230 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
12231 elf_elfheader (abfd
)->e_flags
|= val
;
12236 /* Whether to sort relocs output by ld -r or ld --emit-relocs, by r_offset.
12237 Don't do so for code sections. We want to keep ordering of HI16/LO16
12238 as is. On the other hand, elf-eh-frame.c processing requires .eh_frame
12239 relocs to be sorted. */
12242 _bfd_mips_elf_sort_relocs_p (asection
*sec
)
12244 return (sec
->flags
& SEC_CODE
) == 0;
12248 /* The final processing done just before writing out a MIPS ELF object
12249 file. This gets the MIPS architecture right based on the machine
12250 number. This is used by both the 32-bit and the 64-bit ABI. */
12253 _bfd_mips_elf_final_write_processing (bfd
*abfd
,
12254 bfd_boolean linker ATTRIBUTE_UNUSED
)
12257 Elf_Internal_Shdr
**hdrpp
;
12261 /* Keep the existing EF_MIPS_MACH and EF_MIPS_ARCH flags if the former
12262 is nonzero. This is for compatibility with old objects, which used
12263 a combination of a 32-bit EF_MIPS_ARCH and a 64-bit EF_MIPS_MACH. */
12264 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_MACH
) == 0)
12265 mips_set_isa_flags (abfd
);
12267 /* Set the sh_info field for .gptab sections and other appropriate
12268 info for each special section. */
12269 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
12270 i
< elf_numsections (abfd
);
12273 switch ((*hdrpp
)->sh_type
)
12275 case SHT_MIPS_MSYM
:
12276 case SHT_MIPS_LIBLIST
:
12277 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
12279 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
12282 case SHT_MIPS_GPTAB
:
12283 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
12284 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
12285 BFD_ASSERT (name
!= NULL
12286 && CONST_STRNEQ (name
, ".gptab."));
12287 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
12288 BFD_ASSERT (sec
!= NULL
);
12289 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
12292 case SHT_MIPS_CONTENT
:
12293 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
12294 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
12295 BFD_ASSERT (name
!= NULL
12296 && CONST_STRNEQ (name
, ".MIPS.content"));
12297 sec
= bfd_get_section_by_name (abfd
,
12298 name
+ sizeof ".MIPS.content" - 1);
12299 BFD_ASSERT (sec
!= NULL
);
12300 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
12303 case SHT_MIPS_SYMBOL_LIB
:
12304 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
12306 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
12307 sec
= bfd_get_section_by_name (abfd
, ".liblist");
12309 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
12312 case SHT_MIPS_EVENTS
:
12313 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
12314 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
12315 BFD_ASSERT (name
!= NULL
);
12316 if (CONST_STRNEQ (name
, ".MIPS.events"))
12317 sec
= bfd_get_section_by_name (abfd
,
12318 name
+ sizeof ".MIPS.events" - 1);
12321 BFD_ASSERT (CONST_STRNEQ (name
, ".MIPS.post_rel"));
12322 sec
= bfd_get_section_by_name (abfd
,
12324 + sizeof ".MIPS.post_rel" - 1));
12326 BFD_ASSERT (sec
!= NULL
);
12327 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
12334 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
12338 _bfd_mips_elf_additional_program_headers (bfd
*abfd
,
12339 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
12344 /* See if we need a PT_MIPS_REGINFO segment. */
12345 s
= bfd_get_section_by_name (abfd
, ".reginfo");
12346 if (s
&& (s
->flags
& SEC_LOAD
))
12349 /* See if we need a PT_MIPS_ABIFLAGS segment. */
12350 if (bfd_get_section_by_name (abfd
, ".MIPS.abiflags"))
12353 /* See if we need a PT_MIPS_OPTIONS segment. */
12354 if (IRIX_COMPAT (abfd
) == ict_irix6
12355 && bfd_get_section_by_name (abfd
,
12356 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
12359 /* See if we need a PT_MIPS_RTPROC segment. */
12360 if (IRIX_COMPAT (abfd
) == ict_irix5
12361 && bfd_get_section_by_name (abfd
, ".dynamic")
12362 && bfd_get_section_by_name (abfd
, ".mdebug"))
12365 /* Allocate a PT_NULL header in dynamic objects. See
12366 _bfd_mips_elf_modify_segment_map for details. */
12367 if (!SGI_COMPAT (abfd
)
12368 && bfd_get_section_by_name (abfd
, ".dynamic"))
12374 /* Modify the segment map for an IRIX5 executable. */
12377 _bfd_mips_elf_modify_segment_map (bfd
*abfd
,
12378 struct bfd_link_info
*info
)
12381 struct elf_segment_map
*m
, **pm
;
12384 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
12386 s
= bfd_get_section_by_name (abfd
, ".reginfo");
12387 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
12389 for (m
= elf_seg_map (abfd
); m
!= NULL
; m
= m
->next
)
12390 if (m
->p_type
== PT_MIPS_REGINFO
)
12395 m
= bfd_zalloc (abfd
, amt
);
12399 m
->p_type
= PT_MIPS_REGINFO
;
12401 m
->sections
[0] = s
;
12403 /* We want to put it after the PHDR and INTERP segments. */
12404 pm
= &elf_seg_map (abfd
);
12406 && ((*pm
)->p_type
== PT_PHDR
12407 || (*pm
)->p_type
== PT_INTERP
))
12415 /* If there is a .MIPS.abiflags section, we need a PT_MIPS_ABIFLAGS
12417 s
= bfd_get_section_by_name (abfd
, ".MIPS.abiflags");
12418 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
12420 for (m
= elf_seg_map (abfd
); m
!= NULL
; m
= m
->next
)
12421 if (m
->p_type
== PT_MIPS_ABIFLAGS
)
12426 m
= bfd_zalloc (abfd
, amt
);
12430 m
->p_type
= PT_MIPS_ABIFLAGS
;
12432 m
->sections
[0] = s
;
12434 /* We want to put it after the PHDR and INTERP segments. */
12435 pm
= &elf_seg_map (abfd
);
12437 && ((*pm
)->p_type
== PT_PHDR
12438 || (*pm
)->p_type
== PT_INTERP
))
12446 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
12447 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
12448 PT_MIPS_OPTIONS segment immediately following the program header
12450 if (NEWABI_P (abfd
)
12451 /* On non-IRIX6 new abi, we'll have already created a segment
12452 for this section, so don't create another. I'm not sure this
12453 is not also the case for IRIX 6, but I can't test it right
12455 && IRIX_COMPAT (abfd
) == ict_irix6
)
12457 for (s
= abfd
->sections
; s
; s
= s
->next
)
12458 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
12463 struct elf_segment_map
*options_segment
;
12465 pm
= &elf_seg_map (abfd
);
12467 && ((*pm
)->p_type
== PT_PHDR
12468 || (*pm
)->p_type
== PT_INTERP
))
12471 if (*pm
== NULL
|| (*pm
)->p_type
!= PT_MIPS_OPTIONS
)
12473 amt
= sizeof (struct elf_segment_map
);
12474 options_segment
= bfd_zalloc (abfd
, amt
);
12475 options_segment
->next
= *pm
;
12476 options_segment
->p_type
= PT_MIPS_OPTIONS
;
12477 options_segment
->p_flags
= PF_R
;
12478 options_segment
->p_flags_valid
= TRUE
;
12479 options_segment
->count
= 1;
12480 options_segment
->sections
[0] = s
;
12481 *pm
= options_segment
;
12487 if (IRIX_COMPAT (abfd
) == ict_irix5
)
12489 /* If there are .dynamic and .mdebug sections, we make a room
12490 for the RTPROC header. FIXME: Rewrite without section names. */
12491 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
12492 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
12493 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
12495 for (m
= elf_seg_map (abfd
); m
!= NULL
; m
= m
->next
)
12496 if (m
->p_type
== PT_MIPS_RTPROC
)
12501 m
= bfd_zalloc (abfd
, amt
);
12505 m
->p_type
= PT_MIPS_RTPROC
;
12507 s
= bfd_get_section_by_name (abfd
, ".rtproc");
12512 m
->p_flags_valid
= 1;
12517 m
->sections
[0] = s
;
12520 /* We want to put it after the DYNAMIC segment. */
12521 pm
= &elf_seg_map (abfd
);
12522 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
12532 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
12533 .dynstr, .dynsym, and .hash sections, and everything in
12535 for (pm
= &elf_seg_map (abfd
); *pm
!= NULL
;
12537 if ((*pm
)->p_type
== PT_DYNAMIC
)
12540 /* GNU/Linux binaries do not need the extended PT_DYNAMIC section.
12541 glibc's dynamic linker has traditionally derived the number of
12542 tags from the p_filesz field, and sometimes allocates stack
12543 arrays of that size. An overly-big PT_DYNAMIC segment can
12544 be actively harmful in such cases. Making PT_DYNAMIC contain
12545 other sections can also make life hard for the prelinker,
12546 which might move one of the other sections to a different
12547 PT_LOAD segment. */
12548 if (SGI_COMPAT (abfd
)
12551 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
12553 static const char *sec_names
[] =
12555 ".dynamic", ".dynstr", ".dynsym", ".hash"
12559 struct elf_segment_map
*n
;
12561 low
= ~(bfd_vma
) 0;
12563 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
12565 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
12566 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
12573 if (high
< s
->vma
+ sz
)
12574 high
= s
->vma
+ sz
;
12579 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
12580 if ((s
->flags
& SEC_LOAD
) != 0
12582 && s
->vma
+ s
->size
<= high
)
12585 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
12586 n
= bfd_zalloc (abfd
, amt
);
12593 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
12595 if ((s
->flags
& SEC_LOAD
) != 0
12597 && s
->vma
+ s
->size
<= high
)
12599 n
->sections
[i
] = s
;
12608 /* Allocate a spare program header in dynamic objects so that tools
12609 like the prelinker can add an extra PT_LOAD entry.
12611 If the prelinker needs to make room for a new PT_LOAD entry, its
12612 standard procedure is to move the first (read-only) sections into
12613 the new (writable) segment. However, the MIPS ABI requires
12614 .dynamic to be in a read-only segment, and the section will often
12615 start within sizeof (ElfNN_Phdr) bytes of the last program header.
12617 Although the prelinker could in principle move .dynamic to a
12618 writable segment, it seems better to allocate a spare program
12619 header instead, and avoid the need to move any sections.
12620 There is a long tradition of allocating spare dynamic tags,
12621 so allocating a spare program header seems like a natural
12624 If INFO is NULL, we may be copying an already prelinked binary
12625 with objcopy or strip, so do not add this header. */
12627 && !SGI_COMPAT (abfd
)
12628 && bfd_get_section_by_name (abfd
, ".dynamic"))
12630 for (pm
= &elf_seg_map (abfd
); *pm
!= NULL
; pm
= &(*pm
)->next
)
12631 if ((*pm
)->p_type
== PT_NULL
)
12635 m
= bfd_zalloc (abfd
, sizeof (*m
));
12639 m
->p_type
= PT_NULL
;
12647 /* Return the section that should be marked against GC for a given
12651 _bfd_mips_elf_gc_mark_hook (asection
*sec
,
12652 struct bfd_link_info
*info
,
12653 Elf_Internal_Rela
*rel
,
12654 struct elf_link_hash_entry
*h
,
12655 Elf_Internal_Sym
*sym
)
12657 /* ??? Do mips16 stub sections need to be handled special? */
12660 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
12662 case R_MIPS_GNU_VTINHERIT
:
12663 case R_MIPS_GNU_VTENTRY
:
12667 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
12670 /* Prevent .MIPS.abiflags from being discarded with --gc-sections. */
12673 _bfd_mips_elf_gc_mark_extra_sections (struct bfd_link_info
*info
,
12674 elf_gc_mark_hook_fn gc_mark_hook
)
12678 _bfd_elf_gc_mark_extra_sections (info
, gc_mark_hook
);
12680 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
12684 if (! is_mips_elf (sub
))
12687 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
12689 && MIPS_ELF_ABIFLAGS_SECTION_NAME_P
12690 (bfd_get_section_name (sub
, o
)))
12692 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
12700 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
12701 hiding the old indirect symbol. Process additional relocation
12702 information. Also called for weakdefs, in which case we just let
12703 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
12706 _bfd_mips_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
12707 struct elf_link_hash_entry
*dir
,
12708 struct elf_link_hash_entry
*ind
)
12710 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
12712 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
12714 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
12715 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
12716 /* Any absolute non-dynamic relocations against an indirect or weak
12717 definition will be against the target symbol. */
12718 if (indmips
->has_static_relocs
)
12719 dirmips
->has_static_relocs
= TRUE
;
12721 if (ind
->root
.type
!= bfd_link_hash_indirect
)
12724 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
12725 if (indmips
->readonly_reloc
)
12726 dirmips
->readonly_reloc
= TRUE
;
12727 if (indmips
->no_fn_stub
)
12728 dirmips
->no_fn_stub
= TRUE
;
12729 if (indmips
->fn_stub
)
12731 dirmips
->fn_stub
= indmips
->fn_stub
;
12732 indmips
->fn_stub
= NULL
;
12734 if (indmips
->need_fn_stub
)
12736 dirmips
->need_fn_stub
= TRUE
;
12737 indmips
->need_fn_stub
= FALSE
;
12739 if (indmips
->call_stub
)
12741 dirmips
->call_stub
= indmips
->call_stub
;
12742 indmips
->call_stub
= NULL
;
12744 if (indmips
->call_fp_stub
)
12746 dirmips
->call_fp_stub
= indmips
->call_fp_stub
;
12747 indmips
->call_fp_stub
= NULL
;
12749 if (indmips
->global_got_area
< dirmips
->global_got_area
)
12750 dirmips
->global_got_area
= indmips
->global_got_area
;
12751 if (indmips
->global_got_area
< GGA_NONE
)
12752 indmips
->global_got_area
= GGA_NONE
;
12753 if (indmips
->has_nonpic_branches
)
12754 dirmips
->has_nonpic_branches
= TRUE
;
12757 /* Take care of the special `__gnu_absolute_zero' symbol and ignore attempts
12758 to hide it. It has to remain global (it will also be protected) so as to
12759 be assigned a global GOT entry, which will then remain unchanged at load
12763 _bfd_mips_elf_hide_symbol (struct bfd_link_info
*info
,
12764 struct elf_link_hash_entry
*entry
,
12765 bfd_boolean force_local
)
12767 struct mips_elf_link_hash_table
*htab
;
12769 htab
= mips_elf_hash_table (info
);
12770 BFD_ASSERT (htab
!= NULL
);
12771 if (htab
->use_absolute_zero
12772 && strcmp (entry
->root
.root
.string
, "__gnu_absolute_zero") == 0)
12775 _bfd_elf_link_hash_hide_symbol (info
, entry
, force_local
);
12778 #define PDR_SIZE 32
12781 _bfd_mips_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
12782 struct bfd_link_info
*info
)
12785 bfd_boolean ret
= FALSE
;
12786 unsigned char *tdata
;
12789 o
= bfd_get_section_by_name (abfd
, ".pdr");
12794 if (o
->size
% PDR_SIZE
!= 0)
12796 if (o
->output_section
!= NULL
12797 && bfd_is_abs_section (o
->output_section
))
12800 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
12804 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
12805 info
->keep_memory
);
12812 cookie
->rel
= cookie
->rels
;
12813 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
12815 for (i
= 0, skip
= 0; i
< o
->size
/ PDR_SIZE
; i
++)
12817 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
12826 mips_elf_section_data (o
)->u
.tdata
= tdata
;
12827 if (o
->rawsize
== 0)
12828 o
->rawsize
= o
->size
;
12829 o
->size
-= skip
* PDR_SIZE
;
12835 if (! info
->keep_memory
)
12836 free (cookie
->rels
);
12842 _bfd_mips_elf_ignore_discarded_relocs (asection
*sec
)
12844 if (strcmp (sec
->name
, ".pdr") == 0)
12850 _bfd_mips_elf_write_section (bfd
*output_bfd
,
12851 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
12852 asection
*sec
, bfd_byte
*contents
)
12854 bfd_byte
*to
, *from
, *end
;
12857 if (strcmp (sec
->name
, ".pdr") != 0)
12860 if (mips_elf_section_data (sec
)->u
.tdata
== NULL
)
12864 end
= contents
+ sec
->size
;
12865 for (from
= contents
, i
= 0;
12867 from
+= PDR_SIZE
, i
++)
12869 if ((mips_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
12872 memcpy (to
, from
, PDR_SIZE
);
12875 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
12876 sec
->output_offset
, sec
->size
);
12880 /* microMIPS code retains local labels for linker relaxation. Omit them
12881 from output by default for clarity. */
12884 _bfd_mips_elf_is_target_special_symbol (bfd
*abfd
, asymbol
*sym
)
12886 return _bfd_elf_is_local_label_name (abfd
, sym
->name
);
12889 /* MIPS ELF uses a special find_nearest_line routine in order the
12890 handle the ECOFF debugging information. */
12892 struct mips_elf_find_line
12894 struct ecoff_debug_info d
;
12895 struct ecoff_find_line i
;
12899 _bfd_mips_elf_find_nearest_line (bfd
*abfd
, asymbol
**symbols
,
12900 asection
*section
, bfd_vma offset
,
12901 const char **filename_ptr
,
12902 const char **functionname_ptr
,
12903 unsigned int *line_ptr
,
12904 unsigned int *discriminator_ptr
)
12908 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
12909 filename_ptr
, functionname_ptr
,
12910 line_ptr
, discriminator_ptr
,
12911 dwarf_debug_sections
,
12912 ABI_64_P (abfd
) ? 8 : 0,
12913 &elf_tdata (abfd
)->dwarf2_find_line_info
)
12914 || _bfd_dwarf1_find_nearest_line (abfd
, symbols
, section
, offset
,
12915 filename_ptr
, functionname_ptr
,
12918 /* PR 22789: If the function name or filename was not found through
12919 the debug information, then try an ordinary lookup instead. */
12920 if ((functionname_ptr
!= NULL
&& *functionname_ptr
== NULL
)
12921 || (filename_ptr
!= NULL
&& *filename_ptr
== NULL
))
12923 /* Do not override already discovered names. */
12924 if (functionname_ptr
!= NULL
&& *functionname_ptr
!= NULL
)
12925 functionname_ptr
= NULL
;
12927 if (filename_ptr
!= NULL
&& *filename_ptr
!= NULL
)
12928 filename_ptr
= NULL
;
12930 _bfd_elf_find_function (abfd
, symbols
, section
, offset
,
12931 filename_ptr
, functionname_ptr
);
12937 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
12940 flagword origflags
;
12941 struct mips_elf_find_line
*fi
;
12942 const struct ecoff_debug_swap
* const swap
=
12943 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
12945 /* If we are called during a link, mips_elf_final_link may have
12946 cleared the SEC_HAS_CONTENTS field. We force it back on here
12947 if appropriate (which it normally will be). */
12948 origflags
= msec
->flags
;
12949 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
12950 msec
->flags
|= SEC_HAS_CONTENTS
;
12952 fi
= mips_elf_tdata (abfd
)->find_line_info
;
12955 bfd_size_type external_fdr_size
;
12958 struct fdr
*fdr_ptr
;
12959 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
12961 fi
= bfd_zalloc (abfd
, amt
);
12964 msec
->flags
= origflags
;
12968 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
12970 msec
->flags
= origflags
;
12974 /* Swap in the FDR information. */
12975 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
12976 fi
->d
.fdr
= bfd_alloc (abfd
, amt
);
12977 if (fi
->d
.fdr
== NULL
)
12979 msec
->flags
= origflags
;
12982 external_fdr_size
= swap
->external_fdr_size
;
12983 fdr_ptr
= fi
->d
.fdr
;
12984 fraw_src
= (char *) fi
->d
.external_fdr
;
12985 fraw_end
= (fraw_src
12986 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
12987 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
12988 (*swap
->swap_fdr_in
) (abfd
, fraw_src
, fdr_ptr
);
12990 mips_elf_tdata (abfd
)->find_line_info
= fi
;
12992 /* Note that we don't bother to ever free this information.
12993 find_nearest_line is either called all the time, as in
12994 objdump -l, so the information should be saved, or it is
12995 rarely called, as in ld error messages, so the memory
12996 wasted is unimportant. Still, it would probably be a
12997 good idea for free_cached_info to throw it away. */
13000 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
13001 &fi
->i
, filename_ptr
, functionname_ptr
,
13004 msec
->flags
= origflags
;
13008 msec
->flags
= origflags
;
13011 /* Fall back on the generic ELF find_nearest_line routine. */
13013 return _bfd_elf_find_nearest_line (abfd
, symbols
, section
, offset
,
13014 filename_ptr
, functionname_ptr
,
13015 line_ptr
, discriminator_ptr
);
13019 _bfd_mips_elf_find_inliner_info (bfd
*abfd
,
13020 const char **filename_ptr
,
13021 const char **functionname_ptr
,
13022 unsigned int *line_ptr
)
13025 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
13026 functionname_ptr
, line_ptr
,
13027 & elf_tdata (abfd
)->dwarf2_find_line_info
);
13032 /* When are writing out the .options or .MIPS.options section,
13033 remember the bytes we are writing out, so that we can install the
13034 GP value in the section_processing routine. */
13037 _bfd_mips_elf_set_section_contents (bfd
*abfd
, sec_ptr section
,
13038 const void *location
,
13039 file_ptr offset
, bfd_size_type count
)
13041 if (MIPS_ELF_OPTIONS_SECTION_NAME_P (section
->name
))
13045 if (elf_section_data (section
) == NULL
)
13047 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
13048 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
13049 if (elf_section_data (section
) == NULL
)
13052 c
= mips_elf_section_data (section
)->u
.tdata
;
13055 c
= bfd_zalloc (abfd
, section
->size
);
13058 mips_elf_section_data (section
)->u
.tdata
= c
;
13061 memcpy (c
+ offset
, location
, count
);
13064 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
13068 /* This is almost identical to bfd_generic_get_... except that some
13069 MIPS relocations need to be handled specially. Sigh. */
13072 _bfd_elf_mips_get_relocated_section_contents
13074 struct bfd_link_info
*link_info
,
13075 struct bfd_link_order
*link_order
,
13077 bfd_boolean relocatable
,
13080 /* Get enough memory to hold the stuff */
13081 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
13082 asection
*input_section
= link_order
->u
.indirect
.section
;
13085 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
13086 arelent
**reloc_vector
= NULL
;
13089 if (reloc_size
< 0)
13092 reloc_vector
= bfd_malloc (reloc_size
);
13093 if (reloc_vector
== NULL
&& reloc_size
!= 0)
13096 /* read in the section */
13097 sz
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
13098 if (!bfd_get_section_contents (input_bfd
, input_section
, data
, 0, sz
))
13101 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
13105 if (reloc_count
< 0)
13108 if (reloc_count
> 0)
13113 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
13116 struct bfd_hash_entry
*h
;
13117 struct bfd_link_hash_entry
*lh
;
13118 /* Skip all this stuff if we aren't mixing formats. */
13119 if (abfd
&& input_bfd
13120 && abfd
->xvec
== input_bfd
->xvec
)
13124 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
13125 lh
= (struct bfd_link_hash_entry
*) h
;
13132 case bfd_link_hash_undefined
:
13133 case bfd_link_hash_undefweak
:
13134 case bfd_link_hash_common
:
13137 case bfd_link_hash_defined
:
13138 case bfd_link_hash_defweak
:
13140 gp
= lh
->u
.def
.value
;
13142 case bfd_link_hash_indirect
:
13143 case bfd_link_hash_warning
:
13145 /* @@FIXME ignoring warning for now */
13147 case bfd_link_hash_new
:
13156 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
13158 char *error_message
= NULL
;
13159 bfd_reloc_status_type r
;
13161 /* Specific to MIPS: Deal with relocation types that require
13162 knowing the gp of the output bfd. */
13163 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
13165 /* If we've managed to find the gp and have a special
13166 function for the relocation then go ahead, else default
13167 to the generic handling. */
13169 && (*parent
)->howto
->special_function
13170 == _bfd_mips_elf32_gprel16_reloc
)
13171 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
13172 input_section
, relocatable
,
13175 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
13177 relocatable
? abfd
: NULL
,
13182 asection
*os
= input_section
->output_section
;
13184 /* A partial link, so keep the relocs */
13185 os
->orelocation
[os
->reloc_count
] = *parent
;
13189 if (r
!= bfd_reloc_ok
)
13193 case bfd_reloc_undefined
:
13194 (*link_info
->callbacks
->undefined_symbol
)
13195 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
13196 input_bfd
, input_section
, (*parent
)->address
, TRUE
);
13198 case bfd_reloc_dangerous
:
13199 BFD_ASSERT (error_message
!= NULL
);
13200 (*link_info
->callbacks
->reloc_dangerous
)
13201 (link_info
, error_message
,
13202 input_bfd
, input_section
, (*parent
)->address
);
13204 case bfd_reloc_overflow
:
13205 (*link_info
->callbacks
->reloc_overflow
)
13207 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
13208 (*parent
)->howto
->name
, (*parent
)->addend
,
13209 input_bfd
, input_section
, (*parent
)->address
);
13211 case bfd_reloc_outofrange
:
13220 if (reloc_vector
!= NULL
)
13221 free (reloc_vector
);
13225 if (reloc_vector
!= NULL
)
13226 free (reloc_vector
);
13231 mips_elf_relax_delete_bytes (bfd
*abfd
,
13232 asection
*sec
, bfd_vma addr
, int count
)
13234 Elf_Internal_Shdr
*symtab_hdr
;
13235 unsigned int sec_shndx
;
13236 bfd_byte
*contents
;
13237 Elf_Internal_Rela
*irel
, *irelend
;
13238 Elf_Internal_Sym
*isym
;
13239 Elf_Internal_Sym
*isymend
;
13240 struct elf_link_hash_entry
**sym_hashes
;
13241 struct elf_link_hash_entry
**end_hashes
;
13242 struct elf_link_hash_entry
**start_hashes
;
13243 unsigned int symcount
;
13245 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
13246 contents
= elf_section_data (sec
)->this_hdr
.contents
;
13248 irel
= elf_section_data (sec
)->relocs
;
13249 irelend
= irel
+ sec
->reloc_count
;
13251 /* Actually delete the bytes. */
13252 memmove (contents
+ addr
, contents
+ addr
+ count
,
13253 (size_t) (sec
->size
- addr
- count
));
13254 sec
->size
-= count
;
13256 /* Adjust all the relocs. */
13257 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
13259 /* Get the new reloc address. */
13260 if (irel
->r_offset
> addr
)
13261 irel
->r_offset
-= count
;
13264 BFD_ASSERT (addr
% 2 == 0);
13265 BFD_ASSERT (count
% 2 == 0);
13267 /* Adjust the local symbols defined in this section. */
13268 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
13269 isym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
13270 for (isymend
= isym
+ symtab_hdr
->sh_info
; isym
< isymend
; isym
++)
13271 if (isym
->st_shndx
== sec_shndx
&& isym
->st_value
> addr
)
13272 isym
->st_value
-= count
;
13274 /* Now adjust the global symbols defined in this section. */
13275 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
13276 - symtab_hdr
->sh_info
);
13277 sym_hashes
= start_hashes
= elf_sym_hashes (abfd
);
13278 end_hashes
= sym_hashes
+ symcount
;
13280 for (; sym_hashes
< end_hashes
; sym_hashes
++)
13282 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
13284 if ((sym_hash
->root
.type
== bfd_link_hash_defined
13285 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
13286 && sym_hash
->root
.u
.def
.section
== sec
)
13288 bfd_vma value
= sym_hash
->root
.u
.def
.value
;
13290 if (ELF_ST_IS_MICROMIPS (sym_hash
->other
))
13291 value
&= MINUS_TWO
;
13293 sym_hash
->root
.u
.def
.value
-= count
;
13301 /* Opcodes needed for microMIPS relaxation as found in
13302 opcodes/micromips-opc.c. */
13304 struct opcode_descriptor
{
13305 unsigned long match
;
13306 unsigned long mask
;
13309 /* The $ra register aka $31. */
13313 /* 32-bit instruction format register fields. */
13315 #define OP32_SREG(opcode) (((opcode) >> 16) & 0x1f)
13316 #define OP32_TREG(opcode) (((opcode) >> 21) & 0x1f)
13318 /* Check if a 5-bit register index can be abbreviated to 3 bits. */
13320 #define OP16_VALID_REG(r) \
13321 ((2 <= (r) && (r) <= 7) || (16 <= (r) && (r) <= 17))
13324 /* 32-bit and 16-bit branches. */
13326 static const struct opcode_descriptor b_insns_32
[] = {
13327 { /* "b", "p", */ 0x40400000, 0xffff0000 }, /* bgez 0 */
13328 { /* "b", "p", */ 0x94000000, 0xffff0000 }, /* beq 0, 0 */
13329 { 0, 0 } /* End marker for find_match(). */
13332 static const struct opcode_descriptor bc_insn_32
=
13333 { /* "bc(1|2)(ft)", "N,p", */ 0x42800000, 0xfec30000 };
13335 static const struct opcode_descriptor bz_insn_32
=
13336 { /* "b(g|l)(e|t)z", "s,p", */ 0x40000000, 0xff200000 };
13338 static const struct opcode_descriptor bzal_insn_32
=
13339 { /* "b(ge|lt)zal", "s,p", */ 0x40200000, 0xffa00000 };
13341 static const struct opcode_descriptor beq_insn_32
=
13342 { /* "b(eq|ne)", "s,t,p", */ 0x94000000, 0xdc000000 };
13344 static const struct opcode_descriptor b_insn_16
=
13345 { /* "b", "mD", */ 0xcc00, 0xfc00 };
13347 static const struct opcode_descriptor bz_insn_16
=
13348 { /* "b(eq|ne)z", "md,mE", */ 0x8c00, 0xdc00 };
13351 /* 32-bit and 16-bit branch EQ and NE zero. */
13353 /* NOTE: All opcode tables have BEQ/BNE in the same order: first the
13354 eq and second the ne. This convention is used when replacing a
13355 32-bit BEQ/BNE with the 16-bit version. */
13357 #define BZC32_REG_FIELD(r) (((r) & 0x1f) << 16)
13359 static const struct opcode_descriptor bz_rs_insns_32
[] = {
13360 { /* "beqz", "s,p", */ 0x94000000, 0xffe00000 },
13361 { /* "bnez", "s,p", */ 0xb4000000, 0xffe00000 },
13362 { 0, 0 } /* End marker for find_match(). */
13365 static const struct opcode_descriptor bz_rt_insns_32
[] = {
13366 { /* "beqz", "t,p", */ 0x94000000, 0xfc01f000 },
13367 { /* "bnez", "t,p", */ 0xb4000000, 0xfc01f000 },
13368 { 0, 0 } /* End marker for find_match(). */
13371 static const struct opcode_descriptor bzc_insns_32
[] = {
13372 { /* "beqzc", "s,p", */ 0x40e00000, 0xffe00000 },
13373 { /* "bnezc", "s,p", */ 0x40a00000, 0xffe00000 },
13374 { 0, 0 } /* End marker for find_match(). */
13377 static const struct opcode_descriptor bz_insns_16
[] = {
13378 { /* "beqz", "md,mE", */ 0x8c00, 0xfc00 },
13379 { /* "bnez", "md,mE", */ 0xac00, 0xfc00 },
13380 { 0, 0 } /* End marker for find_match(). */
13383 /* Switch between a 5-bit register index and its 3-bit shorthand. */
13385 #define BZ16_REG(opcode) ((((((opcode) >> 7) & 7) + 0x1e) & 0xf) + 2)
13386 #define BZ16_REG_FIELD(r) (((r) & 7) << 7)
13389 /* 32-bit instructions with a delay slot. */
13391 static const struct opcode_descriptor jal_insn_32_bd16
=
13392 { /* "jals", "a", */ 0x74000000, 0xfc000000 };
13394 static const struct opcode_descriptor jal_insn_32_bd32
=
13395 { /* "jal", "a", */ 0xf4000000, 0xfc000000 };
13397 static const struct opcode_descriptor jal_x_insn_32_bd32
=
13398 { /* "jal[x]", "a", */ 0xf0000000, 0xf8000000 };
13400 static const struct opcode_descriptor j_insn_32
=
13401 { /* "j", "a", */ 0xd4000000, 0xfc000000 };
13403 static const struct opcode_descriptor jalr_insn_32
=
13404 { /* "jalr[.hb]", "t,s", */ 0x00000f3c, 0xfc00efff };
13406 /* This table can be compacted, because no opcode replacement is made. */
13408 static const struct opcode_descriptor ds_insns_32_bd16
[] = {
13409 { /* "jals", "a", */ 0x74000000, 0xfc000000 },
13411 { /* "jalrs[.hb]", "t,s", */ 0x00004f3c, 0xfc00efff },
13412 { /* "b(ge|lt)zals", "s,p", */ 0x42200000, 0xffa00000 },
13414 { /* "b(g|l)(e|t)z", "s,p", */ 0x40000000, 0xff200000 },
13415 { /* "b(eq|ne)", "s,t,p", */ 0x94000000, 0xdc000000 },
13416 { /* "j", "a", */ 0xd4000000, 0xfc000000 },
13417 { 0, 0 } /* End marker for find_match(). */
13420 /* This table can be compacted, because no opcode replacement is made. */
13422 static const struct opcode_descriptor ds_insns_32_bd32
[] = {
13423 { /* "jal[x]", "a", */ 0xf0000000, 0xf8000000 },
13425 { /* "jalr[.hb]", "t,s", */ 0x00000f3c, 0xfc00efff },
13426 { /* "b(ge|lt)zal", "s,p", */ 0x40200000, 0xffa00000 },
13427 { 0, 0 } /* End marker for find_match(). */
13431 /* 16-bit instructions with a delay slot. */
13433 static const struct opcode_descriptor jalr_insn_16_bd16
=
13434 { /* "jalrs", "my,mj", */ 0x45e0, 0xffe0 };
13436 static const struct opcode_descriptor jalr_insn_16_bd32
=
13437 { /* "jalr", "my,mj", */ 0x45c0, 0xffe0 };
13439 static const struct opcode_descriptor jr_insn_16
=
13440 { /* "jr", "mj", */ 0x4580, 0xffe0 };
13442 #define JR16_REG(opcode) ((opcode) & 0x1f)
13444 /* This table can be compacted, because no opcode replacement is made. */
13446 static const struct opcode_descriptor ds_insns_16_bd16
[] = {
13447 { /* "jalrs", "my,mj", */ 0x45e0, 0xffe0 },
13449 { /* "b", "mD", */ 0xcc00, 0xfc00 },
13450 { /* "b(eq|ne)z", "md,mE", */ 0x8c00, 0xdc00 },
13451 { /* "jr", "mj", */ 0x4580, 0xffe0 },
13452 { 0, 0 } /* End marker for find_match(). */
13456 /* LUI instruction. */
13458 static const struct opcode_descriptor lui_insn
=
13459 { /* "lui", "s,u", */ 0x41a00000, 0xffe00000 };
13462 /* ADDIU instruction. */
13464 static const struct opcode_descriptor addiu_insn
=
13465 { /* "addiu", "t,r,j", */ 0x30000000, 0xfc000000 };
13467 static const struct opcode_descriptor addiupc_insn
=
13468 { /* "addiu", "mb,$pc,mQ", */ 0x78000000, 0xfc000000 };
13470 #define ADDIUPC_REG_FIELD(r) \
13471 (((2 <= (r) && (r) <= 7) ? (r) : ((r) - 16)) << 23)
13474 /* Relaxable instructions in a JAL delay slot: MOVE. */
13476 /* The 16-bit move has rd in 9:5 and rs in 4:0. The 32-bit moves
13477 (ADDU, OR) have rd in 15:11 and rs in 10:16. */
13478 #define MOVE32_RD(opcode) (((opcode) >> 11) & 0x1f)
13479 #define MOVE32_RS(opcode) (((opcode) >> 16) & 0x1f)
13481 #define MOVE16_RD_FIELD(r) (((r) & 0x1f) << 5)
13482 #define MOVE16_RS_FIELD(r) (((r) & 0x1f) )
13484 static const struct opcode_descriptor move_insns_32
[] = {
13485 { /* "move", "d,s", */ 0x00000290, 0xffe007ff }, /* or d,s,$0 */
13486 { /* "move", "d,s", */ 0x00000150, 0xffe007ff }, /* addu d,s,$0 */
13487 { 0, 0 } /* End marker for find_match(). */
13490 static const struct opcode_descriptor move_insn_16
=
13491 { /* "move", "mp,mj", */ 0x0c00, 0xfc00 };
13494 /* NOP instructions. */
13496 static const struct opcode_descriptor nop_insn_32
=
13497 { /* "nop", "", */ 0x00000000, 0xffffffff };
13499 static const struct opcode_descriptor nop_insn_16
=
13500 { /* "nop", "", */ 0x0c00, 0xffff };
13503 /* Instruction match support. */
13505 #define MATCH(opcode, insn) ((opcode & insn.mask) == insn.match)
13508 find_match (unsigned long opcode
, const struct opcode_descriptor insn
[])
13510 unsigned long indx
;
13512 for (indx
= 0; insn
[indx
].mask
!= 0; indx
++)
13513 if (MATCH (opcode
, insn
[indx
]))
13520 /* Branch and delay slot decoding support. */
13522 /* If PTR points to what *might* be a 16-bit branch or jump, then
13523 return the minimum length of its delay slot, otherwise return 0.
13524 Non-zero results are not definitive as we might be checking against
13525 the second half of another instruction. */
13528 check_br16_dslot (bfd
*abfd
, bfd_byte
*ptr
)
13530 unsigned long opcode
;
13533 opcode
= bfd_get_16 (abfd
, ptr
);
13534 if (MATCH (opcode
, jalr_insn_16_bd32
) != 0)
13535 /* 16-bit branch/jump with a 32-bit delay slot. */
13537 else if (MATCH (opcode
, jalr_insn_16_bd16
) != 0
13538 || find_match (opcode
, ds_insns_16_bd16
) >= 0)
13539 /* 16-bit branch/jump with a 16-bit delay slot. */
13542 /* No delay slot. */
13548 /* If PTR points to what *might* be a 32-bit branch or jump, then
13549 return the minimum length of its delay slot, otherwise return 0.
13550 Non-zero results are not definitive as we might be checking against
13551 the second half of another instruction. */
13554 check_br32_dslot (bfd
*abfd
, bfd_byte
*ptr
)
13556 unsigned long opcode
;
13559 opcode
= bfd_get_micromips_32 (abfd
, ptr
);
13560 if (find_match (opcode
, ds_insns_32_bd32
) >= 0)
13561 /* 32-bit branch/jump with a 32-bit delay slot. */
13563 else if (find_match (opcode
, ds_insns_32_bd16
) >= 0)
13564 /* 32-bit branch/jump with a 16-bit delay slot. */
13567 /* No delay slot. */
13573 /* If PTR points to a 16-bit branch or jump with a 32-bit delay slot
13574 that doesn't fiddle with REG, then return TRUE, otherwise FALSE. */
13577 check_br16 (bfd
*abfd
, bfd_byte
*ptr
, unsigned long reg
)
13579 unsigned long opcode
;
13581 opcode
= bfd_get_16 (abfd
, ptr
);
13582 if (MATCH (opcode
, b_insn_16
)
13584 || (MATCH (opcode
, jr_insn_16
) && reg
!= JR16_REG (opcode
))
13586 || (MATCH (opcode
, bz_insn_16
) && reg
!= BZ16_REG (opcode
))
13587 /* BEQZ16, BNEZ16 */
13588 || (MATCH (opcode
, jalr_insn_16_bd32
)
13590 && reg
!= JR16_REG (opcode
) && reg
!= RA
))
13596 /* If PTR points to a 32-bit branch or jump that doesn't fiddle with REG,
13597 then return TRUE, otherwise FALSE. */
13600 check_br32 (bfd
*abfd
, bfd_byte
*ptr
, unsigned long reg
)
13602 unsigned long opcode
;
13604 opcode
= bfd_get_micromips_32 (abfd
, ptr
);
13605 if (MATCH (opcode
, j_insn_32
)
13607 || MATCH (opcode
, bc_insn_32
)
13608 /* BC1F, BC1T, BC2F, BC2T */
13609 || (MATCH (opcode
, jal_x_insn_32_bd32
) && reg
!= RA
)
13611 || (MATCH (opcode
, bz_insn_32
) && reg
!= OP32_SREG (opcode
))
13612 /* BGEZ, BGTZ, BLEZ, BLTZ */
13613 || (MATCH (opcode
, bzal_insn_32
)
13614 /* BGEZAL, BLTZAL */
13615 && reg
!= OP32_SREG (opcode
) && reg
!= RA
)
13616 || ((MATCH (opcode
, jalr_insn_32
) || MATCH (opcode
, beq_insn_32
))
13617 /* JALR, JALR.HB, BEQ, BNE */
13618 && reg
!= OP32_SREG (opcode
) && reg
!= OP32_TREG (opcode
)))
13624 /* If the instruction encoding at PTR and relocations [INTERNAL_RELOCS,
13625 IRELEND) at OFFSET indicate that there must be a compact branch there,
13626 then return TRUE, otherwise FALSE. */
13629 check_relocated_bzc (bfd
*abfd
, const bfd_byte
*ptr
, bfd_vma offset
,
13630 const Elf_Internal_Rela
*internal_relocs
,
13631 const Elf_Internal_Rela
*irelend
)
13633 const Elf_Internal_Rela
*irel
;
13634 unsigned long opcode
;
13636 opcode
= bfd_get_micromips_32 (abfd
, ptr
);
13637 if (find_match (opcode
, bzc_insns_32
) < 0)
13640 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
13641 if (irel
->r_offset
== offset
13642 && ELF32_R_TYPE (irel
->r_info
) == R_MICROMIPS_PC16_S1
)
13648 /* Bitsize checking. */
13649 #define IS_BITSIZE(val, N) \
13650 (((((val) & ((1ULL << (N)) - 1)) ^ (1ULL << ((N) - 1))) \
13651 - (1ULL << ((N) - 1))) == (val))
13655 _bfd_mips_elf_relax_section (bfd
*abfd
, asection
*sec
,
13656 struct bfd_link_info
*link_info
,
13657 bfd_boolean
*again
)
13659 bfd_boolean insn32
= mips_elf_hash_table (link_info
)->insn32
;
13660 Elf_Internal_Shdr
*symtab_hdr
;
13661 Elf_Internal_Rela
*internal_relocs
;
13662 Elf_Internal_Rela
*irel
, *irelend
;
13663 bfd_byte
*contents
= NULL
;
13664 Elf_Internal_Sym
*isymbuf
= NULL
;
13666 /* Assume nothing changes. */
13669 /* We don't have to do anything for a relocatable link, if
13670 this section does not have relocs, or if this is not a
13673 if (bfd_link_relocatable (link_info
)
13674 || (sec
->flags
& SEC_RELOC
) == 0
13675 || sec
->reloc_count
== 0
13676 || (sec
->flags
& SEC_CODE
) == 0)
13679 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
13681 /* Get a copy of the native relocations. */
13682 internal_relocs
= (_bfd_elf_link_read_relocs
13683 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
13684 link_info
->keep_memory
));
13685 if (internal_relocs
== NULL
)
13688 /* Walk through them looking for relaxing opportunities. */
13689 irelend
= internal_relocs
+ sec
->reloc_count
;
13690 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
13692 unsigned long r_symndx
= ELF32_R_SYM (irel
->r_info
);
13693 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
13694 bfd_boolean target_is_micromips_code_p
;
13695 unsigned long opcode
;
13701 /* The number of bytes to delete for relaxation and from where
13702 to delete these bytes starting at irel->r_offset. */
13706 /* If this isn't something that can be relaxed, then ignore
13708 if (r_type
!= R_MICROMIPS_HI16
13709 && r_type
!= R_MICROMIPS_PC16_S1
13710 && r_type
!= R_MICROMIPS_26_S1
)
13713 /* Get the section contents if we haven't done so already. */
13714 if (contents
== NULL
)
13716 /* Get cached copy if it exists. */
13717 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
13718 contents
= elf_section_data (sec
)->this_hdr
.contents
;
13719 /* Go get them off disk. */
13720 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
13723 ptr
= contents
+ irel
->r_offset
;
13725 /* Read this BFD's local symbols if we haven't done so already. */
13726 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
13728 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
13729 if (isymbuf
== NULL
)
13730 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
13731 symtab_hdr
->sh_info
, 0,
13733 if (isymbuf
== NULL
)
13737 /* Get the value of the symbol referred to by the reloc. */
13738 if (r_symndx
< symtab_hdr
->sh_info
)
13740 /* A local symbol. */
13741 Elf_Internal_Sym
*isym
;
13744 isym
= isymbuf
+ r_symndx
;
13745 if (isym
->st_shndx
== SHN_UNDEF
)
13746 sym_sec
= bfd_und_section_ptr
;
13747 else if (isym
->st_shndx
== SHN_ABS
)
13748 sym_sec
= bfd_abs_section_ptr
;
13749 else if (isym
->st_shndx
== SHN_COMMON
)
13750 sym_sec
= bfd_com_section_ptr
;
13752 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
13753 symval
= (isym
->st_value
13754 + sym_sec
->output_section
->vma
13755 + sym_sec
->output_offset
);
13756 target_is_micromips_code_p
= ELF_ST_IS_MICROMIPS (isym
->st_other
);
13760 unsigned long indx
;
13761 struct elf_link_hash_entry
*h
;
13763 /* An external symbol. */
13764 indx
= r_symndx
- symtab_hdr
->sh_info
;
13765 h
= elf_sym_hashes (abfd
)[indx
];
13766 BFD_ASSERT (h
!= NULL
);
13768 if (h
->root
.type
!= bfd_link_hash_defined
13769 && h
->root
.type
!= bfd_link_hash_defweak
)
13770 /* This appears to be a reference to an undefined
13771 symbol. Just ignore it -- it will be caught by the
13772 regular reloc processing. */
13775 symval
= (h
->root
.u
.def
.value
13776 + h
->root
.u
.def
.section
->output_section
->vma
13777 + h
->root
.u
.def
.section
->output_offset
);
13778 target_is_micromips_code_p
= (!h
->needs_plt
13779 && ELF_ST_IS_MICROMIPS (h
->other
));
13783 /* For simplicity of coding, we are going to modify the
13784 section contents, the section relocs, and the BFD symbol
13785 table. We must tell the rest of the code not to free up this
13786 information. It would be possible to instead create a table
13787 of changes which have to be made, as is done in coff-mips.c;
13788 that would be more work, but would require less memory when
13789 the linker is run. */
13791 /* Only 32-bit instructions relaxed. */
13792 if (irel
->r_offset
+ 4 > sec
->size
)
13795 opcode
= bfd_get_micromips_32 (abfd
, ptr
);
13797 /* This is the pc-relative distance from the instruction the
13798 relocation is applied to, to the symbol referred. */
13800 - (sec
->output_section
->vma
+ sec
->output_offset
)
13803 /* R_MICROMIPS_HI16 / LUI relaxation to nil, performing relaxation
13804 of corresponding R_MICROMIPS_LO16 to R_MICROMIPS_HI0_LO16 or
13805 R_MICROMIPS_PC23_S2. The R_MICROMIPS_PC23_S2 condition is
13807 (symval % 4 == 0 && IS_BITSIZE (pcrval, 25))
13809 where pcrval has first to be adjusted to apply against the LO16
13810 location (we make the adjustment later on, when we have figured
13811 out the offset). */
13812 if (r_type
== R_MICROMIPS_HI16
&& MATCH (opcode
, lui_insn
))
13814 bfd_boolean bzc
= FALSE
;
13815 unsigned long nextopc
;
13819 /* Give up if the previous reloc was a HI16 against this symbol
13821 if (irel
> internal_relocs
13822 && ELF32_R_TYPE (irel
[-1].r_info
) == R_MICROMIPS_HI16
13823 && ELF32_R_SYM (irel
[-1].r_info
) == r_symndx
)
13826 /* Or if the next reloc is not a LO16 against this symbol. */
13827 if (irel
+ 1 >= irelend
13828 || ELF32_R_TYPE (irel
[1].r_info
) != R_MICROMIPS_LO16
13829 || ELF32_R_SYM (irel
[1].r_info
) != r_symndx
)
13832 /* Or if the second next reloc is a LO16 against this symbol too. */
13833 if (irel
+ 2 >= irelend
13834 && ELF32_R_TYPE (irel
[2].r_info
) == R_MICROMIPS_LO16
13835 && ELF32_R_SYM (irel
[2].r_info
) == r_symndx
)
13838 /* See if the LUI instruction *might* be in a branch delay slot.
13839 We check whether what looks like a 16-bit branch or jump is
13840 actually an immediate argument to a compact branch, and let
13841 it through if so. */
13842 if (irel
->r_offset
>= 2
13843 && check_br16_dslot (abfd
, ptr
- 2)
13844 && !(irel
->r_offset
>= 4
13845 && (bzc
= check_relocated_bzc (abfd
,
13846 ptr
- 4, irel
->r_offset
- 4,
13847 internal_relocs
, irelend
))))
13849 if (irel
->r_offset
>= 4
13851 && check_br32_dslot (abfd
, ptr
- 4))
13854 reg
= OP32_SREG (opcode
);
13856 /* We only relax adjacent instructions or ones separated with
13857 a branch or jump that has a delay slot. The branch or jump
13858 must not fiddle with the register used to hold the address.
13859 Subtract 4 for the LUI itself. */
13860 offset
= irel
[1].r_offset
- irel
[0].r_offset
;
13861 switch (offset
- 4)
13866 if (check_br16 (abfd
, ptr
+ 4, reg
))
13870 if (check_br32 (abfd
, ptr
+ 4, reg
))
13877 nextopc
= bfd_get_micromips_32 (abfd
, contents
+ irel
[1].r_offset
);
13879 /* Give up unless the same register is used with both
13881 if (OP32_SREG (nextopc
) != reg
)
13884 /* Now adjust pcrval, subtracting the offset to the LO16 reloc
13885 and rounding up to take masking of the two LSBs into account. */
13886 pcrval
= ((pcrval
- offset
+ 3) | 3) ^ 3;
13888 /* R_MICROMIPS_LO16 relaxation to R_MICROMIPS_HI0_LO16. */
13889 if (IS_BITSIZE (symval
, 16))
13891 /* Fix the relocation's type. */
13892 irel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_MICROMIPS_HI0_LO16
);
13894 /* Instructions using R_MICROMIPS_LO16 have the base or
13895 source register in bits 20:16. This register becomes $0
13896 (zero) as the result of the R_MICROMIPS_HI16 being 0. */
13897 nextopc
&= ~0x001f0000;
13898 bfd_put_16 (abfd
, (nextopc
>> 16) & 0xffff,
13899 contents
+ irel
[1].r_offset
);
13902 /* R_MICROMIPS_LO16 / ADDIU relaxation to R_MICROMIPS_PC23_S2.
13903 We add 4 to take LUI deletion into account while checking
13904 the PC-relative distance. */
13905 else if (symval
% 4 == 0
13906 && IS_BITSIZE (pcrval
+ 4, 25)
13907 && MATCH (nextopc
, addiu_insn
)
13908 && OP32_TREG (nextopc
) == OP32_SREG (nextopc
)
13909 && OP16_VALID_REG (OP32_TREG (nextopc
)))
13911 /* Fix the relocation's type. */
13912 irel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_MICROMIPS_PC23_S2
);
13914 /* Replace ADDIU with the ADDIUPC version. */
13915 nextopc
= (addiupc_insn
.match
13916 | ADDIUPC_REG_FIELD (OP32_TREG (nextopc
)));
13918 bfd_put_micromips_32 (abfd
, nextopc
,
13919 contents
+ irel
[1].r_offset
);
13922 /* Can't do anything, give up, sigh... */
13926 /* Fix the relocation's type. */
13927 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_MIPS_NONE
);
13929 /* Delete the LUI instruction: 4 bytes at irel->r_offset. */
13934 /* Compact branch relaxation -- due to the multitude of macros
13935 employed by the compiler/assembler, compact branches are not
13936 always generated. Obviously, this can/will be fixed elsewhere,
13937 but there is no drawback in double checking it here. */
13938 else if (r_type
== R_MICROMIPS_PC16_S1
13939 && irel
->r_offset
+ 5 < sec
->size
13940 && ((fndopc
= find_match (opcode
, bz_rs_insns_32
)) >= 0
13941 || (fndopc
= find_match (opcode
, bz_rt_insns_32
)) >= 0)
13943 && (delcnt
= MATCH (bfd_get_16 (abfd
, ptr
+ 4),
13944 nop_insn_16
) ? 2 : 0))
13945 || (irel
->r_offset
+ 7 < sec
->size
13946 && (delcnt
= MATCH (bfd_get_micromips_32 (abfd
,
13948 nop_insn_32
) ? 4 : 0))))
13952 reg
= OP32_SREG (opcode
) ? OP32_SREG (opcode
) : OP32_TREG (opcode
);
13954 /* Replace BEQZ/BNEZ with the compact version. */
13955 opcode
= (bzc_insns_32
[fndopc
].match
13956 | BZC32_REG_FIELD (reg
)
13957 | (opcode
& 0xffff)); /* Addend value. */
13959 bfd_put_micromips_32 (abfd
, opcode
, ptr
);
13961 /* Delete the delay slot NOP: two or four bytes from
13962 irel->offset + 4; delcnt has already been set above. */
13966 /* R_MICROMIPS_PC16_S1 relaxation to R_MICROMIPS_PC10_S1. We need
13967 to check the distance from the next instruction, so subtract 2. */
13969 && r_type
== R_MICROMIPS_PC16_S1
13970 && IS_BITSIZE (pcrval
- 2, 11)
13971 && find_match (opcode
, b_insns_32
) >= 0)
13973 /* Fix the relocation's type. */
13974 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_MICROMIPS_PC10_S1
);
13976 /* Replace the 32-bit opcode with a 16-bit opcode. */
13979 | (opcode
& 0x3ff)), /* Addend value. */
13982 /* Delete 2 bytes from irel->r_offset + 2. */
13987 /* R_MICROMIPS_PC16_S1 relaxation to R_MICROMIPS_PC7_S1. We need
13988 to check the distance from the next instruction, so subtract 2. */
13990 && r_type
== R_MICROMIPS_PC16_S1
13991 && IS_BITSIZE (pcrval
- 2, 8)
13992 && (((fndopc
= find_match (opcode
, bz_rs_insns_32
)) >= 0
13993 && OP16_VALID_REG (OP32_SREG (opcode
)))
13994 || ((fndopc
= find_match (opcode
, bz_rt_insns_32
)) >= 0
13995 && OP16_VALID_REG (OP32_TREG (opcode
)))))
13999 reg
= OP32_SREG (opcode
) ? OP32_SREG (opcode
) : OP32_TREG (opcode
);
14001 /* Fix the relocation's type. */
14002 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_MICROMIPS_PC7_S1
);
14004 /* Replace the 32-bit opcode with a 16-bit opcode. */
14006 (bz_insns_16
[fndopc
].match
14007 | BZ16_REG_FIELD (reg
)
14008 | (opcode
& 0x7f)), /* Addend value. */
14011 /* Delete 2 bytes from irel->r_offset + 2. */
14016 /* R_MICROMIPS_26_S1 -- JAL to JALS relaxation for microMIPS targets. */
14018 && r_type
== R_MICROMIPS_26_S1
14019 && target_is_micromips_code_p
14020 && irel
->r_offset
+ 7 < sec
->size
14021 && MATCH (opcode
, jal_insn_32_bd32
))
14023 unsigned long n32opc
;
14024 bfd_boolean relaxed
= FALSE
;
14026 n32opc
= bfd_get_micromips_32 (abfd
, ptr
+ 4);
14028 if (MATCH (n32opc
, nop_insn_32
))
14030 /* Replace delay slot 32-bit NOP with a 16-bit NOP. */
14031 bfd_put_16 (abfd
, nop_insn_16
.match
, ptr
+ 4);
14035 else if (find_match (n32opc
, move_insns_32
) >= 0)
14037 /* Replace delay slot 32-bit MOVE with 16-bit MOVE. */
14039 (move_insn_16
.match
14040 | MOVE16_RD_FIELD (MOVE32_RD (n32opc
))
14041 | MOVE16_RS_FIELD (MOVE32_RS (n32opc
))),
14046 /* Other 32-bit instructions relaxable to 16-bit
14047 instructions will be handled here later. */
14051 /* JAL with 32-bit delay slot that is changed to a JALS
14052 with 16-bit delay slot. */
14053 bfd_put_micromips_32 (abfd
, jal_insn_32_bd16
.match
, ptr
);
14055 /* Delete 2 bytes from irel->r_offset + 6. */
14063 /* Note that we've changed the relocs, section contents, etc. */
14064 elf_section_data (sec
)->relocs
= internal_relocs
;
14065 elf_section_data (sec
)->this_hdr
.contents
= contents
;
14066 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
14068 /* Delete bytes depending on the delcnt and deloff. */
14069 if (!mips_elf_relax_delete_bytes (abfd
, sec
,
14070 irel
->r_offset
+ deloff
, delcnt
))
14073 /* That will change things, so we should relax again.
14074 Note that this is not required, and it may be slow. */
14079 if (isymbuf
!= NULL
14080 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
14082 if (! link_info
->keep_memory
)
14086 /* Cache the symbols for elf_link_input_bfd. */
14087 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
14091 if (contents
!= NULL
14092 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
14094 if (! link_info
->keep_memory
)
14098 /* Cache the section contents for elf_link_input_bfd. */
14099 elf_section_data (sec
)->this_hdr
.contents
= contents
;
14103 if (internal_relocs
!= NULL
14104 && elf_section_data (sec
)->relocs
!= internal_relocs
)
14105 free (internal_relocs
);
14110 if (isymbuf
!= NULL
14111 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
14113 if (contents
!= NULL
14114 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
14116 if (internal_relocs
!= NULL
14117 && elf_section_data (sec
)->relocs
!= internal_relocs
)
14118 free (internal_relocs
);
14123 /* Create a MIPS ELF linker hash table. */
14125 struct bfd_link_hash_table
*
14126 _bfd_mips_elf_link_hash_table_create (bfd
*abfd
)
14128 struct mips_elf_link_hash_table
*ret
;
14129 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
14131 ret
= bfd_zmalloc (amt
);
14135 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
14136 mips_elf_link_hash_newfunc
,
14137 sizeof (struct mips_elf_link_hash_entry
),
14143 ret
->root
.init_plt_refcount
.plist
= NULL
;
14144 ret
->root
.init_plt_offset
.plist
= NULL
;
14146 return &ret
->root
.root
;
14149 /* Likewise, but indicate that the target is VxWorks. */
14151 struct bfd_link_hash_table
*
14152 _bfd_mips_vxworks_link_hash_table_create (bfd
*abfd
)
14154 struct bfd_link_hash_table
*ret
;
14156 ret
= _bfd_mips_elf_link_hash_table_create (abfd
);
14159 struct mips_elf_link_hash_table
*htab
;
14161 htab
= (struct mips_elf_link_hash_table
*) ret
;
14162 htab
->use_plts_and_copy_relocs
= TRUE
;
14163 htab
->is_vxworks
= TRUE
;
14168 /* A function that the linker calls if we are allowed to use PLTs
14169 and copy relocs. */
14172 _bfd_mips_elf_use_plts_and_copy_relocs (struct bfd_link_info
*info
)
14174 mips_elf_hash_table (info
)->use_plts_and_copy_relocs
= TRUE
;
14177 /* A function that the linker calls to select between all or only
14178 32-bit microMIPS instructions, and between making or ignoring
14179 branch relocation checks for invalid transitions between ISA modes.
14180 Also record whether we have been configured for a GNU target. */
14183 _bfd_mips_elf_linker_flags (struct bfd_link_info
*info
, bfd_boolean insn32
,
14184 bfd_boolean ignore_branch_isa
,
14185 bfd_boolean gnu_target
)
14187 mips_elf_hash_table (info
)->insn32
= insn32
;
14188 mips_elf_hash_table (info
)->ignore_branch_isa
= ignore_branch_isa
;
14189 mips_elf_hash_table (info
)->gnu_target
= gnu_target
;
14192 /* Structure for saying that BFD machine EXTENSION extends BASE. */
14194 struct mips_mach_extension
14196 unsigned long extension
, base
;
14200 /* An array describing how BFD machines relate to one another. The entries
14201 are ordered topologically with MIPS I extensions listed last. */
14203 static const struct mips_mach_extension mips_mach_extensions
[] =
14205 /* MIPS64r2 extensions. */
14206 { bfd_mach_mips_octeon3
, bfd_mach_mips_octeon2
},
14207 { bfd_mach_mips_octeon2
, bfd_mach_mips_octeonp
},
14208 { bfd_mach_mips_octeonp
, bfd_mach_mips_octeon
},
14209 { bfd_mach_mips_octeon
, bfd_mach_mipsisa64r2
},
14210 { bfd_mach_mips_gs264e
, bfd_mach_mips_gs464e
},
14211 { bfd_mach_mips_gs464e
, bfd_mach_mips_gs464
},
14212 { bfd_mach_mips_gs464
, bfd_mach_mipsisa64r2
},
14214 /* MIPS64 extensions. */
14215 { bfd_mach_mipsisa64r2
, bfd_mach_mipsisa64
},
14216 { bfd_mach_mips_sb1
, bfd_mach_mipsisa64
},
14217 { bfd_mach_mips_xlr
, bfd_mach_mipsisa64
},
14219 /* MIPS V extensions. */
14220 { bfd_mach_mipsisa64
, bfd_mach_mips5
},
14222 /* R10000 extensions. */
14223 { bfd_mach_mips12000
, bfd_mach_mips10000
},
14224 { bfd_mach_mips14000
, bfd_mach_mips10000
},
14225 { bfd_mach_mips16000
, bfd_mach_mips10000
},
14227 /* R5000 extensions. Note: the vr5500 ISA is an extension of the core
14228 vr5400 ISA, but doesn't include the multimedia stuff. It seems
14229 better to allow vr5400 and vr5500 code to be merged anyway, since
14230 many libraries will just use the core ISA. Perhaps we could add
14231 some sort of ASE flag if this ever proves a problem. */
14232 { bfd_mach_mips5500
, bfd_mach_mips5400
},
14233 { bfd_mach_mips5400
, bfd_mach_mips5000
},
14235 /* MIPS IV extensions. */
14236 { bfd_mach_mips5
, bfd_mach_mips8000
},
14237 { bfd_mach_mips10000
, bfd_mach_mips8000
},
14238 { bfd_mach_mips5000
, bfd_mach_mips8000
},
14239 { bfd_mach_mips7000
, bfd_mach_mips8000
},
14240 { bfd_mach_mips9000
, bfd_mach_mips8000
},
14242 /* VR4100 extensions. */
14243 { bfd_mach_mips4120
, bfd_mach_mips4100
},
14244 { bfd_mach_mips4111
, bfd_mach_mips4100
},
14246 /* MIPS III extensions. */
14247 { bfd_mach_mips_loongson_2e
, bfd_mach_mips4000
},
14248 { bfd_mach_mips_loongson_2f
, bfd_mach_mips4000
},
14249 { bfd_mach_mips8000
, bfd_mach_mips4000
},
14250 { bfd_mach_mips4650
, bfd_mach_mips4000
},
14251 { bfd_mach_mips4600
, bfd_mach_mips4000
},
14252 { bfd_mach_mips4400
, bfd_mach_mips4000
},
14253 { bfd_mach_mips4300
, bfd_mach_mips4000
},
14254 { bfd_mach_mips4100
, bfd_mach_mips4000
},
14255 { bfd_mach_mips5900
, bfd_mach_mips4000
},
14257 /* MIPS32r3 extensions. */
14258 { bfd_mach_mips_interaptiv_mr2
, bfd_mach_mipsisa32r3
},
14260 /* MIPS32r2 extensions. */
14261 { bfd_mach_mipsisa32r3
, bfd_mach_mipsisa32r2
},
14263 /* MIPS32 extensions. */
14264 { bfd_mach_mipsisa32r2
, bfd_mach_mipsisa32
},
14266 /* MIPS II extensions. */
14267 { bfd_mach_mips4000
, bfd_mach_mips6000
},
14268 { bfd_mach_mipsisa32
, bfd_mach_mips6000
},
14269 { bfd_mach_mips4010
, bfd_mach_mips6000
},
14271 /* MIPS I extensions. */
14272 { bfd_mach_mips6000
, bfd_mach_mips3000
},
14273 { bfd_mach_mips3900
, bfd_mach_mips3000
}
14276 /* Return true if bfd machine EXTENSION is an extension of machine BASE. */
14279 mips_mach_extends_p (unsigned long base
, unsigned long extension
)
14283 if (extension
== base
)
14286 if (base
== bfd_mach_mipsisa32
14287 && mips_mach_extends_p (bfd_mach_mipsisa64
, extension
))
14290 if (base
== bfd_mach_mipsisa32r2
14291 && mips_mach_extends_p (bfd_mach_mipsisa64r2
, extension
))
14294 for (i
= 0; i
< ARRAY_SIZE (mips_mach_extensions
); i
++)
14295 if (extension
== mips_mach_extensions
[i
].extension
)
14297 extension
= mips_mach_extensions
[i
].base
;
14298 if (extension
== base
)
14305 /* Return the BFD mach for each .MIPS.abiflags ISA Extension. */
14307 static unsigned long
14308 bfd_mips_isa_ext_mach (unsigned int isa_ext
)
14312 case AFL_EXT_3900
: return bfd_mach_mips3900
;
14313 case AFL_EXT_4010
: return bfd_mach_mips4010
;
14314 case AFL_EXT_4100
: return bfd_mach_mips4100
;
14315 case AFL_EXT_4111
: return bfd_mach_mips4111
;
14316 case AFL_EXT_4120
: return bfd_mach_mips4120
;
14317 case AFL_EXT_4650
: return bfd_mach_mips4650
;
14318 case AFL_EXT_5400
: return bfd_mach_mips5400
;
14319 case AFL_EXT_5500
: return bfd_mach_mips5500
;
14320 case AFL_EXT_5900
: return bfd_mach_mips5900
;
14321 case AFL_EXT_10000
: return bfd_mach_mips10000
;
14322 case AFL_EXT_LOONGSON_2E
: return bfd_mach_mips_loongson_2e
;
14323 case AFL_EXT_LOONGSON_2F
: return bfd_mach_mips_loongson_2f
;
14324 case AFL_EXT_SB1
: return bfd_mach_mips_sb1
;
14325 case AFL_EXT_OCTEON
: return bfd_mach_mips_octeon
;
14326 case AFL_EXT_OCTEONP
: return bfd_mach_mips_octeonp
;
14327 case AFL_EXT_OCTEON2
: return bfd_mach_mips_octeon2
;
14328 case AFL_EXT_XLR
: return bfd_mach_mips_xlr
;
14329 default: return bfd_mach_mips3000
;
14333 /* Return the .MIPS.abiflags value representing each ISA Extension. */
14336 bfd_mips_isa_ext (bfd
*abfd
)
14338 switch (bfd_get_mach (abfd
))
14340 case bfd_mach_mips3900
: return AFL_EXT_3900
;
14341 case bfd_mach_mips4010
: return AFL_EXT_4010
;
14342 case bfd_mach_mips4100
: return AFL_EXT_4100
;
14343 case bfd_mach_mips4111
: return AFL_EXT_4111
;
14344 case bfd_mach_mips4120
: return AFL_EXT_4120
;
14345 case bfd_mach_mips4650
: return AFL_EXT_4650
;
14346 case bfd_mach_mips5400
: return AFL_EXT_5400
;
14347 case bfd_mach_mips5500
: return AFL_EXT_5500
;
14348 case bfd_mach_mips5900
: return AFL_EXT_5900
;
14349 case bfd_mach_mips10000
: return AFL_EXT_10000
;
14350 case bfd_mach_mips_loongson_2e
: return AFL_EXT_LOONGSON_2E
;
14351 case bfd_mach_mips_loongson_2f
: return AFL_EXT_LOONGSON_2F
;
14352 case bfd_mach_mips_sb1
: return AFL_EXT_SB1
;
14353 case bfd_mach_mips_octeon
: return AFL_EXT_OCTEON
;
14354 case bfd_mach_mips_octeonp
: return AFL_EXT_OCTEONP
;
14355 case bfd_mach_mips_octeon3
: return AFL_EXT_OCTEON3
;
14356 case bfd_mach_mips_octeon2
: return AFL_EXT_OCTEON2
;
14357 case bfd_mach_mips_xlr
: return AFL_EXT_XLR
;
14358 case bfd_mach_mips_interaptiv_mr2
:
14359 return AFL_EXT_INTERAPTIV_MR2
;
14364 /* Encode ISA level and revision as a single value. */
14365 #define LEVEL_REV(LEV,REV) ((LEV) << 3 | (REV))
14367 /* Decode a single value into level and revision. */
14368 #define ISA_LEVEL(LEVREV) ((LEVREV) >> 3)
14369 #define ISA_REV(LEVREV) ((LEVREV) & 0x7)
14371 /* Update the isa_level, isa_rev, isa_ext fields of abiflags. */
14374 update_mips_abiflags_isa (bfd
*abfd
, Elf_Internal_ABIFlags_v0
*abiflags
)
14377 switch (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
)
14379 case E_MIPS_ARCH_1
: new_isa
= LEVEL_REV (1, 0); break;
14380 case E_MIPS_ARCH_2
: new_isa
= LEVEL_REV (2, 0); break;
14381 case E_MIPS_ARCH_3
: new_isa
= LEVEL_REV (3, 0); break;
14382 case E_MIPS_ARCH_4
: new_isa
= LEVEL_REV (4, 0); break;
14383 case E_MIPS_ARCH_5
: new_isa
= LEVEL_REV (5, 0); break;
14384 case E_MIPS_ARCH_32
: new_isa
= LEVEL_REV (32, 1); break;
14385 case E_MIPS_ARCH_32R2
: new_isa
= LEVEL_REV (32, 2); break;
14386 case E_MIPS_ARCH_32R6
: new_isa
= LEVEL_REV (32, 6); break;
14387 case E_MIPS_ARCH_64
: new_isa
= LEVEL_REV (64, 1); break;
14388 case E_MIPS_ARCH_64R2
: new_isa
= LEVEL_REV (64, 2); break;
14389 case E_MIPS_ARCH_64R6
: new_isa
= LEVEL_REV (64, 6); break;
14392 /* xgettext:c-format */
14393 (_("%pB: unknown architecture %s"),
14394 abfd
, bfd_printable_name (abfd
));
14397 if (new_isa
> LEVEL_REV (abiflags
->isa_level
, abiflags
->isa_rev
))
14399 abiflags
->isa_level
= ISA_LEVEL (new_isa
);
14400 abiflags
->isa_rev
= ISA_REV (new_isa
);
14403 /* Update the isa_ext if ABFD describes a further extension. */
14404 if (mips_mach_extends_p (bfd_mips_isa_ext_mach (abiflags
->isa_ext
),
14405 bfd_get_mach (abfd
)))
14406 abiflags
->isa_ext
= bfd_mips_isa_ext (abfd
);
14409 /* Return true if the given ELF header flags describe a 32-bit binary. */
14412 mips_32bit_flags_p (flagword flags
)
14414 return ((flags
& EF_MIPS_32BITMODE
) != 0
14415 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
14416 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
14417 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
14418 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
14419 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
14420 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
14421 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R6
);
14424 /* Infer the content of the ABI flags based on the elf header. */
14427 infer_mips_abiflags (bfd
*abfd
, Elf_Internal_ABIFlags_v0
* abiflags
)
14429 obj_attribute
*in_attr
;
14431 memset (abiflags
, 0, sizeof (Elf_Internal_ABIFlags_v0
));
14432 update_mips_abiflags_isa (abfd
, abiflags
);
14434 if (mips_32bit_flags_p (elf_elfheader (abfd
)->e_flags
))
14435 abiflags
->gpr_size
= AFL_REG_32
;
14437 abiflags
->gpr_size
= AFL_REG_64
;
14439 abiflags
->cpr1_size
= AFL_REG_NONE
;
14441 in_attr
= elf_known_obj_attributes (abfd
)[OBJ_ATTR_GNU
];
14442 abiflags
->fp_abi
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
14444 if (abiflags
->fp_abi
== Val_GNU_MIPS_ABI_FP_SINGLE
14445 || abiflags
->fp_abi
== Val_GNU_MIPS_ABI_FP_XX
14446 || (abiflags
->fp_abi
== Val_GNU_MIPS_ABI_FP_DOUBLE
14447 && abiflags
->gpr_size
== AFL_REG_32
))
14448 abiflags
->cpr1_size
= AFL_REG_32
;
14449 else if (abiflags
->fp_abi
== Val_GNU_MIPS_ABI_FP_DOUBLE
14450 || abiflags
->fp_abi
== Val_GNU_MIPS_ABI_FP_64
14451 || abiflags
->fp_abi
== Val_GNU_MIPS_ABI_FP_64A
)
14452 abiflags
->cpr1_size
= AFL_REG_64
;
14454 abiflags
->cpr2_size
= AFL_REG_NONE
;
14456 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
14457 abiflags
->ases
|= AFL_ASE_MDMX
;
14458 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
14459 abiflags
->ases
|= AFL_ASE_MIPS16
;
14460 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
14461 abiflags
->ases
|= AFL_ASE_MICROMIPS
;
14463 if (abiflags
->fp_abi
!= Val_GNU_MIPS_ABI_FP_ANY
14464 && abiflags
->fp_abi
!= Val_GNU_MIPS_ABI_FP_SOFT
14465 && abiflags
->fp_abi
!= Val_GNU_MIPS_ABI_FP_64A
14466 && abiflags
->isa_level
>= 32
14467 && abiflags
->ases
!= AFL_ASE_LOONGSON_EXT
)
14468 abiflags
->flags1
|= AFL_FLAGS1_ODDSPREG
;
14471 /* We need to use a special link routine to handle the .reginfo and
14472 the .mdebug sections. We need to merge all instances of these
14473 sections together, not write them all out sequentially. */
14476 _bfd_mips_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
14479 struct bfd_link_order
*p
;
14480 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
14481 asection
*rtproc_sec
, *abiflags_sec
;
14482 Elf32_RegInfo reginfo
;
14483 struct ecoff_debug_info debug
;
14484 struct mips_htab_traverse_info hti
;
14485 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
14486 const struct ecoff_debug_swap
*swap
= bed
->elf_backend_ecoff_debug_swap
;
14487 HDRR
*symhdr
= &debug
.symbolic_header
;
14488 void *mdebug_handle
= NULL
;
14493 struct mips_elf_link_hash_table
*htab
;
14495 static const char * const secname
[] =
14497 ".text", ".init", ".fini", ".data",
14498 ".rodata", ".sdata", ".sbss", ".bss"
14500 static const int sc
[] =
14502 scText
, scInit
, scFini
, scData
,
14503 scRData
, scSData
, scSBss
, scBss
14506 htab
= mips_elf_hash_table (info
);
14507 BFD_ASSERT (htab
!= NULL
);
14509 /* Sort the dynamic symbols so that those with GOT entries come after
14511 if (!mips_elf_sort_hash_table (abfd
, info
))
14514 /* Create any scheduled LA25 stubs. */
14516 hti
.output_bfd
= abfd
;
14518 htab_traverse (htab
->la25_stubs
, mips_elf_create_la25_stub
, &hti
);
14522 /* Get a value for the GP register. */
14523 if (elf_gp (abfd
) == 0)
14525 struct bfd_link_hash_entry
*h
;
14527 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
14528 if (h
!= NULL
&& h
->type
== bfd_link_hash_defined
)
14529 elf_gp (abfd
) = (h
->u
.def
.value
14530 + h
->u
.def
.section
->output_section
->vma
14531 + h
->u
.def
.section
->output_offset
);
14532 else if (htab
->is_vxworks
14533 && (h
= bfd_link_hash_lookup (info
->hash
,
14534 "_GLOBAL_OFFSET_TABLE_",
14535 FALSE
, FALSE
, TRUE
))
14536 && h
->type
== bfd_link_hash_defined
)
14537 elf_gp (abfd
) = (h
->u
.def
.section
->output_section
->vma
14538 + h
->u
.def
.section
->output_offset
14540 else if (bfd_link_relocatable (info
))
14542 bfd_vma lo
= MINUS_ONE
;
14544 /* Find the GP-relative section with the lowest offset. */
14545 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
14547 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
14550 /* And calculate GP relative to that. */
14551 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (info
);
14555 /* If the relocate_section function needs to do a reloc
14556 involving the GP value, it should make a reloc_dangerous
14557 callback to warn that GP is not defined. */
14561 /* Go through the sections and collect the .reginfo and .mdebug
14563 abiflags_sec
= NULL
;
14564 reginfo_sec
= NULL
;
14566 gptab_data_sec
= NULL
;
14567 gptab_bss_sec
= NULL
;
14568 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
14570 if (strcmp (o
->name
, ".MIPS.abiflags") == 0)
14572 /* We have found the .MIPS.abiflags section in the output file.
14573 Look through all the link_orders comprising it and remove them.
14574 The data is merged in _bfd_mips_elf_merge_private_bfd_data. */
14575 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
14577 asection
*input_section
;
14579 if (p
->type
!= bfd_indirect_link_order
)
14581 if (p
->type
== bfd_data_link_order
)
14586 input_section
= p
->u
.indirect
.section
;
14588 /* Hack: reset the SEC_HAS_CONTENTS flag so that
14589 elf_link_input_bfd ignores this section. */
14590 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
14593 /* Size has been set in _bfd_mips_elf_always_size_sections. */
14594 BFD_ASSERT(o
->size
== sizeof (Elf_External_ABIFlags_v0
));
14596 /* Skip this section later on (I don't think this currently
14597 matters, but someday it might). */
14598 o
->map_head
.link_order
= NULL
;
14603 if (strcmp (o
->name
, ".reginfo") == 0)
14605 memset (®info
, 0, sizeof reginfo
);
14607 /* We have found the .reginfo section in the output file.
14608 Look through all the link_orders comprising it and merge
14609 the information together. */
14610 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
14612 asection
*input_section
;
14614 Elf32_External_RegInfo ext
;
14618 if (p
->type
!= bfd_indirect_link_order
)
14620 if (p
->type
== bfd_data_link_order
)
14625 input_section
= p
->u
.indirect
.section
;
14626 input_bfd
= input_section
->owner
;
14628 sz
= (input_section
->size
< sizeof (ext
)
14629 ? input_section
->size
: sizeof (ext
));
14630 memset (&ext
, 0, sizeof (ext
));
14631 if (! bfd_get_section_contents (input_bfd
, input_section
,
14635 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
14637 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
14638 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
14639 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
14640 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
14641 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
14643 /* ri_gp_value is set by the function
14644 `_bfd_mips_elf_section_processing' when the section is
14645 finally written out. */
14647 /* Hack: reset the SEC_HAS_CONTENTS flag so that
14648 elf_link_input_bfd ignores this section. */
14649 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
14652 /* Size has been set in _bfd_mips_elf_always_size_sections. */
14653 BFD_ASSERT(o
->size
== sizeof (Elf32_External_RegInfo
));
14655 /* Skip this section later on (I don't think this currently
14656 matters, but someday it might). */
14657 o
->map_head
.link_order
= NULL
;
14662 if (strcmp (o
->name
, ".mdebug") == 0)
14664 struct extsym_info einfo
;
14667 /* We have found the .mdebug section in the output file.
14668 Look through all the link_orders comprising it and merge
14669 the information together. */
14670 symhdr
->magic
= swap
->sym_magic
;
14671 /* FIXME: What should the version stamp be? */
14672 symhdr
->vstamp
= 0;
14673 symhdr
->ilineMax
= 0;
14674 symhdr
->cbLine
= 0;
14675 symhdr
->idnMax
= 0;
14676 symhdr
->ipdMax
= 0;
14677 symhdr
->isymMax
= 0;
14678 symhdr
->ioptMax
= 0;
14679 symhdr
->iauxMax
= 0;
14680 symhdr
->issMax
= 0;
14681 symhdr
->issExtMax
= 0;
14682 symhdr
->ifdMax
= 0;
14684 symhdr
->iextMax
= 0;
14686 /* We accumulate the debugging information itself in the
14687 debug_info structure. */
14689 debug
.external_dnr
= NULL
;
14690 debug
.external_pdr
= NULL
;
14691 debug
.external_sym
= NULL
;
14692 debug
.external_opt
= NULL
;
14693 debug
.external_aux
= NULL
;
14695 debug
.ssext
= debug
.ssext_end
= NULL
;
14696 debug
.external_fdr
= NULL
;
14697 debug
.external_rfd
= NULL
;
14698 debug
.external_ext
= debug
.external_ext_end
= NULL
;
14700 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
14701 if (mdebug_handle
== NULL
)
14705 esym
.cobol_main
= 0;
14709 esym
.asym
.iss
= issNil
;
14710 esym
.asym
.st
= stLocal
;
14711 esym
.asym
.reserved
= 0;
14712 esym
.asym
.index
= indexNil
;
14714 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
14716 esym
.asym
.sc
= sc
[i
];
14717 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
14720 esym
.asym
.value
= s
->vma
;
14721 last
= s
->vma
+ s
->size
;
14724 esym
.asym
.value
= last
;
14725 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
14726 secname
[i
], &esym
))
14730 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
14732 asection
*input_section
;
14734 const struct ecoff_debug_swap
*input_swap
;
14735 struct ecoff_debug_info input_debug
;
14739 if (p
->type
!= bfd_indirect_link_order
)
14741 if (p
->type
== bfd_data_link_order
)
14746 input_section
= p
->u
.indirect
.section
;
14747 input_bfd
= input_section
->owner
;
14749 if (!is_mips_elf (input_bfd
))
14751 /* I don't know what a non MIPS ELF bfd would be
14752 doing with a .mdebug section, but I don't really
14753 want to deal with it. */
14757 input_swap
= (get_elf_backend_data (input_bfd
)
14758 ->elf_backend_ecoff_debug_swap
);
14760 BFD_ASSERT (p
->size
== input_section
->size
);
14762 /* The ECOFF linking code expects that we have already
14763 read in the debugging information and set up an
14764 ecoff_debug_info structure, so we do that now. */
14765 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
14769 if (! (bfd_ecoff_debug_accumulate
14770 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
14771 &input_debug
, input_swap
, info
)))
14774 /* Loop through the external symbols. For each one with
14775 interesting information, try to find the symbol in
14776 the linker global hash table and save the information
14777 for the output external symbols. */
14778 eraw_src
= input_debug
.external_ext
;
14779 eraw_end
= (eraw_src
14780 + (input_debug
.symbolic_header
.iextMax
14781 * input_swap
->external_ext_size
));
14783 eraw_src
< eraw_end
;
14784 eraw_src
+= input_swap
->external_ext_size
)
14788 struct mips_elf_link_hash_entry
*h
;
14790 (*input_swap
->swap_ext_in
) (input_bfd
, eraw_src
, &ext
);
14791 if (ext
.asym
.sc
== scNil
14792 || ext
.asym
.sc
== scUndefined
14793 || ext
.asym
.sc
== scSUndefined
)
14796 name
= input_debug
.ssext
+ ext
.asym
.iss
;
14797 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
14798 name
, FALSE
, FALSE
, TRUE
);
14799 if (h
== NULL
|| h
->esym
.ifd
!= -2)
14804 BFD_ASSERT (ext
.ifd
14805 < input_debug
.symbolic_header
.ifdMax
);
14806 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
14812 /* Free up the information we just read. */
14813 free (input_debug
.line
);
14814 free (input_debug
.external_dnr
);
14815 free (input_debug
.external_pdr
);
14816 free (input_debug
.external_sym
);
14817 free (input_debug
.external_opt
);
14818 free (input_debug
.external_aux
);
14819 free (input_debug
.ss
);
14820 free (input_debug
.ssext
);
14821 free (input_debug
.external_fdr
);
14822 free (input_debug
.external_rfd
);
14823 free (input_debug
.external_ext
);
14825 /* Hack: reset the SEC_HAS_CONTENTS flag so that
14826 elf_link_input_bfd ignores this section. */
14827 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
14830 if (SGI_COMPAT (abfd
) && bfd_link_pic (info
))
14832 /* Create .rtproc section. */
14833 rtproc_sec
= bfd_get_linker_section (abfd
, ".rtproc");
14834 if (rtproc_sec
== NULL
)
14836 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
14837 | SEC_LINKER_CREATED
| SEC_READONLY
);
14839 rtproc_sec
= bfd_make_section_anyway_with_flags (abfd
,
14842 if (rtproc_sec
== NULL
14843 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
14847 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
14853 /* Build the external symbol information. */
14856 einfo
.debug
= &debug
;
14858 einfo
.failed
= FALSE
;
14859 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
14860 mips_elf_output_extsym
, &einfo
);
14864 /* Set the size of the .mdebug section. */
14865 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
14867 /* Skip this section later on (I don't think this currently
14868 matters, but someday it might). */
14869 o
->map_head
.link_order
= NULL
;
14874 if (CONST_STRNEQ (o
->name
, ".gptab."))
14876 const char *subname
;
14879 Elf32_External_gptab
*ext_tab
;
14882 /* The .gptab.sdata and .gptab.sbss sections hold
14883 information describing how the small data area would
14884 change depending upon the -G switch. These sections
14885 not used in executables files. */
14886 if (! bfd_link_relocatable (info
))
14888 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
14890 asection
*input_section
;
14892 if (p
->type
!= bfd_indirect_link_order
)
14894 if (p
->type
== bfd_data_link_order
)
14899 input_section
= p
->u
.indirect
.section
;
14901 /* Hack: reset the SEC_HAS_CONTENTS flag so that
14902 elf_link_input_bfd ignores this section. */
14903 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
14906 /* Skip this section later on (I don't think this
14907 currently matters, but someday it might). */
14908 o
->map_head
.link_order
= NULL
;
14910 /* Really remove the section. */
14911 bfd_section_list_remove (abfd
, o
);
14912 --abfd
->section_count
;
14917 /* There is one gptab for initialized data, and one for
14918 uninitialized data. */
14919 if (strcmp (o
->name
, ".gptab.sdata") == 0)
14920 gptab_data_sec
= o
;
14921 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
14926 /* xgettext:c-format */
14927 (_("%pB: illegal section name `%pA'"), abfd
, o
);
14928 bfd_set_error (bfd_error_nonrepresentable_section
);
14932 /* The linker script always combines .gptab.data and
14933 .gptab.sdata into .gptab.sdata, and likewise for
14934 .gptab.bss and .gptab.sbss. It is possible that there is
14935 no .sdata or .sbss section in the output file, in which
14936 case we must change the name of the output section. */
14937 subname
= o
->name
+ sizeof ".gptab" - 1;
14938 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
14940 if (o
== gptab_data_sec
)
14941 o
->name
= ".gptab.data";
14943 o
->name
= ".gptab.bss";
14944 subname
= o
->name
+ sizeof ".gptab" - 1;
14945 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
14948 /* Set up the first entry. */
14950 amt
= c
* sizeof (Elf32_gptab
);
14951 tab
= bfd_malloc (amt
);
14954 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
14955 tab
[0].gt_header
.gt_unused
= 0;
14957 /* Combine the input sections. */
14958 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
14960 asection
*input_section
;
14962 bfd_size_type size
;
14963 unsigned long last
;
14964 bfd_size_type gpentry
;
14966 if (p
->type
!= bfd_indirect_link_order
)
14968 if (p
->type
== bfd_data_link_order
)
14973 input_section
= p
->u
.indirect
.section
;
14974 input_bfd
= input_section
->owner
;
14976 /* Combine the gptab entries for this input section one
14977 by one. We know that the input gptab entries are
14978 sorted by ascending -G value. */
14979 size
= input_section
->size
;
14981 for (gpentry
= sizeof (Elf32_External_gptab
);
14983 gpentry
+= sizeof (Elf32_External_gptab
))
14985 Elf32_External_gptab ext_gptab
;
14986 Elf32_gptab int_gptab
;
14992 if (! (bfd_get_section_contents
14993 (input_bfd
, input_section
, &ext_gptab
, gpentry
,
14994 sizeof (Elf32_External_gptab
))))
15000 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
15002 val
= int_gptab
.gt_entry
.gt_g_value
;
15003 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
15006 for (look
= 1; look
< c
; look
++)
15008 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
15009 tab
[look
].gt_entry
.gt_bytes
+= add
;
15011 if (tab
[look
].gt_entry
.gt_g_value
== val
)
15017 Elf32_gptab
*new_tab
;
15020 /* We need a new table entry. */
15021 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
15022 new_tab
= bfd_realloc (tab
, amt
);
15023 if (new_tab
== NULL
)
15029 tab
[c
].gt_entry
.gt_g_value
= val
;
15030 tab
[c
].gt_entry
.gt_bytes
= add
;
15032 /* Merge in the size for the next smallest -G
15033 value, since that will be implied by this new
15036 for (look
= 1; look
< c
; look
++)
15038 if (tab
[look
].gt_entry
.gt_g_value
< val
15040 || (tab
[look
].gt_entry
.gt_g_value
15041 > tab
[max
].gt_entry
.gt_g_value
)))
15045 tab
[c
].gt_entry
.gt_bytes
+=
15046 tab
[max
].gt_entry
.gt_bytes
;
15051 last
= int_gptab
.gt_entry
.gt_bytes
;
15054 /* Hack: reset the SEC_HAS_CONTENTS flag so that
15055 elf_link_input_bfd ignores this section. */
15056 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
15059 /* The table must be sorted by -G value. */
15061 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
15063 /* Swap out the table. */
15064 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
15065 ext_tab
= bfd_alloc (abfd
, amt
);
15066 if (ext_tab
== NULL
)
15072 for (j
= 0; j
< c
; j
++)
15073 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
15076 o
->size
= c
* sizeof (Elf32_External_gptab
);
15077 o
->contents
= (bfd_byte
*) ext_tab
;
15079 /* Skip this section later on (I don't think this currently
15080 matters, but someday it might). */
15081 o
->map_head
.link_order
= NULL
;
15085 /* Invoke the regular ELF backend linker to do all the work. */
15086 if (!bfd_elf_final_link (abfd
, info
))
15089 /* Now write out the computed sections. */
15091 if (abiflags_sec
!= NULL
)
15093 Elf_External_ABIFlags_v0 ext
;
15094 Elf_Internal_ABIFlags_v0
*abiflags
;
15096 abiflags
= &mips_elf_tdata (abfd
)->abiflags
;
15098 /* Set up the abiflags if no valid input sections were found. */
15099 if (!mips_elf_tdata (abfd
)->abiflags_valid
)
15101 infer_mips_abiflags (abfd
, abiflags
);
15102 mips_elf_tdata (abfd
)->abiflags_valid
= TRUE
;
15104 bfd_mips_elf_swap_abiflags_v0_out (abfd
, abiflags
, &ext
);
15105 if (! bfd_set_section_contents (abfd
, abiflags_sec
, &ext
, 0, sizeof ext
))
15109 if (reginfo_sec
!= NULL
)
15111 Elf32_External_RegInfo ext
;
15113 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
15114 if (! bfd_set_section_contents (abfd
, reginfo_sec
, &ext
, 0, sizeof ext
))
15118 if (mdebug_sec
!= NULL
)
15120 BFD_ASSERT (abfd
->output_has_begun
);
15121 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
15123 mdebug_sec
->filepos
))
15126 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
15129 if (gptab_data_sec
!= NULL
)
15131 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
15132 gptab_data_sec
->contents
,
15133 0, gptab_data_sec
->size
))
15137 if (gptab_bss_sec
!= NULL
)
15139 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
15140 gptab_bss_sec
->contents
,
15141 0, gptab_bss_sec
->size
))
15145 if (SGI_COMPAT (abfd
))
15147 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
15148 if (rtproc_sec
!= NULL
)
15150 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
15151 rtproc_sec
->contents
,
15152 0, rtproc_sec
->size
))
15160 /* Merge object file header flags from IBFD into OBFD. Raise an error
15161 if there are conflicting settings. */
15164 mips_elf_merge_obj_e_flags (bfd
*ibfd
, struct bfd_link_info
*info
)
15166 bfd
*obfd
= info
->output_bfd
;
15167 struct mips_elf_obj_tdata
*out_tdata
= mips_elf_tdata (obfd
);
15168 flagword old_flags
;
15169 flagword new_flags
;
15172 new_flags
= elf_elfheader (ibfd
)->e_flags
;
15173 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
15174 old_flags
= elf_elfheader (obfd
)->e_flags
;
15176 /* Check flag compatibility. */
15178 new_flags
&= ~EF_MIPS_NOREORDER
;
15179 old_flags
&= ~EF_MIPS_NOREORDER
;
15181 /* Some IRIX 6 BSD-compatibility objects have this bit set. It
15182 doesn't seem to matter. */
15183 new_flags
&= ~EF_MIPS_XGOT
;
15184 old_flags
&= ~EF_MIPS_XGOT
;
15186 /* MIPSpro generates ucode info in n64 objects. Again, we should
15187 just be able to ignore this. */
15188 new_flags
&= ~EF_MIPS_UCODE
;
15189 old_flags
&= ~EF_MIPS_UCODE
;
15191 /* DSOs should only be linked with CPIC code. */
15192 if ((ibfd
->flags
& DYNAMIC
) != 0)
15193 new_flags
|= EF_MIPS_PIC
| EF_MIPS_CPIC
;
15195 if (new_flags
== old_flags
)
15200 if (((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0)
15201 != ((old_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0))
15204 (_("%pB: warning: linking abicalls files with non-abicalls files"),
15209 if (new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
))
15210 elf_elfheader (obfd
)->e_flags
|= EF_MIPS_CPIC
;
15211 if (! (new_flags
& EF_MIPS_PIC
))
15212 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_PIC
;
15214 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
15215 old_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
15217 /* Compare the ISAs. */
15218 if (mips_32bit_flags_p (old_flags
) != mips_32bit_flags_p (new_flags
))
15221 (_("%pB: linking 32-bit code with 64-bit code"),
15225 else if (!mips_mach_extends_p (bfd_get_mach (ibfd
), bfd_get_mach (obfd
)))
15227 /* OBFD's ISA isn't the same as, or an extension of, IBFD's. */
15228 if (mips_mach_extends_p (bfd_get_mach (obfd
), bfd_get_mach (ibfd
)))
15230 /* Copy the architecture info from IBFD to OBFD. Also copy
15231 the 32-bit flag (if set) so that we continue to recognise
15232 OBFD as a 32-bit binary. */
15233 bfd_set_arch_info (obfd
, bfd_get_arch_info (ibfd
));
15234 elf_elfheader (obfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
15235 elf_elfheader (obfd
)->e_flags
15236 |= new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
15238 /* Update the ABI flags isa_level, isa_rev, isa_ext fields. */
15239 update_mips_abiflags_isa (obfd
, &out_tdata
->abiflags
);
15241 /* Copy across the ABI flags if OBFD doesn't use them
15242 and if that was what caused us to treat IBFD as 32-bit. */
15243 if ((old_flags
& EF_MIPS_ABI
) == 0
15244 && mips_32bit_flags_p (new_flags
)
15245 && !mips_32bit_flags_p (new_flags
& ~EF_MIPS_ABI
))
15246 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ABI
;
15250 /* The ISAs aren't compatible. */
15252 /* xgettext:c-format */
15253 (_("%pB: linking %s module with previous %s modules"),
15255 bfd_printable_name (ibfd
),
15256 bfd_printable_name (obfd
));
15261 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
15262 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
15264 /* Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it
15265 does set EI_CLASS differently from any 32-bit ABI. */
15266 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
15267 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
15268 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
15270 /* Only error if both are set (to different values). */
15271 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
15272 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
15273 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
15276 /* xgettext:c-format */
15277 (_("%pB: ABI mismatch: linking %s module with previous %s modules"),
15279 elf_mips_abi_name (ibfd
),
15280 elf_mips_abi_name (obfd
));
15283 new_flags
&= ~EF_MIPS_ABI
;
15284 old_flags
&= ~EF_MIPS_ABI
;
15287 /* Compare ASEs. Forbid linking MIPS16 and microMIPS ASE modules together
15288 and allow arbitrary mixing of the remaining ASEs (retain the union). */
15289 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
15291 int old_micro
= old_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
;
15292 int new_micro
= new_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
;
15293 int old_m16
= old_flags
& EF_MIPS_ARCH_ASE_M16
;
15294 int new_m16
= new_flags
& EF_MIPS_ARCH_ASE_M16
;
15295 int micro_mis
= old_m16
&& new_micro
;
15296 int m16_mis
= old_micro
&& new_m16
;
15298 if (m16_mis
|| micro_mis
)
15301 /* xgettext:c-format */
15302 (_("%pB: ASE mismatch: linking %s module with previous %s modules"),
15304 m16_mis
? "MIPS16" : "microMIPS",
15305 m16_mis
? "microMIPS" : "MIPS16");
15309 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
15311 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
15312 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
15315 /* Compare NaN encodings. */
15316 if ((new_flags
& EF_MIPS_NAN2008
) != (old_flags
& EF_MIPS_NAN2008
))
15318 /* xgettext:c-format */
15319 _bfd_error_handler (_("%pB: linking %s module with previous %s modules"),
15321 (new_flags
& EF_MIPS_NAN2008
15322 ? "-mnan=2008" : "-mnan=legacy"),
15323 (old_flags
& EF_MIPS_NAN2008
15324 ? "-mnan=2008" : "-mnan=legacy"));
15326 new_flags
&= ~EF_MIPS_NAN2008
;
15327 old_flags
&= ~EF_MIPS_NAN2008
;
15330 /* Compare FP64 state. */
15331 if ((new_flags
& EF_MIPS_FP64
) != (old_flags
& EF_MIPS_FP64
))
15333 /* xgettext:c-format */
15334 _bfd_error_handler (_("%pB: linking %s module with previous %s modules"),
15336 (new_flags
& EF_MIPS_FP64
15337 ? "-mfp64" : "-mfp32"),
15338 (old_flags
& EF_MIPS_FP64
15339 ? "-mfp64" : "-mfp32"));
15341 new_flags
&= ~EF_MIPS_FP64
;
15342 old_flags
&= ~EF_MIPS_FP64
;
15345 /* Warn about any other mismatches */
15346 if (new_flags
!= old_flags
)
15348 /* xgettext:c-format */
15350 (_("%pB: uses different e_flags (%#x) fields than previous modules "
15352 ibfd
, new_flags
, old_flags
);
15359 /* Merge object attributes from IBFD into OBFD. Raise an error if
15360 there are conflicting attributes. */
15362 mips_elf_merge_obj_attributes (bfd
*ibfd
, struct bfd_link_info
*info
)
15364 bfd
*obfd
= info
->output_bfd
;
15365 obj_attribute
*in_attr
;
15366 obj_attribute
*out_attr
;
15370 abi_fp_bfd
= mips_elf_tdata (obfd
)->abi_fp_bfd
;
15371 in_attr
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
15372 if (!abi_fp_bfd
&& in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= Val_GNU_MIPS_ABI_FP_ANY
)
15373 mips_elf_tdata (obfd
)->abi_fp_bfd
= ibfd
;
15375 abi_msa_bfd
= mips_elf_tdata (obfd
)->abi_msa_bfd
;
15377 && in_attr
[Tag_GNU_MIPS_ABI_MSA
].i
!= Val_GNU_MIPS_ABI_MSA_ANY
)
15378 mips_elf_tdata (obfd
)->abi_msa_bfd
= ibfd
;
15380 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
15382 /* This is the first object. Copy the attributes. */
15383 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
15385 /* Use the Tag_null value to indicate the attributes have been
15387 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
15392 /* Check for conflicting Tag_GNU_MIPS_ABI_FP attributes and merge
15393 non-conflicting ones. */
15394 out_attr
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
15395 if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
15399 out_fp
= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
15400 in_fp
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
15401 out_attr
[Tag_GNU_MIPS_ABI_FP
].type
= 1;
15402 if (out_fp
== Val_GNU_MIPS_ABI_FP_ANY
)
15403 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_fp
;
15404 else if (out_fp
== Val_GNU_MIPS_ABI_FP_XX
15405 && (in_fp
== Val_GNU_MIPS_ABI_FP_DOUBLE
15406 || in_fp
== Val_GNU_MIPS_ABI_FP_64
15407 || in_fp
== Val_GNU_MIPS_ABI_FP_64A
))
15409 mips_elf_tdata (obfd
)->abi_fp_bfd
= ibfd
;
15410 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
15412 else if (in_fp
== Val_GNU_MIPS_ABI_FP_XX
15413 && (out_fp
== Val_GNU_MIPS_ABI_FP_DOUBLE
15414 || out_fp
== Val_GNU_MIPS_ABI_FP_64
15415 || out_fp
== Val_GNU_MIPS_ABI_FP_64A
))
15416 /* Keep the current setting. */;
15417 else if (out_fp
== Val_GNU_MIPS_ABI_FP_64A
15418 && in_fp
== Val_GNU_MIPS_ABI_FP_64
)
15420 mips_elf_tdata (obfd
)->abi_fp_bfd
= ibfd
;
15421 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
15423 else if (in_fp
== Val_GNU_MIPS_ABI_FP_64A
15424 && out_fp
== Val_GNU_MIPS_ABI_FP_64
)
15425 /* Keep the current setting. */;
15426 else if (in_fp
!= Val_GNU_MIPS_ABI_FP_ANY
)
15428 const char *out_string
, *in_string
;
15430 out_string
= _bfd_mips_fp_abi_string (out_fp
);
15431 in_string
= _bfd_mips_fp_abi_string (in_fp
);
15432 /* First warn about cases involving unrecognised ABIs. */
15433 if (!out_string
&& !in_string
)
15434 /* xgettext:c-format */
15436 (_("warning: %pB uses unknown floating point ABI %d "
15437 "(set by %pB), %pB uses unknown floating point ABI %d"),
15438 obfd
, out_fp
, abi_fp_bfd
, ibfd
, in_fp
);
15439 else if (!out_string
)
15441 /* xgettext:c-format */
15442 (_("warning: %pB uses unknown floating point ABI %d "
15443 "(set by %pB), %pB uses %s"),
15444 obfd
, out_fp
, abi_fp_bfd
, ibfd
, in_string
);
15445 else if (!in_string
)
15447 /* xgettext:c-format */
15448 (_("warning: %pB uses %s (set by %pB), "
15449 "%pB uses unknown floating point ABI %d"),
15450 obfd
, out_string
, abi_fp_bfd
, ibfd
, in_fp
);
15453 /* If one of the bfds is soft-float, the other must be
15454 hard-float. The exact choice of hard-float ABI isn't
15455 really relevant to the error message. */
15456 if (in_fp
== Val_GNU_MIPS_ABI_FP_SOFT
)
15457 out_string
= "-mhard-float";
15458 else if (out_fp
== Val_GNU_MIPS_ABI_FP_SOFT
)
15459 in_string
= "-mhard-float";
15461 /* xgettext:c-format */
15462 (_("warning: %pB uses %s (set by %pB), %pB uses %s"),
15463 obfd
, out_string
, abi_fp_bfd
, ibfd
, in_string
);
15468 /* Check for conflicting Tag_GNU_MIPS_ABI_MSA attributes and merge
15469 non-conflicting ones. */
15470 if (in_attr
[Tag_GNU_MIPS_ABI_MSA
].i
!= out_attr
[Tag_GNU_MIPS_ABI_MSA
].i
)
15472 out_attr
[Tag_GNU_MIPS_ABI_MSA
].type
= 1;
15473 if (out_attr
[Tag_GNU_MIPS_ABI_MSA
].i
== Val_GNU_MIPS_ABI_MSA_ANY
)
15474 out_attr
[Tag_GNU_MIPS_ABI_MSA
].i
= in_attr
[Tag_GNU_MIPS_ABI_MSA
].i
;
15475 else if (in_attr
[Tag_GNU_MIPS_ABI_MSA
].i
!= Val_GNU_MIPS_ABI_MSA_ANY
)
15476 switch (out_attr
[Tag_GNU_MIPS_ABI_MSA
].i
)
15478 case Val_GNU_MIPS_ABI_MSA_128
:
15480 /* xgettext:c-format */
15481 (_("warning: %pB uses %s (set by %pB), "
15482 "%pB uses unknown MSA ABI %d"),
15483 obfd
, "-mmsa", abi_msa_bfd
,
15484 ibfd
, in_attr
[Tag_GNU_MIPS_ABI_MSA
].i
);
15488 switch (in_attr
[Tag_GNU_MIPS_ABI_MSA
].i
)
15490 case Val_GNU_MIPS_ABI_MSA_128
:
15492 /* xgettext:c-format */
15493 (_("warning: %pB uses unknown MSA ABI %d "
15494 "(set by %pB), %pB uses %s"),
15495 obfd
, out_attr
[Tag_GNU_MIPS_ABI_MSA
].i
,
15496 abi_msa_bfd
, ibfd
, "-mmsa");
15501 /* xgettext:c-format */
15502 (_("warning: %pB uses unknown MSA ABI %d "
15503 "(set by %pB), %pB uses unknown MSA ABI %d"),
15504 obfd
, out_attr
[Tag_GNU_MIPS_ABI_MSA
].i
,
15505 abi_msa_bfd
, ibfd
, in_attr
[Tag_GNU_MIPS_ABI_MSA
].i
);
15511 /* Merge Tag_compatibility attributes and any common GNU ones. */
15512 return _bfd_elf_merge_object_attributes (ibfd
, info
);
15515 /* Merge object ABI flags from IBFD into OBFD. Raise an error if
15516 there are conflicting settings. */
15519 mips_elf_merge_obj_abiflags (bfd
*ibfd
, bfd
*obfd
)
15521 obj_attribute
*out_attr
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
15522 struct mips_elf_obj_tdata
*out_tdata
= mips_elf_tdata (obfd
);
15523 struct mips_elf_obj_tdata
*in_tdata
= mips_elf_tdata (ibfd
);
15525 /* Update the output abiflags fp_abi using the computed fp_abi. */
15526 out_tdata
->abiflags
.fp_abi
= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
15528 #define max(a, b) ((a) > (b) ? (a) : (b))
15529 /* Merge abiflags. */
15530 out_tdata
->abiflags
.isa_level
= max (out_tdata
->abiflags
.isa_level
,
15531 in_tdata
->abiflags
.isa_level
);
15532 out_tdata
->abiflags
.isa_rev
= max (out_tdata
->abiflags
.isa_rev
,
15533 in_tdata
->abiflags
.isa_rev
);
15534 out_tdata
->abiflags
.gpr_size
= max (out_tdata
->abiflags
.gpr_size
,
15535 in_tdata
->abiflags
.gpr_size
);
15536 out_tdata
->abiflags
.cpr1_size
= max (out_tdata
->abiflags
.cpr1_size
,
15537 in_tdata
->abiflags
.cpr1_size
);
15538 out_tdata
->abiflags
.cpr2_size
= max (out_tdata
->abiflags
.cpr2_size
,
15539 in_tdata
->abiflags
.cpr2_size
);
15541 out_tdata
->abiflags
.ases
|= in_tdata
->abiflags
.ases
;
15542 out_tdata
->abiflags
.flags1
|= in_tdata
->abiflags
.flags1
;
15547 /* Merge backend specific data from an object file to the output
15548 object file when linking. */
15551 _bfd_mips_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
15553 bfd
*obfd
= info
->output_bfd
;
15554 struct mips_elf_obj_tdata
*out_tdata
;
15555 struct mips_elf_obj_tdata
*in_tdata
;
15556 bfd_boolean null_input_bfd
= TRUE
;
15560 /* Check if we have the same endianness. */
15561 if (! _bfd_generic_verify_endian_match (ibfd
, info
))
15564 (_("%pB: endianness incompatible with that of the selected emulation"),
15569 if (!is_mips_elf (ibfd
) || !is_mips_elf (obfd
))
15572 in_tdata
= mips_elf_tdata (ibfd
);
15573 out_tdata
= mips_elf_tdata (obfd
);
15575 if (strcmp (bfd_get_target (ibfd
), bfd_get_target (obfd
)) != 0)
15578 (_("%pB: ABI is incompatible with that of the selected emulation"),
15583 /* Check to see if the input BFD actually contains any sections. If not,
15584 then it has no attributes, and its flags may not have been initialized
15585 either, but it cannot actually cause any incompatibility. */
15586 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
15588 /* Ignore synthetic sections and empty .text, .data and .bss sections
15589 which are automatically generated by gas. Also ignore fake
15590 (s)common sections, since merely defining a common symbol does
15591 not affect compatibility. */
15592 if ((sec
->flags
& SEC_IS_COMMON
) == 0
15593 && strcmp (sec
->name
, ".reginfo")
15594 && strcmp (sec
->name
, ".mdebug")
15596 || (strcmp (sec
->name
, ".text")
15597 && strcmp (sec
->name
, ".data")
15598 && strcmp (sec
->name
, ".bss"))))
15600 null_input_bfd
= FALSE
;
15604 if (null_input_bfd
)
15607 /* Populate abiflags using existing information. */
15608 if (in_tdata
->abiflags_valid
)
15610 obj_attribute
*in_attr
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
15611 Elf_Internal_ABIFlags_v0 in_abiflags
;
15612 Elf_Internal_ABIFlags_v0 abiflags
;
15614 /* Set up the FP ABI attribute from the abiflags if it is not already
15616 if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
== Val_GNU_MIPS_ABI_FP_ANY
)
15617 in_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_tdata
->abiflags
.fp_abi
;
15619 infer_mips_abiflags (ibfd
, &abiflags
);
15620 in_abiflags
= in_tdata
->abiflags
;
15622 /* It is not possible to infer the correct ISA revision
15623 for R3 or R5 so drop down to R2 for the checks. */
15624 if (in_abiflags
.isa_rev
== 3 || in_abiflags
.isa_rev
== 5)
15625 in_abiflags
.isa_rev
= 2;
15627 if (LEVEL_REV (in_abiflags
.isa_level
, in_abiflags
.isa_rev
)
15628 < LEVEL_REV (abiflags
.isa_level
, abiflags
.isa_rev
))
15630 (_("%pB: warning: inconsistent ISA between e_flags and "
15631 ".MIPS.abiflags"), ibfd
);
15632 if (abiflags
.fp_abi
!= Val_GNU_MIPS_ABI_FP_ANY
15633 && in_abiflags
.fp_abi
!= abiflags
.fp_abi
)
15635 (_("%pB: warning: inconsistent FP ABI between .gnu.attributes and "
15636 ".MIPS.abiflags"), ibfd
);
15637 if ((in_abiflags
.ases
& abiflags
.ases
) != abiflags
.ases
)
15639 (_("%pB: warning: inconsistent ASEs between e_flags and "
15640 ".MIPS.abiflags"), ibfd
);
15641 /* The isa_ext is allowed to be an extension of what can be inferred
15643 if (!mips_mach_extends_p (bfd_mips_isa_ext_mach (abiflags
.isa_ext
),
15644 bfd_mips_isa_ext_mach (in_abiflags
.isa_ext
)))
15646 (_("%pB: warning: inconsistent ISA extensions between e_flags and "
15647 ".MIPS.abiflags"), ibfd
);
15648 if (in_abiflags
.flags2
!= 0)
15650 (_("%pB: warning: unexpected flag in the flags2 field of "
15651 ".MIPS.abiflags (0x%lx)"), ibfd
,
15652 in_abiflags
.flags2
);
15656 infer_mips_abiflags (ibfd
, &in_tdata
->abiflags
);
15657 in_tdata
->abiflags_valid
= TRUE
;
15660 if (!out_tdata
->abiflags_valid
)
15662 /* Copy input abiflags if output abiflags are not already valid. */
15663 out_tdata
->abiflags
= in_tdata
->abiflags
;
15664 out_tdata
->abiflags_valid
= TRUE
;
15667 if (! elf_flags_init (obfd
))
15669 elf_flags_init (obfd
) = TRUE
;
15670 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
15671 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
15672 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
15674 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
15675 && (bfd_get_arch_info (obfd
)->the_default
15676 || mips_mach_extends_p (bfd_get_mach (obfd
),
15677 bfd_get_mach (ibfd
))))
15679 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
15680 bfd_get_mach (ibfd
)))
15683 /* Update the ABI flags isa_level, isa_rev and isa_ext fields. */
15684 update_mips_abiflags_isa (obfd
, &out_tdata
->abiflags
);
15690 ok
= mips_elf_merge_obj_e_flags (ibfd
, info
);
15692 ok
= mips_elf_merge_obj_attributes (ibfd
, info
) && ok
;
15694 ok
= mips_elf_merge_obj_abiflags (ibfd
, obfd
) && ok
;
15698 bfd_set_error (bfd_error_bad_value
);
15705 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
15708 _bfd_mips_elf_set_private_flags (bfd
*abfd
, flagword flags
)
15710 BFD_ASSERT (!elf_flags_init (abfd
)
15711 || elf_elfheader (abfd
)->e_flags
== flags
);
15713 elf_elfheader (abfd
)->e_flags
= flags
;
15714 elf_flags_init (abfd
) = TRUE
;
15719 _bfd_mips_elf_get_target_dtag (bfd_vma dtag
)
15723 default: return "";
15724 case DT_MIPS_RLD_VERSION
:
15725 return "MIPS_RLD_VERSION";
15726 case DT_MIPS_TIME_STAMP
:
15727 return "MIPS_TIME_STAMP";
15728 case DT_MIPS_ICHECKSUM
:
15729 return "MIPS_ICHECKSUM";
15730 case DT_MIPS_IVERSION
:
15731 return "MIPS_IVERSION";
15732 case DT_MIPS_FLAGS
:
15733 return "MIPS_FLAGS";
15734 case DT_MIPS_BASE_ADDRESS
:
15735 return "MIPS_BASE_ADDRESS";
15737 return "MIPS_MSYM";
15738 case DT_MIPS_CONFLICT
:
15739 return "MIPS_CONFLICT";
15740 case DT_MIPS_LIBLIST
:
15741 return "MIPS_LIBLIST";
15742 case DT_MIPS_LOCAL_GOTNO
:
15743 return "MIPS_LOCAL_GOTNO";
15744 case DT_MIPS_CONFLICTNO
:
15745 return "MIPS_CONFLICTNO";
15746 case DT_MIPS_LIBLISTNO
:
15747 return "MIPS_LIBLISTNO";
15748 case DT_MIPS_SYMTABNO
:
15749 return "MIPS_SYMTABNO";
15750 case DT_MIPS_UNREFEXTNO
:
15751 return "MIPS_UNREFEXTNO";
15752 case DT_MIPS_GOTSYM
:
15753 return "MIPS_GOTSYM";
15754 case DT_MIPS_HIPAGENO
:
15755 return "MIPS_HIPAGENO";
15756 case DT_MIPS_RLD_MAP
:
15757 return "MIPS_RLD_MAP";
15758 case DT_MIPS_RLD_MAP_REL
:
15759 return "MIPS_RLD_MAP_REL";
15760 case DT_MIPS_DELTA_CLASS
:
15761 return "MIPS_DELTA_CLASS";
15762 case DT_MIPS_DELTA_CLASS_NO
:
15763 return "MIPS_DELTA_CLASS_NO";
15764 case DT_MIPS_DELTA_INSTANCE
:
15765 return "MIPS_DELTA_INSTANCE";
15766 case DT_MIPS_DELTA_INSTANCE_NO
:
15767 return "MIPS_DELTA_INSTANCE_NO";
15768 case DT_MIPS_DELTA_RELOC
:
15769 return "MIPS_DELTA_RELOC";
15770 case DT_MIPS_DELTA_RELOC_NO
:
15771 return "MIPS_DELTA_RELOC_NO";
15772 case DT_MIPS_DELTA_SYM
:
15773 return "MIPS_DELTA_SYM";
15774 case DT_MIPS_DELTA_SYM_NO
:
15775 return "MIPS_DELTA_SYM_NO";
15776 case DT_MIPS_DELTA_CLASSSYM
:
15777 return "MIPS_DELTA_CLASSSYM";
15778 case DT_MIPS_DELTA_CLASSSYM_NO
:
15779 return "MIPS_DELTA_CLASSSYM_NO";
15780 case DT_MIPS_CXX_FLAGS
:
15781 return "MIPS_CXX_FLAGS";
15782 case DT_MIPS_PIXIE_INIT
:
15783 return "MIPS_PIXIE_INIT";
15784 case DT_MIPS_SYMBOL_LIB
:
15785 return "MIPS_SYMBOL_LIB";
15786 case DT_MIPS_LOCALPAGE_GOTIDX
:
15787 return "MIPS_LOCALPAGE_GOTIDX";
15788 case DT_MIPS_LOCAL_GOTIDX
:
15789 return "MIPS_LOCAL_GOTIDX";
15790 case DT_MIPS_HIDDEN_GOTIDX
:
15791 return "MIPS_HIDDEN_GOTIDX";
15792 case DT_MIPS_PROTECTED_GOTIDX
:
15793 return "MIPS_PROTECTED_GOT_IDX";
15794 case DT_MIPS_OPTIONS
:
15795 return "MIPS_OPTIONS";
15796 case DT_MIPS_INTERFACE
:
15797 return "MIPS_INTERFACE";
15798 case DT_MIPS_DYNSTR_ALIGN
:
15799 return "DT_MIPS_DYNSTR_ALIGN";
15800 case DT_MIPS_INTERFACE_SIZE
:
15801 return "DT_MIPS_INTERFACE_SIZE";
15802 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
:
15803 return "DT_MIPS_RLD_TEXT_RESOLVE_ADDR";
15804 case DT_MIPS_PERF_SUFFIX
:
15805 return "DT_MIPS_PERF_SUFFIX";
15806 case DT_MIPS_COMPACT_SIZE
:
15807 return "DT_MIPS_COMPACT_SIZE";
15808 case DT_MIPS_GP_VALUE
:
15809 return "DT_MIPS_GP_VALUE";
15810 case DT_MIPS_AUX_DYNAMIC
:
15811 return "DT_MIPS_AUX_DYNAMIC";
15812 case DT_MIPS_PLTGOT
:
15813 return "DT_MIPS_PLTGOT";
15814 case DT_MIPS_RWPLT
:
15815 return "DT_MIPS_RWPLT";
15819 /* Return the meaning of Tag_GNU_MIPS_ABI_FP value FP, or null if
15823 _bfd_mips_fp_abi_string (int fp
)
15827 /* These strings aren't translated because they're simply
15829 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
15830 return "-mdouble-float";
15832 case Val_GNU_MIPS_ABI_FP_SINGLE
:
15833 return "-msingle-float";
15835 case Val_GNU_MIPS_ABI_FP_SOFT
:
15836 return "-msoft-float";
15838 case Val_GNU_MIPS_ABI_FP_OLD_64
:
15839 return _("-mips32r2 -mfp64 (12 callee-saved)");
15841 case Val_GNU_MIPS_ABI_FP_XX
:
15844 case Val_GNU_MIPS_ABI_FP_64
:
15845 return "-mgp32 -mfp64";
15847 case Val_GNU_MIPS_ABI_FP_64A
:
15848 return "-mgp32 -mfp64 -mno-odd-spreg";
15856 print_mips_ases (FILE *file
, unsigned int mask
)
15858 if (mask
& AFL_ASE_DSP
)
15859 fputs ("\n\tDSP ASE", file
);
15860 if (mask
& AFL_ASE_DSPR2
)
15861 fputs ("\n\tDSP R2 ASE", file
);
15862 if (mask
& AFL_ASE_DSPR3
)
15863 fputs ("\n\tDSP R3 ASE", file
);
15864 if (mask
& AFL_ASE_EVA
)
15865 fputs ("\n\tEnhanced VA Scheme", file
);
15866 if (mask
& AFL_ASE_MCU
)
15867 fputs ("\n\tMCU (MicroController) ASE", file
);
15868 if (mask
& AFL_ASE_MDMX
)
15869 fputs ("\n\tMDMX ASE", file
);
15870 if (mask
& AFL_ASE_MIPS3D
)
15871 fputs ("\n\tMIPS-3D ASE", file
);
15872 if (mask
& AFL_ASE_MT
)
15873 fputs ("\n\tMT ASE", file
);
15874 if (mask
& AFL_ASE_SMARTMIPS
)
15875 fputs ("\n\tSmartMIPS ASE", file
);
15876 if (mask
& AFL_ASE_VIRT
)
15877 fputs ("\n\tVZ ASE", file
);
15878 if (mask
& AFL_ASE_MSA
)
15879 fputs ("\n\tMSA ASE", file
);
15880 if (mask
& AFL_ASE_MIPS16
)
15881 fputs ("\n\tMIPS16 ASE", file
);
15882 if (mask
& AFL_ASE_MICROMIPS
)
15883 fputs ("\n\tMICROMIPS ASE", file
);
15884 if (mask
& AFL_ASE_XPA
)
15885 fputs ("\n\tXPA ASE", file
);
15886 if (mask
& AFL_ASE_MIPS16E2
)
15887 fputs ("\n\tMIPS16e2 ASE", file
);
15888 if (mask
& AFL_ASE_CRC
)
15889 fputs ("\n\tCRC ASE", file
);
15890 if (mask
& AFL_ASE_GINV
)
15891 fputs ("\n\tGINV ASE", file
);
15892 if (mask
& AFL_ASE_LOONGSON_MMI
)
15893 fputs ("\n\tLoongson MMI ASE", file
);
15894 if (mask
& AFL_ASE_LOONGSON_CAM
)
15895 fputs ("\n\tLoongson CAM ASE", file
);
15896 if (mask
& AFL_ASE_LOONGSON_EXT
)
15897 fputs ("\n\tLoongson EXT ASE", file
);
15898 if (mask
& AFL_ASE_LOONGSON_EXT2
)
15899 fputs ("\n\tLoongson EXT2 ASE", file
);
15901 fprintf (file
, "\n\t%s", _("None"));
15902 else if ((mask
& ~AFL_ASE_MASK
) != 0)
15903 fprintf (stdout
, "\n\t%s (%x)", _("Unknown"), mask
& ~AFL_ASE_MASK
);
15907 print_mips_isa_ext (FILE *file
, unsigned int isa_ext
)
15912 fputs (_("None"), file
);
15915 fputs ("RMI XLR", file
);
15917 case AFL_EXT_OCTEON3
:
15918 fputs ("Cavium Networks Octeon3", file
);
15920 case AFL_EXT_OCTEON2
:
15921 fputs ("Cavium Networks Octeon2", file
);
15923 case AFL_EXT_OCTEONP
:
15924 fputs ("Cavium Networks OcteonP", file
);
15926 case AFL_EXT_OCTEON
:
15927 fputs ("Cavium Networks Octeon", file
);
15930 fputs ("Toshiba R5900", file
);
15933 fputs ("MIPS R4650", file
);
15936 fputs ("LSI R4010", file
);
15939 fputs ("NEC VR4100", file
);
15942 fputs ("Toshiba R3900", file
);
15944 case AFL_EXT_10000
:
15945 fputs ("MIPS R10000", file
);
15948 fputs ("Broadcom SB-1", file
);
15951 fputs ("NEC VR4111/VR4181", file
);
15954 fputs ("NEC VR4120", file
);
15957 fputs ("NEC VR5400", file
);
15960 fputs ("NEC VR5500", file
);
15962 case AFL_EXT_LOONGSON_2E
:
15963 fputs ("ST Microelectronics Loongson 2E", file
);
15965 case AFL_EXT_LOONGSON_2F
:
15966 fputs ("ST Microelectronics Loongson 2F", file
);
15968 case AFL_EXT_INTERAPTIV_MR2
:
15969 fputs ("Imagination interAptiv MR2", file
);
15972 fprintf (file
, "%s (%d)", _("Unknown"), isa_ext
);
15978 print_mips_fp_abi_value (FILE *file
, int val
)
15982 case Val_GNU_MIPS_ABI_FP_ANY
:
15983 fprintf (file
, _("Hard or soft float\n"));
15985 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
15986 fprintf (file
, _("Hard float (double precision)\n"));
15988 case Val_GNU_MIPS_ABI_FP_SINGLE
:
15989 fprintf (file
, _("Hard float (single precision)\n"));
15991 case Val_GNU_MIPS_ABI_FP_SOFT
:
15992 fprintf (file
, _("Soft float\n"));
15994 case Val_GNU_MIPS_ABI_FP_OLD_64
:
15995 fprintf (file
, _("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
15997 case Val_GNU_MIPS_ABI_FP_XX
:
15998 fprintf (file
, _("Hard float (32-bit CPU, Any FPU)\n"));
16000 case Val_GNU_MIPS_ABI_FP_64
:
16001 fprintf (file
, _("Hard float (32-bit CPU, 64-bit FPU)\n"));
16003 case Val_GNU_MIPS_ABI_FP_64A
:
16004 fprintf (file
, _("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
16007 fprintf (file
, "??? (%d)\n", val
);
16013 get_mips_reg_size (int reg_size
)
16015 return (reg_size
== AFL_REG_NONE
) ? 0
16016 : (reg_size
== AFL_REG_32
) ? 32
16017 : (reg_size
== AFL_REG_64
) ? 64
16018 : (reg_size
== AFL_REG_128
) ? 128
16023 _bfd_mips_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
16027 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
16029 /* Print normal ELF private data. */
16030 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
16032 /* xgettext:c-format */
16033 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
16035 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
16036 fprintf (file
, _(" [abi=O32]"));
16037 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
16038 fprintf (file
, _(" [abi=O64]"));
16039 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
16040 fprintf (file
, _(" [abi=EABI32]"));
16041 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
16042 fprintf (file
, _(" [abi=EABI64]"));
16043 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
16044 fprintf (file
, _(" [abi unknown]"));
16045 else if (ABI_N32_P (abfd
))
16046 fprintf (file
, _(" [abi=N32]"));
16047 else if (ABI_64_P (abfd
))
16048 fprintf (file
, _(" [abi=64]"));
16050 fprintf (file
, _(" [no abi set]"));
16052 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
16053 fprintf (file
, " [mips1]");
16054 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
16055 fprintf (file
, " [mips2]");
16056 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
16057 fprintf (file
, " [mips3]");
16058 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
16059 fprintf (file
, " [mips4]");
16060 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
16061 fprintf (file
, " [mips5]");
16062 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
16063 fprintf (file
, " [mips32]");
16064 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
16065 fprintf (file
, " [mips64]");
16066 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
)
16067 fprintf (file
, " [mips32r2]");
16068 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R2
)
16069 fprintf (file
, " [mips64r2]");
16070 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R6
)
16071 fprintf (file
, " [mips32r6]");
16072 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R6
)
16073 fprintf (file
, " [mips64r6]");
16075 fprintf (file
, _(" [unknown ISA]"));
16077 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
16078 fprintf (file
, " [mdmx]");
16080 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
16081 fprintf (file
, " [mips16]");
16083 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
16084 fprintf (file
, " [micromips]");
16086 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_NAN2008
)
16087 fprintf (file
, " [nan2008]");
16089 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_FP64
)
16090 fprintf (file
, " [old fp64]");
16092 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
16093 fprintf (file
, " [32bitmode]");
16095 fprintf (file
, _(" [not 32bitmode]"));
16097 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_NOREORDER
)
16098 fprintf (file
, " [noreorder]");
16100 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
16101 fprintf (file
, " [PIC]");
16103 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_CPIC
)
16104 fprintf (file
, " [CPIC]");
16106 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_XGOT
)
16107 fprintf (file
, " [XGOT]");
16109 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_UCODE
)
16110 fprintf (file
, " [UCODE]");
16112 fputc ('\n', file
);
16114 if (mips_elf_tdata (abfd
)->abiflags_valid
)
16116 Elf_Internal_ABIFlags_v0
*abiflags
= &mips_elf_tdata (abfd
)->abiflags
;
16117 fprintf (file
, "\nMIPS ABI Flags Version: %d\n", abiflags
->version
);
16118 fprintf (file
, "\nISA: MIPS%d", abiflags
->isa_level
);
16119 if (abiflags
->isa_rev
> 1)
16120 fprintf (file
, "r%d", abiflags
->isa_rev
);
16121 fprintf (file
, "\nGPR size: %d",
16122 get_mips_reg_size (abiflags
->gpr_size
));
16123 fprintf (file
, "\nCPR1 size: %d",
16124 get_mips_reg_size (abiflags
->cpr1_size
));
16125 fprintf (file
, "\nCPR2 size: %d",
16126 get_mips_reg_size (abiflags
->cpr2_size
));
16127 fputs ("\nFP ABI: ", file
);
16128 print_mips_fp_abi_value (file
, abiflags
->fp_abi
);
16129 fputs ("ISA Extension: ", file
);
16130 print_mips_isa_ext (file
, abiflags
->isa_ext
);
16131 fputs ("\nASEs:", file
);
16132 print_mips_ases (file
, abiflags
->ases
);
16133 fprintf (file
, "\nFLAGS 1: %8.8lx", abiflags
->flags1
);
16134 fprintf (file
, "\nFLAGS 2: %8.8lx", abiflags
->flags2
);
16135 fputc ('\n', file
);
16141 const struct bfd_elf_special_section _bfd_mips_elf_special_sections
[] =
16143 { STRING_COMMA_LEN (".lit4"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
16144 { STRING_COMMA_LEN (".lit8"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
16145 { STRING_COMMA_LEN (".mdebug"), 0, SHT_MIPS_DEBUG
, 0 },
16146 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
16147 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
16148 { STRING_COMMA_LEN (".ucode"), 0, SHT_MIPS_UCODE
, 0 },
16149 { NULL
, 0, 0, 0, 0 }
16152 /* Merge non visibility st_other attributes. Ensure that the
16153 STO_OPTIONAL flag is copied into h->other, even if this is not a
16154 definiton of the symbol. */
16156 _bfd_mips_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
16157 const Elf_Internal_Sym
*isym
,
16158 bfd_boolean definition
,
16159 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
16161 if ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1)) != 0)
16163 unsigned char other
;
16165 other
= (definition
? isym
->st_other
: h
->other
);
16166 other
&= ~ELF_ST_VISIBILITY (-1);
16167 h
->other
= other
| ELF_ST_VISIBILITY (h
->other
);
16171 && ELF_MIPS_IS_OPTIONAL (isym
->st_other
))
16172 h
->other
|= STO_OPTIONAL
;
16175 /* Decide whether an undefined symbol is special and can be ignored.
16176 This is the case for OPTIONAL symbols on IRIX. */
16178 _bfd_mips_elf_ignore_undef_symbol (struct elf_link_hash_entry
*h
)
16180 return ELF_MIPS_IS_OPTIONAL (h
->other
) ? TRUE
: FALSE
;
16184 _bfd_mips_elf_common_definition (Elf_Internal_Sym
*sym
)
16186 return (sym
->st_shndx
== SHN_COMMON
16187 || sym
->st_shndx
== SHN_MIPS_ACOMMON
16188 || sym
->st_shndx
== SHN_MIPS_SCOMMON
);
16191 /* Return address for Ith PLT stub in section PLT, for relocation REL
16192 or (bfd_vma) -1 if it should not be included. */
16195 _bfd_mips_elf_plt_sym_val (bfd_vma i
, const asection
*plt
,
16196 const arelent
*rel ATTRIBUTE_UNUSED
)
16199 + 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
)
16200 + i
* 4 * ARRAY_SIZE (mips_exec_plt_entry
));
16203 /* Build a table of synthetic symbols to represent the PLT. As with MIPS16
16204 and microMIPS PLT slots we may have a many-to-one mapping between .plt
16205 and .got.plt and also the slots may be of a different size each we walk
16206 the PLT manually fetching instructions and matching them against known
16207 patterns. To make things easier standard MIPS slots, if any, always come
16208 first. As we don't create proper ELF symbols we use the UDATA.I member
16209 of ASYMBOL to carry ISA annotation. The encoding used is the same as
16210 with the ST_OTHER member of the ELF symbol. */
16213 _bfd_mips_elf_get_synthetic_symtab (bfd
*abfd
,
16214 long symcount ATTRIBUTE_UNUSED
,
16215 asymbol
**syms ATTRIBUTE_UNUSED
,
16216 long dynsymcount
, asymbol
**dynsyms
,
16219 static const char pltname
[] = "_PROCEDURE_LINKAGE_TABLE_";
16220 static const char microsuffix
[] = "@micromipsplt";
16221 static const char m16suffix
[] = "@mips16plt";
16222 static const char mipssuffix
[] = "@plt";
16224 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
16225 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
16226 bfd_boolean micromips_p
= MICROMIPS_P (abfd
);
16227 Elf_Internal_Shdr
*hdr
;
16228 bfd_byte
*plt_data
;
16229 bfd_vma plt_offset
;
16230 unsigned int other
;
16231 bfd_vma entry_size
;
16250 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0 || dynsymcount
<= 0)
16253 relplt
= bfd_get_section_by_name (abfd
, ".rel.plt");
16254 if (relplt
== NULL
)
16257 hdr
= &elf_section_data (relplt
)->this_hdr
;
16258 if (hdr
->sh_link
!= elf_dynsymtab (abfd
) || hdr
->sh_type
!= SHT_REL
)
16261 plt
= bfd_get_section_by_name (abfd
, ".plt");
16265 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
16266 if (!(*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
16268 p
= relplt
->relocation
;
16270 /* Calculating the exact amount of space required for symbols would
16271 require two passes over the PLT, so just pessimise assuming two
16272 PLT slots per relocation. */
16273 count
= relplt
->size
/ hdr
->sh_entsize
;
16274 counti
= count
* bed
->s
->int_rels_per_ext_rel
;
16275 size
= 2 * count
* sizeof (asymbol
);
16276 size
+= count
* (sizeof (mipssuffix
) +
16277 (micromips_p
? sizeof (microsuffix
) : sizeof (m16suffix
)));
16278 for (pi
= 0; pi
< counti
; pi
+= bed
->s
->int_rels_per_ext_rel
)
16279 size
+= 2 * strlen ((*p
[pi
].sym_ptr_ptr
)->name
);
16281 /* Add the size of "_PROCEDURE_LINKAGE_TABLE_" too. */
16282 size
+= sizeof (asymbol
) + sizeof (pltname
);
16284 if (!bfd_malloc_and_get_section (abfd
, plt
, &plt_data
))
16287 if (plt
->size
< 16)
16290 s
= *ret
= bfd_malloc (size
);
16293 send
= s
+ 2 * count
+ 1;
16295 names
= (char *) send
;
16296 nend
= (char *) s
+ size
;
16299 opcode
= bfd_get_micromips_32 (abfd
, plt_data
+ 12);
16300 if (opcode
== 0x3302fffe)
16304 plt0_size
= 2 * ARRAY_SIZE (micromips_o32_exec_plt0_entry
);
16305 other
= STO_MICROMIPS
;
16307 else if (opcode
== 0x0398c1d0)
16311 plt0_size
= 2 * ARRAY_SIZE (micromips_insn32_o32_exec_plt0_entry
);
16312 other
= STO_MICROMIPS
;
16316 plt0_size
= 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
);
16321 s
->flags
= BSF_SYNTHETIC
| BSF_FUNCTION
| BSF_LOCAL
;
16325 s
->udata
.i
= other
;
16326 memcpy (names
, pltname
, sizeof (pltname
));
16327 names
+= sizeof (pltname
);
16331 for (plt_offset
= plt0_size
;
16332 plt_offset
+ 8 <= plt
->size
&& s
< send
;
16333 plt_offset
+= entry_size
)
16335 bfd_vma gotplt_addr
;
16336 const char *suffix
;
16341 opcode
= bfd_get_micromips_32 (abfd
, plt_data
+ plt_offset
+ 4);
16343 /* Check if the second word matches the expected MIPS16 instruction. */
16344 if (opcode
== 0x651aeb00)
16348 /* Truncated table??? */
16349 if (plt_offset
+ 16 > plt
->size
)
16351 gotplt_addr
= bfd_get_32 (abfd
, plt_data
+ plt_offset
+ 12);
16352 entry_size
= 2 * ARRAY_SIZE (mips16_o32_exec_plt_entry
);
16353 suffixlen
= sizeof (m16suffix
);
16354 suffix
= m16suffix
;
16355 other
= STO_MIPS16
;
16357 /* Likewise the expected microMIPS instruction (no insn32 mode). */
16358 else if (opcode
== 0xff220000)
16362 gotplt_hi
= bfd_get_16 (abfd
, plt_data
+ plt_offset
) & 0x7f;
16363 gotplt_lo
= bfd_get_16 (abfd
, plt_data
+ plt_offset
+ 2) & 0xffff;
16364 gotplt_hi
= ((gotplt_hi
^ 0x40) - 0x40) << 18;
16366 gotplt_addr
= gotplt_hi
+ gotplt_lo
;
16367 gotplt_addr
+= ((plt
->vma
+ plt_offset
) | 3) ^ 3;
16368 entry_size
= 2 * ARRAY_SIZE (micromips_o32_exec_plt_entry
);
16369 suffixlen
= sizeof (microsuffix
);
16370 suffix
= microsuffix
;
16371 other
= STO_MICROMIPS
;
16373 /* Likewise the expected microMIPS instruction (insn32 mode). */
16374 else if ((opcode
& 0xffff0000) == 0xff2f0000)
16376 gotplt_hi
= bfd_get_16 (abfd
, plt_data
+ plt_offset
+ 2) & 0xffff;
16377 gotplt_lo
= bfd_get_16 (abfd
, plt_data
+ plt_offset
+ 6) & 0xffff;
16378 gotplt_hi
= ((gotplt_hi
^ 0x8000) - 0x8000) << 16;
16379 gotplt_lo
= (gotplt_lo
^ 0x8000) - 0x8000;
16380 gotplt_addr
= gotplt_hi
+ gotplt_lo
;
16381 entry_size
= 2 * ARRAY_SIZE (micromips_insn32_o32_exec_plt_entry
);
16382 suffixlen
= sizeof (microsuffix
);
16383 suffix
= microsuffix
;
16384 other
= STO_MICROMIPS
;
16386 /* Otherwise assume standard MIPS code. */
16389 gotplt_hi
= bfd_get_32 (abfd
, plt_data
+ plt_offset
) & 0xffff;
16390 gotplt_lo
= bfd_get_32 (abfd
, plt_data
+ plt_offset
+ 4) & 0xffff;
16391 gotplt_hi
= ((gotplt_hi
^ 0x8000) - 0x8000) << 16;
16392 gotplt_lo
= (gotplt_lo
^ 0x8000) - 0x8000;
16393 gotplt_addr
= gotplt_hi
+ gotplt_lo
;
16394 entry_size
= 4 * ARRAY_SIZE (mips_exec_plt_entry
);
16395 suffixlen
= sizeof (mipssuffix
);
16396 suffix
= mipssuffix
;
16399 /* Truncated table??? */
16400 if (plt_offset
+ entry_size
> plt
->size
)
16404 i
< count
&& p
[pi
].address
!= gotplt_addr
;
16405 i
++, pi
= (pi
+ bed
->s
->int_rels_per_ext_rel
) % counti
);
16412 *s
= **p
[pi
].sym_ptr_ptr
;
16413 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
16414 we are defining a symbol, ensure one of them is set. */
16415 if ((s
->flags
& BSF_LOCAL
) == 0)
16416 s
->flags
|= BSF_GLOBAL
;
16417 s
->flags
|= BSF_SYNTHETIC
;
16419 s
->value
= plt_offset
;
16421 s
->udata
.i
= other
;
16423 len
= strlen ((*p
[pi
].sym_ptr_ptr
)->name
);
16424 namelen
= len
+ suffixlen
;
16425 if (names
+ namelen
> nend
)
16428 memcpy (names
, (*p
[pi
].sym_ptr_ptr
)->name
, len
);
16430 memcpy (names
, suffix
, suffixlen
);
16431 names
+= suffixlen
;
16434 pi
= (pi
+ bed
->s
->int_rels_per_ext_rel
) % counti
;
16443 /* Return the ABI flags associated with ABFD if available. */
16445 Elf_Internal_ABIFlags_v0
*
16446 bfd_mips_elf_get_abiflags (bfd
*abfd
)
16448 struct mips_elf_obj_tdata
*tdata
= mips_elf_tdata (abfd
);
16450 return tdata
->abiflags_valid
? &tdata
->abiflags
: NULL
;
16453 /* MIPS libc ABI versions, used with the EI_ABIVERSION ELF file header
16454 field. Taken from `libc-abis.h' generated at GNU libc build time.
16455 Using a MIPS_ prefix as other libc targets use different values. */
16458 MIPS_LIBC_ABI_DEFAULT
= 0,
16459 MIPS_LIBC_ABI_MIPS_PLT
,
16460 MIPS_LIBC_ABI_UNIQUE
,
16461 MIPS_LIBC_ABI_MIPS_O32_FP64
,
16462 MIPS_LIBC_ABI_ABSOLUTE
,
16467 _bfd_mips_post_process_headers (bfd
*abfd
, struct bfd_link_info
*link_info
)
16469 struct mips_elf_link_hash_table
*htab
= NULL
;
16470 Elf_Internal_Ehdr
*i_ehdrp
;
16472 i_ehdrp
= elf_elfheader (abfd
);
16475 htab
= mips_elf_hash_table (link_info
);
16476 BFD_ASSERT (htab
!= NULL
);
16479 if (htab
!= NULL
&& htab
->use_plts_and_copy_relocs
&& !htab
->is_vxworks
)
16480 i_ehdrp
->e_ident
[EI_ABIVERSION
] = MIPS_LIBC_ABI_MIPS_PLT
;
16482 if (mips_elf_tdata (abfd
)->abiflags
.fp_abi
== Val_GNU_MIPS_ABI_FP_64
16483 || mips_elf_tdata (abfd
)->abiflags
.fp_abi
== Val_GNU_MIPS_ABI_FP_64A
)
16484 i_ehdrp
->e_ident
[EI_ABIVERSION
] = MIPS_LIBC_ABI_MIPS_O32_FP64
;
16486 /* Mark that we need support for absolute symbols in the dynamic loader. */
16487 if (htab
!= NULL
&& htab
->use_absolute_zero
&& htab
->gnu_target
)
16488 i_ehdrp
->e_ident
[EI_ABIVERSION
] = MIPS_LIBC_ABI_ABSOLUTE
;
16490 _bfd_elf_post_process_headers (abfd
, link_info
);
16494 _bfd_mips_elf_compact_eh_encoding
16495 (struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
16497 return DW_EH_PE_pcrel
| DW_EH_PE_sdata4
;
16500 /* Return the opcode for can't unwind. */
16503 _bfd_mips_elf_cant_unwind_opcode
16504 (struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
16506 return COMPACT_EH_CANT_UNWIND_OPCODE
;